handle syscall's return codes more accurate
This commit is contained in:
+17
-7
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "context.h"
|
||||||
|
|
||||||
int32_t decode_sleb128(uint8_t *sleb128)
|
int32_t decode_sleb128(uint8_t *sleb128)
|
||||||
{
|
{
|
||||||
@@ -117,12 +118,21 @@ unsigned getSLEB128Size(int64_t Value)
|
|||||||
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
bool is_pointer_valid(void *p)
|
#include <errno.h>
|
||||||
|
|
||||||
|
int pst_pointer_valid(void *p)
|
||||||
{
|
{
|
||||||
/* get the page size */
|
long page_size = sysconf(_SC_PAGESIZE);
|
||||||
size_t page_size = sysconf(_SC_PAGESIZE);
|
if(page_size < 0) {
|
||||||
/* find the address of the page that contains p */
|
pst_log(SEVERITY_ERROR, "%s: Failed to determine page size");
|
||||||
void *base = (void *)((((size_t)p) / page_size) * page_size);
|
return EFAULT;
|
||||||
/* call msync, if it returns non-zero, return false */
|
}
|
||||||
return msync(base, page_size, MS_ASYNC) == 0;
|
|
||||||
|
void *aligned = (void *)((((long)p) / page_size) * page_size);
|
||||||
|
//void *aligned = (void *)((uintptr_t)p & ~(page_size - 1));
|
||||||
|
if(msync(aligned, page_size, MS_ASYNC) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (errno == ENOMEM ? EINVAL : EFAULT);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -21,6 +21,6 @@
|
|||||||
|
|
||||||
int32_t decode_sleb128(uint8_t *sleb128);
|
int32_t decode_sleb128(uint8_t *sleb128);
|
||||||
uint32_t decode_uleb128(uint8_t *uleb128);
|
uint32_t decode_uleb128(uint8_t *uleb128);
|
||||||
bool is_pointer_valid(void *p);
|
int pst_pointer_valid(void *p);
|
||||||
|
|
||||||
#endif // __PST_COMMON_H__
|
#endif // __PST_COMMON_H__
|
||||||
|
|||||||
Reference in New Issue
Block a user