diff options
-rw-r--r-- | cpukit/libcsupport/ChangeLog | 7 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc.c | 28 |
2 files changed, 24 insertions, 11 deletions
diff --git a/cpukit/libcsupport/ChangeLog b/cpukit/libcsupport/ChangeLog index 24841054c4..eb44f4a487 100644 --- a/cpukit/libcsupport/ChangeLog +++ b/cpukit/libcsupport/ChangeLog @@ -1,3 +1,10 @@ +2003-11-26 Joel Sherrill <joel@OARcorp.com> + + PR 523/filesystem + * src/malloc.c: Make malloc family safer for use from ISRs and + dispatching critical sections. If in a critical section while doing + a free(), then the free is deferred until the next malloc() attempt. + 2003-11-25 Jennifer Averett <jennifer@OARcorp.com> PR 519/filesystem diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c index f80e2401cb..ebee514393 100644 --- a/cpukit/libcsupport/src/malloc.c +++ b/cpukit/libcsupport/src/malloc.c @@ -170,11 +170,13 @@ void *malloc( * Do not attempt to allocate memory if in a critical section or ISR. */ - if (_Thread_Dispatch_disable_level > 0) - return (void *) 0; + if (_System_state_Is_up(_System_state_Get())) { + if (_Thread_Dispatch_disable_level > 0) + return (void *) 0; - if (_ISR_Nest_level > 0) - return (void *) 0; + if (_ISR_Nest_level > 0) + return (void *) 0; + } /* * If some free's have been deferred, then do them now. @@ -297,11 +299,13 @@ void *realloc( * Do not attempt to allocate memory if in a critical section or ISR. */ - if (_Thread_Dispatch_disable_level > 0) - return (void *) 0; + if (_System_state_Is_up(_System_state_Get())) { + if (_Thread_Dispatch_disable_level > 0) + return (void *) 0; - if (_ISR_Nest_level > 0) - return (void *) 0; + if (_ISR_Nest_level > 0) + return (void *) 0; + } /* * Continue with calloc(). @@ -356,9 +360,11 @@ void free( * Do not attempt to free memory if in a critical section or ISR. */ - if ((_Thread_Dispatch_disable_level > 0) || (_ISR_Nest_level > 0)) { - Chain_Append(&RTEMS_Malloc_GC_list, (Chain_Node *)ptr); - return; + if (_System_state_Is_up(_System_state_Get())) { + if ((_Thread_Dispatch_disable_level > 0) || (_ISR_Nest_level > 0)) { + Chain_Append(&RTEMS_Malloc_GC_list, (Chain_Node *)ptr); + return; + } } #ifdef MALLOC_STATS |