mirror of
https://github.com/Leonmmcoset/cleonos.git
synced 2026-04-24 11:14:01 +00:00
应用程序套件
This commit is contained in:
48
kit/runtime/dlfcn.c
Normal file
48
kit/runtime/dlfcn.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <cleonos_syscall.h>
|
||||
|
||||
void *dlopen(const char *path, int flags) {
|
||||
u64 handle;
|
||||
|
||||
(void)flags;
|
||||
|
||||
if (path == (const char *)0 || path[0] == '\0') {
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
handle = cleonos_sys_dl_open(path);
|
||||
|
||||
if (handle == 0ULL || handle == (u64)-1) {
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
return (void *)handle;
|
||||
}
|
||||
|
||||
void *dlsym(void *handle, const char *symbol) {
|
||||
u64 addr;
|
||||
|
||||
if (handle == (void *)0 || symbol == (const char *)0 || symbol[0] == '\0') {
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
addr = cleonos_sys_dl_sym((u64)handle, symbol);
|
||||
|
||||
if (addr == 0ULL || addr == (u64)-1) {
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
return (void *)addr;
|
||||
}
|
||||
|
||||
int dlclose(void *handle) {
|
||||
u64 rc;
|
||||
|
||||
if (handle == (void *)0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = cleonos_sys_dl_close((u64)handle);
|
||||
return (rc == (u64)-1) ? -1 : 0;
|
||||
}
|
||||
45
kit/runtime/libc_ctype.c
Normal file
45
kit/runtime/libc_ctype.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int isspace(int ch) {
|
||||
return (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '\v' || ch == '\f') ? 1 : 0;
|
||||
}
|
||||
|
||||
int isdigit(int ch) {
|
||||
return (ch >= '0' && ch <= '9') ? 1 : 0;
|
||||
}
|
||||
|
||||
int isalpha(int ch) {
|
||||
return ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) ? 1 : 0;
|
||||
}
|
||||
|
||||
int isalnum(int ch) {
|
||||
return (isalpha(ch) != 0 || isdigit(ch) != 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
int isxdigit(int ch) {
|
||||
return (isdigit(ch) != 0 || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) ? 1 : 0;
|
||||
}
|
||||
|
||||
int isupper(int ch) {
|
||||
return (ch >= 'A' && ch <= 'Z') ? 1 : 0;
|
||||
}
|
||||
|
||||
int islower(int ch) {
|
||||
return (ch >= 'a' && ch <= 'z') ? 1 : 0;
|
||||
}
|
||||
|
||||
int isprint(int ch) {
|
||||
return (ch >= 0x20 && ch <= 0x7E) ? 1 : 0;
|
||||
}
|
||||
|
||||
int iscntrl(int ch) {
|
||||
return (ch >= 0x00 && ch <= 0x1F) || ch == 0x7F ? 1 : 0;
|
||||
}
|
||||
|
||||
int tolower(int ch) {
|
||||
return (isupper(ch) != 0) ? (ch - 'A' + 'a') : ch;
|
||||
}
|
||||
|
||||
int toupper(int ch) {
|
||||
return (islower(ch) != 0) ? (ch - 'a' + 'A') : ch;
|
||||
}
|
||||
254
kit/runtime/libc_stdlib.c
Normal file
254
kit/runtime/libc_stdlib.c
Normal file
@@ -0,0 +1,254 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <cleonos_syscall.h>
|
||||
|
||||
static int clib_digit_value(int ch) {
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
return ch - '0';
|
||||
}
|
||||
|
||||
if (ch >= 'a' && ch <= 'z') {
|
||||
return 10 + (ch - 'a');
|
||||
}
|
||||
|
||||
if (ch >= 'A' && ch <= 'Z') {
|
||||
return 10 + (ch - 'A');
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static const char *clib_skip_space(const char *text) {
|
||||
const char *p = text;
|
||||
|
||||
if (p == (const char *)0) {
|
||||
return (const char *)0;
|
||||
}
|
||||
|
||||
while (*p != '\0' && isspace((unsigned char)*p) != 0) {
|
||||
p++;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int abs(int value) {
|
||||
return (value < 0) ? -value : value;
|
||||
}
|
||||
|
||||
long labs(long value) {
|
||||
return (value < 0L) ? -value : value;
|
||||
}
|
||||
|
||||
long long llabs(long long value) {
|
||||
return (value < 0LL) ? -value : value;
|
||||
}
|
||||
|
||||
int atoi(const char *text) {
|
||||
return (int)strtol(text, (char **)0, 10);
|
||||
}
|
||||
|
||||
long atol(const char *text) {
|
||||
return strtol(text, (char **)0, 10);
|
||||
}
|
||||
|
||||
long long atoll(const char *text) {
|
||||
return strtoll(text, (char **)0, 10);
|
||||
}
|
||||
|
||||
unsigned long strtoul(const char *text, char **out_end, int base) {
|
||||
const char *p = clib_skip_space(text);
|
||||
int negative = 0;
|
||||
unsigned long value = 0UL;
|
||||
int any = 0;
|
||||
int overflow = 0;
|
||||
|
||||
if (out_end != (char **)0) {
|
||||
*out_end = (char *)text;
|
||||
}
|
||||
|
||||
if (p == (const char *)0) {
|
||||
return 0UL;
|
||||
}
|
||||
|
||||
if (*p == '+' || *p == '-') {
|
||||
negative = (*p == '-') ? 1 : 0;
|
||||
p++;
|
||||
}
|
||||
|
||||
if (base == 0) {
|
||||
if (p[0] == '0') {
|
||||
if ((p[1] == 'x' || p[1] == 'X') && isxdigit((unsigned char)p[2]) != 0) {
|
||||
base = 16;
|
||||
p += 2;
|
||||
} else {
|
||||
base = 8;
|
||||
}
|
||||
} else {
|
||||
base = 10;
|
||||
}
|
||||
} else if (base == 16) {
|
||||
if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
|
||||
p += 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (base < 2 || base > 36) {
|
||||
return 0UL;
|
||||
}
|
||||
|
||||
while (*p != '\0') {
|
||||
int digit = clib_digit_value((unsigned char)*p);
|
||||
|
||||
if (digit < 0 || digit >= base) {
|
||||
break;
|
||||
}
|
||||
|
||||
any = 1;
|
||||
|
||||
if (value > (ULONG_MAX - (unsigned long)digit) / (unsigned long)base) {
|
||||
overflow = 1;
|
||||
value = ULONG_MAX;
|
||||
} else if (overflow == 0) {
|
||||
value = value * (unsigned long)base + (unsigned long)digit;
|
||||
}
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
if (any == 0) {
|
||||
return 0UL;
|
||||
}
|
||||
|
||||
if (out_end != (char **)0) {
|
||||
*out_end = (char *)p;
|
||||
}
|
||||
|
||||
if (negative != 0) {
|
||||
return (unsigned long)(0UL - value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
long strtol(const char *text, char **out_end, int base) {
|
||||
const char *p = clib_skip_space(text);
|
||||
int negative = 0;
|
||||
unsigned long long value = 0ULL;
|
||||
unsigned long long limit;
|
||||
int any = 0;
|
||||
int overflow = 0;
|
||||
|
||||
if (out_end != (char **)0) {
|
||||
*out_end = (char *)text;
|
||||
}
|
||||
|
||||
if (p == (const char *)0) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
if (*p == '+' || *p == '-') {
|
||||
negative = (*p == '-') ? 1 : 0;
|
||||
p++;
|
||||
}
|
||||
|
||||
if (base == 0) {
|
||||
if (p[0] == '0') {
|
||||
if ((p[1] == 'x' || p[1] == 'X') && isxdigit((unsigned char)p[2]) != 0) {
|
||||
base = 16;
|
||||
p += 2;
|
||||
} else {
|
||||
base = 8;
|
||||
}
|
||||
} else {
|
||||
base = 10;
|
||||
}
|
||||
} else if (base == 16) {
|
||||
if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
|
||||
p += 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (base < 2 || base > 36) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
limit = (negative != 0) ? ((unsigned long long)LONG_MAX + 1ULL) : (unsigned long long)LONG_MAX;
|
||||
|
||||
while (*p != '\0') {
|
||||
int digit = clib_digit_value((unsigned char)*p);
|
||||
|
||||
if (digit < 0 || digit >= base) {
|
||||
break;
|
||||
}
|
||||
|
||||
any = 1;
|
||||
|
||||
if (value > (limit - (unsigned long long)digit) / (unsigned long long)base) {
|
||||
overflow = 1;
|
||||
value = limit;
|
||||
} else if (overflow == 0) {
|
||||
value = value * (unsigned long long)base + (unsigned long long)digit;
|
||||
}
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
if (any == 0) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
if (out_end != (char **)0) {
|
||||
*out_end = (char *)p;
|
||||
}
|
||||
|
||||
if (overflow != 0) {
|
||||
return (negative != 0) ? LONG_MIN : LONG_MAX;
|
||||
}
|
||||
|
||||
if (negative != 0) {
|
||||
if (value == ((unsigned long long)LONG_MAX + 1ULL)) {
|
||||
return LONG_MIN;
|
||||
}
|
||||
return -(long)value;
|
||||
}
|
||||
|
||||
return (long)value;
|
||||
}
|
||||
|
||||
long long strtoll(const char *text, char **out_end, int base) {
|
||||
return (long long)strtol(text, out_end, base);
|
||||
}
|
||||
|
||||
unsigned long long strtoull(const char *text, char **out_end, int base) {
|
||||
return (unsigned long long)strtoul(text, out_end, base);
|
||||
}
|
||||
|
||||
static unsigned long clib_rand_state = 1UL;
|
||||
|
||||
void srand(unsigned int seed) {
|
||||
clib_rand_state = (unsigned long)seed;
|
||||
if (clib_rand_state == 0UL) {
|
||||
clib_rand_state = 1UL;
|
||||
}
|
||||
}
|
||||
|
||||
int rand(void) {
|
||||
clib_rand_state = (1103515245UL * clib_rand_state) + 12345UL;
|
||||
return (int)((clib_rand_state >> 16) & (unsigned long)RAND_MAX);
|
||||
}
|
||||
|
||||
void exit(int status) {
|
||||
(void)cleonos_sys_exit((u64)(unsigned long long)status);
|
||||
|
||||
for (;;) {
|
||||
(void)cleonos_sys_yield();
|
||||
}
|
||||
}
|
||||
|
||||
void abort(void) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
445
kit/runtime/libc_string.c
Normal file
445
kit/runtime/libc_string.c
Normal file
@@ -0,0 +1,445 @@
|
||||
#include <string.h>
|
||||
|
||||
void *memset(void *dst, int value, size_t size) {
|
||||
unsigned char *d = (unsigned char *)dst;
|
||||
unsigned char byte = (unsigned char)value;
|
||||
size_t i;
|
||||
|
||||
if (d == (unsigned char *)0) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
for (i = 0U; i < size; i++) {
|
||||
d[i] = byte;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t size) {
|
||||
unsigned char *d = (unsigned char *)dst;
|
||||
const unsigned char *s = (const unsigned char *)src;
|
||||
size_t i;
|
||||
|
||||
if (d == (unsigned char *)0 || s == (const unsigned char *)0) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
for (i = 0U; i < size; i++) {
|
||||
d[i] = s[i];
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memmove(void *dst, const void *src, size_t size) {
|
||||
unsigned char *d = (unsigned char *)dst;
|
||||
const unsigned char *s = (const unsigned char *)src;
|
||||
size_t i;
|
||||
|
||||
if (d == (unsigned char *)0 || s == (const unsigned char *)0 || d == s || size == 0U) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
if (d < s || d >= s + size) {
|
||||
for (i = 0U; i < size; i++) {
|
||||
d[i] = s[i];
|
||||
}
|
||||
} else {
|
||||
for (i = size; i > 0U; i--) {
|
||||
d[i - 1U] = s[i - 1U];
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
int memcmp(const void *left, const void *right, size_t size) {
|
||||
const unsigned char *a = (const unsigned char *)left;
|
||||
const unsigned char *b = (const unsigned char *)right;
|
||||
size_t i;
|
||||
|
||||
if (a == b || size == 0U) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a == (const unsigned char *)0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (b == (const unsigned char *)0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0U; i < size; i++) {
|
||||
if (a[i] != b[i]) {
|
||||
return (a[i] < b[i]) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *memchr(const void *src, int value, size_t size) {
|
||||
const unsigned char *s = (const unsigned char *)src;
|
||||
unsigned char needle = (unsigned char)value;
|
||||
size_t i;
|
||||
|
||||
if (s == (const unsigned char *)0) {
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
for (i = 0U; i < size; i++) {
|
||||
if (s[i] == needle) {
|
||||
return (void *)(s + i);
|
||||
}
|
||||
}
|
||||
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
size_t strlen(const char *text) {
|
||||
size_t len = 0U;
|
||||
|
||||
if (text == (const char *)0) {
|
||||
return 0U;
|
||||
}
|
||||
|
||||
while (text[len] != '\0') {
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t strnlen(const char *text, size_t max_size) {
|
||||
size_t len = 0U;
|
||||
|
||||
if (text == (const char *)0) {
|
||||
return 0U;
|
||||
}
|
||||
|
||||
while (len < max_size && text[len] != '\0') {
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
char *strcpy(char *dst, const char *src) {
|
||||
size_t i = 0U;
|
||||
|
||||
if (dst == (char *)0 || src == (const char *)0) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
while (src[i] != '\0') {
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
dst[i] = '\0';
|
||||
return dst;
|
||||
}
|
||||
|
||||
char *strncpy(char *dst, const char *src, size_t size) {
|
||||
size_t i = 0U;
|
||||
|
||||
if (dst == (char *)0 || src == (const char *)0) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
while (i < size && src[i] != '\0') {
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
while (i < size) {
|
||||
dst[i++] = '\0';
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
int strcmp(const char *left, const char *right) {
|
||||
size_t i = 0U;
|
||||
|
||||
if (left == right) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (left == (const char *)0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (right == (const char *)0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (left[i] != '\0' && right[i] != '\0') {
|
||||
if (left[i] != right[i]) {
|
||||
return (left[i] < right[i]) ? -1 : 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (left[i] == right[i]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (left[i] < right[i]) ? -1 : 1;
|
||||
}
|
||||
|
||||
int strncmp(const char *left, const char *right, size_t size) {
|
||||
size_t i = 0U;
|
||||
|
||||
if (size == 0U || left == right) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (left == (const char *)0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (right == (const char *)0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (i < size && left[i] != '\0' && right[i] != '\0') {
|
||||
if (left[i] != right[i]) {
|
||||
return (left[i] < right[i]) ? -1 : 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i == size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (left[i] == right[i]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (left[i] < right[i]) ? -1 : 1;
|
||||
}
|
||||
|
||||
char *strchr(const char *text, int ch) {
|
||||
char needle = (char)ch;
|
||||
size_t i = 0U;
|
||||
|
||||
if (text == (const char *)0) {
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
while (text[i] != '\0') {
|
||||
if (text[i] == needle) {
|
||||
return (char *)(text + i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (needle == '\0') {
|
||||
return (char *)(text + i);
|
||||
}
|
||||
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
char *strrchr(const char *text, int ch) {
|
||||
char needle = (char)ch;
|
||||
const char *last = (const char *)0;
|
||||
size_t i = 0U;
|
||||
|
||||
if (text == (const char *)0) {
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
while (text[i] != '\0') {
|
||||
if (text[i] == needle) {
|
||||
last = text + i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (needle == '\0') {
|
||||
return (char *)(text + i);
|
||||
}
|
||||
|
||||
return (char *)last;
|
||||
}
|
||||
|
||||
char *strstr(const char *haystack, const char *needle) {
|
||||
size_t i;
|
||||
size_t j;
|
||||
size_t nlen;
|
||||
|
||||
if (haystack == (const char *)0 || needle == (const char *)0) {
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
nlen = strlen(needle);
|
||||
if (nlen == 0U) {
|
||||
return (char *)haystack;
|
||||
}
|
||||
|
||||
for (i = 0U; haystack[i] != '\0'; i++) {
|
||||
if (haystack[i] != needle[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (j = 1U; j < nlen; j++) {
|
||||
if (haystack[i + j] == '\0' || haystack[i + j] != needle[j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == nlen) {
|
||||
return (char *)(haystack + i);
|
||||
}
|
||||
}
|
||||
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
static int clib_delim_contains(const char *delim, char ch) {
|
||||
size_t i = 0U;
|
||||
|
||||
if (delim == (const char *)0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (delim[i] != '\0') {
|
||||
if (delim[i] == ch) {
|
||||
return 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t strspn(const char *text, const char *accept) {
|
||||
size_t n = 0U;
|
||||
|
||||
if (text == (const char *)0 || accept == (const char *)0) {
|
||||
return 0U;
|
||||
}
|
||||
|
||||
while (text[n] != '\0' && clib_delim_contains(accept, text[n]) != 0) {
|
||||
n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t strcspn(const char *text, const char *reject) {
|
||||
size_t n = 0U;
|
||||
|
||||
if (text == (const char *)0 || reject == (const char *)0) {
|
||||
return 0U;
|
||||
}
|
||||
|
||||
while (text[n] != '\0' && clib_delim_contains(reject, text[n]) == 0) {
|
||||
n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
char *strpbrk(const char *text, const char *accept) {
|
||||
size_t i = 0U;
|
||||
|
||||
if (text == (const char *)0 || accept == (const char *)0) {
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
while (text[i] != '\0') {
|
||||
if (clib_delim_contains(accept, text[i]) != 0) {
|
||||
return (char *)(text + i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
char *strtok_r(char *text, const char *delim, char **saveptr) {
|
||||
char *start;
|
||||
char *cursor;
|
||||
|
||||
if (delim == (const char *)0 || saveptr == (char **)0) {
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
if (text != (char *)0) {
|
||||
cursor = text;
|
||||
} else {
|
||||
cursor = *saveptr;
|
||||
}
|
||||
|
||||
if (cursor == (char *)0) {
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
while (*cursor != '\0' && clib_delim_contains(delim, *cursor) != 0) {
|
||||
cursor++;
|
||||
}
|
||||
|
||||
if (*cursor == '\0') {
|
||||
*saveptr = cursor;
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
start = cursor;
|
||||
while (*cursor != '\0' && clib_delim_contains(delim, *cursor) == 0) {
|
||||
cursor++;
|
||||
}
|
||||
|
||||
if (*cursor == '\0') {
|
||||
*saveptr = cursor;
|
||||
} else {
|
||||
*cursor = '\0';
|
||||
*saveptr = cursor + 1;
|
||||
}
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
char *strtok(char *text, const char *delim) {
|
||||
static char *state = (char *)0;
|
||||
return strtok_r(text, delim, &state);
|
||||
}
|
||||
|
||||
char *strcat(char *dst, const char *src) {
|
||||
size_t dlen = strlen(dst);
|
||||
size_t i = 0U;
|
||||
|
||||
if (dst == (char *)0 || src == (const char *)0) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
while (src[i] != '\0') {
|
||||
dst[dlen + i] = src[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
dst[dlen + i] = '\0';
|
||||
return dst;
|
||||
}
|
||||
|
||||
char *strncat(char *dst, const char *src, size_t size) {
|
||||
size_t dlen = strlen(dst);
|
||||
size_t i = 0U;
|
||||
|
||||
if (dst == (char *)0 || src == (const char *)0) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
while (i < size && src[i] != '\0') {
|
||||
dst[dlen + i] = src[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
dst[dlen + i] = '\0';
|
||||
return dst;
|
||||
}
|
||||
8
kit/runtime/main_adapter.c
Normal file
8
kit/runtime/main_adapter.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <cleonos_syscall.h>
|
||||
|
||||
extern int main(int argc, char **argv);
|
||||
|
||||
int cleonos_app_main(int argc, char **argv, char **envp) {
|
||||
(void)envp;
|
||||
return main(argc, argv);
|
||||
}
|
||||
53
kit/runtime/runtime.c
Normal file
53
kit/runtime/runtime.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <cleonos_syscall.h>
|
||||
|
||||
#define CLEONOS_RUNTIME_ARGV_MAX 24ULL
|
||||
#define CLEONOS_RUNTIME_ENVP_MAX 24ULL
|
||||
#define CLEONOS_RUNTIME_ITEM_MAX 128ULL
|
||||
|
||||
extern int cleonos_app_main(int argc, char **argv, char **envp);
|
||||
extern void cleonos_cmd_runtime_pre_main(char **envp) __attribute__((weak));
|
||||
|
||||
u64 _start(void) {
|
||||
static char argv_items[CLEONOS_RUNTIME_ARGV_MAX][CLEONOS_RUNTIME_ITEM_MAX];
|
||||
static char env_items[CLEONOS_RUNTIME_ENVP_MAX][CLEONOS_RUNTIME_ITEM_MAX];
|
||||
static char *argv_ptrs[CLEONOS_RUNTIME_ARGV_MAX + 1ULL];
|
||||
static char *env_ptrs[CLEONOS_RUNTIME_ENVP_MAX + 1ULL];
|
||||
u64 argc = 0ULL;
|
||||
u64 envc = 0ULL;
|
||||
u64 i;
|
||||
int code;
|
||||
|
||||
argc = cleonos_sys_proc_argc();
|
||||
envc = cleonos_sys_proc_envc();
|
||||
|
||||
if (argc > CLEONOS_RUNTIME_ARGV_MAX) {
|
||||
argc = CLEONOS_RUNTIME_ARGV_MAX;
|
||||
}
|
||||
|
||||
if (envc > CLEONOS_RUNTIME_ENVP_MAX) {
|
||||
envc = CLEONOS_RUNTIME_ENVP_MAX;
|
||||
}
|
||||
|
||||
for (i = 0ULL; i < argc; i++) {
|
||||
argv_items[i][0] = '\0';
|
||||
(void)cleonos_sys_proc_argv(i, argv_items[i], CLEONOS_RUNTIME_ITEM_MAX);
|
||||
argv_ptrs[i] = argv_items[i];
|
||||
}
|
||||
|
||||
argv_ptrs[argc] = (char *)0;
|
||||
|
||||
for (i = 0ULL; i < envc; i++) {
|
||||
env_items[i][0] = '\0';
|
||||
(void)cleonos_sys_proc_env(i, env_items[i], CLEONOS_RUNTIME_ITEM_MAX);
|
||||
env_ptrs[i] = env_items[i];
|
||||
}
|
||||
|
||||
env_ptrs[envc] = (char *)0;
|
||||
|
||||
if (cleonos_cmd_runtime_pre_main != (void (*)(char **))0) {
|
||||
cleonos_cmd_runtime_pre_main(env_ptrs);
|
||||
}
|
||||
|
||||
code = cleonos_app_main((int)argc, argv_ptrs, env_ptrs);
|
||||
return (u64)code;
|
||||
}
|
||||
712
kit/runtime/stdio.c
Normal file
712
kit/runtime/stdio.c
Normal file
@@ -0,0 +1,712 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <cleonos_syscall.h>
|
||||
|
||||
typedef unsigned long clio_size_t;
|
||||
|
||||
#define CLIO_SINK_FD 1
|
||||
#define CLIO_SINK_BUF 2
|
||||
|
||||
struct clio_sink {
|
||||
int mode;
|
||||
int fd;
|
||||
char *buffer;
|
||||
clio_size_t capacity;
|
||||
clio_size_t count;
|
||||
int failed;
|
||||
};
|
||||
|
||||
static clio_size_t clio_strlen(const char *text) {
|
||||
clio_size_t len = 0UL;
|
||||
|
||||
if (text == (const char *)0) {
|
||||
return 0UL;
|
||||
}
|
||||
|
||||
while (text[len] != '\0') {
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int clio_write_all_fd(int fd, const char *text, clio_size_t len) {
|
||||
const char *cursor = text;
|
||||
clio_size_t left = len;
|
||||
|
||||
if (fd < 0 || (text == (const char *)0 && len != 0UL)) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
while (left > 0UL) {
|
||||
u64 wrote = cleonos_sys_fd_write((u64)fd, cursor, (u64)left);
|
||||
clio_size_t progressed;
|
||||
|
||||
if (wrote == 0ULL || wrote == (u64)-1) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
progressed = (wrote > (u64)left) ? left : (clio_size_t)wrote;
|
||||
cursor += progressed;
|
||||
left -= progressed;
|
||||
}
|
||||
|
||||
if (len > 0x7FFFFFFFUL) {
|
||||
return 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
static void clio_sink_init_fd(struct clio_sink *sink, int fd) {
|
||||
sink->mode = CLIO_SINK_FD;
|
||||
sink->fd = fd;
|
||||
sink->buffer = (char *)0;
|
||||
sink->capacity = 0UL;
|
||||
sink->count = 0UL;
|
||||
sink->failed = 0;
|
||||
}
|
||||
|
||||
static void clio_sink_init_buffer(struct clio_sink *sink, char *out, clio_size_t out_size) {
|
||||
sink->mode = CLIO_SINK_BUF;
|
||||
sink->fd = -1;
|
||||
sink->buffer = out;
|
||||
sink->capacity = out_size;
|
||||
sink->count = 0UL;
|
||||
sink->failed = 0;
|
||||
|
||||
if (out != (char *)0 && out_size > 0UL) {
|
||||
out[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static void clio_sink_finalize_buffer(struct clio_sink *sink) {
|
||||
if (sink->mode != CLIO_SINK_BUF || sink->buffer == (char *)0 || sink->capacity == 0UL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sink->count < sink->capacity) {
|
||||
sink->buffer[sink->count] = '\0';
|
||||
} else {
|
||||
sink->buffer[sink->capacity - 1UL] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static int clio_sink_emit(struct clio_sink *sink, const char *text, clio_size_t len) {
|
||||
if (sink == (struct clio_sink *)0 || text == (const char *)0 || len == 0UL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sink->mode == CLIO_SINK_FD) {
|
||||
if (clio_write_all_fd(sink->fd, text, len) == EOF) {
|
||||
sink->failed = 1;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (sink->buffer != (char *)0 && sink->capacity > 0UL) {
|
||||
clio_size_t i;
|
||||
clio_size_t start = sink->count;
|
||||
clio_size_t writable = 0UL;
|
||||
|
||||
if (start + 1UL < sink->capacity) {
|
||||
writable = (sink->capacity - 1UL) - start;
|
||||
}
|
||||
|
||||
if (len < writable) {
|
||||
writable = len;
|
||||
}
|
||||
|
||||
for (i = 0UL; i < writable; i++) {
|
||||
sink->buffer[start + i] = text[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sink->count += len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static clio_size_t clio_u64_to_base(unsigned long long value, unsigned int base, int uppercase, char *out,
|
||||
clio_size_t out_size) {
|
||||
char tmp[64];
|
||||
clio_size_t pos = 0UL;
|
||||
clio_size_t i = 0UL;
|
||||
|
||||
if (out == (char *)0 || out_size < 2UL || base < 2U || base > 16U) {
|
||||
return 0UL;
|
||||
}
|
||||
|
||||
if (value == 0ULL) {
|
||||
out[0] = '0';
|
||||
out[1] = '\0';
|
||||
return 1UL;
|
||||
}
|
||||
|
||||
while (value != 0ULL && pos < (clio_size_t)sizeof(tmp)) {
|
||||
unsigned long long digit = value % (unsigned long long)base;
|
||||
|
||||
if (digit < 10ULL) {
|
||||
tmp[pos++] = (char)('0' + digit);
|
||||
} else {
|
||||
char alpha = (uppercase != 0) ? 'A' : 'a';
|
||||
tmp[pos++] = (char)(alpha + (char)(digit - 10ULL));
|
||||
}
|
||||
|
||||
value /= (unsigned long long)base;
|
||||
}
|
||||
|
||||
if (pos + 1UL > out_size) {
|
||||
return 0UL;
|
||||
}
|
||||
|
||||
while (pos > 0UL) {
|
||||
pos--;
|
||||
out[i++] = tmp[pos];
|
||||
}
|
||||
|
||||
out[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
static clio_size_t clio_i64_to_dec(long long value, char *out, clio_size_t out_size) {
|
||||
unsigned long long magnitude;
|
||||
clio_size_t offset = 0UL;
|
||||
clio_size_t len;
|
||||
|
||||
if (out == (char *)0 || out_size < 2UL) {
|
||||
return 0UL;
|
||||
}
|
||||
|
||||
if (value < 0LL) {
|
||||
out[offset++] = '-';
|
||||
if (offset + 2UL > out_size) {
|
||||
return 0UL;
|
||||
}
|
||||
magnitude = (unsigned long long)(-(value + 1LL)) + 1ULL;
|
||||
} else {
|
||||
magnitude = (unsigned long long)value;
|
||||
}
|
||||
|
||||
len = clio_u64_to_base(magnitude, 10U, 0, out + offset, out_size - offset);
|
||||
|
||||
if (len == 0UL) {
|
||||
return 0UL;
|
||||
}
|
||||
|
||||
return offset + len;
|
||||
}
|
||||
|
||||
static int clio_is_digit(char ch) {
|
||||
return (ch >= '0' && ch <= '9') ? 1 : 0;
|
||||
}
|
||||
|
||||
static int clio_emit_repeat(struct clio_sink *sink, char ch, clio_size_t count) {
|
||||
while (count > 0UL) {
|
||||
if (clio_sink_emit(sink, &ch, 1UL) == 0) {
|
||||
return 0;
|
||||
}
|
||||
count--;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int clio_emit_with_width(struct clio_sink *sink, const char *text, clio_size_t text_len, int left_align,
|
||||
char pad_char, clio_size_t width) {
|
||||
if (left_align == 0 && width > text_len) {
|
||||
if (clio_emit_repeat(sink, pad_char, width - text_len) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (text_len > 0UL && clio_sink_emit(sink, text, text_len) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (left_align != 0 && width > text_len) {
|
||||
if (clio_emit_repeat(sink, ' ', width - text_len) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int clio_vformat(struct clio_sink *sink, const char *fmt, va_list args) {
|
||||
const char *cursor = fmt;
|
||||
|
||||
if (sink == (struct clio_sink *)0 || fmt == (const char *)0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
while (*cursor != '\0') {
|
||||
if (*cursor != '%') {
|
||||
if (clio_sink_emit(sink, cursor, 1UL) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
cursor++;
|
||||
continue;
|
||||
}
|
||||
|
||||
cursor++;
|
||||
|
||||
if (*cursor == '%') {
|
||||
if (clio_sink_emit(sink, "%", 1UL) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
cursor++;
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
int left_align = 0;
|
||||
int zero_pad = 0;
|
||||
clio_size_t width = 0UL;
|
||||
int has_precision = 0;
|
||||
clio_size_t precision = 0UL;
|
||||
int length_mode = 0; /* 0: default, 1: l, 2: ll, 3: z */
|
||||
char spec = *cursor;
|
||||
char number_buf[96];
|
||||
|
||||
while (spec == '-' || spec == '0') {
|
||||
if (spec == '-') {
|
||||
left_align = 1;
|
||||
} else if (spec == '0') {
|
||||
zero_pad = 1;
|
||||
}
|
||||
cursor++;
|
||||
spec = *cursor;
|
||||
}
|
||||
|
||||
while (clio_is_digit(spec) != 0) {
|
||||
width = (width * 10UL) + (clio_size_t)(unsigned long)(spec - '0');
|
||||
cursor++;
|
||||
spec = *cursor;
|
||||
}
|
||||
|
||||
if (spec == '.') {
|
||||
has_precision = 1;
|
||||
precision = 0UL;
|
||||
cursor++;
|
||||
spec = *cursor;
|
||||
|
||||
while (clio_is_digit(spec) != 0) {
|
||||
precision = (precision * 10UL) + (clio_size_t)(unsigned long)(spec - '0');
|
||||
cursor++;
|
||||
spec = *cursor;
|
||||
}
|
||||
}
|
||||
|
||||
if (spec == 'l') {
|
||||
cursor++;
|
||||
spec = *cursor;
|
||||
length_mode = 1;
|
||||
|
||||
if (spec == 'l') {
|
||||
cursor++;
|
||||
spec = *cursor;
|
||||
length_mode = 2;
|
||||
}
|
||||
} else if (spec == 'z') {
|
||||
cursor++;
|
||||
spec = *cursor;
|
||||
length_mode = 3;
|
||||
}
|
||||
|
||||
if (spec == '\0') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (spec == 's') {
|
||||
const char *text = va_arg(args, const char *);
|
||||
clio_size_t text_len;
|
||||
|
||||
if (text == (const char *)0) {
|
||||
text = "(null)";
|
||||
}
|
||||
|
||||
text_len = clio_strlen(text);
|
||||
if (has_precision != 0 && precision < text_len) {
|
||||
text_len = precision;
|
||||
}
|
||||
|
||||
if (clio_emit_with_width(sink, text, text_len, left_align, ' ', width) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
} else if (spec == 'c') {
|
||||
char out = (char)va_arg(args, int);
|
||||
char out_buf[1];
|
||||
|
||||
out_buf[0] = out;
|
||||
if (clio_emit_with_width(sink, out_buf, 1UL, left_align, ' ', width) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
} else if (spec == 'd' || spec == 'i') {
|
||||
long long value;
|
||||
char sign_char = '\0';
|
||||
const char *digits = number_buf;
|
||||
clio_size_t digits_len;
|
||||
clio_size_t leading_zeros = 0UL;
|
||||
clio_size_t core_len;
|
||||
int sign_emitted = 0;
|
||||
|
||||
if (length_mode == 2) {
|
||||
value = va_arg(args, long long);
|
||||
} else if (length_mode == 1) {
|
||||
value = (long long)va_arg(args, long);
|
||||
} else if (length_mode == 3) {
|
||||
value = (long long)va_arg(args, long long);
|
||||
} else {
|
||||
value = (long long)va_arg(args, int);
|
||||
}
|
||||
|
||||
digits_len = clio_i64_to_dec(value, number_buf, (clio_size_t)sizeof(number_buf));
|
||||
if (digits_len == 0UL) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (number_buf[0] == '-') {
|
||||
sign_char = '-';
|
||||
digits = number_buf + 1;
|
||||
digits_len--;
|
||||
}
|
||||
|
||||
if (has_precision != 0 && precision == 0UL && value == 0LL) {
|
||||
digits_len = 0UL;
|
||||
}
|
||||
|
||||
if (has_precision != 0 && precision > digits_len) {
|
||||
leading_zeros = precision - digits_len;
|
||||
}
|
||||
|
||||
core_len = digits_len + leading_zeros + ((sign_char != '\0') ? 1UL : 0UL);
|
||||
|
||||
if (left_align == 0 && width > core_len) {
|
||||
if (zero_pad != 0 && has_precision == 0) {
|
||||
if (sign_char != '\0') {
|
||||
if (clio_sink_emit(sink, &sign_char, 1UL) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
sign_emitted = 1;
|
||||
}
|
||||
if (clio_emit_repeat(sink, '0', width - core_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
} else {
|
||||
if (clio_emit_repeat(sink, ' ', width - core_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sign_char != '\0' && sign_emitted == 0) {
|
||||
if (clio_sink_emit(sink, &sign_char, 1UL) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
|
||||
if (clio_emit_repeat(sink, '0', leading_zeros) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (digits_len > 0UL && clio_sink_emit(sink, digits, digits_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (left_align != 0 && width > core_len) {
|
||||
if (clio_emit_repeat(sink, ' ', width - core_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
} else if (spec == 'u' || spec == 'x' || spec == 'X') {
|
||||
unsigned long long value;
|
||||
unsigned int base = (spec == 'u') ? 10U : 16U;
|
||||
int upper = (spec == 'X') ? 1 : 0;
|
||||
clio_size_t digits_len;
|
||||
clio_size_t leading_zeros = 0UL;
|
||||
clio_size_t core_len;
|
||||
char pad_char = ' ';
|
||||
|
||||
if (length_mode == 2) {
|
||||
value = va_arg(args, unsigned long long);
|
||||
} else if (length_mode == 1) {
|
||||
value = (unsigned long long)va_arg(args, unsigned long);
|
||||
} else if (length_mode == 3) {
|
||||
value = (unsigned long long)va_arg(args, unsigned long long);
|
||||
} else {
|
||||
value = (unsigned long long)va_arg(args, unsigned int);
|
||||
}
|
||||
|
||||
digits_len = clio_u64_to_base(value, base, upper, number_buf, (clio_size_t)sizeof(number_buf));
|
||||
if (digits_len == 0UL) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (has_precision != 0 && precision == 0UL && value == 0ULL) {
|
||||
digits_len = 0UL;
|
||||
}
|
||||
|
||||
if (has_precision != 0 && precision > digits_len) {
|
||||
leading_zeros = precision - digits_len;
|
||||
}
|
||||
|
||||
core_len = digits_len + leading_zeros;
|
||||
|
||||
if (zero_pad != 0 && has_precision == 0 && left_align == 0) {
|
||||
pad_char = '0';
|
||||
}
|
||||
|
||||
if (left_align == 0 && width > core_len) {
|
||||
if (clio_emit_repeat(sink, pad_char, width - core_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
|
||||
if (clio_emit_repeat(sink, '0', leading_zeros) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (digits_len > 0UL && clio_sink_emit(sink, number_buf, digits_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (left_align != 0 && width > core_len) {
|
||||
if (clio_emit_repeat(sink, ' ', width - core_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
} else if (spec == 'p') {
|
||||
const void *ptr = va_arg(args, const void *);
|
||||
unsigned long long value = (unsigned long long)(usize)ptr;
|
||||
clio_size_t digits_len;
|
||||
clio_size_t leading_zeros = 0UL;
|
||||
clio_size_t core_len;
|
||||
|
||||
digits_len = clio_u64_to_base(value, 16U, 0, number_buf, (clio_size_t)sizeof(number_buf));
|
||||
if (digits_len == 0UL) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (has_precision != 0 && precision == 0UL && value == 0ULL) {
|
||||
digits_len = 0UL;
|
||||
}
|
||||
|
||||
if (has_precision != 0 && precision > digits_len) {
|
||||
leading_zeros = precision - digits_len;
|
||||
}
|
||||
|
||||
core_len = 2UL + leading_zeros + digits_len;
|
||||
|
||||
if (left_align == 0 && width > core_len) {
|
||||
if (clio_emit_repeat(sink, ' ', width - core_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
|
||||
if (clio_sink_emit(sink, "0x", 2UL) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (clio_emit_repeat(sink, '0', leading_zeros) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (digits_len > 0UL && clio_sink_emit(sink, number_buf, digits_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (left_align != 0 && width > core_len) {
|
||||
if (clio_emit_repeat(sink, ' ', width - core_len) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
} else if (spec == 'n') {
|
||||
int *out_count = va_arg(args, int *);
|
||||
if (out_count != (int *)0) {
|
||||
if (sink->count > 0x7FFFFFFFUL) {
|
||||
*out_count = 0x7FFFFFFF;
|
||||
} else {
|
||||
*out_count = (int)sink->count;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
char fallback[2];
|
||||
fallback[0] = spec;
|
||||
fallback[1] = '\0';
|
||||
|
||||
if (clio_sink_emit(sink, "%", 1UL) == 0 || clio_sink_emit(sink, fallback, 1UL) == 0) {
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
|
||||
cursor++;
|
||||
}
|
||||
}
|
||||
|
||||
if (sink->mode == CLIO_SINK_BUF) {
|
||||
clio_sink_finalize_buffer(sink);
|
||||
}
|
||||
|
||||
if (sink->failed != 0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (sink->count > 0x7FFFFFFFUL) {
|
||||
return 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
return (int)sink->count;
|
||||
}
|
||||
|
||||
int putchar(int ch) {
|
||||
char out = (char)(ch & 0xFF);
|
||||
return (clio_write_all_fd(1, &out, 1UL) == EOF) ? EOF : (int)(unsigned char)out;
|
||||
}
|
||||
|
||||
int getchar(void) {
|
||||
char ch = '\0';
|
||||
|
||||
for (;;) {
|
||||
u64 got = cleonos_sys_fd_read(0ULL, &ch, 1ULL);
|
||||
|
||||
if (got == 1ULL) {
|
||||
return (int)(unsigned char)ch;
|
||||
}
|
||||
|
||||
if (got == (u64)-1) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
(void)cleonos_sys_yield();
|
||||
}
|
||||
}
|
||||
|
||||
int fputc(int ch, int fd) {
|
||||
char out = (char)(ch & 0xFF);
|
||||
return (clio_write_all_fd(fd, &out, 1UL) == EOF) ? EOF : (int)(unsigned char)out;
|
||||
}
|
||||
|
||||
int fgetc(int fd) {
|
||||
char ch = '\0';
|
||||
|
||||
if (fd < 0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
u64 got = cleonos_sys_fd_read((u64)fd, &ch, 1ULL);
|
||||
|
||||
if (got == 1ULL) {
|
||||
return (int)(unsigned char)ch;
|
||||
}
|
||||
|
||||
if (got == (u64)-1) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
(void)cleonos_sys_yield();
|
||||
}
|
||||
}
|
||||
|
||||
int fputs(const char *text, int fd) {
|
||||
clio_size_t len;
|
||||
|
||||
if (text == (const char *)0) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
len = clio_strlen(text);
|
||||
return clio_write_all_fd(fd, text, len);
|
||||
}
|
||||
|
||||
int puts(const char *text) {
|
||||
int wrote = fputs(text, 1);
|
||||
|
||||
if (wrote == EOF) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (putchar('\n') == EOF) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
return wrote + 1;
|
||||
}
|
||||
|
||||
int vsnprintf(char *out, unsigned long out_size, const char *fmt, va_list args) {
|
||||
struct clio_sink sink;
|
||||
va_list args_copy;
|
||||
int rc;
|
||||
|
||||
clio_sink_init_buffer(&sink, out, out_size);
|
||||
va_copy(args_copy, args);
|
||||
rc = clio_vformat(&sink, fmt, args_copy);
|
||||
va_end(args_copy);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int snprintf(char *out, unsigned long out_size, const char *fmt, ...) {
|
||||
va_list args;
|
||||
int rc;
|
||||
|
||||
va_start(args, fmt);
|
||||
rc = vsnprintf(out, out_size, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int vdprintf(int fd, const char *fmt, va_list args) {
|
||||
struct clio_sink sink;
|
||||
va_list args_copy;
|
||||
int rc;
|
||||
|
||||
clio_sink_init_fd(&sink, fd);
|
||||
va_copy(args_copy, args);
|
||||
rc = clio_vformat(&sink, fmt, args_copy);
|
||||
va_end(args_copy);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int dprintf(int fd, const char *fmt, ...) {
|
||||
va_list args;
|
||||
int rc;
|
||||
|
||||
va_start(args, fmt);
|
||||
rc = vdprintf(fd, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int vfprintf(int fd, const char *fmt, va_list args) {
|
||||
return vdprintf(fd, fmt, args);
|
||||
}
|
||||
|
||||
int fprintf(int fd, const char *fmt, ...) {
|
||||
va_list args;
|
||||
int rc;
|
||||
|
||||
va_start(args, fmt);
|
||||
rc = vdprintf(fd, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int vprintf(const char *fmt, va_list args) {
|
||||
return vdprintf(1, fmt, args);
|
||||
}
|
||||
|
||||
int printf(const char *fmt, ...) {
|
||||
va_list args;
|
||||
int rc;
|
||||
|
||||
va_start(args, fmt);
|
||||
rc = vdprintf(1, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return rc;
|
||||
}
|
||||
413
kit/runtime/syscall.c
Normal file
413
kit/runtime/syscall.c
Normal file
@@ -0,0 +1,413 @@
|
||||
#include <cleonos_syscall.h>
|
||||
|
||||
u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2) {
|
||||
u64 ret;
|
||||
|
||||
__asm__ volatile("int $0x80" : "=a"(ret) : "a"(id), "b"(arg0), "c"(arg1), "d"(arg2) : "memory");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
u64 cleonos_sys_log_write(const char *message, u64 length) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_LOG_WRITE, (u64)message, length, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_timer_ticks(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_TIMER_TICKS, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_task_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_TASK_COUNT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_service_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_SERVICE_COUNT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_service_ready_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_SERVICE_READY_COUNT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_context_switches(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_CONTEXT_SWITCHES, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kelf_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KELF_COUNT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kelf_runs(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KELF_RUNS, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_node_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_NODE_COUNT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_child_count(const char *dir_path) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_CHILD_COUNT, (u64)dir_path, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_get_child_name(const char *dir_path, u64 index, char *out_name) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_GET_CHILD_NAME, (u64)dir_path, index, (u64)out_name);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_read(const char *path, char *out_buffer, u64 buffer_size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_READ, (u64)path, (u64)out_buffer, buffer_size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_exec_path(const char *path) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_PATH, (u64)path, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_exec_pathv(const char *path, const char *argv_line, const char *env_line) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_PATHV, (u64)path, (u64)argv_line, (u64)env_line);
|
||||
}
|
||||
|
||||
struct cleonos_exec_pathv_io_req {
|
||||
u64 env_line_ptr;
|
||||
u64 stdin_fd;
|
||||
u64 stdout_fd;
|
||||
u64 stderr_fd;
|
||||
};
|
||||
|
||||
u64 cleonos_sys_exec_pathv_io(const char *path, const char *argv_line, const char *env_line, u64 stdin_fd,
|
||||
u64 stdout_fd, u64 stderr_fd) {
|
||||
struct cleonos_exec_pathv_io_req req;
|
||||
|
||||
req.env_line_ptr = (u64)env_line;
|
||||
req.stdin_fd = stdin_fd;
|
||||
req.stdout_fd = stdout_fd;
|
||||
req.stderr_fd = stderr_fd;
|
||||
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_PATHV_IO, (u64)path, (u64)argv_line, (u64)&req);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_exec_request_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_REQUESTS, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_exec_success_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_SUCCESS, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_user_shell_ready(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_USER_SHELL_READY, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_user_exec_requested(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_USER_EXEC_REQUESTED, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_user_launch_tries(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_USER_LAUNCH_TRIES, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_user_launch_ok(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_USER_LAUNCH_OK, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_user_launch_fail(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_USER_LAUNCH_FAIL, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_tty_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_TTY_COUNT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_tty_active(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_TTY_ACTIVE, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_tty_switch(u64 tty_index) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_TTY_SWITCH, tty_index, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_tty_write(const char *text, u64 length) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_TTY_WRITE, (u64)text, length, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_tty_write_char(char ch) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_TTY_WRITE_CHAR, (u64)(unsigned char)ch, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kbd_get_char(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KBD_GET_CHAR, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_stat_type(const char *path) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_STAT_TYPE, (u64)path, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_stat_size(const char *path) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_STAT_SIZE, (u64)path, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_mkdir(const char *path) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_MKDIR, (u64)path, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_write(const char *path, const char *data, u64 size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_WRITE, (u64)path, (u64)data, size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_append(const char *path, const char *data, u64 size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_APPEND, (u64)path, (u64)data, size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fs_remove(const char *path) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FS_REMOVE, (u64)path, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_log_journal_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_LOG_JOURNAL_COUNT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_log_journal_read(u64 index_from_oldest, char *out_line, u64 out_size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_LOG_JOURNAL_READ, index_from_oldest, (u64)out_line, out_size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kbd_buffered(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KBD_BUFFERED, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kbd_pushed(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KBD_PUSHED, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kbd_popped(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KBD_POPPED, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kbd_dropped(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KBD_DROPPED, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kbd_hotkey_switches(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KBD_HOTKEY_SWITCHES, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_getpid(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_GETPID, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_spawn_path(const char *path) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_SPAWN_PATH, (u64)path, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_spawn_pathv(const char *path, const char *argv_line, const char *env_line) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_SPAWN_PATHV, (u64)path, (u64)argv_line, (u64)env_line);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_wait_pid(u64 pid, u64 *out_status) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_WAITPID, pid, (u64)out_status, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_exit(u64 status) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_EXIT, status, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_sleep_ticks(u64 ticks) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_SLEEP_TICKS, ticks, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_yield(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_YIELD, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
u64 cleonos_sys_shutdown(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_SHUTDOWN, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_restart(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_RESTART, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_audio_available(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_AUDIO_AVAILABLE, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_audio_play_tone(u64 hz, u64 ticks) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_AUDIO_PLAY_TONE, hz, ticks, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_audio_stop(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_AUDIO_STOP, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_argc(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ARGC, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_argv(u64 index, char *out_value, u64 out_size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ARGV, index, (u64)out_value, out_size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_envc(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ENVC, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_env(u64 index, char *out_value, u64 out_size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ENV, index, (u64)out_value, out_size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_last_signal(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_LAST_SIGNAL, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_fault_vector(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_FAULT_VECTOR, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_fault_error(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_FAULT_ERROR, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_fault_rip(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_FAULT_RIP, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_COUNT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_pid_at(u64 index, u64 *out_pid) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_PID_AT, index, (u64)out_pid, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_snapshot(u64 pid, cleonos_proc_snapshot *out_snapshot, u64 out_size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_SNAPSHOT, pid, (u64)out_snapshot, out_size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_proc_kill(u64 pid, u64 signal) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_PROC_KILL, pid, signal, 0ULL);
|
||||
}
|
||||
|
||||
struct cleonos_kdbg_bt_req {
|
||||
u64 rbp;
|
||||
u64 rip;
|
||||
u64 out_ptr;
|
||||
u64 out_size;
|
||||
};
|
||||
|
||||
u64 cleonos_sys_kdbg_sym(u64 addr, char *out_line, u64 out_size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KDBG_SYM, addr, (u64)out_line, out_size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kdbg_bt(u64 rbp, u64 rip, char *out_text, u64 out_size) {
|
||||
struct cleonos_kdbg_bt_req req;
|
||||
|
||||
req.rbp = rbp;
|
||||
req.rip = rip;
|
||||
req.out_ptr = (u64)out_text;
|
||||
req.out_size = out_size;
|
||||
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KDBG_BT, (u64)&req, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kdbg_regs(char *out_text, u64 out_size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KDBG_REGS, (u64)out_text, out_size, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_stats_total(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_STATS_TOTAL, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_stats_id_count(u64 id) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_STATS_ID_COUNT, id, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_stats_recent_window(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_STATS_RECENT_WINDOW, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_stats_recent_id(u64 id) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_STATS_RECENT_ID, id, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fd_open(const char *path, u64 flags, u64 mode) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FD_OPEN, (u64)path, flags, mode);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fd_read(u64 fd, void *out_buffer, u64 size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FD_READ, fd, (u64)out_buffer, size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fd_write(u64 fd, const void *buffer, u64 size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FD_WRITE, fd, (u64)buffer, size);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fd_close(u64 fd) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FD_CLOSE, fd, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fd_dup(u64 fd) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FD_DUP, fd, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_dl_open(const char *path) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DL_OPEN, (u64)path, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_dl_close(u64 handle) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DL_CLOSE, handle, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_dl_sym(u64 handle, const char *symbol) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DL_SYM, handle, (u64)symbol, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fb_info(cleonos_fb_info *out_info) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FB_INFO, (u64)out_info, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fb_blit(const cleonos_fb_blit_req *req) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FB_BLIT, (u64)req, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_fb_clear(u64 rgb) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_FB_CLEAR, rgb, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_kernel_version(char *out_version, u64 out_size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_KERNEL_VERSION, (u64)out_version, out_size, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_present(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_PRESENT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_size_bytes(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_SIZE_BYTES, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_sector_count(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_SECTOR_COUNT, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_formatted(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_FORMATTED, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_format_fat32(const char *label) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_FORMAT_FAT32, (u64)label, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_mount(const char *mount_path) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_MOUNT, (u64)mount_path, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_mounted(void) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_MOUNTED, 0ULL, 0ULL, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_mount_path(char *out_path, u64 out_size) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_MOUNT_PATH, (u64)out_path, out_size, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_read_sector(u64 lba, void *out_sector) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_READ_SECTOR, lba, (u64)out_sector, 0ULL);
|
||||
}
|
||||
|
||||
u64 cleonos_sys_disk_write_sector(u64 lba, const void *sector_data) {
|
||||
return cleonos_syscall(CLEONOS_SYSCALL_DISK_WRITE_SECTOR, lba, (u64)sector_data, 0ULL);
|
||||
}
|
||||
Reference in New Issue
Block a user