Lots of process cleanup implemented; improved cursor rendering
This commit is contained in:
parent
ffbe7b7b38
commit
816ddc8f3e
@ -552,6 +552,7 @@ void ext2_disk_write_inode(ext2_inodetable_t *inode, uint32_t index) {
|
||||
ext2_disk_read_block(inode_table_block + block_offset, (uint8_t *)inodet);
|
||||
memcpy(&inodet[offset_in_block], inode, sizeof(ext2_inodetable_t));
|
||||
ext2_disk_write_block(inode_table_block + block_offset, (uint8_t *)inodet);
|
||||
free(inodet);
|
||||
}
|
||||
|
||||
uint32_t write_ext2_disk(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
|
||||
|
@ -118,6 +118,7 @@ int create_file_fs(char *name, uint16_t permission) {
|
||||
if (dir_name[i - 1] == '/')
|
||||
dir_name[i - 1] = '\0';
|
||||
if (strlen(dir_name) == 0) {
|
||||
free(dir_name);
|
||||
return 1;
|
||||
}
|
||||
for (i = strlen(dir_name) - 1; i >= 0; i--) {
|
||||
@ -159,6 +160,7 @@ int mkdir_fs(char *name, uint16_t permission) {
|
||||
if (dir_name[i - 1] == '/')
|
||||
dir_name[i - 1] = '\0';
|
||||
if (strlen(dir_name) == 0) {
|
||||
free(dir_name);
|
||||
return 1;
|
||||
}
|
||||
for (i = strlen(dir_name) - 1; i >= 0; i--) {
|
||||
|
@ -51,6 +51,7 @@ typedef struct descriptor_table {
|
||||
fs_node_t ** entries;
|
||||
size_t length;
|
||||
size_t capacity;
|
||||
size_t refs;
|
||||
} fd_table_t;
|
||||
|
||||
/* XXX */
|
||||
|
@ -372,14 +372,14 @@ void *
|
||||
sbrk(
|
||||
uintptr_t increment
|
||||
) {
|
||||
ASSERT((increment % 0x1000 == 0) && "Kernel requested to expand heap by a non-page-multiple value");
|
||||
ASSERT((heap_end % 0x1000 == 0) && "Kernel heap is not page-aligned!");
|
||||
ASSERT(heap_end + increment <= KERNEL_HEAP_END && "The kernel has attempted to allocate beyond the end of its heap.");
|
||||
#if 1
|
||||
if (current_process) {
|
||||
kprintf("[kernel] sbrk [0x%x]+0x%x pid=%d [%s]\n", heap_end, increment, getpid(), current_process->name);
|
||||
}
|
||||
#endif
|
||||
ASSERT((increment % 0x1000 == 0) && "Kernel requested to expand heap by a non-page-multiple value");
|
||||
ASSERT((heap_end % 0x1000 == 0) && "Kernel heap is not page-aligned!");
|
||||
ASSERT(heap_end + increment <= KERNEL_HEAP_END && "The kernel has attempted to allocate beyond the end of its heap.");
|
||||
uintptr_t address = heap_end;
|
||||
heap_end += increment;
|
||||
memset((void *)address, 0x0, increment);
|
||||
|
@ -44,7 +44,10 @@ exec(
|
||||
return 0;
|
||||
}
|
||||
/* Read in the binary contents */
|
||||
Elf32_Header * header = (Elf32_Header *)malloc(file->length + 100);
|
||||
for (uintptr_t x = 0x30000000; x < 0x30000000 + file->length; x += 0x1000) {
|
||||
alloc_frame(get_page(x, 1, current_directory), 0, 1);
|
||||
}
|
||||
Elf32_Header * header = (Elf32_Header *)0x30000000; //(Elf32_Header *)malloc(file->length + 100);
|
||||
read_fs(file, 0, file->length, (uint8_t *)header);
|
||||
|
||||
current_process->name = malloc(strlen(path) + 1);
|
||||
@ -58,7 +61,9 @@ exec(
|
||||
header->e_ident[3] != ELFMAG3) {
|
||||
/* What? This isn't an ELF... */
|
||||
kprintf("Fatal: Not a valid ELF executable.\n");
|
||||
free(header);
|
||||
for (uintptr_t x = 0x30000000; x < 0x30000000 + file->length; x += 0x1000) {
|
||||
free_frame(get_page(x, 0, current_directory));
|
||||
}
|
||||
close_fs(file);
|
||||
return -1;
|
||||
}
|
||||
@ -95,7 +100,9 @@ exec(
|
||||
uintptr_t entry = (uintptr_t)header->e_entry;
|
||||
|
||||
/* Free the space we used for the ELF headers and files */
|
||||
free(header);
|
||||
for (uintptr_t x = 0x30000000; x < 0x30000000 + file->length; x += 0x1000) {
|
||||
free_frame(get_page(x, 0, current_directory));
|
||||
}
|
||||
close_fs(file);
|
||||
|
||||
for (uintptr_t stack_pointer = USER_STACK_BOTTOM; stack_pointer < USER_STACK_TOP; stack_pointer += 0x1000) {
|
||||
|
@ -163,6 +163,7 @@ process_t * spawn_init() {
|
||||
init->group = 0; /* Task group 0 */
|
||||
init->status = 0; /* Run status */
|
||||
init->fds = malloc(sizeof(fd_table_t));
|
||||
init->fds->refs = 1;
|
||||
init->fds->length = 3; /* Initialize the file descriptors */
|
||||
init->fds->capacity = 4;
|
||||
init->fds->entries = malloc(sizeof(fs_node_t *) * init->fds->capacity);
|
||||
@ -236,7 +237,9 @@ process_t * spawn_process(volatile process_t * parent) {
|
||||
assert(process_tree->root && "Attempted to spawn a process without init.");
|
||||
|
||||
/* Allocate a new process */
|
||||
kprintf(" process_t {\n");
|
||||
process_t * proc = malloc(sizeof(process_t));
|
||||
kprintf(" }\n");
|
||||
proc->id = get_next_pid(); /* Set its PID */
|
||||
proc->group = proc->id; /* Set the GID */
|
||||
proc->name = default_name; /* Use the default name */
|
||||
@ -256,7 +259,9 @@ process_t * spawn_process(volatile process_t * parent) {
|
||||
proc->image.heap = parent->image.heap;
|
||||
proc->image.heap_actual = parent->image.heap_actual;
|
||||
proc->image.size = parent->image.size;
|
||||
proc->image.stack = kvmalloc(KERNEL_STACK_SIZE) + KERNEL_STACK_SIZE;
|
||||
kprintf(" stack {\n");
|
||||
proc->image.stack = (uintptr_t)malloc(KERNEL_STACK_SIZE) + KERNEL_STACK_SIZE;
|
||||
kprintf(" }\n");
|
||||
proc->image.user_stack = parent->image.user_stack;
|
||||
proc->image.shm_heap = 0x20000000; /* Yeah, a bit of a hack. */
|
||||
|
||||
@ -264,13 +269,17 @@ process_t * spawn_process(volatile process_t * parent) {
|
||||
|
||||
/* Clone the file descriptors from the original process */
|
||||
proc->fds = malloc(sizeof(fd_table_t));
|
||||
proc->fds->refs = 1;
|
||||
proc->fds->length = parent->fds->length;
|
||||
proc->fds->capacity = parent->fds->capacity;
|
||||
kprintf(" fds / files {\n");
|
||||
proc->fds->entries = malloc(sizeof(fs_node_t *) * proc->fds->capacity);
|
||||
assert(proc->fds->entries && "Failed to allocate file descriptor table for new process.");
|
||||
kprintf(" ---\n");
|
||||
for (uint32_t i = 0; i < parent->fds->length; ++i) {
|
||||
proc->fds->entries[i] = clone_fs(parent->fds->entries[i]);
|
||||
}
|
||||
kprintf(" }\n");
|
||||
|
||||
/* As well as the working directory */
|
||||
proc->wd_node = clone_fs(parent->wd_node);
|
||||
|
@ -184,6 +184,7 @@ static int execve(const char * filename, char *const argv[], char *const envp[])
|
||||
while (argv[i]) {
|
||||
++i;
|
||||
}
|
||||
kprintf("Allocating space for arguments...\n");
|
||||
char ** argv_ = malloc(sizeof(char *) * i);
|
||||
for (int j = 0; j < i; ++j) {
|
||||
argv_[j] = malloc((strlen(argv[j]) + 1) * sizeof(char));
|
||||
|
@ -70,9 +70,11 @@ void release_directory(page_directory_t * dir) {
|
||||
continue;
|
||||
}
|
||||
if (kernel_directory->tables[i] != dir->tables[i]) {
|
||||
for (uint32_t j = 0; j < 1024; ++j) {
|
||||
if (dir->tables[i]->pages[j].frame) {
|
||||
free_frame(&(dir->tables[i]->pages[j]));
|
||||
if (i * 0x1000 * 1024 < 0x20000000) {
|
||||
for (uint32_t j = 0; j < 1024; ++j) {
|
||||
if (dir->tables[i]->pages[j].frame) {
|
||||
free_frame(&(dir->tables[i]->pages[j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
free(dir->tables[i]);
|
||||
@ -82,22 +84,36 @@ void release_directory(page_directory_t * dir) {
|
||||
}
|
||||
}
|
||||
|
||||
extern char * default_name;
|
||||
|
||||
void reap_process(process_t * proc) {
|
||||
list_free(proc->wait_queue);
|
||||
free(proc->wait_queue);
|
||||
list_free(proc->signal_queue);
|
||||
free(proc->signal_queue);
|
||||
if (proc->image.stack - KERNEL_STACK_SIZE > heap_end) {
|
||||
kprintf("\033[1;41;32mNot sure what's happening, this seems wrong:\n");
|
||||
kprintf(" Process' claimed kernel stack is at 0x%x?\033[0m\n", proc->image.stack - KERNEL_STACK_SIZE);
|
||||
} else {
|
||||
free(proc->wd_name);
|
||||
shm_release_all(proc);
|
||||
free(proc->shm_mappings);
|
||||
if (proc->name != default_name) {
|
||||
free(proc->name);
|
||||
}
|
||||
if (proc->signal_kstack) {
|
||||
free(proc->signal_kstack);
|
||||
}
|
||||
proc->fds->refs--;
|
||||
if (proc->fds->refs == 0) {
|
||||
free(proc->thread.page_directory);
|
||||
for (uint32_t i = 0; i < proc->fds->length; ++i) {
|
||||
close_fs(proc->fds->entries[i]);
|
||||
free(proc->fds->entries[i]);
|
||||
}
|
||||
free(proc->fds->entries);
|
||||
free(proc->fds);
|
||||
free((void *)(proc->image.stack - KERNEL_STACK_SIZE));
|
||||
}
|
||||
release_directory(proc->thread.page_directory);
|
||||
/* XXX: Free file descriptors! */
|
||||
//free((void *)(proc->fds->entries));
|
||||
|
||||
shm_release_all(proc);
|
||||
// These things are bad!
|
||||
//delete_process(proc);
|
||||
//free((void *)proc);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -178,7 +194,9 @@ fork() {
|
||||
page_directory_t * directory = clone_directory(current_directory);
|
||||
assert(directory && "Could not allocate a new page directory!");
|
||||
/* Spawn a new process from this one */
|
||||
kprintf("\033[1;32mALLOC {\033[0m\n");
|
||||
process_t * new_proc = spawn_process(current_process);
|
||||
kprintf("\033[1;32m}\033[0m\n");
|
||||
assert(new_proc && "Could not allocate a new process!");
|
||||
/* Set the new process' page directory to clone */
|
||||
set_process_environment(new_proc, directory);
|
||||
@ -317,6 +335,7 @@ clone(uintptr_t new_stack, uintptr_t thread_func, uintptr_t arg) {
|
||||
|
||||
free(new_proc->fds);
|
||||
new_proc->fds = current_process->fds;
|
||||
new_proc->fds->refs++;
|
||||
|
||||
/* Set the new process instruction pointer (to the return from read_eip) */
|
||||
new_proc->thread.eip = eip;
|
||||
@ -535,20 +554,6 @@ void task_exit(int retval) {
|
||||
current_process->status = retval;
|
||||
current_process->finished = 1;
|
||||
wakeup_queue(current_process->wait_queue);
|
||||
#if 0
|
||||
/*
|
||||
* These things should be done by another thread.
|
||||
*/
|
||||
#if 0
|
||||
for (uintptr_t i = 0; i < current_process->image.size; i += 0x1000) {
|
||||
free_frame(get_page(current_process->image.entry + i, 0, current_process->image.page_directory));
|
||||
}
|
||||
#endif
|
||||
free((void *)(current_process->image.stack - KERNEL_STACK_SIZE));
|
||||
free((void *)current_process->thread.page_directory);
|
||||
free((void *)current_process->fds->entries);
|
||||
free((void *)current_process);
|
||||
#endif
|
||||
make_process_reapable((process_t *)current_process);
|
||||
switch_next();
|
||||
}
|
||||
|
@ -73,6 +73,12 @@ int32_t mouse_x, mouse_y;
|
||||
#define MOUSE_OFFSET_X 26
|
||||
#define MOUSE_OFFSET_Y 26
|
||||
|
||||
void redraw_region_slow(int32_t x, int32_t y, int32_t width, int32_t height);
|
||||
void redraw_cursor() {
|
||||
redraw_region_slow(mouse_x / MOUSE_SCALE - 32, mouse_y / MOUSE_SCALE - 32, 64, 64);
|
||||
draw_sprite(sprites[3], mouse_x / MOUSE_SCALE - MOUSE_OFFSET_X, mouse_y / MOUSE_SCALE - MOUSE_OFFSET_Y);
|
||||
}
|
||||
|
||||
extern window_t * init_window (process_windows_t * pw, wid_t wid, int32_t x, int32_t y, uint16_t width, uint16_t height, uint16_t index);
|
||||
extern void free_window (window_t * window);
|
||||
extern void resize_window_buffer (window_t * window, int16_t left, int16_t top, uint16_t width, uint16_t height);
|
||||
@ -257,6 +263,9 @@ void redraw_window(window_t *window, uint16_t x, uint16_t y, uint16_t width, uin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//redraw_region_slow(mouse_x / MOUSE_SCALE - 32, mouse_y / MOUSE_SCALE - 32, 64, 64);
|
||||
redraw_cursor();
|
||||
}
|
||||
|
||||
void reorder_window (window_t * window, uint16_t new_zed) {
|
||||
|
Loading…
Reference in New Issue
Block a user