1 //===-- Loader test to check if tls size is read correctly ----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "include/errno.h"
10 #include "include/sys/mman.h"
11
12 #undef NDEBUG
13 #include "src/assert/assert.h"
14
15 #include "src/errno/llvmlibc_errno.h"
16 #include "src/sys/mman/mmap.h"
17
18 constexpr int threadLocalDataSize = 101;
19 _Thread_local int a[threadLocalDataSize] = {123};
20
main(int argc,char ** argv,char ** envp)21 int main(int argc, char **argv, char **envp) {
22 assert(a[0] == 123);
23
24 for (int i = 1; i < threadLocalDataSize; ++i)
25 a[i] = i;
26 for (int i = 1; i < threadLocalDataSize; ++i)
27 assert(a[i] == i);
28
29 // Call mmap with bad params so that an error value is
30 // set in errno. Since errno is implemented using a thread
31 // local var, this helps us test setting of errno and
32 // reading it back.
33 assert(llvmlibc_errno == 0);
34 void *addr = __llvm_libc::mmap(nullptr, 0, PROT_READ,
35 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
36 assert(addr == MAP_FAILED);
37 assert(llvmlibc_errno == EINVAL);
38
39 return 0;
40 }
41