WSL2-Linux-Kernel/arch/xtensa/kernel
Ulrich Drepper ed8cae8ba0 flag parameters: pipe
This patch introduces the new syscall pipe2 which is like pipe but it also
takes an additional parameter which takes a flag value.  This patch implements
the handling of O_CLOEXEC for the flag.  I did not add support for the new
syscall for the architectures which have a special sys_pipe implementation.  I
think the maintainers of those archs have the chance to go with the unified
implementation but that's up to them.

The implementation introduces do_pipe_flags.  I did that instead of changing
all callers of do_pipe because some of the callers are written in assembler.
I would probably screw up changing the assembly code.  To avoid breaking code
do_pipe is now a small wrapper around do_pipe_flags.  Once all callers are
changed over to do_pipe_flags the old do_pipe function can be removed.

The following test must be adjusted for architectures other than x86 and
x86-64 and in case the syscall numbers changed.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>

#ifndef __NR_pipe2
# ifdef __x86_64__
#  define __NR_pipe2 293
# elif defined __i386__
#  define __NR_pipe2 331
# else
#  error "need __NR_pipe2"
# endif
#endif

int
main (void)
{
  int fd[2];
  if (syscall (__NR_pipe2, fd, 0) != 0)
    {
      puts ("pipe2(0) failed");
      return 1;
    }
  for (int i = 0; i < 2; ++i)
    {
      int coe = fcntl (fd[i], F_GETFD);
      if (coe == -1)
        {
          puts ("fcntl failed");
          return 1;
        }
      if (coe & FD_CLOEXEC)
        {
          printf ("pipe2(0) set close-on-exit for fd[%d]\n", i);
          return 1;
        }
    }
  close (fd[0]);
  close (fd[1]);

  if (syscall (__NR_pipe2, fd, O_CLOEXEC) != 0)
    {
      puts ("pipe2(O_CLOEXEC) failed");
      return 1;
    }
  for (int i = 0; i < 2; ++i)
    {
      int coe = fcntl (fd[i], F_GETFD);
      if (coe == -1)
        {
          puts ("fcntl failed");
          return 1;
        }
      if ((coe & FD_CLOEXEC) == 0)
        {
          printf ("pipe2(O_CLOEXEC) does not set close-on-exit for fd[%d]\n", i);
          return 1;
        }
    }
  close (fd[0]);
  close (fd[1]);

  puts ("OK");

  return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ulrich Drepper <drepper@redhat.com>
Acked-by: Davide Libenzi <davidel@xmailserver.org>
Cc: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-24 10:47:28 -07:00
..
Makefile Generic semaphore implementation 2008-04-17 10:42:34 -04:00
align.S [PATCH] xtensa: remove extra header files 2006-12-10 09:55:39 -08:00
asm-offsets.c xtensa: use kbuild.h macros instead of defining them in asm-offsets.c 2008-04-29 08:06:29 -07:00
coprocessor.S [XTENSA] Add support for configurable registers and coprocessors 2008-02-13 17:41:43 -08:00
entry.S [XTENSA] Fix register corruption for certain processor configurations 2008-02-13 17:43:54 -08:00
head.S [XTENSA] Move common sections into bss sections 2007-05-31 17:48:07 -07:00
init_task.c [PATCH] take init_files to fs/file.c 2008-05-16 17:22:20 -04:00
io.c [XTENSA] Move string-io functions to io.c from pci.c 2007-08-27 13:53:22 -07:00
irq.c [PATCH] xtensa: fix irq and misc fixes 2006-12-10 09:55:39 -08:00
module.c [XTENSA] Fix modules for non-exec processor configurations 2008-02-13 17:23:26 -08:00
pci-dma.c fix file specification in comments 2007-05-09 08:58:16 +02:00
pci.c [XTENSA] Move string-io functions to io.c from pci.c 2007-08-27 13:53:22 -07:00
platform.c Remove obsolete #include <linux/config.h> 2006-06-30 19:25:36 +02:00
process.c [XTENSA] Add support for configurable registers and coprocessors 2008-02-13 17:41:43 -08:00
ptrace.c [XTENSA] Allow debugger to modify the WINDOWBASE register. 2008-02-13 17:45:36 -08:00
setup.c PAGE_ALIGN(): correctly handle 64-bit values on 32-bit architectures 2008-07-24 10:47:21 -07:00
signal.c [XTENSA] Add support for the sa_restorer function 2008-02-13 17:42:31 -08:00
syscall.c flag parameters: pipe 2008-07-24 10:47:28 -07:00
time.c calibrate_delay() must be __cpuinit 2008-02-06 10:41:08 -08:00
traps.c [XTENSA] Add support for configurable registers and coprocessors 2008-02-13 17:41:43 -08:00
vectors.S [PATCH] xtensa: remove extra header files 2006-12-10 09:55:39 -08:00
vmlinux.lds.S [XTENSA] Add missing RELOCATE_ENTRY for debug vector 2008-02-13 17:25:14 -08:00
xtensa_ksyms.c Generic semaphore implementation 2008-04-17 10:42:34 -04:00