|
6 | 6 | */
|
7 | 7 |
|
8 | 8 | /* minimal libc implementation */
|
9 |
| - |
10 |
| -#define NULL 0 |
11 |
| - |
12 |
| -#define bool _Bool |
13 |
| -#define true 1 |
14 |
| -#define false 0 |
15 |
| - |
16 |
| -#define INT_MAX 0x7fffffff |
17 |
| -#define INT_MIN 0x80000000 |
18 |
| - |
19 |
| -#if defined(__arm__) |
20 |
| -#define __SIZEOF_POINTER__ 4 |
21 |
| -#define __syscall_exit 1 |
22 |
| -#define __syscall_read 3 |
23 |
| -#define __syscall_write 4 |
24 |
| -#define __syscall_close 6 |
25 |
| -#define __syscall_open 5 |
26 |
| -#define __syscall_mmap2 192 |
27 |
| -#define __syscall_munmap 91 |
28 |
| - |
29 |
| -#elif defined(__riscv) |
30 |
| -#define __SIZEOF_POINTER__ 4 |
31 |
| -#define __syscall_exit 93 |
32 |
| -#define __syscall_read 63 |
33 |
| -#define __syscall_write 64 |
34 |
| -#define __syscall_close 57 |
35 |
| -#define __syscall_open 1024 |
36 |
| -#define __syscall_openat 56 |
37 |
| -#define __syscall_mmap2 222 |
38 |
| -#define __syscall_munmap 215 |
39 |
| - |
40 |
| -#else /* Only Arm32 and RV32 are supported */ |
41 |
| -#error "Unsupported architecture" |
42 |
| -#endif |
43 |
| - |
| 9 | +#include "c.h" |
44 | 10 | #define INT_BUF_LEN 16
|
45 | 11 |
|
46 |
| -typedef int FILE; |
47 |
| - |
48 |
| -/* va_list support for variadic functions */ |
49 |
| -typedef int *va_list; |
50 |
| - |
51 |
| -void abort(void); |
52 |
| - |
53 | 12 | int strlen(char *str)
|
54 | 13 | {
|
55 | 14 | /* process the string by checking 4 characters (a 32-bit word) at a time */
|
@@ -584,18 +543,11 @@ int fputc(int c, FILE *stream)
|
584 | 543 | return c;
|
585 | 544 | }
|
586 | 545 |
|
587 |
| -/* Non-portable: Assume page size is 4KiB */ |
588 |
| -#define PAGESIZE 4096 |
589 |
| - |
590 | 546 | #define CHUNK_SIZE_FREED_MASK 1
|
591 | 547 | #define CHUNK_SIZE_SZ_MASK 0xFFFFFFFE
|
592 | 548 | #define CHUNK_GET_SIZE(size) (size & CHUNK_SIZE_SZ_MASK)
|
593 | 549 | #define IS_CHUNK_GET_FREED(size) (size & CHUNK_SIZE_FREED_MASK)
|
594 | 550 |
|
595 |
| -/* Minimum alignment for all memory allocations. */ |
596 |
| -#define MIN_ALIGNMENT 8 |
597 |
| -#define ALIGN_UP(val, align) (((val) + (align) - 1) & ~((align) - 1)) |
598 |
| - |
599 | 551 | typedef struct chunk {
|
600 | 552 | struct chunk *next, *prev;
|
601 | 553 | int size;
|
|
0 commit comments