ref: 1b8a56941708e6fe884f4649f718fae7c543c045
parent: 9d46360c9d83fa95f42f1eebbad49ecd9281fb0d
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Apr 11 01:03:49 EDT 2020
cc, ?[acl]: fix gethunk() and move common memory allocator code to cc/compat for gethunk() to work, all allocators have to use it, including allocations done by libc thru malloc(), so the fake allocation functions are mandatory for everyone. to avoid duplication the code is moved to cc/compat and prototypes provided in new cc/compat.h header.
--- a/sys/src/cmd/1a/a.h
+++ b/sys/src/cmd/1a/a.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../2c/2.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Sym Sym;
typedef struct Ref Ref;
typedef struct Gen Gen;
@@ -113,7 +110,6 @@
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
-EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -120,7 +116,6 @@
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@@ -132,11 +127,9 @@
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
-EXTERN uintptr thunk;
EXTERN Biobuf obuf;
int assemble(char*);
-void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@@ -172,28 +165,7 @@
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
-void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
-
-/*
- * system-dependent stuff from ../cc/compat.c
- */
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2,
-};
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-char* mygetwd(char*, int);
-int myexec(char*, char*[]);
-int mydup(int, int);
-int myfork(void);
-int mypipe(int*);
-void* mysbrk(ulong);
--- a/sys/src/cmd/1a/mkfile
+++ b/sys/src/cmd/1a/mkfile
@@ -7,6 +7,7 @@
HFILES=\
../2c/2.out.h\
+ ../cc/compat.h\
y.tab.h\
a.h\
--- a/sys/src/cmd/1c/mkfile
+++ b/sys/src/cmd/1c/mkfile
@@ -15,6 +15,7 @@
HFILES=\
gc.h\
../2c/2.out.h\
+ ../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O
--- a/sys/src/cmd/1l/compat.c
+++ b/sys/src/cmd/1l/compat.c
@@ -1,56 +1,2 @@
#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void *p, ulong n)
-{
- fprint(2, "realloc(0x%p %ld) called\n", p, n);
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
- USED(v, pc);
-}
+#include "../cc/compat"
--- a/sys/src/cmd/1l/l.h
+++ b/sys/src/cmd/1l/l.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../2c/2.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
#define P ((Prog*)0)
#define S ((Sym*)0)
#define TNAME (curtext?curtext->from.sym->name:noname)
@@ -178,7 +175,6 @@
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
-EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@@ -187,7 +183,6 @@
EXTERN long relocsize;
EXTERN long ndata;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN long nsymbol;
EXTERN char* noname;
EXTERN short* op;
@@ -200,7 +195,6 @@
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
-EXTERN uintptr thunk;
EXTERN int version;
EXTERN Prog zprg;
@@ -240,7 +234,6 @@
int find1(long, int);
int find2(long, int);
void follow(void);
-void gethunk(void);
int gnuxi(Ieee*, int, int);
void histtoauto(void);
double ieeedtod(Ieee*);
@@ -254,7 +247,6 @@
void lput(long);
void main(int, char*[]);
void mkfwd(void);
-void* mysbrk(ulong);
void nuxiinit(void);
void objfile(char*);
void patch(void);
--- a/sys/src/cmd/1l/mkfile
+++ b/sys/src/cmd/1l/mkfile
@@ -14,6 +14,7 @@
HFILES=\
l.h\
../2c/2.out.h\
+ ../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@@ -20,3 +21,5 @@
enam.$O: ../2c/enam.c
$CC $CFLAGS ../2c/enam.c
+
+compat.$O: ../cc/compat
--- a/sys/src/cmd/1l/obj.c
+++ b/sys/src/cmd/1l/obj.c
@@ -1083,28 +1083,6 @@
}
void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(thunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(thunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char*)-1) {
- diag("out of memory");
- errorexit();
- }
- hunk = h;
- nhunk = nh;
- thunk += nh;
-}
-
-void
doprof1(void)
{
Sym *s;
--- a/sys/src/cmd/2a/a.h
+++ b/sys/src/cmd/2a/a.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../2c/2.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Sym Sym;
typedef struct Ref Ref;
typedef struct Gen Gen;
@@ -115,7 +112,6 @@
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
-EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -122,7 +118,6 @@
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@@ -134,10 +129,8 @@
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
-EXTERN uintptr thunk;
EXTERN Biobuf obuf;
-void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@@ -173,29 +166,7 @@
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
-void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
-
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2
-};
-
-/*
- * system-dependent stuff from ../cc/compat.c
- */
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-char* mygetwd(char*, int);
-int myexec(char*, char*[]);
-int mydup(int, int);
-int myfork(void);
-int mypipe(int*);
-void* mysbrk(ulong);
--- a/sys/src/cmd/2a/mkfile
+++ b/sys/src/cmd/2a/mkfile
@@ -7,6 +7,7 @@
HFILES=\
../2c/2.out.h\
+ ../cc/compat.h\
y.tab.h\
a.h\
--- a/sys/src/cmd/2c/mkfile
+++ b/sys/src/cmd/2c/mkfile
@@ -15,6 +15,7 @@
HFILES=\
gc.h\
2.out.h\
+ ../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O
--- a/sys/src/cmd/2l/compat.c
+++ b/sys/src/cmd/2l/compat.c
@@ -1,56 +1,2 @@
#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void *p, ulong n)
-{
- fprint(2, "realloc(0x%p %ld) called\n", p, n);
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
- USED(v, pc);
-}
+#include "../cc/compat"
--- a/sys/src/cmd/2l/l.h
+++ b/sys/src/cmd/2l/l.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../2c/2.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
#define P ((Prog*)0)
#define S ((Sym*)0)
#define TNAME (curtext?curtext->from.sym->name:noname)
@@ -168,7 +165,6 @@
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
-EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@@ -177,7 +173,6 @@
EXTERN long ncase;
EXTERN long ndata;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN long nsymbol;
EXTERN char* noname;
EXTERN short* op;
@@ -190,7 +185,6 @@
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
-EXTERN uintptr thunk;
EXTERN int version;
EXTERN Prog zprg;
@@ -238,7 +232,6 @@
int find1(long, int);
int find2(long, int);
void follow(void);
-void gethunk(void);
int gnuxi(Ieee*, int, int);
void histtoauto(void);
double ieeedtod(Ieee*);
@@ -250,7 +243,6 @@
void lput(long);
void main(int, char*[]);
void mkfwd(void);
-void* mysbrk(ulong);
void nuxiinit(void);
void objfile(char*);
void patch(void);
--- a/sys/src/cmd/2l/mkfile
+++ b/sys/src/cmd/2l/mkfile
@@ -14,6 +14,7 @@
HFILES=\
l.h\
../2c/2.out.h\
+ ../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@@ -20,3 +21,5 @@
enam.$O: ../2c/enam.c
$CC $CFLAGS ../2c/enam.c
+
+compat.$O: ../cc/compat
--- a/sys/src/cmd/2l/obj.c
+++ b/sys/src/cmd/2l/obj.c
@@ -1105,28 +1105,6 @@
}
void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(thunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(thunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char*)-1) {
- diag("out of memory");
- errorexit();
- }
- hunk = h;
- nhunk = nh;
- thunk += nh;
-}
-
-void
doprof1(void)
{
Sym *s;
--- a/sys/src/cmd/5a/a.h
+++ b/sys/src/cmd/5a/a.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../5c/5.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Sym Sym;
typedef struct Gen Gen;
typedef struct Io Io;
@@ -96,7 +93,6 @@
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
-EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -103,7 +99,6 @@
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@@ -115,11 +110,8 @@
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
-EXTERN uintptr thunk;
EXTERN Biobuf obuf;
-void* alloc(long);
-void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@@ -160,20 +152,3 @@
int yyparse(void);
void setinclude(char*);
int assemble(char*);
-
-/*
- * system-dependent stuff from ../cc/compat.c
- */
-
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2,
-};
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-int myfork(void);
-void* mysbrk(ulong);
--- a/sys/src/cmd/5a/mkfile
+++ b/sys/src/cmd/5a/mkfile
@@ -7,6 +7,7 @@
HFILES=\
../5c/5.out.h\
+ ../cc/compat.h\
y.tab.h\
a.h\
@@ -16,4 +17,4 @@
< /sys/src/cmd/mkone
YFLAGS=-D1 -d
-lex.$O: ../cc/macbody ../cc/lexbody
+lex.$O: ../cc/macbody ../cc/lexbody ../cc/compat
--- a/sys/src/cmd/5c/mkfile
+++ b/sys/src/cmd/5c/mkfile
@@ -18,6 +18,7 @@
HFILES=\
gc.h\
5.out.h\
+ ../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O
--- a/sys/src/cmd/5l/compat.c
+++ b/sys/src/cmd/5l/compat.c
@@ -1,56 +1,2 @@
#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void *p, ulong n)
-{
- fprint(2, "realloc(0x%p %ld) called\n", p, n);
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
- USED(v, pc);
-}
+#include "../cc/compat"
--- a/sys/src/cmd/5l/l.h
+++ b/sys/src/cmd/5l/l.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../5c/5.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
#define LIBNAMELEN 300
void addlibpath(char*);
@@ -252,7 +249,6 @@
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
-EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@@ -260,7 +256,6 @@
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN long instoffset;
EXTERN Opcross opcross[8];
EXTERN Oprang oprange[ALAST];
@@ -270,7 +265,6 @@
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
-EXTERN uintptr thunk;
EXTERN int version;
EXTERN char xcmp[C_GOK+1][C_GOK+1];
EXTERN Prog zprg;
@@ -349,7 +343,6 @@
int find1(long, int);
char* findlib(char*);
void follow(void);
-void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
@@ -363,7 +356,6 @@
void lput(long);
void lputl(long);
void mkfwd(void);
-void* mysbrk(ulong);
void names(void);
void nocache(Prog*);
void nuxiinit(void);
--- a/sys/src/cmd/5l/mkfile
+++ b/sys/src/cmd/5l/mkfile
@@ -15,6 +15,7 @@
HFILES=\
l.h\
../5c/5.out.h\
+ ../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@@ -24,6 +25,8 @@
enam.$O: ../5c/enam.c
$CC $CFLAGS ../5c/enam.c
+
+compat.$O: ../cc/compat
x:V: $O.out
$O.out -la -o/dev/null x.5
--- a/sys/src/cmd/5l/obj.c
+++ b/sys/src/cmd/5l/obj.c
@@ -1136,28 +1136,6 @@
}
void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(thunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(thunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char*)-1) {
- diag("out of memory");
- errorexit();
- }
- hunk = h;
- nhunk = nh;
- thunk += nh;
-}
-
-void
doprof1(void)
{
Sym *s;
--- a/sys/src/cmd/6a/a.h
+++ b/sys/src/cmd/6a/a.h
@@ -2,12 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../6c/6.out.h"
+#include "../cc/compat.h"
-
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Sym Sym;
typedef struct Ref Ref;
typedef struct Gen Gen;
@@ -109,7 +105,6 @@
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
-EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -116,7 +111,6 @@
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@@ -128,10 +122,8 @@
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
-EXTERN uintptr thunk;
EXTERN Biobuf obuf;
-void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@@ -168,28 +160,7 @@
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
-void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
-
-/*
- * Posix.c/Inferno.c/Nt.c
- */
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2
-};
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-char* mygetwd(char*, int);
-int myexec(char*, char*[]);
-int mydup(int, int);
-int myfork(void);
-int mypipe(int*);
-void* mysbrk(ulong);
--- a/sys/src/cmd/6a/mkfile
+++ b/sys/src/cmd/6a/mkfile
@@ -7,6 +7,7 @@
HFILES=\
../6c/6.out.h\
+ ../cc/compat.h\
y.tab.h\
a.h\
--- a/sys/src/cmd/6c/mkfile
+++ b/sys/src/cmd/6c/mkfile
@@ -19,6 +19,7 @@
HFILES=\
gc.h\
6.out.h\
+ ../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O
--- a/sys/src/cmd/6l/compat.c
+++ b/sys/src/cmd/6l/compat.c
@@ -1,55 +1,2 @@
#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void*, ulong)
-{
- fprint(2, "realloc called\n");
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void*, uintptr)
-{
-}
+#include "../cc/compat"
--- a/sys/src/cmd/6l/l.h
+++ b/sys/src/cmd/6l/l.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../6c/6.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
#define P ((Prog*)0)
#define S ((Sym*)0)
#define TNAME (curtext?curtext->from.sym->name:noname)
@@ -279,7 +276,6 @@
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
-EXTERN char* hunk;
EXTERN uchar inuxi1[1];
EXTERN uchar inuxi2[2];
EXTERN uchar inuxi4[4];
@@ -293,7 +289,6 @@
EXTERN Prog* lastp;
EXTERN long lcsize;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN long nsymbol;
EXTERN char* noname;
EXTERN char* outfile;
@@ -303,7 +298,6 @@
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN vlong textsize;
-EXTERN uintptr thunk;
EXTERN int version;
EXTERN Prog zprg;
EXTERN int dtype;
@@ -358,7 +352,6 @@
int find1v(vlong, int);
int find2(long, int);
void follow(void);
-void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
@@ -371,7 +364,6 @@
void lputl(long);
void main(int, char*[]);
void mkfwd(void);
-void* mysbrk(ulong);
void nuxiinit(void);
void objfile(char*);
int opsize(Prog*);
--- a/sys/src/cmd/6l/mkfile
+++ b/sys/src/cmd/6l/mkfile
@@ -29,3 +29,4 @@
enam.$O: ../6c/enam.c
$CC $CFLAGS ../6c/enam.c
+compat.$O: ../cc/compat
--- a/sys/src/cmd/6l/obj.c
+++ b/sys/src/cmd/6l/obj.c
@@ -1206,28 +1206,6 @@
}
void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(thunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(thunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char*)-1) {
- diag("out of memory");
- errorexit();
- }
- hunk = h;
- nhunk = nh;
- thunk += nh;
-}
-
-void
doprof1(void)
{
Sym *s;
--- a/sys/src/cmd/7a/a.h
+++ b/sys/src/cmd/7a/a.h
@@ -5,13 +5,10 @@
#include <libc.h>
#include <bio.h>
#include "../7c/7.out.h"
+#include "../cc/compat.h"
typedef vlong int64;
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Sym Sym;
typedef struct Gen Gen;
typedef struct Io Io;
@@ -101,7 +98,6 @@
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
-EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -108,7 +104,6 @@
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@@ -120,11 +115,8 @@
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
-EXTERN uintptr thunk;
EXTERN Biobuf obuf;
-void* alloc(long);
-void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@@ -161,25 +153,7 @@
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
-void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
-
-/*
- * system-dependent stuff from ../cc/compat.c
- */
-
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2,
-};
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-int myfork(void);
-void* mysbrk(ulong);
--- a/sys/src/cmd/7a/mkfile
+++ b/sys/src/cmd/7a/mkfile
@@ -7,6 +7,7 @@
HFILES=\
../7c/7.out.h\
+ ../cc/compat.h\
y.tab.h\
a.h\
@@ -16,4 +17,5 @@
< /sys/src/cmd/mkone
YFLAGS=-D1 -d
-lex.$O: ../cc/macbody ../cc/lexbody
+lex.$O: ../cc/macbody ../cc/lexbody ../cc/compat
+
--- a/sys/src/cmd/7c/mkfile
+++ b/sys/src/cmd/7c/mkfile
@@ -18,6 +18,7 @@
HFILES=\
gc.h\
7.out.h\
+ ../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O
--- a/sys/src/cmd/7l/compat.c
+++ b/sys/src/cmd/7l/compat.c
@@ -1,56 +1,2 @@
#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void *p, ulong n)
-{
- fprint(2, "realloc(0x%p %ld) called\n", p, n);
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
- USED(v, pc);
-}
+#include "../cc/compat"
--- a/sys/src/cmd/7l/l.h
+++ b/sys/src/cmd/7l/l.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../7c/7.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
#define LIBNAMELEN 300
void addlibpath(char*);
@@ -291,7 +288,6 @@
EXTERN Sym* histfrog[MAXHIST];
EXTERN int histfrogp;
EXTERN int histgen;
-EXTERN char* hunk;
EXTERN char* library[50];
EXTERN char* libraryobj[50];
@@ -300,7 +296,6 @@
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN char* noname;
EXTERN vlong instoffset;
EXTERN Opcross opcross[8];
@@ -310,7 +305,6 @@
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN vlong textsize;
-EXTERN uintptr thunk;
EXTERN int version;
EXTERN char xcmp[C_NCLASS][C_NCLASS];
EXTERN int xrefresolv;
@@ -378,7 +372,6 @@
void errorexit(void);
void export(void);
void follow(void);
-void gethunk(void);
void histtoauto(void);
void* halloc(usize);
int isnop(Prog*);
@@ -395,7 +388,6 @@
void lputl(long);
void mkfwd(void);
int movcon(vlong);
-void* mysbrk(ulong);
void names(void);
void nocache(Prog*);
void nuxiinit(void);
--- a/sys/src/cmd/7l/mkfile
+++ b/sys/src/cmd/7l/mkfile
@@ -20,6 +20,7 @@
HFILES=\
l.h\
../7c/7.out.h\
+ ../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@@ -32,6 +33,8 @@
enam.$O: ../7c/enam.c
$CC $CFLAGS ../7c/enam.c
+
+compat.$O: ../cc/compat
x:V: $O.out
$O.out -la -o/dev/null x.7
--- a/sys/src/cmd/7l/obj.c
+++ b/sys/src/cmd/7l/obj.c
@@ -1162,28 +1162,6 @@
}
void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(thunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(thunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char*)-1) {
- diag("out of memory");
- errorexit();
- }
- hunk = h;
- nhunk = nh;
- thunk += nh;
-}
-
-void
doprof1(void)
{
Sym *s;
--- a/sys/src/cmd/8a/a.h
+++ b/sys/src/cmd/8a/a.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../8c/8.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Sym Sym;
typedef struct Ref Ref;
typedef struct Gen Gen;
@@ -109,7 +106,6 @@
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
-EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -116,7 +112,6 @@
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@@ -128,10 +123,8 @@
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
-EXTERN uintptr thunk;
EXTERN Biobuf obuf;
-void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@@ -168,28 +161,7 @@
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
-void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
-
-/*
- * system-dependent stuff from ../cc/compat.c
- */
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2
-};
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-char* mygetwd(char*, int);
-int myexec(char*, char*[]);
-int mydup(int, int);
-int myfork(void);
-int mypipe(int*);
-void* mysbrk(ulong);
--- a/sys/src/cmd/8a/mkfile
+++ b/sys/src/cmd/8a/mkfile
@@ -7,6 +7,7 @@
HFILES=\
../8c/8.out.h\
+ ../cc/compat.h\
y.tab.h\
a.h\
--- a/sys/src/cmd/8c/mkfile
+++ b/sys/src/cmd/8c/mkfile
@@ -20,6 +20,7 @@
HFILES=\
gc.h\
8.out.h\
+ ../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O
--- a/sys/src/cmd/8l/compat.c
+++ b/sys/src/cmd/8l/compat.c
@@ -1,56 +1,2 @@
#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void*, ulong)
-{
- fprint(2, "realloc called\n");
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
- USED(v, pc);
-}
+#include "../cc/compat"
--- a/sys/src/cmd/8l/l.h
+++ b/sys/src/cmd/8l/l.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../8c/8.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
#define P ((Prog*)0)
#define S ((Sym*)0)
#define TNAME (curtext?curtext->from.sym->name:noname)
@@ -255,7 +252,6 @@
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
-EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@@ -266,7 +262,6 @@
EXTERN Prog* lastp;
EXTERN long lcsize;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN long nsymbol;
EXTERN char* noname;
EXTERN char* outfile;
@@ -276,7 +271,6 @@
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
-EXTERN uintptr thunk;
EXTERN int version;
EXTERN Prog zprg;
EXTERN int dtype;
@@ -328,7 +322,6 @@
int find1(long, int);
int find2(long, int);
void follow(void);
-void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
@@ -341,7 +334,6 @@
void lputl(long);
void main(int, char*[]);
void mkfwd(void);
-void* mysbrk(ulong);
void nuxiinit(void);
void objfile(char*);
int opsize(Prog*);
--- a/sys/src/cmd/8l/mkfile
+++ b/sys/src/cmd/8l/mkfile
@@ -13,6 +13,7 @@
HFILES=\
l.h\
+ ../cc/compat.h\
../8c/8.out.h\
BIN=/$objtype/bin
@@ -29,3 +30,4 @@
enam.$O: ../8c/enam.c
$CC $CFLAGS ../8c/enam.c
+compat.$O: ../cc/compat
--- a/sys/src/cmd/8l/obj.c
+++ b/sys/src/cmd/8l/obj.c
@@ -1180,28 +1180,6 @@
}
void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(thunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(thunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char*)-1) {
- diag("out of memory");
- errorexit();
- }
- hunk = h;
- nhunk = nh;
- thunk += nh;
-}
-
-void
doprof1(void)
{
Sym *s;
--- a/sys/src/cmd/cc/cc.h
+++ b/sys/src/cmd/cc/cc.h
@@ -5,9 +5,7 @@
#pragma lib "../cc/cc.a$O"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
+#include "../cc/compat.h"
typedef struct Node Node;
typedef struct Sym Sym;
@@ -184,13 +182,6 @@
NALIGN,
};
-enum /* also in ../{8a,0a}.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2,
-};
-
enum
{
DMARK,
@@ -437,7 +428,6 @@
EXTERN int fperror;
EXTERN Sym* hash[NHASH];
EXTERN int hasdoubled;
-EXTERN char* hunk;
EXTERN char* include[20];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -451,7 +441,6 @@
EXTERN long nearln;
EXTERN int nerrors;
EXTERN int newflag;
-EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Node* nodproto;
EXTERN Node* nodcast;
@@ -471,7 +460,6 @@
EXTERN int thechar;
EXTERN char* thestring;
EXTERN Type* thisfn;
-EXTERN uintptr thunk;
EXTERN Type* types[NTYPE];
EXTERN Type* fntypes[NTYPE];
EXTERN Node* initlist;
@@ -522,21 +510,6 @@
extern ulong thash[];
/*
- * compat.c/unix.c/windows.c
- */
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-int myaccess(char*);
-char* mygetwd(char*, int);
-int myexec(char*, char*[]);
-int mydup(int, int);
-int myfork(void);
-int mypipe(int*);
-void* mysbrk(ulong);
-
-/*
* parser
*/
int yyparse(void);
@@ -545,8 +518,6 @@
/*
* lex.c
*/
-void* allocn(void*, long, long);
-void* alloc(long);
void cinit(void);
int compile(char*, char**, int);
void errorexit(void);
@@ -666,7 +637,6 @@
int deadheads(Node*);
Type* dotsearch(Sym*, Type*, Node*, long*);
long dotoffset(Type*, Type*, Node*);
-void gethunk(void);
Node* invert(Node*);
int bitno(long);
void makedot(Node*, Type*, long);
--- a/sys/src/cmd/cc/compat
+++ b/sys/src/cmd/cc/compat
@@ -1,4 +1,3 @@
-
int
myaccess(char *f)
{
@@ -76,4 +75,118 @@
myfork(void)
{
return fork();
+}
+
+/*
+ * real allocs
+ */
+void
+gethunk(void)
+{
+ char *h;
+ ulong 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;
+ else
+ nh += (h - hunk) - nhunk;
+ nhunk += nh;
+ thunk += nh;
+}
+
+void*
+alloc(long n)
+{
+ void *p;
+
+ while((uintptr)hunk & 7) {
+ hunk++;
+ nhunk--;
+ }
+ while(nhunk < n)
+ gethunk();
+ p = hunk;
+ nhunk -= n;
+ hunk += n;
+ return p;
+}
+
+void*
+allocn(void *p, long on, long n)
+{
+ void *q;
+
+ q = (uchar*)p + on;
+ if(q != hunk || nhunk < n) {
+ while(nhunk < on+n)
+ gethunk();
+ memmove(hunk, p, on);
+ p = hunk;
+ hunk += on;
+ nhunk -= on;
+ }
+ hunk += n;
+ nhunk -= n;
+ return p;
+}
+
+/*
+ * fake mallocs
+ */
+void*
+malloc(ulong n)
+{
+ return alloc(n);
+}
+
+void*
+calloc(ulong m, ulong n)
+{
+ return alloc(m*n);
+}
+
+void*
+realloc(void *o, ulong n)
+{
+ ulong m;
+ void *a;
+
+ if(n == 0)
+ return nil;
+ if(o == nil)
+ return alloc(n);
+ a = alloc(n);
+ m = (char*)a - (char*)o;
+ if(m < n)
+ n = m;
+ memmove(a, o, n);
+ return a;
+}
+
+void
+free(void*)
+{
+}
+
+/* needed when profiling */
+void*
+mallocz(ulong size, int)
+{
+ return alloc(size);
+}
+
+void
+setmalloctag(void*, uintptr)
+{
+}
+
+void
+setrealloctag(void*, uintptr)
+{
}
--- a/sys/src/cmd/cc/compat.c
+++ b/sys/src/cmd/cc/compat.c
@@ -1,62 +1,2 @@
#include "cc.h"
#include "compat"
-
-/*
- * fake mallocs
- */
-void*
-malloc(ulong n)
-{
- return alloc(n);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- return alloc(m*n);
-}
-
-void*
-realloc(void *o, ulong n)
-{
- ulong m;
- void *a;
-
- if(n == 0)
- return nil;
- if(o == nil)
- return alloc(n);
- a = alloc(n);
- m = (char*)a - (char*)o;
- if(m < n)
- n = m;
- memmove(a, o, n);
- return a;
-}
-
-void
-free(void*)
-{
-}
-
-/* needed when profiling */
-void*
-mallocz(ulong size, int clr)
-{
- void *v;
-
- v = alloc(size);
- if(clr && v != nil)
- memset(v, 0, size);
- return v;
-}
-
-void
-setmalloctag(void*, uintptr)
-{
-}
-
-void
-setrealloctag(void*, uintptr)
-{
-}
--- /dev/null
+++ b/sys/src/cmd/cc/compat.h
@@ -1,0 +1,35 @@
+/*
+ * functions shared by compilers, linkers and assemblers.
+ */
+
+#ifndef EXTERN
+#define EXTERN extern
+#endif
+
+enum
+{
+ Plan9 = 1<<0,
+ Unix = 1<<1,
+ Windows = 1<<2
+};
+EXTERN int systemtype(int);
+EXTERN int pathchar(void);
+
+EXTERN int myaccess(char *);
+EXTERN int mywait(int*);
+EXTERN int mycreat(char*, int);
+EXTERN char* mygetwd(char*, int);
+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 uintptr thunk;
+
+EXTERN void* alloc(long n);
+EXTERN void* allocn(void *p, long on, long n);
--- a/sys/src/cmd/cc/lex.c
+++ b/sys/src/cmd/cc/lex.c
@@ -1524,45 +1524,6 @@
return fmtstrcpy(fp, str);
}
-/*
- * real allocs
- */
-void*
-alloc(long n)
-{
- void *p;
-
- while((uintptr)hunk & MAXALIGN) {
- hunk++;
- nhunk--;
- }
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void*
-allocn(void *p, long on, long n)
-{
- void *q;
-
- q = (uchar*)p + on;
- if(q != hunk || nhunk < n) {
- while(nhunk < on+n)
- gethunk();
- memmove(hunk, p, on);
- p = hunk;
- hunk += on;
- nhunk -= on;
- }
- hunk += n;
- nhunk -= n;
- return p;
-}
-
void
setinclude(char *p)
{
--- a/sys/src/cmd/cc/lexbody
+++ b/sys/src/cmd/cc/lexbody
@@ -37,45 +37,6 @@
;
}
-/*
- * real allocs
- */
-void*
-alloc(long n)
-{
- void *p;
-
- while((uintptr)hunk & MAXALIGN) {
- hunk++;
- nhunk--;
- }
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void*
-allocn(void *p, long on, long n)
-{
- void *q;
-
- q = (uchar*)p + on;
- if(q != hunk || nhunk < n) {
- while(nhunk < on+n)
- gethunk();
- memmove(hunk, p, on);
- p = hunk;
- hunk += on;
- nhunk -= on;
- }
- hunk += n;
- nhunk -= n;
- return p;
-}
-
void
setinclude(char *p)
{
--- a/sys/src/cmd/cc/mac.c
+++ b/sys/src/cmd/cc/mac.c
@@ -1,3 +1,2 @@
#include "cc.h"
-
#include "macbody"
--- a/sys/src/cmd/cc/macbody
+++ b/sys/src/cmd/cc/macbody
@@ -847,22 +847,3 @@
ehist->link = h;
ehist = h;
}
-
-void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(thunk >= 10L*NHUNK)
- nh = 10L*NHUNK;
- h = (char*)mysbrk(nh);
- if(h == (char*)-1) {
- yyerror("out of memory");
- errorexit();
- }
- hunk = h;
- nhunk = nh;
- thunk += nh;
-}
--- a/sys/src/cmd/cc/mkfile
+++ b/sys/src/cmd/cc/mkfile
@@ -19,6 +19,7 @@
omachcap.$O\
HFILES=cc.h\
+ compat.h\
y.tab.h\
YFILES=cc.y\
@@ -34,7 +35,9 @@
$LIB: $LIBOBJ
ar vu $LIB $OFILES
-mac.$O: macbody
+mac.$O: macbody
+
+compat.$O: compat
everything:V:
# mk the current compilers
--- a/sys/src/cmd/ka/a.h
+++ b/sys/src/cmd/ka/a.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../kc/k.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Sym Sym;
typedef struct Gen Gen;
typedef struct Io Io;
@@ -95,7 +92,6 @@
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
-EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -102,7 +98,6 @@
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN int ninclude;
EXTERN int nosched;
EXTERN Gen nullgen;
@@ -115,11 +110,8 @@
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
-EXTERN uintptr thunk;
EXTERN Biobuf obuf;
-void* alloc(long);
-void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@@ -154,29 +146,7 @@
void prfile(long);
void outhist(void);
void linehist(char*, int);
-void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
-
-/*
- * system-dependent stuff from ../cc/compat.c
- */
-
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2
-};
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-char* mygetwd(char*, int);
-int myexec(char*, char*[]);
-int mydup(int, int);
-int myfork(void);
-int mypipe(int*);
-void* mysbrk(ulong);
--- a/sys/src/cmd/ka/mkfile
+++ b/sys/src/cmd/ka/mkfile
@@ -7,6 +7,7 @@
HFILES=\
../kc/k.out.h\
+ ../cc/compat.h\
y.tab.h\
a.h\
--- a/sys/src/cmd/kc/mkfile
+++ b/sys/src/cmd/kc/mkfile
@@ -17,6 +17,7 @@
HFILES=\
gc.h\
k.out.h\
+ ../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O
--- a/sys/src/cmd/kl/compat.c
+++ b/sys/src/cmd/kl/compat.c
@@ -1,56 +1,2 @@
#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void *p, ulong n)
-{
- fprint(2, "realloc(0x%p %ld) called\n", p, n);
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
- USED(v, pc);
-}
+#include "../cc/compat"
--- a/sys/src/cmd/kl/l.h
+++ b/sys/src/cmd/kl/l.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../kc/k.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Adr Adr;
typedef struct Sym Sym;
typedef struct Autom Auto;
@@ -224,7 +221,6 @@
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
-EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@@ -232,7 +228,6 @@
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN char* noname;
EXTERN long instoffset;
EXTERN char* outfile;
@@ -241,7 +236,6 @@
EXTERN long staticgen;
EXTERN Prog* textp;
EXTERN long textsize;
-EXTERN uintptr tothunk;
EXTERN char xcmp[C_NCLASS][C_NCLASS];
EXTERN int version;
EXTERN Prog zprg;
@@ -290,7 +284,6 @@
void exchange(Prog*);
int find1(long, int);
void follow(void);
-void gethunk(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
int isnop(Prog*);
@@ -301,7 +294,6 @@
Sym* lookup(char*, int);
void lput(long);
void mkfwd(void);
-void* mysbrk(ulong);
void names(void);
void nocache(Prog*);
void noops(void);
--- a/sys/src/cmd/kl/mkfile
+++ b/sys/src/cmd/kl/mkfile
@@ -16,6 +16,7 @@
HFILES=\
l.h\
../kc/k.out.h\
+ ../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@@ -22,3 +23,6 @@
enam.$O: ../kc/enam.c
$CC $CFLAGS ../kc/enam.c
+
+compat.$O: ../cc/compat
+
--- a/sys/src/cmd/kl/obj.c
+++ b/sys/src/cmd/kl/obj.c
@@ -194,7 +194,7 @@
out:
if(debug['v']) {
Bprint(&bso, "%5.2f cpu time\n", cputime());
- Bprint(&bso, "%zud memory used\n", tothunk);
+ Bprint(&bso, "%zud memory used\n", thunk);
Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
}
@@ -974,29 +974,6 @@
*p = zprg;
return p;
-}
-
-void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(tothunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(tothunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char *)-1) {
- diag("out of memory");
- errorexit();
- }
-
- hunk = h;
- nhunk = nh;
- tothunk += nh;
}
void
--- a/sys/src/cmd/qa/a.h
+++ b/sys/src/cmd/qa/a.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../qc/q.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Sym Sym;
typedef struct Gen Gen;
typedef struct Io Io;
@@ -115,7 +112,6 @@
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
-EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -122,7 +118,6 @@
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN int nosched;
EXTERN int ninclude;
EXTERN Gen nullgen;
@@ -135,7 +130,6 @@
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
-EXTERN uintptr thunk;
EXTERN Biobuf obuf;
void errorexit(void);
@@ -173,28 +167,7 @@
void prfile(long);
void outhist(void);
void linehist(char*, int);
-void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
-
-/*
- * system-dependent stuff from ../cc/compat.c
- */
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2
-};
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-char* mygetwd(char*, int);
-int myexec(char*, char*[]);
-int mydup(int, int);
-int myfork(void);
-int mypipe(int*);
-void* mysbrk(ulong);
--- a/sys/src/cmd/qa/mkfile
+++ b/sys/src/cmd/qa/mkfile
@@ -7,6 +7,7 @@
HFILES=\
../qc/q.out.h\
+ ../cc/compat.h\
y.tab.h\
a.h\
--- a/sys/src/cmd/qc/mkfile
+++ b/sys/src/cmd/qc/mkfile
@@ -18,6 +18,7 @@
HFILES=\
gc.h\
q.out.h\
+ ../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O
--- a/sys/src/cmd/ql/compat.c
+++ b/sys/src/cmd/ql/compat.c
@@ -1,56 +1,2 @@
#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void*, ulong)
-{
- fprint(2, "realloc called\n");
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
- USED(v, pc);
-}
+#include "../cc/compat"
--- a/sys/src/cmd/ql/l.h
+++ b/sys/src/cmd/ql/l.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../qc/q.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Adr Adr;
typedef struct Sym Sym;
typedef struct Autom Auto;
@@ -216,7 +213,6 @@
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
-EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@@ -224,7 +220,6 @@
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN char* noname;
EXTERN long instoffset;
EXTERN char* outfile;
@@ -234,7 +229,6 @@
EXTERN long staticgen;
EXTERN Prog* textp;
EXTERN long textsize;
-EXTERN uintptr tothunk;
EXTERN char xcmp[C_NCLASS][C_NCLASS];
EXTERN int version;
EXTERN Prog zprg;
@@ -289,7 +283,6 @@
void export(void);
int find1(long, int);
void follow(void);
-void gethunk(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
void import(void);
@@ -301,7 +294,6 @@
Sym* lookup(char*, int);
void lput(long);
void mkfwd(void);
-void* mysbrk(ulong);
void names(void);
void nocache(Prog*);
void noops(void);
--- a/sys/src/cmd/ql/mkfile
+++ b/sys/src/cmd/ql/mkfile
@@ -18,6 +18,7 @@
HFILES=\
l.h\
../qc/q.out.h\
+ ../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@@ -26,3 +27,4 @@
$CC $CFLAGS ../qc/enam.c
cnam.c: l.h
rc mkcname
+compat.$O: ../cc/compat
--- a/sys/src/cmd/ql/obj.c
+++ b/sys/src/cmd/ql/obj.c
@@ -273,7 +273,7 @@
out:
if(debug['v']) {
Bprint(&bso, "%5.2f cpu time\n", cputime());
- Bprint(&bso, "%zud memory used\n", tothunk);
+ Bprint(&bso, "%zud memory used\n", thunk);
Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
}
@@ -1108,29 +1108,6 @@
*p = zprg;
return p;
-}
-
-void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(tothunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(tothunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char *)-1) {
- diag("out of memory");
- errorexit();
- }
-
- hunk = h;
- nhunk = nh;
- tothunk += nh;
}
void
--- a/sys/src/cmd/va/a.h
+++ b/sys/src/cmd/va/a.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../vc/v.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Sym Sym;
typedef struct Gen Gen;
typedef struct Io Io;
@@ -94,7 +91,6 @@
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
-EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
@@ -101,7 +97,6 @@
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN int nosched;
EXTERN int ninclude;
EXTERN Gen nullgen;
@@ -114,11 +109,8 @@
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
-EXTERN uintptr thunk;
EXTERN Biobuf obuf;
-void* alloc(long);
-void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@@ -154,29 +146,7 @@
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
-void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
-
-/*
- * system-dependent stuff from ../cc/compat.c
- */
-
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2
-};
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-char* mygetwd(char*, int);
-int myexec(char*, char*[]);
-int mydup(int, int);
-int myfork(void);
-int mypipe(int*);
-void* mysbrk(ulong);
--- a/sys/src/cmd/va/mkfile
+++ b/sys/src/cmd/va/mkfile
@@ -7,6 +7,7 @@
HFILES=\
../vc/v.out.h\
+ ../cc/compat.h\
y.tab.h\
a.h\
--- a/sys/src/cmd/vc/mkfile
+++ b/sys/src/cmd/vc/mkfile
@@ -17,6 +17,7 @@
HFILES=\
gc.h\
v.out.h\
+ ../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O
--- a/sys/src/cmd/vl/compat.c
+++ b/sys/src/cmd/vl/compat.c
@@ -1,56 +1,2 @@
#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void *p, ulong n)
-{
- fprint(2, "realloc(0x%p %ld) called\n", p, n);
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
- USED(v, pc);
-}
+#include "../cc/compat"
--- a/sys/src/cmd/vl/l.h
+++ b/sys/src/cmd/vl/l.h
@@ -2,11 +2,8 @@
#include <libc.h>
#include <bio.h>
#include "../vc/v.out.h"
+#include "../cc/compat.h"
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
typedef struct Adr Adr;
typedef struct Sym Sym;
typedef struct Autom Auto;
@@ -215,7 +212,6 @@
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
-EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@@ -223,7 +219,6 @@
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
-EXTERN long nhunk;
EXTERN long instoffset;
EXTERN Opcross opcross[10];
EXTERN Oprang oprange[ALAST];
@@ -233,7 +228,6 @@
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
-EXTERN uintptr thunk;
EXTERN int version;
EXTERN char xcmp[32][32];
EXTERN Prog zprg;
@@ -292,7 +286,6 @@
void exchange(Prog*);
int find1(long, int);
void follow(void);
-void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
--- a/sys/src/cmd/vl/mkfile
+++ b/sys/src/cmd/vl/mkfile
@@ -16,6 +16,7 @@
HFILES=\
l.h\
../vc/v.out.h\
+ ../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@@ -22,6 +23,8 @@
enam.$O: ../vc/enam.c
$CC $CFLAGS ../vc/enam.c
+
+compat.$O: ../cc/compat
x:V: $O.out
$O.out -la -o/dev/null x.v
--- a/sys/src/cmd/vl/obj.c
+++ b/sys/src/cmd/vl/obj.c
@@ -1059,28 +1059,6 @@
}
void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(thunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(thunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char*)-1) {
- diag("out of memory");
- errorexit();
- }
- hunk = h;
- nhunk = nh;
- thunk += nh;
-}
-
-void
doprof1(void)
{
Sym *s;