return during "int"

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
GLneo

return during "int"

Post by GLneo »

my system call set up works like this:

Code: Select all

_int_handler_set:
    push eax
    push ebx
    push ecx
    push edx
    mov eax, _int_handler
    call eax
    iret
which gets called after int 30h, which in turn calls:

Code: Select all

void int_handler(volatile unsigned int EDX, volatile unsigned int ECX, 
            volatile unsigned int EBX, volatile unsigned int EAX)
{
    if(EAX == 1)
        free((void *)EBX);
    else if(EAX == 2)
        EAX = (unsigned int)malloc(EBX);
    else if(EAX == 3)
        cls();
    else if(EAX == 4)
        putchar((char)EBX);
    else if(EAX == 5)
        putint(EBX);
    else if(EAX == 6)
        puts((unsigned char *)EBX);
    else if(EAX == 7)
        attr((short)EBX);
}
but i think whats wrong is the functions get called and after they do what they do, they "ret" but because it has been after an "int" it should be a "iret" so the sys goes crazy, help???
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:return during "int"

Post by Brendan »

Hi,
GLneo wrote:but i think whats wrong is the functions get called and after they do what they do, they "ret" but because it has been after an "int" it should be a "iret" so the sys goes crazy, help???
The C functions get "CALLed" from within the assembly stub, and therefore should use a "RET" to return to the assembly stub.

The problem is your assembly stub, which pushes a pile of general registers onto the stack that are never popped off again. Try changing to:

Code: Select all

_int_handler_set:
    pushad
    push eax
    push ebx
    push ecx
    push edx
    call _int_handler
    add esp,16
    popad
    iret

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:return during "int"

Post by Pype.Clicker »

oh, btw, you might want to write free, malloc, etc. into a syscall_table[] and issue

Code: Select all

syscall_table[EAX](EBX,ECX,EDX)
rather than having them in a bunch of "if ... elsif .. elsif ..."
GLneo

Re:return during "int"

Post by GLneo »

thx, brendan, that fixed it! :)

@Pype.Clicker: how would i do that, just have "syscall_table" have an array of pointers to functions?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:return during "int"

Post by Pype.Clicker »

yes, that's roughly the idea ...
Post Reply