From 76ad8e974fefb4588b0a318f6502fde6bd730097 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Wed, 10 Aug 2022 06:37:21 -0400 Subject: [PATCH] avoid user-level segfault if a process doesn't call exit() --- Makefile | 2 +- user/ulib.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 330f440..6f0f40e 100644 --- a/Makefile +++ b/Makefile @@ -90,7 +90,7 @@ tags: $(OBJS) _init ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o _%: %.o $(ULIB) - $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^ + $(LD) $(LDFLAGS) -N -e _main -Ttext 0 -o $@ $^ $(OBJDUMP) -S $@ > $*.asm $(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym diff --git a/user/ulib.c b/user/ulib.c index 4775939..c7b66c4 100644 --- a/user/ulib.c +++ b/user/ulib.c @@ -3,6 +3,17 @@ #include "kernel/fcntl.h" #include "user/user.h" +// +// wrapper so that it's OK if main() does not call exit(). +// +void +_main() +{ + extern int main(); + main(); + exit(0); +} + char* strcpy(char *s, const char *t) {