For debugging purposes I need to test a pointer to see if it points to a valid readable page. Currently I am parsing /proc/[pid]/maps to see if the address is mapped ok, but this seems a bit long-winded. Is there a better way? Thanks.
The canonical way is to use the write()
system call to read from the page (writing to a dummy pipe()
file descriptor). Instead of faulting, it will return -1
with errno == EFAULT
if the buffer passed to write()
is unreadable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.