diff --git a/src/include/hlib.h b/src/include/hlib.h index c57b875..6b27b81 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -46,6 +46,8 @@ extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); extern uint32_t getFunction(uint32_t serviceId, char *functionName); +extern bool stackContains(uint32_t serviceId); + #define MAX(x, y) (x > y ? (x) : (y)) #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index c57b875..6b27b81 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -46,6 +46,8 @@ extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); extern uint32_t getFunction(uint32_t serviceId, char *functionName); +extern bool stackContains(uint32_t serviceId); + #define MAX(x, y) (x > y ? (x) : (y)) #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index ede83b1..8395e6c 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -15,6 +15,7 @@ SymbolEntry *symbolTable; char *stringTable; uint32_t symbolTableSize; + uint32_t id; } Service; // the name is subject to change diff --git a/src/include/hlib.h b/src/include/hlib.h index c57b875..6b27b81 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -46,6 +46,8 @@ extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); extern uint32_t getFunction(uint32_t serviceId, char *functionName); +extern bool stackContains(uint32_t serviceId); + #define MAX(x, y) (x > y ? (x) : (y)) #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index ede83b1..8395e6c 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -15,6 +15,7 @@ SymbolEntry *symbolTable; char *stringTable; uint32_t symbolTableSize; + uint32_t id; } Service; // the name is subject to change diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 1164adc..7b5ee70 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -2,12 +2,12 @@ #include #include -extern void loadProgram(char *name, Syscall *respondingTo, bool initialize); +extern Service *loadProgram(char *name, Syscall *respondingTo, bool initialize); void handleLoadFromInitrdSyscall(Syscall *call) { - call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; - loadProgram(name, (void *)call, call->parameters[1]); + Service *result = loadProgram(name, (void *)call, call->parameters[1]); + call->returnValue = result->id; call->avoidReschedule = call->parameters[1]; } diff --git a/src/include/hlib.h b/src/include/hlib.h index c57b875..6b27b81 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -46,6 +46,8 @@ extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); extern uint32_t getFunction(uint32_t serviceId, char *functionName); +extern bool stackContains(uint32_t serviceId); + #define MAX(x, y) (x > y ? (x) : (y)) #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index ede83b1..8395e6c 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -15,6 +15,7 @@ SymbolEntry *symbolTable; char *stringTable; uint32_t symbolTableSize; + uint32_t id; } Service; // the name is subject to change diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 1164adc..7b5ee70 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -2,12 +2,12 @@ #include #include -extern void loadProgram(char *name, Syscall *respondingTo, bool initialize); +extern Service *loadProgram(char *name, Syscall *respondingTo, bool initialize); void handleLoadFromInitrdSyscall(Syscall *call) { - call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; - loadProgram(name, (void *)call, call->parameters[1]); + Service *result = loadProgram(name, (void *)call, call->parameters[1]); + call->returnValue = result->id; call->avoidReschedule = call->parameters[1]; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index f227df2..14d0d98 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -34,6 +34,7 @@ service->pagingInfo.pageDirectory = malloc(0x1000); service->name = serviceName; service->nameHash = insertString(serviceName); + service->id = listCount(services); fireEvent(loadInitrdEvent, service->nameHash); void *current = &functionsStart; if (hlib) { diff --git a/src/include/hlib.h b/src/include/hlib.h index c57b875..6b27b81 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -46,6 +46,8 @@ extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); extern uint32_t getFunction(uint32_t serviceId, char *functionName); +extern bool stackContains(uint32_t serviceId); + #define MAX(x, y) (x > y ? (x) : (y)) #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index ede83b1..8395e6c 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -15,6 +15,7 @@ SymbolEntry *symbolTable; char *stringTable; uint32_t symbolTableSize; + uint32_t id; } Service; // the name is subject to change diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 1164adc..7b5ee70 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -2,12 +2,12 @@ #include #include -extern void loadProgram(char *name, Syscall *respondingTo, bool initialize); +extern Service *loadProgram(char *name, Syscall *respondingTo, bool initialize); void handleLoadFromInitrdSyscall(Syscall *call) { - call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; - loadProgram(name, (void *)call, call->parameters[1]); + Service *result = loadProgram(name, (void *)call, call->parameters[1]); + call->returnValue = result->id; call->avoidReschedule = call->parameters[1]; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index f227df2..14d0d98 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -34,6 +34,7 @@ service->pagingInfo.pageDirectory = malloc(0x1000); service->name = serviceName; service->nameHash = insertString(serviceName); + service->id = listCount(services); fireEvent(loadInitrdEvent, service->nameHash); void *current = &functionsStart; if (hlib) { diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index fd5db70..288819d 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -18,15 +18,7 @@ } void handleGetServiceIdSyscall(Syscall *call) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == call->service) { - call->returnValue = i; - return; - } - i++; - }) - ; + call->returnValue = ((Service *)call->service)->id; } void handleGetServiceSyscall(Syscall *call) { @@ -84,7 +76,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash, getServiceId(service)); + service->nameHash, service->id); call->avoidReschedule = true; } @@ -102,3 +94,15 @@ } } } + +void handleStackContainsSyscall(Syscall *call) { + Syscall *currentCall = call; + while (currentCall) { + if (((Service *)currentCall->service)->id == call->parameters[0]) { + call->returnValue = 1; + return; + } + currentCall = currentCall->respondingTo; + } + call->returnValue = 0; +} diff --git a/src/include/hlib.h b/src/include/hlib.h index c57b875..6b27b81 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -46,6 +46,8 @@ extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); extern uint32_t getFunction(uint32_t serviceId, char *functionName); +extern bool stackContains(uint32_t serviceId); + #define MAX(x, y) (x > y ? (x) : (y)) #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index ede83b1..8395e6c 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -15,6 +15,7 @@ SymbolEntry *symbolTable; char *stringTable; uint32_t symbolTableSize; + uint32_t id; } Service; // the name is subject to change diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 1164adc..7b5ee70 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -2,12 +2,12 @@ #include #include -extern void loadProgram(char *name, Syscall *respondingTo, bool initialize); +extern Service *loadProgram(char *name, Syscall *respondingTo, bool initialize); void handleLoadFromInitrdSyscall(Syscall *call) { - call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; - loadProgram(name, (void *)call, call->parameters[1]); + Service *result = loadProgram(name, (void *)call, call->parameters[1]); + call->returnValue = result->id; call->avoidReschedule = call->parameters[1]; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index f227df2..14d0d98 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -34,6 +34,7 @@ service->pagingInfo.pageDirectory = malloc(0x1000); service->name = serviceName; service->nameHash = insertString(serviceName); + service->id = listCount(services); fireEvent(loadInitrdEvent, service->nameHash); void *current = &functionsStart; if (hlib) { diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index fd5db70..288819d 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -18,15 +18,7 @@ } void handleGetServiceIdSyscall(Syscall *call) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == call->service) { - call->returnValue = i; - return; - } - i++; - }) - ; + call->returnValue = ((Service *)call->service)->id; } void handleGetServiceSyscall(Syscall *call) { @@ -84,7 +76,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash, getServiceId(service)); + service->nameHash, service->id); call->avoidReschedule = true; } @@ -102,3 +94,15 @@ } } } + +void handleStackContainsSyscall(Syscall *call) { + Syscall *currentCall = call; + while (currentCall) { + if (((Service *)currentCall->service)->id == call->parameters[0]) { + call->returnValue = 1; + return; + } + currentCall = currentCall->respondingTo; + } + call->returnValue = 0; +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index ca5779e..5133cde 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -69,6 +69,7 @@ handleReadStringSyscall, handleDiscardStringSyscall; extern uintptr_t handleRequestMemorySyscall; extern uintptr_t handleLookupSymbolSyscall; +extern uintptr_t handleStackContainsSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -91,6 +92,7 @@ (void *)&handleDiscardStringSyscall, (void *)&handleRequestMemorySyscall, (void *)&handleLookupSymbolSyscall, + (void *)&handleStackContainsSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/include/hlib.h b/src/include/hlib.h index c57b875..6b27b81 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -46,6 +46,8 @@ extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); extern uint32_t getFunction(uint32_t serviceId, char *functionName); +extern bool stackContains(uint32_t serviceId); + #define MAX(x, y) (x > y ? (x) : (y)) #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index ede83b1..8395e6c 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -15,6 +15,7 @@ SymbolEntry *symbolTable; char *stringTable; uint32_t symbolTableSize; + uint32_t id; } Service; // the name is subject to change diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 1164adc..7b5ee70 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -2,12 +2,12 @@ #include #include -extern void loadProgram(char *name, Syscall *respondingTo, bool initialize); +extern Service *loadProgram(char *name, Syscall *respondingTo, bool initialize); void handleLoadFromInitrdSyscall(Syscall *call) { - call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; - loadProgram(name, (void *)call, call->parameters[1]); + Service *result = loadProgram(name, (void *)call, call->parameters[1]); + call->returnValue = result->id; call->avoidReschedule = call->parameters[1]; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index f227df2..14d0d98 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -34,6 +34,7 @@ service->pagingInfo.pageDirectory = malloc(0x1000); service->name = serviceName; service->nameHash = insertString(serviceName); + service->id = listCount(services); fireEvent(loadInitrdEvent, service->nameHash); void *current = &functionsStart; if (hlib) { diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index fd5db70..288819d 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -18,15 +18,7 @@ } void handleGetServiceIdSyscall(Syscall *call) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == call->service) { - call->returnValue = i; - return; - } - i++; - }) - ; + call->returnValue = ((Service *)call->service)->id; } void handleGetServiceSyscall(Syscall *call) { @@ -84,7 +76,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash, getServiceId(service)); + service->nameHash, service->id); call->avoidReschedule = true; } @@ -102,3 +94,15 @@ } } } + +void handleStackContainsSyscall(Syscall *call) { + Syscall *currentCall = call; + while (currentCall) { + if (((Service *)currentCall->service)->id == call->parameters[0]) { + call->returnValue = 1; + return; + } + currentCall = currentCall->respondingTo; + } + call->returnValue = 0; +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index ca5779e..5133cde 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -69,6 +69,7 @@ handleReadStringSyscall, handleDiscardStringSyscall; extern uintptr_t handleRequestMemorySyscall; extern uintptr_t handleLookupSymbolSyscall; +extern uintptr_t handleStackContainsSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -91,6 +92,7 @@ (void *)&handleDiscardStringSyscall, (void *)&handleRequestMemorySyscall, (void *)&handleLookupSymbolSyscall, + (void *)&handleStackContainsSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 3410b46..9d72a54 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -25,6 +25,7 @@ SYS_DISCARD_STRING = 17, SYS_REQUEST_MEMORY = 18, SYS_LOOKUP_SYMBOL = 19, + SYS_STACK_CONTAINS = 20, } SyscallIds; extern uint32_t getFunction(uint32_t module, char *name); diff --git a/src/include/hlib.h b/src/include/hlib.h index c57b875..6b27b81 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -46,6 +46,8 @@ extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); extern uint32_t getFunction(uint32_t serviceId, char *functionName); +extern bool stackContains(uint32_t serviceId); + #define MAX(x, y) (x > y ? (x) : (y)) #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index ede83b1..8395e6c 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -15,6 +15,7 @@ SymbolEntry *symbolTable; char *stringTable; uint32_t symbolTableSize; + uint32_t id; } Service; // the name is subject to change diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 1164adc..7b5ee70 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -2,12 +2,12 @@ #include #include -extern void loadProgram(char *name, Syscall *respondingTo, bool initialize); +extern Service *loadProgram(char *name, Syscall *respondingTo, bool initialize); void handleLoadFromInitrdSyscall(Syscall *call) { - call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; - loadProgram(name, (void *)call, call->parameters[1]); + Service *result = loadProgram(name, (void *)call, call->parameters[1]); + call->returnValue = result->id; call->avoidReschedule = call->parameters[1]; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index f227df2..14d0d98 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -34,6 +34,7 @@ service->pagingInfo.pageDirectory = malloc(0x1000); service->name = serviceName; service->nameHash = insertString(serviceName); + service->id = listCount(services); fireEvent(loadInitrdEvent, service->nameHash); void *current = &functionsStart; if (hlib) { diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index fd5db70..288819d 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -18,15 +18,7 @@ } void handleGetServiceIdSyscall(Syscall *call) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == call->service) { - call->returnValue = i; - return; - } - i++; - }) - ; + call->returnValue = ((Service *)call->service)->id; } void handleGetServiceSyscall(Syscall *call) { @@ -84,7 +76,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash, getServiceId(service)); + service->nameHash, service->id); call->avoidReschedule = true; } @@ -102,3 +94,15 @@ } } } + +void handleStackContainsSyscall(Syscall *call) { + Syscall *currentCall = call; + while (currentCall) { + if (((Service *)currentCall->service)->id == call->parameters[0]) { + call->returnValue = 1; + return; + } + currentCall = currentCall->respondingTo; + } + call->returnValue = 0; +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index ca5779e..5133cde 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -69,6 +69,7 @@ handleReadStringSyscall, handleDiscardStringSyscall; extern uintptr_t handleRequestMemorySyscall; extern uintptr_t handleLookupSymbolSyscall; +extern uintptr_t handleStackContainsSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -91,6 +92,7 @@ (void *)&handleDiscardStringSyscall, (void *)&handleRequestMemorySyscall, (void *)&handleLookupSymbolSyscall, + (void *)&handleStackContainsSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 3410b46..9d72a54 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -25,6 +25,7 @@ SYS_DISCARD_STRING = 17, SYS_REQUEST_MEMORY = 18, SYS_LOOKUP_SYMBOL = 19, + SYS_STACK_CONTAINS = 20, } SyscallIds; extern uint32_t getFunction(uint32_t module, char *name); diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 0f558b1..e30d166 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -58,3 +58,7 @@ target++; } } + +bool stackContains(uint32_t serviceId) { + return syscall(SYS_STACK_CONTAINS, serviceId, 0, 0, 0); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index c57b875..6b27b81 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -46,6 +46,8 @@ extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); extern uint32_t getFunction(uint32_t serviceId, char *functionName); +extern bool stackContains(uint32_t serviceId); + #define MAX(x, y) (x > y ? (x) : (y)) #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index ede83b1..8395e6c 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -15,6 +15,7 @@ SymbolEntry *symbolTable; char *stringTable; uint32_t symbolTableSize; + uint32_t id; } Service; // the name is subject to change diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 1164adc..7b5ee70 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -2,12 +2,12 @@ #include #include -extern void loadProgram(char *name, Syscall *respondingTo, bool initialize); +extern Service *loadProgram(char *name, Syscall *respondingTo, bool initialize); void handleLoadFromInitrdSyscall(Syscall *call) { - call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; - loadProgram(name, (void *)call, call->parameters[1]); + Service *result = loadProgram(name, (void *)call, call->parameters[1]); + call->returnValue = result->id; call->avoidReschedule = call->parameters[1]; } diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index f227df2..14d0d98 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -34,6 +34,7 @@ service->pagingInfo.pageDirectory = malloc(0x1000); service->name = serviceName; service->nameHash = insertString(serviceName); + service->id = listCount(services); fireEvent(loadInitrdEvent, service->nameHash); void *current = &functionsStart; if (hlib) { diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index fd5db70..288819d 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -18,15 +18,7 @@ } void handleGetServiceIdSyscall(Syscall *call) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == call->service) { - call->returnValue = i; - return; - } - i++; - }) - ; + call->returnValue = ((Service *)call->service)->id; } void handleGetServiceSyscall(Syscall *call) { @@ -84,7 +76,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash, getServiceId(service)); + service->nameHash, service->id); call->avoidReschedule = true; } @@ -102,3 +94,15 @@ } } } + +void handleStackContainsSyscall(Syscall *call) { + Syscall *currentCall = call; + while (currentCall) { + if (((Service *)currentCall->service)->id == call->parameters[0]) { + call->returnValue = 1; + return; + } + currentCall = currentCall->respondingTo; + } + call->returnValue = 0; +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index ca5779e..5133cde 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -69,6 +69,7 @@ handleReadStringSyscall, handleDiscardStringSyscall; extern uintptr_t handleRequestMemorySyscall; extern uintptr_t handleLookupSymbolSyscall; +extern uintptr_t handleStackContainsSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -91,6 +92,7 @@ (void *)&handleDiscardStringSyscall, (void *)&handleRequestMemorySyscall, (void *)&handleLookupSymbolSyscall, + (void *)&handleStackContainsSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 3410b46..9d72a54 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -25,6 +25,7 @@ SYS_DISCARD_STRING = 17, SYS_REQUEST_MEMORY = 18, SYS_LOOKUP_SYMBOL = 19, + SYS_STACK_CONTAINS = 20, } SyscallIds; extern uint32_t getFunction(uint32_t module, char *name); diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 0f558b1..e30d166 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -58,3 +58,7 @@ target++; } } + +bool stackContains(uint32_t serviceId) { + return syscall(SYS_STACK_CONTAINS, serviceId, 0, 0, 0); +} diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 0a13b8e..81f8184 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -17,20 +17,27 @@ } } -void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, - uint32_t callerId) { +void logMain(uint32_t stringId) { while (lock) { syscall(-1, 0, 0, 0, 0); } - if (callerId == focusService) { - lock = true; - readString(stringId, buffer); - for (uint32_t i = 0; buffer[i]; i++) { - request(mainService, mainOut, buffer[i], 0); - } - lock = false; + lock = true; + readString(stringId, buffer); + for (uint32_t i = 0; buffer[i]; i++) { + request(mainService, mainOut, buffer[i], 0); + } + lock = false; +} + +void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, + uint32_t callerId) { + if (stackContains(focusService)) { + logMain(stringId); return; } + while (lock) { + syscall(-1, 0, 0, 0, 0); + } lock = true; writeString("[ "); readString(caller, buffer);