/* libc.h - Minimal libc for Pactor64 userspace programs */ #ifndef _LIBC_H #define _LIBC_H /* Basic types for freestanding userspace */ typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef unsigned long uint64_t; typedef signed char int8_t; typedef signed short int16_t; typedef signed int int32_t; typedef signed long int64_t; typedef uint64_t size_t; typedef int64_t ssize_t; #define NULL ((void *)0) /* GCC built-in va_list for variadic functions */ typedef __builtin_va_list va_list; #define va_start(v,l) __builtin_va_start(v,l) #define va_end(v) __builtin_va_end(v) #define va_arg(v,t) __builtin_va_arg(v,t) /* === System call wrappers === */ /* write(fd, buf, count) */ long write(int fd, const void *buf, unsigned long count); /* read(fd, buf, count) */ long read(int fd, void *buf, unsigned long count); /* exit(status) - does not return */ void exit(int status) __attribute__((noreturn)); /* brk(addr) - set program break */ long brk(void *addr); /* === String functions === */ unsigned long strlen(const char *s); int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, unsigned long n); char *strcpy(char *dst, const char *src); char *strncpy(char *dst, const char *src, unsigned long n); void *memset(void *s, int c, unsigned long n); void *memcpy(void *dst, const void *src, unsigned long n); void *memmove(void *dst, const void *src, unsigned long n); /* === Memory allocation (bump allocator) === */ void *malloc(unsigned long size); void free(void *ptr); /* === I/O === */ int puts(const char *s); int putchar(int c); /* printf - simplified, supports %d, %s, %x, %c, %u, %% */ int printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); /* === Entry point === */ /* _start is defined in start.c and calls main() */ extern int main(int argc, char **argv); #endif /* _LIBC_H */