mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Introduce native support for MacOS ARM64
There's a new program named ape/ape-m1.c which will be used to build an embeddable binary that can load ape and elf executables. The support is mostly working so far, but still chasing down ABI issues.
This commit is contained in:
parent
b852650c08
commit
1422e96b4e
757 changed files with 2988 additions and 1321 deletions
|
@ -17,10 +17,12 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/subprocess.h"
|
||||
|
@ -58,12 +60,14 @@ TEST(execve, testArgPassing) {
|
|||
execve(GetProgramExecutableName(),
|
||||
(char *const[]){GetProgramExecutableName(), "-", ibuf, buf, 0},
|
||||
(char *const[]){0});
|
||||
notpossible;
|
||||
kprintf("execve failed: %m\n");
|
||||
EXITS(0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(execve, ziposELF) {
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (!__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (!IsLinux() && !IsFreebsd()) {
|
||||
EXPECT_SYS(ENOSYS, -1,
|
||||
execve("/zip/life.elf", (char *const[]){0}, (char *const[]){0}));
|
||||
|
@ -71,11 +75,13 @@ TEST(execve, ziposELF) {
|
|||
}
|
||||
SPAWN(fork);
|
||||
execve("/zip/life.elf", (char *const[]){0}, (char *const[]){0});
|
||||
notpossible;
|
||||
kprintf("execve failed: %m\n");
|
||||
EXITS(42);
|
||||
}
|
||||
|
||||
TEST(execve, ziposAPE) {
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (!__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (!IsLinux() && !IsFreebsd()) {
|
||||
EXPECT_EQ(-1, execve("/zip/life-nomod.com", (char *const[]){0},
|
||||
(char *const[]){0}));
|
||||
|
@ -83,7 +89,7 @@ TEST(execve, ziposAPE) {
|
|||
}
|
||||
SPAWN(fork);
|
||||
execve("/zip/life-nomod.com", (char *const[]){0}, (char *const[]){0});
|
||||
notpossible;
|
||||
kprintf("execve failed: %m\n");
|
||||
EXITS(42);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ void OnSig(int sig) {
|
|||
|
||||
TEST(posixAdvisoryLocks, twoProcesses) {
|
||||
if (IsWindows()) return; // due to signals
|
||||
if (IsNetbsd()) return; // TODO: why does sigusr1 kill runitd?
|
||||
|
||||
int ws, pid;
|
||||
struct flock lock;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -35,6 +36,11 @@ int fds[2];
|
|||
char buf[8];
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
void SetUp(void) {
|
||||
if (IsFreebsd()) exit(0); // TODO: fixme on freebsd
|
||||
if (!__is_linux_2_6_23()) exit(0); // TODO: fixme on old linux
|
||||
}
|
||||
|
||||
TEST(execve, elfIsUnreadable_mayBeExecuted) {
|
||||
if (IsWindows() || IsXnu()) return;
|
||||
testlib_extract("/zip/echo", "echo", 0111);
|
||||
|
|
|
@ -33,6 +33,9 @@ void SetUp(void) {
|
|||
if (!IsLinux() && !IsFreebsd() && !IsWindows()) {
|
||||
exit(0);
|
||||
}
|
||||
if (IsFreebsd() && getuid() != 0) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(sched_getaffinity, firstOnly) {
|
||||
|
|
|
@ -123,6 +123,7 @@ TEST(setrlimit, testMemoryLimit) {
|
|||
char *p;
|
||||
bool gotsome;
|
||||
int i, wstatus;
|
||||
if (IsXnu()) return;
|
||||
if (IsAsan()) return; /* b/c we use sys_mmap */
|
||||
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
||||
if (wstatus == -2) {
|
||||
|
|
|
@ -69,6 +69,7 @@ TEST(sigaction, raise) {
|
|||
// test kill()
|
||||
|
||||
TEST(sigaction, testPingPongParentChildWithSigint) {
|
||||
if (IsNetbsd()) return; // TODO: what's up with runitd on netbsd?
|
||||
int pid, status;
|
||||
sigset_t blockint, oldmask;
|
||||
struct sigaction oldint;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
35
test/libc/intrin/fmax_test.c
Normal file
35
test/libc/intrin/fmax_test.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "third_party/libcxx/math.h"
|
||||
|
||||
TEST(fmax, test) {
|
||||
EXPECT_TRUE(fmax(2., 3.) == 3.);
|
||||
EXPECT_TRUE(fmax(3., 2.) == 3.);
|
||||
EXPECT_TRUE(fmax(NAN, 3.) == 3.);
|
||||
EXPECT_TRUE(fmax(NAN, -3.) == -3.);
|
||||
EXPECT_TRUE(fmax(-NAN, 3.) == 3.);
|
||||
EXPECT_TRUE(fmax(-NAN, -3.) == -3.);
|
||||
EXPECT_TRUE(fmax(3., NAN) == 3.);
|
||||
EXPECT_TRUE(fmax(-3., NAN) == -3.);
|
||||
EXPECT_TRUE(fmax(3., -NAN) == 3.);
|
||||
EXPECT_TRUE(fmax(-3., -NAN) == -3.);
|
||||
EXPECT_TRUE(fmax(-0., +0.) == +0.);
|
||||
EXPECT_TRUE(fmax(+0., -0.) == +0.);
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/linux/mmap.h"
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/dce.h"
|
||||
|
@ -77,7 +78,7 @@ TEST(mmap, outOfAutomapRange) {
|
|||
|
||||
TEST(mmap, noreplaceImage) {
|
||||
ASSERT_SYS(EEXIST, MAP_FAILED,
|
||||
mmap(_base, FRAMESIZE, PROT_READ,
|
||||
mmap(__executable_start, FRAMESIZE, PROT_READ,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED_NOREPLACE, -1, 0));
|
||||
}
|
||||
|
||||
|
|
|
@ -243,8 +243,8 @@ uint64_t MobyDick(void) {
|
|||
|
||||
uint64_t ExecutableImage(void) {
|
||||
static int i;
|
||||
if ((i += 8) > _end - _base) i = 8;
|
||||
return READ64LE(_base + i);
|
||||
if ((i += 8) > _end - __executable_start) i = 8;
|
||||
return READ64LE(__executable_start + i);
|
||||
}
|
||||
|
||||
uint32_t SeventhEditionRand(void) {
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(strlcpy, testEmptyBuffer_doesNothing) {
|
||||
|
@ -34,3 +37,11 @@ TEST(strlcpy, testShortBuffer_copies) {
|
|||
EXPECT_EQ(5, strlcpy(buf, "hello", 2));
|
||||
EXPECT_STREQ("h", buf);
|
||||
}
|
||||
|
||||
BENCH(strlcpy, bench) {
|
||||
char buf[256];
|
||||
EZBENCH2("strlcpy", donothing,
|
||||
EXPROPRIATE(strlcpy(VEIL("r", buf), "hello there", sizeof(buf))));
|
||||
EZBENCH2("strncpy", donothing,
|
||||
EXPROPRIATE(strncpy(VEIL("r", buf), "hello there", sizeof(buf))));
|
||||
}
|
||||
|
|
|
@ -17,9 +17,13 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/magicu.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/tinymath/magicu.h"
|
||||
|
||||
#define T uint32_t
|
||||
#define TBIT (sizeof(T) * CHAR_BIT - 1)
|
||||
|
@ -43,10 +47,10 @@ TEST(magicu, test) {
|
|||
}
|
||||
}
|
||||
|
||||
BENCH(cog, bench) {
|
||||
struct magicu d = __magicu_get(7);
|
||||
EZBENCH2("__magicu_get", donothing, __magicu_get(VEIL("r", 77)));
|
||||
BENCH(magicu, bench) {
|
||||
struct magicu d = __magicu_get(UINT32_MAX);
|
||||
EZBENCH2("__magicu_get", donothing, __magicu_get(VEIL("r", UINT32_MAX)));
|
||||
EZBENCH2("__magicu_div", donothing,
|
||||
EXPROPRIATE(__magicu_div(VEIL("r", 77), d)));
|
||||
EZBENCH2("/", donothing, EXPROPRIATE(VEIL("r", 77) / VEIL("r", 7)));
|
||||
EXPROPRIATE(__magicu_div(VEIL("r", 77u), d)));
|
||||
EZBENCH2("/", donothing, EXPROPRIATE(VEIL("r", 77u) / VEIL("r", UINT32_MAX)));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue