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