From 690861c3c62602142e6ec2c8c0a36e48e7e47e2c Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 26 Nov 2003 17:50:53 +0000 Subject: 2003-11-26 Joel Sherrill 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. --- cpukit/libcsupport/src/malloc.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'cpukit/libcsupport/src/malloc.c') 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 -- cgit v1.2.3