Handle syscall cstring argument when pointing to extram

This commit is contained in:
Toby Jaffey 2025-12-12 14:45:25 +00:00
parent ce63353156
commit 74267d94df
3 changed files with 100 additions and 13 deletions

View file

@ -42,6 +42,25 @@ void main(void) {
uint16_t *p = (uint16_t *)UVM32_EXTRAM_BASE;
printdec(p[7]); // short read
} break;
case TEST9: {
uint8_t *p = (uint8_t *)UVM32_EXTRAM_BASE;
p[0] = 'h';
p[1] = 'e';
p[2] = 'l';
p[3] = 'l';
p[4] = 'o';
printbuf(p, 5); // try to print from extram (unterminated)
} break;
case TEST10: {
uint8_t *p = (uint8_t *)UVM32_EXTRAM_BASE;
p[0] = 'h';
p[1] = 'e';
p[2] = 'l';
p[3] = 'l';
p[4] = 'o';
p[5] = '\0';
println(p); // try to print from extram (terminated)
} break;
}
}

View file

@ -189,4 +189,44 @@ void test_extram_short_read(void) {
TEST_ASSERT_EQUAL(0xCDEF, uvm32_getval(&vmst, &evt, ARG0));
}
void test_extram_buf_unterminated(void) {
// run the vm
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst));
// check for picktest syscall
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
TEST_ASSERT_EQUAL(evt.data.syscall.code, SYSCALL_PICKTEST);
uvm32_setval(&vmst, &evt, RET, TEST9);
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(true, uvm32_extramDirty(&vmst));
// check for printbuf of val
TEST_ASSERT_EQUAL(UVM32_EVT_SYSCALL, evt.typ);
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTBUF);
uvm32_evt_syscall_buf_t buf = uvm32_getbuf(&vmst, &evt, ARG0, ARG1);
TEST_ASSERT_EQUAL(5, buf.len);
TEST_ASSERT_EQUAL(0, memcmp(buf.ptr, "hello", 5));
}
void test_extram_buf_terminated(void) {
// run the vm
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst));
// check for picktest syscall
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
TEST_ASSERT_EQUAL(evt.data.syscall.code, SYSCALL_PICKTEST);
uvm32_setval(&vmst, &evt, RET, TEST9);
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(true, uvm32_extramDirty(&vmst));
// check for printbuf of val
TEST_ASSERT_EQUAL(UVM32_EVT_SYSCALL, evt.typ);
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTBUF);
const char *str = uvm32_getcstr(&vmst, &evt, ARG0);
TEST_ASSERT_NOT_EQUAL(NULL, str);
TEST_ASSERT_EQUAL(0, strcmp(str, "hello"));
}