Discussion:
check memory mapping
Emmanuel Dreyfus
2014-08-22 09:59:16 UTC
Permalink
Hi

Is there a way for a process to check whether a given address in mmeory
is accessible, without triggering a signal?

There is mincore(), but it jus says wether it is already in resident
memory, not if accessing the address will swap it in or cause a SIGSEGV.
--
Emmanuel Dreyfus
***@netbsd.org
Christos Zoulas
2014-08-22 13:47:53 UTC
Permalink
Post by Emmanuel Dreyfus
Hi
Is there a way for a process to check whether a given address in mmeory
is accessible, without triggering a signal?
There is mincore(), but it jus says wether it is already in resident
memory, not if accessing the address will swap it in or cause a SIGSEGV.
You could access it via system call like read(2) from /dev/zero to test
if it is writable, or write(2) to /dev/null for readability.

christos
Emmanuel Dreyfus
2014-08-22 13:53:16 UTC
Permalink
Post by Christos Zoulas
You could access it via system call like read(2) from /dev/zero to test
if it is writable, or write(2) to /dev/null for readability.
I retain the read test. The write test is troublesome because it modify memory
if it is accessible.
--
Emmanuel Dreyfus
***@netbsd.org
Emmanuel Dreyfus
2014-08-23 11:45:55 UTC
Permalink
Post by Emmanuel Dreyfus
Post by Christos Zoulas
You could access it via system call like read(2) from /dev/zero to test
if it is writable, or write(2) to /dev/null for readability.
I retain the read test. The write test is troublesome because it modify memory
if it is accessible.
The read test works very well, but what about a write test that does not
really change memory?
--
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
***@netbsd.org
Christos Zoulas
2014-08-23 11:50:07 UTC
Permalink
On Aug 23, 1:45pm, ***@netbsd.org (Emmanuel Dreyfus) wrote:
-- Subject: Re: check memory mapping

| Emmanuel Dreyfus <***@netbsd.org> wrote:
|
| > > You could access it via system call like read(2) from /dev/zero to test
| > > if it is writable, or write(2) to /dev/null for readability.
| >
| > I retain the read test. The write test is troublesome because it modify memory
| > if it is accessible.
|
| The read test works very well, but what about a write test that does not
| really change memory?

You write the pointer to a file, if the write was successful, you can read
the contents of the pointer. You rewind the file, and read from it into
the pointer. If successful, you can write to the pointer and since you
read what you just wrote, the memory contents are the same.

christos
Emmanuel Dreyfus
2014-08-23 12:50:22 UTC
Permalink
Post by Christos Zoulas
You write the pointer to a file, if the write was successful, you can read
the contents of the pointer. You rewind the file, and read from it into
the pointer. If successful, you can write to the pointer and since you
read what you just wrote, the memory contents are the same.
The location is set to PROT_WRITE using mprotect(), hence I cannot read
from it.

Some context information: this is to pass a regression test suite for a
NetBSD implemenation of Linux's libaio. I do it in user space on top of
librt while Linux does it in kernel. Hence some test checks that a
system call (which is a function for me) returns EFAULT depending of
memory protection.
--
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
***@netbsd.org
Christos Zoulas
2014-08-23 15:14:41 UTC
Permalink
On Aug 23, 2:50pm, ***@netbsd.org (Emmanuel Dreyfus) wrote:
-- Subject: Re: check memory mapping

| Christos Zoulas <***@zoulas.com> wrote:
|
| > You write the pointer to a file, if the write was successful, you can read
| > the contents of the pointer. You rewind the file, and read from it into
| > the pointer. If successful, you can write to the pointer and since you
| > read what you just wrote, the memory contents are the same.
|
| The location is set to PROT_WRITE using mprotect(), hence I cannot read
| from it.
|
| Some context information: this is to pass a regression test suite for a
| NetBSD implemenation of Linux's libaio. I do it in user space on top of
| librt while Linux does it in kernel. Hence some test checks that a
| system call (which is a function for me) returns EFAULT depending of
| memory protection.

Wel, I think that the conversion to uvm lost kernacc(9) and useracc(9) which
would be exactly want you want. I think FreeBSD has them.

christos

Loading...