Skip to content

Commit 9862637

Browse files
committed
replaced more vmm calls with heap calls
1 parent 8295528 commit 9862637

File tree

10 files changed

+30
-31
lines changed

10 files changed

+30
-31
lines changed

mckrnl/core/driver/acpi/madt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <stdint.h>
55
#include <stddef.h>
66
#include <stdio.h>
7-
#include <memory/vmm.h>
7+
#include <memory/heap.h>
88

99
uint8_t* madt_lapic_ids = NULL;
1010
uint8_t madt_lapic_count = 0;
@@ -32,16 +32,16 @@ void parse_madt() {
3232
case 0: // Processor local apic
3333
{
3434
madt_local_processor_t* processor = (madt_local_processor_t*) record;
35-
madt_lapic_ids = vmm_resize(sizeof(uint8_t), madt_lapic_count, madt_lapic_count + 1, madt_lapic_ids);
35+
madt_lapic_ids = krealloc(madt_lapic_ids, sizeof(uint8_t) * (madt_lapic_count + 1));
3636
madt_lapic_ids[madt_lapic_count++] = processor->apic_id;
3737
}
3838
break;
3939

4040
case 1: // I/O apic
4141
{
4242
madt_io_apic_t* ioapic = (madt_io_apic_t*) record;
43-
madt_ioapic_ids = vmm_resize(sizeof(uint8_t), madt_ioapic_count, madt_ioapic_count + 1, madt_ioapic_ids);
44-
madt_ioapic_base_addr = vmm_resize(sizeof(uint32_t), madt_ioapic_count, madt_ioapic_count + 1, madt_ioapic_base_addr);
43+
madt_ioapic_ids = krealloc(madt_ioapic_ids, sizeof(uint8_t) * (madt_ioapic_count + 1));
44+
madt_ioapic_base_addr = krealloc(madt_ioapic_base_addr, sizeof(uint32_t) * (madt_ioapic_count + 1));
4545
madt_ioapic_ids[madt_ioapic_count] = ioapic->io_apic_id;
4646
madt_ioapic_base_addr[madt_ioapic_count++] = ioapic->io_apic_address;
4747
}

mckrnl/core/driver/disk_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
#include <config.h>
44
#include <assert.h>
55
#include <stdio.h>
6-
#include <memory/vmm.h>
6+
#include <memory/heap.h>
77
#include <stddef.h>
88

99
int num_disks = 0;
1010
disk_driver_t** disks = NULL;
1111

1212
int register_disk(disk_driver_t* disk) {
13-
disks = vmm_resize(sizeof(disk_driver_t*), num_disks, num_disks + 1, disks);
13+
disks = krealloc(disks, sizeof(disk_driver_t*) * (num_disks + 1));
1414
disks[num_disks] = disk;
1515
debugf("Registered disk %d", num_disks);
1616
num_disks++;

mckrnl/core/driver/driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <driver/driver.h>
22

33
#include <stdio.h>
4-
#include <memory/vmm.h>
4+
#include <memory/heap.h>
55
#include <stddef.h>
66

77
driver_t** drivers = NULL;
88
int num_drivers = 0;
99

1010
void register_driver(driver_t* driver) {
11-
drivers = vmm_resize(sizeof(driver_t*), num_drivers, num_drivers + 1, drivers);
11+
drivers = krealloc(drivers, sizeof(driver_t*) * (num_drivers + 1));
1212
drivers[num_drivers] = driver;
1313
num_drivers++;
1414
}

mckrnl/core/driver/pci/pci.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <config.h>
55

66
#include <stddef.h>
7-
#include <memory/vmm.h>
7+
#include <memory/heap.h>
88

99
pci_driver_t* pci_drivers = NULL;
1010
int num_pci_drivers = 0;
@@ -25,7 +25,7 @@ void apend_pci_device(pci_device_header_t header, uint16_t bus, uint16_t device
2525
.driver_loaded = driver
2626
};
2727

28-
pci_devices = vmm_resize(sizeof(pci_device_list_entry_t), num_pci_devices, num_pci_devices + 1, pci_devices);
28+
pci_devices = krealloc(pci_devices, sizeof(pci_device_list_entry_t) * (num_pci_devices + 1));
2929
pci_devices[num_pci_devices++] = entry;
3030
}
3131

@@ -74,7 +74,7 @@ void register_pci_driver_cs(uint8_t _class, uint8_t subclass, uint8_t prog_IF, v
7474
driver.prog_IF = prog_IF;
7575
driver.use_class_subclass_prog_IF = true;
7676
driver.load_driver = load_driver;
77-
pci_drivers = vmm_resize(sizeof(pci_driver_t), num_pci_drivers, num_pci_drivers + 1, pci_drivers);
77+
pci_drivers = krealloc(pci_drivers, sizeof(pci_driver_t) * (num_pci_drivers + 1));
7878
pci_drivers[num_pci_drivers++] = driver;
7979

8080
debugf("Registered PCI driver with class %d, subclass %d, prog_IF %d", _class, subclass, prog_IF);
@@ -86,7 +86,7 @@ void register_pci_driver_vd(uint16_t vendor_id, uint16_t device_id, void (*load_
8686
driver.device_id = device_id;
8787
driver.use_vendor_device_id = true;
8888
driver.load_driver = load_driver;
89-
pci_drivers = vmm_resize(sizeof(pci_driver_t), num_pci_drivers, num_pci_drivers + 1, pci_drivers);
89+
pci_drivers = krealloc(pci_drivers, sizeof(pci_driver_t) * (num_pci_drivers + 1));
9090
pci_drivers[num_pci_drivers++] = driver;
9191

9292
debugf("Registered PCI driver with vendor_id %x, device_id %x", vendor_id, device_id);

mckrnl/core/fs/fd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <fs/fd.h>
22

33
#include <config.h>
4-
#include <memory/vmm.h>
4+
#include <memory/heap.h>
55
#include <stddef.h>
66

77
file_t** fd_table;
@@ -15,7 +15,7 @@ int file_to_fd(file_t* file) {
1515
}
1616
}
1717

18-
fd_table = vmm_resize(sizeof(file_t*), num_fd, num_fd + 1, fd_table);
18+
fd_table = krealloc(fd_table, sizeof(file_t*) * (num_fd + 1));
1919
fd_table[num_fd] = file;
2020
num_fd++;
2121

mckrnl/core/fs/vfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <config.h>
66
#include <driver/disk_driver.h>
77

8-
#include <memory/vmm.h>
8+
#include <memory/heap.h>
99
#include <stddef.h>
1010

1111
vfs_mount_t** vfs_mounts = NULL;
@@ -36,7 +36,7 @@ bool try_read_disk_label(char* out, vfs_mount_t* mount) {
3636
void vfs_mount(vfs_mount_t* mount) {
3737
debugf("VFS: Mounting %s", mount->name(mount));
3838

39-
vfs_mounts = vmm_resize(sizeof(vfs_mount_t*), num_vfs_mounts, num_vfs_mounts + 1, vfs_mounts);
39+
vfs_mounts = krealloc(vfs_mounts, sizeof(vfs_mount_t*) * (num_vfs_mounts + 1));
4040
vfs_mounts[num_vfs_mounts] = mount;
4141
num_vfs_mounts++;
4242
}
@@ -190,7 +190,7 @@ bool vfs_fs_at(int idx, char* out) {
190190
}
191191

192192
void vfs_register_fs_scanner(fs_scanner scanner) {
193-
vfs_scanner = vmm_resize(sizeof(fs_scanner), num_vfs_scanners, num_vfs_scanners + 1, vfs_scanner);
193+
vfs_scanner = krealloc(vfs_scanner, sizeof(fs_scanner) * (num_vfs_scanners + 1));
194194
vfs_scanner[num_vfs_scanners] = scanner;
195195
debugf("Registered VFS scanner %d at 0x%x", num_vfs_scanners, scanner);
196196
num_vfs_scanners++;

mckrnl/core/net/ipv4.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#include <net/ipv4.h>
22
#include <net/arp.h>
33
#include <stdio.h>
4-
#include <memory/vmm.h>
54
#include <string.h>
65

7-
#include <memory/vmm.h>
6+
#include <memory/heap.h>
87
#include <string.h>
98
#include <config.h>
109
#ifdef NETWORK_STACK
1110

1211
void ipv4_register(network_stack_t* stack, ipv4_handler_t handler) {
13-
stack->ipv4->handlers = vmm_resize(sizeof(ipv4_handler_t), stack->ipv4->num_handlers, stack->ipv4->num_handlers + 1, stack->ipv4->handlers);
12+
stack->ipv4->handlers = krealloc(stack->ipv4->handlers, sizeof(ipv4_handler_t) * (stack->ipv4->num_handlers + 1));
1413
stack->ipv4->handlers[stack->ipv4->num_handlers] = handler;
1514
stack->ipv4->num_handlers++;
1615
}
@@ -33,7 +32,7 @@ mac_u ipv4_resolve_route(network_stack_t* stack, async_t* async, ip_u dest_ip) {
3332
}
3433

3534
void ipv4_send(ipv4_handler_t* handler, network_stack_t* stack, ip_u dest_ip, mac_u route, uint8_t* payload, uint32_t size) {
36-
uint8_t* buffer = vmm_alloc((size + sizeof(ipv4_message_t)) / 0x1000 + 1);
35+
uint8_t* buffer = kmalloc(size + sizeof(ipv4_message_t));
3736
memset(buffer, 0, size + sizeof(ipv4_message_t));
3837
ipv4_message_t* ipv4 = (ipv4_message_t*) buffer;
3938

@@ -60,7 +59,7 @@ void ipv4_send(ipv4_handler_t* handler, network_stack_t* stack, ip_u dest_ip, ma
6059

6160
etherframe_send(&stack->ipv4->handler, stack, route.mac, buffer, size + sizeof(ipv4_message_t));
6261

63-
vmm_free(buffer, (size + sizeof(ipv4_message_t)) / 0x1000 + 1);
62+
kfree(buffer);
6463
}
6564

6665
void ipv4_etherframe_recv(struct ether_frame_handler* handler, mac_u src_mac, uint8_t* payload, uint32_t size) {
@@ -117,7 +116,7 @@ uint16_t ipv4_checksum(uint16_t* data, uint32_t size) {
117116
}
118117

119118
void ipv4_init(network_stack_t* stack) {
120-
stack->ipv4 = vmm_alloc(PAGES_OF(ipv4_provider_t));
119+
stack->ipv4 = kmalloc(sizeof(ipv4_provider_t));
121120
memset(stack->ipv4, 0, sizeof(ipv4_provider_t));
122121

123122
stack->ipv4->handler.ether_type_be = BSWAP16(0x0800);

mckrnl/core/scheduler/resource.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <scheduler/scheduler.h>
22
#include <stddef.h>
3+
#include <memory/heap.h>
34

45
void resource_register_self(resource_t resource) {
56
task_t* self = get_self();
@@ -11,7 +12,7 @@ void resource_register_self(resource_t resource) {
1112
}
1213
}
1314

14-
self->resources = vmm_resize(sizeof(resource_t), self->num_resources, self->num_resources + 1, self->resources);
15+
self->resources = krealloc(self->resources, sizeof(resource_t) * (self->num_resources + 1));
1516
self->resources[self->num_resources] = resource;
1617
self->num_resources++;
1718
}
@@ -36,7 +37,7 @@ void resource_dealloc_self() {
3637
}
3738

3839
if (self->resources != NULL) {
39-
vmm_free(self->resources, TO_PAGES(sizeof(resource_t) * self->num_resources));
40+
kfree(self->resources);
4041
self->resources = NULL;
4142
}
4243
}
@@ -49,7 +50,7 @@ void resource_dealloc(task_t* self) {
4950
}
5051

5152
if (self->resources != NULL) {
52-
vmm_free(self->resources, TO_PAGES(sizeof(resource_t) * self->num_resources));
53+
kfree(self->resources);
5354
self->resources = NULL;
5455
}
5556
}

mckrnl/core/syscall/syscalls.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <stdio.h>
44
#include <stddef.h>
5-
#include <memory/vmm.h>
5+
#include <memory/heap.h>
66
#include <config.h>
77

88
syscall_handler_t* syscall_table = { 0 };
@@ -15,9 +15,8 @@ void register_syscall(uint8_t syscall_id, syscall_handler_t handler) {
1515
}
1616

1717
if (syscall_id >= num_syscall_handlers) {
18-
int old_num_syscall_handlers = num_syscall_handlers;
1918
num_syscall_handlers = syscall_id + 1;
20-
syscall_table = vmm_resize(sizeof(syscall_handler_t), old_num_syscall_handlers, num_syscall_handlers, syscall_table);
19+
syscall_table = krealloc(syscall_table, sizeof(syscall_handler_t) * num_syscall_handlers);
2120
}
2221

2322
syscall_table[syscall_id] = handler;

mckrnl/core/utils/trace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <utils/trace.h>
22
#include <stdio.h>
33
#include <stddef.h>
4-
#include <memory/vmm.h>
4+
#include <memory/heap.h>
55
#include <string.h>
66

77
void stack_unwind(int max, void (*callback)(int frame_num, uint32_t eip)) {
@@ -25,7 +25,7 @@ void register_symbol(symbol_t sym) {
2525
if (sym.name[0] == '_' && sym.name[1] == '_' && sym.name[2] == 'F') {
2626
return;
2727
}
28-
symbols = vmm_resize(sizeof(symbol_t), symbols_count, symbols_count + 1, symbols);
28+
symbols = krealloc(symbols, sizeof(symbol_t) * (symbols_count + 1));
2929
symbols[symbols_count] = sym;
3030
symbols_count++;
3131
}

0 commit comments

Comments
 (0)