diff options
author | Anton Kling <anton@kling.gg> | 2023-11-22 00:47:55 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-22 00:47:55 +0100 |
commit | f3c7d7fbdea1f2bac81909116ddb747a1f8abdf5 (patch) | |
tree | 62a1d998ce11bf4db4343f69dea4e8d231191e48 /kernel | |
parent | 24f81104f5ff9cb4ab7db766c53f77fe0e5b86cc (diff) |
Meta: Cleanup of header files such that they are partially shared
The /include directory contains definitons that both the kernel and libc
need to be in sync.
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 4 | ||||
-rw-r--r-- | kernel/drivers/rtl8139.c | 6 | ||||
-rw-r--r-- | kernel/fs/vfs.c | 6 | ||||
-rw-r--r-- | kernel/includes/sys/stat.h | 36 | ||||
-rw-r--r-- | kernel/includes/sys/types.h | 15 | ||||
-rw-r--r-- | kernel/includes/typedefs.h | 11 | ||||
-rw-r--r-- | kernel/network/arp.c | 7 | ||||
-rw-r--r-- | kernel/network/ethernet.c | 8 | ||||
-rw-r--r-- | kernel/network/ipv4.c | 3 | ||||
-rw-r--r-- | kernel/network/tcp.c | 18 | ||||
-rw-r--r-- | kernel/socket.c | 11 | ||||
-rw-r--r-- | kernel/socket.h | 3 |
12 files changed, 16 insertions, 112 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index ce4400e..e2c3db2 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,8 +1,8 @@ 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 cpu/int_syscall.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 -CFLAGS = -Ofast -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 -INCLUDE=-I./includes/ -I./libc/include/ +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 +INCLUDE=-I./includes/ -I../include/ -I./libc/include/ all: myos.iso diff --git a/kernel/drivers/rtl8139.c b/kernel/drivers/rtl8139.c index cfe5cf2..0ed562e 100644 --- a/kernel/drivers/rtl8139.c +++ b/kernel/drivers/rtl8139.c @@ -48,9 +48,7 @@ void handle_packet(void) { struct PACKET_HEADER packet_header; packet_header.raw = *buf; assert(packet_header.data.ROK); - kprintf("packet_header.raw: %x\n", packet_header.raw); u16 packet_length = *(buf + 1); - kprintf("packet_length: %x\n", packet_length); u8 packet_buffer[8192 + 16]; if (current_packet_read + packet_length >= 8192 + 16) { @@ -77,14 +75,11 @@ void handle_packet(void) { __attribute__((interrupt)) void rtl8139_handler(void *regs) { (void)regs; u16 status = inw(rtl8139.gen.base_mem_io + 0x3e); - kprintf("status: %x\n", status); outw(rtl8139.gen.base_mem_io + 0x3E, 0x5); if (status & (1 << 2)) { - kprintf("Packet sent\n"); } if (status & (1 << 0)) { - kprintf("Received packet\n"); handle_packet(); } @@ -118,7 +113,6 @@ void get_mac_address(u8 mac[6]) { u16 high_mac = inw(base_address + 0x4); mac_address = ((u64)high_mac << 32) | low_mac; } - kprintf("mac_address: %x\n", mac_address); memcpy(mac, &mac_address, sizeof(u8[6])); } diff --git a/kernel/fs/vfs.c b/kernel/fs/vfs.c index f2fe0a9..214cfd3 100644 --- a/kernel/fs/vfs.c +++ b/kernel/fs/vfs.c @@ -291,8 +291,7 @@ int vfs_close(int fd) { return 0; } -int raw_vfs_pread(vfs_fd_t *vfs_fd, void *buf, u64 count, - u64 offset) { +int raw_vfs_pread(vfs_fd_t *vfs_fd, void *buf, u64 count, u64 offset) { if (!(vfs_fd->flags & O_READ)) return -EBADF; return vfs_fd->inode->read(buf, offset, count, vfs_fd); @@ -325,8 +324,7 @@ int vfs_pread(int fd, void *buf, u64 count, u64 offset) { return rc; } -int raw_vfs_pwrite(vfs_fd_t *vfs_fd, void *buf, u64 count, - u64 offset) { +int raw_vfs_pwrite(vfs_fd_t *vfs_fd, void *buf, u64 count, u64 offset) { assert(vfs_fd); assert(vfs_fd->inode); assert(vfs_fd->inode->write); diff --git a/kernel/includes/sys/stat.h b/kernel/includes/sys/stat.h deleted file mode 100644 index 92bb67e..0000000 --- a/kernel/includes/sys/stat.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef SYS_STAT_H -#define SYS_STAT_H -#include <sys/types.h> -#include <time.h> - -#define STAT_REG 0 -#define STAT_DIR 1 - -struct stat { - dev_t st_dev; // Device ID of device containing file. - ino_t st_ino; // File serial number. - mode_t st_mode; // Mode of file (see below). - nlink_t st_nlink; // Number of hard links to the file. - uid_t st_uid; // User ID of file. - gid_t st_gid; // Group ID of file. - dev_t st_rdev; // Device ID (if file is character or block special). - - off_t st_size; // For regular files, the file size in bytes. - // For symbolic links, the length in bytes of the - // pathname contained in the symbolic link. - // For a shared memory object, the length in bytes. - // For a typed memory object, the length in bytes. - // For other file types, the use of this field is - // unspecified. - - struct timespec st_atim; // Last data access timestamp. - struct timespec st_mtim; // Last data modification timestamp. - struct timespec st_ctim; // Last file status change timestamp. - - blksize_t st_blksize; // A file system-specific preferred I/O block size - // for this object. In some file system types, this - // may vary from file to file. - - blkcnt_t st_blocks; // Number of blocks allocated for this object. -}; -#endif diff --git a/kernel/includes/sys/types.h b/kernel/includes/sys/types.h deleted file mode 100644 index f82eff7..0000000 --- a/kernel/includes/sys/types.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef TYPES_H -#define TYPES_H -#include <typedefs.h> -typedef int time_t; -typedef int pid_t; -typedef u16 dev_t; -typedef u16 uid_t; -typedef u16 ino_t; -typedef u16 mode_t; -typedef u16 nlink_t; -typedef i32 gid_t; -typedef u64 off_t; -typedef i64 blksize_t; -typedef i64 blkcnt_t; -#endif diff --git a/kernel/includes/typedefs.h b/kernel/includes/typedefs.h deleted file mode 100644 index e290716..0000000 --- a/kernel/includes/typedefs.h +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdint.h> - -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; - -typedef int8_t i8; -typedef int16_t i16; -typedef int32_t i32; -typedef int64_t i64; diff --git a/kernel/network/arp.c b/kernel/network/arp.c index dfa1131..b5825be 100644 --- a/kernel/network/arp.c +++ b/kernel/network/arp.c @@ -114,12 +114,6 @@ void handle_arp(const u8 *payload) { assert(4 == data->plen); // Assert it is a request if (0x0001 /*arp_request*/ == ntohs(data->opcode)) { - print_mac("srchw: ", data->srchw); - print_ip("srcpr: ", data->srcpr); - - print_mac("dsthw: ", data->dsthw); - print_ip("dstpr: ", data->dstpr); - struct ARP_TABLE_ENTRY *entry = find_arp_entry_to_use(); entry->is_used = 1; memcpy(entry->mac, data->srchw, sizeof(uint8_t[6])); @@ -148,7 +142,6 @@ void handle_arp(const u8 *payload) { entry->is_used = 1; memcpy(entry->mac, data->srchw, sizeof(u8[6])); memcpy(entry->ip, data->srcpr, sizeof(u8[4])); - print_ip("Added ip: ", entry->ip); } else { kprintf("GOT A ARP REQEUST WITH TYPE: %x\n", ntohs(data->opcode)); assert(0); diff --git a/kernel/network/ethernet.c b/kernel/network/ethernet.c index 5cf1a54..6255ecb 100644 --- a/kernel/network/ethernet.c +++ b/kernel/network/ethernet.c @@ -50,10 +50,6 @@ void handle_ethernet(const u8 *packet, u64 packet_length) { packet += sizeof(struct ETHERNET_HEADER); const u8 *payload = packet; packet += packet_length - sizeof(struct ETHERNET_HEADER); - u32 crc = *((u32 *)packet - 1); - kprintf("PACKET crc: %x\n", crc); - kprintf("OUR OWN CALCULATED crc: %x\n", - crc32((const char *)eth_header, (packet_length - 4))); u16 type = ntohs(eth_header->type); switch (type) { @@ -84,10 +80,8 @@ void send_ethernet_packet(u8 mac_dst[6], u16 type, u8 *payload, memcpy(eth_header->mac_dst, mac_dst, sizeof(u8[6])); get_mac_address(eth_header->mac_src); eth_header->type = htons(type); - *(u32 *)(buffer) = - htonl(crc32((const char *)buffer_start, buffer_size - 4)); + *(u32 *)(buffer) = htonl(crc32((const char *)buffer_start, buffer_size - 4)); assert(rtl8139_send_data(buffer_start, buffer_size)); kfree(buffer_start); - kprintf("sent data\n"); } diff --git a/kernel/network/ipv4.c b/kernel/network/ipv4.c index 891e74f..e38ab9b 100644 --- a/kernel/network/ipv4.c +++ b/kernel/network/ipv4.c @@ -63,9 +63,7 @@ void send_ipv4_packet(u32 ip, u8 protocol, const u8 *payload, memcpy(ip_copy, &ip, sizeof(u8[4])); for (; !get_mac_from_ip(ip_copy, mac);) ; - kprintf("pre send_ethernet: %x\n", pit_num_ms()); send_ethernet_packet(mac, 0x0800, packet, packet_length); - kprintf("after send_ethernet: %x\n", pit_num_ms()); kfree(packet); } @@ -80,7 +78,6 @@ void handle_ipv4(const u8 *payload, u32 packet_length) { u8 version = (*payload & 0xF0) >> 4; u8 IHL = (*payload & 0xF); - kprintf("version: %x\n", version); assert(4 == version); assert(5 == IHL); u16 ipv4_total_length = ntohs(*(u16 *)(payload + 2)); diff --git a/kernel/network/tcp.c b/kernel/network/tcp.c index 6c693cf..4b2c462 100644 --- a/kernel/network/tcp.c +++ b/kernel/network/tcp.c @@ -60,9 +60,8 @@ u16 tcp_checksum(u16 *buffer, int size) { return (u16)(~cksum); } -void tcp_calculate_checksum(u8 src_ip[4], u8 dst_ip[4], - const u8 *payload, u16 payload_length, - struct TCP_HEADER *header) { +void tcp_calculate_checksum(u8 src_ip[4], u8 dst_ip[4], const u8 *payload, + u16 payload_length, struct TCP_HEADER *header) { struct PSEUDO_TCP_HEADER ps = {0}; memcpy(&ps.src_addr, src_ip, sizeof(u32)); memcpy(&ps.dst_addr, dst_ip, sizeof(u32)); @@ -135,8 +134,7 @@ void send_tcp_packet(struct INCOMING_TCP_CONNECTION *inc, u8 *payload, } void send_empty_tcp_message(struct INCOMING_TCP_CONNECTION *inc, u8 flags, - u32 inc_seq_num, u16 n_dst_port, - u16 n_src_port) { + u32 inc_seq_num, u16 n_dst_port, u16 n_src_port) { struct TCP_HEADER header = {0}; header.src_port = n_dst_port; header.dst_port = n_src_port; @@ -148,15 +146,13 @@ void send_empty_tcp_message(struct INCOMING_TCP_CONNECTION *inc, u8 flags, header.window_size = htons(512); // TODO: What does this actually mean? header.urgent_pointer = 0; char payload[0]; - tcp_calculate_checksum(ip_address, inc->ip, (const u8 *)payload, 0, - &header); + tcp_calculate_checksum(ip_address, inc->ip, (const u8 *)payload, 0, &header); u32 dst_ip; memcpy(&dst_ip, inc->ip, sizeof(dst_ip)); send_ipv4_packet(dst_ip, 6, (const u8 *)&header, sizeof(header)); } -void handle_tcp(u8 src_ip[4], const u8 *payload, - u32 payload_length) { +void handle_tcp(u8 src_ip[4], const u8 *payload, u32 payload_length) { const struct TCP_HEADER *inc_header = (const struct TCP_HEADER *)payload; u16 n_src_port = *(u16 *)(payload); u16 n_dst_port = *(u16 *)(payload + 2); @@ -225,12 +221,10 @@ void handle_tcp(u8 src_ip[4], const u8 *payload, header.window_size = htons(512); // TODO: What does this actually mean? header.urgent_pointer = 0; char payload[0]; - tcp_calculate_checksum(ip_address, src_ip, (const u8 *)payload, 0, - &header); + tcp_calculate_checksum(ip_address, src_ip, (const u8 *)payload, 0, &header); u32 dst_ip; memcpy(&dst_ip, src_ip, sizeof(dst_ip)); send_ipv4_packet(dst_ip, 6, (const u8 *)&header, sizeof(header)); - kprintf("after ipv4 packet: %x\n", pit_num_ms()); return; } } diff --git a/kernel/socket.c b/kernel/socket.c index 1922a93..630c203 100644 --- a/kernel/socket.c +++ b/kernel/socket.c @@ -14,8 +14,7 @@ OPEN_INET_SOCKET *inet_sockets[100] = {0}; struct INCOMING_TCP_CONNECTION tcp_connections[100] = {0}; -int tcp_socket_write(u8 *buffer, u64 offset, u64 len, - vfs_fd_t *fd) { +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) @@ -24,8 +23,7 @@ int tcp_socket_write(u8 *buffer, u64 offset, u64 len, return len; } -int tcp_socket_read(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) @@ -60,8 +58,7 @@ struct INCOMING_TCP_CONNECTION *get_incoming_tcp_connection(u8 ip[4], } struct INCOMING_TCP_CONNECTION * -handle_incoming_tcp_connection(u8 ip[4], u16 n_port, - u16 dst_port) { +handle_incoming_tcp_connection(u8 ip[4], u16 n_port, u16 dst_port) { OPEN_INET_SOCKET *in = find_open_tcp_port(htons(dst_port)); if (!in) { kprintf("TCP SYN to unopened port: %d\n", dst_port); @@ -282,7 +279,7 @@ int socket(int domain, int type, int protocol) { NULL /*truncate*/, NULL /*stat*/); 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 | O_NONBLOCK, 0, 0 /*is_tty*/, inode, &fd); new_socket->domain = domain; new_socket->type = type; diff --git a/kernel/socket.h b/kernel/socket.h index 7be5571..5e8c3b1 100644 --- a/kernel/socket.h +++ b/kernel/socket.h @@ -85,8 +85,7 @@ int socket(int domain, int type, int protocol); int accept(int socket, struct sockaddr *address, socklen_t *address_len); int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); struct INCOMING_TCP_CONNECTION * -handle_incoming_tcp_connection(u8 ip[4], u16 n_port, - u16 dst_port); +handle_incoming_tcp_connection(u8 ip[4], u16 n_port, u16 dst_port); struct INCOMING_TCP_CONNECTION *get_incoming_tcp_connection(u8 ip[4], u16 n_port); #endif |