libc: move syscall defs; consistently use SYS_ macros
This commit is contained in:
parent
9d8962c8f3
commit
c9c18f70ad
@ -121,6 +121,7 @@ DECL_SYSCALL0(setsid);
|
||||
DECL_SYSCALL2(setpgid,int,int);
|
||||
DECL_SYSCALL1(getpgid,int);
|
||||
DECL_SYSCALL0(geteuid);
|
||||
DECL_SYSCALL2(lstat, char *, void *);
|
||||
|
||||
_End_C_Header
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <_cheader.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
_Begin_C_Header
|
||||
@ -89,4 +90,6 @@ extern pid_t getpgid(pid_t);
|
||||
|
||||
extern unsigned int alarm(unsigned int seconds);
|
||||
|
||||
extern void *sbrk(intptr_t increment);
|
||||
|
||||
_End_C_Header
|
||||
|
@ -2,9 +2,12 @@
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <errno.h>
|
||||
#include <bits/dirent.h>
|
||||
|
||||
DEFN_SYSCALL3(readdir, SYS_READDIR, int, int, void *);
|
||||
|
||||
DIR * opendir (const char * dirname) {
|
||||
int fd = open(dirname, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
|
@ -1,7 +1,10 @@
|
||||
#include <errno.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
DEFN_SYSCALL2(mkdir, SYS_MKDIR, char *, unsigned int);
|
||||
|
||||
int mkdir(const char *pathname, mode_t mode) {
|
||||
__sets_errno(syscall_mkdir((char *)pathname, mode));
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
DEFN_SYSCALL3(ioctl, SYS_IOCTL, int, int, void *);
|
||||
|
||||
int ioctl(int fd, int request, void * argp) {
|
||||
return syscall_ioctl(fd, request, argp);
|
||||
}
|
||||
|
35
libc/main.c
35
libc/main.c
@ -5,38 +5,9 @@
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL1(exit, 0, int);
|
||||
DEFN_SYSCALL1(print, 1, const char *);
|
||||
DEFN_SYSCALL2(gettimeofday, 6, void *, void *);
|
||||
DEFN_SYSCALL3(execve, 7, char *, char **, char **);
|
||||
DEFN_SYSCALL1(sbrk, 10, int);
|
||||
DEFN_SYSCALL0(getgraphicsaddress, 11);
|
||||
DEFN_SYSCALL1(setgraphicsoffset, 16, int);
|
||||
DEFN_SYSCALL1(wait, 17, unsigned int);
|
||||
DEFN_SYSCALL0(getgraphicswidth, 18);
|
||||
DEFN_SYSCALL0(getgraphicsheight, 19);
|
||||
DEFN_SYSCALL0(getgraphicsdepth, 20);
|
||||
DEFN_SYSCALL0(mkpipe, 21);
|
||||
DEFN_SYSCALL1(kernel_string_XXX, 25, char *);
|
||||
DEFN_SYSCALL0(reboot, 26);
|
||||
DEFN_SYSCALL3(readdir, 27, int, int, void *);
|
||||
DEFN_SYSCALL3(clone, 30, uintptr_t, uintptr_t, void *);
|
||||
DEFN_SYSCALL0(mousedevice, 33);
|
||||
DEFN_SYSCALL2(mkdir, 34, char *, unsigned int);
|
||||
DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *);
|
||||
DEFN_SYSCALL1(shm_release, 36, char *);
|
||||
DEFN_SYSCALL2(share_fd, 39, int, int);
|
||||
DEFN_SYSCALL1(get_fd, 40, int);
|
||||
DEFN_SYSCALL0(gettid, 41);
|
||||
DEFN_SYSCALL2(system_function, 43, int, char **);
|
||||
DEFN_SYSCALL1(open_serial, 44, int);
|
||||
DEFN_SYSCALL2(sleepabs, 45, unsigned long, unsigned long);
|
||||
DEFN_SYSCALL3(ioctl, 47, int, int, void *);
|
||||
DEFN_SYSCALL2(access, 48, char *, int);
|
||||
DEFN_SYSCALL2(stat, 49, char *, void *);
|
||||
DEFN_SYSCALL3(waitpid, 53, int, int *, int);
|
||||
DEFN_SYSCALL5(mount, SYS_MOUNT, char *, char *, char *, unsigned long, void *);
|
||||
DEFN_SYSCALL2(lstat, SYS_LSTAT, char *, void *);
|
||||
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();
|
||||
extern void _fini();
|
||||
|
@ -5,10 +5,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
DEFN_SYSCALL3(clone, SYS_CLONE, uintptr_t, uintptr_t, void *);
|
||||
DEFN_SYSCALL0(gettid, SYS_GETTID);
|
||||
|
||||
#define PTHREAD_STACK_SIZE 0x100000
|
||||
|
||||
int clone(uintptr_t a,uintptr_t b,void* c) {
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include <signal.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <errno.h>
|
||||
|
||||
DEFN_SYSCALL2(send_signal, 37, uint32_t, uint32_t);
|
||||
DEFN_SYSCALL2(send_signal, SYS_KILL, uint32_t, uint32_t);
|
||||
|
||||
int kill(int pid, int sig) {
|
||||
__sets_errno(syscall_send_signal(pid, sig));
|
||||
|
@ -1,8 +1,10 @@
|
||||
#include <signal.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL2(signal, 38, uint32_t, void *);
|
||||
DEFN_SYSCALL2(signal, SYS_SIGNAL, uint32_t, void *);
|
||||
|
||||
/* XXX This syscall interface is screwy, doesn't allow for good errno handling */
|
||||
sighandler_t signal(int signum, sighandler_t handler) {
|
||||
return (sighandler_t)syscall_signal(signum, (void *)handler);
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <errno.h>
|
||||
|
||||
DEFN_SYSCALL5(mount, SYS_MOUNT, char *, char *, char *, unsigned long, void *);
|
||||
|
||||
int mount(char * source, char * target, char * type, unsigned long flags, void * data) {
|
||||
__sets_errno(syscall_mount(source, target, type, flags, data));
|
||||
}
|
||||
|
7
libc/sys/reboot.c
Normal file
7
libc/sys/reboot.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <unistd.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL0(reboot, SYS_REBOOT);
|
||||
|
||||
/* TODO: define reboot() */
|
5
libc/sys/shm.c
Normal file
5
libc/sys/shm.c
Normal file
@ -0,0 +1,5 @@
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL2(shm_obtain, SYS_SHM_OBTAIN, char *, size_t *);
|
||||
DEFN_SYSCALL1(shm_release, SYS_SHM_RELEASE, char *);
|
@ -1,7 +1,8 @@
|
||||
#include <sys/utsname.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL1(uname, 12, void *);
|
||||
DEFN_SYSCALL1(uname, SYS_UNAME, void *);
|
||||
|
||||
int uname(struct utsname *__name) {
|
||||
return syscall_uname((void *)__name);
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <errno.h>
|
||||
|
||||
DEFN_SYSCALL3(waitpid, SYS_WAITPID, int, int *, int);
|
||||
|
||||
int waitpid(int pid, int *status, int options) {
|
||||
/* XXX: status, options? */
|
||||
__sets_errno(syscall_waitpid(pid, status, options));
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include <sys/time.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL2(gettimeofday, SYS_GETTIMEOFDAY, void *, void *);
|
||||
|
||||
int gettimeofday(struct timeval *p, void *z){
|
||||
return syscall_gettimeofday(p,z);
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL2(access, SYS_ACCESS, char *, int);
|
||||
|
||||
int access(const char *pathname, int mode) {
|
||||
int result = syscall_access((char *)pathname, mode);
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include <unistd.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <errno.h>
|
||||
|
||||
DEFN_SYSCALL1(chdir, 28, char *);
|
||||
DEFN_SYSCALL1(chdir, SYS_CHDIR, char *);
|
||||
|
||||
int chdir(const char *path) {
|
||||
__sets_errno(syscall_chdir((char*)path));
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include <errno.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
DEFN_SYSCALL2(chmod, 50, char *, int);
|
||||
DEFN_SYSCALL2(chmod, SYS_CHMOD, char *, int);
|
||||
|
||||
int chmod(const char *path, mode_t mode) {
|
||||
__sets_errno(syscall_chmod((char *)path, mode));
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL1(close, 5, int);
|
||||
DEFN_SYSCALL1(close, SYS_CLOSE, int);
|
||||
|
||||
int close(int file) {
|
||||
return syscall_close(file);
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL2(dup2, 22, int, int);
|
||||
DEFN_SYSCALL2(dup2, SYS_DUP2, int, int);
|
||||
|
||||
int dup2(int oldfd, int newfd) {
|
||||
return syscall_dup2(oldfd, newfd);
|
||||
|
@ -1,10 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
DEFN_SYSCALL3(execve, SYS_EXECVE, char *, char **, char **);
|
||||
|
||||
extern char ** environ;
|
||||
extern char * _argv_0;
|
||||
extern int __libc_debug;
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL0(fork, 8);
|
||||
DEFN_SYSCALL0(fork, SYS_FORK);
|
||||
|
||||
pid_t fork(void) {
|
||||
return syscall_fork();
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL2(getcwd, 29, char *, size_t);
|
||||
DEFN_SYSCALL2(getcwd, SYS_GETCWD, char *, size_t);
|
||||
|
||||
char *getcwd(char *buf, size_t size) {
|
||||
if (!buf) buf = malloc(size);
|
||||
|
@ -1,9 +1,11 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL3(lseek, 14, int, int, int);
|
||||
DEFN_SYSCALL3(lseek, SYS_SEEK, int, int, int);
|
||||
|
||||
off_t lseek(int file, off_t ptr, int dir) {
|
||||
return syscall_lseek(file,ptr,dir);
|
||||
__sets_errno(syscall_lseek(file,ptr,dir));
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,9 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL3(open, 2, const char *, int, int);
|
||||
DEFN_SYSCALL3(open, SYS_OPEN, const char *, int, int);
|
||||
|
||||
int open(const char *name, int flags, ...) {
|
||||
va_list argp;
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL1(pipe, 54, int *);
|
||||
DEFN_SYSCALL1(pipe, SYS_PIPE, int *);
|
||||
|
||||
int pipe(int fildes[2]) {
|
||||
__sets_errno(syscall_pipe((int *)fildes));
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL3(read, 3, int, char *, int);
|
||||
DEFN_SYSCALL3(read, SYS_READ, int, char *, int);
|
||||
|
||||
int read(int file, void *ptr, size_t len) {
|
||||
return syscall_read(file,ptr,len);
|
||||
|
9
libc/unistd/sbrk.c
Normal file
9
libc/unistd/sbrk.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <unistd.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <syscall.h>
|
||||
|
||||
DEFN_SYSCALL1(sbrk, SYS_SBRK, int);
|
||||
|
||||
void *sbrk(intptr_t increment) {
|
||||
return (void *)syscall_sbrk(increment);
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
DEFN_SYSCALL1(setuid, 24, unsigned int);
|
||||
DEFN_SYSCALL1(setuid, SYS_SETUID, unsigned int);
|
||||
|
||||
int setuid(uid_t uid) {
|
||||
return syscall_setuid(uid);
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include <errno.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef syscall_lstat
|
||||
DECL_SYSCALL2(lstat, char *, void *);
|
||||
#endif
|
||||
DEFN_SYSCALL2(stat, SYS_STATF, char *, void *);
|
||||
DEFN_SYSCALL2(lstat, SYS_LSTAT, char *, void *);
|
||||
|
||||
int stat(const char *file, struct stat *st){
|
||||
int ret = syscall_stat((char *)file, (void *)st);
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL2(nanosleep, 46, unsigned long, unsigned long);
|
||||
DEFN_SYSCALL2(nanosleep, SYS_SLEEP, unsigned long, unsigned long);
|
||||
|
||||
int usleep(useconds_t usec) {
|
||||
syscall_nanosleep((usec / 10000) / 1000, (usec / 10000) % 1000);
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include <syscall.h>
|
||||
#include <syscall_nums.h>
|
||||
|
||||
DEFN_SYSCALL3(write, 4, int, char *, int);
|
||||
DEFN_SYSCALL3(write, SYS_WRITE, int, char *, int);
|
||||
|
||||
ssize_t write(int file, const void *ptr, size_t len) {
|
||||
return syscall_write(file,(char *)ptr,len);
|
||||
|
Loading…
Reference in New Issue
Block a user