Changeset 5614a191 for libcfa/src/concurrency/coroutine.cfa
- Timestamp:
- Feb 17, 2022, 12:56:46 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 8ee163e2
- Parents:
- 3263e2a4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
r3263e2a4 r5614a191 85 85 // minimum feasible stack size in bytes 86 86 static const size_t MinStackSize = 1000; 87 extern size_t __page_size; // architecture pagesize HACK, should go in proper runtime singleton 88 extern int __map_prot; 87 88 extern "C" { 89 extern size_t __cfa_page_size; // architecture pagesize HACK, should go in proper runtime singleton 90 extern int __map_prot; 91 } 89 92 90 93 void __stack_prepare( __stack_info_t * this, size_t create_size ); … … 157 160 [void *, size_t] __stack_alloc( size_t storageSize ) { 158 161 const size_t stack_data_size = libCeiling( sizeof(__stack_t), 16 ); // minimum alignment 159 assert(__ page_size != 0l);162 assert(__cfa_page_size != 0l); 160 163 size_t size = libCeiling( storageSize, 16 ) + stack_data_size; 161 size = ceiling(size, __ page_size);164 size = ceiling(size, __cfa_page_size); 162 165 163 166 // If we are running debug, we also need to allocate a guardpage to catch stack overflows. 164 167 void * storage; 165 168 #if CFA_COROUTINE_USE_MMAP 166 storage = mmap(0p, size + __ page_size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);169 storage = mmap(0p, size + __cfa_page_size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); 167 170 if(storage == ((void*)-1)) { 168 171 abort( "coroutine stack creation : internal error, mmap failure, error(%d) %s.", errno, strerror( errno ) ); 169 172 } 170 if ( mprotect( storage, __ page_size, PROT_NONE ) == -1 ) {173 if ( mprotect( storage, __cfa_page_size, PROT_NONE ) == -1 ) { 171 174 abort( "coroutine stack creation : internal error, mprotect failure, error(%d) %s.", errno, strerror( errno ) ); 172 175 } // if 173 storage = (void *)(((intptr_t)storage) + __ page_size);176 storage = (void *)(((intptr_t)storage) + __cfa_page_size); 174 177 #else 175 178 __cfaabi_dbg_debug_do( 176 storage = memalign( __ page_size, size + __page_size );179 storage = memalign( __cfa_page_size, size + __cfa_page_size ); 177 180 ); 178 181 __cfaabi_dbg_no_debug_do( … … 181 184 182 185 __cfaabi_dbg_debug_do( 183 if ( mprotect( storage, __ page_size, PROT_NONE ) == -1 ) {186 if ( mprotect( storage, __cfa_page_size, PROT_NONE ) == -1 ) { 184 187 abort( "__stack_alloc : internal error, mprotect failure, error(%d) %s.", (int)errno, strerror( (int)errno ) ); 185 188 } 186 storage = (void *)(((intptr_t)storage) + __ page_size);189 storage = (void *)(((intptr_t)storage) + __cfa_page_size); 187 190 ); 188 191 #endif … … 198 201 #if CFA_COROUTINE_USE_MMAP 199 202 size_t size = ((intptr_t)this->storage->base) - ((intptr_t)this->storage->limit) + sizeof(__stack_t); 200 storage = (void *)(((intptr_t)storage) - __ page_size);201 if(munmap(storage, size + __ page_size) == -1) {203 storage = (void *)(((intptr_t)storage) - __cfa_page_size); 204 if(munmap(storage, size + __cfa_page_size) == -1) { 202 205 abort( "coroutine stack destruction : internal error, munmap failure, error(%d) %s.", errno, strerror( errno ) ); 203 206 } 204 207 #else 205 208 __cfaabi_dbg_debug_do( 206 storage = (char*)(storage) - __ page_size;207 if ( mprotect( storage, __ page_size, __map_prot ) == -1 ) {209 storage = (char*)(storage) - __cfa_page_size; 210 if ( mprotect( storage, __cfa_page_size, __map_prot ) == -1 ) { 208 211 abort( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) ); 209 212 }
Note: See TracChangeset
for help on using the changeset viewer.