Skip to content

[asan] Add test case for alignment of FakeStack frames for 4KB objects with smaller thread stack sizes #152892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions compiler-rt/test/asan/TestCases/fakestack_alignment2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 %s -o %t && %run %t 2>&1
// XFAIL: *

#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct alignas(4096) page {
int x;
};

void *Thread(void *unused) {
page p1;
uint alignment = (unsigned long)&p1 % alignof(page);
printf("Thread: address modulo alignment is %u\n", alignment);
assert(alignment == 0);

return NULL;
}

int main(int argc, char **argv) {
pthread_attr_t attr;
pthread_attr_init(&attr);

// When the stack size is 1<<16, FakeStack's GetFrame() is out of alignment,
// because SizeRequiredForFlags(16) == 2K.
pthread_attr_setstacksize(&attr, 1 << 16);

pthread_t t;
pthread_create(&t, &attr, Thread, 0);
pthread_attr_destroy(&attr);
pthread_join(t, 0);

return 0;
}
Loading