Skip to content

Commit 992cda2

Browse files
committed
Deduplicate a macro
1 parent a4658d3 commit 992cda2

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/iso_alloc_sanity.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ int32_t _sane_sampled;
1818
uint8_t _sane_cache[SANE_CACHE_SIZE];
1919
_sane_allocation_t _sane_allocations[MAX_SANE_SAMPLES];
2020

21+
#if MEMCPY_SANITY || MEMSET_SANITY
22+
#define MEM_SANITY_CHK(p) (user_pages_start <= p && (user_pages_start + ZONE_USER_SIZE) - n > p && n > zone->chunk_size)
23+
#endif
24+
2125
#if UNINIT_READ_SANITY
2226
pthread_t _page_fault_thread;
2327
struct uffdio_api _uffd_api;
@@ -278,8 +282,6 @@ INTERNAL_HIDDEN void *_iso_alloc_sample(const size_t size) {
278282

279283
#if MEMCPY_SANITY
280284

281-
#define MEMCPY_SANITY_CHK(p) (user_pages_start <= p && (user_pages_start + ZONE_USER_SIZE) - n > p && n > zone->chunk_size)
282-
283285
INTERNAL_HIDDEN void *__iso_memcpy(void *restrict dest, const void *restrict src, size_t n) {
284286
char *p_dest = (char *) dest;
285287
char const *p_src = (char const *) src;
@@ -302,14 +304,14 @@ INTERNAL_HIDDEN void *_iso_alloc_memcpy(void *restrict dest, const void *restric
302304
iso_alloc_zone_t *zone = search_chunk_lookup_table(dest);
303305
void *user_pages_start = UNMASK_USER_PTR(zone);
304306

305-
if(MEMCPY_SANITY_CHK(dest)) {
307+
if(MEM_SANITY_CHK(dest)) {
306308
LOG_AND_ABORT("Detected an out of bounds write memcpy: dest=0x%p (%d bytes) src=0x%p size=%d", dest, zone->chunk_size, src, n);
307309
}
308310

309311
zone = search_chunk_lookup_table(src);
310312
user_pages_start = UNMASK_USER_PTR(zone);
311313

312-
if(MEMCPY_SANITY_CHK(src)) {
314+
if(MEM_SANITY_CHK(src)) {
313315
LOG_AND_ABORT("Detected an out of bounds read memcpy: dest=0x%p src=0x%p (%d bytes) size=%d", dest, src, zone->chunk_size, n);
314316
}
315317
}
@@ -320,8 +322,6 @@ INTERNAL_HIDDEN void *_iso_alloc_memcpy(void *restrict dest, const void *restric
320322

321323
#if MEMSET_SANITY
322324

323-
#define MEMSET_SANITY_CHK(p) (user_pages_start <= p && (user_pages_start + ZONE_USER_SIZE) - n > p && n > zone->chunk_size)
324-
325325
INTERNAL_HIDDEN void *__iso_memset(void *dest, int b, size_t n) {
326326
char *p_dest = (char *) dest;
327327

@@ -337,7 +337,7 @@ INTERNAL_HIDDEN void *_iso_alloc_memset(void *dest, int b, size_t n) {
337337
iso_alloc_zone_t *zone = search_chunk_lookup_table(dest);
338338
void *user_pages_start = UNMASK_USER_PTR(zone);
339339

340-
if(MEMSET_SANITY_CHK(dest)) {
340+
if(MEM_SANITY_CHK(dest)) {
341341
LOG_AND_ABORT("Detected an out of bounds write memset: dest=0x%p (%d bytes) size=%d", dest, zone->chunk_size, n);
342342
}
343343
}

0 commit comments

Comments
 (0)