Skip to content

Commit a7cb689

Browse files
committed
Cleanup
1 parent 8306c8d commit a7cb689

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

buildall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tabulate import tabulate
66
from concurrent.futures import ThreadPoolExecutor, as_completed
77

8-
targets = ["x86", "x64", "armv7m", "armv7emsp", "armv7emdp", "xtensa", "xtensawin"] # "armv6m", "rv32imc"
8+
targets = ["x86", "x64", "armv6m", "armv7m", "armv7emsp", "armv7emdp", "xtensa", "xtensawin"] # "rv32imc"
99
apps = ["assemblyscript", "cpp", "rust", "tinygo", "zig", "virgil", "wat", "coremark"]
1010

1111

runtime/libc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
* Created: 24.08.2024
44
**/
55

6+
#if !defined(__riscv)
67
// define errno before any includes so it gets into BSS
78
int errno;
9+
#endif
810

911
#include "py/dynruntime.h"
1012

@@ -58,18 +60,21 @@ int strncmp(const char *_l, const char *_r, size_t n) {
5860
return *l - *r;
5961
}
6062

63+
#if !defined(__riscv)
6164
int *__errno(void) {
6265
return &errno;
6366
}
6467

6568
int *__errno_location(void) {
6669
return &errno;
6770
}
71+
#endif
6872

6973
__attribute__ ((noreturn))
7074
void abort(void) {
71-
mp_printf(&mp_plat_print, "Aborting\n");
72-
__builtin_trap();
75+
//mp_printf(&mp_plat_print, "WASM: Aborting\n");
76+
//__builtin_trap();
77+
mp_raise_msg(&mp_type_RuntimeError, "WASM: Aborted");
7378
for(;;) {} // Should not reach here
7479
}
7580

runtime/runtime.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "py/dynruntime.h"
77
#include "wasm.h"
88

9+
#define mp_type_AttributeError (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_AttributeError)))
10+
911
// Instance of the WASM module
1012
w2c_wasm module;
1113

@@ -35,13 +37,13 @@ static mp_obj_t getattr(mp_obj_t attr) {
3537
size_t attr_len;
3638
char* attr_str = mp_obj_str_get_data(attr, &attr_len);
3739
if (!attr_str) {
38-
mp_raise_msg(&mp_type_RuntimeError, "Invalid attr");
40+
mp_raise_msg(&mp_type_AttributeError, "Invalid attr");
3941
return mp_const_none;
4042
}
4143
if (!strncmp(attr_str, "_memory", attr_len + 1)) {
4244
return mp_obj_new_bytearray_by_ref(module.w2c_memory.size, (void*)(module.w2c_memory.data));
4345
} else {
44-
mp_raise_msg(&mp_type_RuntimeError, "Unknown attr");
46+
mp_raise_msg(&mp_type_AttributeError, "Unknown attr");
4547
return mp_const_none;
4648
}
4749
}
@@ -73,7 +75,10 @@ void w2c_wiring_digitalWrite(struct w2c_wiring* wiring, u32 pin, u32 value) {
7375
}
7476

7577
void w2c_wiring_print(struct w2c_wiring* wiring, u32 offset, u32 len) {
76-
// TODO: verify bounds
78+
if (len > module.w2c_memory.size || offset > (module.w2c_memory.size - len)) {
79+
mp_raise_msg(&mp_type_RuntimeError, "OOB in external func");
80+
abort();
81+
}
7782
mp_printf(&mp_plat_print, "%.*s", len, (const uint8_t*)module.w2c_memory.data + offset);
7883
}
7984

0 commit comments

Comments
 (0)