@@ -33,9 +33,9 @@ extern "C" void __stack_chk_fail() {
33
33
namespace LIBC_NAMESPACE {
34
34
35
35
#ifdef SYS_mmap2
36
- static constexpr long mmapSyscallNumber = SYS_mmap2;
36
+ static constexpr long MMAP_SYSCALL_NUMBER = SYS_mmap2;
37
37
#elif SYS_mmap
38
- static constexpr long mmapSyscallNumber = SYS_mmap;
38
+ static constexpr long MMAP_SYSCALL_NUMBER = SYS_mmap;
39
39
#else
40
40
#error "mmap and mmap2 syscalls not available."
41
41
#endif
@@ -54,49 +54,50 @@ void init_tls(TLSDescriptor &tls_descriptor) {
54
54
}
55
55
56
56
// We will assume the alignment is always a power of two.
57
- uintptr_t tlsSize = app.tls .size & -app.tls .align ;
58
- if (tlsSize != app.tls .size )
59
- tlsSize += app.tls .align ;
57
+ uintptr_t tls_size = app.tls .size & -app.tls .align ;
58
+ if (tls_size != app.tls .size )
59
+ tls_size += app.tls .align ;
60
60
61
61
// Per the x86_64 TLS ABI, the entry pointed to by the thread pointer is the
62
62
// address of the TLS block. So, we add more size to accomodate this address
63
63
// entry.
64
64
// We also need to include space for the stack canary. The canary is at
65
65
// offset 0x28 (40) and is of size uintptr_t.
66
- uintptr_t tlsSizeWithAddr = tlsSize + sizeof (uintptr_t ) + 40 ;
66
+ uintptr_t tls_size_with_addr = tls_size + sizeof (uintptr_t ) + 40 ;
67
67
68
68
// We cannot call the mmap function here as the functions set errno on
69
69
// failure. Since errno is implemented via a thread local variable, we cannot
70
70
// use errno before TLS is setup.
71
- long mmapRetVal = LIBC_NAMESPACE::syscall_impl<long >(
72
- mmapSyscallNumber , nullptr , tlsSizeWithAddr , PROT_READ | PROT_WRITE,
71
+ long mmap_retval = LIBC_NAMESPACE::syscall_impl<long >(
72
+ MMAP_SYSCALL_NUMBER , nullptr , tls_size_with_addr , PROT_READ | PROT_WRITE,
73
73
MAP_ANONYMOUS | MAP_PRIVATE, -1 , 0 );
74
74
// We cannot check the return value with MAP_FAILED as that is the return
75
75
// of the mmap function and not the mmap syscall.
76
- if (mmapRetVal < 0 && static_cast <uintptr_t >(mmapRetVal ) > -app.pageSize )
76
+ if (mmap_retval < 0 && static_cast <uintptr_t >(mmap_retval ) > -app.page_size )
77
77
LIBC_NAMESPACE::syscall_impl<long >(SYS_exit, 1 );
78
- uintptr_t *tlsAddr = reinterpret_cast <uintptr_t *>(mmapRetVal );
78
+ uintptr_t *tls_addr = reinterpret_cast <uintptr_t *>(mmap_retval );
79
79
80
80
// x86_64 TLS faces down from the thread pointer with the first entry
81
81
// pointing to the address of the first real TLS byte.
82
- uintptr_t endPtr = reinterpret_cast <uintptr_t >(tlsAddr ) + tlsSize ;
83
- *reinterpret_cast <uintptr_t *>(endPtr ) = endPtr ;
82
+ uintptr_t end_ptr = reinterpret_cast <uintptr_t >(tls_addr ) + tls_size ;
83
+ *reinterpret_cast <uintptr_t *>(end_ptr ) = end_ptr ;
84
84
85
- LIBC_NAMESPACE::inline_memcpy (reinterpret_cast <char *>(tlsAddr ),
85
+ LIBC_NAMESPACE::inline_memcpy (reinterpret_cast <char *>(tls_addr ),
86
86
reinterpret_cast <const char *>(app.tls .address ),
87
87
app.tls .init_size );
88
- uintptr_t *stackGuardAddr = reinterpret_cast <uintptr_t *>(endPtr + 40 );
88
+ uintptr_t *stack_guard_addr = reinterpret_cast <uintptr_t *>(end_ptr + 40 );
89
89
// Setting the stack guard to a random value.
90
90
// We cannot call the get_random function here as the function sets errno on
91
91
// failure. Since errno is implemented via a thread local variable, we cannot
92
92
// use errno before TLS is setup.
93
- ssize_t stackGuardRetVal = LIBC_NAMESPACE::syscall_impl<ssize_t >(
94
- SYS_getrandom, reinterpret_cast <long >(stackGuardAddr ), sizeof (uint64_t ),
93
+ ssize_t stack_guard_retval = LIBC_NAMESPACE::syscall_impl<ssize_t >(
94
+ SYS_getrandom, reinterpret_cast <long >(stack_guard_addr ), sizeof (uint64_t ),
95
95
0 );
96
- if (stackGuardRetVal < 0 )
96
+ if (stack_guard_retval < 0 )
97
97
LIBC_NAMESPACE::syscall_impl (SYS_exit, 1 );
98
98
99
- tls_descriptor = {tlsSizeWithAddr, uintptr_t (tlsAddr), endPtr};
99
+ tls_descriptor = {tls_size_with_addr, reinterpret_cast <uintptr_t >(tls_addr),
100
+ end_ptr};
100
101
return ;
101
102
}
102
103
@@ -181,7 +182,7 @@ extern "C" void _start() {
181
182
// value. We step over it (the "+ 1" below) to get to the env values.
182
183
uint64_t *env_ptr = app.args ->argv + app.args ->argc + 1 ;
183
184
uint64_t *env_end_marker = env_ptr;
184
- app.envPtr = env_ptr;
185
+ app.env_ptr = env_ptr;
185
186
while (*env_end_marker)
186
187
++env_end_marker;
187
188
@@ -190,28 +191,28 @@ extern "C" void _start() {
190
191
191
192
// After the env array, is the aux-vector. The end of the aux-vector is
192
193
// denoted by an AT_NULL entry.
193
- Elf64_Phdr *programHdrTable = nullptr ;
194
- uintptr_t programHdrCount ;
194
+ Elf64_Phdr *program_hdr_table = nullptr ;
195
+ uintptr_t program_hdr_count = 0 ;
195
196
for (AuxEntry *aux_entry = reinterpret_cast <AuxEntry *>(env_end_marker + 1 );
196
197
aux_entry->type != AT_NULL; ++aux_entry) {
197
198
switch (aux_entry->type ) {
198
199
case AT_PHDR:
199
- programHdrTable = reinterpret_cast <Elf64_Phdr *>(aux_entry->value );
200
+ program_hdr_table = reinterpret_cast <Elf64_Phdr *>(aux_entry->value );
200
201
break ;
201
202
case AT_PHNUM:
202
- programHdrCount = aux_entry->value ;
203
+ program_hdr_count = aux_entry->value ;
203
204
break ;
204
205
case AT_PAGESZ:
205
- app.pageSize = aux_entry->value ;
206
+ app.page_size = aux_entry->value ;
206
207
break ;
207
208
default :
208
209
break ; // TODO: Read other useful entries from the aux vector.
209
210
}
210
211
}
211
212
212
213
app.tls .size = 0 ;
213
- for (uintptr_t i = 0 ; i < programHdrCount ; ++i) {
214
- Elf64_Phdr *phdr = programHdrTable + i;
214
+ for (uintptr_t i = 0 ; i < program_hdr_count ; ++i) {
215
+ Elf64_Phdr *phdr = program_hdr_table + i;
215
216
if (phdr->p_type != PT_TLS)
216
217
continue ;
217
218
// TODO: p_vaddr value has to be adjusted for static-pie executables.
0 commit comments