GNU bug report logs -
#21694
'clone' syscall binding unreliable
Previous Next
Reported by: ludo <at> gnu.org (Ludovic Courtès)
Date: Fri, 16 Oct 2015 20:41:02 UTC
Severity: normal
Done: ludo <at> gnu.org (Ludovic Courtès)
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
ludo <at> gnu.org (Ludovic Courtès) writes:
> Looking at (guix build syscalls) though, I see an ABI mismatch between
> our definition and the actual ‘syscall’ C function, and between our
> ‘clone’ definition and the actual C function.
Good catch! However, please see below.
> This leads to the attached patch, which also fixes the above problem for me.
>
> diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
> index 80b9d00..f931f8d 100644
> --- a/guix/build/syscalls.scm
> +++ b/guix/build/syscalls.scm
> @@ -322,10 +322,16 @@ string TMPL and return its file name. TMPL must end with 'XXXXXX'."
> (define CLONE_NEWNET #x40000000)
>
> ;; The libc interface to sys_clone is not useful for Scheme programs, so the
> -;; low-level system call is wrapped instead.
> +;; low-level system call is wrapped instead. The 'syscall' function is
> +;; declared in <unistd.h> as a variadic function; in practice, it expects 6
> +;; pointer-sized arguments, as shown in, e.g., x86_64/syscall.S.
> (define clone
> (let* ((ptr (dynamic-func "syscall" (dynamic-link)))
> - (proc (pointer->procedure int ptr (list int int '*)))
> + (proc (pointer->procedure long ptr
> + (list long ;sysno
> + unsigned-long ;flags
'long' and 'unsigned long' might not be the same size as a pointer.
Better to use 'size_t' for both of these. While not strictly guaranteed
to be the same size as a pointer, in practice they should be the same
except on architectures with segmented memory models.
What do you think?
Mark
PS: 'intptr_t' and 'uintptr_t' would be best, but they are optional in
C99 and not in (system foreign). 'ptrdiff_t' would be better, but
was not available in (system foreign) before guile-2.0.9.
This bug report was last modified 9 years and 264 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.