libc: add more toaru-specific syscall wrappers

This commit is contained in:
K. Lange 2018-12-10 18:44:34 +09:00
parent 5b8d7e47c2
commit 54e9044161
14 changed files with 98 additions and 31 deletions

View File

@ -16,7 +16,6 @@
*/
#include <stdio.h>
#include <stdint.h>
#include <syscall.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
@ -30,6 +29,8 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/fswait.h>
#include <sys/sysfunc.h>
#include <sys/shm.h>
#include <pthread.h>
#include <dlfcn.h>
/* auto-dep: export-dynamic */
@ -423,7 +424,7 @@ static yutani_server_window_t * server_window_create(yutani_globals_t * yg, int
size_t size = (width * height * 4);
win->buffer = (uint8_t *)syscall_shm_obtain(key, &size);
win->buffer = shm_obtain(key, &size);
memset(win->buffer, 0, size);
list_insert(yg->mid_zs, win);
@ -469,7 +470,7 @@ static uint32_t server_window_resize(yutani_globals_t * yg, yutani_server_window
YUTANI_SHMKEY_EXP(yg->server_ident, key, 1024, win->newbufid);
size_t size = (width * height * 4);
win->newbuffer = (uint8_t *)syscall_shm_obtain(key, &size);
win->newbuffer = shm_obtain(key, &size);
}
return win->newbufid;
@ -504,7 +505,7 @@ static void server_window_resize_finish(yutani_globals_t * yg, yutani_server_win
{
char key[1024];
YUTANI_SHMKEY_EXP(yg->server_ident, key, 1024, oldbufid);
syscall_shm_release(key);
shm_release(key);
}
spin_unlock(&yg->redraw_lock);
@ -1129,7 +1130,7 @@ void yutani_clip_init(yutani_globals_t * yg) {
*/
static void * redraw(void * in) {
syscall_system_function(11,(char *[]){"compositor","render thread",NULL});
sysfunc(TOARU_SYS_FUNC_THREADNAME,(char *[]){"compositor","render thread",NULL});
yutani_globals_t * yg = in;
while (yg->server) {
@ -1276,7 +1277,7 @@ static void window_actually_close(yutani_globals_t * yg, yutani_server_window_t
* thread holds that lock already and we are only called from the
* render thread, so we don't bother.
*/
syscall_shm_release(key);
shm_release(key);
}
/* Notify subscribers that there are changes to windows */
@ -2128,7 +2129,7 @@ int main(int argc, char * argv[]) {
char tmp[100];
sprintf(tmp, "sys.%s.fonts", yg->server_ident);
size_t s = font_data_size;
char * font = (char *)syscall_shm_obtain(tmp, &s);
char * font = shm_obtain(tmp, &s);
assert((s >= font_data_size) && "Font server failure.");
uint32_t * data = (uint32_t *)font;

View File

@ -11,9 +11,9 @@
* try to move the hardware cursor off screen so it doesn't
* interfere with the rest of the terminal and look weird.
*/
#include <syscall.h>
#include <sys/sysfunc.h>
int main(int argc, char * argv[]) {
int x[] = {0xFF,0xFF};
return syscall_system_function(13, (char **)x);
return sysfunc(TOARU_SYS_FUNC_SETVGACURSOR, (char **)x);
}

View File

@ -14,7 +14,7 @@
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <syscall.h>
#include <sys/shm.h>
#if 0
#include <toaru/trace.h>
@ -55,7 +55,7 @@ static char * precache_shmfont(char * ident, char * name) {
fseek(f, 0, SEEK_SET);
size_t shm_size = s;
char * font = (char *)syscall_shm_obtain(ident, &shm_size);
char * font = shm_obtain(ident, &shm_size);
assert((shm_size >= s) && "shm_obtain returned too little memory to load a font into!");
fread(font, s, 1, f);

View File

@ -7,7 +7,8 @@
*
*/
#include <stdio.h>
#include <syscall.h>
#include <errno.h>
#include <sys/sysfunc.h>
int main(int argc, char * argv[]) {
if (argc < 2) {
@ -16,9 +17,9 @@ int main(int argc, char * argv[]) {
}
int ret = 0;
for (int i = 1; i < argc; ++i) {
int status = syscall_system_function(8, &argv[i]);
if (status) {
fprintf(stderr, "%s: %s: kernel returned %d\n", argv[0], argv[i], status);
int status = sysfunc(TOARU_SYS_FUNC_INSMOD, &argv[i]);
if (status < 0) {
fprintf(stderr, "%s: %s: %s\n", argv[0], argv[i], strerror(errno));
ret = 1;
}
}

View File

@ -5,12 +5,13 @@
*
* kdebug - Launch kernel shell
*/
#include <syscall.h>
#include <sys/wait.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/sysfunc.h>
int main(int argc, char * argv[]) {
syscall_system_function(7, NULL);
sysfunc(TOARU_SYS_FUNC_KDEBUG, NULL);
int status;
while (wait(&status)) {
if (errno == ECHILD) break;

View File

@ -8,10 +8,17 @@
* Executes an "extended system function" which
* is basically just a super-syscall.
*/
#include <syscall.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/sysfunc.h>
int main(int argc, char ** argv) {
if (argc < 2) return 1;
return syscall_system_function(atoi(argv[1]), &argv[2]);
int ret = sysfunc(atoi(argv[1]), &argv[2]);
if (ret < 0) {
fprintf(stderr, "%s: %s\n", argv[0], strerror(errno));
}
return ret;
}

View File

@ -0,0 +1,10 @@
#pragma once
#include <_cheader.h>
#include <sys/types.h>
_Begin_C_Header
extern void * shm_obtain(char * path, size_t * size);
extern int shm_release(char * path);
_End_C_Header

View File

@ -0,0 +1,30 @@
#pragma once
/**
* The sysfunc interface is deprecated. Anything still using these
* should be migrated to real system calls. The sysfunc interface
* exists because it was annoying to add new syscall bindings to
* newlib, but we're not using newlib anymore, so adding new system
* calls should be easy.
*/
#include <_cheader.h>
/* Privileged */
#define TOARU_SYS_FUNC_SYNC 3
#define TOARU_SYS_FUNC_LOGHERE 4
#define TOARU_SYS_FUNC_SETFDS 5
#define TOARU_SYS_FUNC_WRITESDB 6
#define TOARU_SYS_FUNC_KDEBUG 7
#define TOARU_SYS_FUNC_INSMOD 8
/* Unpriviliged */
#define TOARU_SYS_FUNC_SETHEAP 9
#define TOARU_SYS_FUNC_MMAP 10
#define TOARU_SYS_FUNC_THREADNAME 11
#define TOARU_SYS_FUNC_DEBUGPRINT 12
#define TOARU_SYS_FUNC_SETVGACURSOR 13
_Begin_C_Header
extern int sysfunc(int command, char ** args);
_End_C_Header

View File

@ -8,7 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <syscall.h>
#include <sys/shm.h>
#include <toaru/graphics.h>
#include <toaru/hashmap.h>
@ -71,7 +71,7 @@ static void _init_sdf(void) {
char * display = getenv("DISPLAY");
if (!display) display = "compositor";
sprintf(tmp, "sys.%s.fonts", display);
_font_data = (char *)syscall_shm_obtain(tmp, &_font_data_size);
_font_data = shm_obtain(tmp, &_font_data_size);
}
if (!_font_data_size) return;

View File

@ -9,7 +9,7 @@
*/
#include <string.h>
#include <stdlib.h>
#include <syscall.h>
#include <sys/shm.h>
#include <toaru/pex.h>
#include <toaru/graphics.h>
@ -581,7 +581,7 @@ yutani_window_t * yutani_window_create_flags(yutani_t * y, int width, int height
YUTANI_SHMKEY(y->server_ident, key, 1024, win);
size_t size = (width * height * 4);
win->buffer = (char *)syscall_shm_obtain(key, &size);
win->buffer = shm_obtain(key, &size);
return win;
}
@ -632,7 +632,7 @@ void yutani_close(yutani_t * y, yutani_window_t * win) {
{
char key[1024];
YUTANI_SHMKEY_EXP(y->server_ident, key, 1024, win->bufid);
syscall_shm_release(key);
shm_release(key);
}
hashmap_remove(y->windows, (void*)win->wid);
@ -718,7 +718,7 @@ void yutani_window_resize_accept(yutani_t * yctx, yutani_window_t * window, uint
YUTANI_SHMKEY(yctx->server_ident, key, 1024, window);
size_t size = (window->width * window->height * 4);
window->buffer = (char *)syscall_shm_obtain(key, &size);
window->buffer = shm_obtain(key, &size);
}
}
@ -734,7 +734,7 @@ void yutani_window_resize_done(yutani_t * yctx, yutani_window_t * window) {
{
char key[1024];
YUTANI_SHMKEY_EXP(yctx->server_ident, key, 1024, window->oldbufid);
syscall_shm_release(key);
shm_release(key);
}
yutani_msg_buildx_window_resize_alloc(m);

View File

@ -6,7 +6,6 @@
#include <syscall_nums.h>
DEFN_SYSCALL1(exit, SYS_EXT, int);
DEFN_SYSCALL2(system_function, SYS_SYSFUNC, int, char **);
DEFN_SYSCALL2(sleepabs, SYS_SLEEPABS, unsigned long, unsigned long);
extern void _init();

View File

@ -3,3 +3,11 @@
DEFN_SYSCALL2(shm_obtain, SYS_SHM_OBTAIN, char *, size_t *);
DEFN_SYSCALL1(shm_release, SYS_SHM_RELEASE, char *);
void * shm_obtain(char * path, size_t * size) {
return (void *)syscall_shm_obtain(path, size);
}
int shm_release(char * path) {
return syscall_shm_release(path);
}

10
libc/sys/sysfunc.c Normal file
View File

@ -0,0 +1,10 @@
#include <errno.h>
#include <syscall.h>
#include <syscall_nums.h>
#include <sys/sysfunc.h>
DEFN_SYSCALL2(system_function, SYS_SYSFUNC, int, char **);
extern int sysfunc(int command, char ** args) {
__sets_errno(syscall_system_function(command, args));
}

View File

@ -25,9 +25,9 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <syscall.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/sysfunc.h>
#include <kernel/elf.h>
@ -291,7 +291,7 @@ static uintptr_t object_load(elf_t * object, uintptr_t base) {
{
/* Request memory to load this PHDR into */
char * args[] = {(char *)(base + phdr.p_vaddr), (char *)phdr.p_memsz};
syscall_system_function(10, args);
sysfunc(TOARU_SYS_FUNC_MMAP, args);
/* Copy the code into memory */
fseek(object->file, phdr.p_offset, SEEK_SET);
@ -848,7 +848,7 @@ nope:
/* Move heap start (kind of like a weird sbrk) */
{
char * args[] = {(char*)end_addr};
syscall_system_function(9, args);
sysfunc(TOARU_SYS_FUNC_SETHEAP, args);
}
/* Set heap functions for later usage */