3 ms·
> I could also make up my own convention for system calls, but that seems unnecessary. Is there possibly a utility in at least using your own interrupt for sys
by dnautics 13y ago
> I could also make up my own convention for system calls, but that seems unnecessary.
Is there possibly a utility in at least using your own interrupt for system calls, so that you could implement a linux compatibility layer down the line? Linux syscalls are a little bit odd relative to what you would generally do in the modern era of tons of memory.
- jvns 13y agoMaybe! Why are Linux syscalls odd? How would you do it instead?
- Locke1689 13y agoGiven that you're probably writing an x86 kernel, I'd suggest looking into the SYSCALL/SYSENTER instructions.
- dnautics 13y agoI could be wrong about this but if my memory serves me correctly, linux syscalls put the first argument in AX, second argument in BX, third argument in CX, and fourth argument in DX. BSD syscalls do the saner thing and just put everything on the stack.
- darkf 13y ago>BSD syscalls do the saner thing and just put everything on the stack. Is that not slower (requiring a memory store and a SUB, then a load and an ADD to pop) than just MOVing a register?
- KMag 13y agoThere's probably more utility in implementing ptrace. One could then write a program that spawns off a ptrace'd child process and intercepts all syscalls and translates them from Linux syscalls to your OS's syscalls. As a bonus, ptrace would allow you to host a slightly modified copy of your kernel in userspace, similar to User-Mode Linux. (Or you could modify a copy of User-Mode Linux to run on top of your kernel, as a heavier weight version of the syscall translation layer mentioned above.) Other advantages of implementing ptrace include some debugging and sandboxing tools. Note, however, that if sandboxing a multithreaded process, if the sandbox intercepts a syscall where some of the arguments aren't in CPU regisetrs, the sandbox needs to pause all of the other threads in the sandboxed process, otherwise they may modify "safe" syscall arguments to be "unsafe" syscall arguments between when the sandbox inspects them and when the kernel actually processes them.