introduce pointer dereference validation method

This commit is contained in:
2020-04-23 09:22:56 +04:00
parent 46bcfad427
commit 187032a773
2 changed files with 14 additions and 0 deletions
+12
View File
@@ -114,3 +114,15 @@ unsigned getSLEB128Size(int64_t Value)
return Size;
}
#include <sys/mman.h>
#include <unistd.h>
bool is_pointer_valid(void *p)
{
/* get the page size */
size_t page_size = sysconf(_SC_PAGESIZE);
/* find the address of the page that contains p */
void *base = (void *)((((size_t)p) / page_size) * page_size);
/* call msync, if it returns non-zero, return false */
return msync(base, page_size, MS_ASYNC) == 0;
}
+2
View File
@@ -9,6 +9,7 @@
#include <stdint.h>
#include <stdbool.h>
#define USE_LIBUNWIND
@@ -20,5 +21,6 @@
int32_t decode_sleb128(uint8_t *sleb128);
uint32_t decode_uleb128(uint8_t *uleb128);
bool is_pointer_valid(void *p);
#endif // __PST_COMMON_H__