Hacker News new | past | comments | ask | show | jobs | submit login
Write a System Call (2016) (brennan.io)
58 points by marcodiego on Aug 29, 2021 | hide | past | favorite | 5 comments



It should be noted that there is generally not really any reason to do this, and you should especially not do this to implement some vendor specific quirk.

I posted this nice, real life example here back in February: https://twitter.com/RichFelker/status/1357733309737021444

Even in the example of the `sys_stephen` syscall from November 2016, it already clashes with the syscall number of `sys_leftpad`, proposed upstream in April 2016[1].

[1] https://lkml.org/lkml/2016/3/31/1109


> Unlike my previous articles on kernel development, implementing a system call is not something you can do in a kernel module.

Not with that attitude ;)


Can anyone help me understand why transitioning to kernel mode is architecture-dependent? I’m not clear on why the linux system call kernel entry code in arch/x86/entry/common.c has to be in assembly, instead of C.


The mode is actually tracked/enforced by the CPU but the implementation differs per architecture. For example:

> The hardware severely restricts the ways in which control can be passed from one ring to another, and also enforces restrictions on the types of memory access that can be performed across rings. Using x86 as an example, there is a special gate structure which is referenced by the call instruction that transfers control in a secure way.

https://en.wikipedia.org/wiki/Protection_ring#Implementation...


transitioning to kernel mode requires a context switch, which is inherently a cpu operation, i.e it works differently on different architectures.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: