Re: check if memory is accessible
- From: John Reiser <jreiser@xxxxxxxxxxxx>
- Date: Mon, 24 Dec 2007 12:10:59 -0800
Does there exist an assembly instruction to check if a
particular memory is accessible
No.
On x86 the instruction LAR (Load Access Rights; 0x0F 0x02 /r)
gives some info about the segment, but nothing about the offset.
On all UNIX-like systems, the return value and errno from
write(fd, address, 1)
tells whether the user is permitted to *read* one byte from address,
if fd is a valid file descriptor that is open for writing.
A few purists are not pleased that this is so, and have deprecated
using this function call for the purpose of checking access privileges
to memory regions. However, it works.
On Linux, reading and parsing /proc/self/maps gives the required
information for ordinary memory pages (RAM or a regular file S_IFREG).
A page that is mapped to a hardware device other than ordinary memory
(or to a full page beyond the end of a regular file) can have "holes",
and accessing a hole might give SIGBUS.
--
.
- Prev by Date: Re: mmap(), MAP_SHARED, MAP_ANONYMOUS and sharing memory
- Next by Date: frame buffer device
- Previous by thread: Re: check if memory is accessible
- Next by thread: frame buffer device
- Index(es):
Relevant Pages
|