summaryrefslogtreecommitdiff
path: root/riscv/riscv-probe/examples/malloc
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-07-10 22:18:39 +0200
committerCarlos Maiolino <[email protected]>2025-07-10 22:18:39 +0200
commit8c6fc0c15415b32080a848bbde640e104098cf13 (patch)
tree04a21bd28f9dc82c8e216390d6208ed93b9bcd11 /riscv/riscv-probe/examples/malloc
Initial drop
Add some riscv code Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'riscv/riscv-probe/examples/malloc')
-rw-r--r--riscv/riscv-probe/examples/malloc/main.c21
-rw-r--r--riscv/riscv-probe/examples/malloc/rules.mk1
2 files changed, 22 insertions, 0 deletions
diff --git a/riscv/riscv-probe/examples/malloc/main.c b/riscv/riscv-probe/examples/malloc/main.c
new file mode 100644
index 0000000..cde2038
--- /dev/null
+++ b/riscv/riscv-probe/examples/malloc/main.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+ const size_t nelems = 8;
+ const size_t elemsize = 128;
+ char *alloc[nelems];
+
+ for (size_t i = 0; i < nelems; i++) {
+ if (alloc[i] = malloc(elemsize)) {
+ memset(alloc[i], 0, elemsize);
+ }
+ printf("malloc[%d]=0x%x\n", i, alloc[i]);
+ }
+
+ for (size_t i = 0; i < nelems; i++) {
+ free(alloc[i]);
+ }
+} \ No newline at end of file
diff --git a/riscv/riscv-probe/examples/malloc/rules.mk b/riscv/riscv-probe/examples/malloc/rules.mk
new file mode 100644
index 0000000..82b0bc6
--- /dev/null
+++ b/riscv/riscv-probe/examples/malloc/rules.mk
@@ -0,0 +1 @@
+malloc_objs = main.o