Skip to content

Commit

Permalink
[libhooks] Add hooks for library calls to memcpy, memmove, and memset…
Browse files Browse the repository at this point in the history
  • Loading branch information
neboat committed Jul 19, 2022
1 parent 7c14829 commit 78c82e2
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions cilksan/libhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,74 @@ CILKSAN_API void __csan_memcmp(const csi_id_t call_id, const csi_id_t func_id,
check_read_bytes(call_id, rhs_MAAPVal, rhs, count);
}

CILKSAN_API void __csan_memcpy(const csi_id_t call_id, const csi_id_t func_id,
unsigned MAAP_count, const call_prop_t prop,
void *result, void *dst, const void *src,
size_t count) {
START_HOOK(call_id);

MAAP_t dst_MAAPVal = MAAP_t::ModRef, src_MAAPVal = MAAP_t::ModRef;
if (MAAP_count > 0) {
// Pop MAAP values off in reverse order
dst_MAAPVal = MAAPs.back().second;
MAAPs.pop();
src_MAAPVal = MAAPs.back().second;
MAAPs.pop();
}

if (!is_execution_parallel())
return;

if (nullptr == dst || nullptr == src)
return;

check_read_bytes(call_id, src_MAAPVal, src, count);
check_write_bytes(call_id, dst_MAAPVal, dst, count);
}

CILKSAN_API void __csan_memmove(const csi_id_t call_id, const csi_id_t func_id,
unsigned MAAP_count, const call_prop_t prop,
void *result, void *dst, const void *src,
size_t count) {
START_HOOK(call_id);

MAAP_t dst_MAAPVal = MAAP_t::ModRef, src_MAAPVal = MAAP_t::ModRef;
if (MAAP_count > 0) {
// Pop MAAP values off in reverse order
dst_MAAPVal = MAAPs.back().second;
MAAPs.pop();
src_MAAPVal = MAAPs.back().second;
MAAPs.pop();
}

if (!is_execution_parallel())
return;

if (nullptr == dst || nullptr == src)
return;

check_read_bytes(call_id, src_MAAPVal, src, count);
check_write_bytes(call_id, dst_MAAPVal, dst, count);
}

CILKSAN_API void __csan_memset(const csi_id_t call_id, const csi_id_t func_id,
unsigned MAAP_count, const call_prop_t prop,
void *result, void *dst, int ch, size_t count) {
START_HOOK(call_id);

MAAP_t dst_MAAPVal = MAAP_t::ModRef;
if (MAAP_count > 0) {
// Pop MAAP values off in reverse order
dst_MAAPVal = MAAPs.back().second;
MAAPs.pop();
}

if (!is_execution_parallel())
return;

check_write_bytes(call_id, dst_MAAPVal, dst, count);
}

CILKSAN_API void __csan_mkdir(const csi_id_t call_id, const csi_id_t func_id,
unsigned MAAP_count, const call_prop_t prop,
int result, const char *filename, mode_t mode) {
Expand Down

0 comments on commit 78c82e2

Please sign in to comment.