Blame elf/dl-write.c

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