shithub: drawcpu

Download patch

ref: 87e4f99c53687d25184d321ec6e57a75a8d45f03
parent: 543763a08d4652736766543fa1369dec622ac886
author: halfwit <michaelmisch1985@gmail.com>
date: Fri Mar 20 19:31:42 EDT 2026

Add in a bit more logging to try to fix the /bin/test failure

--- a/include/user.h
+++ b/include/user.h
@@ -36,6 +36,7 @@
 #define iounit	sysiounit
 #define getenv	sysgetenv
 
+extern  int await(char*, int);
 extern	int	bind(char*, char*, int);
 extern	int	chdir(char*);
 extern	int	close(int);
--- a/kern/arm.c
+++ b/kern/arm.c
@@ -4,6 +4,8 @@
 #include "fns.h"
 #include "proc.h"
 
+#include <execinfo.h>
+
 enum {
 	fI = 1<<25,  // Immediate bit 
 	fP = 1<<24,  // Pre/post indexing bit
@@ -34,6 +36,9 @@
 invalid(u32int instr, char *from)
 {
     print("%s: undefined instruction %.8ux @ %.8ux pid=%d source=%s\n", (char*)up->arg, instr, up->R[15] - 4, up->pid, from);
+    void *bt[32];
+    int n = backtrace(bt, 32);
+    backtrace_symbols_fd(bt, n, 2);
     pexit("invalid", 1);
 }
 
--- a/kern/posix.c
+++ b/kern/posix.c
@@ -23,6 +23,18 @@
 #include "fns.h"
 #include <a.out.h>
 
+#include <execinfo.h>
+
+static void
+sigsegv_handler(int sig)
+{
+    void *bt[32];
+    int n = backtrace(bt, 32);
+    backtrace_symbols_fd(bt, n, 2);
+    signal(SIGSEGV, SIG_DFL);
+    raise(SIGSEGV);
+}
+
 pthread_t thids[64];
 
 typedef struct Oproc Oproc;
@@ -59,6 +71,7 @@
 	if(pthread_key_create(&prdakey, 0))
 		panic("cannot pthread_key_create");
 
+	signal(SIGSEGV, sigsegv_handler);
 	signal(SIGPIPE, SIG_IGN);
 }
 
--- a/kern/seg.c
+++ b/kern/seg.c
@@ -76,9 +76,10 @@
 	Segment **s, *ss;
 
 	for(s = up->seg; s < up->seg + NSEG; s++) {
-		if(*s == nil)
-			continue;
 		ss = *s;
+		*s = nil;
+		if(ss == nil)
+			continue;
 		// Assure we don't have any weird state
 		if(!ss->dref || ss->dref->ref == 0 || ss->ref.ref != 0)
 			continue;
@@ -85,8 +86,7 @@
 		if(decref(ss->dref) == 0)
 			free(ss->dref);
 		if(decref(&ss->ref) == 0)
-			free(*s);
-		*s = nil;
+			free(ss);
 	}
 }
 
--- a/kern/syscall.c
+++ b/kern/syscall.c
@@ -617,25 +617,20 @@
 static void
 _sysawait(void)
 {
-	u32int p, n;
+	u32int s, n;
 	Waitmsg w;
-	char *pt;
-	int copied;
+	char *st;
+	int buffered;
 
-	p = arg(0);
+	s = arg(0);
 	n = arg(1);
-	pt = copyifnec(p, 1, &copied);
+	st = bufifnec(s, n, &buffered);
 #ifdef DSYSCALL
-	print("sysawait: pid=%d, n=%ux, pt=%s\n", up->pid, n, pt);
+	print("sysawait: pid=%d, n=%ux, pt=%s\n", up->pid, n, st);
 #endif
-	pwait(&w);
-	up->R[0] = (uintptr)snprint(pt, n, "%d %lud %lud %lud %q",
-		w.pid,
-	 	1000, 1000, 1000,
-		//w.time[TUser], w.time[TSys], w.time[TReal],
-		w.msg);
-	if(copied)
-		free(pt);
+	up->R[0] = noteerr(await(st, n), 0);
+	if(buffered)
+		copyback(s, up->R[0], st);
 }
 
 static void
--- a/kern/sysfile.c
+++ b/kern/sysfile.c
@@ -1039,6 +1039,19 @@
 }
 
 int
+sysawait(char *p, int n)
+{
+	Waitmsg w;
+
+	pwait(&w);
+	return (uintptr)snprint(p, n, "%d %lud %lud %lud %q",
+		w.pid,
+		1000, 1000, 1000,
+		w.msg
+	);
+}
+
+int
 sysunmount(char *old, char *new)
 {
 	int n;
--- a/kern/sysproc.c
+++ b/kern/sysproc.c
@@ -134,12 +134,12 @@
 {
     ulong tos, sp, ap, size, i, len;
     
-    tos = (USTKTOP & ~7) - sizeof(Tos) * 2;
+    tos = (USTKTOP & ~7) - sizeof(Tos);
 	((Tos *) vaddrnol(tos, sizeof(Tos)))->pid = up->pid;
 
     sp = tos;
 #ifdef DTRACE
-    print("initstack: tos=%.8ux tossz=%.8ux USTKTOP=%.8ux\n", tos, sizeof(Tos), USTKTOP);
+    print("initstack: tos=%.8ux tossz=%.8ux USTKTOP=%.8ux pid=%d\n", tos, sizeof(Tos), USTKTOP, up->pid);
 #endif
     size = 8;
     for(i = 0; i < argc; i++)
@@ -155,7 +155,7 @@
     sp += 4;
     ap = sp + (argc + 1) * 4;
 #ifdef DTRACE
-    print("initstack: argc=%d sp=%.8ux ap=%.8ux\n", argc, sp, ap);
+    print("initstack: argc=%d sp=%.8ux ap=%.8ux pid=%d\n", argc, sp, ap, up->pid);
 #endif
     for(i = 0; i < argc; i++) {
         *(ulong *) vaddrnol(sp, 4) = ap;
@@ -222,7 +222,7 @@
 int
 loadtext(char *file, int argc, char **argv)
 {
-    Segment *text, *data, *bss, *stack;
+    Segment *text, *data, *bss, *stack, *old;
     uvlong txtaddr, txtsz, dataddr, datsz, datoff, bsssz, hdrsz;
     Exec hdr;
 	char buf[2];
@@ -275,7 +275,7 @@
     initstack(argc, argv);
 
 #ifdef DTRACE
-    print("loadtext: PC=%.8ux, R1=%.8ux, R13=%.8ux\n", up->R[15], up->R[1], up->R[13]);
+    print("loadtext: PC=%.8ux, R1=%.8ux, R13=%.8ux, pid=%d\n", up->R[15], up->R[1], up->R[13], up->pid);
 #endif
     resetvfp();
     return 0;
--