Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I know that this is not as efficient as "real" system calls. However, I was thinking whether this would be elegant or not. I am sure that this is already implemented somewhere.
The page-fault handler would recognize the syscall number the user is trying to store at this "illegal" address. With C programming language, it is not very easy to recognize the call number portably. What about the parameters? Putting them to "parameter passing" space?
All the implementation details aside, what do you think about this in general? System calls could be triggered without any platform-specific opcodes. Programs could see system services like they see memory-mapped devices.
Last edited by Antti on Tue Jul 16, 2013 3:28 am, edited 1 time in total.
- No concurrent system calls (race conditions).
- Significantly slower system calls.
- Actual pagefaults may be mistaken for system calls - try free(0) and it might just access that address
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
I think you are addressing a problem that doesn't exist. Some parts of an OS are always going to be non-portable; for example the actual paging mechanism to implement your system would differ on different processors (as, almost certainly, would the fake address used).
Until all computers use the same instruction set you aren't going to get binary compatibility of a kernel, so why focus on the system call mechanism in particular? It can be made portable except for a small amount of architecture-dependent code. I don't see that as being a problem.
Combuster wrote: ... try free(0) and it might just access that address
According to ISO-IEC 9899 (N1124) the behavior is; (7.20.3.2)
The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs.
That gives the next problem, a pagefault doesn't show you the value that was attempted to be read or written, only the target address and the instruction that caused it. The pagefault handler couldn't sanely access the character value.
One could have a sys call page-fault address per thread.
And which portable mechanism are you going to use to get that address?
According to ISO-IEC 9899 (N1124) the behavior is
I must have gotten used to broken implementations.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
One could have a sys call page-fault address per thread.
And which portable mechanism are you going to use to get that address?
Assuming you get the first one, when creating a process, it's just a matter of implementing the allocation of a sys call page-fault address as a part of the create thread method, I guess.
Assuming that threads are created from old threads, and that you're able to bootstrap 1 thread.
// Skeen
// Developing a yet unnamed microkernel in C++14.
Combuster wrote:That gives the next problem, a pagefault doesn't show you the value that was attempted to be read or written, only the target address and the instruction that caused it. The pagefault handler couldn't sanely access the character value.
What one could do is to use two pages per thread to support sys calls. One to pass all arguments and such, and one to trigger the sys call. First one being present, last one not being.
However then writing to the non-present page would be somewhat alike doing a software interrupt, as it would just be a trap into the kernel.
Last edited by skeen on Tue Jul 16, 2013 4:59 am, edited 1 time in total.
// Skeen
// Developing a yet unnamed microkernel in C++14.
Combuster wrote:That gives the next problem, a pagefault doesn't show you the value that was attempted to be read or written, only the target address and the instruction that caused it.
A real problem. I already mentioned it in the original post (when using C). In assembly, something like "mov [address], eax" would be possible. Then the page-fault handler would have to take that eax value (or whatever register would be) and store it. However, it is starting to look like the traditional system calls. It does not seem good if we had to care how the value is written. The simplicity and elegancy are lost.
Maybe this is not possible to implement on x86-platforms but it does not mean the idea is totally bad.
Well, you could write an instruction emulator to "parse" the parameter from the faulting instruction and then skip the instruction before reentering userspace. This way you also get rid of the race conditions.
skeen wrote:Assuming you get the first one, when creating a process, it's just a matter of implementing the allocation of a sys call page-fault address as a part of the create thread method, I guess.
And then what? Add an additional argument to every possible function in the app so you can pass it through?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]