bool malloc_is_system_state_OK(void) { if ( _Thread_Dispatch_in_critical_section() ) return false; if ( _ISR_Nest_level > 0 ) return false; return true; }
void _BSP_Fatal_error(unsigned int v) { unsigned long flags; const char *err = 0; rtems_interrupt_disable(flags); printk("%s\n",_RTEMS_version); printk("FATAL ERROR:\n"); printk("Internal error: %s\n", ISITNL? "Yes":"No"); printk("Environment:"); switch (THESRC) { case INTERNAL_ERROR_CORE: printk(" RTEMS Core\n"); err = score_status_text(THEERR); break; case INTERNAL_ERROR_RTEMS_API: printk(" RTEMS API\n"); err = rtems_status_text(THEERR); break; case INTERNAL_ERROR_POSIX_API: printk(" POSIX API (errno)\n"); /* could use strerror but I'd rather avoid using this here */ break; default: printk(" UNKNOWN (0x%x)\n",THESRC); break; } if ( _Thread_Dispatch_in_critical_section() ) printk( " Error occurred in a Thread Dispatching DISABLED context (level %i)\n", _Thread_Dispatch_get_disable_level()); else printk("enabled\n"); if ( _ISR_Nest_level ) { printk( " Error occurred from ISR context (ISR nest level %i)\n", _ISR_Nest_level ); } printk("Error %d",THEERR); if (err) { printk(": %s",err); } printk("\n"); printk("Stack Trace:\n"); CPU_print_stack(); rebootQuestion(); }
void __ISR_Handler( uint32_t vector) { ISR_Level level; _ISR_Disable( level ); _Thread_Dispatch_increment_disable_level(); #if (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE) if ( _ISR_Nest_level == 0 ) { /* Install irq stack */ _old_stack_ptr = stack_ptr; stack_ptr = _CPU_Interrupt_stack_high; } #endif _ISR_Nest_level++; _ISR_Enable( level ); /* call isp */ if ( _ISR_Vector_table[ vector]) (*_ISR_Vector_table[ vector ])( vector ); _ISR_Disable( level ); _Thread_Dispatch_decrement_disable_level(); _ISR_Nest_level--; #if (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE) if ( _ISR_Nest_level == 0 ) /* restore old stack pointer */ stack_ptr = _old_stack_ptr; #endif _ISR_Enable( level ); if ( _ISR_Nest_level ) return; if ( _Thread_Dispatch_in_critical_section() ) { return; } if ( _Thread_Dispatch_necessary ) { _Thread_Dispatch(); } }
void __ISR_Handler(uint32_t vector, CPU_Interrupt_frame *ifr) { register uint32_t level; _exception_stack_frame = NULL; /* Interrupts are disabled upon entry to this Handler */ _Thread_Dispatch_increment_disable_level(); #if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE) if ( _ISR_Nest_level == 0 ) { /* Install irq stack */ _old_stack_ptr = stack_ptr; stack_ptr = _CPU_Interrupt_stack_high - 4; } #endif _ISR_Nest_level++; if ( _ISR_Vector_table[ vector] ) { (*_ISR_Vector_table[ vector ])(vector, ifr); }; /* Make sure that interrupts are disabled again */ _CPU_ISR_Disable( level ); _ISR_Nest_level--; #if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE) if( _ISR_Nest_level == 0) stack_ptr = _old_stack_ptr; #endif _Thread_Dispatch_decrement_disable_level(); _CPU_ISR_Enable( level ); if ( _ISR_Nest_level ) return; if ( _Thread_Dispatch_necessary && !_Thread_Dispatch_in_critical_section() ) { /* save off our stack frame so the context switcher can get to it */ _exception_stack_frame = ifr; _Thread_Dispatch(); /* and make sure its clear in case we didn't dispatch. if we did, its * already cleared */ _exception_stack_frame = NULL; } }
void __ISR_Handler(void) { register uint32_t level; /* Interrupts are disabled upon entry to this Handler */ #if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE) if ( _ISR_Nest_level == 0 ) { /* Install irq stack */ _old_stack_ptr = stack_ptr; stack_ptr = _CPU_Interrupt_stack_high - 4; } #endif _ISR_Nest_level++; _Thread_Dispatch_increment_disable_level(); __IIC_Handler(); /* Make sure that interrupts are disabled again */ _CPU_ISR_Disable( level ); _Thread_Dispatch_decrement_disable_level(); _ISR_Nest_level--; if( _ISR_Nest_level == 0) { #if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE) stack_ptr = _old_stack_ptr; #endif if( !_Thread_Dispatch_in_critical_section() ) { if ( _Thread_Dispatch_necessary ) { _CPU_ISR_Enable( level ); _Thread_Dispatch(); /* may have switched to another task and not return here immed. */ _CPU_ISR_Disable( level ); /* Keep _pairs_ of Enable/Disable */ } } } _CPU_ISR_Enable( level ); }
void rtems_filesystem_global_location_release( rtems_filesystem_global_location_t *global_loc ) { if (!_Thread_Dispatch_in_critical_section()) { release_with_count(global_loc, 1); } else { if (global_loc->deferred_released_count == 0) { rtems_filesystem_global_location_t *head = deferred_released_global_locations; global_loc->deferred_released_count = 1; global_loc->deferred_released_next = head; deferred_released_global_locations = global_loc; } else { ++global_loc->deferred_released_count; } } }
void *realloc( void *ptr, size_t size ) { uintptr_t old_size; char *new_area; MSBUMP(realloc_calls, 1); /* * Do not attempt to allocate memory if in a critical section or ISR. */ if (_System_state_Is_up(_System_state_Get())) { if (_Thread_Dispatch_in_critical_section()) return (void *) 0; if (_ISR_Nest_level > 0) return (void *) 0; } /* * Continue with realloc(). */ if ( !ptr ) return malloc( size ); if ( !size ) { free( ptr ); return (void *) 0; } if ( !_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, ptr, &old_size) ) { errno = EINVAL; return (void *) 0; } /* * Now resize it. */ if ( _Protected_heap_Resize_block( RTEMS_Malloc_Heap, ptr, size ) ) { return ptr; } /* * There used to be a free on this error case but it is wrong to * free the memory per OpenGroup Single UNIX Specification V2 * and the C Standard. */ new_area = malloc( size ); MSBUMP(malloc_calls, (uint32_t) -1); /* subtract off the malloc */ if ( !new_area ) { return (void *) 0; } memcpy( new_area, ptr, (size < old_size) ? size : old_size ); free( ptr ); return new_area; }