I need to test if memory address is readable, so I searched and found this question: How to test if an address is readable in linux userspace app As user @caf stated:
The canonical way is to use the write() system call to read from the page (writing to a dummy pipe() file descriptor).
Unfortunatelly he didn't provide any code example, and I can't comment (low reputation) nor send him a message (at least I don't know how).
EDIT
Can't I just omit creating the pipe by doing something like that?
int result = write(0, addr, 1);
@Mats Petersson: I'm trying to analyze and change a function after already loading it to memory using function pointer (I'm incrementing the pointer and copying its value byte by byte), so to determine whether it's still this function i need to know if the memory is writeable and readable (it's a little stupid thing to do, I know). Anyhow I'd like to not change my program's memory reading/writing privileges, so what you've said might be a problem.
EDIT 2 @Damon: so is there any other sure way to do this?