diff options
author | Anton Kling <anton@kling.gg> | 2024-02-16 18:28:14 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-02-16 18:28:14 +0100 |
commit | 413d09388bf33c658f3e71b18e4b069f18461393 (patch) | |
tree | 5df4e31367142bbf1c8285c51366f2d9398135ca /kernel | |
parent | 3922adcdec5bd003b4106ffce79c28553bc40c15 (diff) |
General cleanup
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/cpu/idt.c | 13 | ||||
-rw-r--r-- | kernel/cpu/syscall.c | 1 | ||||
-rw-r--r-- | kernel/drivers/rtl8139.c | 1 | ||||
-rw-r--r-- | kernel/ipc.c | 39 | ||||
-rw-r--r-- | kernel/lib/buffered_write.c | 32 | ||||
-rw-r--r-- | kernel/lib/buffered_write.h | 12 | ||||
-rw-r--r-- | kernel/lib/stack.c | 35 | ||||
-rw-r--r-- | kernel/lib/stack.h | 18 | ||||
-rw-r--r-- | kernel/network/tcp.c | 8 | ||||
-rw-r--r-- | kernel/sched/scheduler.c | 34 | ||||
-rw-r--r-- | kernel/sched/scheduler.h | 8 | ||||
-rw-r--r-- | kernel/socket.c | 84 | ||||
-rw-r--r-- | kernel/socket.h | 2 | ||||
-rw-r--r-- | kernel/syscalls/install_irq.c | 3 |
15 files changed, 208 insertions, 84 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index ea8781c..3a88d91 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,6 +1,6 @@ CC="i686-sb-gcc" AS="i686-sb-as" -OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o halts.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o syscalls/randomfill.o syscalls/open.o syscalls/write.o syscalls/pwrite.o ipc.o syscalls/ipc.o syscalls/port.o syscalls/map_frames.o syscalls/virtual_to_physical.o syscalls/install_irq.o arch/i386/interrupts.o cpu/isr.o lib/stack.o +OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o halts.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o syscalls/randomfill.o syscalls/open.o syscalls/write.o syscalls/pwrite.o ipc.o syscalls/ipc.o syscalls/port.o syscalls/map_frames.o syscalls/virtual_to_physical.o syscalls/install_irq.o arch/i386/interrupts.o cpu/isr.o lib/stack.o lib/buffered_write.o CFLAGS = -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL #LDFLAGS=-flto -Ofast LDFLAGS= diff --git a/kernel/cpu/idt.c b/kernel/cpu/idt.c index 30b6253..32186c5 100644 --- a/kernel/cpu/idt.c +++ b/kernel/cpu/idt.c @@ -65,23 +65,17 @@ void double_fault(registers_t *regs) { ; } -void tmp_jump_process(u32, u32, u32, u32); -void jump_process(const process_t *p) { - // tmp_jump_process(p->eip, p->cr3->physical_address, p->ebp, p->esp); -} - -void none_save_switch(void); -extern PageDirectory *active_directory; void page_fault(reg_t *regs) { volatile uint32_t cr2; asm volatile("mov %%cr2, %0" : "=r"(cr2)); - kprintf("CR2: %x\n", cr2); if (0xDEADC0DE == cr2) { + asm("cli"); EOI(0xB); process_pop_restore_context(NULL, regs); return; } klog("Page Fault", LOG_ERROR); + kprintf("CR2: %x\n", cr2); if (get_current_task()) { kprintf("PID: %x\n", get_current_task()->pid); kprintf("Name: %s\n", get_current_task()->program_name); @@ -238,9 +232,6 @@ void int_handler(reg_t *r) { if (sig) { process_push_restore_context(NULL, *r); r->eip = sig->handler_ip; - kprintf("jumping to: %x\n", r->eip); - // kprintf("esp: %x\n", r->esp); - // kprintf("ebp: %x\n", r->ebp); // Add magic value to the stack such that the signal handler // returns to 0xDEADC0DE diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c index 9b93a4d..77e9ac5 100644 --- a/kernel/cpu/syscall.c +++ b/kernel/cpu/syscall.c @@ -38,7 +38,6 @@ int syscall_exec(SYS_EXEC_PARAMS *args) { } void syscall_tmp_handle_packet(void *packet, u32 len) { - kprintf("syscall tmp handle packet\n"); handle_ethernet((u8 *)packet, len); } diff --git a/kernel/drivers/rtl8139.c b/kernel/drivers/rtl8139.c index b178078..34d9b85 100644 --- a/kernel/drivers/rtl8139.c +++ b/kernel/drivers/rtl8139.c @@ -111,7 +111,6 @@ void rtl8139_send_data(u8 *data, u16 data_size) { data_size -= 0x1000; return rtl8139_send_data(data, data_size); } - kprintf("ipc_write\n"); ipc_write(0, data, data_size); /* const struct PCI_DEVICE *device = &rtl8139; diff --git a/kernel/ipc.c b/kernel/ipc.c index e29b169..d051ea1 100644 --- a/kernel/ipc.c +++ b/kernel/ipc.c @@ -13,28 +13,33 @@ struct IpcEndpoint { struct IpcEndpoint ipc_endpoints[100]; bool ipc_register_endpoint(u32 endpoint) { - if (endpoint >= 100) + if (endpoint >= 100) { return false; - if (ipc_endpoints[endpoint].in_use) + } + if (ipc_endpoints[endpoint].in_use) { return false; + } ipc_endpoints[endpoint].in_use = 1; ipc_endpoints[endpoint].pid = get_current_task()->pid; return true; } bool ipc_endpoint_to_pid(u32 endpoint, u32 *pid) { - if (endpoint >= 100) + if (endpoint >= 100) { return false; - if (!ipc_endpoints[endpoint].in_use) + } + if (!ipc_endpoints[endpoint].in_use) { return false; + } *pid = ipc_endpoints[endpoint].pid; return true; } int ipc_get_mailbox(u32 id, struct IpcMailbox **out) { process_t *p; - if (!get_task_from_pid(id, &p)) + if (!get_task_from_pid(id, &p)) { return 0; + } *out = &p->ipc_mailbox; return 1; } @@ -43,27 +48,36 @@ int ipc_read(u8 *buffer, u32 length, u32 *sender_pid) { struct IpcMailbox *handler = &get_current_task()->ipc_mailbox; u32 read_ptr = handler->read_ptr; - struct IpcMessage *ipc_message = NULL; + struct IpcMessage *ipc_message = &handler->data[read_ptr]; for (;;) { - ipc_message = &handler->data[read_ptr]; if (!ipc_message->is_used) { - return 0; + if (get_current_task()->is_interrupted) { + get_current_task()->is_interrupted = 0; + get_current_task()->is_halted = 0; + return 0; + } + get_current_task()->is_halted = 1; + asm("sti"); + continue; } - kprintf("breaking out\n"); break; } + get_current_task()->is_halted = 0; + asm("cli"); ipc_message->is_used = 0; // TODO: Verify sender_pid is a valid address - if (sender_pid) + if (sender_pid) { *sender_pid = ipc_message->sender_pid; + } u32 len = min(length, ipc_message->size); memcpy(buffer, ipc_message->buffer, len); // Update read_ptr read_ptr++; - if (read_ptr >= IPC_NUM_DATA) + if (read_ptr >= IPC_NUM_DATA) { read_ptr = 0; + } handler->read_ptr = read_ptr; return len; } @@ -82,8 +96,9 @@ int ipc_write_to_process(int pid, u8 *buffer, u32 length) { // Update write_ptr write_ptr++; - if (write_ptr >= IPC_NUM_DATA) + if (write_ptr >= IPC_NUM_DATA) { write_ptr = 0; + } handler->write_ptr = write_ptr; return len; } diff --git a/kernel/lib/buffered_write.c b/kernel/lib/buffered_write.c new file mode 100644 index 0000000..e948e00 --- /dev/null +++ b/kernel/lib/buffered_write.c @@ -0,0 +1,32 @@ +#include <lib/buffered_write.h> +#include <kmalloc.h> + +int buffered_init(struct buffered *ctx, u16 size) { + ctx->data = kmalloc(size); + if (NULL == ctx->data) { + return 0; + } + ctx->buffer_size = size; + ctx->buffer_usage = 0; + return 1; +} + +int buffered_write(struct buffered *ctx, u8 *data, u16 length) { + if (length + ctx->buffer_usage > ctx->buffer_size) { + return 0; + } + u8 *data_ptr = ctx->data; + data_ptr += ctx->buffer_usage; + + memcpy(data_ptr, data, length); + ctx->buffer_usage += length; + return 1; +} + +void buffered_clear(struct buffered *ctx) { + ctx->buffer_usage = 0; +} + +void buffered_free(struct buffered *ctx) { + kfree(ctx->data); +} diff --git a/kernel/lib/buffered_write.h b/kernel/lib/buffered_write.h new file mode 100644 index 0000000..5dc78e7 --- /dev/null +++ b/kernel/lib/buffered_write.h @@ -0,0 +1,12 @@ +#include <typedefs.h> + +struct buffered { + u8 *data; + u16 buffer_usage; + u16 buffer_size; +}; + +int buffered_init(struct buffered *ctx, u16 size); +int buffered_write(struct buffered *ctx, u8 *data, u16 length); +void buffered_clear(struct buffered *ctx); +void buffered_free(struct buffered *ctx); diff --git a/kernel/lib/stack.c b/kernel/lib/stack.c new file mode 100644 index 0000000..7f31867 --- /dev/null +++ b/kernel/lib/stack.c @@ -0,0 +1,35 @@ +#include <kmalloc.h> +#include <lib/stack.h> +#include <stddef.h> + +void stack_init(struct stack *s) { + s->head = NULL; +} + +// 1 = Success +// 0 = Failure +int stack_push(struct stack *s, void *data) { + struct entry *new_entry = kmalloc(sizeof(struct entry)); + if (NULL == new_entry) { + return 0; + } + new_entry->ptr = data; + + new_entry->next = s->head; + s->head = new_entry; + return 1; +} + +// Returns data on success +// Returns NULL on failure +void *stack_pop(struct stack *s) { + struct entry *recieved_entry = s->head; + if (NULL == recieved_entry) { + return NULL; + } + s->head = recieved_entry->next; + + void *r = recieved_entry->ptr; + kfree(recieved_entry); + return r; +} diff --git a/kernel/lib/stack.h b/kernel/lib/stack.h new file mode 100644 index 0000000..e514a04 --- /dev/null +++ b/kernel/lib/stack.h @@ -0,0 +1,18 @@ +#include <stdint.h> + +//struct entry; +//struct stack; + +struct entry { + void *ptr; + // TODO: Maybe don't use a linkedlist + struct entry *next; +}; + +struct stack { + struct entry *head; +}; + +void stack_init(struct stack *s); +int stack_push(struct stack *s, void *data); +void *stack_pop(struct stack *s); diff --git a/kernel/network/tcp.c b/kernel/network/tcp.c index 86cfdd1..a3ba7cd 100644 --- a/kernel/network/tcp.c +++ b/kernel/network/tcp.c @@ -178,7 +178,6 @@ void handle_tcp(u8 src_ip[4], const u8 *payload, u32 payload_length) { (void)ack_num; if (SYN == flags) { - kprintf("GOT SYN UPTIME: %d\n", pit_num_ms()); struct INCOMING_TCP_CONNECTION *inc; if (!(inc = handle_incoming_tcp_connection(src_ip, n_src_port, dst_port))) return; @@ -210,10 +209,13 @@ void handle_tcp(u8 src_ip[4], const u8 *payload, u32 payload_length) { // inc->seq_num = ack_num; } if (flags & PSH) { + kprintf("TCP: Got PSH\n"); u16 tcp_payload_length = payload_length - inc_header->data_offset * sizeof(u32); - fifo_object_write((u8 *)(payload + inc_header->data_offset * sizeof(u32)), - 0, tcp_payload_length, inc->data_file); + int rc = fifo_object_write( + (u8 *)(payload + inc_header->data_offset * sizeof(u32)), 0, + tcp_payload_length, inc->data_file); + kprintf("fifo object write rc: %x\n", rc); *inc->has_data_ptr = 1; // Send back a ACK diff --git a/kernel/sched/scheduler.c b/kernel/sched/scheduler.c index 505dbd8..9ed6552 100644 --- a/kernel/sched/scheduler.c +++ b/kernel/sched/scheduler.c @@ -53,37 +53,20 @@ void process_push_signal(process_t *p, signal_t s) { p = current_task; } - int index = -1; - for (int i = 0; i < 100; i++) { - const signal_t *s = p->active_signals[i]; - if (!s) { - index = i; - break; - } - } - if (-1 == index) { - assert(0); - return; + if (p->is_halted) { + p->is_interrupted = 1; } + signal_t *new_signal_entry = kmalloc(sizeof(signal_t)); memcpy(new_signal_entry, &s, sizeof(signal_t)); - p->active_signals[index] = new_signal_entry; + stack_push(&p->signal_stack, new_signal_entry); } const signal_t *process_pop_signal(process_t *p) { if (!p) { p = current_task; } - - for (int i = 0; i < 100; i++) { - const signal_t *s = p->active_signals[i]; - if (!s) { - continue; - } - p->active_signals[i] = NULL; - return s; - } - return NULL; + return stack_pop(&p->signal_stack); } bool get_task_from_pid(u32 pid, process_t **out) { @@ -107,7 +90,6 @@ void set_signal_handler(int sig, void (*handler)(int)) { void insert_eip_on_stack(u32 cr3, u32 address, u32 value); process_t *create_process(process_t *p, u32 esp, u32 eip) { - kprintf("CREATE_PROCESS\n"); process_t *r; r = kcalloc(1, sizeof(process_t)); r->dead = 0; @@ -115,6 +97,8 @@ process_t *create_process(process_t *p, u32 esp, u32 eip) { r->esp = r->ebp = 0; r->eip = 0; r->sleep_until = 0; + r->is_interrupted = 0; + r->is_halted = 0; if (!p) { assert(1 == next_pid); strncpy(r->program_name, "[kernel]", sizeof(current_task->program_name)); @@ -132,9 +116,6 @@ process_t *create_process(process_t *p, u32 esp, u32 eip) { r->interrupt_handler = NULL; r->tcb = kcalloc(1, sizeof(struct TCB)); - kprintf("r->tcb: %x\n", r->tcb); - kprintf("r->cr3: %x\n", r->cr3); - kprintf("p: %x\n", p); r->tcb->CR3 = r->cr3->physical_address; // Temporarily switch to the page directory to be able to place the @@ -209,6 +190,7 @@ void tasking_init(void) { int i = 0; void free_process(void) { + kprintf("pid: %x\n", get_current_task()->pid); kprintf("Exiting process: %s\n", get_current_task()->program_name); // free_process() will purge all contents such as allocated frames // out of the current process. This will be called by exit() and diff --git a/kernel/sched/scheduler.h b/kernel/sched/scheduler.h index f73d8ef..03f4710 100644 --- a/kernel/sched/scheduler.h +++ b/kernel/sched/scheduler.h @@ -68,11 +68,8 @@ struct Process { vfs_inode_t *write_halt_inode[100]; vfs_inode_t *disconnect_halt_inode[100]; - // // FIXME: Make this a array or circular buffer - // reg_t restore_context; struct stack restore_context_stack; - - signal_t *active_signals[100]; + struct stack signal_stack; u32 halts[2]; struct Halt *halt_list; @@ -82,6 +79,9 @@ struct Process { TCB *tcb; + int is_interrupted; + int is_halted; + // TODO: Create a linkedlist of childs so that the parent process // can do stuff such as reap zombies and get status. process_t *child; diff --git a/kernel/socket.c b/kernel/socket.c index 48b09ea..ceed435 100644 --- a/kernel/socket.c +++ b/kernel/socket.c @@ -17,8 +17,25 @@ struct INCOMING_TCP_CONNECTION tcp_connections[100] = {0}; int tcp_socket_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { struct INCOMING_TCP_CONNECTION *s = (struct INCOMING_TCP_CONNECTION *)fd->inode->internal_object; - if (s->connection_closed) + if (s->connection_closed) { return -EBADF; + } + + if (buffered_write(&s->buffer, buffer, len)) { + return len; + } + + // Use the current buffered input + if (s->buffer.buffer_usage > 0) { + send_tcp_packet(s, s->buffer.data, s->buffer.buffer_usage); + buffered_clear(&s->buffer); + + // Try to add to the buffer again. If it fails just send the whole + // thing immediatley. + if (buffered_write(&s->buffer, buffer, len)) { + return len; + } + } send_tcp_packet(s, buffer, len); return len; } @@ -26,16 +43,23 @@ int tcp_socket_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { int tcp_socket_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { struct INCOMING_TCP_CONNECTION *s = (struct INCOMING_TCP_CONNECTION *)fd->inode->internal_object; - if (s->connection_closed) + if (s->connection_closed) { return -EBADF; + } return fifo_object_read(buffer, offset, len, s->data_file); } void tcp_socket_close(vfs_fd_t *fd) { - kprintf("TCP SOCKET CLOSE\n"); struct INCOMING_TCP_CONNECTION *s = (struct INCOMING_TCP_CONNECTION *)fd->inode->internal_object; + + // Flush the remaining buffer + if (s->buffer.buffer_usage > 0) { + send_tcp_packet(s, s->buffer.data, s->buffer.buffer_usage); + } + buffered_free(&s->buffer); + if (s->connection_closed) { s->is_used = 0; return; @@ -48,10 +72,12 @@ void tcp_socket_close(vfs_fd_t *fd) { struct INCOMING_TCP_CONNECTION *get_incoming_tcp_connection(u8 ip[4], u16 n_port) { for (int i = 0; i < 100; i++) { - if (0 != memcmp(tcp_connections[i].ip, ip, sizeof(u8[4]))) + if (0 != memcmp(tcp_connections[i].ip, ip, sizeof(u8[4]))) { continue; - if (n_port != tcp_connections[i].n_port) + } + if (n_port != tcp_connections[i].n_port) { continue; + } return &tcp_connections[i]; } return NULL; @@ -77,6 +103,8 @@ handle_incoming_tcp_connection(u8 ip[4], u16 n_port, u16 dst_port) { tcp_connections[i].dst_port = dst_port; tcp_connections[i].data_file = create_fifo_object(); + buffered_init(&tcp_connections[i].buffer, 0x2000); + SOCKET *s = in->s; vfs_inode_t *inode = vfs_create_inode( @@ -89,7 +117,7 @@ handle_incoming_tcp_connection(u8 ip[4], u16 n_port, u16 dst_port) { tcp_connections[i].has_data_ptr = &inode->has_data; vfs_fd_t *fd; - int n = vfs_create_fd(O_RDWR | O_NONBLOCK, 0, 0 /*is_tty*/, inode, &fd); + int n = vfs_create_fd(O_RDWR, 0, 0 /*is_tty*/, inode, &fd); fd->reference_count++; s->incoming_fd = fd; @@ -109,14 +137,15 @@ handle_incoming_tcp_connection(u8 ip[4], u16 n_port, u16 dst_port) { OPEN_INET_SOCKET *find_open_tcp_port(u16 port) { for (int i = 0; i < 100; i++) { - if (!inet_sockets[i]) + if (!inet_sockets[i]) { continue; - kprintf("socket type: %d\n", inet_sockets[i]->s->type); - kprintf("socket port: %d\n", inet_sockets[i]->port); - if (inet_sockets[i]->port != port) + } + if (inet_sockets[i]->port != port) { continue; - if (inet_sockets[i]->s->type != SOCK_STREAM) + } + if (inet_sockets[i]->s->type != SOCK_STREAM) { continue; + } return inet_sockets[i]; } return NULL; @@ -124,12 +153,15 @@ OPEN_INET_SOCKET *find_open_tcp_port(u16 port) { OPEN_INET_SOCKET *find_open_udp_port(u16 port) { for (int i = 0; i < 100; i++) { - if (!inet_sockets[i]) + if (!inet_sockets[i]) { continue; - if (inet_sockets[i]->port != port) + } + if (inet_sockets[i]->port != port) { continue; - if (inet_sockets[i]->s->type != SOCK_DGRAM) + } + if (inet_sockets[i]->s->type != SOCK_DGRAM) { continue; + } return inet_sockets[i]; } return NULL; @@ -141,8 +173,9 @@ int uds_open(const char *path) { // Find the socket that path belongs to SOCKET *s = NULL; for (int i = 0; i < 100; i++) { - if (!un_sockets[i]) + if (!un_sockets[i]) { continue; + } const char *p = path; const char *e = p; for (; *e; e++) @@ -203,11 +236,13 @@ int accept(int socket, struct sockaddr *address, socklen_t *address_len) { int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { (void)addrlen; vfs_fd_t *fd = get_vfs_fd(sockfd); - if (!fd) + if (!fd) { return -EBADF; + } vfs_inode_t *inode = fd->inode; - if (!inode) + if (!inode) { return -EBADF; + } SOCKET *s = (SOCKET *)inode->internal_object; if (AF_UNIX == s->domain) { struct sockaddr_un *un = (struct sockaddr_un *)addr; @@ -218,9 +253,11 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { OPEN_UNIX_SOCKET *us; int i = 0; - for (; i < 100; i++) - if (!un_sockets[i]) + for (; i < 100; i++) { + if (!un_sockets[i]) { break; + } + } us = un_sockets[i] = kmalloc(sizeof(OPEN_UNIX_SOCKET)); @@ -235,9 +272,11 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { assert(in->sin_family == AF_INET); // FIXME: Figure out error value OPEN_INET_SOCKET *inet; int i = 0; - for (; i < 100; i++) - if (!inet_sockets[i]) + for (; i < 100; i++) { + if (!inet_sockets[i]) { break; + } + } inet = inet_sockets[i] = kmalloc(sizeof(OPEN_INET_SOCKET)); inet->address = in->sin_addr.s_addr; @@ -270,8 +309,9 @@ void socket_close(vfs_fd_t *fd) { } int socket(int domain, int type, int protocol) { - if (!(AF_UNIX == domain || AF_INET == domain)) + if (!(AF_UNIX == domain || AF_INET == domain)) { return -EINVAL; + } SOCKET *new_socket = kmalloc(sizeof(SOCKET)); vfs_inode_t *inode = vfs_create_inode( diff --git a/kernel/socket.h b/kernel/socket.h index 954ee4d..f765fb7 100644 --- a/kernel/socket.h +++ b/kernel/socket.h @@ -2,6 +2,7 @@ #define SOCKET_H #include <fs/fifo.h> #include <fs/vfs.h> +#include <lib/buffered_write.h> #include <stddef.h> #include <typedefs.h> @@ -46,6 +47,7 @@ struct INCOMING_TCP_CONNECTION { u16 n_port; u16 dst_port; FIFO_FILE *data_file; + struct buffered buffer; u8 *has_data_ptr; u8 is_used; u32 ack_num; diff --git a/kernel/syscalls/install_irq.c b/kernel/syscalls/install_irq.c index c50c6e0..4c990ee 100644 --- a/kernel/syscalls/install_irq.c +++ b/kernel/syscalls/install_irq.c @@ -7,8 +7,6 @@ void *handler; void jump_signal_handler(void *func, u32 esp); void test_handler(reg_t *regs) { - kprintf("IRQ FIRED\n"); - kprintf("handler: %x\n", handler); tmp->interrupt_handler = handler; signal_t sig; sig.handler_ip = (uintptr_t)handler; @@ -20,7 +18,6 @@ int syscall_install_irq(void (*irq_handler)(), u8 irq) { // TODO: This should be able to fail if the handler is already set tmp = get_current_task(); handler = irq_handler; - kprintf("IRQ INSTALLED\n"); install_handler(test_handler, INT_32_INTERRUPT_GATE(0x0), 0x20 + irq); return 1; } |