Subject: lseek again
To: Lennart Augustsson <augustss@cs.chalmers.se>
From: J.T. Conklin <conklin@ngai.kaleida.com>
List: current-users
Date: 03/31/1994 10:05:45
Lennart> I'll correct myself on the lseek system call. The problem
Lennart> is (of course) not in the kernel, but in libc. The cerror
Lennart> routine (where you jump when system call fails) only sets
Lennart> %eax to -1, not %edx.
Indeed -- lseek is an (the?) oddball among syscalls because it returns
a off_t instead of an int. We got away with it when off_t == long
because sizeof(long) == sizeof(int).
On the iX86, we could change cerror to always clear %edx before
returning; but then every other syscall would waste n-cycles (1 for
the i486 & i586, 2 for the i386).
Due to function return conventions, it may be impossible to use a
similar hack in cerror for other architectures. With that in mind, a
better solution may be to provide a custom implementation in
libc/arch/i386/sys that sets errno itself instead of jmp'ing to
cerror. Perhaps something like this:
#include "SYS.h"
.globl _errno
ENTRY(lseek)
movl $(SYS_lseek),%eax
LCALL(7,0)
jc 2f
ret
2:
#ifdef PIC
PIC_PROLOGUE
movl PIC_GOT(_errno),%ecx
PIC_EPILOGUE
movl %eax,(%ecx)
#else
movl %eax,_errno
#endif
xorl %edx,%edx
movl $-1,%eax
ret
--jtc
------------------------------------------------------------------------------