Blame elf/dl-writev.h

Packit Service 82fcde
/* Message-writing for the dynamic linker.  Generic version.
Packit Service 82fcde
   Copyright (C) 2013-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <sys/uio.h>
Packit Service 82fcde
#include <ldsodefs.h>
Packit Service 82fcde
#include <libc-lock.h>
Packit Service 82fcde
Packit Service 82fcde
/* This is used from only one place: dl-misc.c:_dl_debug_vdprintf.
Packit Service 82fcde
   Hence it's in a header with the expectation it will be inlined.
Packit Service 82fcde
Packit Service 82fcde
   This is writev, but with a constraint added and others loosened:
Packit Service 82fcde
Packit Service 82fcde
   1. Under RTLD_PRIVATE_ERRNO, it must not clobber the private errno
Packit Service 82fcde
      when another thread holds the dl_load_lock.
Packit Service 82fcde
   2. It is not obliged to detect and report errors at all.
Packit Service 82fcde
   3. It's not really obliged to deliver a single atomic write
Packit Service 82fcde
      (though it may be preferable).  */
Packit Service 82fcde
Packit Service 82fcde
static inline void
Packit Service 82fcde
_dl_writev (int fd, const struct iovec *iov, size_t niov)
Packit Service 82fcde
{
Packit Service 82fcde
  /* Note that if __writev is an implementation that calls malloc,
Packit Service 82fcde
     this will cause linking problems building the dynamic linker.  */
Packit Service 82fcde
Packit Service 82fcde
#if RTLD_PRIVATE_ERRNO
Packit Service 82fcde
  /* We have to take this lock just to be sure we don't clobber the private
Packit Service 82fcde
     errno when it's being used by another thread that cares about it.
Packit Service 82fcde
     Yet we must be sure not to try calling the lock functions before
Packit Service 82fcde
     the thread library is fully initialized.  */
Packit Service 82fcde
  if (__glibc_unlikely (_dl_starting_up))
Packit Service 82fcde
    __writev (fd, iov, niov);
Packit Service 82fcde
  else
Packit Service 82fcde
    {
Packit Service 82fcde
      __rtld_lock_lock_recursive (GL(dl_load_lock));
Packit Service 82fcde
      __writev (fd, iov, niov);
Packit Service 82fcde
      __rtld_lock_unlock_recursive (GL(dl_load_lock));
Packit Service 82fcde
    }
Packit Service 82fcde
#else
Packit Service 82fcde
  __writev (fd, iov, niov);
Packit Service 82fcde
#endif
Packit Service 82fcde
}