[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:
Alexey Samsonov 2012-09-17 09:12:39 +00:00
parent 3869b4b35a
commit 97ca306641
5 changed files with 59 additions and 4 deletions

View File

@ -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));

View File

@ -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_ =

View File

@ -110,6 +110,10 @@ const char *GetEnv(const char *name) {
return 0;
}
void ReExec() {
UNIMPLEMENTED();
}
// ----------------- sanitizer_procmaps.h
MemoryMappingLayout::MemoryMappingLayout() {

View File

@ -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);
}

View File

@ -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);
}