Re: check if memory is accessible



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.

--
.



Relevant Pages

  • Re: mfs and vnconfig questions out of curiosity
    ... Upon unmount of the FS, the regular file will stay there, ... Presumably this works with virtual memory and lazy ... Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. ...
    (freebsd-stable)
  • Re: Taint mode & user supplied file names
    ... want to make sure that a user is not for instance printing a socket or some ... part of the memory. ... if it is not a regular file. ... popular Perl-based forum system accidentally let remote users retrieve ...
    (perl.beginners)
  • Re: system calls
    ... Error found!: Cannot allocate memory ... As I said in my reply to Keith, you should only print errno if ... The c program seems to keep the memory locked up until it exits ... you can release it by calling free() before ...
    (comp.unix.shell)
  • Re: Help! Shared memory is getting deleted after process is killed
    ... memory created. ... Also, I am getting the errno as ENOENT, which means ... shmId = shmget; ...
    (comp.os.linux.development.apps)
  • Re: Handling read() errors
    ... what errno values correspond to these cases? ... the what kind of object you're reading from - if you're ... doesn't have enough memory you may get ENOBUFS or ENOMEM. ...
    (comp.unix.programmer)