diff --git a/bin/ikarus b/bin/ikarus index 1e73a8c..653d817 100755 Binary files a/bin/ikarus and b/bin/ikarus differ diff --git a/bin/ikarus-runtime.c b/bin/ikarus-runtime.c index 515895d..26d036d 100644 --- a/bin/ikarus-runtime.c +++ b/bin/ikarus-runtime.c @@ -905,3 +905,16 @@ ikrt_bytes_allocated_major(ikpcb* pcb){ return fix(pcb->allocation_count_major); } + +ikp +ikrt_fork(){ + int pid = fork(); + return fix(pid); +} + +ikp +ikrt_waitpid(ikp pid){ + int status; + pid_t t = waitpid(unfix(pid), &status, 0); + return fix(t); +} diff --git a/src/ikarus.boot b/src/ikarus.boot index cd03ec9..3c8e413 100644 Binary files a/src/ikarus.boot and b/src/ikarus.boot differ diff --git a/src/libposix.ss b/src/libposix.ss index 6e80eef..57c7146 100644 --- a/src/libposix.ss +++ b/src/libposix.ss @@ -1,16 +1,22 @@ -;;; ($pcb-set! posix-fork -;;; (lambda () -;;; (foreign-call "S_fork"))) -;;; -;;; ($pcb-set! fork -;;; (lambda (parent-proc child-proc) -;;; (let ([pid (posix-fork)]) -;;; (cond -;;; [(fx= pid 0) (child-proc)] -;;; [(fx= pid -1) -;;; (error 'fork "failed")] -;;; [else (parent-proc pid)])))) +(primitive-set! 'posix-fork + (lambda () + (foreign-call "ikrt_fork"))) + +(primitive-set! 'fork + (lambda (parent-proc child-proc) + (let ([pid (posix-fork)]) + (cond + [(fx= pid 0) (child-proc)] + [(fx= pid -1) + (error 'fork "failed")] + [else (parent-proc pid)])))) + +(primitive-set! 'waitpid + (lambda (pid) + (unless (fixnum? pid) + (error 'waitpid "~s is not a fixnum" pid)) + (foreign-call "ikrt_waitpid" pid))) (primitive-set! 'system (lambda (x) diff --git a/src/makefile.ss b/src/makefile.ss index 4fef4cc..68b0279 100755 --- a/src/makefile.ss +++ b/src/makefile.ss @@ -86,6 +86,7 @@ make-guardian weak-cons collect interrupt-handler time-it + posix-fork fork waitpid )) (define system-primitives