1

im using this https://github.com/openjudge/sandbox project to control my program execution on server. I have done almost everything except i cant understand how part of sample code works. The part is:

int16_t abi32(int scno)
{
    assert((scno >= 0) && (scno < 1024));
#ifdef __x86_64__
    return (int16_t)(scno | (1 << 10));
#else /* __i386__ */
    return (int16_t)(scno);
#endif /* __x86_64__ */
}

...
const int16_t sc_safe[] =
{
    abi32(0), abi32(3), abi32(4), abi32(19), abi32(45), abi32(54),
    abi32(90), abi32(91), abi32(122), abi32(125), abi32(140), abi32(163),
    abi32(192), abi32(197), abi32(224), abi32(243), abi32(252),
#ifdef __x86_64__
    0, 1, 5, 8, 9, 10, 11, 12, 16, 25, 63, 158, 219, 231,
#endif /* __x86_64__ */
    -1, /* sentinel */
};

...

The sc_safe array is whitelist of syscalls and since they differ between os types, there is macros #ifdef x86_64. But why arent the 32 bit syscalls in #else branch and why should it work for 64bit os if 32bit syscall %eax is increased by 1024? Is it ignored that way or something??

Jānis Gruzis
  • 905
  • 1
  • 10
  • 25

0 Answers0