sb-posix: abort(3), exit(3), and _exit(2)
authorNikodemus Siivola <nikodemus@random-state.net>
Wed, 2 May 2012 13:46:13 +0000 (16:46 +0300)
committerNikodemus Siivola <nikodemus@random-state.net>
Wed, 2 May 2012 14:13:59 +0000 (17:13 +0300)
  Also fix docstring of SB-EXT:EXIT, which referred to exit as being section 2.

NEWS
contrib/sb-posix/defpackage.lisp
contrib/sb-posix/interface.lisp
contrib/sb-posix/macros.lisp
src/code/cold-init.lisp

diff --git a/NEWS b/NEWS
index 5b4ac62..eda0e56 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,8 @@ changes relative to sbcl-1.0.56:
     (lp#936304)
   * enhancement: backtraces show the correct number of arguments for frames
     called with too many arguments.
+  * enhancement: support for abort(3), exit(3), and _exit(2) has been added to
+    SB-POSIX.
   * optimization: fewer uses of full calls to signed modular functions.
     (lp#903821)
   * optimization: typechecking alien values is typically 5 x faster.
index 23c5cce..ecd7f59 100644 (file)
@@ -1,5 +1,5 @@
 (defpackage :sb-posix (:use #:sb-alien #:cl)
-  (:shadow close open ftruncate truncate time read write)
+  (:shadow abort close open ftruncate truncate time read write)
   (:export #:syscall-error #:syscall-errno #:syscall-name
 
            ;; types and type conversion
index bf408a0..8025930 100644 (file)
 
   ;; uid, gid
   (define-call "geteuid" uid-t never-fails) ; "always successful", it says
-#-sunos  (define-call "getresuid" uid-t never-fails)
+  #-sunos
+  (define-call "getresuid" uid-t never-fails)
   (define-call "getuid" uid-t never-fails)
   (define-call "seteuid" int minusp (uid uid-t))
-#-sunos  (define-call "setfsuid" int minusp (uid uid-t))
+  #-sunos
+  (define-call "setfsuid" int minusp (uid uid-t))
   (define-call "setreuid" int minusp (ruid uid-t) (euid uid-t))
-#-sunos  (define-call "setresuid" int minusp (ruid uid-t) (euid uid-t) (suid uid-t))
+  #-sunos
+  (define-call "setresuid" int minusp (ruid uid-t) (euid uid-t) (suid uid-t))
   (define-call "setuid" int minusp (uid uid-t))
   (define-call "getegid" gid-t never-fails)
   (define-call "getgid" gid-t never-fails)
-#-sunos  (define-call "getresgid" gid-t never-fails)
+  #-sunos
+  (define-call "getresgid" gid-t never-fails)
   (define-call "setegid" int minusp (gid gid-t))
-#-sunos  (define-call "setfsgid" int minusp (gid gid-t))
+  #-sunos
+  (define-call "setfsgid" int minusp (gid gid-t))
   (define-call "setgid" int minusp (gid gid-t))
   (define-call "setregid" int minusp (rgid gid-t) (egid gid-t))
-#-sunos  (define-call "setresgid" int minusp (rgid gid-t) (egid gid-t) (sgid gid-t))
+  #-sunos
+  (define-call "setresgid" int minusp (rgid gid-t) (egid gid-t) (sgid gid-t))
 
   ;; processes, signals
   (define-call "alarm" int never-fails (seconds unsigned))
 
-
+  ;; exit and abort, not much point inlining these
+  (define-simple-call abort void)
+  (define-simple-call exit void (status int))
+  (define-simple-call _exit void (status int))
 
   ;; FIXME this is a lie, of course this can fail, but there's no
   ;; error handling here yet!
index 95d25b7..aa69c47 100644 (file)
@@ -140,3 +140,13 @@ a FILE-STREAM designating the underlying file-descriptor."
       (declaim (inline ,lisp-name))
       (defun ,lisp-name ,arglist
         ,@body))))
+
+(defmacro define-simple-call (name return-type &rest arguments)
+  (multiple-value-bind (lisp-name c-name)
+      (values name (substitute #\_ #\- (string-downcase name)))
+    `(progn
+       (export ',lisp-name :sb-posix)
+       (defun ,lisp-name ,(mapcar #'first arguments)
+         (alien-funcall (extern-alien ,c-name (function ,return-type
+                                                        ,@(mapcar #'second arguments)))
+                        ,@(mapcar #'first arguments))))))
\ No newline at end of file
index 28ee7a8..802b325 100644 (file)
@@ -293,13 +293,13 @@ defaults to 0 when ABORT is false, and 1 when it is true.
 
 When ABORT is false (the default), current thread is first unwound,
 *EXIT-HOOKS* are run, other threads are terminated, and standard
-output streams are flushed before SBCL calls exit(2) -- at which point
+output streams are flushed before SBCL calls exit(3) -- at which point
 atexit(3) functions will run. If multiple threads call EXIT with ABORT
 being false, the first one to call it will complete the protocol.
 
 When ABORT is true, SBCL exits immediately by calling _exit(2) without
 unwinding stack, or calling exit hooks. Note that _exit(2) does not
-call atexit(3) functions unlike exit(2).
+call atexit(3) functions unlike exit(3).
 
 Recursive calls to EXIT cause EXIT to behave as it ABORT was true.