how to make gcc work with segmentation
Posted: Sun May 16, 2010 9:31 am
hi
i have the following problem
my toy os uses segmentation in the sense that the base address of a segment not necessarily starts at 0
rather, the executable code of each process starts at offset 0 within the bounds of the code segment of that process, get my point?
so, i have done quite a bit in assembly so far, but im tired of it because its just to error prone and slow, so i want to switch over to C
and now im having a big big problem:
whenever my c code calls something like this:
someFunction(&someVariable); //some variable being a local variable
then the compiler does something like this:
lea someVariable, eax
push eax
call someFunction
the problem with this is that someFunction gets as a parameter the linear address of someVariable, whereas what it needs to make sense of the address is the offset relative to its own data segment...
if someFunction is written in assembly then i can of course subtract the base address of the data segment from the address provided and then use it as an offset but what if someFunction is written in C?
do i have a chance at all here??
thanks
martin
i have the following problem
my toy os uses segmentation in the sense that the base address of a segment not necessarily starts at 0
rather, the executable code of each process starts at offset 0 within the bounds of the code segment of that process, get my point?
so, i have done quite a bit in assembly so far, but im tired of it because its just to error prone and slow, so i want to switch over to C
and now im having a big big problem:
whenever my c code calls something like this:
someFunction(&someVariable); //some variable being a local variable
then the compiler does something like this:
lea someVariable, eax
push eax
call someFunction
the problem with this is that someFunction gets as a parameter the linear address of someVariable, whereas what it needs to make sense of the address is the offset relative to its own data segment...
if someFunction is written in assembly then i can of course subtract the base address of the data segment from the address provided and then use it as an offset but what if someFunction is written in C?
do i have a chance at all here??
thanks
martin