I'm guessing the answer is no, but can you install a signal handler and suck it and see?
Benno On Tue, Jan 13, 2009 at 7:00 PM, Peter Miller <pmil...@opensource.org.au> wrote: > Dear Coders, > > Here is a fun puzzle to kick off the new year... > > > Background: > > when libexplain goes to print string arguments, it takes care to avoid > segfaults. > > Strings are relatively easy to check for valid-ness, and libexplain uses > > lstat(s, &st) < 0 && errno == EFAULT > > to test if a string pointer is valid. Obviously, if (the string is not > a path && the string is longer than PATH_MAX) it's not useful, but that > usually does not happen. This is certainly easier than trapping > SIGSEGV, doing a strlen, and then restoring SIGSEGV. > > > The Puzzle: > > 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? 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. > > Using a file descriptor may not be possible (library client could have > run out), so read(2) is tempting but no banana. > > > -- > Regards > Peter Miller <pmil...@opensource.org.au> > /\/\* http://www.canb.auug.org.au/~millerp/ > > PGP public key ID: 1024D/D0EDB64D > fingerprint = AD0A C5DF C426 4F03 5D53 2BDB 18D8 A4E2 D0ED B64D > See http://www.keyserver.net or any PGP keyserver for public key. > _______________________________________________ > coders mailing list > coders@slug.org.au > http://lists.slug.org.au/listinfo/coders > _______________________________________________ coders mailing list coders@slug.org.au http://lists.slug.org.au/listinfo/coders