mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
Move internal static garbage into vmst.
Potentially, this could have ended up being non-zero when used by concurrent threads.
This commit is contained in:
parent
1e7343d385
commit
9bda566997
2 changed files with 9 additions and 11 deletions
|
|
@ -39,9 +39,6 @@ SOFTWARE.
|
||||||
#include CUSTOM_STDLIB_H
|
#include CUSTOM_STDLIB_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// On an invalid operation, an error is set in uvm32_state_t, but a valid pointer still needs to be temporarily used
|
|
||||||
static uint32_t garbage;
|
|
||||||
|
|
||||||
#ifdef UVM32_STACK_PROTECTION
|
#ifdef UVM32_STACK_PROTECTION
|
||||||
#define STACK_CANARY_VALUE 0x42 // magic value for stack canary
|
#define STACK_CANARY_VALUE 0x42 // magic value for stack canary
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -364,8 +361,8 @@ static uint32_t *arg_to_ptr(uvm32_state_t *vmst, uvm32_evt_t *evt, uvm32_arg_t a
|
||||||
// if something invalid is passed to arg, we should never crash
|
// if something invalid is passed to arg, we should never crash
|
||||||
// return a pointer to something readable
|
// return a pointer to something readable
|
||||||
setStatusErr(vmst, UVM32_ERR_ARGS);
|
setStatusErr(vmst, UVM32_ERR_ARGS);
|
||||||
garbage = 0;
|
vmst->garbage = 0;
|
||||||
return &garbage;
|
return &vmst->garbage;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -384,8 +381,8 @@ const char *uvm32_arg_getcstr(uvm32_state_t *vmst, uvm32_evt_t *evt, uvm32_arg_t
|
||||||
return (const char *)scb.ptr; // we know the buffer in cpu memory is null terminated, so safe to pass back
|
return (const char *)scb.ptr; // we know the buffer in cpu memory is null terminated, so safe to pass back
|
||||||
} else {
|
} else {
|
||||||
setStatusErr(vmst, UVM32_ERR_MEM_RD);
|
setStatusErr(vmst, UVM32_ERR_MEM_RD);
|
||||||
garbage = 0;
|
vmst->garbage = 0;
|
||||||
return (const char *)&garbage;
|
return (const char *)&vmst->garbage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,8 +390,8 @@ uvm32_slice_t uvm32_arg_getslice(uvm32_state_t *vmst, uvm32_evt_t *evt, uvm32_ar
|
||||||
uvm32_slice_t scb;
|
uvm32_slice_t scb;
|
||||||
if (!get_safeptr(vmst, uvm32_arg_getval(vmst, evt, argPtr), uvm32_arg_getval(vmst, evt, argLen), &scb)) {
|
if (!get_safeptr(vmst, uvm32_arg_getval(vmst, evt, argPtr), uvm32_arg_getval(vmst, evt, argLen), &scb)) {
|
||||||
setStatusErr(vmst, UVM32_ERR_MEM_RD);
|
setStatusErr(vmst, UVM32_ERR_MEM_RD);
|
||||||
garbage = 0;
|
vmst->garbage = 0;
|
||||||
scb.ptr = (uint8_t *)&garbage;
|
scb.ptr = (uint8_t *)&vmst->garbage;
|
||||||
scb.len = 0;
|
scb.len = 0;
|
||||||
}
|
}
|
||||||
return scb;
|
return scb;
|
||||||
|
|
@ -404,8 +401,8 @@ uvm32_slice_t uvm32_arg_getslice_fixed(uvm32_state_t *vmst, uvm32_evt_t *evt, uv
|
||||||
uvm32_slice_t scb;
|
uvm32_slice_t scb;
|
||||||
if (!get_safeptr(vmst, uvm32_arg_getval(vmst, evt, argPtr), len, &scb)) {
|
if (!get_safeptr(vmst, uvm32_arg_getval(vmst, evt, argPtr), len, &scb)) {
|
||||||
setStatusErr(vmst, UVM32_ERR_MEM_RD);
|
setStatusErr(vmst, UVM32_ERR_MEM_RD);
|
||||||
garbage = 0;
|
vmst->garbage = 0;
|
||||||
scb.ptr = (uint8_t *)&garbage;
|
scb.ptr = (uint8_t *)&vmst->garbage;
|
||||||
scb.len = 0;
|
scb.len = 0;
|
||||||
}
|
}
|
||||||
return scb;
|
return scb;
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,7 @@ typedef struct {
|
||||||
uint8_t *_extram; /*! External RAM pointer, or NULL */
|
uint8_t *_extram; /*! External RAM pointer, or NULL */
|
||||||
uint32_t _extramLen; /*! Length of external RAM */
|
uint32_t _extramLen; /*! Length of external RAM */
|
||||||
bool _extramDirty; /*! Flag to indicate VM code has modified extram since last run */
|
bool _extramDirty; /*! Flag to indicate VM code has modified extram since last run */
|
||||||
|
uint32_t garbage; /*! Used for returning valid pointer when operations fail */
|
||||||
} uvm32_state_t;
|
} uvm32_state_t;
|
||||||
|
|
||||||
/*! Initialise a VM instance */
|
/*! Initialise a VM instance */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue