diff options
| author | Alexander Potapenko <glider@google.com> | 2012-12-10 13:10:40 +0000 |
|---|---|---|
| committer | Alexander Potapenko <glider@google.com> | 2012-12-10 13:10:40 +0000 |
| commit | 1746f555ee5eb19893c2aa64599d48b7273a6ded (patch) | |
| tree | ab3849a6ae72123ac3a3dc48ab3d2a19e2917003 | |
| parent | 0f5855810170f1d286b5b0812370c6c36cbbe82f (diff) | |
| download | bcm5719-llvm-1746f555ee5eb19893c2aa64599d48b7273a6ded.tar.gz bcm5719-llvm-1746f555ee5eb19893c2aa64599d48b7273a6ded.zip | |
Add a libsanitizer API __sanitizer_sandbox_on_notify(void* reserved), which should be used by
the client programs to notify the tools that sandboxing is about to be turned on.
llvm-svn: 169732
6 files changed, 29 insertions, 0 deletions
diff --git a/compiler-rt/include/sanitizer/common_interface_defs.h b/compiler-rt/include/sanitizer/common_interface_defs.h index 1eb182095ec..9d8fa5582b6 100644 --- a/compiler-rt/include/sanitizer/common_interface_defs.h +++ b/compiler-rt/include/sanitizer/common_interface_defs.h @@ -81,6 +81,12 @@ extern "C" { // stderr. void __sanitizer_set_report_fd(int fd) SANITIZER_INTERFACE_ATTRIBUTE; + + // Notify the tools that the sandbox is going to be turned on. The reserved + // parameter will be used in the future to hold a structure with functions + // that the tools may call to bypass the sandbox. + void __sanitizer_sandbox_on_notify(void *reserved) + SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE; } // extern "C" #endif // SANITIZER_COMMON_INTERFACE_DEFS_H diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 11e7a4d2d08..ca1f6bd2ef6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -201,4 +201,10 @@ void __sanitizer_set_report_fd(int fd) { internal_close(report_fd); report_fd = fd; } + +void NOINLINE __sanitizer_sandbox_on_notify(void *reserved) { + (void)reserved; + PrepareForSandboxing(); +} + } // extern "C" diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 93efdfa360f..77fcc5cd6dd 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -123,6 +123,7 @@ const char *GetPwd(); void ReExec(); bool StackSizeIsUnlimited(); void SetStackSizeLimitInBytes(uptr limit); +void PrepareForSandboxing(); // Other void SleepForSeconds(int seconds); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc index 4e9f7de99b5..5be76e9e6a6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc @@ -218,6 +218,14 @@ void ReExec() { execv(argv[0], argv.data()); } +void PrepareForSandboxing() { + // Some kinds of sandboxes may forbid filesystem access, so we won't be able + // to read the file mappings from /proc/self/maps. Luckily, neither the + // process will be able to load additional libraries, so it's fine to use the + // cached mappings. + MemoryMappingLayout::CacheMemoryMappings(); +} + // ----------------- sanitizer_procmaps.h // Linker initialized. ProcSelfMapsBuff MemoryMappingLayout::cached_proc_self_maps_; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc index 189d997a299..e156eaa5221 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc @@ -126,6 +126,10 @@ void ReExec() { UNIMPLEMENTED(); } +void PrepareForSandboxing() { + // Nothing here for now. +} + // ----------------- sanitizer_procmaps.h MemoryMappingLayout::MemoryMappingLayout() { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc index 31ae7f1e695..49a4e8b48f3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc @@ -129,6 +129,10 @@ void ReExec() { UNIMPLEMENTED(); } +void PrepareForSandboxing() { + // Nothing here for now. +} + bool StackSizeIsUnlimited() { UNIMPLEMENTED(); } |

