Вопрос

I've been programming x86 Assembly and C for some time in university now, and upon this day, I couldn't get my head around one thing: Who stops me from developing a program that writes values to 0x0 or other addresses that, by their address values, seem to be 'important' for my running system?

Who guarantees that, first of all, I am able to do that (I am able to do this, right?) and second of all, no other process misbehaves in case it was actually using 0x0 or any other address?

How is this managed?

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

Решение

Two different processes on a unix-like system will not have a shared memory address space. There will also be a difference between "user space" (where the process can read and write, with wild abandon) and "kernel space", where the process will most probably be able to neither read nor write, but may be able to call functions (depending on the exact syscall convention on the hardware architecture, this could be done using call-gates, interrupts or possibly other mechanisms).

Two processes, A and B, may attempt to both write to address 0x800000 in their local address space, with one write ending up being written to (physical) memory location 0x100 and the other to (physical) memory location 0x3000, depending on exactly how the kernel has decided to map virtual address space onto physical address space.

There are systems where this is not true, however.

Другие советы

You can't write to protected address. Parts of memory are protected by kernel, and the protection is easy since every request must go through kernel. See this article: http://en.wikipedia.org/wiki/Kernel_(computing)

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