1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#include <windows.h>
#include <lib9.h>
#define Windows (1<<2) /* hack - can't include cc.h because of clashes */
#define Chunk (1*1024*1024)
void*
mysbrk(ulong size)
{
void *v;
static int chunk;
static uchar *brk;
if(chunk < size) {
chunk = Chunk;
if(chunk < size)
chunk = Chunk + size;
brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if(brk == 0)
return (void*)-1;
}
v = brk;
chunk -= size;
brk += size;
return v;
}
int
mycreat(char *n, int p)
{
return create(n, 1, p);
}
int
mywait(int *s)
{
fprint(2, "mywait called\n");
abort();
return 0;
}
int
mydup(int f1, int f2)
{
int ok;
ok = _dup2(f1, f2);
if(ok < 0)
return -1;
return f2;
/*
fprint(2, "mydup called\n");
abort();
return 0;
*/
}
int
mypipe(int *fd)
{
fprint(2, "mypipe called\n");
abort();
return 0;
}
int
systemtype(int sys)
{
return sys&Windows;
}
int
pathchar(void)
{
return '/';
}
char*
mygetwd(char *path, int len)
{
return getcwd(path, len);
}
int
myexec(char *path, char *argv[])
{
fprint(2, "myexec called\n");
abort();
return 0;
}
int
myfork(void)
{
fprint(2, "myfork called\n");
abort();
return 0;
}
/*
* fake mallocs
*/
void*
malloc(uint n)
{
return mysbrk(n);
}
void*
calloc(uint m, uint n)
{
return mysbrk(m*n);
}
void*
realloc(void *p, uint n)
{
void *new;
new = malloc(n);
if(new && p)
memmove(new, p, n);
return new;
}
void
free(void *p)
{
}
|