How can I use mmap to get the start and end address of a function? I want to execute the function and then call __clear_cache. To clear everything from the cache that has just been executed. clear_cache requires the start and end address.
One function in my code represents a test case, I need to clear the cache in order to benchmark correctly. I am using Linux 3.7 and C.
I need to use mmap and not malloc as said here:
How clear and invalidate ARM v7 processor cache from User Mode on Linux 2.6.35
Currently I have just made an mmap that is 32kb in size, the size of my cache. But how to get the start and end address and map it to a particular function?
I have done this
//In the header
extern void __clear_cache (char*, char*);
//Function pointer to get address. typedef void (*_func_pointer) (void);
in the .c
_func_pointer = test_func;
uint32_t * map_to_function = mmap(
NULL,
32768, // 32kb -- Whole Cache.
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0);
if (map_to_function == MAP_FAILED) {
printf("Could not mmap a memory buffer with the proper permissions.\n");
return -1;
}
test_func = (_func_pointer ) map_to_function ;
//Run Test case 1:
Some how run function 1 and get start and end address.
__clear_cache((char*)start_address, (char*)end_address);
Thanks for any help