Problem with method call that has a parameter
Posted: Sun Dec 28, 2014 10:04 am
Hi,
I have a problem with my code when calling a specific method of a class.
Basically this happens when creating a new process, here is the function.
Okay, the process initialization goes well and exists to the main program.
The problem occurs in the else section when the scheduler fires the child process. Basically, when I hit the first function call specifically as below it fires a page fault.
At the beginning I could not identify the cause of the problem (and still don't), but after trying different things I realized that the problem occur when I call this method with a parameter.
So I added another method. Below are the two methods in CoreManager that I use alternatively
So they basically do the same thing, which is calling a method in another object stored in an array based on the core_id of the processor running this peice of code.
When I call the first method (The one with the parameters) I get the page fault, while if I use the second one, it goes through. I also tried and emptied the first method (The one with the parameters) completely to make it return NULL as below and still the problem exists at the call.
I suspect that it has to do with the stack or rbp ?? I use a clean stack before jumping to the code location of the child, and set the rsp and rbp to the start of the stack (the higher base address). the child never returns as it hits an infinite loop so I don't need to copy the parent stack content (May be I will need in the future) but I don't think that I have reached a point where this could be the problem.
Here is the output of objdump of the faulty part:
Thanks,
Karim.
I have a problem with my code when calling a specific method of a class.
Basically this happens when creating a new process, here is the function.
Code: Select all
int create_process (routine _startRoutine)
{
asm volatile("cli");
uint64_t _rip = read_rip();
// The child come back later here, and jumps to the else section
uint8_t core_id = Utils::getAPICId();
if ( coreManager->getCurrentKernelPageManager(core_id)->getParentKernelPageManager() == NULL)
{
// Process initialization
asm volatile("sti");
return 0 ;
}
else
{
routine _threadRoutine = coreManager->getCurrentKernelPageManager(core_id)->getStartRoutine();
// When I use routine _threadRoutine = coreManager->getCurrentKernelPageManager()->getStartRoutine() everything works fine.
_threadRoutine();
return 100;
}
}
The problem occurs in the else section when the scheduler fires the child process. Basically, when I hit the first function call specifically as below it fires a page fault.
Code: Select all
routine _threadRoutine = coreManager->getCurrentKernelPageManager(core_id)->getStartRoutine();
So I added another method. Below are the two methods in CoreManager that I use alternatively
Code: Select all
KernelPageManager * CoreManager::getCurrentKernelPageManager (uint16_t core_id)
{
if ( core_id < core_count)
return cores[core_id]->getCurrentKernelPageManager();
return NULL;
}
KernelPageManager * CoreManager::getCurrentKernelPageManager ()
{
uint16_t core_id = Utils::getAPICId();
if ( core_id < core_count)
return cores[core_id]->getCurrentKernelPageManager();
return NULL;
}
So they basically do the same thing, which is calling a method in another object stored in an array based on the core_id of the processor running this peice of code.
When I call the first method (The one with the parameters) I get the page fault, while if I use the second one, it goes through. I also tried and emptied the first method (The one with the parameters) completely to make it return NULL as below and still the problem exists at the call.
Code: Select all
KernelPageManager * CoreManager::getCurrentKernelPageManager (uint16_t core_id)
{
return NULL;
}
I suspect that it has to do with the stack or rbp ?? I use a clean stack before jumping to the code location of the child, and set the rsp and rbp to the start of the stack (the higher base address). the child never returns as it hits an infinite loop so I don't need to copy the parent stack content (May be I will need in the future) but I don't think that I have reached a point where this could be the problem.
Here is the output of objdump of the faulty part:
Code: Select all
}
else
{
routine _threadRoutine = coreManager->getCurrentKernelPageManager(core_id)->getStartRoutine();
17c9b: 89 de mov %ebx,%esi
17c9d: 48 b8 20 20 02 00 00 movabs $0x22020,%rax
17ca4: 00 00 00
17ca7: 48 8b 38 mov (%rax),%rdi
17caa: ff d5 callq *%rbp
17cac: 48 89 c7 mov %rax,%rdi
17caf: 48 b8 90 37 01 00 00 movabs $0x13790,%rax
17cb6: 00 00 00
17cb9: ff d0 callq *%rax
_threadRoutine();
17cbb: ff d0 callq *%rax
return 100;
17cbd: b8 64 00 00 00 mov $0x64,%eax
}
}
Thanks,
Karim.