summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/src/malloc.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2003-11-26 17:50:53 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2003-11-26 17:50:53 +0000
commit690861c3c62602142e6ec2c8c0a36e48e7e47e2c (patch)
treee8a3db5ad49e035c3aecdc3a091fd82e8578398b /cpukit/libcsupport/src/malloc.c
parent2003-11-26 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-690861c3c62602142e6ec2c8c0a36e48e7e47e2c.tar.bz2
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.
Diffstat (limited to 'cpukit/libcsupport/src/malloc.c')
-rw-r--r--cpukit/libcsupport/src/malloc.c28
1 files changed, 17 insertions, 11 deletions
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