Skip to content

Commit

Permalink
core-helper: add null function to obfuscate (void *)0 values
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Ian King <[email protected]>
  • Loading branch information
ColinIanKing committed Dec 11, 2023
1 parent 866ebc3 commit b40b7ce
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
12 changes: 12 additions & 0 deletions core-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,18 @@ uint64_t stress_get_uint64_zero(void)
return g_shared->zero;
}

/*
* stress_get_uint64_zero()
* return null in way that force less smart
* static analysers to realise we are doing this
* to force a division by zero. I'd like to have
* a better solution than this ghastly way.
*/
void *stress_get_null(void)
{
return (void *)g_shared->zero;
}

/*
* stress_base36_encode_uint64()
* encode 64 bit hash of filename into a unique base 36
Expand Down
1 change: 1 addition & 0 deletions core-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extern WARN_UNUSED int stress_strcmp_munged(const char *s1, const char *s2);
extern WARN_UNUSED ssize_t stress_get_stack_direction(void);
extern WARN_UNUSED void *stress_get_stack_top(void *start, size_t size);
extern WARN_UNUSED uint64_t stress_get_uint64_zero(void);
extern WARN_UNUSED void *stress_get_null(void);
extern int stress_temp_filename(char *path, const size_t len, const char *name,
const pid_t pid, const uint32_t instance, const uint64_t magic);
extern int stress_temp_filename_args(stress_args_t *args, char *path,
Expand Down
4 changes: 2 additions & 2 deletions stress-mlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ static void stress_mlock_misc(stress_args_t *args, const size_t page_size, const
VOID_RET(int, shim_munlock((void *)(~(uintptr_t)0 & ~(page_size - 1)), page_size << 1));

VOID_RET(int, shim_mlock((void *)0, ~(size_t)0));
VOID_RET(int, munlock((void *)stress_get_uint64_zero(), ~(size_t)0));
VOID_RET(int, munlock((void *)stress_get_null(), ~(size_t)0));

VOID_RET(int, shim_mlock((void *)0, 0));
VOID_RET(int, munlock((void *)stress_get_uint64_zero(), 0));
VOID_RET(int, munlock((void *)stress_get_null(), 0));

#if defined(HAVE_MLOCKALL)
{
Expand Down
4 changes: 2 additions & 2 deletions stress-mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ static int stress_mmap_child(stress_args_t *args, void *ctxt)
/*
* Step #6, invalid unmappings
*/
(void)munmap(NULL, 0);
(void)munmap(NULL, ~(size_t)0);
(void)munmap(stress_get_null(), 0);
(void)munmap(stress_get_null(), ~(size_t)0);

/*
* Step #7, random choice from any of the valid/invalid
Expand Down
4 changes: 2 additions & 2 deletions stress-schedpolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static int stress_schedpolicy(stress_args_t *args)
#if defined(__linux__)
/* Linux allows NULL param, will return EFAULT */
(void)shim_memset(&param, 0, sizeof(param));
VOID_RET(int, sched_getparam(pid, NULL));
VOID_RET(int, sched_getparam(pid, stress_get_null()));
#endif

/* Exercise bad pid, ESRCH error */
Expand All @@ -291,7 +291,7 @@ static int stress_schedpolicy(stress_args_t *args)

#if defined(__linux__)
/* Linux allows NULL param, will return EFAULT */
VOID_RET(int, sched_setparam(pid, NULL));
VOID_RET(int, sched_setparam(pid, stress_get_null()));
#endif

/*
Expand Down
2 changes: 1 addition & 1 deletion stress-vm-segv.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static NOINLINE void vm_unmap_child(const size_t page_size)

len = len ^ (len >> 1);
while (len > page_size) {
(void)munmap((void *)stress_get_uint64_zero(), len - page_size);
(void)munmap((void *)stress_get_null(), len - page_size);
len >>= 1;
#if !defined(__DragonFly__)
shim_clflush(addr);
Expand Down

0 comments on commit b40b7ce

Please sign in to comment.