Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void lai_eisaid(lai_variable_t *object, const char *id) {
if (lai_strlen(id) != 7) {
if (lai_create_string(object, n) != LAI_ERROR_NONE)
lai_panic("could not allocate memory for string");
memcpy(lai_exec_string_access(object), id, n);
laihost_memcpy(lai_exec_string_access(object), id, n);
return;
}

Expand Down
32 changes: 16 additions & 16 deletions core/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static lai_api_error_t lai_exec_parse(int parse_mode, lai_state_t *state);
// Param: lai_nsnode_t *method - identifies the control method

void lai_init_state(lai_state_t *state) {
memset(state, 0, sizeof(lai_state_t));
laihost_memset(state, 0, sizeof(lai_state_t));
state->ctxstack_base = state->small_ctxstack;
state->blkstack_base = state->small_blkstack;
state->stack_base = state->small_stack;
Expand Down Expand Up @@ -425,8 +425,8 @@ static lai_api_error_t lai_exec_reduce_op(int opcode, lai_state_t *state,
char *buffer0 = lai_exec_buffer_access(&operand0_convert);
char *buffer1 = lai_exec_buffer_access(&operand1_convert);
char *result_buffer = lai_exec_buffer_access(&result);
memcpy(result_buffer, buffer0, b0size);
memcpy(result_buffer + b0size, buffer1, b0size);
laihost_memcpy(result_buffer, buffer0, b0size);
laihost_memcpy(result_buffer + b0size, buffer1, b0size);
result.type = LAI_BUFFER;
break;
}
Expand Down Expand Up @@ -476,8 +476,8 @@ static lai_api_error_t lai_exec_reduce_op(int opcode, lai_state_t *state,
char *string0 = lai_exec_string_access(&operand0_convert);
char *string1 = lai_exec_string_access(&operand1_convert);
char *result_string = lai_exec_string_access(&result);
memcpy(result_string, string0, s0len);
memcpy(result_string + s0len, string1, s1len);
laihost_memcpy(result_string, string0, s0len);
laihost_memcpy(result_string + s0len, string1, s1len);
result_string[s0len + s1len + 1] = '\0';
result.type = LAI_STRING;
}
Expand Down Expand Up @@ -827,7 +827,7 @@ static lai_api_error_t lai_exec_reduce_op(int opcode, lai_state_t *state,

if (buf1_size == 0)
buf1_size
= 2; // Make it 2 so memcpy will actually copy 0 zero bytes since it is empty
= 2; // Make it 2 so laihost_memcpy will actually copy 0 zero bytes since it is empty

if (buf2_size == 0)
buf2_size = 2;
Expand All @@ -837,8 +837,8 @@ static lai_api_error_t lai_exec_reduce_op(int opcode, lai_state_t *state,
lai_create_buffer(&result, result_size);
char *result_buffer = lai_exec_buffer_access(&result);

memcpy(result_buffer, buf1, buf1_size - 2);
memcpy(result_buffer + (buf1_size - 2), buf2, buf2_size - 2);
laihost_memcpy(result_buffer, buf1, buf1_size - 2);
laihost_memcpy(result_buffer + (buf1_size - 2), buf2, buf2_size - 2);
result_buffer[(buf1_size - 2) + (buf2_size - 2)] = 0x79; // Small End Tag

// Calculate checksum to put into the End Tag
Expand Down Expand Up @@ -1037,7 +1037,7 @@ static lai_api_error_t lai_exec_reduce_op(int opcode, lai_state_t *state,
}
char *buffer0 = lai_exec_string_access(&object);
char *result_string = lai_exec_string_access(&result);
memcpy(result_string, buffer0 + n, sz);
laihost_memcpy(result_string, buffer0 + n, sz);
result.type = LAI_STRING;
break;
}
Expand All @@ -1049,7 +1049,7 @@ static lai_api_error_t lai_exec_reduce_op(int opcode, lai_state_t *state,
}
char *buffer0 = lai_exec_buffer_access(&object);
char *result_buffer = lai_exec_buffer_access(&result);
memcpy(result_buffer, buffer0 + n, sz);
laihost_memcpy(result_buffer, buffer0 + n, sz);
result.type = LAI_BUFFER;
break;
}
Expand Down Expand Up @@ -1473,7 +1473,7 @@ static lai_api_error_t lai_exec_process(lai_state_t *state) {
lai_panic("buffer initializer has negative size");
if (initial_size > (int)lai_exec_buffer_size(&result))
lai_panic("buffer initializer overflows buffer");
memcpy(lai_exec_buffer_access(&result), method + block->pc, initial_size);
laihost_memcpy(lai_exec_buffer_access(&result), method + block->pc, initial_size);

if (item->buf_want_result) {
// Note: there is no need to reserve() as we pop an operand above.
Expand Down Expand Up @@ -1597,7 +1597,7 @@ static lai_api_error_t lai_exec_process(lai_state_t *state) {

// TODO: Make sure that this does not leak memory.
lai_variable_t args[7];
memset(args, 0, sizeof(lai_variable_t) * 7);
laihost_memset(args, 0, sizeof(lai_variable_t) * 7);

for (int i = 0; i < argc; i++) {
struct lai_operand *operand
Expand Down Expand Up @@ -1635,7 +1635,7 @@ static lai_api_error_t lai_exec_process(lai_state_t *state) {
method_ctxitem->invocation = laihost_malloc(sizeof(struct lai_invocation));
if (!method_ctxitem->invocation)
lai_panic("could not allocate memory for method invocation");
memset(method_ctxitem->invocation, 0, sizeof(struct lai_invocation));
laihost_memset(method_ctxitem->invocation, 0, sizeof(struct lai_invocation));
lai_list_init(&method_ctxitem->invocation->per_method_list);

for (int i = 0; i < argc; i++)
Expand Down Expand Up @@ -2265,7 +2265,7 @@ static lai_api_error_t lai_exec_parse(int parse_mode, lai_state_t *state) {
opstack_res->tag = LAI_OPERAND_OBJECT;
if (lai_create_string(&opstack_res->object, n) != LAI_ERROR_NONE)
lai_panic("could not allocate memory for string");
memcpy(lai_exec_string_access(&opstack_res->object), method + data_pc, n);
laihost_memcpy(lai_exec_string_access(&opstack_res->object), method + data_pc, n);
} else
LAI_ENSURE(parse_mode == LAI_EXEC_MODE);
break;
Expand Down Expand Up @@ -3716,7 +3716,7 @@ lai_api_error_t lai_eval_args(lai_variable_t *result, lai_nsnode_t *handle, lai_
method_ctxitem->invocation = laihost_malloc(sizeof(struct lai_invocation));
if (!method_ctxitem->invocation)
lai_panic("could not allocate memory for method invocation");
memset(method_ctxitem->invocation, 0, sizeof(struct lai_invocation));
laihost_memset(method_ctxitem->invocation, 0, sizeof(struct lai_invocation));
lai_list_init(&method_ctxitem->invocation->per_method_list);

for (int i = 0; i < n; i++)
Expand Down Expand Up @@ -3764,7 +3764,7 @@ lai_api_error_t lai_eval_vargs(lai_variable_t *result, lai_nsnode_t *handle, lai
va_list vl) {
int n = 0;
lai_variable_t args[7];
memset(args, 0, sizeof(lai_variable_t) * 7);
laihost_memset(args, 0, sizeof(lai_variable_t) * 7);

for (;;) {
LAI_ENSURE(n < 7 && "ACPI supports at most 7 arguments");
Expand Down
16 changes: 8 additions & 8 deletions core/exec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static inline int lai_exec_reserve_ctxstack(lai_state_t *state) {
lai_warn("failed to allocate memory for context stack");
return 1;
}
memcpy(new_stack, state->ctxstack_base,
laihost_memcpy(new_stack, state->ctxstack_base,
(state->ctxstack_ptr + 1) * sizeof(struct lai_ctxitem));
if (state->ctxstack_base != state->small_ctxstack)
laihost_free(state->ctxstack_base,
Expand All @@ -248,7 +248,7 @@ static inline struct lai_ctxitem *lai_exec_push_ctxstack(lai_state_t *state) {
state->ctxstack_ptr++;
// Users are expected to call the reserve() function before this one.
LAI_ENSURE(state->ctxstack_ptr < state->ctxstack_capacity);
memset(&state->ctxstack_base[state->ctxstack_ptr], 0, sizeof(struct lai_ctxitem));
laihost_memset(&state->ctxstack_base[state->ctxstack_ptr], 0, sizeof(struct lai_ctxitem));
return &state->ctxstack_base[state->ctxstack_ptr];
}

Expand Down Expand Up @@ -285,7 +285,7 @@ static inline int lai_exec_reserve_blkstack(lai_state_t *state) {
lai_warn("failed to allocate memory for block stack");
return 1;
}
memcpy(new_stack, state->blkstack_base,
laihost_memcpy(new_stack, state->blkstack_base,
(state->blkstack_ptr + 1) * sizeof(struct lai_blkitem));
if (state->blkstack_base != state->small_blkstack)
laihost_free(state->blkstack_base,
Expand All @@ -301,7 +301,7 @@ static inline struct lai_blkitem *lai_exec_push_blkstack(lai_state_t *state) {
state->blkstack_ptr++;
// Users are expected to call the reserve() function before this one.
LAI_ENSURE(state->blkstack_ptr < state->blkstack_capacity);
memset(&state->blkstack_base[state->blkstack_ptr], 0, sizeof(struct lai_blkitem));
laihost_memset(&state->blkstack_base[state->blkstack_ptr], 0, sizeof(struct lai_blkitem));
return &state->blkstack_base[state->blkstack_ptr];
}

Expand Down Expand Up @@ -330,7 +330,7 @@ static inline int lai_exec_reserve_stack(lai_state_t *state) {
lai_warn("failed to allocate memory for execution stack");
return 1;
}
memcpy(new_stack, state->stack_base, (state->stack_ptr + 1) * sizeof(lai_stackitem_t));
laihost_memcpy(new_stack, state->stack_base, (state->stack_ptr + 1) * sizeof(lai_stackitem_t));
if (state->stack_base != state->small_stack)
laihost_free(state->stack_base, state->stack_capacity * sizeof(lai_stackitem_t));
state->stack_base = new_stack;
Expand Down Expand Up @@ -384,9 +384,9 @@ static inline int lai_exec_reserve_opstack(lai_state_t *state) {
lai_warn("failed to allocate memory for operand stack");
return 1;
}
// TODO: Here, we rely on the fact that moving lai_variable_t via memcpy() is OK.
// TODO: Here, we rely on the fact that moving lai_variable_t via laihost_memcpy() is OK.
// Implement a some sophisticated lai_operand_move()?
memcpy(new_stack, state->opstack_base, state->opstack_ptr * sizeof(struct lai_operand));
laihost_memcpy(new_stack, state->opstack_base, state->opstack_ptr * sizeof(struct lai_operand));
if (state->opstack_base != state->small_opstack)
laihost_free(state->opstack_base, state->opstack_capacity * sizeof(struct lai_operand));
state->opstack_base = new_stack;
Expand All @@ -410,7 +410,7 @@ static inline struct lai_operand *lai_exec_push_opstack(lai_state_t *state) {
// Users are expected to call the reserve() function before this one.
LAI_ENSURE(state->opstack_ptr < state->opstack_capacity);
struct lai_operand *object = &state->opstack_base[state->opstack_ptr];
memset(object, 0, sizeof(struct lai_operand));
laihost_memset(object, 0, sizeof(struct lai_operand));
state->opstack_ptr++;
return object;
}
Expand Down
2 changes: 1 addition & 1 deletion core/libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void *lai_calloc(size_t count, size_t item_size) {
size_t size = count * item_size;
void *p = laihost_malloc(size);
if (p)
memset(p, 0, size);
laihost_memset(p, 0, size);
return p;
}

Expand Down
8 changes: 4 additions & 4 deletions core/ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ lai_nsnode_t *lai_create_nsnode(void) {
return NULL;
// here we assume that the host does not return zeroed memory,
// so lai must zero the returned memory itself.
memset(node, 0, sizeof(lai_nsnode_t));
laihost_memset(node, 0, sizeof(lai_nsnode_t));
return node;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ lai_api_error_t lai_install_nsnode(lai_nsnode_t *node) {
struct lai_hashtable_chain chain = LAI_HASHTABLE_CHAIN_INITIALIZER;
while (!lai_hashtable_chain_advance(&parent->children, h, &chain)) {
lai_nsnode_t *child = lai_hashtable_chain_get(&parent->children, h, &chain);
if (!memcmp(child->name, node->name, 4)) {
if (!laihost_memcmp(child->name, node->name, 4)) {
LAI_CLEANUP_FREE_STRING char *fullpath = lai_stringify_node_path(node);
lai_warn("trying to install duplicate namespace node %s, ignoring", fullpath);
return LAI_ERROR_UNEXPECTED_RESULT;
Expand Down Expand Up @@ -144,7 +144,7 @@ lai_nsnode_t *lai_ns_get_child(lai_nsnode_t *parent, const char *name) {
struct lai_hashtable_chain chain = LAI_HASHTABLE_CHAIN_INITIALIZER;
while (!lai_hashtable_chain_advance(&parent->children, h, &chain)) {
lai_nsnode_t *child = lai_hashtable_chain_get(&parent->children, h, &chain);
if (!memcmp(child->name, name, 4))
if (!laihost_memcmp(child->name, name, 4))
return child;
}
return NULL;
Expand Down Expand Up @@ -534,7 +534,7 @@ static struct lai_aml_segment *lai_load_table(void *ptr, int index) {
struct lai_aml_segment *amls = laihost_malloc(sizeof(struct lai_aml_segment));
if (!amls)
lai_panic("could not allocate memory for struct lai_aml_segment");
memset(amls, 0, sizeof(struct lai_aml_segment));
laihost_memset(amls, 0, sizeof(struct lai_aml_segment));

amls->table = ptr;
amls->index = index;
Expand Down
Loading