Very new to this. Usercode data gets overwritten with 0s
Posted: Sat Oct 30, 2021 12:01 pm
First of all, I'm sorry if I have made very obvious mistakes. We were given a version of Pure64 that has a lot of the more complex stuff solved. What we have to do is implement some exceptions management, syscalls, and use that to code a very basic shell and some games from the Userspace.
The problem I'm having and I really don't understand why this happens is that, sometimes changing a line of code that has no relation whatsoever with other .c files somehow ends up messing up other binary code. Another thing I noticed is that a lot of the times, static variables that are intialized to zero for some reason have a completely different value when I run the code with gdb.
From what I understand, the first step that happens when running the os is that the Userspace code gets copied to address 0x400000, so I don't get why modifying something in kernel code could affect it.
Example 1:
When I initialize some variables from 'naiveConsole.c' with a zero:
And I try to see its value when I call a naiveConsole function from 'initializeKernelBinary' I get this:
So, it isn't that I am messing up something from the code on the Userspace (I think) since it hasn't even had the chance to run yet.
Example 2:
If I make an objdump of the Userspace code, and compare it to what gdb shows, in some functions the binary code is exactly the same, but in others, the content changes depending on what I write on 'naiveConsole.c':
The debugger shows me this:
the consecutive 'add' instructions make it seem as if some repetitive data is corrupting the code maybe? (actually, the binary code for the instruction is a set of zeros, but I don't know where it comes from). The screen is supposed to start from address 0xB8000 so unless I'm messing something up with the prints, it shouldn't be happening
In reality it should be this:
My professors could grade this as a pass, but I am probably going to keep working on this after, and I feel like the fact that it is *kind of* working is pure luck. If someone could give me an idea on where I could get more informed to understand what is wrong with it I would greatly appreciate it.
This is the Repo: https://github.com/Khato1319/naiveOS
The problem I'm having and I really don't understand why this happens is that, sometimes changing a line of code that has no relation whatsoever with other .c files somehow ends up messing up other binary code. Another thing I noticed is that a lot of the times, static variables that are intialized to zero for some reason have a completely different value when I run the code with gdb.
From what I understand, the first step that happens when running the os is that the Userspace code gets copied to address 0x400000, so I don't get why modifying something in kernel code could affect it.
Example 1:
When I initialize some variables from 'naiveConsole.c' with a zero:
And I try to see its value when I call a naiveConsole function from 'initializeKernelBinary' I get this:
So, it isn't that I am messing up something from the code on the Userspace (I think) since it hasn't even had the chance to run yet.
Example 2:
If I make an objdump of the Userspace code, and compare it to what gdb shows, in some functions the binary code is exactly the same, but in others, the content changes depending on what I write on 'naiveConsole.c':
The debugger shows me this:
the consecutive 'add' instructions make it seem as if some repetitive data is corrupting the code maybe? (actually, the binary code for the instruction is a set of zeros, but I don't know where it comes from). The screen is supposed to start from address 0xB8000 so unless I'm messing something up with the prints, it shouldn't be happening
In reality it should be this:
My professors could grade this as a pass, but I am probably going to keep working on this after, and I feel like the fact that it is *kind of* working is pure luck. If someone could give me an idea on where I could get more informed to understand what is wrong with it I would greatly appreciate it.
This is the Repo: https://github.com/Khato1319/naiveOS