diff options
-rw-r--r-- | libc/SYSCALLS.TXT | 2 | ||||
-rw-r--r-- | libc/arch-arm/syscalls/sethostname.S | 14 | ||||
-rw-r--r-- | libc/arch-arm64/syscalls/sethostname.S | 14 | ||||
-rw-r--r-- | libc/arch-mips/syscalls/sethostname.S | 19 | ||||
-rw-r--r-- | libc/arch-mips64/syscalls/sethostname.S | 25 | ||||
-rw-r--r-- | libc/arch-x86/syscalls/sethostname.S | 26 | ||||
-rw-r--r-- | libc/arch-x86_64/syscalls/sethostname.S | 15 | ||||
-rw-r--r-- | libc/include/unistd.h | 3 | ||||
-rw-r--r-- | tests/unistd_test.cpp | 8 |
9 files changed, 125 insertions, 1 deletions
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 866671d..39ff37d 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -313,6 +313,8 @@ int __set_tid_address:set_tid_address(int*) all int setfsgid(gid_t) all int setfsuid(uid_t) all +int sethostname(const char*, size_t) all + pid_t wait4(pid_t, int*, int, struct rusage*) all int __waitid:waitid(int, pid_t, struct siginfo_t*, int, void*) all diff --git a/libc/arch-arm/syscalls/sethostname.S b/libc/arch-arm/syscalls/sethostname.S new file mode 100644 index 0000000..0a98fd3 --- /dev/null +++ b/libc/arch-arm/syscalls/sethostname.S @@ -0,0 +1,14 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include <private/bionic_asm.h> + +ENTRY(sethostname) + mov ip, r7 + ldr r7, =__NR_sethostname + swi #0 + mov r7, ip + cmn r0, #(MAX_ERRNO + 1) + bxls lr + neg r0, r0 + b __set_errno_internal +END(sethostname) diff --git a/libc/arch-arm64/syscalls/sethostname.S b/libc/arch-arm64/syscalls/sethostname.S new file mode 100644 index 0000000..2dea457 --- /dev/null +++ b/libc/arch-arm64/syscalls/sethostname.S @@ -0,0 +1,14 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include <private/bionic_asm.h> + +ENTRY(sethostname) + mov x8, __NR_sethostname + svc #0 + + cmn x0, #(MAX_ERRNO + 1) + cneg x0, x0, hi + b.hi __set_errno_internal + + ret +END(sethostname) diff --git a/libc/arch-mips/syscalls/sethostname.S b/libc/arch-mips/syscalls/sethostname.S new file mode 100644 index 0000000..2987b52 --- /dev/null +++ b/libc/arch-mips/syscalls/sethostname.S @@ -0,0 +1,19 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include <private/bionic_asm.h> + +ENTRY(sethostname) + .set noreorder + .cpload t9 + li v0, __NR_sethostname + syscall + bnez a3, 1f + move a0, v0 + j ra + nop +1: + la t9,__set_errno_internal + j t9 + nop + .set reorder +END(sethostname) diff --git a/libc/arch-mips64/syscalls/sethostname.S b/libc/arch-mips64/syscalls/sethostname.S new file mode 100644 index 0000000..2f132a2 --- /dev/null +++ b/libc/arch-mips64/syscalls/sethostname.S @@ -0,0 +1,25 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include <private/bionic_asm.h> + +ENTRY(sethostname) + .set push + .set noreorder + li v0, __NR_sethostname + syscall + bnez a3, 1f + move a0, v0 + j ra + nop +1: + move t0, ra + bal 2f + nop +2: + .cpsetup ra, t1, 2b + LA t9,__set_errno_internal + .cpreturn + j t9 + move ra, t0 + .set pop +END(sethostname) diff --git a/libc/arch-x86/syscalls/sethostname.S b/libc/arch-x86/syscalls/sethostname.S new file mode 100644 index 0000000..bfcfd73 --- /dev/null +++ b/libc/arch-x86/syscalls/sethostname.S @@ -0,0 +1,26 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include <private/bionic_asm.h> + +ENTRY(sethostname) + pushl %ebx + .cfi_def_cfa_offset 8 + .cfi_rel_offset ebx, 0 + pushl %ecx + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset ecx, 0 + mov 12(%esp), %ebx + mov 16(%esp), %ecx + movl $__NR_sethostname, %eax + int $0x80 + cmpl $-MAX_ERRNO, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno_internal + addl $4, %esp +1: + popl %ecx + popl %ebx + ret +END(sethostname) diff --git a/libc/arch-x86_64/syscalls/sethostname.S b/libc/arch-x86_64/syscalls/sethostname.S new file mode 100644 index 0000000..4bcd12d --- /dev/null +++ b/libc/arch-x86_64/syscalls/sethostname.S @@ -0,0 +1,15 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include <private/bionic_asm.h> + +ENTRY(sethostname) + movl $__NR_sethostname, %eax + syscall + cmpq $-MAX_ERRNO, %rax + jb 1f + negl %eax + movl %eax, %edi + call __set_errno_internal +1: + ret +END(sethostname) diff --git a/libc/include/unistd.h b/libc/include/unistd.h index deac92b..dca9b3d 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -183,7 +183,8 @@ extern unsigned int alarm(unsigned int); extern unsigned int sleep(unsigned int); extern int usleep(useconds_t); -extern int gethostname(char *, size_t); +int gethostname(char*, size_t); +int sethostname(const char*, size_t); extern void *__brk(void *); extern int brk(void *); diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp index 7232ae2..38c8efa 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -470,3 +470,11 @@ class unistd_DeathTest : public BionicDeathTest {}; TEST_F(unistd_DeathTest, abort) { ASSERT_EXIT(abort(), testing::KilledBySignal(SIGABRT), ""); } + +TEST(unistd, sethostname) { + // The permissions check happens before the argument check, so this will + // fail for a different reason if you're running as root than if you're + // not, but it'll fail either way. Checking that we have the symbol is about + // all we can do for sethostname(2). + ASSERT_EQ(-1, sethostname("", -1)); +} |