Вопрос

It bothers me that there is no explanation anywhere I have searched for this question so here is what I know:

Software applications are loaded into memory when executed The application will use kernel's system calls such as allocating memory If the software application is converted to binary and so is the kernel, both in memory, how do they communicate with each other at the low level?

There are surely a lot of gaps in my knowledge so what I can assume is that the application is compiled to code the kernel can understand and not directly converted to machine code. Anyone knowledgeable enough to explain this?

Это было полезно?

Решение

The details depend heavily on the specific operating system and architecture that you're asking about, but, in general, userspace applications can make a system call by performing some specific operation that causes a CPU interrupt, causing execution to jump to the kernel. The application will have stored some data in registers or on the stack which indicates what the desired system call and arguments are, and the results are passed back similarly when the system call is complete.

For example, for a 32-bit x86 Linux system, the designated operation to perform a system call is int 0x80. When an application wants to perform a system call, it places the ID of the system call in eax, and stores up to six arguments in ebx, ecx, edx, esi, edi, and ebp (in that order). Once the system call is complete, its result is stored in eax.

In most situations, the code which makes a system call is stored in a special page of data mapped by the kernel near the top of memory. This page contains optimized code which can be called by libc. (Thus, your code never needs to call into the kernel directly — this is all handled by the libc functions which wrap system calls, like read() and write().) For more information, see "What are vdso and vsyscall".

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top