This is an automated email from Gerrit. Evan Hunter (evanhunter...@gmail.com) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/2393
-- gerrit commit 3a5d05811a42abf3b68c6e824154d701703584be Author: Evan Hunter <ehun...@broadcom.com> Date: Fri Nov 21 17:29:31 2014 +0000 RTOS: add ability to wipe RTOS before use to avoid old data in memory This allows users to add a comand such as: $_TARGETNAME configure -rtos auto -rtos-wipe This will locate the target variables which hold the RTOS thread data and ensure that they are wiped before they are used. This prevents data from an previous execution from showing up as an incorrect thread list. Change-Id: Ib439071cda81fac69c2e1ed3df15626487adbe0a Signed-off-by: Evan Hunter <ehun...@broadcom.com> diff --git a/src/rtos/FreeRTOS.c b/src/rtos/FreeRTOS.c index 1e699c6..48ed8a5 100644 --- a/src/rtos/FreeRTOS.c +++ b/src/rtos/FreeRTOS.c @@ -94,6 +94,7 @@ static int FreeRTOS_create(struct target *target); static int FreeRTOS_update_threads(struct rtos *rtos); static int FreeRTOS_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, char **hex_reg_list); static int FreeRTOS_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]); +static int FreeRTOS_wipe(struct rtos *rtos); struct rtos_type FreeRTOS_rtos = { .name = "FreeRTOS", @@ -103,6 +104,7 @@ struct rtos_type FreeRTOS_rtos = { .update_threads = FreeRTOS_update_threads, .get_thread_reg_list = FreeRTOS_get_thread_reg_list, .get_symbol_list_to_lookup = FreeRTOS_get_symbol_list_to_lookup, + .wipe = FreeRTOS_wipe, }; enum FreeRTOS_symbol_values { @@ -134,6 +136,25 @@ static const char * const FreeRTOS_symbol_list[] = { NULL }; + +static int FreeRTOS_wipe(struct rtos *rtos) +{ + int retval = ERROR_FAIL; + uint8_t zeros[4] = { 0, 0, 0, 0 }; + symbol_table_elem_t *sym = rtos->symbols; + while (sym->symbol_name != NULL) { + if (sym->address == 0) + return ERROR_FAIL; + + retval = target_write_buffer(rtos->target, sym->address, 4, zeros); + if (retval != ERROR_OK) + return retval; + LOG_DEBUG("Wiped rtos variable: %s at 0x%08X", sym->symbol_name, (uint32_t)sym->address); + sym++; + } + return retval; +} + /* TODO: */ /* this is not safe for little endian yet */ /* may be problems reading if sizes are not 32 bit long integers. */ diff --git a/src/rtos/ThreadX.c b/src/rtos/ThreadX.c index 88470b6..fc7bcba 100644 --- a/src/rtos/ThreadX.c +++ b/src/rtos/ThreadX.c @@ -36,6 +36,7 @@ static int ThreadX_create(struct target *target); static int ThreadX_update_threads(struct rtos *rtos); static int ThreadX_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, char **hex_reg_list); static int ThreadX_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]); +static int ThreadX_wipe(struct rtos *rtos); struct ThreadX_thread_state { int value; @@ -115,8 +116,27 @@ const struct rtos_type ThreadX_rtos = { .update_threads = ThreadX_update_threads, .get_thread_reg_list = ThreadX_get_thread_reg_list, .get_symbol_list_to_lookup = ThreadX_get_symbol_list_to_lookup, + .wipe = ThreadX_wipe, }; +static int ThreadX_wipe(struct rtos *rtos) +{ + int retval = ERROR_FAIL; + uint8_t zeros[4] = { 0, 0, 0, 0 }; + symbol_table_elem_t *sym = rtos->symbols; + while (sym->symbol_name != NULL) { + if (sym->address == 0) + return ERROR_FAIL; + + retval = target_write_buffer(rtos->target, sym->address, 4, zeros); + if (retval != ERROR_OK) + return retval; + LOG_DEBUG("Wiped rtos variable: %s at 0x%08X", sym->symbol_name, (uint32_t)sym->address); + sym++; + } + return retval; +} + static int ThreadX_update_threads(struct rtos *rtos) { int retval; diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 735c106..8a5cdb4 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -46,6 +46,7 @@ static struct rtos_type *rtos_types[] = { NULL }; +static void rtos_wipe_if_needed(struct target *target); int rtos_thread_packet(struct connection *connection, const char *packet, int packet_size); int rtos_smp_init(struct target *target) @@ -67,6 +68,7 @@ static int os_alloc(struct target *target, struct rtos_type *ostype) os->current_thread = 0; os->symbols = NULL; os->target = target; + os->wiped = 0; /* RTOS drivers can override the packet handler in _create(). */ os->gdb_thread_packet = rtos_thread_packet; @@ -99,6 +101,12 @@ static int os_alloc_create(struct target *target, struct rtos_type *ostype) return ret; } +int rtos_set_wipe(Jim_GetOptInfo *goi, struct target *target) +{ + target->rtos_wipe = 1; + return ERROR_OK; +} + int rtos_create(Jim_GetOptInfo *goi, struct target *target) { int x; @@ -325,6 +333,7 @@ int rtos_thread_packet(struct connection *connection, char const *packet, int pa if (rtos_qsymbol(connection, packet, packet_size) == 1) { target->rtos_auto_detect = false; target->rtos->type->create(target); + rtos_wipe_if_needed(target); target->rtos->type->update_threads(target->rtos); } return ERROR_OK; @@ -409,6 +418,8 @@ int rtos_get_gdb_reg_list(struct connection *connection) ((current_threadid != target->rtos->current_thread) || (target->smp))) { /* in smp several current thread are possible */ char *hex_reg_list; + rtos_wipe_if_needed(target); + target->rtos->type->get_thread_reg_list(target->rtos, current_threadid, &hex_reg_list); @@ -508,10 +519,23 @@ int rtos_try_next(struct target *target) return 1; } +static void rtos_wipe_if_needed(struct target *target) +{ + if ((target->rtos_wipe == 1) && + (target->rtos != NULL) && + (target->rtos->wiped == 0) && + (target->rtos->type->wipe != NULL)) { + if (ERROR_OK == target->rtos->type->wipe(target->rtos)) + target->rtos->wiped = 1; + } +} + int rtos_update_threads(struct target *target) { - if ((target->rtos != NULL) && (target->rtos->type != NULL)) + if ((target->rtos != NULL) && (target->rtos->type != NULL)) { + rtos_wipe_if_needed(target); target->rtos->type->update_threads(target->rtos); + } return ERROR_OK; } diff --git a/src/rtos/rtos.h b/src/rtos/rtos.h index 980d95d..f4b4584 100644 --- a/src/rtos/rtos.h +++ b/src/rtos/rtos.h @@ -58,6 +58,7 @@ struct rtos { int thread_count; int (*gdb_thread_packet)(struct connection *connection, char const *packet, int packet_size); void *rtos_specific_params; + bool wiped; }; struct rtos_type { @@ -70,6 +71,7 @@ struct rtos_type { int (*get_symbol_list_to_lookup)(symbol_table_elem_t *symbol_list[]); int (*clean)(struct target *target); char * (*ps_command)(struct target *target); + int (*wipe)(struct rtos *rtos); }; struct stack_register_offset { @@ -102,5 +104,6 @@ void rtos_free_threadlist(struct rtos *rtos); int rtos_smp_init(struct target *target); /* function for handling symbol access */ int rtos_qsymbol(struct connection *connection, char const *packet, int packet_size); +int rtos_set_wipe(Jim_GetOptInfo *goi, struct target *target); #endif /* RTOS_H */ diff --git a/src/target/target.c b/src/target/target.c index d7a2c48..0a5a8cf 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4119,6 +4119,7 @@ enum target_cfg_param { TCFG_CHAIN_POSITION, TCFG_DBGBASE, TCFG_RTOS, + TCFG_RTOS_WIPE, }; static Jim_Nvp nvp_config_opts[] = { @@ -4133,6 +4134,7 @@ static Jim_Nvp nvp_config_opts[] = { { .name = "-chain-position", .value = TCFG_CHAIN_POSITION }, { .name = "-dbgbase", .value = TCFG_DBGBASE }, { .name = "-rtos", .value = TCFG_RTOS }, + { .name = "-rtos-wipe", .value = TCFG_RTOS_WIPE }, { .name = NULL, .value = -1 } }; @@ -4407,6 +4409,16 @@ no_params: } /* loop for more */ break; + case TCFG_RTOS_WIPE: + /* RTOS wipe*/ + { + int result = rtos_set_wipe(goi, target); + if (result != JIM_OK) + return result; + } + /* loop for more */ + break; + } } /* while (goi->argc) */ @@ -5140,6 +5152,7 @@ static int target_create(Jim_GetOptInfo *goi) target->rtos = NULL; target->rtos_auto_detect = false; + target->rtos_wipe = false; /* Do the rest as "configure" options */ goi->isconfigure = 1; diff --git a/src/target/target.h b/src/target/target.h index 0552b8f..0c90dac 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -184,6 +184,8 @@ struct target { struct rtos *rtos; /* Instance of Real Time Operating System support */ bool rtos_auto_detect; /* A flag that indicates that the RTOS has been specified as "auto" * and must be detected when symbols are offered */ + bool rtos_wipe; /* A flag that indicates that the RTOS variables should be + * wiped before use to avoid old values retained in memory */ struct backoff_timer backoff; int smp; /* add some target attributes for smp support */ struct target_list *head; -- ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk _______________________________________________ OpenOCD-devel mailing list OpenOCD-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openocd-devel