no more serial syscall

More cleanup

Oopsy
This commit is contained in:
Kevin Lange 2014-03-15 20:05:07 -07:00
parent 877c2d9d6f
commit 82a917d270
7 changed files with 61 additions and 75 deletions

View File

@ -52,7 +52,9 @@ DD = dd conv=notrunc
# There are a few modules that are kinda required for a working system
# such as all of the dependencies needed to mount the root partition.
# We can also include things like the debug shell...
BOOT_MODULES := zero serial procfs ata tmpfs debug_shell random
BOOT_MODULES := zero random
BOOT_MODULES += procfs tmpfs ata
BOOT_MODULES += serial debug_shell
# This is kinda silly. We're going to form an -initrd argument..
# which is basically -initrd "hdd/mod/%.ko,hdd/mod/%.ko..."

View File

@ -133,42 +133,42 @@ static void * __attribute__ ((malloc)) klcalloc(uintptr_t nmemb, uintptr_t size)
static void * __attribute__ ((malloc)) klvalloc(uintptr_t size);
static void klfree(void * ptr);
static uint8_t volatile lock = 0;
static uint8_t volatile mem_lock = 0;
void * __attribute__ ((malloc)) malloc(uintptr_t size) {
spin_lock(&lock);
spin_lock(&mem_lock);
void * ret = klmalloc(size);
spin_unlock(&lock);
spin_unlock(&mem_lock);
return ret;
}
void * __attribute__ ((malloc)) realloc(void * ptr, uintptr_t size) {
spin_lock(&lock);
spin_lock(&mem_lock);
void * ret = klrealloc(ptr, size);
spin_unlock(&lock);
spin_unlock(&mem_lock);
return ret;
}
void * __attribute__ ((malloc)) calloc(uintptr_t nmemb, uintptr_t size) {
spin_lock(&lock);
spin_lock(&mem_lock);
void * ret = klcalloc(nmemb, size);
spin_unlock(&lock);
spin_unlock(&mem_lock);
return ret;
}
void * __attribute__ ((malloc)) valloc(uintptr_t size) {
spin_lock(&lock);
spin_lock(&mem_lock);
void * ret = klvalloc(size);
spin_unlock(&lock);
spin_unlock(&mem_lock);
return ret;
}
void free(void * ptr) {
spin_lock(&lock);
spin_lock(&mem_lock);
if ((uintptr_t)ptr > placement_pointer) {
klfree(ptr);
}
spin_unlock(&lock);
spin_unlock(&mem_lock);
}

View File

