mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 19:16:43 +00:00
[Sanitizer] Hoist functions to get/set stack size and re-exec from memory-sanitizer branch to sanitizer_common
llvm-svn: 164020
This commit is contained in:
parent
3869b4b35a
commit
97ca306641
@ -112,12 +112,16 @@ uptr ReadFileToBuffer(const char *file_name, char **buff,
|
||||
// in '*buff_size'.
|
||||
void *MapFileToMemory(const char *file_name, uptr *buff_size);
|
||||
|
||||
const char *GetEnv(const char *name);
|
||||
const char *GetPwd();
|
||||
|
||||
// Other
|
||||
// OS
|
||||
void DisableCoreDumper();
|
||||
void DumpProcessMap();
|
||||
const char *GetEnv(const char *name);
|
||||
const char *GetPwd();
|
||||
void ReExec();
|
||||
bool StackSizeIsUnlimited();
|
||||
void SetStackSizeLimitInBytes(uptr limit);
|
||||
|
||||
// Other
|
||||
void SleepForSeconds(int seconds);
|
||||
void SleepForMillis(int millis);
|
||||
int Atexit(void (*function)(void));
|
||||
|
@ -164,6 +164,26 @@ const char *GetEnv(const char *name) {
|
||||
return 0; // Not found.
|
||||
}
|
||||
|
||||
void ReExec() {
|
||||
static const int kMaxArgv = 100;
|
||||
InternalScopedBuffer<char*> argv(kMaxArgv + 1);
|
||||
static char *buff;
|
||||
uptr buff_size = 0;
|
||||
ReadFileToBuffer("/proc/self/cmdline", &buff, &buff_size, 1024 * 1024);
|
||||
argv[0] = buff;
|
||||
int argc, i;
|
||||
for (argc = 1, i = 1; ; i++) {
|
||||
if (buff[i] == 0) {
|
||||
if (buff[i+1] == 0) break;
|
||||
argv[argc] = &buff[i+1];
|
||||
CHECK_LE(argc, kMaxArgv); // FIXME: make this more flexible.
|
||||
argc++;
|
||||
}
|
||||
}
|
||||
argv[argc] = 0;
|
||||
execv(argv[0], argv.data());
|
||||
}
|
||||
|
||||
// ----------------- sanitizer_procmaps.h
|
||||
MemoryMappingLayout::MemoryMappingLayout() {
|
||||
proc_self_maps_buff_len_ =
|
||||
|
@ -110,6 +110,10 @@ const char *GetEnv(const char *name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ReExec() {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
// ----------------- sanitizer_procmaps.h
|
||||
|
||||
MemoryMappingLayout::MemoryMappingLayout() {
|
||||
|
@ -138,6 +138,20 @@ void DisableCoreDumper() {
|
||||
setrlimit(RLIMIT_CORE, &nocore);
|
||||
}
|
||||
|
||||
bool StackSizeIsUnlimited() {
|
||||
struct rlimit rlim;
|
||||
CHECK_EQ(0, getrlimit(RLIMIT_STACK, &rlim));
|
||||
return (rlim.rlim_cur == (uptr)-1);
|
||||
}
|
||||
|
||||
void SetStackSizeLimitInBytes(uptr limit) {
|
||||
struct rlimit rlim;
|
||||
rlim.rlim_cur = limit;
|
||||
rlim.rlim_max = limit;
|
||||
CHECK_EQ(0, setrlimit(RLIMIT_STACK, &rlim));
|
||||
CHECK(!StackSizeIsUnlimited());
|
||||
}
|
||||
|
||||
void SleepForSeconds(int seconds) {
|
||||
sleep(seconds);
|
||||
}
|
||||
|
@ -109,6 +109,19 @@ void DisableCoreDumper() {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
void ReExec() {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
bool StackSizeIsUnlimited() {
|
||||
UNIMPLEMENTED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void SetStackSizeLimitInBytes(uptr limit) {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
void SleepForSeconds(int seconds) {
|
||||
Sleep(seconds * 1000);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user