Page 1 of 1

Fast system calls with SYSENTER and SYSEXIT

Posted: Sun Jan 27, 2008 3:04 pm
by XCHG
Has anybody made fast system calls with SYSENTER and SYSEXIT from DPL0 to DPL0? Is this possible? If not, what is the fastest way of making system calls from DPL0 to DPL0.

Posted: Sun Jan 27, 2008 3:48 pm
by Combuster
If you're doing kernel->kernel calls (which is what you say), just use normal function calls, no?

sysenter/syscall are for ring 3 <-> ring 0 exclusively.

Posted: Sun Jan 27, 2008 11:09 pm
by bewing
Yeah, your kernel (or whatever) needs to export its entrypoints -- usually by writing them to a table at a known memory location. Then you call the entrypoint from the other ring0 app.

Code: Select all

free		equ	0x20000c

	call [free]

Posted: Mon Jan 28, 2008 8:43 am
by Ready4Dis
Yeah, as said above, it's just a regular function call since it's in the same ring. My drivers and kernel reside in the same ring, and I link my drivers to the kernel when they are loaded to link symbolic information (I use coff files, but a.out, elf, pe are other commonly used variants), or as stated, use a known location to generate a table (my old way I did it). Basically, set aside a block of memory to hold function pointers... so, for example... a viod SayHi(char *Say); function :).

You reserve a known address space (we'll even forget about paging right now since it's outside the scope of this discussion), lets say we want our function table to be at 0x1000, or the first 4k page boundary. Would would simply do this in the kernel:

Code: Select all

u32 *FuncTable = 0x1000;

void SayHi(char *Say)
{
 kprintf("SayHi: %s\n",Say); //Print the string passed for testing
}

void SetFuncPointer(void *Func, unsigned long FunctionNumber)
{
  FuncTable[FunctionNumber] = (u32)Func;
}

void InitFuncs(void)
{
 SetFuncPointer(SayHi,0); //first function
}
now for your driver/application to find the function for SayHi, it knows that it is function 0... so..

Code: Select all

u32 FuncTable = (u32*)0x1000;

void *GetFuncPointer(u32 FunctionNumber)
{
 return (void*)FuncTable[FunctionNumber];
}

void (*SayHi)(char *Say);
void InitKernelFuncs(void)
{
 SayHi = (void(*)(char*))GetFuncPointer(0);
}
So, now your application knows that the location of the function SayHi is the first entry in the table @ 0x1000, so it can call it without any extra information once the function pointer is set at the correct place. I typed it all in this window, so maybe a casting error or similar, but it should give you the idea on what's going on.