Blame elf/dl-write.c

Packit Service 3451db
/* Implementation of the _dl_write function.  Generic version.
Packit Service 3451db
   Copyright (C) 2020 Free Software Foundation, Inc.
Packit Service 3451db
   This file is part of the GNU C Library.
Packit Service 3451db
Packit Service 3451db
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 3451db
   modify it under the terms of the GNU Lesser General Public
Packit Service 3451db
   License as published by the Free Software Foundation; either
Packit Service 3451db
   version 2.1 of the License, or (at your option) any later version.
Packit Service 3451db
Packit Service 3451db
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 3451db
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 3451db
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 3451db
   Lesser General Public License for more details.
Packit Service 3451db
Packit Service 3451db
   You should have received a copy of the GNU Lesser General Public
Packit Service 3451db
   License along with the GNU C Library; if not, see
Packit Service 3451db
   <https://www.gnu.org/licenses/>.  */
Packit Service 3451db
Packit Service 3451db
#include <errno.h>
Packit Service 3451db
#include <ldsodefs.h>
Packit Service 3451db
#include <libc-lock.h>
Packit Service 3451db
#include <sys/uio.h>
Packit Service 3451db
Packit Service 3451db
ssize_t
Packit Service 3451db
_dl_write (int fd, const void *buffer, size_t length)
Packit Service 3451db
{
Packit Service 3451db
  struct iovec iov = { .iov_base = (void *) buffer, .iov_len = length };
Packit Service 3451db
  ssize_t ret;
Packit Service 3451db
Packit Service 3451db
#if RTLD_PRIVATE_ERRNO
Packit Service 3451db
  /* We have to take this lock just to be sure we don't clobber the private
Packit Service 3451db
     errno when it's being used by another thread that cares about it.
Packit Service 3451db
     Yet we must be sure not to try calling the lock functions before
Packit Service 3451db
     the thread library is fully initialized.  */
Packit Service 3451db
  if (__glibc_unlikely (_dl_starting_up))
Packit Service 3451db
    {
Packit Service 3451db
      ret = __writev (fd, &iov, 1);
Packit Service 3451db
      if (ret < 0)
Packit Service 3451db
        ret = -errno;
Packit Service 3451db
    }
Packit Service 3451db
  else
Packit Service 3451db
    {
Packit Service 3451db
      __rtld_lock_lock_recursive (GL(dl_load_lock));
Packit Service 3451db
      __writev (fd, &iov, 1);
Packit Service 3451db
      if (ret < 0)
Packit Service 3451db
        ret = -errno;
Packit Service 3451db
      __rtld_lock_unlock_recursive (GL(dl_load_lock));
Packit Service 3451db
    }
Packit Service 3451db
#else
Packit Service 3451db
  ret = __writev (fd, &iov, 1);
Packit Service 3451db
  if (ret < 0)
Packit Service 3451db
    ret = -errno;
Packit Service 3451db
#endif
Packit Service 3451db
Packit Service 3451db
  return ret;
Packit Service 3451db
}