I understand that there are system calls to provide access to features that are prohibited in user space, for example, when accessing the hard drive using the read() system call. I also understand that they are abstracted out by the user mode layer in the form of library calls, such as fread() , to ensure compatibility between the equipment.
So, from the point of view of application developers, we have something like:
//library //syscall //k_driver //device_driver fread() -> read() -> k_read() -> d_read()
My question is: what prevents me from inserting all the instructions in the fread() and read() functions directly into my program? The instructions are the same, so should the processor behave the same? I have not tried, but I believe that this does not work for some reason, I am missing. Otherwise, any application can get arbitrary work in kernel mode.
TL DR: What allows system calls in kernel mode 'enter' that cannot be copied by the application?
lynks source share