summaryrefslogtreecommitdiff
path: root/sys/src/cmd/cc
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-04-11 14:19:35 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2020-04-11 14:19:35 +0200
commitca9d65e40b3f78d2580fff9ff1844bad1be08673 (patch)
treea82f5577a3e5e93ea8b2865916f270ac1b41f81b /sys/src/cmd/cc
parent49c159b50f113fe0c61cc841c14a6fc664f87b49 (diff)
cc: remove mysbrk(), exponentially increase gethunk() allocation delta
mysbrk() was only used in gethunk() and should not be called by anyone, so dont export the symbol. simplify gethunk() using brk(). double allocation size on each call until we reach 1000*NHUNK. use signed long for nhunk as alignment rountin might make it negative and handle that case.
Diffstat (limited to 'sys/src/cmd/cc')
-rw-r--r--sys/src/cmd/cc/compat36
-rw-r--r--sys/src/cmd/cc/compat.h3
2 files changed, 20 insertions, 19 deletions
diff --git a/sys/src/cmd/cc/compat b/sys/src/cmd/cc/compat
index df59f0c98..7a9eafa0f 100644
--- a/sys/src/cmd/cc/compat
+++ b/sys/src/cmd/cc/compat
@@ -4,12 +4,6 @@ myaccess(char *f)
return access(f, AEXIST);
}
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
int
mycreat(char *n, int p)
{
@@ -77,27 +71,35 @@ myfork(void)
return fork();
}
+
/*
* real allocs
*/
+
+extern char end[];
+
+char* hunk = end;
+long nhunk;
+uintptr thunk;
+
void
gethunk(void)
{
- char *h;
- ulong nh;
+ long nh;
- nh = NHUNK;
- if(thunk >= 10L*NHUNK)
- nh = 10L*NHUNK;
- h = (char*)mysbrk(nh);
- if(h == (char*)-1)
- sysfatal("out of memory");
- if(nhunk == 0)
- hunk = h;
+ if(thunk < NHUNK)
+ nh = NHUNK;
+ else if(thunk < 1000*NHUNK)
+ nh = thunk;
else
- nh += (h - hunk) - nhunk;
+ nh = 1000*NHUNK;
+
+ if(nhunk < 0)
+ nhunk = 0;
nhunk += nh;
thunk += nh;
+ if(brk(hunk+nhunk) < 0)
+ sysfatal("out of memory");
}
void*
diff --git a/sys/src/cmd/cc/compat.h b/sys/src/cmd/cc/compat.h
index 9f056e36a..d7f3112b5 100644
--- a/sys/src/cmd/cc/compat.h
+++ b/sys/src/cmd/cc/compat.h
@@ -23,12 +23,11 @@ EXTERN int myexec(char*, char*[]);
EXTERN int mydup(int, int);
EXTERN int myfork(void);
EXTERN int mypipe(int*);
-EXTERN void* mysbrk(ulong);
EXTERN void gethunk(void);
EXTERN char* hunk;
-EXTERN uintptr nhunk;
+EXTERN long nhunk;
EXTERN uintptr thunk;
EXTERN void* alloc(long n);