Skip to content

Commit

Permalink
sanitizers: intercept FreeBSD's cpuset_getaffinity call.
Browse files Browse the repository at this point in the history
Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D152609
  • Loading branch information
devnexen committed Jun 12, 2023
1 parent bd4f978 commit 203078b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10158,6 +10158,19 @@ INTERCEPTOR(int, argp_parse, const struct argp *argp, int argc, char **argv,
#define INIT_ARGP_PARSE
#endif

#if SANITIZER_INTERCEPT_CPUSET_GETAFFINITY
INTERCEPTOR(int, cpuset_getaffinity, int level, int which, __int64_t id, SIZE_T cpusetsize, __sanitizer_cpuset_t *mask) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, cpuset_getaffinity, level, which, id, cpusetsize, mask);
int res = REAL(cpuset_getaffinity)(level, which, id, cpusetsize, mask);
if (mask && !res) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, mask, cpusetsize);
return res;
}
#define INIT_CPUSET_GETAFFINITY COMMON_INTERCEPT_FUNCTION(cpuset_getaffinity);
#else
#define INIT_CPUSET_GETAFFINITY
#endif

#include "sanitizer_common_interceptors_netbsd_compat.inc"

namespace __sanitizer {
Expand Down Expand Up @@ -10476,6 +10489,7 @@ static void InitializeCommonInterceptors() {
INIT___XUNAME;
INIT_HEXDUMP;
INIT_ARGP_PARSE;
INIT_CPUSET_GETAFFINITY;

INIT___PRINTF_CHK;
}
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@
#define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD
#define SANITIZER_INTERCEPT_HEXDUMP SI_FREEBSD
#define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
#define SANITIZER_INTERCEPT_CPUSET_GETAFFINITY SI_FREEBSD

// This macro gives a way for downstream users to override the above
// interceptor macros irrespective of the platform they are on. They have
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <sys/capsicum.h>
#include <sys/consio.h>
#include <sys/cpuset.h>
#include <sys/filio.h>
#include <sys/ipc.h>
#include <sys/kbio.h>
Expand Down Expand Up @@ -103,6 +104,7 @@ void *__sanitizer_get_link_map_by_dlopen_handle(void *handle) {
return internal_dlinfo(handle, RTLD_DI_LINKMAP, &p) == 0 ? p : nullptr;
}

unsigned struct_cpuset_sz = sizeof(cpuset_t);
unsigned struct_cap_rights_sz = sizeof(cap_rights_t);
unsigned struct_utsname_sz = sizeof(struct utsname);
unsigned struct_stat_sz = sizeof(struct stat);
Expand Down Expand Up @@ -564,4 +566,5 @@ COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE);
CHECK_TYPE_SIZE(sem_t);

COMPILER_CHECK(sizeof(__sanitizer_cap_rights_t) >= sizeof(cap_rights_t));
COMPILER_CHECK(sizeof(__sanitizer_cpuset_t) >= sizeof(cpuset_t));
#endif // SANITIZER_FREEBSD
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,13 @@ extern unsigned struct_cap_rights_sz;

extern unsigned struct_fstab_sz;
extern unsigned struct_StringList_sz;

struct __sanitizer_cpuset {
long __bits[(256 + (sizeof(long) * 8) - 1) / (sizeof(long) * 8)];
};

typedef struct __sanitizer_cpuset __sanitizer_cpuset_t;
extern unsigned struct_cpuset_sz;
} // namespace __sanitizer

# define CHECK_TYPE_SIZE(TYPE) \
Expand Down

0 comments on commit 203078b

Please sign in to comment.