mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Make improvements
This change progresses our AARCH64 support: - The AARCH64 build and tests are now passing - Add 128-bit floating-point support to printf() - Fix clone() so it initializes cosmo's x28 TLS register - Fix TLS memory layout issue with aarch64 _Alignas vars - Revamp microbenchmarking tools so they work on aarch64 - Make some subtle improvements to aarch64 crash reporting - Make kisdangerous() memory checks more accurate on aarch64 - Remove sys_open() since it's not available on Linux AARCH64 This change makes general improvements to Cosmo and Redbean: - Introduce GetHostIsa() function in Redbean - You can now feature check using pledge(0, 0) - You can now feature check using unveil("",0) - Refactor some more x86-specific asm comments - Refactor and write docs for some libm functions - Make the mmap() API behave more similar to Linux - Fix WIFSIGNALED() which wrongly returned true for zero - Rename some obscure cosmo keywords from noFOO to dontFOO
This commit is contained in:
parent
5655c9a4e7
commit
8f522cb702
116 changed files with 1194 additions and 1025 deletions
|
@ -25,6 +25,7 @@
|
|||
#include "libc/intrin/promises.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
|
@ -32,10 +33,11 @@
|
|||
#include "libc/testlib/subprocess.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
void SetUp(void) {
|
||||
if (!__is_linux_2_6_23() && !IsOpenbsd()) exit(0);
|
||||
if (pledge(0, 0) == -1) {
|
||||
fprintf(stderr, "warning: pledge() not supported on this system\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(pledge, testSoftError) {
|
||||
|
@ -116,5 +118,3 @@ TEST(pledge, testEmptyPledge_doesntUseTrapping) {
|
|||
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
TERMS(IsOpenbsd() ? SIGABRT : SIGSYS);
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -62,9 +62,6 @@
|
|||
#include "libc/time/time.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
// TODO(jart): Get pledge truly working on AARCH64
|
||||
#ifdef __x86_64__
|
||||
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
void OnSig(int sig) {
|
||||
|
@ -75,7 +72,10 @@ int sys_memfd_secret(unsigned int); // our ENOSYS threshold
|
|||
|
||||
void SetUp(void) {
|
||||
__enable_threads();
|
||||
if (!__is_linux_2_6_23() && !IsOpenbsd()) exit(0);
|
||||
if (pledge(0, 0) == -1) {
|
||||
fprintf(stderr, "warning: pledge() not supported on this system\n");
|
||||
exit(0);
|
||||
}
|
||||
testlib_extract("/zip/life.elf", "life.elf", 0755);
|
||||
testlib_extract("/zip/sock.elf", "sock.elf", 0755);
|
||||
__pledge_mode = PLEDGE_PENALTY_RETURN_EPERM;
|
||||
|
@ -659,5 +659,3 @@ BENCH(pledge, bench) {
|
|||
}
|
||||
wait(0);
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -45,28 +45,6 @@ TEST(read, eof) {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static long Read(long fd, void *buf, unsigned long size) {
|
||||
#ifdef __x86_64__
|
||||
long ax, di, si, dx;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ax), "=D"(di), "=S"(si), "=d"(dx)
|
||||
: "0"(__NR_read), "1"(fd), "2"(buf), "3"(size)
|
||||
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
|
||||
return ax;
|
||||
#elif defined(__aarch64__)
|
||||
register long r0 asm("x0") = (long)fd;
|
||||
register long r1 asm("x1") = (long)buf;
|
||||
register long r2 asm("x2") = (long)size;
|
||||
register long r8 asm("x8") = (long)__NR_read;
|
||||
register long res_x0 asm("x0");
|
||||
asm volatile("svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "r"(r0), "r"(r1), "r"(r2), "r"(r8)
|
||||
: "memory");
|
||||
return res_x0;
|
||||
#endif
|
||||
}
|
||||
|
||||
BENCH(read, bench) {
|
||||
char buf[16];
|
||||
ASSERT_SYS(0, 3, open("/dev/zero", O_RDONLY));
|
||||
|
@ -80,7 +58,5 @@ BENCH(read, bench) {
|
|||
preadv(3, (struct iovec[]){{buf, 1}, {buf + 1, 4}}, 2, 0));
|
||||
EZBENCH2("sys_read", donothing, sys_read(3, buf, 5));
|
||||
EZBENCH2("sys_readv", donothing, sys_readv(3, &(struct iovec){buf, 5}, 1));
|
||||
EZBENCH2("Read", donothing, Read(3, buf, 5));
|
||||
EZBENCH2("Read", donothing, Read(3, buf, 5));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
|
|
@ -118,25 +118,20 @@ o/$(MODE)/test/libc/calls/ioctl_siocgifconf_test.com.runs: \
|
|||
o/$(MODE)/test/libc/calls/poll_test.com.runs: \
|
||||
private .PLEDGE = stdio rpath wpath cpath fattr proc inet
|
||||
|
||||
o/$(MODE)/test/libc/calls/fcntl_test.com.runs: \
|
||||
private .PLEDGE = stdio rpath wpath cpath fattr proc flock
|
||||
|
||||
o/$(MODE)/test/libc/calls/lock_test.com.runs: \
|
||||
private .PLEDGE = stdio rpath wpath cpath fattr proc flock
|
||||
|
||||
o/$(MODE)/test/libc/calls/lock2_test.com.runs: \
|
||||
private .PLEDGE = stdio rpath wpath cpath fattr proc flock
|
||||
|
||||
o/$(MODE)/test/libc/calls/fcntl_test.com.runs \
|
||||
o/$(MODE)/test/libc/calls/lock_test.com.runs \
|
||||
o/$(MODE)/test/libc/calls/lock2_test.com.runs \
|
||||
o/$(MODE)/test/libc/calls/lock_ofd_test.com.runs: \
|
||||
private .PLEDGE = stdio rpath wpath cpath fattr proc flock
|
||||
|
||||
o/$(MODE)/test/libc/calls/unveil_test.com.runs \
|
||||
o/$(MODE)/test/libc/calls/openbsd_test.com.runs: \
|
||||
private .PLEDGE = stdio rpath wpath cpath fattr proc unveil
|
||||
|
||||
o/$(MODE)/test/libc/calls/fexecve_test.com.runs: \
|
||||
private .UNSANDBOXED = 1 # for memfd_create()
|
||||
|
||||
o/$(MODE)/test/libc/calls/execve_test.com.runs: \
|
||||
o/$(MODE)/test/libc/calls/execve_test.com.runs: \
|
||||
private .UNSANDBOXED = 1 # for memfd_create()
|
||||
|
||||
o/$(MODE)/test/libc/calls/read_test.com.runs: \
|
||||
|
|
|
@ -51,16 +51,21 @@ char testlib_enable_tmp_setup_teardown;
|
|||
|
||||
struct stat st;
|
||||
|
||||
static bool SupportsLandlock(void) {
|
||||
int e = errno;
|
||||
bool r = landlock_create_ruleset(0, 0, LANDLOCK_CREATE_RULESET_VERSION) >= 0;
|
||||
errno = e;
|
||||
return r;
|
||||
bool HasUnveilSupport(void) {
|
||||
return unveil("", 0) >= 0;
|
||||
}
|
||||
|
||||
bool UnveilCanSecureTruncate(void) {
|
||||
int abi = unveil("", 0);
|
||||
return abi == 0 || abi >= 3;
|
||||
}
|
||||
|
||||
void SetUpOnce(void) {
|
||||
__enable_threads();
|
||||
if (!(IsLinux() && SupportsLandlock()) && !IsOpenbsd()) exit(0);
|
||||
if (!HasUnveilSupport()) {
|
||||
fprintf(stderr, "warning: unveil() not supported on this system: %m\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp(void) {
|
||||
|
@ -68,10 +73,6 @@ void SetUp(void) {
|
|||
ASSERT_SYS(0, 0, stat("/zip/life.elf", &st));
|
||||
}
|
||||
|
||||
bool HasTruncateSupport(void) {
|
||||
return IsOpenbsd() || landlock_create_ruleset(0, 0, LANDLOCK_CREATE_RULESET_VERSION) >= 3;
|
||||
}
|
||||
|
||||
TEST(unveil, api_differences) {
|
||||
SPAWN(fork);
|
||||
ASSERT_SYS(0, 0, mkdir("foo", 0755));
|
||||
|
@ -249,7 +250,7 @@ TEST(unveil, truncate_isForbiddenBySeccomp) {
|
|||
ASSERT_SYS(0, 0, xbarf("garden/secret.txt", "hello", 5));
|
||||
ASSERT_SYS(0, 0, unveil("jail", "rw"));
|
||||
ASSERT_SYS(0, 0, unveil(0, 0));
|
||||
ASSERT_SYS(!HasTruncateSupport() ? EPERM : EACCES_OR_ENOENT, -1,
|
||||
ASSERT_SYS(!UnveilCanSecureTruncate() ? EPERM : EACCES_OR_ENOENT, -1,
|
||||
truncate("garden/secret.txt", 0));
|
||||
if (IsLinux()) {
|
||||
ASSERT_SYS(0, 0, stat("garden/secret.txt", &st));
|
||||
|
|
|
@ -96,30 +96,6 @@ TEST(write, rlimitFsizeExceeded_raisesEfbig) {
|
|||
EXITS(0);
|
||||
}
|
||||
|
||||
static long Write(long fd, const void *data, unsigned long size) {
|
||||
#ifdef __x86_64__
|
||||
long ax, di, si, dx;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ax), "=D"(di), "=S"(si), "=d"(dx)
|
||||
: "0"(__NR_write), "1"(fd), "2"(data), "3"(size)
|
||||
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
|
||||
return ax;
|
||||
#elif defined(__aarch64__)
|
||||
register long r0 asm("x0") = (long)fd;
|
||||
register long r1 asm("x1") = (long)data;
|
||||
register long r2 asm("x2") = (long)size;
|
||||
register long r8 asm("x8") = (long)__NR_write;
|
||||
register long res_x0 asm("x0");
|
||||
asm volatile("svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "r"(r0), "r"(r1), "r"(r2), "r"(r8)
|
||||
: "memory");
|
||||
return res_x0;
|
||||
#else
|
||||
#error "unsupported architecture"
|
||||
#endif
|
||||
}
|
||||
|
||||
BENCH(write, bench) {
|
||||
ASSERT_SYS(0, 3, open("/dev/null", O_WRONLY));
|
||||
EZBENCH2("write", donothing, write(3, "hello", 5));
|
||||
|
@ -127,7 +103,5 @@ BENCH(write, bench) {
|
|||
EZBENCH2("sys_write", donothing, sys_write(3, "hello", 5));
|
||||
EZBENCH2("sys_writev", donothing,
|
||||
sys_writev(3, &(struct iovec){"hello", 5}, 1));
|
||||
EZBENCH2("Write", donothing, Write(3, "hello", 5));
|
||||
EZBENCH2("Write", donothing, Write(3, "hello", 5));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue