Subject: lseek again
To: Lennart Augustsson <>
From: J.T. Conklin <>
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

		movl $(SYS_lseek),%eax
		jc 2f
	#ifdef PIC
		movl	PIC_GOT(_errno),%ecx
		movl	%eax,(%ecx)
		movl	%eax,_errno
		xorl	%edx,%edx
		movl	$-1,%eax