From d034f5145c6a44dd2760f7a7d987a0db4648e815 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 16 Feb 1988 17:48:39 +0000 Subject: [PATCH] malloc now allows users to use sbrk too, setjmp/longjmp now save/restore the signal mask on BSD 4.2 systems, some minor mods in atof --- lang/cem/libcc/gen/atof.c | 4 ++-- lang/cem/libcc/gen/malloc.c | 37 +++++++++++++++++++++++++------------ lang/cem/libcc/gen/setjmp.e | 22 ++++++++++++++++++---- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/lang/cem/libcc/gen/atof.c b/lang/cem/libcc/gen/atof.c index 5f6c6494c..8c2c3029a 100644 --- a/lang/cem/libcc/gen/atof.c +++ b/lang/cem/libcc/gen/atof.c @@ -62,8 +62,8 @@ atof(p) if (exp != 0) { int oldexp = exp; - double exp5 = 5; - double correction = 1; + double exp5 = 5.0; + double correction = 1.0; while (exp) { if (exp % 2) correction *= exp5; diff --git a/lang/cem/libcc/gen/malloc.c b/lang/cem/libcc/gen/malloc.c index 11258c004..fd799932a 100644 --- a/lang/cem/libcc/gen/malloc.c +++ b/lang/cem/libcc/gen/malloc.c @@ -27,19 +27,29 @@ unsigned len; register char *p; register int click = CLICK_SIZE; + p = sbrk(0); + len += (char *) ALIGN((vir_bytes) p, sizeof(char *)) - p; while (click >= 4) { - p = (char *) ALIGN((vir_bytes) top + sizeof(char *) + len, click) - + BUGFIX; - if (p > top && brk(p - BUGFIX) >= 0) break; - click >>= 1; + unsigned len1 = ALIGN((vir_bytes) p + len + sizeof(char *), click) - (vir_bytes) p; + char *p1 = p; + if (p + len1 + BUGFIX < p || (p1 = sbrk(len1)) == (char *) -1) { + click >>= 1; + continue; + } + p = p1; + if (top + sizeof(char *) != p) { + /* someone else has done an sbrk */ + NEXT(top) = (char *) ((vir_bytes) p | BUSY); + } else { + for (p = bottom; NEXT(p) != 0; p = (char *) (* (vir_bytes *) p & ~BUSY)) + ; + } + top = p + len1 - sizeof(char *); + NEXT(p) = top; + NEXT(top) = 0; + return 1; } - if (click < 4) return(0); - top = p - (BUGFIX + sizeof(char *)); - for (p = bottom; NEXT(p) != 0; p = (char *) (* (vir_bytes *) p & ~BUSY)) - ; - NEXT(p) = top; - NEXT(top) = 0; - return(1); + return 0; } char *malloc(size) @@ -49,7 +59,10 @@ unsigned size; register unsigned len = ALIGN(size, sizeof(char *)) + sizeof(char *); if ((p = bottom) == 0) { - top = bottom = p = sbrk(sizeof(char *)); + p = sbrk(sizeof(char *)); + sbrk((char *) ALIGN((vir_bytes) p, sizeof(char *)) - p); + p = (char *) ALIGN((vir_bytes) p, sizeof(char *)); + top = bottom = p; NEXT(p) = 0; } while ((next = NEXT(p)) != 0) diff --git a/lang/cem/libcc/gen/setjmp.e b/lang/cem/libcc/gen/setjmp.e index 2cd1b063d..f9137590b 100644 --- a/lang/cem/libcc/gen/setjmp.e +++ b/lang/cem/libcc/gen/setjmp.e @@ -2,7 +2,7 @@ mes 2,EM_WSIZE,EM_PSIZE exp $setjmp - pro $setjmp,2*EM_WSIZE + pro $setjmp,3*EM_WSIZE ; setjmp saves the StackPointer and the LocalBase, and the chunk of ; memory between the StackPointer and the ArgumentBase, + its size in a @@ -20,6 +20,13 @@ ; setjmp does not have register variables, and that it saves all registers ; that are available for variables. +#ifdef __BSD4_2 + loc 0 + cal $sigblock + asp EM_WSIZE + lfr EM_WSIZE + stl -3*EM_WSIZE +#endif loc 0 stl -2*EM_WSIZE lor 1 ; load StackPointer @@ -65,10 +72,10 @@ bls EM_WSIZE ; block copy loc 0 ret EM_WSIZE - end 2*EM_WSIZE + end 3*EM_WSIZE exp $longjmp - pro $longjmp,2*EM_WSIZE + pro $longjmp,3*EM_WSIZE ; first, find out wether the stack grows upwards loc 0 @@ -136,6 +143,13 @@ str 0 ; restore LocalBase stl -EM_WSIZE ; saves the return value str 1 ; restores the StackPointer +#ifdef __BSD4_2 + lol -3*EM_WSIZE + cal $sigsetmask + asp EM_WSIZE + lfr EM_WSIZE + asp EM_WSIZE +#endif lol -EM_WSIZE dup EM_WSIZE zne *3 @@ -144,4 +158,4 @@ loc 1 3 ret EM_WSIZE - end 2*EM_WSIZE + end 3*EM_WSIZE -- 2.34.1