[cffi-devel] "Unhandled memory fault" on any memory allocation after fork
Hi all ! First, thank you for your great work on this library. I just use it for the first time. I write the following code to test unix fork: =============================================== (asdf:oos 'asdf:load-op :cffi) (defpackage :testfork (:use :common-lisp :cffi)) (in-package :testfork) (defcvar "errno" :int) (cffi:defcfun ("getpid" unix-getpid) :int) (cffi:defcfun ("getuid" unix-getuid) :int) (cffi:defcfun ("getgid" unix-getgid) :int) (cffi:defcfun ("fork" unix-fork) :int) (cffi:defcfun ("exit" unix-exit) :void (code :int)) (cffi:defcfun ("wait" unix-wait) :int (statloc :pointer)) (when (zerop (unix-fork)) (with-foreign-pointer-as-string (str 6 str-size :encoding :ascii) (lisp-string-to-foreign "Hello, foreign world!" str str-size)) (unix-exit 0)) (progn (format t "I'm parent, Pid=~A~%" (unix-getpid)) (format t "one child claimed!~A~%" (unix-wait (cffi:null-pointer))) ) =============================================== When I add two lines using with-foreign-pointer-as-string and lisp-string-to-foreign, my SBCL always crashes, and tell me " fatal error encountered in SBCL pid XXXX: Unhandled memory fault. " I have tried other memory allocation macros, I get the same result. But if I remove them, the program runs and exits normally. What's the problem about allocating memory in child process? Or I use them in the wrong way? My environment is : OSX 10.8.3 Processor Intel Core i7, SBCL 1.0.55.0-abb03f9, cffi_0.10.7.1 installed from quicklisp Thank you very much!
On Wed, Mar 20, 2013 at 5:48 PM, agile software <agilesoftware@gmail.com> wrote:
I have tried other memory allocation macros, I get the same result. But if I remove them, the program runs and exits normally.
This is likely to be unrelated to CFFI itself. I suggest you convert your test case to plain SB-ALIEN -- you can get most of the way there simply by macro-expanding your DEFCFUNs, etc -- and report the issue to the SBCL developers. Let us know if you need help with that. Cheers, -- Luís Oliveira http://r42.eu/~luis/
You're right! I try my test in CCL, it runs smoothly. I can fork many child processes to do networking without any problem. I will report it to the SBCL developers. Thanks On Thu, Mar 21, 2013 at 4:01 AM, Luís Oliveira <luismbo@gmail.com> wrote:
On Wed, Mar 20, 2013 at 5:48 PM, agile software <agilesoftware@gmail.com> wrote:
I have tried other memory allocation macros, I get the same result. But if I remove them, the program runs and exits normally.
This is likely to be unrelated to CFFI itself. I suggest you convert your test case to plain SB-ALIEN -- you can get most of the way there simply by macro-expanding your DEFCFUNs, etc -- and report the issue to the SBCL developers. Let us know if you need help with that.
Cheers,
-- Luís Oliveira http://r42.eu/~luis/
participants (2)
-
agile software
-
Luís Oliveira