Skip to content

Commit b9b2111

Browse files
committed
fixing broken resize in etherframe handlers
1 parent 0f039a8 commit b9b2111

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

mckrnl/core/memory/heap.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void print_allocations(const char* msg) {
102102
debugf("--- End of heap allocations ---");
103103
}
104104

105+
#if 0
105106
void expand_heap(size_t length) {
106107
print_allocations("Before expanding heap");
107108
if (length % 0x1000) {
@@ -114,7 +115,7 @@ void expand_heap(size_t length) {
114115

115116
for (size_t i = 0; i < page_count; i++) {
116117
void* physical_page = pmm_alloc();
117-
vmm_map_page(heap_end, (uintptr_t) heap_end, (uintptr_t) physical_page, PTE_PRESENT | PTE_WRITE);
118+
vmm_map_page(kernel_context, (uintptr_t) heap_end, (uintptr_t) physical_page, PTE_PRESENT | PTE_WRITE);
118119

119120
debugf("Mapped new heap page: virtual 0x%x to physical 0x%x\n", heap_end, physical_page);
120121

@@ -129,6 +130,7 @@ void expand_heap(size_t length) {
129130
new_segment->length = length - sizeof(heap_segment_header_t);
130131
hsh_combine_backward(new_segment);
131132
}
133+
#endif
132134

133135
void* kmalloc(size_t size) {
134136
if (size % 0x10 > 0) { // it is not a multiple of 0x10
@@ -161,8 +163,13 @@ void* kmalloc(size_t size) {
161163
current_seg = current_seg->next;
162164
}
163165

166+
#if 0
164167
expand_heap(size);
165168
return kmalloc(size);
169+
#else
170+
print_allocations("Heap full");
171+
abortf(false, "kernel heap full: could not allocate %d bytes", size);
172+
#endif
166173
}
167174

168175
void* krealloc(void* ptr, size_t size) {

mckrnl/core/net/arp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void arp_init(network_stack_t* stack) {
157157
memset(stack->arp, 0, sizeof(arp_provider_t));
158158

159159
memset(stack->arp->ip_cache, 0xff, sizeof(stack->arp->ip_cache));
160-
memset(stack->arp->mac_cache, 0xff, sizeof(stack->arp->ip_cache));
160+
memset(stack->arp->mac_cache, 0xff, sizeof(stack->arp->mac_cache));
161161

162162
stack->arp->handler.ether_type_be = BSWAP16(0x806);
163163
stack->arp->handler.stack = stack;

mckrnl/core/net/etherframe.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "driver/nic_driver.h"
21
#include <net/etherframe.h>
32
#include <stdio.h>
43
#include <memory/heap.h>
@@ -9,7 +8,7 @@
98

109
void etherframe_register(network_stack_t* stack, ether_frame_handler_t handler) {
1110
debugf("Registering etherframe handler for %d", handler.ether_type_be);
12-
stack->ether_frame->handlers = kmalloc(sizeof(ether_frame_handler_t) * (stack->ether_frame->num_handlers + 1));
11+
stack->ether_frame->handlers = krealloc(stack->ether_frame->handlers, sizeof(ether_frame_handler_t) * (stack->ether_frame->num_handlers + 1));
1312
stack->ether_frame->handlers[stack->ether_frame->num_handlers] = handler;
1413
stack->ether_frame->num_handlers++;
1514
}

0 commit comments

Comments
 (0)