For an user process running in Linux 32-bits, any virtual address from 0xc0000000
upwards is illegal, because it belongs to the kernel. For Windows 32-bits without the /3G
boot switch, any virtual address equal or above 0x80000000
is illegal for the same reasons (if /3G
is used and the process executable file has the LARGE_ADDRESS
flag enabled, the boundary is at the same address as in Linux)
Without leaving Linux 32-bits, if you are able to walk through the page directory of your own process, you can take any virtual address ans see if it is mapped to somewhere within an actual physical page, and if so, which permissions does that page have.
Beware! as memory allocated with malloc()
is of course legal, but if you try to check its legality by peeling the directory page, you will find that almost all the allocated memory block appears as "not present", hence you would infer that the address is illegal. When a memory access is performed to a valid address within the block, and that address belongs to a still not present page, a page fault is triggered, but it does not become a segfault, but the kernel silently allocates actual memory to map the page which the accessed address belongs to, and reissues the instruction that first caused the page fault.
With a suitable device driver, a process can know about its own memory map and walk through its page directory. Of course, this is heavily implementation specific. See here for details.