malloc now allows users to use sbrk too,
authorceriel <none@none>
Tue, 16 Feb 1988 17:48:39 +0000 (17:48 +0000)
committerceriel <none@none>
Tue, 16 Feb 1988 17:48:39 +0000 (17:48 +0000)
setjmp/longjmp now save/restore the signal mask on BSD 4.2 systems,
some minor mods in atof

lang/cem/libcc/gen/atof.c
lang/cem/libcc/gen/malloc.c
lang/cem/libcc/gen/setjmp.e

index 5f6c649..8c2c302 100644 (file)
@@ -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;
index 11258c0..fd79993 100644 (file)
@@ -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)
index 2cd1b06..f913759 100644 (file)
@@ -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
 ; 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
  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
  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
  loc 1
 3
  ret EM_WSIZE
- end 2*EM_WSIZE
+ end 3*EM_WSIZE