How to test if an address is readable in linux userspace app

后端 未结 1 1271
無奈伤痛
無奈伤痛 2020-12-18 18:52

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

相关标签:
1条回答
  • 2020-12-18 19:39

    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.

    0 讨论(0)
提交回复
热议问题