Changeset 633a642 for src/libcfa/concurrency/coroutine.c
- Timestamp:
- Jan 30, 2018, 4:52:54 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1449d83, 5ff188f
- Parents:
- 320eb73a (diff), 7416d46a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/coroutine.c
r320eb73a r633a642 118 118 } //ctxSwitchDirect 119 119 120 void create_stack( coStack_t* this, unsigned int storageSize ) {120 void create_stack( coStack_t* this, unsigned int storageSize ) with( *this ) { 121 121 //TEMP HACK do this on proper kernel startup 122 122 if(pageSize == 0ul) pageSize = sysconf( _SC_PAGESIZE ); … … 124 124 size_t cxtSize = libCeiling( sizeof(machine_context_t), 8 ); // minimum alignment 125 125 126 if ( (intptr_t) this->storage == 0 ) {127 this->userStack = false;128 this->size = libCeiling( storageSize, 16 );126 if ( (intptr_t)storage == 0 ) { 127 userStack = false; 128 size = libCeiling( storageSize, 16 ); 129 129 // use malloc/memalign because "new" raises an exception for out-of-memory 130 130 131 131 // assume malloc has 8 byte alignment so add 8 to allow rounding up to 16 byte alignment 132 __cfaabi_dbg_debug_do( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) );133 __cfaabi_dbg_no_debug_do( this->storage = malloc( cxtSize + this->size + 8 ) );132 __cfaabi_dbg_debug_do( storage = memalign( pageSize, cxtSize + size + pageSize ) ); 133 __cfaabi_dbg_no_debug_do( storage = malloc( cxtSize + size + 8 ) ); 134 134 135 135 __cfaabi_dbg_debug_do( 136 if ( mprotect( this->storage, pageSize, PROT_NONE ) == -1 ) {136 if ( mprotect( storage, pageSize, PROT_NONE ) == -1 ) { 137 137 abortf( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) ); 138 138 } // if 139 139 ); 140 140 141 if ( (intptr_t) this->storage == 0 ) {142 abortf( "Attempt to allocate %d bytes of storage for coroutine or task execution-state but insufficient memory available.", this->size );141 if ( (intptr_t)storage == 0 ) { 142 abortf( "Attempt to allocate %d bytes of storage for coroutine or task execution-state but insufficient memory available.", size ); 143 143 } // if 144 144 145 __cfaabi_dbg_debug_do( this->limit = (char *)this->storage + pageSize );146 __cfaabi_dbg_no_debug_do( this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ) ); // minimum alignment145 __cfaabi_dbg_debug_do( limit = (char *)storage + pageSize ); 146 __cfaabi_dbg_no_debug_do( limit = (char *)libCeiling( (unsigned long)storage, 16 ) ); // minimum alignment 147 147 148 148 } else { 149 assertf( ((size_t) this->storage & (libAlign() - 1)) != 0ul, "Stack storage %p for task/coroutine must be aligned on %d byte boundary.", this->storage, (int)libAlign() );150 this->userStack = true;151 this->size = storageSize - cxtSize;149 assertf( ((size_t)storage & (libAlign() - 1)) != 0ul, "Stack storage %p for task/coroutine must be aligned on %d byte boundary.", storage, (int)libAlign() ); 150 userStack = true; 151 size = storageSize - cxtSize; 152 152 153 if ( this->size % 16 != 0u ) this->size -= 8;153 if ( size % 16 != 0u ) size -= 8; 154 154 155 this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ); // minimum alignment155 limit = (char *)libCeiling( (unsigned long)storage, 16 ); // minimum alignment 156 156 } // if 157 assertf( this->size >= MinStackSize, "Stack size %zd provides less than minimum of %d bytes for a stack.", this->size, MinStackSize );157 assertf( size >= MinStackSize, "Stack size %zd provides less than minimum of %d bytes for a stack.", size, MinStackSize ); 158 158 159 this->base = (char *)this->limit + this->size;160 this->context = this->base;161 t his->top = (char *)this->context + cxtSize;159 base = (char *)limit + size; 160 context = base; 161 top = (char *)context + cxtSize; 162 162 } 163 163
Note: See TracChangeset
for help on using the changeset viewer.