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
This commit is contained in:
ceriel 1988-02-16 17:48:39 +00:00
parent 7bc8ed1270
commit d034f5145c
3 changed files with 45 additions and 18 deletions

View 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;

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

View 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
@ -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