22 if((fd
= open("/env", OREAD
)) < 0)
24 n
= dirreadall(fd
, &d
);
26 env
= kmalloc(sizeof(env
[0]) * (n
+ 1));
34 // filter out some stuff...
35 if(strncmp(k
, "fn#", 3) == 0)
37 if(strcmp(k
, "timezone") == 0)
42 if((v
= getenv(d
[i
].name
)) == nil
)
44 if((env
[c
] = ksmprint("%s=%s", k
, v
)) == nil
)
67 onstack(long *stk
, int (*func
)(void *), void *arg
)
69 struct onstackargs a
, *args
;
74 if((long*)sp
>= stk
&& (long*)sp
< stk
+(KSTACK
/ sizeof(long)))
77 if(args
= (struct onstackargs
*)setjmp(jmp
)){
78 args
->ret
= onstack(args
->stk
, args
->func
, args
->arg
);
79 longjmp(args
->jmp
, 1);
82 sp
= &stk
[(KSTACK
/ sizeof(long))-16];
83 jmp
[JMPBUFSP
] = (long)sp
;
85 memset(stk
, 0, KSTACK
);
92 if(!setjmp(args
->jmp
))
93 longjmp(jmp
, (int)args
);
101 proff(void (*fn
)(void*), void *arg
)
103 if(_tos
->prof
.what
== 0){
106 prof(fn
, arg
, 2000, _tos
->prof
.what
);
111 profexitjmpfn(void *arg
)
114 * we are now called by the profiling function on the profstack.
115 * save the current continuation so we can return here on exit.
118 longjmp((long*)arg
, 1); /* return from profme() */
122 profmeprofstack(void *arg
)
124 proff(profexitjmpfn
, arg
);
130 static long *profstack
;
138 onstack(profstack
, profmeprofstack
, j
);
143 vpanic(char *msg
, va_list arg
)
148 fprint(2, "PANIC: ");
149 vfprint(2, msg
, arg
);
155 snprint(buf
, sizeof(buf
), "/proc/%d/notepg", getpid());
156 if((fd
= open(buf
, OWRITE
)) >= 0){
157 write(fd
, "kill", 4);
164 panic(char *msg
, ...)
175 fprint(2, "usage: linuxemu [-d] [-u uid] [-g gid] cmd [args]\n");
181 long profstack
[KSTACK
/ sizeof(long)];
182 long kstack
[KSTACK
/ sizeof(long)];
187 void main(int argc
, char *argv
[])
194 fmtinstall('E', Efmt
);
195 fmtinstall('S', Sfmt
);
206 uid
= atoi(EARGF(usage()));
209 gid
= atoi(EARGF(usage()));
228 profstack
= ms
.profstack
;
229 exitjmp
= ms
.exitjmp
;
240 /* emulated console */
242 if((fd
= sys_open("/dev/cons", O_RDWR
, 0)) != 0)
243 fprint(2, "cant open console for stdin\n");
246 fprint(2, "cant dup stdout\n");
249 fprint(2, "cant dup stderr\n");
251 sys_fcntl(0, F_SETFD
, 0);
252 sys_fcntl(1, F_SETFD
, 0);
253 sys_fcntl(2, F_SETFD
, 0);
255 err
= sys_execve(*argv
, argv
, readenv());
257 fprint(2, "%s: %E\n", *argv
, err
);