@ -33,8 +33,8 @@ void enter_signal_handler(uintptr_t location, int signum, uintptr_t stack) {
kprintf("Failed to jump to signal handler!\n");
}
static uint8_t volatile lock;
static uint8_t volatile lock_b;
static uint8_t volatile sig_lock;
static uint8_t volatile sig_lock_b;
char isdeadly[] = {
0, /* 0? */
@ -133,9 +133,9 @@ void return_from_signal_handler(void) {
rets_from_sig = list_create();
}
spin_lock(&lock);
spin_lock(&sig_lock);
list_insert(rets_from_sig, (process_t *)current_process);
spin_unlock(&lock);
spin_unlock(&sig_lock);
switch_next();
}
@ -143,11 +143,11 @@ void return_from_signal_handler(void) {
void fix_signal_stacks(void) {
uint8_t redo_me = 0;
if (rets_from_sig) {
spin_lock(&lock_b);
spin_lock(&sig_lock_b);
while (rets_from_sig->head) {
spin_lock(&lock);
spin_lock(&sig_lock);
node_t * n = list_dequeue(rets_from_sig);
spin_unlock(&lock);
spin_unlock(&sig_lock);
if (!n) {
continue;
}
@ -165,12 +165,12 @@ void fix_signal_stacks(void) {
p->signal_kstack = NULL;
make_process_ready(p);
}
spin_unlock(&lock_b);
spin_unlock(&sig_lock_b);
}
if (redo_me) {
spin_lock(&lock);
spin_lock(&sig_lock);
list_insert(rets_from_sig, (process_t *)current_process);
spin_unlock(&lock);
spin_unlock(&sig_lock);
switch_next();
}
}

View File

@ -15,6 +15,10 @@
static char hostname[256];
static size_t hostname_len = 0;
static int RESERVED(void) {
return -1;
}
/*
* System calls themselves
*/
@ -657,7 +661,15 @@ static int system_function(int fn, char ** args) {
kprint_to_file = current_process->fds->entries[(int)args];
break;
case 5:
debug_print(ERROR, "this system function has been deprecated", getpid());
validate((char *)args);
debug_print(NOTICE, "Replacing process %d's file descriptors with pointers to %s", (char *)args);
fs_node_t * repdev = kopen((char *)args, 0);
while (current_process->fds->length < 3) {
process_append_fd((process_t *)current_process, repdev);
}
current_process->fds->entries[0] = repdev;
current_process->fds->entries[1] = repdev;
current_process->fds->entries[2] = repdev;
break;
case 6:
debug_print(WARNING, "writing contents of file %s to sdb", args[0]);
@ -775,7 +787,7 @@ static uintptr_t syscalls[] = {
(uintptr_t)&gettid,
(uintptr_t)&yield,
(uintptr_t)&system_function,
(uintptr_t)NULL, /* 44 */
(uintptr_t)&RESERVED, /* 44 */
(uintptr_t)&sleep,
(uintptr_t)&sleep_rel,
(uintptr_t)&ioctl,

View File

@ -12,7 +12,7 @@
#define TMPFS_TYPE_FILE 1
#define TMPFS_TYPE_DIR 2
static uint8_t volatile lock = 0;
static uint8_t volatile tmpfs_lock = 0;
struct tmpfs_file {
char * name;
@ -50,7 +50,7 @@ static fs_node_t * tmpfs_from_dir(struct tmpfs_dir * d);
static struct tmpfs_file * tmpfs_file_new(char * name) {
spin_lock(&lock);
spin_lock(&tmpfs_lock);
struct tmpfs_file * t = malloc(sizeof(struct tmpfs_file));
t->name = strdup(name);
@ -69,12 +69,12 @@ static struct tmpfs_file * tmpfs_file_new(char * name) {
t->blocks[i] = NULL;
}
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
return t;
}
static struct tmpfs_dir * tmpfs_dir_new(char * name, struct tmpfs_dir * parent) {
spin_lock(&lock);
spin_lock(&tmpfs_lock);
struct tmpfs_dir * d = malloc(sizeof(struct tmpfs_dir));
d->name = strdup(name);
@ -87,7 +87,7 @@ static struct tmpfs_dir * tmpfs_dir_new(char * name, struct tmpfs_dir * parent)
d->ctime = d->atime;
d->files = list_create();
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
return d;
}
@ -106,7 +106,7 @@ static void tmpfs_file_blocks_embiggen(struct tmpfs_file * t) {
static char * tmpfs_file_getset_block(struct tmpfs_file * t, size_t blockid, int create) {
debug_print(INFO, "Reading block %d from file %s", blockid, t->name);
if (create) {
spin_lock(&lock);
spin_lock(&tmpfs_lock);
while (blockid >= t->pointers) {
tmpfs_file_blocks_embiggen(t);
}
@ -115,7 +115,7 @@ static char * tmpfs_file_getset_block(struct tmpfs_file * t, size_t blockid, int
t->blocks[t->block_count] = malloc(BLOCKSIZE);
t->block_count += 1;
}
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
} else {
if (blockid >= t->block_count) {
debug_print(CRITICAL, "This will probably end badly.");
@ -288,12 +288,12 @@ static fs_node_t * finddir_tmpfs(fs_node_t * node, char * name) {
struct tmpfs_dir * d = (struct tmpfs_dir *)node->device;
spin_lock(&lock);
spin_lock(&tmpfs_lock);
foreach(f, d->files) {
struct tmpfs_file * t = (struct tmpfs_file *)f->value;
if (!strcmp(name, t->name)) {
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
switch (t->type) {
case TMPFS_TYPE_FILE:
return tmpfs_from_file(t);
@ -303,7 +303,7 @@ static fs_node_t * finddir_tmpfs(fs_node_t * node, char * name) {
}
}
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
return NULL;
}
@ -311,7 +311,7 @@ static fs_node_t * finddir_tmpfs(fs_node_t * node, char * name) {
static void unlink_tmpfs(fs_node_t * node, char * name) {
struct tmpfs_dir * d = (struct tmpfs_dir *)node->device;
int i = -1, j = 0;
spin_lock(&lock);
spin_lock(&tmpfs_lock);
foreach(f, d->files) {
struct tmpfs_file * t = (struct tmpfs_file *)f->value;
@ -328,7 +328,7 @@ static void unlink_tmpfs(fs_node_t * node, char * name) {
list_remove(d->files, i);
}
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
return;
}
@ -338,16 +338,16 @@ static void create_tmpfs(fs_node_t *parent, char *name, uint16_t permission) {
struct tmpfs_dir * d = (struct tmpfs_dir *)parent->device;
debug_print(CRITICAL, "Creating TMPFS file %s in %s", name, d->name);
spin_lock(&lock);
spin_lock(&tmpfs_lock);
foreach(f, d->files) {
struct tmpfs_file * t = (struct tmpfs_file *)f->value;
if (!strcmp(name, t->name)) {
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
debug_print(WARNING, "... already exists.");
return; /* Already exists */
}
}
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
debug_print(NOTICE, "... creating a new file.");
struct tmpfs_file * t = tmpfs_file_new(name);
@ -364,16 +364,16 @@ static void mkdir_tmpfs(fs_node_t * parent, char * name, uint16_t permission) {
struct tmpfs_dir * d = (struct tmpfs_dir *)parent->device;
debug_print(CRITICAL, "Creating TMPFS directory %s (in %s)", name, d->name);
spin_lock(&lock);
spin_lock(&tmpfs_lock);
foreach(f, d->files) {
struct tmpfs_file * t = (struct tmpfs_file *)f->value;
if (!strcmp(name, t->name)) {
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
debug_print(WARNING, "... already exists.");
return; /* Already exists */
}
}
spin_unlock(&lock);
spin_unlock(&tmpfs_lock);
debug_print(NOTICE, "... creating a new directory.");
struct tmpfs_dir * out = tmpfs_dir_new(name, d);

View File

@ -1540,7 +1540,8 @@ int main(int argc, char ** argv) {
setenv("DISPLAY", WINS_SERVER_IDENTIFIER, 1);
if (!fork()) {
syscall_system_function(5,0);
char * foo = "/dev/null";
syscall_system_function(5,(char **)foo);
if (argc < 2) {
char * args[] = {"/bin/glogin", NULL};
execvp(args[0], args);

View File

@ -40,14 +40,6 @@
#include "terminal-palette.h"
#include "terminal-font.h"
/*
* If you're working on updating the terminal's handling of escapes,
* switch this option to 1 to have it print an escaped bit of output
* to the serial line, so you can examine exactly which codes were
* processed.
*/
#define DEBUG_TERMINAL_WITH_SERIAL 0
#define USE_BELL 0
static int volatile lock = 0;
@ -1516,23 +1508,6 @@ void reinit(int send_sig) {
}
}
#if DEBUG_TERMINAL_WITH_SERIAL
DEFN_SYSCALL1(serial, 44, int);
int serial_fd;
void serial_put(uint8_t c) {
if (c == '\033') {
char out[3] = {'\\', 'E', 0};
write(serial_fd, out, 2);
} else if (c < 32) {
char out[5] = {'\\', '0' + ((c / 8) / 8) % 8, '0' + (c / 8) % 8, '0' + c % 8, 0};
write(serial_fd, out, 4);
} else {
char out[2] = {c, 0};
write(serial_fd, out, 1);
}
}
#endif
void * handle_incoming(void * garbage) {
while (!exit_application) {
w_keyboard_t * kbd = poll_keyboard();
@ -1619,10 +1594,6 @@ int main(int argc, char ** argv) {
}
}
#if DEBUG_TERMINAL_WITH_SERIAL
serial_fd = syscall_serial(0x3F8);
#endif
putenv("TERM=toaru");
/* Initialize the windowing library */
@ -1733,11 +1704,11 @@ int main(int argc, char ** argv) {
unsigned char buf[1024];
while (!exit_application) {
int r = read(fd_master, buf, 1024);
char exit_message[] = "FOO\n";
write(fd_slave, exit_message, sizeof(exit_message));
for (uint32_t i = 0; i < r; ++i) {
ansi_put(buf[i]);
#if DEBUG_TERMINAL_WITH_SERIAL
serial_put(buf[i]);
#endif
}
}