Implement crash reporting for AARCH64

The ShowCrashReports() feature for aarch64 should work even better than
the x86 crash reports. Thanks to the benefit of hindsight these reports
should be rock solid reliable and beautiful to read.

This change also improves the syscall polyfills for aarch64. Some of the
sys_foo() functions have been removed, usually because they're legacy or
downright footguns not worth building.
This commit is contained in:
Justine Tunney 2023-05-12 05:47:54 -07:00
parent 285e8a2348
commit 1f2a5a8fc1
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
42 changed files with 540 additions and 247 deletions

View file

@ -255,11 +255,11 @@ static int Cd(void) {
if (!chdir(s)) {
return 0;
} else {
Log("chdir: ", s, ": ", _strerdoc(errno), 0);
Log("chdir: ", s, ": ", _strerdoc(errno), NULL);
return 1;
}
} else {
Log("chdir: missing argument", 0);
Log("chdir: missing argument", NULL);
return 1;
}
}
@ -270,7 +270,7 @@ static int Mkdir(void) {
if (n >= 3 && !strcmp(args[1], "-p")) ++i, f = makedirs;
for (; i < n; ++i) {
if (f(args[i], 0755)) {
Log("mkdir: ", args[i], ": ", _strerdoc(errno), 0);
Log("mkdir: ", args[i], ": ", _strerdoc(errno), NULL);
return errno;
}
}
@ -287,7 +287,7 @@ static int Kill(void) {
}
for (; i < n; ++i) {
if (kill(atoi(args[i]), sig)) {
Log("kill: ", args[i], ": ", _strerdoc(errno), 0);
Log("kill: ", args[i], ": ", _strerdoc(errno), NULL);
rc = 1;
}
}
@ -345,7 +345,7 @@ static int Rm(void) {
if (n > 1 && args[1][0] != '-') {
for (i = 1; i < n; ++i) {
if (unlink(args[i])) {
Log("rm: ", args[i], ": ", _strerdoc(errno), 0);
Log("rm: ", args[i], ": ", _strerdoc(errno), NULL);
return 1;
}
}
@ -360,7 +360,7 @@ static int Rmdir(void) {
if (n > 1 && args[1][0] != '-') {
for (i = 1; i < n; ++i) {
if (rmdir(args[i])) {
Log("rmdir: ", args[i], ": ", _strerdoc(errno), 0);
Log("rmdir: ", args[i], ": ", _strerdoc(errno), NULL);
return 1;
}
}
@ -375,7 +375,7 @@ static int Touch(void) {
if (n > 1 && args[1][0] != '-') {
for (i = 1; i < n; ++i) {
if (touch(args[i], 0644)) {
Log("touch: ", args[i], ": ", _strerdoc(errno), 0);
Log("touch: ", args[i], ": ", _strerdoc(errno), NULL);
return 1;
}
}

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/strace.internal.h"
@ -70,6 +71,7 @@ textstartup void cosmo(long *sp) {
// needed by kisdangerous()
__oldstack = (intptr_t)sp;
__pid = sys_getpid().ax;
// initialize mmap() manager extremely early
_mmi.n = ARRAYLEN(_mmi.s);

View file

@ -18,8 +18,11 @@
*/
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/sysv/consts/sig.h"
int sys_fork(void) {
#ifdef __x86_64__
axdx_t ad;
int ax, dx;
ad = __sys_fork();
@ -31,4 +34,26 @@ int sys_fork(void) {
ax &= dx - 1;
}
return ax;
#elif defined(__aarch64__)
int flags = 17; // SIGCHLD;
void *child_stack = 0;
void *parent_tidptr = 0;
void *newtls = 0;
void *child_tidptr = 0;
register long r0 asm("x0") = (long)flags;
register long r1 asm("x1") = (long)child_stack;
register long r2 asm("x2") = (long)parent_tidptr;
register long r3 asm("x3") = (long)newtls;
register long r4 asm("x4") = (long)child_tidptr;
register long res_x0 asm("x0");
asm volatile("mov\tx8,%1\n\t"
"svc\t0"
: "=r"(res_x0)
: "i"(220), "r"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4)
: "x8", "memory");
return _sysret(res_x0);
#endif
}

View file

@ -126,8 +126,11 @@ forceinline pureconst bool IsOldStackFrame(int x) {
/* openbsd uses 4mb stack by default */
/* freebsd uses 512mb stack by default */
/* most systems use 8mb stack by default */
intptr_t old = ROUNDDOWN(__oldstack, GetStackSize());
return (old >> 16) <= x && x <= ((old + (GetStackSize() - FRAMESIZE)) >> 16);
size_t foss_stack_size = 4ul * 1024 * 1024;
uintptr_t top = ROUNDUP(__oldstack, FRAMESIZE);
uintptr_t bot = top - foss_stack_size;
uintptr_t old = ROUNDDOWN(__oldstack, foss_stack_size);
return (int)(bot >> 16) <= x && x <= (int)((top >> 16) - 1);
}
forceinline pureconst bool IsFixedFrame(int x) {