asan: fix crash on odd stack size
The test currently crashes as: AddressSanitizer: CHECK failed: asan_poisoning.cpp:38 "((AddrIsAlignedByGranularity(addr))) != (0)" Main stack address/size don't have to be aligned on asan shadow granularity. Align stack bottom. Reviewed By: melver, vitalybuka Differential Revision: https://reviews.llvm.org/D145799
This commit is contained in:
parent
47208f8d34
commit
4989779d7a
|
@ -306,6 +306,7 @@ void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
|
|||
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_size,
|
||||
&tls_begin_, &tls_size);
|
||||
stack_top_ = RoundDownTo(stack_bottom_ + stack_size, ASAN_SHADOW_GRANULARITY);
|
||||
stack_bottom_ = RoundDownTo(stack_bottom_, ASAN_SHADOW_GRANULARITY);
|
||||
tls_end_ = tls_begin_ + tls_size;
|
||||
dtls_ = DTLS_Get();
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// RUN: %clangxx -O1 %s -o %t && %run %t
|
||||
// UNSUPPORTED: android
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (getenv("SANITIZER_TEST_REEXECED"))
|
||||
exit(0);
|
||||
struct rlimit rl;
|
||||
assert(!getrlimit(RLIMIT_STACK, &rl));
|
||||
struct rlimit rl_new = rl;
|
||||
rl_new.rlim_cur = 17351;
|
||||
assert(!setrlimit(RLIMIT_STACK, &rl_new));
|
||||
int pid = fork();
|
||||
assert(pid >= 0);
|
||||
if (pid == 0) {
|
||||
const char *envp[] = {"SANITIZER_TEST_REEXECED=1", nullptr};
|
||||
execve(argv[0], argv, const_cast<char **>(envp));
|
||||
assert(false);
|
||||
}
|
||||
int status;
|
||||
while (waitpid(-1, &status, __WALL) != pid) {
|
||||
}
|
||||
assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user