Make machine configuration authoritative and restore native checkpoints exactly
This commit is contained in:
@@ -11,6 +11,23 @@ typedef struct {
|
||||
|
||||
static sim_state state;
|
||||
|
||||
#ifndef SIM_CHECKPOINT_BUILD_ID
|
||||
#define SIM_CHECKPOINT_BUILD_ID "unversioned"
|
||||
#endif
|
||||
const char *sim_checkpoint_build_id(void) { return SIM_CHECKPOINT_BUILD_ID; }
|
||||
|
||||
uint32_t sim_core_checkpoint_size(void) { return sizeof(state); }
|
||||
int32_t sim_core_checkpoint_export(uint8_t *output, uint32_t capacity) {
|
||||
if (output == NULL || capacity != sizeof(state)) return SIM_ERR_INVALID_ARGUMENT;
|
||||
memcpy(output, &state, sizeof(state)); return SIM_OK;
|
||||
}
|
||||
int32_t sim_core_checkpoint_restore(const uint8_t *input, uint32_t length) {
|
||||
if (input == NULL || length != sizeof(state)) return SIM_ERR_INVALID_ARGUMENT;
|
||||
const sim_state *saved = (const sim_state *)input;
|
||||
if (saved->created > 1 || saved->loaded > 1 || saved->pending_event > 1) return SIM_ERR_INVALID_ARGUMENT;
|
||||
memcpy(&state, saved, sizeof(state)); return SIM_OK;
|
||||
}
|
||||
|
||||
static int valid_buffer(const uint8_t *data, uint32_t len) {
|
||||
return len == 0 || data != NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user