- File:
-
- 1 edited
-
libcfa/src/concurrency/coroutine.cfa (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
r0957f62 r6b33e89 10 10 // Created On : Mon Nov 28 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Mar 1 17:36:41 202613 // Update Count : 11512 // Last Modified On : Fri Apr 25 06:48:19 2025 13 // Update Count : 31 14 14 // 15 15 … … 326 326 void ^?{}( ehm_cleanup & this ) { free( this.ex ); } 327 327 328 void * stack_pointer( coroutine$ * cor ) libcfa_public {329 if ( active_coroutine() == cor ) { // accessing myself ?330 void * sp; // use my current stack value331 #if defined( __i386__ )332 asm( "movl %%esp,%0" : "=m" (sp) : );333 #elif defined( __x86_64__ )334 asm( "movq %%rsp,%0" : "=m" (sp) : );335 #elif defined( __arm_64__ )336 asm( "mov x9, sp; str x9,%0" : "=m" (sp) : : "x9" );337 #else338 #error Cforall : internal error, unsupported architecture339 #endif340 return sp;341 } else { // accessing another coroutine342 return cor->context.SP;343 } // if344 } // stackPointer345 346 void * stack_pointer() libcfa_public { return stack_pointer( active_coroutine() ); }347 348 #define xstr(s) str(s)349 #define str(s) #s350 #define STACK_ERROR 4351 #define STACK_WARNING 16352 353 void stack_verify( coroutine$ * cor ) libcfa_public {354 void * sp = stack_pointer( cor ); // optimizations355 struct __stack_t * cor_stack = __get_stack( cor );356 void * safelimit = (void *)((char *)cor_stack->limit + STACK_ERROR * 1024); // space needed for printing abort message and backtrace357 358 if ( sp < safelimit ) { // must leave stack space to call abort359 abort( "Stack overflow detected: stack pointer %p below safe limit %p.\n"360 "Possible cause is allocation of large stack frame(s) and/or deep call stack.",361 sp, safelimit );362 } else if ( sp < (void *)((char *)cor_stack->limit + STACK_WARNING * 1024) ) { // must leave stack space to call abort363 #define STACK_WARNING_MSG "Cforall Runtime warning : within " xstr(STACK_WARNING) "K of stack limit.\n"364 __cfaabi_bits_write( STDERR_FILENO, STACK_WARNING_MSG, sizeof( STACK_WARNING_MSG ) - 1 );365 } else if ( sp > cor_stack->base ) {366 abort( "Stack underflow detected: stack pointer %p above base %p.\n"367 "Possible cause is corrupted stack frame via overwriting memory.",368 sp, cor_stack->base );369 } // if370 } // verify371 372 void stack_verify() libcfa_public { return stack_verify( active_coroutine() ); }373 374 328 bool poll( coroutine$ * cor ) libcfa_public { 375 329 nonlocal_exception * nl_ex = pop_ehm_head( cor ); … … 397 351 // user facing ehm operations 398 352 forall(T & | is_coroutine(T)) { 399 void * stack_pointer( T & cor ) libcfa_public { return stack_pointer( get_coroutine( cor ) ); }400 void stack_verify( T & cor ) libcfa_public { return stack_verify( get_coroutine( cor ) ); }401 402 353 // enable/disable non-local exceptions 403 354 void enable_ehm( T & cor ) libcfa_public { get_coroutine( cor )->ehm_state.ehm_enabled = true; }
Note:
See TracChangeset
for help on using the changeset viewer.