Any one can see why the following ifs, lines 3279-3285 in xv6-rev6 code, are used:
int num;
num = proc−>tf−>eax;
if (num >= 0 && num < SYS_open && syscalls[num]) {
proc−>tf−>eax = syscalls[num]();
} else if (num >= SYS_open && num < NELEM(syscalls) && syscalls[num]) {
proc−>tf−>eax = syscalls[num]();
} else {...}
and not just:
int num;
num = proc−>tf−>eax;
if (num >= 0 && num < NELEM(syscalls) && syscalls[num]) {
proc−>tf−>eax = syscalls[num]();
} else {...}
My original answer is below, which is partially right.
I took the liberty of contacting the authors at MIT and received the following response:
So the two parts were different and, when they were changed to be the same, the modification simply didn't merge the two bits back together.
No, those two bits of code are equivalent.
It may be that at some point the calls to
syscalls[?]()
was different somehow, either with parameters or return locations but that's not the case now.There may also have been a gap of some sort in there, something which may be supported by the fact there's a blank line at line 3115:
This is the entire contents of
syscalls.h
and the blank line is somewhat suspicious.There's no obvious functional grouping - though all the ones 15 and above seem to be related to file system manipulation,
SYS_read
andSYS_fstat
are in the first group.Maybe you should contact the authors to ask them (
6.828-staff at pdos.csail.mit.edu
).I know (since I have the book) that it's not carried over from the Lions-era code since that has no such gaps in the list - they're also in a different order as well, with read and write next to each other for example.