Skip to content

Commit

Permalink
Fixed issues with process startup, and a crash, there is still one we…
Browse files Browse the repository at this point in the history
…re memory is overwritten somewhere
  • Loading branch information
Meulengracht committed Oct 29, 2018
1 parent f712fbd commit 2440634
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 40 deletions.
6 changes: 3 additions & 3 deletions kernel/arch/x86/components/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ SetVirtualPageMapping(
if (vAddress < MEMORY_LOCATION_KERNEL_END) {
if (CpuHasFeatures(0, CPUID_FEAT_EDX_PGE) == OsSuccess) {
ConvertedFlags |= PAGE_GLOBAL;
}
}
}

// If table is null creation failed
Expand All @@ -431,8 +431,8 @@ SetVirtualPageMapping(
if (ConvertedFlags & PAGE_PERSISTENT) {
if (Mapping != (pAddress & PAGE_MASK)) {
FATAL(FATAL_SCOPE_KERNEL,
"Tried to remap fixed virtual address 0x%x => 0x%x (Existing 0x%x)",
vAddress, pAddress, Mapping);
"Tried to remap fixed virtual address 0x%x => 0x%x (Existing 0x%x), debug-address 0x%x",
vAddress, pAddress, Mapping, &Table->Pages[PAGE_TABLE_INDEX((vAddress & PAGE_MASK))]);
}
}
Status = OsExists;
Expand Down
10 changes: 4 additions & 6 deletions kernel/arch/x86/components/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ StartApplicationCore(
_In_ SystemCpuCore_t* Core)
{
// Perform the IPI
TRACE(" > Booting core %u", Core->Id);
TRACE(" > booting core %u", Core->Id);
if (ApicPerformIPI(Core->Id, 1) != OsSuccess) {
ERROR("Failed to boot core %u (IPI failed)", Core->Id);
ERROR(" > failed to boot core %u (ipi failed)", Core->Id);
return;
}
// ApicPerformIPI(Core->Id, 0); is needed on older cpus

// Perform the SIPI - some cpu's require two SIPI's
if (ApicPerformSIPI(Core->Id, MEMORY_LOCATION_TRAMPOLINE_CODE) != OsSuccess) {
ERROR("Failed to boot core %u (SIPI failed)", Core->Id);
ERROR(" > failed to boot core %u (sipi failed)", Core->Id);
return;
}

Expand All @@ -92,7 +92,7 @@ StartApplicationCore(
CpuStall(200);
if (Core->State != CpuStateRunning) {
if (ApicPerformSIPI(Core->Id, MEMORY_LOCATION_TRAMPOLINE_CODE) != OsSuccess) {
ERROR("Failed to boot core %u (SIPI failed)", Core->Id);
ERROR(" > failed to boot core %u (sipi failed)", Core->Id);
return;
}
}
Expand All @@ -106,8 +106,6 @@ CpuSmpInitialize(void)
uint32_t *CodePointer = (uint32_t*)((uint8_t*)(&__GlbTramplineCode[0]) + __GlbTramplineCode_length);
uint32_t EntryCode = (uint32_t)(uint32_t*)SmpApplicationCoreEntry;

TRACE("CpuSmpInitialize(%i)", GetMachine()->Processor.NumberOfCores);

*(CodePointer - 1) = EntryCode;
*(CodePointer - 2) = GetCurrentSystemMemorySpace()->Data[MEMORY_SPACE_CR3];
memcpy((void*)MEMORY_LOCATION_TRAMPOLINE_CODE, (char*)__GlbTramplineCode, __GlbTramplineCode_length);
Expand Down
4 changes: 2 additions & 2 deletions kernel/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void*
LookupHandle(
_In_ UUId_t Handle)
{
SystemHandle_t *Instance;
DataKey_t Key;
SystemHandle_t* Instance;
DataKey_t Key;

// Lookup the handle
Key.Value = (int)Handle;
Expand Down
4 changes: 2 additions & 2 deletions kernel/include/revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#define _REVISION_H_

#define BUILD_DATE "29 October 2018"
#define BUILD_TIME "11:22:51"
#define BUILD_TIME "12:52:07"
#define BUILD_SYSTEM "clang"

#define REVISION_MAJOR 0
#define REVISION_MINOR 4
#define REVISION_BUILD 9205
#define REVISION_BUILD 9209

#endif //!_REVISION_H_
51 changes: 30 additions & 21 deletions kernel/process/phoenix.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,19 @@
#include <handle.h>
#include <assert.h>
#include <debug.h>
#include <heap.h>

OsStatus_t PhoenixFileHandler(void *UserData);

struct ServiceDescriptor {
CollectionItem_t ListHeader;
UUId_t ProcessHandle;
DevInfo_t VendorId;
DevInfo_t DeviceId;
DevInfo_t DeviceClass;
DevInfo_t DeviceSubClass;
};

static Collection_t Services = COLLECTION_INIT(KeyInteger);
static UUId_t AliasMap[PHOENIX_MAX_ALIASES] = { 0 };
static UUId_t GcFileHandleId = 0;
Expand Down Expand Up @@ -118,19 +128,19 @@ CreateService(
_In_ DevInfo_t DeviceClass,
_In_ DevInfo_t DeviceSubClass)
{
DevInfo_t ServiceInfo[4] = {
VendorId, DeviceId, DeviceClass, DeviceSubClass
};
ProcessStartupInformation_t Info = {
(const char*)&ServiceInfo[0], sizeof(ServiceInfo), 0
};

UUId_t Handle;
OsStatus_t Status = CreateProcess(Path, &Info, ProcessService, &Handle);
ProcessStartupInformation_t Info = { 0 };
struct ServiceDescriptor* Descriptor;
UUId_t Handle;
OsStatus_t Status = CreateProcess(Path, &Info, ProcessService, &Handle);
if (Status == OsSuccess) {
DataKey_t Value;
Value.Value = Handle;
CollectionAppend(&Services, CollectionCreateNode(Value, LookupHandle(Handle)));
Descriptor = (struct ServiceDescriptor*)kmalloc(sizeof(struct ServiceDescriptor));
memset(Descriptor, 0, sizeof(struct ServiceDescriptor));
Descriptor->ProcessHandle = Handle;
Descriptor->VendorId = VendorId;
Descriptor->DeviceId = DeviceId;
Descriptor->DeviceClass = DeviceClass;
Descriptor->DeviceSubClass = DeviceSubClass;
CollectionAppend(&Services, &Descriptor->ListHeader);
}
return Status;
}
Expand All @@ -146,22 +156,21 @@ GetServiceByIdentification(
_Out_ UUId_t* ServiceHandle)
{
foreach(Node, &Services) {
SystemProcess_t* Service = (SystemProcess_t*)Node->Data;
DevInfo_t* ServiceInfo = (DevInfo_t*)Service->StartupInformation.ArgumentPointer;
struct ServiceDescriptor* Descriptor = (struct ServiceDescriptor*)Node;

// Should we check vendor-id && device-id?
if (VendorId != 0 && DeviceId != 0) {
if (ServiceInfo[0] == VendorId && ServiceInfo[1] == DeviceId) {
*ServiceHandle = (UUId_t)Node->Key.Value;
return Service;
if (Descriptor->VendorId == VendorId && Descriptor->DeviceId == DeviceId) {
*ServiceHandle = Descriptor->ProcessHandle;
return LookupHandle(Descriptor->ProcessHandle);
}
}

// Skip all fixed-vendor ids
if (ServiceInfo[0] != 0xFFEF) {
if (ServiceInfo[2] == DeviceClass && ServiceInfo[3] == DeviceSubClass) {
*ServiceHandle = (UUId_t)Node->Key.Value;
return Service;
if (Descriptor->VendorId != 0xFFEF) {
if (Descriptor->DeviceClass == DeviceClass && Descriptor->DeviceSubClass == DeviceSubClass) {
*ServiceHandle = Descriptor->ProcessHandle;
return LookupHandle(Descriptor->ProcessHandle);
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions kernel/process/phoenix_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* file events and creating/destroying processes.
*/
#define __MODULE "PROC"
#define __TRACE
//#define __TRACE

#include <modules/modules.h>
#include <process/phoenix.h>
Expand Down Expand Up @@ -58,11 +58,13 @@ ProcessThreadEntry(
MCoreThread_t* Thread = ThreadingGetCurrentThread(CurrentCpu);
uintptr_t BaseAddress;

assert(Package != NULL);
assert(Process != NULL);
assert(Thread != NULL);

// Argument when calling a new process is just NULL
Thread->ParentThreadId = UUID_INVALID;
Thread->ProcessHandle = Package->ProcessHandle;
Thread->Function = (ThreadEntry_t)Process->Executable->EntryAddress;
Thread->Arguments = NULL;

// Update currently running thread, by nulling parent we mark
// it as a standalone thread, which make sure it's not a part of a killable chain
Expand All @@ -78,6 +80,11 @@ ProcessThreadEntry(
Package->FileBufferLength, &BaseAddress, Package->LoadedFromInitRD);
Process->NextLoadingAddress = BaseAddress;

// Update entry functions
assert(Process->Executable != NULL);
Thread->Function = (ThreadEntry_t)Process->Executable->EntryAddress;
Thread->Arguments = NULL;

if (!Package->LoadedFromInitRD) {
kfree(Package->FileBuffer);
}
Expand Down Expand Up @@ -128,7 +135,6 @@ HandleProcessStartupInformation(

// Handle the inheritance block
if (StartupInformation->InheritanceBlockPointer != NULL && StartupInformation->InheritanceBlockLength != 0) {
// Create a kernel space copy
void *InheritanceBlock = kmalloc(StartupInformation->InheritanceBlockLength);
memcpy(InheritanceBlock, StartupInformation->InheritanceBlockPointer, StartupInformation->InheritanceBlockLength);
StartupInformation->InheritanceBlockPointer = InheritanceBlock;
Expand Down
4 changes: 2 additions & 2 deletions revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#define _REVISION_H_

#define BUILD_DATE "29 October 2018"
#define BUILD_TIME "11:22:51"
#define BUILD_TIME "12:52:07"
#define BUILD_SYSTEM "clang"

#define REVISION_MAJOR 0
#define REVISION_MINOR 4
#define REVISION_BUILD 9205
#define REVISION_BUILD 9209

#endif //!_REVISION_H_

0 comments on commit 2440634

Please sign in to comment.