[fpc-devel]Linux syscalls

Colin Western mftq75 at dsl.pipex.com
Sat Jan 24 11:19:57 CET 2004


I think there is a problem with testing the return values from linux 
syscalls; at least under i386 negative values can be OK. Looking at the 
glibc source I find:

     DO_CALL (syscall_name, args); 

     cmpl $-4095, %eax; 

     jae SYSCALL_ERROR_LABEL; 


rather than a simple test on the sign that is currently in 
rtl/linux/i386/syscalls.inc. There is a helpful comment explaining this 
(in glibc/sysdeps/unix/sysv/linux/i386/sysdeps.h):

/* Linux uses a negative return value to indicate syscall errors,
    unlike most Unices, which use the condition codes' carry flag.
 

    Since version 2.1 the return value of a system call might be
    negative even if the call succeeded.  E.g., the `lseek' system call
    might return a large offset.  Therefore we must not anymore test
    for < 0, but test for a real error by making sure the value in %eax
    is a real error number.  Linus said he will make sure the no syscall
    returns a value in -1 .. -4095 as a valid result so we can savely
    test with -4095.  */

Colin





More information about the fpc-devel mailing list