More rough stubs and fixes
This commit is contained in:
parent
21aeb34ea4
commit
ef459bdaad
BIN
hdd/usr/share/terminfo/t/toaru
Normal file
BIN
hdd/usr/share/terminfo/t/toaru
Normal file
Binary file not shown.
BIN
hdd/usr/share/terminfo/t/toaru-small
Normal file
BIN
hdd/usr/share/terminfo/t/toaru-small
Normal file
Binary file not shown.
@ -165,6 +165,8 @@ void close_pty_master(fs_node_t * node) {
|
||||
uint32_t read_pty_slave(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) {
|
||||
pty_t * pty = (pty_t *)node->inode;
|
||||
|
||||
debug_print(INFO, "tty read at offset=%d, size=%d", offset, size);
|
||||
|
||||
/* Standard pipe read */
|
||||
size_t collected = 0;
|
||||
while (collected == 0) {
|
||||
@ -181,6 +183,8 @@ uint32_t read_pty_slave(fs_node_t * node, uint32_t offset, uint32_t size, uint8
|
||||
}
|
||||
}
|
||||
|
||||
debug_print(INFO, "} completed");
|
||||
|
||||
return collected;
|
||||
}
|
||||
uint32_t write_pty_slave(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) {
|
||||
|
@ -117,9 +117,11 @@ uint8_t should_reap();
|
||||
process_t * next_reapable_process();
|
||||
uint32_t process_append_fd(process_t * proc, fs_node_t * node);
|
||||
process_t * process_from_pid(pid_t pid);
|
||||
process_t * process_get_first_child(process_t * process);
|
||||
void delete_process(process_t * proc);
|
||||
uint32_t process_move_fd(process_t * proc, int src, int dest);
|
||||
int process_is_ready(process_t * proc);
|
||||
void set_reaped(process_t * proc);
|
||||
|
||||
void wakeup_sleepers(unsigned long seconds, unsigned long subseconds);
|
||||
void sleep_until(process_t * process, unsigned long seconds, unsigned long subseconds);
|
||||
|
@ -16,6 +16,7 @@ list_t * process_list; /* Flat storage */
|
||||
list_t * process_queue; /* Ready queue */
|
||||
list_t * reap_queue; /* Processes to reap */
|
||||
list_t * sleep_queue;
|
||||
list_t * recently_reaped;
|
||||
volatile process_t * current_process = NULL;
|
||||
|
||||
static uint8_t volatile reap_lock;
|
||||
@ -33,6 +34,7 @@ void initialize_process_tree() {
|
||||
process_queue = list_create();
|
||||
reap_queue = list_create();
|
||||
sleep_queue = list_create();
|
||||
recently_reaped = list_create();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -106,11 +108,18 @@ void make_process_ready(process_t * proc) {
|
||||
}
|
||||
|
||||
void make_process_reapable(process_t * proc) {
|
||||
delete_process(proc);
|
||||
spin_lock(&reap_lock);
|
||||
list_insert(reap_queue, (void *)proc);
|
||||
spin_unlock(&reap_lock);
|
||||
}
|
||||
|
||||
void set_reaped(process_t * proc) {
|
||||
spin_lock(&reap_lock);
|
||||
list_insert(recently_reaped, (void *)proc);
|
||||
spin_unlock(&reap_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a process from the process tree
|
||||
*
|
||||
@ -130,8 +139,6 @@ void delete_process(process_t * proc) {
|
||||
tree_remove(process_tree, entry);
|
||||
list_delete(process_list, list_find(process_list, proc));
|
||||
spin_unlock(&tree_lock);
|
||||
|
||||
free(proc);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -315,6 +322,14 @@ process_t * spawn_process(volatile process_t * parent) {
|
||||
return proc;
|
||||
}
|
||||
|
||||
process_t * find_reaped_process(pid_t pid) {
|
||||
foreach(node, recently_reaped) {
|
||||
process_t * proc = node->value;
|
||||
if (proc && proc->id == pid) return proc;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t process_compare(void * proc_v, void * pid_v) {
|
||||
pid_t pid = (*(pid_t *)pid_v);
|
||||
process_t * proc = (process_t *)proc_v;
|
||||
@ -331,8 +346,33 @@ process_t * process_from_pid(pid_t pid) {
|
||||
if (entry) {
|
||||
return (process_t *)entry->value;
|
||||
} else {
|
||||
return find_reaped_process(pid);
|
||||
}
|
||||
}
|
||||
|
||||
process_t * process_get_first_child_rec(tree_node_t * node, process_t * target) {
|
||||
if (!node) return NULL;
|
||||
process_t * proc = (process_t *)node->value;
|
||||
if (proc == target) {
|
||||
foreach(child, node->children) {
|
||||
debug_print(WARNING, "Found a child: %d", ((process_t *)child->value)->id);
|
||||
return child->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
foreach(child, node->children) {
|
||||
/* Recursively print the children */
|
||||
process_t * out = process_get_first_child_rec(child->value, target);
|
||||
if (out) return out;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
process_t * process_get_first_child(process_t * process) {
|
||||
spin_lock(&tree_lock);
|
||||
process_t * result = process_get_first_child_rec(process_tree->root, process);
|
||||
spin_unlock(&tree_lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <system.h>
|
||||
#include <signal.h>
|
||||
#include <logging.h>
|
||||
|
||||
void enter_signal_handler(uintptr_t location, int signum, uintptr_t stack) {
|
||||
IRQ_OFF;
|
||||
@ -60,6 +61,8 @@ void handle_signal(process_t * proc, signal_t * sig) {
|
||||
return;
|
||||
}
|
||||
|
||||
debug_print(NOTICE, "handling signal in process %d (%d)", proc->id, signum);
|
||||
|
||||
uintptr_t stack = 0xFFFF0000;
|
||||
if (proc->syscall_registers->useresp < 0x10000100) {
|
||||
stack = proc->image.user_stack;
|
||||
|
@ -128,23 +128,28 @@ static int write(int fd, char * ptr, int len) {
|
||||
}
|
||||
|
||||
static int wait(int child) {
|
||||
if (child < 1) {
|
||||
process_t * volatile child_task;
|
||||
if (child == 0) {
|
||||
debug_print_process_tree();
|
||||
child_task = process_get_first_child(current_process);
|
||||
} else if (child < 1) {
|
||||
debug_print(WARNING, "Process %d requested group wait, which we can not do!", getpid());
|
||||
return 0;
|
||||
} else {
|
||||
child_task = process_from_pid(child);
|
||||
}
|
||||
process_t * volatile child_task = process_from_pid(child);
|
||||
/* If the child task doesn't exist, bail */
|
||||
if (!child_task) {
|
||||
debug_print(WARNING, "Tried to wait for non-existent process");
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
debug_print(NOTICE, "pid=%d waiting on pid=%d", current_process->id, child_task->id);
|
||||
while (child_task->finished == 0) {
|
||||
/* Add us to the wait queue for this child */
|
||||
sleep_on(child_task->wait_queue);
|
||||
}
|
||||
/* Grab the child's return value */
|
||||
int ret = child_task->status;
|
||||
delete_process(child_task);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -121,9 +121,7 @@ void reap_process(process_t * proc) {
|
||||
free((void *)(proc->image.stack - KERNEL_STACK_SIZE));
|
||||
}
|
||||
debug_print(INFO, "Reaped process %d; mem after = %d", proc->id, memory_use());
|
||||
// XXX These things are bad!
|
||||
//delete_process(proc);
|
||||
//free((void *)proc);
|
||||
set_reaped(proc);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <sys/errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/termios.h>
|
||||
#include <stdio.h>
|
||||
#include <utime.h>
|
||||
|
||||
@ -17,7 +18,6 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "syscall.h"
|
||||
#include "termios.h"
|
||||
#include <bits/dirent.h>
|
||||
|
||||
extern void _init();
|
||||
@ -123,15 +123,15 @@ int kill(int pid, int sig) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int wait(int *status) {
|
||||
fprintf(stderr, "[debug] pid %d: wait(**)\n", getpid());
|
||||
errno = ECHILD;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int waitpid(int pid, int *status, int options) {
|
||||
/* XXX: status, options? */
|
||||
return syscall_wait(pid);
|
||||
int x = syscall_wait(pid);
|
||||
if (status) *status = x;
|
||||
return x;
|
||||
}
|
||||
|
||||
int wait(int *status) {
|
||||
return waitpid(0, status, 0);
|
||||
}
|
||||
|
||||
// --- I/O ---
|
||||
@ -219,6 +219,10 @@ char *getwd(char *buf) {
|
||||
return syscall_getcwd(buf, 256);
|
||||
}
|
||||
|
||||
char *getcwd(char *buf, size_t size) {
|
||||
return syscall_getcwd(buf, size);
|
||||
}
|
||||
|
||||
int lstat(const char *path, struct stat *buf) {
|
||||
return stat(path, buf);
|
||||
}
|
||||
@ -331,7 +335,7 @@ unsigned int alarm(unsigned int seconds) {
|
||||
}
|
||||
|
||||
clock_t times(struct tms *buf) {
|
||||
fprintf(stderr, "times(...)\n");
|
||||
/* TODO: times() */
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -366,29 +370,29 @@ int unlink(char *name) {
|
||||
int access(const char *pathname, int mode) {
|
||||
fprintf(stderr, "[user/debug] Unsupported operation [access]\n");
|
||||
/* Not supported */
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
long pathconf(char *path, int name) {
|
||||
fprintf(stderr, "[user/debug] Unsupported operation [pathconf]\n");
|
||||
/* Not supported */
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int utime(const char *filename, const struct utimbuf *times) {
|
||||
fprintf(stderr, "[user/debug] Unsupported operation [utime]\n");
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chown(const char *path, uid_t owner, gid_t group) {
|
||||
fprintf(stderr, "[user/debug] Unsupported operation [chown]\n");
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rmdir(const char *pathname) {
|
||||
fprintf(stderr, "[user/debug] Unsupported operation [rmdir]\n");
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -398,8 +402,15 @@ char *ttyname(int fd) {
|
||||
}
|
||||
|
||||
long sysconf(int name) {
|
||||
fprintf(stderr, "sysconf(%d);\n", name);
|
||||
return -1;
|
||||
switch (name) {
|
||||
case 8:
|
||||
return 4096;
|
||||
case 11:
|
||||
return 10000;
|
||||
default:
|
||||
fprintf(stderr, "sysconf(%d);\n", name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ioctl(int fd, int request, void * argp) {
|
||||
@ -416,11 +427,11 @@ speed_t cfgetospeed(const struct termios * tio) {
|
||||
|
||||
int cfsetispeed(struct termios * tio, speed_t speed) {
|
||||
/* hahahaha, yeah right */
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cfsetospeed(struct termios * tio, speed_t speed) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tcdrain(int i) {
|
||||
@ -455,6 +466,12 @@ int tcsendbreak(int a, int b) {
|
||||
|
||||
int tcsetattr(int fd, int actions, struct termios * tio) {
|
||||
fprintf(stderr, "tcsetattr(%d,%d,...)\n", fd, actions);
|
||||
|
||||
fprintf(stderr, " 0x%8x\n", tio->c_cflag);
|
||||
fprintf(stderr, " 0x%8x\n", tio->c_iflag);
|
||||
fprintf(stderr, " 0x%8x\n", tio->c_lflag);
|
||||
fprintf(stderr, " 0x%8x\n", tio->c_oflag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -463,3 +480,28 @@ int fpathconf(char * file, int name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getuid() {
|
||||
return syscall_getuid();
|
||||
}
|
||||
|
||||
int getgid() {
|
||||
return getuid();
|
||||
}
|
||||
|
||||
int getpgrp() {
|
||||
/* XXX */
|
||||
return getgid();
|
||||
}
|
||||
|
||||
int geteuid() {
|
||||
return getuid();
|
||||
}
|
||||
|
||||
int dup(int oldfd) {
|
||||
return dup2(oldfd, 0);
|
||||
}
|
||||
|
||||
void sync() {
|
||||
/* LOOOL NOPE */
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ void (*redraw_cursor)(void) = NULL;
|
||||
/* Stuffs a string into the stdin of the terminal's child process
|
||||
* Useful for things like the ANSI DSR command. */
|
||||
void input_buffer_stuff(char * str) {
|
||||
size_t s = strlen(str);
|
||||
size_t s = strlen(str) + 1;
|
||||
write(fd_master, str, s);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user