Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2004-01

Linux syscalls

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Colin Western

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

Reply by email

Marco van de Voort
to Colin Western
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):

*BSD use carry indeed. However they also have 64-bit return values for lseek since a _long_ time, so this problem doesn't exist there as much.

Show quoted text 11 lines
/* 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. */

I'll see if I can fix it tonight.

Reply by email