OpenCloudOS-Kernel/include/asm-parisc
Ulrich Drepper aaca0bdca5 flag parameters: paccept
This patch is by far the most complex in the series.  It adds a new syscall
paccept.  This syscall differs from accept in that it adds (at the userlevel)
two additional parameters:

- a signal mask
- a flags value

The flags parameter can be used to set flag like SOCK_CLOEXEC.  This is
imlpemented here as well.  Some people argued that this is a property which
should be inherited from the file desriptor for the server but this is against
POSIX.  Additionally, we really want the signal mask parameter as well
(similar to pselect, ppoll, etc).  So an interface change in inevitable.

The flag value is the same as for socket and socketpair.  I think diverging
here will only create confusion.  Similar to the filesystem interfaces where
the use of the O_* constants differs, it is acceptable here.

The signal mask is handled as for pselect etc.  The mask is temporarily
installed for the thread and removed before the call returns.  I modeled the
code after pselect.  If there is a problem it's likely also in pselect.

For architectures which use socketcall I maintained this interface instead of
adding a system call.  The symmetry shouldn't be broken.

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/syscall.h>

#ifndef __NR_paccept
# ifdef __x86_64__
#  define __NR_paccept 288
# elif defined __i386__
#  define SYS_PACCEPT 18
#  define USE_SOCKETCALL 1
# else
#  error "need __NR_paccept"
# endif
#endif

#ifdef USE_SOCKETCALL
# define paccept(fd, addr, addrlen, mask, flags) \
  ({ long args[6] = { \
       (long) fd, (long) addr, (long) addrlen, (long) mask, 8, (long) flags }; \
     syscall (__NR_socketcall, SYS_PACCEPT, args); })
#else
# define paccept(fd, addr, addrlen, mask, flags) \
  syscall (__NR_paccept, fd, addr, addrlen, mask, 8, flags)
#endif

#define PORT 57392

#define SOCK_CLOEXEC O_CLOEXEC

static pthread_barrier_t b;

