Page 1 of 1

Undefined Behaviour when creating new processes

Posted: Mon Sep 03, 2018 2:47 am
by thomtl
Hello,
I am currently in the stage of an OS where a shell is being run, but when spawning new processes via syscalls undefined behaviour happens. When spawning a process loaded from the initrd it tries to access the addresses 0xFFFFFFFF and 0x83042000 and it also interrupted interrupt vector 255 but i have not set that vector. after mapping the previously named addresses to 0x0 it ran, but when i try to run it a second time qemu aborts and bochs has a 3rd exception with no resolution. After trying a lot of different things I cannot figure out why this behaviour happens, so I hope someone is able to help me resolve this.

Source: https://github.com/thomtl/Project-Rhino

The code that spawns the process is in src/kernel/user/init.c void create_process(char* prg) at line 71 the two address workaround lines can be seen at line 84 and 85.

The shell is located at utils/TSH and the process that is being spawned is at utils/UserTest

Documentation for syscalls is at doc/syscalls.txt

To build it Make assumes yasm and i686-elf-gcc are in your PATH and you need to go to utils/TSH and make that then go to utils/UserTest and make that and then you can go back to the root and make that

I'm sorry that I am not able to supply more information about the problem and that my English is not that good.

-thomtl

Re: Undefined Behaviour when creating new processes

Posted: Fri Sep 07, 2018 6:11 am
by thomtl
bump

Re: Undefined Behaviour when creating new processes

Posted: Fri Sep 07, 2018 2:29 pm
by SpyderTL
Unless you happen to know the address of the code you are trying to troubleshoot, you may want to add a "Magic Breakpoint".

https://wiki.osdev.org/Bochs#Magic_Breakpoint

By adding a specific ASM instruction, and enabling magic breakpoints in Bochs, you can get Bochs to break at a specific instruction, and you can walk through the next few instructions one at a time, and see what is happening.

Once you get into multi-threading in your OS, you really need to have a good debugging solution in place. It's quite difficult to proceed without one.

Re: Undefined Behaviour when creating new processes

Posted: Sat Sep 08, 2018 8:34 am
by thomtl
Hello,
I have figured it out, I was allocating to much space for the stack in the process which in turn led to it running out of space and there not being a valid stack.
Thanks SpyderTL your tip about Magic Breakpoints led me to the stack being corrupted. It works perfectly now.
-thomtl