Page 1 of 1

Argument passing

Posted: Mon Aug 29, 2022 3:02 pm
by WinExperements
Hello, guys!

I have problem with passing arguments to user mode process. If i do this:

Code: Select all

int *stack = (int *)fr->usersp+4;
All works fine, but if i try to add something to the allocated stack, the stack are brokes:

Code: Select all

frame->usersp = (isUser ? ((int)pmml_alloc(true)+4096) : 0);
The first poping from stack are zero, i use this code for checking valid of stack:

Code: Select all

pop eax
    ; Check if argument exists
    cmp eax,0
    je .exit
And program always jumps to exit label, this means that after the poping from stack done, the register eax are zero.
What i am doing wrong?

Re: Argument passing

Posted: Mon Aug 29, 2022 3:38 pm
by Octocontrabass
Where is your code to add something to the allocated stack?

Re: Argument passing

Posted: Mon Aug 29, 2022 3:43 pm
by WinExperements
Octocontrabass wrote:Where is your code to add something to the allocated stack?
Here is:

Code: Select all

*(--stack) = (int)argv;

Re: Argument passing

Posted: Mon Aug 29, 2022 3:58 pm
by Octocontrabass
That looks fine.

After you add that value to the user stack, do you put the user stack pointer back into the stack frame?

Re: Argument passing

Posted: Mon Aug 29, 2022 4:03 pm
by WinExperements
Octocontrabass wrote:That looks fine.

After you add that value to the user stack, do you put the user stack pointer back into the stack frame?
Ah, yeah i don't update the pointer of stack. Thank now all works fine!