static void *
tf (void *arg)
{
  pthread_barrier_wait (&b);
  int s = socket (AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in sin;
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  sin.sin_port = htons (PORT);
  connect (s, (const struct sockaddr *) &sin, sizeof (sin));
  close (s);

  pthread_barrier_wait (&b);
  s = socket (AF_INET, SOCK_STREAM, 0);
  sin.sin_port = htons (PORT);
  connect (s, (const struct sockaddr *) &sin, sizeof (sin));
  close (s);
  pthread_barrier_wait (&b);

  pthread_barrier_wait (&b);
  sleep (2);
  pthread_kill ((pthread_t) arg, SIGUSR1);

  return NULL;
}

static void
handler (int s)
{
}

int
main (void)
{
  pthread_barrier_init (&b, NULL, 2);

  struct sockaddr_in sin;
  pthread_t th;
  if (pthread_create (&th, NULL, tf, (void *) pthread_self ()) != 0)
    {
      puts ("pthread_create failed");
      return 1;
    }

  int s = socket (AF_INET, SOCK_STREAM, 0);
  int reuse = 1;
  setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  sin.sin_port = htons (PORT);
  bind (s, (struct sockaddr *) &sin, sizeof (sin));
  listen (s, SOMAXCONN);

  pthread_barrier_wait (&b);

  int s2 = paccept (s, NULL, 0, NULL, 0);
  if (s2 < 0)
    {
      puts ("paccept(0) failed");
      return 1;
    }

  int coe = fcntl (s2, F_GETFD);
  if (coe & FD_CLOEXEC)
    {
      puts ("paccept(0) set close-on-exec-flag");
      return 1;
    }
  close (s2);

  pthread_barrier_wait (&b);

  s2 = paccept (s, NULL, 0, NULL, SOCK_CLOEXEC);
  if (s2 < 0)
    {
      puts ("paccept(SOCK_CLOEXEC) failed");
      return 1;
    }

  coe = fcntl (s2, F_GETFD);
  if ((coe & FD_CLOEXEC) == 0)
    {
      puts ("paccept(SOCK_CLOEXEC) does not set close-on-exec flag");
      return 1;
    }
  close (s2);

  pthread_barrier_wait (&b);

  struct sigaction sa;
  sa.sa_handler = handler;
  sa.sa_flags = 0;
  sigemptyset (&sa.sa_mask);
  sigaction (SIGUSR1, &sa, NULL);

  sigset_t ss;
  pthread_sigmask (SIG_SETMASK, NULL, &ss);
  sigaddset (&ss, SIGUSR1);
  pthread_sigmask (SIG_SETMASK, &ss, NULL);

  sigdelset (&ss, SIGUSR1);
  alarm (4);
  pthread_barrier_wait (&b);

  errno = 0 ;
  s2 = paccept (s, NULL, 0, &ss, 0);
  if (s2 != -1 || errno != EINTR)
    {
      puts ("paccept did not fail with EINTR");
      return 1;
    }

  close (s);

  puts ("OK");

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

[akpm@linux-foundation.org: make it compile]
[akpm@linux-foundation.org: add sys_ni stub]
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>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Roland McGrath <roland@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-24 10:47:27 -07:00
..
Kbuild [PARISC] Export pdc.h for palo 2007-10-18 00:58:29 -07:00
a.out.h aout: move STACK_TOP[_MAX] to asm/processor.h 2008-02-08 09:22:29 -08:00
agp.h x86: remove flush_agp_mappings() 2008-01-30 13:34:07 +01:00
asmregs.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
assembly.h parisc: use conditional macro for 64-bit wide ops 2008-05-15 11:03:43 -04:00
atomic.h Add cmpxchg_local to parisc 2008-02-07 08:42:32 -08:00
auxvec.h [PATCH] auxiliary vector cleanups 2005-09-07 16:57:21 -07:00
bitops.h generic: implement __fls on all 64-bit archs 2008-04-26 19:21:16 +02:00
bug.h Fix WARN_ON() on bitfield ops for all other archs 2007-08-01 20:45:38 -07:00
bugs.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
byteorder.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
cache.h [PARISC] Clean up the cache and tlb headers 2007-02-17 00:41:30 -05:00
cacheflush.h [PARISC] Add prototypes for flush_user_dcache_range and flush_user_icache_range 2007-02-17 00:43:51 -05:00
checksum.h parisc: fix miscompilation of ip_fast_csum with gcc >= 4.3 2008-06-13 10:49:56 -04:00
compat.h asm-*/compat.h: fix typo in comment 2008-02-03 16:32:51 +02:00
compat_rt_sigframe.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
compat_signal.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
compat_ucontext.h [PARISC] Arch-specific compat signals 2006-01-22 20:57:42 -05:00
cputime.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
current.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
delay.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
device.h Driver core: add dev_archdata to struct device 2006-12-01 14:52:01 -08:00
div64.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
dma-mapping.h [PARISC] Fix ccio_request_resource when CONFIG_IOMMU_CCIO is not defined 2006-12-08 00:33:59 -05:00
dma.h Fix misc .c/.h comment typos 2006-11-30 05:24:39 +01:00
eisa_bus.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
eisa_eeprom.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
elf.h [PARISC] clean up include/asm-parisc/elf.h 2008-03-15 19:12:10 -07:00
emergency-restart.h [PATCH] Add emergency_restart() 2005-07-26 14:35:41 -07:00
errno.h [PARISC] Add ECANCELED to errno.h 2005-10-21 22:53:43 -04:00
fb.h fbdev: detect primary display device 2007-07-17 10:23:11 -07:00
fcntl.h Introduce O_CLOEXEC 2007-07-16 09:05:45 -07:00
fixmap.h [PARISC] move VMALLOC_* definitions to fixmap.h 2008-03-15 19:11:49 -07:00
floppy.h cleanup floppy.h 2007-10-17 08:42:55 -07:00
futex.h asm-*/futex.h should include linux/uaccess.h 2008-04-30 08:29:52 -07:00
grfioctl.h [PARISC] Use kzalloc and other janitor-style cleanups 2006-01-22 20:26:31 -05:00
hardirq.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
hardware.h [PARISC] fix section mismatches in arch/parisc/kernel 2007-05-27 13:36:27 -04:00
hw_irq.h [PATCH] genirq: add ->retrigger() irq op to consolidate hw_irq_resend() 2006-06-29 10:26:23 -07:00
ide.h ide: remove ide_default_io_ctl() macro 2008-04-18 00:46:34 +02:00
io.h [PARISC] parisc: "extern inline" -> "static inline" 2007-10-18 00:58:41 -07:00
ioctl.h parisc: Remove ioctl.h content picked up from <asm-generic/ioctl.h>. 2008-05-15 11:03:34 -04:00
ioctls.h parisc: new termios definitions 2008-05-15 10:38:54 -04:00
ipcbuf.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
irq.h [PARISC] Allow nested interrupts 2006-10-04 06:48:57 -06:00
irq_regs.h Build fixes for struct pt_regs removal 2006-10-06 20:47:23 -06:00
kdebug.h move die notifier handling to common code 2007-05-08 11:15:04 -07:00
kmap_types.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
kvm.h kvm: provide kvm.h for all architecture: fixes headers_install 2008-04-02 15:28:18 -07:00
led.h [PARISC] Convert soft power switch driver to kthread 2007-02-17 01:03:43 -05:00
linkage.h include/asm-parisc/: Spelling fixes 2008-02-03 17:00:11 +02:00
local.h local_t: parisc cleanup 2007-05-08 11:15:20 -07:00
machdep.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mc146818rtc.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mckinley.h [PARISC] Add asm-parisc/mckinley.h bus header 2006-10-04 06:45:48 -06:00
mman.h [PATCH] Remove final references to deprecated "MAP_ANON" page protection flag 2007-02-11 10:51:17 -08:00
mmu.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mmu_context.h Detach sched.h from mm.h 2007-05-21 09:18:19 -07:00
mmzone.h [PARISC] convert to use CONFIG_64BIT instead of __LP64__ 2007-02-17 01:17:13 -05:00
module.h [PARISC] convert to use CONFIG_64BIT instead of __LP64__ 2007-02-17 01:17:13 -05:00
msgbuf.h [PARISC] convert to use CONFIG_64BIT instead of __LP64__ 2007-02-17 01:17:13 -05:00
mutex.h [PATCH] mutex subsystem, add default include/asm-*/mutex.h files 2006-01-09 15:59:19 -08:00
namei.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
page.h PAGE_ALIGN(): correctly handle 64-bit values on 32-bit architectures 2008-07-24 10:47:21 -07:00
param.h [PARISC] Use CONFIG_HZ to determine interval timer rate (aka clock ticks) 2006-10-04 06:47:46 -06:00
parisc-device.h [PARISC] convert to use CONFIG_64BIT instead of __LP64__ 2007-02-17 01:17:13 -05:00
parport.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
pci.h [PARISC] parisc: "extern inline" -> "static inline" 2007-10-18 00:58:41 -07:00
pdc.h [PARISC] pdc_console: fix bizarre panic on boot 2008-03-15 19:12:03 -07:00
pdc_chassis.h [PARISC] Clarify pdc_stable license terms 2006-03-30 17:48:41 +00:00
pdcpat.h [PARISC] Remove duplicate PDC_PAT_CELL defines 2006-12-08 00:34:47 -05:00
percpu.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
perf.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
pgalloc.h [PARISC] unbreak pgalloc.h 2008-03-15 19:11:52 -07:00
pgtable.h mm: introduce pte_special pte bit 2008-04-28 08:58:23 -07:00
poll.h Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
posix_types.h asm-*/posix_types.h: scrub __GLIBC__ 2008-02-08 09:22:34 -08:00
prefetch.h [PARISC] parisc: "extern inline" -> "static inline" 2007-10-18 00:58:41 -07:00
processor.h aout: move STACK_TOP[_MAX] to asm/processor.h 2008-02-08 09:22:29 -08:00
psw.h Don't include linux/config.h from anywhere else in include/ 2006-04-26 12:56:16 +01:00
ptrace.h [PARISC] Take into account nullified insn and lock functions for profiling 2005-10-21 22:42:18 -04:00
real.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
resource.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
ropes.h Fix misc .c/.h comment typos 2006-11-30 05:24:39 +01:00
rt_sigframe.h [PARISC] Arch-specific compat signals 2006-01-22 20:57:42 -05:00
rtc.h [PARISC] fix uninitialized variable warning in asm/rtc.h 2007-10-20 13:23:00 -07:00
runway.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
scatterlist.h parisc: fix sg_page() fallout 2007-10-23 09:49:31 +02:00
sections.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
segment.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
semaphore.h Generic semaphore implementation 2008-04-17 10:42:34 -04:00
sembuf.h [PARISC] convert to use CONFIG_64BIT instead of __LP64__ 2007-02-17 01:17:13 -05:00
serial.h [PARISC] Clean up asm-parisc/serial.h 2006-10-04 06:47:03 -06:00
setup.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
shmbuf.h [PARISC] convert to use CONFIG_64BIT instead of __LP64__ 2007-02-17 01:17:13 -05:00
shmparam.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
sigcontext.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
siginfo.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
signal.h [PARISC] convert to use CONFIG_64BIT instead of __LP64__ 2007-02-17 01:17:13 -05:00
smp.h parisc: convert to generic helpers for IPI function calls 2008-06-26 11:22:57 +02:00
socket.h flag parameters: paccept 2008-07-24 10:47:27 -07:00
sockios.h [NET]: Introduce SIOCGSTAMPNS ioctl to get timestamps with nanosec resolution 2007-04-25 22:24:04 -07:00
spinlock.h [PARISC] Enable interrupts while spinning 2006-10-04 06:48:17 -06:00
spinlock_types.h [PARISC] "Fix" circular includes 2007-02-17 00:43:10 -05:00
stat.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
statfs.h [PATCH] use __u64 rather than u64 in parisc statfs structs 2007-02-08 18:56:57 -05:00
string.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
superio.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
system.h [PATCH] sched: sched_cacheflush is now unused 2007-07-19 21:28:35 +02:00
termbits.h parisc: new termios definitions 2008-05-15 10:38:54 -04:00
termios.h parisc: new termios definitions 2008-05-15 10:38:54 -04:00
thread_info.h remove unused TIF_NOTIFY_RESUME flag 2007-07-31 15:39:38 -07:00
timex.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
tlb.h add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
tlbflush.h remove unused flush_tlb_pgtables 2007-10-19 11:53:34 -07:00
topology.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
traps.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
types.h parisc: types: use <asm-generic/int-*.h> for the parisc architecture 2008-05-02 16:18:32 -07:00
uaccess.h [PARISC] add ASM_EXCEPTIONTABLE_ENTRY() macro 2007-02-17 01:16:26 -05:00
ucontext.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
unaligned.h kernel: Move arches to use common unaligned access 2008-04-29 08:06:27 -07:00
unistd.h [PARISC] bump __NR_syscalls 2008-03-15 19:11:54 -07:00
unwind.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
user.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
vga.h vga.h: Fix prepocessor warning 2008-02-03 15:59:02 +02:00
xor.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00