fix for fragment keys

This commit is contained in:
Andrew Pamment 2022-07-21 14:52:54 +10:00
parent d2ed8e8361
commit 9e8e50ed4a
24 changed files with 103 additions and 108 deletions

3
arp.c
View File

@ -40,7 +40,8 @@ void arp_process_packet(struct ether_t *ether, struct arp_packet_t *packet) {
arp_packet.tha[4] = packet->sha[4]; arp_packet.tha[4] = packet->sha[4];
arp_packet.tha[5] = packet->sha[5]; arp_packet.tha[5] = packet->sha[5];
arp_packet.tpa = packet->spa; arp_packet.tpa = packet->spa;
struct ether_packet_t *ether_packet = (struct ether_packet_t *)dbmalloc(sizeof(struct arp_packet_t) + sizeof(struct ether_packet_t), "arp_process_packet 1"); struct ether_packet_t *ether_packet =
(struct ether_packet_t *)dbmalloc(sizeof(struct arp_packet_t) + sizeof(struct ether_packet_t), "arp_process_packet 1");
ether_packet->destmac[0] = packet->sha[0]; ether_packet->destmac[0] = packet->sha[0];
ether_packet->destmac[1] = packet->sha[1]; ether_packet->destmac[1] = packet->sha[1];

View File

@ -5,8 +5,7 @@
#define htons(A) ((((uint16_t)(A)&0xff00) >> 8) | (((uint16_t)(A)&0x00ff) << 8)) #define htons(A) ((((uint16_t)(A)&0xff00) >> 8) | (((uint16_t)(A)&0x00ff) << 8))
#define htonl(A) \ #define htonl(A) \
((((uint32_t)(A)&0xff000000) >> 24) | (((uint32_t)(A)&0x00ff0000) >> 8) | (((uint32_t)(A)&0x0000ff00) << 8) | \ ((((uint32_t)(A)&0xff000000) >> 24) | (((uint32_t)(A)&0x00ff0000) >> 8) | (((uint32_t)(A)&0x0000ff00) << 8) | (((uint32_t)(A)&0x000000ff) << 24))
(((uint32_t)(A)&0x000000ff) << 24))
#define ETH_MIN_PACKET_SIZE 60 #define ETH_MIN_PACKET_SIZE 60

11
gui.c
View File

@ -28,8 +28,8 @@ struct gui_colour_scheme_t sys_color;
outportw(0x8A00, 0x08AE0); outportw(0x8A00, 0x08AE0);
#define BochsConsolePrintChar(c) outportb(0xe9, c) #define BochsConsolePrintChar(c) outportb(0xe9, c)
void render(uint8_t *dest, uint8_t *src, uint32_t src_width, uint32_t src_height, int dest_x, int dest_y, uint32_t dest_width, void render(uint8_t *dest, uint8_t *src, uint32_t src_width, uint32_t src_height, int dest_x, int dest_y, uint32_t dest_width, uint32_t dest_height,
uint32_t dest_height, uint32_t src_depth); uint32_t src_depth);
void gui_pagemap(); void gui_pagemap();
struct ModeInfoBlock { struct ModeInfoBlock {
@ -359,8 +359,7 @@ int gui_change_window_caption(int serialno, char *cap) {
return -1; return -1;
} }
int gui_add_window(uint8_t *contents, char *name, int x, int y, int w, int h, uint8_t *icon, uint32_t flags, int gui_add_window(uint8_t *contents, char *name, int x, int y, int w, int h, uint8_t *icon, uint32_t flags, void (*keyboard_d)(uint8_t c, uint8_t state)) {
void (*keyboard_d)(uint8_t c, uint8_t state)) {
struct window_t *new_window; struct window_t *new_window;
new_window = (struct window_t *)dbmalloc(sizeof(struct window_t), "gui: add window (malloc 1)"); new_window = (struct window_t *)dbmalloc(sizeof(struct window_t), "gui: add window (malloc 1)");
@ -879,8 +878,8 @@ static uint32_t blendPreMulAlpha(uint32_t p1, uint32_t p2) {
return ((rb & RBMASK) | (ag & AGMASK)); return ((rb & RBMASK) | (ag & AGMASK));
} }
void render(uint8_t *dest, uint8_t *src, uint32_t src_width, uint32_t src_height, int dest_x, int dest_y, uint32_t dest_width, void render(uint8_t *dest, uint8_t *src, uint32_t src_width, uint32_t src_height, int dest_x, int dest_y, uint32_t dest_width, uint32_t dest_height,
uint32_t dest_height, uint32_t src_depth) { uint32_t src_depth) {
int i; int i;
int pitch = dest_width * depth; int pitch = dest_width * depth;
int src_off_x = 0; int src_off_x = 0;

View File

@ -127,7 +127,6 @@ void init_isrs() {
extern uint32_t read_cr2(); extern uint32_t read_cr2();
void print_regs(struct regs *r) { void print_regs(struct regs *r) {
kprintf("EIP: %p CS: %x\n", r->eip, r->cs); kprintf("EIP: %p CS: %x\n", r->eip, r->cs);
kprintf("EAX: %p, EBX: %p, ECX: %p, EDX: %p\n", r->eax, r->ebx, r->ecx, r->edx); kprintf("EAX: %p, EBX: %p, ECX: %p, EDX: %p\n", r->eax, r->ebx, r->ecx, r->edx);
@ -140,7 +139,6 @@ void print_regs(struct regs *r) {
kprintf("KSTACK: 0x%p USTACK: 0x%p TASK: %s\n", current_task->kstack, current_task->ustack, current_task->name); kprintf("KSTACK: 0x%p USTACK: 0x%p TASK: %s\n", current_task->kstack, current_task->ustack, current_task->name);
} }
// int i; // int i;
/* /*
@ -391,7 +389,6 @@ void init_irqs(void) {
int irq_handler(struct regs *r) { int irq_handler(struct regs *r) {
if (current_task != NULL) { if (current_task != NULL) {
current_task->eflags = r->eflags; current_task->eflags = r->eflags;
} }

View File

@ -1,7 +1,6 @@
#ifndef __INTTYPES_H #ifndef __INTTYPES_H
#define __INTTYPES_H #define __INTTYPES_H
extern void __assert_fail(const char *__assertion, const char *__file, unsigned int __line); extern void __assert_fail(const char *__assertion, const char *__file, unsigned int __line);
#define assert(expr) ((expr ? (void)(0) : __assert_fail(#expr, __FILE__, __LINE__))) #define assert(expr) ((expr ? (void)(0) : __assert_fail(#expr, __FILE__, __LINE__)))

19
ipv4.c
View File

@ -45,9 +45,9 @@ struct ipv4_header_t {
struct ipv4_frag_t { struct ipv4_frag_t {
char key[6]; char key[6];
struct ipv4_header_t *first_packet; struct ipv4_header_t *first_packet;
struct ipv4_header_t *last_packet;
struct ipv4_header_t **middle_packets; struct ipv4_header_t **middle_packets;
int middle_packet_count; int middle_packet_count;
struct ipv4_header_t *last_packet;
uint32_t time_created; uint32_t time_created;
}; };
@ -206,14 +206,15 @@ void ipv4_reassemble_packet(struct ether_t *ether, struct ipv4_header_t *iph) {
struct ipv4_frag_t *frag; struct ipv4_frag_t *frag;
int error; int error;
int i; int i;
shortkey[5] = '\0'; ptr = shortkey;
ptr = &shortkey[5];
while (key > 0) { while (key > 0 && ptr) {
ptr--;
*ptr = (key % 10) + '0'; *ptr = (key % 10) + '0';
ptr++;
*ptr = '\0';
key = key / 10; key = key / 10;
} }
error = hashmap_get(ipv4_frag_map, shortkey, (void **)&frag); error = hashmap_get(ipv4_frag_map, shortkey, (void **)&frag);
if (error == MAP_OK) { if (error == MAP_OK) {
if (!(htons(iph->ipoffset) & 0x8000)) { if (!(htons(iph->ipoffset) & 0x8000)) {
@ -237,7 +238,8 @@ void ipv4_reassemble_packet(struct ether_t *ether, struct ipv4_header_t *iph) {
if (frag->middle_packet_count == 0) { if (frag->middle_packet_count == 0) {
frag->middle_packets = (struct ipv4_header_t **)dbmalloc(sizeof(struct ipv4_header_t *), "ipv4 reassemble packet 3"); frag->middle_packets = (struct ipv4_header_t **)dbmalloc(sizeof(struct ipv4_header_t *), "ipv4 reassemble packet 3");
} else { } else {
frag->middle_packets = (struct ipv4_header_t **)dbrealloc(frag->middle_packets, sizeof(struct ipv4_header_t *) * (frag->middle_packet_count + 1), "ipv4 reassemble packet 4"); frag->middle_packets = (struct ipv4_header_t **)dbrealloc(frag->middle_packets, sizeof(struct ipv4_header_t *) * (frag->middle_packet_count + 1),
"ipv4 reassemble packet 4");
} }
frag->middle_packets[frag->middle_packet_count] = (struct ipv4_header_t *)dbmalloc(htons(iph->len), "ipv4 reassemble packet 5"); frag->middle_packets[frag->middle_packet_count] = (struct ipv4_header_t *)dbmalloc(htons(iph->len), "ipv4 reassemble packet 5");
memcpy(frag->middle_packets[frag->middle_packet_count], iph, htons(iph->len)); memcpy(frag->middle_packets[frag->middle_packet_count], iph, htons(iph->len));
@ -265,7 +267,8 @@ void ipv4_reassemble_packet(struct ether_t *ether, struct ipv4_header_t *iph) {
if (frag->middle_packet_count == 0) { if (frag->middle_packet_count == 0) {
frag->middle_packets = (struct ipv4_header_t **)dbmalloc(sizeof(struct ipv4_header_t *), "ipv4 reassemble packet 9"); frag->middle_packets = (struct ipv4_header_t **)dbmalloc(sizeof(struct ipv4_header_t *), "ipv4 reassemble packet 9");
} else { } else {
frag->middle_packets = (struct ipv4_header_t **)dbrealloc(frag->middle_packets, sizeof(struct ipv4_header_t *) * (frag->middle_packet_count + 1), "ipv4 reassemble packet 10"); frag->middle_packets = (struct ipv4_header_t **)dbrealloc(frag->middle_packets, sizeof(struct ipv4_header_t *) * (frag->middle_packet_count + 1),
"ipv4 reassemble packet 10");
} }
frag->middle_packets[frag->middle_packet_count] = (struct ipv4_header_t *)dbmalloc(htons(iph->len), "ipv4 reassemble packet 11"); frag->middle_packets[frag->middle_packet_count] = (struct ipv4_header_t *)dbmalloc(htons(iph->len), "ipv4 reassemble packet 11");
memcpy(frag->middle_packets[frag->middle_packet_count], iph, htons(iph->len)); memcpy(frag->middle_packets[frag->middle_packet_count], iph, htons(iph->len));
@ -359,7 +362,9 @@ void ipv4_reassemble_packet(struct ether_t *ether, struct ipv4_header_t *iph) {
for (i = 0; i < frag->middle_packet_count; i++) { for (i = 0; i < frag->middle_packet_count; i++) {
dbfree(frag->middle_packets[i], "ipv4 reassemble packet 17"); dbfree(frag->middle_packets[i], "ipv4 reassemble packet 17");
} }
if (frag->middle_packet_count > 0) {
dbfree(frag->middle_packets, "ipv4 reassemble packet 18"); dbfree(frag->middle_packets, "ipv4 reassemble packet 18");
}
dbfree(frag, "ipv4 reassemble packet 19"); dbfree(frag, "ipv4 reassemble packet 19");
} }

View File

@ -554,7 +554,8 @@ char *mem_alloc_user_page(uint32_t virt) {
current_task->user_pages_virt = (uint32_t *)dbmalloc(current_task->user_pages_cnt * sizeof(uint32_t), "mem alloc user page 2"); current_task->user_pages_virt = (uint32_t *)dbmalloc(current_task->user_pages_cnt * sizeof(uint32_t), "mem alloc user page 2");
} else { } else {
current_task->user_pages = (uint32_t *)dbrealloc(current_task->user_pages, current_task->user_pages_cnt * sizeof(uint32_t), "mem alloc user page 3"); current_task->user_pages = (uint32_t *)dbrealloc(current_task->user_pages, current_task->user_pages_cnt * sizeof(uint32_t), "mem alloc user page 3");
current_task->user_pages_virt = (uint32_t *)dbrealloc(current_task->user_pages_virt, current_task->user_pages_cnt * sizeof(uint32_t), "mem alloc user page 4"); current_task->user_pages_virt =
(uint32_t *)dbrealloc(current_task->user_pages_virt, current_task->user_pages_cnt * sizeof(uint32_t), "mem alloc user page 4");
} }
current_task->user_pages[current_task->user_pages_cnt - 1] = (uint32_t)mem_alloc(); current_task->user_pages[current_task->user_pages_cnt - 1] = (uint32_t)mem_alloc();

11
minix.c
View File

@ -218,8 +218,8 @@ int minix_add_directory_entry(struct vfs_device_t *device, struct minix_inode *d
return 1; return 1;
} }
static struct minix_inode *minix_new_node(struct vfs_device_t *device, struct minix_inode *dirp, uint32_t dir_ino, char *name, uint16_t mode, static struct minix_inode *minix_new_node(struct vfs_device_t *device, struct minix_inode *dirp, uint32_t dir_ino, char *name, uint16_t mode, uint32_t z0,
uint32_t z0, uint32_t *new_ino) { uint32_t *new_ino) {
struct minix_inode *new_inode; struct minix_inode *new_inode;
uint32_t ino; uint32_t ino;
@ -892,7 +892,6 @@ struct minix_inode *minix_get_inode(struct vfs_device_t *device, int ino) {
int inodes_per_block = mdata->sb.s_blocksize / sizeof(struct minix_inode); int inodes_per_block = mdata->sb.s_blocksize / sizeof(struct minix_inode);
uint32_t block; uint32_t block;
char *buffer = (char *)dbmalloc(mdata->sb.s_blocksize, "minix get inode 1"); char *buffer = (char *)dbmalloc(mdata->sb.s_blocksize, "minix get inode 1");
if (!buffer) { if (!buffer) {
@ -1404,8 +1403,7 @@ int minix_read_data(struct vfs_device_t *device, struct minix_file_info *info, c
} }
} else if ((device->device & 0xff00) == 0x100) { } else if ((device->device & 0xff00) == 0x100) {
for (j = block_start; j < block_start + blockcount; j++) { for (j = block_start; j < block_start + blockcount; j++) {
hd_read_block((device->device & 0xff), minix_read_map(device, inode, (uint64_t)(j * mdata->sb.s_blocksize)), tempbuffer, hd_read_block((device->device & 0xff), minix_read_map(device, inode, (uint64_t)(j * mdata->sb.s_blocksize)), tempbuffer, mdata->sb.s_blocksize);
mdata->sb.s_blocksize);
if (j == block_start) { if (j == block_start) {
if (count + block_offset > mdata->sb.s_blocksize) { if (count + block_offset > mdata->sb.s_blocksize) {
memcpy(buffer, &tempbuffer[block_offset], mdata->sb.s_blocksize - block_offset); memcpy(buffer, &tempbuffer[block_offset], mdata->sb.s_blocksize - block_offset);
@ -1436,8 +1434,7 @@ int minix_read_data(struct vfs_device_t *device, struct minix_file_info *info, c
return 0; return 0;
} }
int minix_get_dents(struct vfs_device_t *device, struct minix_file_info *info, char *buffer, int len, uint64_t offset, int minix_get_dents(struct vfs_device_t *device, struct minix_file_info *info, char *buffer, int len, uint64_t offset, uint64_t *newoffset) {
uint64_t *newoffset) {
struct minix_inode *inode = minix_get_inode(device, info->inode); struct minix_inode *inode = minix_get_inode(device, info->inode);
char *buffer2; char *buffer2;
int dirlen = minix_read_entire_file(device, inode, &buffer2); int dirlen = minix_read_entire_file(device, inode, &buffer2);

View File

@ -55,8 +55,7 @@ struct minix_data {
#define NO_BLOCK 0 #define NO_BLOCK 0
extern struct minix_inode *minix_get_inode(struct vfs_device_t *device, int ino); extern struct minix_inode *minix_get_inode(struct vfs_device_t *device, int ino);
extern int minix_get_dents(struct vfs_device_t *device, struct minix_file_info *info, char *buffer, int len, uint64_t offset, extern int minix_get_dents(struct vfs_device_t *device, struct minix_file_info *info, char *buffer, int len, uint64_t offset, uint64_t *newoffset);
uint64_t *newoffset);
extern struct minix_file_info *minix_check_if_exists(struct vfs_device_t *device, const char *path, int type); extern struct minix_file_info *minix_check_if_exists(struct vfs_device_t *device, const char *path, int type);
extern int minix_create_file(struct vfs_device_t *device, char *path); extern int minix_create_file(struct vfs_device_t *device, char *path);
extern void minix_trunc_file(struct vfs_device_t *device, struct minix_file_info *finfo); extern void minix_trunc_file(struct vfs_device_t *device, struct minix_file_info *finfo);

6
pata.c
View File

@ -267,8 +267,7 @@ void ide_wait_irq() {
} }
void ide_irq_isr(struct regs *r) { ide_irq_invoked = 1; } void ide_irq_isr(struct regs *r) { ide_irq_invoked = 1; }
uint8_t ide_ata_dma_access(struct ide_dev *device, uint8_t direction, uint8_t drive, uint32_t lba, uint8_t numsects, uint8_t ide_ata_dma_access(struct ide_dev *device, uint8_t direction, uint8_t drive, uint32_t lba, uint8_t numsects, uint16_t selector, uint32_t edi) {
uint16_t selector, uint32_t edi) {
uint32_t channel = device->ide_devices[drive].channel; // Read the Channel. uint32_t channel = device->ide_devices[drive].channel; // Read the Channel.
uint32_t slavebit = device->ide_devices[drive].drive; // Read the Drive [Master/Slave] uint32_t slavebit = device->ide_devices[drive].drive; // Read the Drive [Master/Slave]
@ -404,8 +403,7 @@ uint8_t ide_ata_dma_access(struct ide_dev *device, uint8_t direction, uint8_t dr
ide_write(device, channel, ATA_REG_CONTROL, device->channels[channel].nIEN = (ide_irq_invoked = 0x0) + 0x2); ide_write(device, channel, ATA_REG_CONTROL, device->channels[channel].nIEN = (ide_irq_invoked = 0x0) + 0x2);
return 0; return 0;
} }
uint8_t ide_ata_access(struct ide_dev *device, uint8_t direction, uint8_t drive, uint32_t lba, uint8_t numsects, uint8_t ide_ata_access(struct ide_dev *device, uint8_t direction, uint8_t drive, uint32_t lba, uint8_t numsects, uint16_t selector, uint32_t edi) {
uint16_t selector, uint32_t edi) {
uint8_t lba_mode /* 0: CHS, 1:LBA28, 2: LBA48 */, dma /* 0: No DMA, 1: DMA */, cmd; uint8_t lba_mode /* 0: CHS, 1:LBA28, 2: LBA48 */, dma /* 0: No DMA, 1: DMA */, cmd;
uint8_t lba_io[6]; uint8_t lba_io[6];
uint32_t channel = device->ide_devices[drive].channel; // Read the Channel. uint32_t channel = device->ide_devices[drive].channel; // Read the Channel.