diff --git a/src/include/hlib.h b/src/include/hlib.h index d36b727..377446a 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -29,7 +29,7 @@ extern void request(uint32_t service, uint32_t provider, void *data, uint32_t size); extern uint32_t getServiceId(); -extern uintptr_t insertString(char *string, uintptr_t size); +extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); diff --git a/src/include/hlib.h b/src/include/hlib.h index d36b727..377446a 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -29,7 +29,7 @@ extern void request(uint32_t service, uint32_t provider, void *data, uint32_t size); extern uint32_t getServiceId(); -extern uintptr_t insertString(char *string, uintptr_t size); +extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index f92325a..642834a 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -1,11 +1,13 @@ #include #include +#include void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { if (service == call->service) { call->returnValue = i; + return; } i++; }) @@ -15,8 +17,10 @@ void handleGetServiceSyscall(Syscall *call) { uint32_t i = 0; Service *callService = call->service; - char *name = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[0]))); + char *name = retrieveString(call->parameters[0], NULL); + if (!name) { + return; + } foreach (services, Service *, service, { if (stringEquals(service->name, name)) { call->returnValue = i; @@ -30,8 +34,10 @@ void handleGetProviderSyscall(Syscall *call) { uint32_t i = 0; Service *callService = call->service; - char *name = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *name = retrieveString(call->parameters[1], NULL); + if (!name) { + return; + } Service *providerService = listGet(services, call->parameters[0]); foreach (providerService->providers, Provider *, provider, { if (stringEquals(provider->name, name)) { @@ -44,15 +50,16 @@ } void handleInstallSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); + if (!name) { + return; + } Provider *provider = malloc(sizeof(Provider)); Service *service = call->service; - char *providerName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - provider->name = providerName; + provider->name = name; provider->address = PTR(call->parameters[1]); provider->service = call->service; call->returnValue = listCount(service->providers); - // todo make listAdd return the new index listAdd(&service->providers, provider); } diff --git a/src/include/hlib.h b/src/include/hlib.h index d36b727..377446a 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -29,7 +29,7 @@ extern void request(uint32_t service, uint32_t provider, void *data, uint32_t size); extern uint32_t getServiceId(); -extern uintptr_t insertString(char *string, uintptr_t size); +extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index f92325a..642834a 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -1,11 +1,13 @@ #include #include +#include void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { if (service == call->service) { call->returnValue = i; + return; } i++; }) @@ -15,8 +17,10 @@ void handleGetServiceSyscall(Syscall *call) { uint32_t i = 0; Service *callService = call->service; - char *name = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[0]))); + char *name = retrieveString(call->parameters[0], NULL); + if (!name) { + return; + } foreach (services, Service *, service, { if (stringEquals(service->name, name)) { call->returnValue = i; @@ -30,8 +34,10 @@ void handleGetProviderSyscall(Syscall *call) { uint32_t i = 0; Service *callService = call->service; - char *name = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *name = retrieveString(call->parameters[1], NULL); + if (!name) { + return; + } Service *providerService = listGet(services, call->parameters[0]); foreach (providerService->providers, Provider *, provider, { if (stringEquals(provider->name, name)) { @@ -44,15 +50,16 @@ } void handleInstallSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); + if (!name) { + return; + } Provider *provider = malloc(sizeof(Provider)); Service *service = call->service; - char *providerName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - provider->name = providerName; + provider->name = name; provider->address = PTR(call->parameters[1]); provider->service = call->service; call->returnValue = listCount(service->providers); - // todo make listAdd return the new index listAdd(&service->providers, provider); } diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 44a287f..366f292 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -35,13 +35,17 @@ for (uint32_t startBit = 0; startBit < BITS(uintptr_t) - 4; startBit += 4) { void *nextLayer = currentLayer[(stringId >> startBit) & 0xF]; if (!nextLayer) { - *size = 0; + if (size) { + *size = 0; + } return NULL; } currentLayer = nextLayer; } char *result = currentLayer[stringId >> (BITS(uintptr_t) - 4)]; - *size = strlen(result); + if (size) { + *size = strlen(result); + } return result; } diff --git a/src/include/hlib.h b/src/include/hlib.h index d36b727..377446a 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -29,7 +29,7 @@ extern void request(uint32_t service, uint32_t provider, void *data, uint32_t size); extern uint32_t getServiceId(); -extern uintptr_t insertString(char *string, uintptr_t size); +extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index f92325a..642834a 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -1,11 +1,13 @@ #include #include +#include void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { if (service == call->service) { call->returnValue = i; + return; } i++; }) @@ -15,8 +17,10 @@ void handleGetServiceSyscall(Syscall *call) { uint32_t i = 0; Service *callService = call->service; - char *name = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[0]))); + char *name = retrieveString(call->parameters[0], NULL); + if (!name) { + return; + } foreach (services, Service *, service, { if (stringEquals(service->name, name)) { call->returnValue = i; @@ -30,8 +34,10 @@ void handleGetProviderSyscall(Syscall *call) { uint32_t i = 0; Service *callService = call->service; - char *name = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *name = retrieveString(call->parameters[1], NULL); + if (!name) { + return; + } Service *providerService = listGet(services, call->parameters[0]); foreach (providerService->providers, Provider *, provider, { if (stringEquals(provider->name, name)) { @@ -44,15 +50,16 @@ } void handleInstallSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); + if (!name) { + return; + } Provider *provider = malloc(sizeof(Provider)); Service *service = call->service; - char *providerName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - provider->name = providerName; + provider->name = name; provider->address = PTR(call->parameters[1]); provider->service = call->service; call->returnValue = listCount(service->providers); - // todo make listAdd return the new index listAdd(&service->providers, provider); } diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 44a287f..366f292 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -35,13 +35,17 @@ for (uint32_t startBit = 0; startBit < BITS(uintptr_t) - 4; startBit += 4) { void *nextLayer = currentLayer[(stringId >> startBit) & 0xF]; if (!nextLayer) { - *size = 0; + if (size) { + *size = 0; + } return NULL; } currentLayer = nextLayer; } char *result = currentLayer[stringId >> (BITS(uintptr_t) - 4)]; - *size = strlen(result); + if (size) { + *size = strlen(result); + } return result; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index f11ba62..53b12cc 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -1,4 +1,5 @@ #include "include/syscalls.h" +#include #include #define PTR(x) ((void *)(uintptr_t)x) @@ -28,8 +29,10 @@ syscall(SYS_REQUEST, module, function, U32(data), size); } -uint32_t installServiceProvider(char *name, void(provider)(void *)) { - return syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); +uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)) { + uintptr_t id = insertString(name); + return syscall(SYS_REGISTER_FUNCTION, id, U32(provider), 0, 0); } uint32_t strlen(char *string) { @@ -42,11 +45,13 @@ } uint32_t getService(char *name) { - return syscall(SYS_GET_SERVICE, U32(name), strlen(name), 0, 0); + uintptr_t id = insertString(name); + return syscall(SYS_GET_SERVICE, id, 0, 0, 0); } uint32_t getProvider(uint32_t module, char *name) { - return syscall(SYS_GET_PROVIDER, module, U32(name), strlen(name), 0); + uintptr_t id = insertString(name); + return syscall(SYS_GET_PROVIDER, module, id, 0, 0); } void loadFromInitrd(char *name) { @@ -83,8 +88,8 @@ uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } -uintptr_t insertString(char *string, uintptr_t size) { - return syscall(SYS_INSERT_STRING, U32(string), size, 0, 0); +uintptr_t insertString(char *string) { + return syscall(SYS_INSERT_STRING, U32(string), strlen(string), 0, 0); } uintptr_t getStringLength(uintptr_t stringId) { diff --git a/src/include/hlib.h b/src/include/hlib.h index d36b727..377446a 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -29,7 +29,7 @@ extern void request(uint32_t service, uint32_t provider, void *data, uint32_t size); extern uint32_t getServiceId(); -extern uintptr_t insertString(char *string, uintptr_t size); +extern uintptr_t insertString(char *string); extern uintptr_t getStringLength(uintptr_t stringId); extern void readString(uintptr_t stringId, void *buffer); extern void discardString(uintptr_t stringId); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index f92325a..642834a 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -1,11 +1,13 @@ #include #include +#include void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { if (service == call->service) { call->returnValue = i; + return; } i++; }) @@ -15,8 +17,10 @@ void handleGetServiceSyscall(Syscall *call) { uint32_t i = 0; Service *callService = call->service; - char *name = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[0]))); + char *name = retrieveString(call->parameters[0], NULL); + if (!name) { + return; + } foreach (services, Service *, service, { if (stringEquals(service->name, name)) { call->returnValue = i; @@ -30,8 +34,10 @@ void handleGetProviderSyscall(Syscall *call) { uint32_t i = 0; Service *callService = call->service; - char *name = kernelMapPhysical(getPhysicalAddress( - callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); + char *name = retrieveString(call->parameters[1], NULL); + if (!name) { + return; + } Service *providerService = listGet(services, call->parameters[0]); foreach (providerService->providers, Provider *, provider, { if (stringEquals(provider->name, name)) { @@ -44,15 +50,16 @@ } void handleInstallSyscall(Syscall *call) { + char *name = retrieveString(call->parameters[0], NULL); + if (!name) { + return; + } Provider *provider = malloc(sizeof(Provider)); Service *service = call->service; - char *providerName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); - provider->name = providerName; + provider->name = name; provider->address = PTR(call->parameters[1]); provider->service = call->service; call->returnValue = listCount(service->providers); - // todo make listAdd return the new index listAdd(&service->providers, provider); } diff --git a/src/kernel/stringmap/stringmap.c b/src/kernel/stringmap/stringmap.c index 44a287f..366f292 100644 --- a/src/kernel/stringmap/stringmap.c +++ b/src/kernel/stringmap/stringmap.c @@ -35,13 +35,17 @@ for (uint32_t startBit = 0; startBit < BITS(uintptr_t) - 4; startBit += 4) { void *nextLayer = currentLayer[(stringId >> startBit) & 0xF]; if (!nextLayer) { - *size = 0; + if (size) { + *size = 0; + } return NULL; } currentLayer = nextLayer; } char *result = currentLayer[stringId >> (BITS(uintptr_t) - 4)]; - *size = strlen(result); + if (size) { + *size = strlen(result); + } return result; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index f11ba62..53b12cc 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -1,4 +1,5 @@ #include "include/syscalls.h" +#include #include #define PTR(x) ((void *)(uintptr_t)x) @@ -28,8 +29,10 @@ syscall(SYS_REQUEST, module, function, U32(data), size); } -uint32_t installServiceProvider(char *name, void(provider)(void *)) { - return syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); +uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)) { + uintptr_t id = insertString(name); + return syscall(SYS_REGISTER_FUNCTION, id, U32(provider), 0, 0); } uint32_t strlen(char *string) { @@ -42,11 +45,13 @@ } uint32_t getService(char *name) { - return syscall(SYS_GET_SERVICE, U32(name), strlen(name), 0, 0); + uintptr_t id = insertString(name); + return syscall(SYS_GET_SERVICE, id, 0, 0, 0); } uint32_t getProvider(uint32_t module, char *name) { - return syscall(SYS_GET_PROVIDER, module, U32(name), strlen(name), 0); + uintptr_t id = insertString(name); + return syscall(SYS_GET_PROVIDER, module, id, 0, 0); } void loadFromInitrd(char *name) { @@ -83,8 +88,8 @@ uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } -uintptr_t insertString(char *string, uintptr_t size) { - return syscall(SYS_INSERT_STRING, U32(string), size, 0, 0); +uintptr_t insertString(char *string) { + return syscall(SYS_INSERT_STRING, U32(string), strlen(string), 0, 0); } uintptr_t getStringLength(uintptr_t stringId) { diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index cdef5a7..7587694 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -13,7 +13,7 @@ loadFromInitrd("pic"); loadFromInitrd("keyboard"); log(testString); - uintptr_t id = insertString(testString, strlen(testString)); + uintptr_t id = insertString(testString); uintptr_t length = getStringLength(id); lengthString[0] += length; log(lengthString);