Re: Function to verify a virtual address?

From: Måns Rullgård (mru_at_inprovide.com)
Date: 03/23/05


Date: Wed, 23 Mar 2005 19:37:41 +0100


"Timur Tabi" <nospam_timur@tabi.org> writes:

> Is there a function that can verify a particular virtual address (or
> preferably, a range of virtual addresses) is valid for the current
> process? By valid, I mean that the process can read from that address
> without causing a segfault.

There is such explicit function. Instead, you can use a system call
like access(), and check for EFAULT. Quite often, mincore() is
mentioned in response to this question. mincore() does not do what
you want. It tells whether a page is resident in RAM, as opposed to
being swapped to disk. The man page doesn't say what it does with
unmapped pages.

That said, if you ever end up with pointers you don't know for sure
are valid, you have a design problem. There are many ways for a
pointer to be invalid in non-detectable ways, and it is use of these
pointers that causes serious trouble.

-- 
Måns Rullgård
mru@inprovide.com


Relevant Pages

  • Re: teaching a child - console or GUI
    ... >> possible to set up some pretty fancy 'accelerators' ... disk under a file name that is ... ... or are they really a bunch of pointers ... You mean that you had to be convinced of the 'CD in RAM' approach? ...
    (comp.lang.pascal.delphi.misc)
  • Re: How to send or copy malloc() memory to heard disk
    ... memory to heard disk because some times both ram and swap memory is not ... Rob Thorpe's comment regarding pointers is the most salient: ... and is glacial in comparision to RAM or cache. ...
    (comp.programming)
  • Execute a program only from memory? RAMDisk?
    ... I would like to execute a program *only* from RAM. ... *never saved to the actual disk* - and then ... Any comments or pointers are appreciated. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: teaching a child - console or GUI
    ... >> Are these objects very complex, or are they really a bunch of pointers ... >> One can hold a lot of those on disk ... ... Sure they do - however since memory is finite ... lists of pointers on disk, extract files of frequent search fields in ...
    (comp.lang.pascal.delphi.misc)
  • Re: Garbage collection
    ... "I *could* store pointers in disk and read it later, ... or not being allowed to use dynamically-allocated memory (I didn't ...
    (comp.lang.c)