more debugging

This commit is contained in:
Andrew Pamment 2022-07-20 21:00:19 +10:00
parent 479553d12b
commit cab68ebc36
5 changed files with 30 additions and 7 deletions

View File

@ -206,8 +206,7 @@ int fault_handler(struct regs *r) {
kprintf("Kernel Page Fault: %p\n", fault_address); kprintf("Kernel Page Fault: %p\n", fault_address);
print_regs(r); print_regs(r);
gui_flip(); gui_flip();
while (1) abort();
;
} }
} }

4
ipv4.c
View File

@ -72,9 +72,10 @@ void ipv4_fragment_trim() {
hashmap_iterate(ipv4_frag_map, ipv4_fragment_trim_iter, &totrim); hashmap_iterate(ipv4_frag_map, ipv4_fragment_trim_iter, &totrim);
for (size_t i = 0; i < ptr_vector_len(&totrim); i++) { for (size_t i = 0; i < ptr_vector_len(&totrim); i++) {
struct ipv4_frag_t *frag = (struct ipv4_frag_t *)ptr_vector_get(&totrim, i); struct ipv4_frag_t *frag = (struct ipv4_frag_t *)ptr_vector_del(&totrim, 0);
hashmap_remove(ipv4_frag_map, frag->key); hashmap_remove(ipv4_frag_map, frag->key);
if (frag->first_packet != NULL) { if (frag->first_packet != NULL) {
dbfree(frag->first_packet, "ipv4_fragment_trim 1"); dbfree(frag->first_packet, "ipv4_fragment_trim 1");
} }
@ -87,6 +88,7 @@ void ipv4_fragment_trim() {
if (frag->middle_packet_count > 0) { if (frag->middle_packet_count > 0) {
dbfree(frag->middle_packets, "ipv4_fragment_trim 4"); dbfree(frag->middle_packets, "ipv4_fragment_trim 4");
} }
dbfree(frag, "ipv4_fragment_trim 5");
} }
destroy_ptr_vector(&totrim); destroy_ptr_vector(&totrim);

View File

@ -40,7 +40,9 @@ void __assert_fail(const char *__assertion, const char *__file, unsigned int __l
void abort(void) { void abort(void) {
kprintf("Abort.\n"); kprintf("Abort.\n");
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
kprintf("DBMALLOC[%d]. %s\n", i, db_malloc_caller[i]); if (db_malloc_caller[i] != NULL) {
kprintf("DBMALLOC[%d]. %s\n", i, db_malloc_caller[i]);
}
} }
kprintf("PID: %d (%s)\n", current_task->pid, current_task->name); kprintf("PID: %d (%s)\n", current_task->pid, current_task->name);
kprintf("LAST SYSCALL %d\n", last_syscall); kprintf("LAST SYSCALL %d\n", last_syscall);
@ -51,7 +53,9 @@ void abort(void) {
void abort_on_usage(void *m) { void abort_on_usage(void *m) {
kprintf("Abort on Usage error\n"); kprintf("Abort on Usage error\n");
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
kprintf("DBMALLOC[%d]. %s\n", i, db_malloc_caller[i]); if (db_malloc_caller[i] != NULL) {
kprintf("DBMALLOC[%d]. %s\n", i, db_malloc_caller[i]);
}
} }
kprintf("PID: %d\n", current_task->pid); kprintf("PID: %d\n", current_task->pid);
kprintf("LAST SYSCALL %d\n", last_syscall); kprintf("LAST SYSCALL %d\n", last_syscall);

View File

@ -4,12 +4,15 @@
void memset(char *ptr, char value, int len) { void memset(char *ptr, char value, int len) {
int i; int i;
assert(ptr != NULL);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
ptr[i] = value; ptr[i] = value;
} }
} }
void *memmove(void *dest, const void *src, uint32_t n) { void *memmove(void *dest, const void *src, uint32_t n) {
assert(dest != NULL && src != NULL);
char *pDest = (char *)dest; char *pDest = (char *)dest;
const char *pSrc = (const char *)src; const char *pSrc = (const char *)src;
// allocate memory for tmp array // allocate memory for tmp array
@ -32,6 +35,7 @@ void *memmove(void *dest, const void *src, uint32_t n) {
} }
void memcpy(void *dest, void *src, int size) { void memcpy(void *dest, void *src, int size) {
assert(dest != NULL && src != NULL);
uint8_t *pdest = (uint8_t *)dest; uint8_t *pdest = (uint8_t *)dest;
uint8_t *psrc = (uint8_t *)src; uint8_t *psrc = (uint8_t *)src;
@ -51,6 +55,7 @@ void memcpy(void *dest, void *src, int size) {
} }
char *strncpy(char *dest, const char *src, int len) { char *strncpy(char *dest, const char *src, int len) {
assert(dest != NULL && src != NULL);
const char *ptr = src; const char *ptr = src;
char *ptr2 = dest; char *ptr2 = dest;
int i = 0; int i = 0;
@ -67,6 +72,7 @@ char *strncpy(char *dest, const char *src, int len) {
} }
char *strcpy(char *dest, const char *src) { char *strcpy(char *dest, const char *src) {
assert(dest != NULL && src != NULL);
const char *ptr = src; const char *ptr = src;
char *ptr2 = dest; char *ptr2 = dest;
while (*ptr != '\0') { while (*ptr != '\0') {
@ -79,6 +85,9 @@ char *strcpy(char *dest, const char *src) {
} }
int memcmp(const uint8_t *m1, const uint8_t *m2, int size) { int memcmp(const uint8_t *m1, const uint8_t *m2, int size) {
assert(m1 != NULL && m2 != NULL);
while ((*m1) && (*m1 == *m2) && size > 0) { while ((*m1) && (*m1 == *m2) && size > 0) {
--size; --size;
++m1; ++m1;
@ -88,6 +97,8 @@ int memcmp(const uint8_t *m1, const uint8_t *m2, int size) {
} }
int strncmp(const char *s1, const char *s2, int n) { int strncmp(const char *s1, const char *s2, int n) {
assert(s1 != NULL && s2 != NULL);
while ((*s1) && (*s1 == *s2) && n > 0) { while ((*s1) && (*s1 == *s2) && n > 0) {
--n; --n;
++s1; ++s1;
@ -97,6 +108,8 @@ int strncmp(const char *s1, const char *s2, int n) {
} }
int strcmp(const char *s1, const char *s2) { int strcmp(const char *s1, const char *s2) {
assert(s1 != NULL && s2 != NULL);
while ((*s1) && (*s1 == *s2)) { while ((*s1) && (*s1 == *s2)) {
++s1; ++s1;
++s2; ++s2;
@ -107,6 +120,8 @@ int strcmp(const char *s1, const char *s2) {
int strlen(const char *str) { int strlen(const char *str) {
int i = 0; int i = 0;
assert(str != NULL);
while (*str != '\0') { while (*str != '\0') {
str++; str++;
i++; i++;
@ -115,6 +130,7 @@ int strlen(const char *str) {
} }
char *strcat(char *dest, const char *src) { char *strcat(char *dest, const char *src) {
assert(dest != NULL && src != NULL);
char *ptr = dest; char *ptr = dest;
while (*dest != '\0') { while (*dest != '\0') {
dest++; dest++;

6
vfs.c
View File

@ -410,6 +410,7 @@ void vfs_close_file(int fno) {
if (current_task->filehandles[fno].info->ref == 0) { if (current_task->filehandles[fno].info->ref == 0) {
free(current_task->filehandles[fno].info); free(current_task->filehandles[fno].info);
} }
free(current_task->filehandles[fno].filepath);
current_task->filehandles[fno].device = NULL; current_task->filehandles[fno].device = NULL;
break; break;
case 3: case 3:
@ -802,17 +803,18 @@ int vfs_open_file_dev(struct vfs_device_t *device, char *path, int flags, int mo
} }
} }
if (i == 256) { if (i == 256) {
dbfree(temppath, "vfs_open file dev 4");
return -1; return -1;
} }
current_task->filehandles[i].free = 0; current_task->filehandles[i].free = 0;
current_task->filehandles[i].device = device; current_task->filehandles[i].device = device;
current_task->filehandles[i].filepath = NULL; current_task->filehandles[i].filepath = (char *)dbmalloc(strlen(temppath) + 1, "vfs_open file dev 4");
strcpy(current_task->filehandles[i].filepath, temppath);
current_task->filehandles[i].info = (struct vfs_file_handle_info_t *)dbmalloc(sizeof(struct vfs_file_handle_info_t), "vfs_open file dev 3"); current_task->filehandles[i].info = (struct vfs_file_handle_info_t *)dbmalloc(sizeof(struct vfs_file_handle_info_t), "vfs_open file dev 3");
current_task->filehandles[i].info->position = 0; current_task->filehandles[i].info->position = 0;
current_task->filehandles[i].info->size = 0; current_task->filehandles[i].info->size = 0;
current_task->filehandles[i].info->ref = 1; current_task->filehandles[i].info->ref = 1;
dbfree(temppath, "vfs_open file dev 4"); dbfree(temppath, "vfs_open file dev 4");
return i; return i;
case 3: { case 3: {