Undefined Behaviour when creating new processes

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Undefined Behaviour when creating new processes

Post 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
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: Undefined Behaviour when creating new processes

Post by thomtl »

bump
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Undefined Behaviour when creating new processes

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: Undefined Behaviour when creating new processes

Post 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
Post Reply