-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Sanitizer] Support only device compilation on CPU device (#10)
* [Sanitizer] Support only device compilation on CPU device * Refine some logics
- Loading branch information
Showing
7 changed files
with
98 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "common.hpp" | ||
#include <sys/mman.h> | ||
#include <asm/param.h> | ||
|
||
extern "C" __attribute__((weak)) void __asan_init(void); | ||
|
||
namespace ur_sanitizer_layer { | ||
|
||
bool IsInASanContext() { return __asan_init != nullptr; } | ||
|
||
static bool ReserveShadowMem(uptr Addr, uptr Size) { | ||
Size = RoundUpTo(Size, EXEC_PAGESIZE); | ||
Addr = RoundDownTo(Addr, EXEC_PAGESIZE); | ||
void *P = | ||
mmap((void *)Addr, Size, PROT_READ | PROT_WRITE, | ||
MAP_PRIVATE | MAP_FIXED | MAP_NORESERVE | MAP_ANONYMOUS, -1, 0); | ||
return Addr == (uptr)P; | ||
} | ||
|
||
static bool ProtectShadowGap(uptr Addr, uptr Size) { | ||
void *P = | ||
mmap((void *)Addr, Size, PROT_NONE, | ||
MAP_PRIVATE | MAP_FIXED | MAP_NORESERVE | MAP_ANONYMOUS, -1, 0); | ||
return Addr == (uptr)P; | ||
} | ||
|
||
bool SetupShadowMem() { | ||
if (!ReserveShadowMem(LOW_SHADOW_BEGIN, LOW_SHADOW_SIZE)) { | ||
return false; | ||
} | ||
|
||
if (!ReserveShadowMem(HIGH_SHADOW_BEGIN, HIGH_SHADOW_SIZE)) { | ||
return false; | ||
} | ||
|
||
if (!ProtectShadowGap(SHADOW_GAP_BEGIN, SHADOW_GAP_SIZE)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool DestroyShadowMem() { | ||
if (munmap((void *)LOW_SHADOW_BEGIN, LOW_SHADOW_SIZE) == -1) { | ||
return false; | ||
} | ||
|
||
if (munmap((void *)HIGH_SHADOW_BEGIN, HIGH_SHADOW_SIZE) == -1) { | ||
return false; | ||
} | ||
|
||
if (munmap((void *)SHADOW_GAP_BEGIN, SHADOW_GAP_SIZE) == -1) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace ur_sanitizer_layer |
File renamed without changes.