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)
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)
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