diff --git a/libc/Android.mk b/libc/Android.mk index 7c098a8af..1164bd67f 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -112,7 +112,6 @@ libc_common_src_files := \ bionic/recv.c \ bionic/sched_cpualloc.c \ bionic/sched_cpucount.c \ - bionic/sched_getcpu.c \ bionic/semaphore.c \ bionic/send.c \ bionic/setpgrp.c \ @@ -261,6 +260,7 @@ libc_bionic_src_files := \ bionic/sbrk.cpp \ bionic/scandir.cpp \ bionic/sched_getaffinity.cpp \ + bionic/sched_getcpu.cpp \ bionic/setegid.cpp \ bionic/__set_errno.cpp \ bionic/seteuid.cpp \ diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 19b4d2241..d0fa528f4 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -179,7 +179,6 @@ int removexattr(const char*, const char*) all int lremovexattr(const char*, const char*) all int __statfs64:statfs64(const char*, size_t, struct statfs*) arm,mips,x86 int statfs(const char*, struct statfs*) aarch64,x86_64 -long unshare(unsigned long) all int swapon(const char*, int) all int swapoff(const char*) all @@ -256,8 +255,10 @@ int sched_get_priority_max(int policy) all int sched_get_priority_min(int policy) all int sched_rr_get_interval(pid_t pid, struct timespec* interval) all int sched_setaffinity(pid_t pid, size_t setsize, const cpu_set_t* set) all +int setns(int, int) all +int unshare(int) all int __sched_getaffinity:sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set) all -int __getcpu:getcpu(unsigned* cpu, unsigned* node, void* unused) all +int __getcpu:getcpu(unsigned*, unsigned*, void*) all # io priorities int ioprio_set(int which, int who, int ioprio) all diff --git a/libc/arch-aarch64/syscalls.mk b/libc/arch-aarch64/syscalls.mk index ab9c839d1..3e5d191f7 100644 --- a/libc/arch-aarch64/syscalls.mk +++ b/libc/arch-aarch64/syscalls.mk @@ -147,6 +147,7 @@ syscall_src += arch-aarch64/syscalls/sendto.S syscall_src += arch-aarch64/syscalls/setgid.S syscall_src += arch-aarch64/syscalls/setgroups.S syscall_src += arch-aarch64/syscalls/setitimer.S +syscall_src += arch-aarch64/syscalls/setns.S syscall_src += arch-aarch64/syscalls/setpgid.S syscall_src += arch-aarch64/syscalls/setpriority.S syscall_src += arch-aarch64/syscalls/setregid.S diff --git a/libc/arch-aarch64/syscalls/setns.S b/libc/arch-aarch64/syscalls/setns.S new file mode 100644 index 000000000..2ce2a75fd --- /dev/null +++ b/libc/arch-aarch64/syscalls/setns.S @@ -0,0 +1,21 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(setns) + stp x29, x30, [sp, #-16]! + mov x29, sp + str x8, [sp, #-16]! + + mov x8, __NR_setns + svc #0 + + ldr x8, [sp], #16 + ldp x29, x30, [sp], #16 + + cmn x0, #(MAX_ERRNO + 1) + cneg x0, x0, hi + b.hi __set_errno + + ret +END(setns) diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk index a1d4689fc..f1763efaf 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -154,6 +154,7 @@ syscall_src += arch-arm/syscalls/sendto.S syscall_src += arch-arm/syscalls/setgid.S syscall_src += arch-arm/syscalls/setgroups.S syscall_src += arch-arm/syscalls/setitimer.S +syscall_src += arch-arm/syscalls/setns.S syscall_src += arch-arm/syscalls/setpgid.S syscall_src += arch-arm/syscalls/setpriority.S syscall_src += arch-arm/syscalls/setregid.S diff --git a/libc/arch-arm/syscalls/setns.S b/libc/arch-arm/syscalls/setns.S new file mode 100644 index 000000000..7afbff065 --- /dev/null +++ b/libc/arch-arm/syscalls/setns.S @@ -0,0 +1,14 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(setns) + mov ip, r7 + ldr r7, =__NR_setns + swi #0 + mov r7, ip + cmn r0, #(MAX_ERRNO + 1) + bxls lr + neg r0, r0 + b __set_errno +END(setns) diff --git a/libc/arch-mips/syscalls.mk b/libc/arch-mips/syscalls.mk index 40932b712..cc7e557d6 100644 --- a/libc/arch-mips/syscalls.mk +++ b/libc/arch-mips/syscalls.mk @@ -154,6 +154,7 @@ syscall_src += arch-mips/syscalls/sendto.S syscall_src += arch-mips/syscalls/setgid.S syscall_src += arch-mips/syscalls/setgroups.S syscall_src += arch-mips/syscalls/setitimer.S +syscall_src += arch-mips/syscalls/setns.S syscall_src += arch-mips/syscalls/setpgid.S syscall_src += arch-mips/syscalls/setpriority.S syscall_src += arch-mips/syscalls/setregid.S diff --git a/libc/arch-mips/syscalls/setns.S b/libc/arch-mips/syscalls/setns.S new file mode 100644 index 000000000..fd4529e73 --- /dev/null +++ b/libc/arch-mips/syscalls/setns.S @@ -0,0 +1,23 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + .text + .globl setns + .align 4 + .ent setns + +setns: + .set noreorder + .cpload $t9 + li $v0, __NR_setns + syscall + bnez $a3, 1f + move $a0, $v0 + j $ra + nop +1: + la $t9,__set_errno + j $t9 + nop + .set reorder + .end setns diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk index 780972f1f..0699d091a 100644 --- a/libc/arch-x86/syscalls.mk +++ b/libc/arch-x86/syscalls.mk @@ -153,6 +153,7 @@ syscall_src += arch-x86/syscalls/sendto.S syscall_src += arch-x86/syscalls/setgid.S syscall_src += arch-x86/syscalls/setgroups.S syscall_src += arch-x86/syscalls/setitimer.S +syscall_src += arch-x86/syscalls/setns.S syscall_src += arch-x86/syscalls/setpgid.S syscall_src += arch-x86/syscalls/setpriority.S syscall_src += arch-x86/syscalls/setregid.S diff --git a/libc/arch-x86/syscalls/setns.S b/libc/arch-x86/syscalls/setns.S new file mode 100644 index 000000000..6bdb98cb4 --- /dev/null +++ b/libc/arch-x86/syscalls/setns.S @@ -0,0 +1,23 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(setns) + pushl %ebx + pushl %ecx + mov 12(%esp), %ebx + mov 16(%esp), %ecx + movl $__NR_setns, %eax + int $0x80 + cmpl $-MAX_ERRNO, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %ecx + popl %ebx + ret +END(setns) diff --git a/libc/arch-x86_64/syscalls.mk b/libc/arch-x86_64/syscalls.mk index 9e2bfccfe..cac7423dc 100644 --- a/libc/arch-x86_64/syscalls.mk +++ b/libc/arch-x86_64/syscalls.mk @@ -148,6 +148,7 @@ syscall_src += arch-x86_64/syscalls/sendto.S syscall_src += arch-x86_64/syscalls/setgid.S syscall_src += arch-x86_64/syscalls/setgroups.S syscall_src += arch-x86_64/syscalls/setitimer.S +syscall_src += arch-x86_64/syscalls/setns.S syscall_src += arch-x86_64/syscalls/setpgid.S syscall_src += arch-x86_64/syscalls/setpriority.S syscall_src += arch-x86_64/syscalls/setregid.S diff --git a/libc/arch-x86_64/syscalls/setns.S b/libc/arch-x86_64/syscalls/setns.S new file mode 100644 index 000000000..bab147b02 --- /dev/null +++ b/libc/arch-x86_64/syscalls/setns.S @@ -0,0 +1,16 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +ENTRY(setns) + movl $__NR_setns, %eax + syscall + cmpq $-MAX_ERRNO, %rax + jb 1f + negl %eax + movl %eax, %edi + call __set_errno + orq $-1, %rax +1: + ret +END(setns) diff --git a/libc/bionic/sched_getcpu.c b/libc/bionic/sched_getcpu.cpp similarity index 87% rename from libc/bionic/sched_getcpu.c rename to libc/bionic/sched_getcpu.cpp index 954df3727..1f92e5438 100644 --- a/libc/bionic/sched_getcpu.c +++ b/libc/bionic/sched_getcpu.cpp @@ -25,16 +25,17 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + #define _GNU_SOURCE 1 #include -extern int __getcpu(unsigned *cpu, unsigned *node, void* unused); +extern "C" int __getcpu(unsigned*, unsigned*, void*); -int sched_getcpu(void) -{ - unsigned cpu; - if (__getcpu(&cpu, NULL, NULL) < 0) - return 0; - - return (int)cpu; +int sched_getcpu() { + unsigned cpu; + int rc = __getcpu(&cpu, NULL, NULL); + if (rc == -1) { + return -1; // errno is already set. + } + return cpu; } diff --git a/libc/include/sched.h b/libc/include/sched.h index 4d7d8c6b1..fba6514e9 100644 --- a/libc/include/sched.h +++ b/libc/include/sched.h @@ -31,54 +31,32 @@ #include #include +#include + __BEGIN_DECLS -#define SCHED_NORMAL 0 -#define SCHED_OTHER 0 -#define SCHED_FIFO 1 -#define SCHED_RR 2 +/* This name is used by glibc, but not by the kernel. */ +#define SCHED_OTHER SCHED_NORMAL struct sched_param { - int sched_priority; + int sched_priority; }; -extern int sched_setscheduler(pid_t, int, const struct sched_param *); +extern int sched_setscheduler(pid_t, int, const struct sched_param*); extern int sched_getscheduler(pid_t); extern int sched_yield(void); -extern int sched_get_priority_max(int policy); -extern int sched_get_priority_min(int policy); -extern int sched_setparam(pid_t, const struct sched_param *); -extern int sched_getparam(pid_t, struct sched_param *); -extern int sched_rr_get_interval(pid_t pid, struct timespec *tp); - -#define CLONE_VM 0x00000100 -#define CLONE_FS 0x00000200 -#define CLONE_FILES 0x00000400 -#define CLONE_SIGHAND 0x00000800 -#define CLONE_PTRACE 0x00002000 -#define CLONE_VFORK 0x00004000 -#define CLONE_PARENT 0x00008000 -#define CLONE_THREAD 0x00010000 -#define CLONE_NEWNS 0x00020000 -#define CLONE_SYSVSEM 0x00040000 -#define CLONE_SETTLS 0x00080000 -#define CLONE_PARENT_SETTID 0x00100000 -#define CLONE_CHILD_CLEARTID 0x00200000 -#define CLONE_DETACHED 0x00400000 -#define CLONE_UNTRACED 0x00800000 -#define CLONE_CHILD_SETTID 0x01000000 -#define CLONE_STOPPED 0x02000000 +extern int sched_get_priority_max(int); +extern int sched_get_priority_min(int); +extern int sched_setparam(pid_t, const struct sched_param*); +extern int sched_getparam(pid_t, struct sched_param*); +extern int sched_rr_get_interval(pid_t, struct timespec*); #ifdef _GNU_SOURCE -extern int clone(int (*fn)(void *), void *child_stack, int flags, void* arg, ...); + +extern int clone(int (*)(void*), void*, int, void*, ...); extern int unshare(int); -#endif - -/* Support for cpu thread affinity */ -#ifdef _GNU_SOURCE - extern int sched_getcpu(void); - +extern int setns(int, int); /* Our implementation supports up to 32 independent CPUs, which is also * the maximum supported by the kernel at the moment. GLibc uses 1024 by diff --git a/libc/include/sys/glibc-syscalls.h b/libc/include/sys/glibc-syscalls.h index 0deb73a42..3131b6b3f 100644 --- a/libc/include/sys/glibc-syscalls.h +++ b/libc/include/sys/glibc-syscalls.h @@ -375,6 +375,7 @@ #define SYS_fcntl64 __NR_fcntl64 #define SYS_fdatasync __NR_fdatasync #define SYS_fgetxattr __NR_fgetxattr +#define SYS_finit_module __NR_finit_module #define SYS_flistxattr __NR_flistxattr #define SYS_flock __NR_flock #define SYS_fork __NR_fork @@ -439,6 +440,7 @@ #define SYS_ioprio_get __NR_ioprio_get #define SYS_ioprio_set __NR_ioprio_set #define SYS_ipc __NR_ipc +#define SYS_kcmp __NR_kcmp #define SYS_kexec_load __NR_kexec_load #define SYS_keyctl __NR_keyctl #define SYS_kill __NR_kill diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py index ef201c324..58d1afd14 100755 --- a/libc/tools/gensyscalls.py +++ b/libc/tools/gensyscalls.py @@ -416,7 +416,7 @@ class State: glibc_fp.write("#if defined(__aarch64__)\n") self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-generic/unistd.h") glibc_fp.write("#elif defined(__arm__)\n") - self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-arm/asm/unistd.h") + self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-arm/asm/unistd.h") glibc_fp.write("#elif defined(__mips__)\n") self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-mips/asm/unistd.h") glibc_fp.write("#elif defined(__i386__)\n")