8

I ran across this strangeness the other day.

_llseek takes a 64 bit value in ecx:edx ; however ftruncate64 takes a 64 bit value in edx:ecx.

I see that it is; and I can't understand the decision process that made it be.

My system still has a manpage for _llseek but no manpage for ftruncate64. Furthermore, the manpage for _llseek shows the wrong argument types being passed. strace got it right.

Note that these system calls only exist on 32 bit Linux, not 64 bit Linux. (On x64 you can actually call them using the int 80h interface, which you should not be doing unless you are a 32 bit process for reasons that are entirely non-obvious.)

4
  • 2
    System designers sometimes do things are not consistent with what their predecessors did. Commented 2 days ago
  • @dave: Perhaps so; I had to double check something really quickly. As far as I can tell both of these are at least as old as the (potentially late) 2.0 kernel era. Commented 2 days ago
  • 1
    Unless the designers documented their reasons for making their choices, any answer is likely to be opinion based. Commented 2 days ago
  • 1
    Just because someone may post an uninformed opinionated post, that isn't to say that someone who actually knows the answer may also post the real answer. For that reason, I vote to left the question open. Commented 2 days ago

1 Answer 1

14

Under the linux x86 syscall ABI, the syscall is in register EAX, the first parameter is in EBX, the second in ECX, the third in EDX.

Your man page probably says something like:

_syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, loff_t *, res, uint, wh);

int _llseek(unsigned int fd, unsigned long offset_high, unsigned long offset_low,
           loff_t * result, unsigned int whence);

That is, the 64-bit offset is split into two parts, the high word in ECX, the low word in EDX.

_llseek was added sometime around 1995. ftruncate64 was added sometime around 2000. By then there were more 64-bits calls (pread64, pwrite64, stat64, etc) and the convention for handling 64-bit arguments had changed. Perhaps you can find a spirited discussion on the lkml.

Addendum: llseek was added in linux 1.1.46, circa August 31 1994 by Remy CARD

5
  • _syscall5 is not how it would have been said in 2000. All i386 system calls used the same variadic entry point. (Arguments were passed on the stack to the syscall function, making this dirt simple.) Commented 2 days ago
  • Oops; ftruncate64 predates lkml archives. Commented 2 days ago
  • In any case, you did good work getting the approximate times of addition. Commented 2 days ago
  • 2
    here is some 1996 _llseek code using _syscall5 Commented 2 days ago
  • 1
    Ah; I only know how libc did it. _llseek -> call syscall (which was a local function, not the exported library function), which did math on its return address to generate the system call number. Commented yesterday

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.