xref: /inferno-os/utils/ld/Nt.c (revision e45fa0eb0763b57d6fb0649c064bc3b95ccdea6c)
1 #include <windows.h>
2 #include <lib9.h>
3 
4 /*
5  *	We can't include l.h, because Windoze wants to use some names
6  *	like FLOAT and ABC which we declare.  Define what we need here.
7  */
8 typedef	unsigned char	uchar;
9 typedef	unsigned int	uint;
10 typedef	unsigned long	ulong;
11 
12 extern char	*hunk;
13 extern long	nhunk;
14 
15 void	gethunk(void);
16 
17 /*
18  * fake malloc
19  */
20 void*
21 malloc(uint n)
22 {
23 	void *p;
24 
25 	while(n & 7)
26 		n++;
27 	while(nhunk < n)
28 		gethunk();
29 	p = hunk;
30 	nhunk -= n;
31 	hunk += n;
32 	return p;
33 }
34 
35 void
36 free(void *p)
37 {
38 }
39 
40 void*
41 calloc(uint m, uint n)
42 {
43 	void *p;
44 
45 	n *= m;
46 	p = malloc(n);
47 	memset(p, 0, n);
48 	return p;
49 }
50 
51 void*
52 realloc(void *p, uint n)
53 {
54 	void *new;
55 
56 	new = malloc(n);
57 	if(new && p)
58 		memmove(new, p, n);
59 	return new;
60 }
61 
62 #define	Chunk	(1*1024*1024)
63 
64 void*
65 mysbrk(ulong size)
66 {
67 	void *v;
68 	static int chunk;
69 	static uchar *brk;
70 
71 	if(chunk < size) {
72 		chunk = Chunk;
73 		if(chunk < size)
74 			chunk = Chunk + size;
75 		brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
76 		if(brk == 0)
77 			return (void*)-1;
78 	}
79 	v = brk;
80 	chunk -= size;
81 	brk += size;
82 	return v;
83 }
84 
85 double
86 cputime(void)
87 {
88 	return ((double)0);
89 }
90 
91 int
92 fileexists(char *name)
93 {
94 	int fd;
95 
96 	fd = open(name, OREAD);
97 	if(fd < 0)
98 		return 0;
99 	close(fd);
100 	return 1;
101 }
102