add acct, accept4, setns, and dup3 syscalls (linux extensions)
authorRich Felker <dalias@aerifal.cx>
Sun, 9 Sep 2012 00:22:08 +0000 (20:22 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 9 Sep 2012 00:22:08 +0000 (20:22 -0400)
based on patch by Justin Cormack

arch/i386/bits/syscall.h
include/sched.h
include/sys/acct.h [new file with mode: 0644]
include/sys/socket.h
include/unistd.h
src/linux/accept4.c [new file with mode: 0644]
src/linux/dup3.c [new file with mode: 0644]
src/linux/setns.c [new file with mode: 0644]

index 77c7f11..c36d81f 100644 (file)
@@ -131,6 +131,9 @@ static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long
 #define __SC_getsockopt  15
 #define __SC_sendmsg     16
 #define __SC_recvmsg     17
+#define __SC_accept4     18
+#define __SC_recvmmsg    19
+#define __SC_sendmmsg    20
 
 #define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_socketcall, __SC_##nm, \
     ((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f }))
index 9062772..3df4c7b 100644 (file)
@@ -59,6 +59,7 @@ int     sched_yield(void);
 #define CLONE_IO       0x80000000
 int clone (int (*)(void *), void *, int, void *, ...);
 int unshare(int);
+int setns(int, int);
 #endif
 
 #ifdef __cplusplus
diff --git a/include/sys/acct.h b/include/sys/acct.h
new file mode 100644 (file)
index 0000000..ee576c4
--- /dev/null
@@ -0,0 +1,75 @@
+#ifndef _SYS_ACCT_H
+#define _SYS_ACCT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <features.h>
+#include <endian.h>
+#include <time.h>
+#include <stdint.h>
+
+#define ACCT_COMM 16
+
+typedef uint16_t comp_t;
+
+struct acct
+{
+       char ac_flag;
+       uint16_t ac_uid;
+       uint16_t ac_gid;
+       uint16_t ac_tty;
+       uint32_t ac_btime;
+       comp_t ac_utime;
+       comp_t ac_stime;
+       comp_t ac_etime;
+       comp_t ac_mem;
+       comp_t ac_io;
+       comp_t ac_rw;
+       comp_t ac_minflt;
+       comp_t ac_majflt;
+       comp_t ac_swaps;
+       uint32_t ac_exitcode;
+       char ac_comm[ACCT_COMM+1];
+       char ac_pad[10];
+};
+
+
+struct acct_v3
+{
+       char ac_flag;
+       char ac_version;
+       uint16_t ac_tty;
+       uint32_t ac_exitcode;
+       uint32_t ac_uid;
+       uint32_t ac_gid;
+       uint32_t ac_pid;
+       uint32_t ac_ppid;
+       uint32_t ac_btime;
+       float ac_etime;
+       comp_t ac_utime;
+       comp_t ac_stime;
+       comp_t ac_mem;
+       comp_t ac_io;
+       comp_t ac_rw;
+       comp_t ac_minflt;
+       comp_t ac_majflt;
+       comp_t ac_swaps;
+       char ac_comm[ACCT_COMM];
+};
+
+#define AFORK 1
+#define ASU 2
+#define ACORE 8
+#define AXSIG 16
+#define ACCT_BYTEORDER (128*(__BYTE_ORDER==__BIG_ENDIAN))
+#define AHZ 100
+
+int acct(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 97d7887..4afec4e 100644 (file)
@@ -255,6 +255,10 @@ int sockatmark (int);
 #define SHUT_WR 1
 #define SHUT_RDWR 2
 
+#ifdef _GNU_SOURCE
+int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index b5206a6..4f6953c 100644 (file)
@@ -171,6 +171,7 @@ int daemon(int, int);
 void setusershell(void);
 void endusershell(void);
 char *getusershell(void);
+int acct(const char *);
 #endif
 
 #ifdef _GNU_SOURCE
@@ -181,6 +182,7 @@ int getresuid(uid_t *, uid_t *, uid_t *);
 int getresgid(gid_t *, gid_t *, gid_t *);
 char *get_current_dir_name(void);
 int pipe2(int [2], int);
+int dup3(int, int, int);
 #endif
 
 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
diff --git a/src/linux/accept4.c b/src/linux/accept4.c
new file mode 100644 (file)
index 0000000..6b5c16c
--- /dev/null
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE
+#include <sys/socket.h>
+#include "syscall.h"
+#include "libc.h"
+
+int accept4(int fd, struct sockaddr *restrict addr, socklen_t *restrict len, int flg)
+{
+       return socketcall_cp(accept4, fd, addr, len, flg, 0, 0);
+}
diff --git a/src/linux/dup3.c b/src/linux/dup3.c
new file mode 100644 (file)
index 0000000..e201ef0
--- /dev/null
@@ -0,0 +1,10 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <errno.h>
+#include "syscall.h"
+
+int dup3(int old, int new, int flags) {
+        int r;
+        while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
+        return __syscall_ret(r);
+}
diff --git a/src/linux/setns.c b/src/linux/setns.c
new file mode 100644 (file)
index 0000000..af3eb09
--- /dev/null
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE
+#include <sched.h>
+#include "syscall.h"
+#include "libc.h"
+
+int setns(int fd, int nstype)
+{
+        return syscall(SYS_setns, fd, nstype);
+}