elibc 0.1.0

edos kernel libc
Documentation
#include "stdint.h"

#define PROT_NONE 0

#define PROT_READ 1

#define PROT_WRITE 2

#define PROT_EXEC 4

#define MAP_PRIVATE 2

#define MAP_ANONYMOUS 32

#define MAP_FIXED 16

#define MAP_FAILED ~0ull

#define STDIN_FD 0

#define STDOUT_FD 1

void *malloc(uint64_t size);

void free(void *_ptr);

void *memcpy(void *dest, const void *src, uintptr_t n);

uint8_t *memmove(uint8_t *dest, const uint8_t *src, uintptr_t n);

void *memset(void *dst, int value, uintptr_t n);

int32_t memcmp(const uint8_t *s1, const uint8_t *s2, uintptr_t n);

int strlen(const int8_t *s);

void *strcpy(void *dest, const void *src);

void *strncpy(void *dest, const void *src, uintptr_t n);

void bzero(void *dst, uintptr_t count);

int bcmp(const void *s1, const void *s2, uintptr_t n);

/**
 * # Safety
 *
 * Pointer and len must be valid.
 */
uint64_t write(uint64_t fd, const uint8_t *data, uint64_t len);

uint64_t read(uint64_t fd, uint8_t *data, uint64_t len);

uint64_t open(const int8_t *path, uint64_t flags);

uint64_t close(uint64_t fd);

void exit(uint64_t code);

/**
 * Change data segment size.
 *
 * If addr is 0, returns current break.
 *
 * Otherwise, attempts to set break to addr.
 *
 * Returns new break on success, current break on failure.
 */
uint64_t brk(uint64_t addr);

/**
 * Allocate memory by expanding heap (simple sbrk-like function)
 */
uint64_t sbrk(int64_t increment);

/**
 * Map memory into the process address space
 *
 * # Safety
 * The caller must ensure proper usage of the returned pointer
 */
uint8_t *mmap(void *addr,
              uint64_t length,
              uint64_t prot,
              uint64_t flags,
              int32_t fd,
              uint64_t offset);

/**
 * Unmap memory from the process address space
 */
int32_t munmap(void *addr, uint64_t length);

/**
 * Raw syscall with 3 arguments
 */
uint64_t syscall3(uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3);

/**
 * Raw syscall with 1 argument
 */
uint64_t syscall1(uint64_t num, uint64_t arg1);

/**
 * Raw syscall with 6 arguments
 */
uint64_t syscall6(uint64_t num,
                  uint64_t arg1,
                  uint64_t arg2,
                  uint64_t arg3,
                  uint64_t arg4,
                  uint64_t arg5,
                  uint64_t arg6);

/**
 * Raw syscall with 2 arguments
 */
uint64_t syscall2(uint64_t num, uint64_t arg1, uint64_t arg2);

void puts(const char *text);