Peter Miller <pmil...@opensource.org.au> writes:

> Here is a fun puzzle to kick off the new year...

[...]

> Is there a simple way (preferably a single system call) to discover if
> a user space memory range (rather than a C string) is all valid?

I believe you already know, or could cache, the system page size.
On that basis, mincore should be sufficient: round the pointer to the
start of the next page down, pass an appropriate length, and consider
ENOMEM to reflect invalid memory.

> E.g.  write(fildes, data, data_size) trying to discover whether or not
> (data,data_size) describes a piece of user memory none of which will
> segfault when accessed?
>
> Portable posix tests are better than linux-specific tests.

mincore isn't posix, but should be portable enough for most uses.

Regards,
        Daniel
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders

Reply via email to