mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 20:40:28 +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
|
@ -57,36 +57,36 @@ forceinline long double tau(void) {
|
|||
return pi() * 2;
|
||||
}
|
||||
|
||||
forceinline void sincosl(long double x, long double *sin, long double *cos) {
|
||||
forceinline void sincosl_(long double x, long double *sin, long double *cos) {
|
||||
asm("fsincos" : "=t"(*sin), "=u"(*cos) : "0"(x));
|
||||
}
|
||||
|
||||
forceinline long double atan2l(long double x, long double y) {
|
||||
forceinline long double atan2l_(long double x, long double y) {
|
||||
asm("fpatan" : "+t"(x) : "u"(y) : "st(1)");
|
||||
return x;
|
||||
}
|
||||
|
||||
forceinline long lrintl(long double x) {
|
||||
forceinline long lrintl_(long double x) {
|
||||
long i;
|
||||
asm("fistp%z0\t%0" : "=m"(i) : "t"(x) : "st");
|
||||
return i;
|
||||
}
|
||||
|
||||
forceinline long double truncl(long double x) {
|
||||
forceinline long double truncl_(long double x) {
|
||||
asm("frndint" : "+t"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
forceinline long double fabsl(long double x) {
|
||||
forceinline long double fabsl_(long double x) {
|
||||
asm("fabs" : "+t"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
forceinline long lroundl(long double x) {
|
||||
forceinline long lroundl_(long double x) {
|
||||
int s = signbit(x);
|
||||
x = truncl(fabsl(x) + .5);
|
||||
x = truncl_(fabsl_(x) + .5);
|
||||
if (s) x = -x;
|
||||
return lrintl(x);
|
||||
return lrintl_(x);
|
||||
}
|
||||
|
||||
static unsigned short GetFpuControlWord(void) {
|
||||
|
@ -111,13 +111,13 @@ static void spiral(unsigned char p[25][80][2], unsigned char B[25][80], int g) {
|
|||
int i, x, y;
|
||||
long double a, b, u, v, h;
|
||||
for (a = b = i = 0; i < 1000; ++i) {
|
||||
sincosl(a, &u, &v);
|
||||
h = atan2l(u, v) - .333L * g;
|
||||
x = lroundl(80 + u * b);
|
||||
y = lroundl(25 + v * b * (1. / ((266 / 64.) * (900 / 1600.))));
|
||||
sincosl_(a, &u, &v);
|
||||
h = atan2l_(u, v) - .333L * g;
|
||||
x = lroundl_(80 + u * b);
|
||||
y = lroundl_(25 + v * b * (1. / ((266 / 64.) * (900 / 1600.))));
|
||||
B[y >> 1][x >> 1] |= 1 << ((y & 1) << 1 | (x & 1));
|
||||
POKE(p[y >> 1][x >> 1][0], kBlocks[B[y >> 1][x >> 1]]);
|
||||
POKE(p[y >> 1][x >> 1][1], (lrintl((h + tau()) * (8 / tau())) & 7) + 8);
|
||||
POKE(p[y >> 1][x >> 1][1], (lrintl_((h + tau()) * (8 / tau())) & 7) + 8);
|
||||
a += .05;
|
||||
b += .05;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ Keywords={
|
|||
"textexit",
|
||||
"externinline",
|
||||
"dontinline",
|
||||
"noclone",
|
||||
"dontclone",
|
||||
"donothing",
|
||||
"printfesque",
|
||||
"flattenout",
|
||||
|
@ -102,7 +102,7 @@ Keywords={
|
|||
"forceinline",
|
||||
"nocallersavedregisters",
|
||||
"dontthrow",
|
||||
"nooptimize",
|
||||
"dontoptimize",
|
||||
"optimizesize",
|
||||
"optimizespeed",
|
||||
"alignof",
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
"forceinline"
|
||||
"nocallersavedregisters"
|
||||
"dontthrow"
|
||||
"nooptimize"
|
||||
"dontoptimize"
|
||||
"optimizesize"
|
||||
"optimizespeed"
|
||||
"alignof"
|
||||
|
|
|
@ -614,9 +614,8 @@
|
|||
((eq major-mode 'sh-mode)
|
||||
(compile (format "sh -c %s" file)))
|
||||
((eq major-mode 'lua-mode)
|
||||
(let* ((mode (cosmo--make-mode arg))
|
||||
(redbean ))
|
||||
(compile (format "make -j16 MODE=%s o/%s/tool/net/redbean.com && o/%s/tool/net/redbean.com -i %s" mode mode mode file))))
|
||||
(let* ((mode (cosmo--make-mode arg)))
|
||||
(compile (format "make -j16 MODE=%s o/%s/tool/net/redbean.com && build/run o/%s/tool/net/redbean.com -i %s" mode mode mode file))))
|
||||
((and (eq major-mode 'python-mode)
|
||||
(cosmo-startswith "third_party/python/Lib/test/" file))
|
||||
(let ((mode (cosmo--make-mode arg)))
|
||||
|
|
|
@ -349,7 +349,7 @@ cosmo_kws = frozenset([
|
|||
"dontinline",
|
||||
"noinstrument",
|
||||
"nointerpose",
|
||||
"nooptimize",
|
||||
"dontoptimize",
|
||||
"noprune",
|
||||
"wontreturn",
|
||||
"nosideeffect",
|
||||
|
@ -411,7 +411,7 @@ cosmo_kws = frozenset([
|
|||
"dontinline",
|
||||
"noinstrument",
|
||||
"nointerpose",
|
||||
"nooptimize",
|
||||
"dontoptimize",
|
||||
"noprune",
|
||||
"wontreturn",
|
||||
"nosideeffect",
|
||||
|
|
|
@ -1196,6 +1196,10 @@ function GetHost() end
|
|||
---@nodiscard
|
||||
function GetHostOs() end
|
||||
|
||||
---@return "X86_64"|"AARCH64"|"POWERPC64"|"S390X" isaname string that describes the host instruction set architecture
|
||||
---@nodiscard
|
||||
function GetHostIsa() end
|
||||
|
||||
---@param str string|integer monospace display width of string.
|
||||
--- This is useful for fixed-width formatting. For example, CJK characters
|
||||
--- typically take up two cells. This function takes into consideration combining
|
||||
|
|
|
@ -1202,6 +1202,15 @@ FUNCTIONS
|
|||
- `"FREEBSD"`
|
||||
- `"OPENBSD"`
|
||||
|
||||
GetHostIsa() → str
|
||||
Returns string describing host instruction set architecture.
|
||||
|
||||
This can return:
|
||||
|
||||
- `"X86_64"` for Intel and AMD systems
|
||||
- `"AARCH64"` for ARM64, M1, and Raspberry Pi systems
|
||||
- `"POWERPC64"` for OpenPOWER Raptor Computing Systems
|
||||
|
||||
GetMonospaceWidth(str|char) → int
|
||||
Returns monospace display width of string. This is useful for
|
||||
fixed-width formatting. For example, CJK characters typically take
|
||||
|
@ -4296,6 +4305,16 @@ UNIX MODULE
|
|||
OpenBSD should ignore the chown functions without crashing. Linux
|
||||
will just EPERM.
|
||||
|
||||
Root access isn't required. Support is limited to OpenBSD and Linux
|
||||
2.6.23+ (i.e. RHEL6 c. 2012) so long as Redbean is running directly
|
||||
on the host system, i.e. not running in a userspace emulator like
|
||||
Blink or Qemu. If your environment isn't supported, then pledge()
|
||||
will return 0 and do nothing, rather than raising ENOSYS, so the
|
||||
apps you share with others will err on the side of not breaking. If
|
||||
a functionality check is needed, please use `unix.pledge(nil, nil)`
|
||||
which is a no-op that will fail appropriately when the necessary
|
||||
system support isn't available to impose security restrictions.
|
||||
|
||||
`promises` is a string that may include any of the following groups
|
||||
delimited by spaces. This list has been curated to focus on the
|
||||
system calls for which this module provides wrappers. See the
|
||||
|
@ -4502,6 +4521,18 @@ UNIX MODULE
|
|||
This system call is supported natively on OpenBSD and polyfilled on
|
||||
Linux using the Landlock LSM[1].
|
||||
|
||||
This function requires OpenBSD or Linux 5.13+ (2022+). If the kernel
|
||||
support isn't available (or we're in an emulator like Qemu or Blink)
|
||||
then zero is returned and nothing happens (instead of raising
|
||||
ENOSYS) because the files are still unveiled. Use `unix.unveil("",
|
||||
nil)` to feature check the host system, which is defined as a no-op
|
||||
that'll fail if the host system doesn't have the necessary features
|
||||
that allow unix.unveil() impose bona-fide security restrictions.
|
||||
Otherwise, if everything is good, a return value `>=0` is returned,
|
||||
where `0` means OpenBSD, and `>=1` means Linux with Landlock LSM, in
|
||||
which case the return code shall be the maximum supported Landlock
|
||||
ABI version.
|
||||
|
||||
`path` is the file or directory to unveil
|
||||
|
||||
`permissions` is a string consisting of zero or more of the
|
||||
|
|
|
@ -213,6 +213,23 @@ int LuaGetHostOs(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int LuaGetHostIsa(lua_State *L) {
|
||||
const char *s;
|
||||
#ifdef __x86_64__
|
||||
s = "X86_64";
|
||||
#elif defined(__aarch64__)
|
||||
s = "AARCH64";
|
||||
#elif defined(__powerpc64__)
|
||||
s = "POWERPC64";
|
||||
#elif defined(__s390x__)
|
||||
s = "S390X";
|
||||
#else
|
||||
#error "unsupported architecture"
|
||||
#endif
|
||||
lua_pushstring(L, s);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaFormatIp(lua_State *L) {
|
||||
char b[16];
|
||||
uint32_t ip;
|
||||
|
|
|
@ -41,6 +41,7 @@ int LuaGetCpuCore(lua_State *);
|
|||
int LuaGetCpuCount(lua_State *);
|
||||
int LuaGetCpuNode(lua_State *);
|
||||
int LuaGetCryptoHash(lua_State *);
|
||||
int LuaGetHostIsa(lua_State *);
|
||||
int LuaGetHostOs(lua_State *);
|
||||
int LuaGetHttpReason(lua_State *);
|
||||
int LuaGetLogLevel(lua_State *);
|
||||
|
|
|
@ -1091,7 +1091,6 @@ static void UpdateLuaPath(const char *s) {
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void ProgramDirectory(const char *path) {
|
||||
char *s;
|
||||
size_t n;
|
||||
|
@ -5163,6 +5162,7 @@ static const luaL_Reg kLuaFuncs[] = {
|
|||
{"GetHeader", LuaGetHeader}, //
|
||||
{"GetHeaders", LuaGetHeaders}, //
|
||||
{"GetHost", LuaGetHost}, //
|
||||
{"GetHostIsa", LuaGetHostIsa}, //
|
||||
{"GetHostOs", LuaGetHostOs}, //
|
||||
{"GetHttpReason", LuaGetHttpReason}, //
|
||||
{"GetHttpVersion", LuaGetHttpVersion}, //
|
||||
|
@ -6905,6 +6905,7 @@ static int HandleConnection(size_t i) {
|
|||
}
|
||||
|
||||
static void MakeExecutableModifiable(void) {
|
||||
#ifdef __x86_64__
|
||||
int ft;
|
||||
size_t n;
|
||||
extern char ape_rom_vaddr[] __attribute__((__weak__));
|
||||
|
@ -6923,6 +6924,9 @@ static void MakeExecutableModifiable(void) {
|
|||
ftrace_install();
|
||||
ftrace_enabled(ft);
|
||||
}
|
||||
#else
|
||||
// TODO
|
||||
#endif
|
||||
}
|
||||
|
||||
static int HandleReadline(void) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue