You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include <stdio.h>
#include "ExtremeCMock.h"
static int test() {
int i = 10;
return i;
}
int test_mock() {
return (100);
}
int main(void) {
MOCK_FUNC(test, test_mock);
printf("test result is %d\n", test());
unmock_all();
printf("test result is %d\n", test());
return 0;
}
I use ExtremeCMock to mock self static function,console show "could not set protection on next page: Cannot allocate memory".I found the reason is function unprotect_address try to mprotect next page memory of real function. What is the purpose to mprotect next page memory?
static void unprotect_address(mocked_function_t * functionp) {
char *p;
long psize = sysconf(_SC_PAGESIZE);
for (p = (char *)functionp->addr; (unsigned long)p % psize; --p)
;
if (-1 == mprotect(p,128, PROT_WRITE|PROT_READ|PROT_EXEC)){
perror("could not set protection");
exit(-1);
}
if (-1 == mprotect(p+psize,128, PROT_WRITE|PROT_READ|PROT_EXEC)){ // why unprotect next page ?
perror("could not set protection on next page");
exit(-1);
}
my_memcpy(functionp->backup_function_data,functionp->addr,STUB_SIZE);
}
The text was updated successfully, but these errors were encountered:
Sorry, it's been a while since I looked at this and didn't realize I had an issue filed. In hi_jack_function, we overwrite the machine code at my_memcpy(functionp->addr, hijack_stub, sizeof(hijack_stub));. I unprotecting the next page just in case that over-write crosses into the next page.
I use ExtremeCMock to mock self static function,console show "could not set protection on next page: Cannot allocate memory".I found the reason is function unprotect_address try to mprotect next page memory of real function. What is the purpose to mprotect next page memory?
The text was updated successfully, but these errors were encountered: