 |
|
 |
|
|
 |
Find out the process address space |
 |
 |
|
|
01-23-04 10:01 PM
Hi there,
Is there a way to find out the process address space boundaries
(interms of addresses) programatically (in the user space only). Also
the start and end boundaries of different segments, if they can be
found out.
More precisely, I want to find out an authentic way by which I can
say a given address is invalid for this process (or for the current
process), and I get EFAULT kind of error if I use this address for
system calls like write,sigaction etc. Is there any existing library
routine exists which can do so. More wanted for Linux.
I hope I am clear in specifying my doubt.
TIA!
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
 |
Re: Find out the process address space |
 |
 |
|
|
|
|
 |
Re: Find out the process address space |
 |
 |
|
|
 |
|
 |
|
|
 |
Re: Find out the process address space |
 |
 |
|
|
01-23-04 10:01 PM
singhal_maneesh@yahoo.com (For-NG) writes:
quote:
> Is there a way to find out the process address space boundaries
> (interms of addresses) programatically (in the user space only). Also
> the start and end boundaries of different segments, if they can be
> found out.
No.
quote:
> More precisely, I want to find out an authentic way by which I can
> say a given address is invalid for this process (or for the current
> process), and I get EFAULT kind of error if I use this address for
> system calls like write,sigaction etc. Is there any existing library
> routine exists which can do so. More wanted for Linux.
Read the address. If you get a SIGSEGV, it wasn't valid. Relying on
being able to determine the validity of an address is bad design.
--
Måns Rullgård
mru@kth.se
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Find out the process address space |
 |
 |
|
|
01-23-04 10:01 PM
singhal_maneesh@yahoo.com (For-NG) writes:
quote:
> Is there a way to find out the process address space boundaries
> (interms of addresses) programatically (in the user space only). Also
> the start and end boundaries of different segments, if they can be
> found out.
No.
quote:
> More precisely, I want to find out an authentic way by which I can
> say a given address is invalid for this process (or for the current
> process), and I get EFAULT kind of error if I use this address for
> system calls like write,sigaction etc. Is there any existing library
> routine exists which can do so. More wanted for Linux.
Read the address. If you get a SIGSEGV, it wasn't valid. Relying on
being able to determine the validity of an address is bad design.
--
Måns Rullgård
mru@kth.se
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Find out the process address space |
 |
 |
|
|
01-23-04 10:01 PM
mjt <mjtobler@removethis_consultant.com> writes:
quote:
>
> ...hmmm. smells like homework ...
.. or possibly an mswindows programmer. If it is homework, someone
should have a word with the teacher.
--
Måns Rullgård
mru@kth.se
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Find out the process address space |
 |
 |
|
|
01-23-04 10:01 PM
In article <b0e1dd47.0311290416.10c8b8be@posting.google.com>,
singhal_maneesh@yahoo.com (For-NG) writes:quote:
> Hi there,
>
> Is there a way to find out the process address space boundaries
> (interms of addresses) programatically (in the user space only). Also
> the start and end boundaries of different segments, if they can be
> found out.
On Solaris, you can use procfs (the /proc filesystem) to do this.
Not tried on Linux, but I imagine you could do the same, although
the code required is likely to be different.
quote:
> More precisely, I want to find out an authentic way by which I can
> say a given address is invalid for this process (or for the current
> process), and I get EFAULT kind of error if I use this address for
> system calls like write,sigaction etc. Is there any existing library
> routine exists which can do so. More wanted for Linux.
Well, you found a way already -- try using the address with a system
call. A good system call for this purpose is mincore(2). Again, you
are not interested in knowing if a particular address is in or out
of 'core' (main store if you're a youngster;-), but you look to see
if you get EFAULT meaning the address you enquired about is invalid
in the process's address space. (Again, I'm not sure if Linux has
mincore(2) or not -- I'll leave you to check.)
--
Andrew Gabriel
Consultant Software Engineer
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Find out the process address space |
 |
 |
|
|
01-23-04 10:01 PM
In article <b0e1dd47.0311290416.10c8b8be@posting.google.com>,
singhal_maneesh@yahoo.com (For-NG) writes:quote:
> Hi there,
>
> Is there a way to find out the process address space boundaries
> (interms of addresses) programatically (in the user space only). Also
> the start and end boundaries of different segments, if they can be
> found out.
On Solaris, you can use procfs (the /proc filesystem) to do this.
Not tried on Linux, but I imagine you could do the same, although
the code required is likely to be different.
quote:
> More precisely, I want to find out an authentic way by which I can
> say a given address is invalid for this process (or for the current
> process), and I get EFAULT kind of error if I use this address for
> system calls like write,sigaction etc. Is there any existing library
> routine exists which can do so. More wanted for Linux.
Well, you found a way already -- try using the address with a system
call. A good system call for this purpose is mincore(2). Again, you
are not interested in knowing if a particular address is in or out
of 'core' (main store if you're a youngster;-), but you look to see
if you get EFAULT meaning the address you enquired about is invalid
in the process's address space. (Again, I'm not sure if Linux has
mincore(2) or not -- I'll leave you to check.)
--
Andrew Gabriel
Consultant Software Engineer
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Find out the process address space |
 |
 |
|
|
01-23-04 10:01 PM
mru@kth.se (Måns Rullgård) writes:
quote:
> Relying on
> being able to determine the validity of an address is bad design.
Not necessarily.
There are a few legitimate reasons why one would want to know. Such
as malloc debugger doing a memory sweep while searching for leaks.
In general, al kinds of "in-process debuggers" do care about address
space layout, and it's a pity Linux doesn't provide one.
In this thread another reason for "knowing" is given:
http://groups.google.com/groups?sel...%40BitWagon.com
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Find out the process address space |
 |
 |
|
|
01-23-04 10:01 PM
mru@kth.se (examnotes) writes:
quote:
>singhal_maneesh@yahoo.com (For-NG) writes:
quote:
[QUOTE]
>No.
In some OSes they can be found out; mincore() can be used to
probe the whole address space (only doable in 32 bit mode).
On Solaris, /proc/self/map has the info you need.
Making the code that uses this portable is hard and it
seems to indicate that you want to do other unportable
things like "MAP_FIXED" of self-specified addresses.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 01:15 PM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|