diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 75bd5fa..041422b 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -34,6 +34,6 @@ extern Service *findService(char *); extern Provider *findProvider(Service *, char *); extern Service *currentService; -extern void scheduleProvider(Provider *provider, void *data, - uint32_t dataLength, Syscall *respondingTo); +extern void scheduleProvider(Provider *provider, uintptr_t data1, + uintptr_t data2, Syscall *respondingTo); #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 75bd5fa..041422b 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -34,6 +34,6 @@ extern Service *findService(char *); extern Provider *findProvider(Service *, char *); extern Service *currentService; -extern void scheduleProvider(Provider *provider, void *data, - uint32_t dataLength, Syscall *respondingTo); +extern void scheduleProvider(Provider *provider, uintptr_t data1, + uintptr_t data2, Syscall *respondingTo); #endif diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 1c63546..a4fd4a3 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -58,6 +58,9 @@ } void free(void *location) { + if (!location) { + return; + } AllocationBlock *block = (void *)((uintptr_t)location & ~0xFFF); if (block->magic != ALLOCATION_MAGIC) { freePage(location); diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 75bd5fa..041422b 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -34,6 +34,6 @@ extern Service *findService(char *); extern Provider *findProvider(Service *, char *); extern Service *currentService; -extern void scheduleProvider(Provider *provider, void *data, - uint32_t dataLength, Syscall *respondingTo); +extern void scheduleProvider(Provider *provider, uintptr_t data1, + uintptr_t data2, Syscall *respondingTo); #endif diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 1c63546..a4fd4a3 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -58,6 +58,9 @@ } void free(void *location) { + if (!location) { + return; + } AllocationBlock *block = (void *)((uintptr_t)location & ~0xFFF); if (block->magic != ALLOCATION_MAGIC) { freePage(location); diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 3d48de5..c8f2ed6 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -1,12 +1,12 @@ #include +#include #include extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); Service *service = call->service; - char *programName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - loadProgram(programName, (void *)call); + loadProgram(name, (void *)call); call->avoidReschedule = true; } diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 75bd5fa..041422b 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -34,6 +34,6 @@ extern Service *findService(char *); extern Provider *findProvider(Service *, char *); extern Service *currentService; -extern void scheduleProvider(Provider *provider, void *data, - uint32_t dataLength, Syscall *respondingTo); +extern void scheduleProvider(Provider *provider, uintptr_t data1, + uintptr_t data2, Syscall *respondingTo); #endif diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 1c63546..a4fd4a3 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -58,6 +58,9 @@ } void free(void *location) { + if (!location) { + return; + } AllocationBlock *block = (void *)((uintptr_t)location & ~0xFFF); if (block->magic != ALLOCATION_MAGIC) { freePage(location); diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 3d48de5..c8f2ed6 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -1,12 +1,12 @@ #include +#include #include extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); Service *service = call->service; - char *programName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - loadProgram(programName, (void *)call); + loadProgram(name, (void *)call); call->avoidReschedule = true; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 7ac6bd6..98f1367 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -1,5 +1,5 @@ -#include "elf.h" #include "service.h" +#include "elf.h" #include #include #include @@ -88,12 +88,11 @@ return NULL; } -void scheduleProvider(Provider *provider, void *data, uint32_t dataLength, +void scheduleProvider(Provider *provider, uintptr_t data1, uintptr_t data2, Syscall *respondingTo) { - sharePage(&provider->service->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = 0; - runCall->esp = malloc(0x1000); + runCall->esp = malloc(0x1000); // todo: free this runCall->respondingTo = respondingTo; runCall->cr3 = getPhysicalAddressKernel(provider->service->pagingInfo.pageDirectory); @@ -103,7 +102,7 @@ runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; *(void **)(runCall->esp + 0x4) = &runEnd; - *(void **)(runCall->esp + 0x8) = data; - *(uint32_t *)(runCall->esp + 0xC) = dataLength; + *(uint32_t *)(runCall->esp + 0x8) = data1; + *(uint32_t *)(runCall->esp + 0xC) = data2; listAdd(&callsToProcess, runCall); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 75bd5fa..041422b 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -34,6 +34,6 @@ extern Service *findService(char *); extern Provider *findProvider(Service *, char *); extern Service *currentService; -extern void scheduleProvider(Provider *provider, void *data, - uint32_t dataLength, Syscall *respondingTo); +extern void scheduleProvider(Provider *provider, uintptr_t data1, + uintptr_t data2, Syscall *respondingTo); #endif diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 1c63546..a4fd4a3 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -58,6 +58,9 @@ } void free(void *location) { + if (!location) { + return; + } AllocationBlock *block = (void *)((uintptr_t)location & ~0xFFF); if (block->magic != ALLOCATION_MAGIC) { freePage(location); diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 3d48de5..c8f2ed6 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -1,12 +1,12 @@ #include +#include #include extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); Service *service = call->service; - char *programName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - loadProgram(programName, (void *)call); + loadProgram(name, (void *)call); call->avoidReschedule = true; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 7ac6bd6..98f1367 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -1,5 +1,5 @@ -#include "elf.h" #include "service.h" +#include "elf.h" #include #include #include @@ -88,12 +88,11 @@ return NULL; } -void scheduleProvider(Provider *provider, void *data, uint32_t dataLength, +void scheduleProvider(Provider *provider, uintptr_t data1, uintptr_t data2, Syscall *respondingTo) { - sharePage(&provider->service->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = 0; - runCall->esp = malloc(0x1000); + runCall->esp = malloc(0x1000); // todo: free this runCall->respondingTo = respondingTo; runCall->cr3 = getPhysicalAddressKernel(provider->service->pagingInfo.pageDirectory); @@ -103,7 +102,7 @@ runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; *(void **)(runCall->esp + 0x4) = &runEnd; - *(void **)(runCall->esp + 0x8) = data; - *(uint32_t *)(runCall->esp + 0xC) = dataLength; + *(uint32_t *)(runCall->esp + 0x8) = data1; + *(uint32_t *)(runCall->esp + 0xC) = data2; listAdd(&callsToProcess, runCall); } diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index 642834a..be118d1 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -68,8 +68,6 @@ Service *providerService = listGet(services, call->parameters[0]); Provider *provider = listGet(providerService->providers, call->parameters[1]); - void *data = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[2]))); - scheduleProvider(provider, data, call->parameters[3], call); + scheduleProvider(provider, call->parameters[2], call->parameters[3], call); call->avoidReschedule = true; } diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 75bd5fa..041422b 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -34,6 +34,6 @@ extern Service *findService(char *); extern Provider *findProvider(Service *, char *); extern Service *currentService; -extern void scheduleProvider(Provider *provider, void *data, - uint32_t dataLength, Syscall *respondingTo); +extern void scheduleProvider(Provider *provider, uintptr_t data1, + uintptr_t data2, Syscall *respondingTo); #endif diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 1c63546..a4fd4a3 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -58,6 +58,9 @@ } void free(void *location) { + if (!location) { + return; + } AllocationBlock *block = (void *)((uintptr_t)location & ~0xFFF); if (block->magic != ALLOCATION_MAGIC) { freePage(location); diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 3d48de5..c8f2ed6 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -1,12 +1,12 @@ #include +#include #include extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); Service *service = call->service; - char *programName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - loadProgram(programName, (void *)call); + loadProgram(name, (void *)call); call->avoidReschedule = true; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 7ac6bd6..98f1367 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -1,5 +1,5 @@ -#include "elf.h" #include "service.h" +#include "elf.h" #include #include #include @@ -88,12 +88,11 @@ return NULL; } -void scheduleProvider(Provider *provider, void *data, uint32_t dataLength, +void scheduleProvider(Provider *provider, uintptr_t data1, uintptr_t data2, Syscall *respondingTo) { - sharePage(&provider->service->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = 0; - runCall->esp = malloc(0x1000); + runCall->esp = malloc(0x1000); // todo: free this runCall->respondingTo = respondingTo; runCall->cr3 = getPhysicalAddressKernel(provider->service->pagingInfo.pageDirectory); @@ -103,7 +102,7 @@ runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; *(void **)(runCall->esp + 0x4) = &runEnd; - *(void **)(runCall->esp + 0x8) = data; - *(uint32_t *)(runCall->esp + 0xC) = dataLength; + *(uint32_t *)(runCall->esp + 0x8) = data1; + *(uint32_t *)(runCall->esp + 0xC) = data2; listAdd(&callsToProcess, runCall); } diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index 642834a..be118d1 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -68,8 +68,6 @@ Service *providerService = listGet(services, call->parameters[0]); Provider *provider = listGet(providerService->providers, call->parameters[1]); - void *data = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[2]))); - scheduleProvider(provider, data, call->parameters[3], call); + scheduleProvider(provider, call->parameters[2], call->parameters[3], call); call->avoidReschedule = true; } diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 366f292..7c543e4 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -26,7 +26,9 @@ } currentLayer = nextLayer; } - currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; + if (!currentLayer[hash >> (BITS(uintptr_t) - 4)]) { + currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; + } return hash; } diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 75bd5fa..041422b 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -34,6 +34,6 @@ extern Service *findService(char *); extern Provider *findProvider(Service *, char *); extern Service *currentService; -extern void scheduleProvider(Provider *provider, void *data, - uint32_t dataLength, Syscall *respondingTo); +extern void scheduleProvider(Provider *provider, uintptr_t data1, + uintptr_t data2, Syscall *respondingTo); #endif diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 1c63546..a4fd4a3 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -58,6 +58,9 @@ } void free(void *location) { + if (!location) { + return; + } AllocationBlock *block = (void *)((uintptr_t)location & ~0xFFF); if (block->magic != ALLOCATION_MAGIC) { freePage(location); diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 3d48de5..c8f2ed6 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -1,12 +1,12 @@ #include +#include #include extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); Service *service = call->service; - char *programName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - loadProgram(programName, (void *)call); + loadProgram(name, (void *)call); call->avoidReschedule = true; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 7ac6bd6..98f1367 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -1,5 +1,5 @@ -#include "elf.h" #include "service.h" +#include "elf.h" #include #include #include @@ -88,12 +88,11 @@ return NULL; } -void scheduleProvider(Provider *provider, void *data, uint32_t dataLength, +void scheduleProvider(Provider *provider, uintptr_t data1, uintptr_t data2, Syscall *respondingTo) { - sharePage(&provider->service->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = 0; - runCall->esp = malloc(0x1000); + runCall->esp = malloc(0x1000); // todo: free this runCall->respondingTo = respondingTo; runCall->cr3 = getPhysicalAddressKernel(provider->service->pagingInfo.pageDirectory); @@ -103,7 +102,7 @@ runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; *(void **)(runCall->esp + 0x4) = &runEnd; - *(void **)(runCall->esp + 0x8) = data; - *(uint32_t *)(runCall->esp + 0xC) = dataLength; + *(uint32_t *)(runCall->esp + 0x8) = data1; + *(uint32_t *)(runCall->esp + 0xC) = data2; listAdd(&callsToProcess, runCall); } diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index 642834a..be118d1 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -68,8 +68,6 @@ Service *providerService = listGet(services, call->parameters[0]); Provider *provider = listGet(providerService->providers, call->parameters[1]); - void *data = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[2]))); - scheduleProvider(provider, data, call->parameters[3], call); + scheduleProvider(provider, call->parameters[2], call->parameters[3], call); call->avoidReschedule = true; } diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 366f292..7c543e4 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -26,7 +26,9 @@ } currentLayer = nextLayer; } - currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; + if (!currentLayer[hash >> (BITS(uintptr_t) - 4)]) { + currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; + } return hash; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 53b12cc..c73ab04 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -8,7 +8,7 @@ uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { uint32_t esp; - asm("push %%eax" ::"a"(&&end)); + asm("push %%eax" ::"a"(&&end)); // end: return address asm("mov %%esp, %%eax" : "=a"(esp)); asm("sysenter\n" : @@ -25,8 +25,9 @@ return 0; } -void request(uint32_t module, uint32_t function, void *data, uint32_t size) { - syscall(SYS_REQUEST, module, function, U32(data), size); +void request(uint32_t module, uint32_t function, uintptr_t data1, + uintptr_t data2) { + syscall(SYS_REQUEST, module, function, data1, data2); } uint32_t installServiceProvider(char *name, @@ -55,7 +56,8 @@ } void loadFromInitrd(char *name) { - syscall(SYS_LOAD_INITRD, U32(name), strlen(name), 0, 0); + uintptr_t id = insertString(name); + syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } uint32_t logModule = 0, logProvider; @@ -65,7 +67,9 @@ logModule = getService("log"); logProvider = getProvider(logModule, "log"); } - request(logModule, logProvider, message, strlen(message)); + uintptr_t id = insertString(message); + request(logModule, logProvider, id, 0); + discardString(id); } uint32_t ioIn(uint16_t port, uint8_t size) { @@ -80,10 +84,11 @@ syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); } -void requestName(char *service, char *provider, void *data, uint32_t size) { +void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2) { uint32_t serviceId = getService(service); uint32_t providerId = getProvider(serviceId, provider); - request(serviceId, providerId, data, size); + request(serviceId, providerId, data1, data2); } uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 75bd5fa..041422b 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -34,6 +34,6 @@ extern Service *findService(char *); extern Provider *findProvider(Service *, char *); extern Service *currentService; -extern void scheduleProvider(Provider *provider, void *data, - uint32_t dataLength, Syscall *respondingTo); +extern void scheduleProvider(Provider *provider, uintptr_t data1, + uintptr_t data2, Syscall *respondingTo); #endif diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 1c63546..a4fd4a3 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -58,6 +58,9 @@ } void free(void *location) { + if (!location) { + return; + } AllocationBlock *block = (void *)((uintptr_t)location & ~0xFFF); if (block->magic != ALLOCATION_MAGIC) { freePage(location); diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 3d48de5..c8f2ed6 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -1,12 +1,12 @@ #include +#include #include extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); Service *service = call->service; - char *programName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - loadProgram(programName, (void *)call); + loadProgram(name, (void *)call); call->avoidReschedule = true; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 7ac6bd6..98f1367 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -1,5 +1,5 @@ -#include "elf.h" #include "service.h" +#include "elf.h" #include #include #include @@ -88,12 +88,11 @@ return NULL; } -void scheduleProvider(Provider *provider, void *data, uint32_t dataLength, +void scheduleProvider(Provider *provider, uintptr_t data1, uintptr_t data2, Syscall *respondingTo) { - sharePage(&provider->service->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = 0; - runCall->esp = malloc(0x1000); + runCall->esp = malloc(0x1000); // todo: free this runCall->respondingTo = respondingTo; runCall->cr3 = getPhysicalAddressKernel(provider->service->pagingInfo.pageDirectory); @@ -103,7 +102,7 @@ runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; *(void **)(runCall->esp + 0x4) = &runEnd; - *(void **)(runCall->esp + 0x8) = data; - *(uint32_t *)(runCall->esp + 0xC) = dataLength; + *(uint32_t *)(runCall->esp + 0x8) = data1; + *(uint32_t *)(runCall->esp + 0xC) = data2; listAdd(&callsToProcess, runCall); } diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index 642834a..be118d1 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -68,8 +68,6 @@ Service *providerService = listGet(services, call->parameters[0]); Provider *provider = listGet(providerService->providers, call->parameters[1]); - void *data = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[2]))); - scheduleProvider(provider, data, call->parameters[3], call); + scheduleProvider(provider, call->parameters[2], call->parameters[3], call); call->avoidReschedule = true; } diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 366f292..7c543e4 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -26,7 +26,9 @@ } currentLayer = nextLayer; } - currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; + if (!currentLayer[hash >> (BITS(uintptr_t) - 4)]) { + currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; + } return hash; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 53b12cc..c73ab04 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -8,7 +8,7 @@ uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { uint32_t esp; - asm("push %%eax" ::"a"(&&end)); + asm("push %%eax" ::"a"(&&end)); // end: return address asm("mov %%esp, %%eax" : "=a"(esp)); asm("sysenter\n" : @@ -25,8 +25,9 @@ return 0; } -void request(uint32_t module, uint32_t function, void *data, uint32_t size) { - syscall(SYS_REQUEST, module, function, U32(data), size); +void request(uint32_t module, uint32_t function, uintptr_t data1, + uintptr_t data2) { + syscall(SYS_REQUEST, module, function, data1, data2); } uint32_t installServiceProvider(char *name, @@ -55,7 +56,8 @@ } void loadFromInitrd(char *name) { - syscall(SYS_LOAD_INITRD, U32(name), strlen(name), 0, 0); + uintptr_t id = insertString(name); + syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } uint32_t logModule = 0, logProvider; @@ -65,7 +67,9 @@ logModule = getService("log"); logProvider = getProvider(logModule, "log"); } - request(logModule, logProvider, message, strlen(message)); + uintptr_t id = insertString(message); + request(logModule, logProvider, id, 0); + discardString(id); } uint32_t ioIn(uint16_t port, uint8_t size) { @@ -80,10 +84,11 @@ syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); } -void requestName(char *service, char *provider, void *data, uint32_t size) { +void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2) { uint32_t serviceId = getService(service); uint32_t providerId = getProvider(serviceId, provider); - request(serviceId, providerId, data, size); + request(serviceId, providerId, data1, data2); } uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/userland/log/main.c b/src/userland/log/main.c index e71e38a..ed1f9d4 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -3,21 +3,22 @@ uint32_t outService, outProvider; -void writeParallel(uint8_t data) { - request(outService, outProvider, PTR(data), 0); -} +void writeParallel(uint8_t data) { request(outService, outProvider, data, 0); } -void handleLog(void *data, uint32_t dataLength) { - char *string = data, dump; - for (uint32_t i = 0; i < dataLength; i++) { - writeParallel(string[i]); +char buffer[100]; + +void handleLog(uint32_t stringId, uint32_t unused) { + readString(stringId, buffer); + uint32_t length = strlen(buffer); + for (uint32_t i = 0; i < length; i++) { + writeParallel(buffer[i]); } writeParallel('\r'); writeParallel('\n'); } -void registerOut(uint32_t *service, uint32_t provider) { - outService = *service; +void registerOut(uintptr_t service, uintptr_t provider) { + outService = service; outProvider = provider; } diff --git a/src/include/hlib.h b/src/include/hlib.h index 377446a..d14b911 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -24,10 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); -extern void requestName(char *service, char *provider, void *data, - uint32_t size); -extern void request(uint32_t service, uint32_t provider, void *data, - uint32_t size); +extern void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2); +extern void request(uint32_t service, uint32_t provider, uintptr_t data1, + uintptr_t data2); extern uint32_t getServiceId(); extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 75bd5fa..041422b 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -34,6 +34,6 @@ extern Service *findService(char *); extern Provider *findProvider(Service *, char *); extern Service *currentService; -extern void scheduleProvider(Provider *provider, void *data, - uint32_t dataLength, Syscall *respondingTo); +extern void scheduleProvider(Provider *provider, uintptr_t data1, + uintptr_t data2, Syscall *respondingTo); #endif diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 1c63546..a4fd4a3 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -58,6 +58,9 @@ } void free(void *location) { + if (!location) { + return; + } AllocationBlock *block = (void *)((uintptr_t)location & ~0xFFF); if (block->magic != ALLOCATION_MAGIC) { freePage(location); diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 3d48de5..c8f2ed6 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -1,12 +1,12 @@ #include +#include #include extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); Service *service = call->service; - char *programName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - loadProgram(programName, (void *)call); + loadProgram(name, (void *)call); call->avoidReschedule = true; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 7ac6bd6..98f1367 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -1,5 +1,5 @@ -#include "elf.h" #include "service.h" +#include "elf.h" #include #include #include @@ -88,12 +88,11 @@ return NULL; } -void scheduleProvider(Provider *provider, void *data, uint32_t dataLength, +void scheduleProvider(Provider *provider, uintptr_t data1, uintptr_t data2, Syscall *respondingTo) { - sharePage(&provider->service->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = 0; - runCall->esp = malloc(0x1000); + runCall->esp = malloc(0x1000); // todo: free this runCall->respondingTo = respondingTo; runCall->cr3 = getPhysicalAddressKernel(provider->service->pagingInfo.pageDirectory); @@ -103,7 +102,7 @@ runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; *(void **)(runCall->esp + 0x4) = &runEnd; - *(void **)(runCall->esp + 0x8) = data; - *(uint32_t *)(runCall->esp + 0xC) = dataLength; + *(uint32_t *)(runCall->esp + 0x8) = data1; + *(uint32_t *)(runCall->esp + 0xC) = data2; listAdd(&callsToProcess, runCall); } diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index 642834a..be118d1 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -68,8 +68,6 @@ Service *providerService = listGet(services, call->parameters[0]); Provider *provider = listGet(providerService->providers, call->parameters[1]); - void *data = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[2]))); - scheduleProvider(provider, data, call->parameters[3], call); + scheduleProvider(provider, call->parameters[2], call->parameters[3], call); call->avoidReschedule = true; } diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 366f292..7c543e4 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -26,7 +26,9 @@ } currentLayer = nextLayer; } - currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; + if (!currentLayer[hash >> (BITS(uintptr_t) - 4)]) { + currentLayer[hash >> (BITS(uintptr_t) - 4)] = string; + } return hash; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 53b12cc..c73ab04 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -8,7 +8,7 @@ uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { uint32_t esp; - asm("push %%eax" ::"a"(&&end)); + asm("push %%eax" ::"a"(&&end)); // end: return address asm("mov %%esp, %%eax" : "=a"(esp)); asm("sysenter\n" : @@ -25,8 +25,9 @@ return 0; } -void request(uint32_t module, uint32_t function, void *data, uint32_t size) { - syscall(SYS_REQUEST, module, function, U32(data), size); +void request(uint32_t module, uint32_t function, uintptr_t data1, + uintptr_t data2) { + syscall(SYS_REQUEST, module, function, data1, data2); } uint32_t installServiceProvider(char *name, @@ -55,7 +56,8 @@ } void loadFromInitrd(char *name) { - syscall(SYS_LOAD_INITRD, U32(name), strlen(name), 0, 0); + uintptr_t id = insertString(name); + syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } uint32_t logModule = 0, logProvider; @@ -65,7 +67,9 @@ logModule = getService("log"); logProvider = getProvider(logModule, "log"); } - request(logModule, logProvider, message, strlen(message)); + uintptr_t id = insertString(message); + request(logModule, logProvider, id, 0); + discardString(id); } uint32_t ioIn(uint16_t port, uint8_t size) { @@ -80,10 +84,11 @@ syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); } -void requestName(char *service, char *provider, void *data, uint32_t size) { +void requestName(char *service, char *provider, uintptr_t data1, + uintptr_t data2) { uint32_t serviceId = getService(service); uint32_t providerId = getProvider(serviceId, provider); - request(serviceId, providerId, data, size); + request(serviceId, providerId, data1, data2); } uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/userland/log/main.c b/src/userland/log/main.c index e71e38a..ed1f9d4 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -3,21 +3,22 @@ uint32_t outService, outProvider; -void writeParallel(uint8_t data) { - request(outService, outProvider, PTR(data), 0); -} +void writeParallel(uint8_t data) { request(outService, outProvider, data, 0); } -void handleLog(void *data, uint32_t dataLength) { - char *string = data, dump; - for (uint32_t i = 0; i < dataLength; i++) { - writeParallel(string[i]); +char buffer[100]; + +void handleLog(uint32_t stringId, uint32_t unused) { + readString(stringId, buffer); + uint32_t length = strlen(buffer); + for (uint32_t i = 0; i < length; i++) { + writeParallel(buffer[i]); } writeParallel('\r'); writeParallel('\n'); } -void registerOut(uint32_t *service, uint32_t provider) { - outService = *service; +void registerOut(uintptr_t service, uintptr_t provider) { + outService = service; outProvider = provider; } diff --git a/src/userland/parallel/main.c b/src/userland/parallel/main.c index 7838a3e..0db0671 100644 --- a/src/userland/parallel/main.c +++ b/src/userland/parallel/main.c @@ -26,6 +26,6 @@ event0 = createEvent("in"); event1 = createEvent("parallelIn"); uint32_t thisService = getServiceId(); - requestName("log", "registerOut", &thisService, provider); + requestName("log", "registerOut", thisService, provider); return 0; }