From aacc5b583c6415fe8d3e6fc99066d6ef819fa22c Mon Sep 17 00:00:00 2001 From: Øyvind Harboe Date: Sun, 22 Nov 2009 18:58:42 +0100 Subject: target: reduce stack usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4096 byte buffer allocated dynamically. Better for embedded OS's. Signed-off-by: Øyvind Harboe --- src/target/target.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/target/target.c') diff --git a/src/target/target.c b/src/target/target.c index 70fd8f2b..55adcce6 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3145,7 +3145,6 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, uint32_t count; uint32_t v; const char *varname; - uint8_t buffer[4096]; int n, e, retval; uint32_t i; @@ -3227,14 +3226,20 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, /* index counter */ n = 0; + + size_t buffersize = 4096; + uint8_t *buffer = malloc(buffersize); + if (buffer == NULL) + return JIM_ERR; + /* assume ok */ e = JIM_OK; while (len) { /* Slurp... in buffer size chunks */ count = len; /* in objects.. */ - if (count > (sizeof(buffer)/width)) { - count = (sizeof(buffer)/width); + if (count > (buffersize/width)) { + count = (buffersize/width); } retval = target_read_memory(target, addr, width, count, buffer); @@ -3268,6 +3273,8 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, } } + free(buffer); + Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); return JIM_OK; @@ -3331,7 +3338,6 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, uint32_t count; uint32_t v; const char *varname; - uint8_t buffer[4096]; int n, e, retval; uint32_t i; @@ -3415,12 +3421,18 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, n = 0; /* assume ok */ e = JIM_OK; + + size_t buffersize = 4096; + uint8_t *buffer = malloc(buffersize); + if (buffer == NULL) + return JIM_ERR; + while (len) { /* Slurp... in buffer size chunks */ count = len; /* in objects.. */ - if (count > (sizeof(buffer)/width)) { - count = (sizeof(buffer)/width); + if (count > (buffersize/width)) { + count = (buffersize/width); } v = 0; /* shut up gcc */ @@ -3454,6 +3466,8 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, } } + free(buffer); + Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); return JIM_OK; -- cgit v1.2.3