tags:

views:

40

answers:

2

I've to implement a char device, a LKM.

I know some basics about OS, but I feel I don't have the big picture.

In a C programm, when I call a syscall what I think it happens is that the CPU is changed to ring0, then goes to the syscall vector and jumps to a kernel memmory space function that handle it. (I think that it does int 0x80 and in eax is the offset of the syscall vector, not sure).

Then, I'm in the syscall itself, but I guess that for the kernel is the same process that was before, only that it is in kernel mode, I mean the current PCB is the process that called the syscall.

So far... so good?, correct me if something is wrong.

Others questions... how can I write/read in process memory?. If in the syscall handler I refer to address, say, 0xbfffffff. What it means that address? physical one? Some virtual kernel one?

+1  A: 

To read/write memory from the kernel, you need to use function calls such as get_user or __copy_to_user.

See the User Space Memory Access API of the Linux Kernel.

R Samuel Klatchko
A: 

You can never get to ring0 from a regular process.

You'll have to write a kernel module to get to ring0.

And you never have to deal with any physical addresses, 0xbfffffff represents an address in a virtual address space of your process.

zed_0xff
I meant that if I reference 0xbfffffff in the syscall handle that is in kernel space. What it means that address
fsdfa