System Debugging Functions syscall
This commit is contained in:
parent
99d12d70a6
commit
5457de3906
@ -128,6 +128,7 @@ static int open(const char * file, int flags, int mode) {
|
||||
if (!node && (flags & 0x600)) {
|
||||
/* Um, make one */
|
||||
if (!create_file_fs((char *)file, 0777)) {
|
||||
kprintf("[creat] Creating file!\n");
|
||||
node = kopen((char *)file, 0);
|
||||
}
|
||||
}
|
||||
@ -135,7 +136,9 @@ static int open(const char * file, int flags, int mode) {
|
||||
return -1;
|
||||
}
|
||||
node->offset = 0;
|
||||
return process_append_fd((process_t *)current_process, node);
|
||||
int fd = process_append_fd((process_t *)current_process, node);
|
||||
kprintf("[open] pid=%d %s -> %d\n", getpid(), file, fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int close(int fd) {
|
||||
@ -235,6 +238,7 @@ static int seek(int fd, int offset, int whence) {
|
||||
if (fd < 3) {
|
||||
return 0;
|
||||
}
|
||||
kprintf("[seek] pid=%d fd=%d offset=%d whence=%d\n", getpid(), fd, offset, whence);
|
||||
if (whence == 0) {
|
||||
current_process->fds->entries[fd]->offset = offset;
|
||||
} else if (whence == 1) {
|
||||
@ -493,6 +497,33 @@ static int yield() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* System Function
|
||||
*/
|
||||
static int system_function(int fn, char * args) {
|
||||
/* System Functions are special debugging system calls */
|
||||
if (current_process->user == USER_ROOT_UID) {
|
||||
kprintf("Executing system function %d\n", fn);
|
||||
switch (fn) {
|
||||
case 1:
|
||||
/* Print memory information */
|
||||
/* Future: /proc/meminfo */
|
||||
kprintf("Memory used: %d\n", memory_use());
|
||||
kprintf("Memory available: %d\n", memory_total());
|
||||
return 0;
|
||||
case 2:
|
||||
/* Print process tree */
|
||||
/* Future: /proc in general */
|
||||
debug_print_process_tree();
|
||||
return 0;
|
||||
default:
|
||||
kprintf("Bad system function.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return -1; /* Bad system function or access failure */
|
||||
}
|
||||
|
||||
/*
|
||||
* System Call Internals
|
||||
*/
|
||||
@ -542,6 +573,7 @@ static uintptr_t syscalls[] = {
|
||||
(uintptr_t)&get_fd, /* 40 */
|
||||
(uintptr_t)&gettid,
|
||||
(uintptr_t)&yield,
|
||||
(uintptr_t)&system_function,
|
||||
0
|
||||
};
|
||||
uint32_t num_syscalls;
|
||||
|
10
userspace/sysfunc.c
Normal file
10
userspace/sysfunc.c
Normal file
@ -0,0 +1,10 @@
|
||||
/* vim:tabstop=4 shiftwidth=4 noexpandtab
|
||||
*/
|
||||
#include <syscall.h>
|
||||
#include <stdlib.h>
|
||||
DEFN_SYSCALL2(system_function, 43, int, char **);
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
if (argc < 2) return 1;
|
||||
return syscall_system_function(atoi(argv[1]), &argv[2]);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user