System calls problem [Closed]

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
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

System calls problem [Closed]

Post by Ycep »

Hi,
I have recently somehow broke my system calls.
The problem is that by some reason, parameters do not pass to requested function properly anymore.

Code: Select all

void Reserved()
{
	puts("This system call is reserved for future, and thus could not be used.\n");
}
void* sfunc[]=
{
	Reserved,Reserved,putc,puts,OpenFile,Reserved,ReadFile,Reserved,Reserved,Reserved,Reserved,Reserved,sleep,getch,Reserved,Reserved,Reserved
};
__declspec(naked) void SystemCallIrq()
{
	static uint16 no;
	_asm mov [no], bx
	if(no>16)_asm iretd
	static void* callsy=sfunc[no];
	_asm
	{
		push edi
		push esi
		push edx
		push ecx
		push ebx
		push eax
		call callsy
		add esp, 24
		iretd
	}
}
Basically, function number is being put in BX register and parameters are being put from register EAX-EDI.
Because this is an interrupt, to not corrupt any previously ran code I return stack by 6 entries.

Anywhooo?
Last edited by Ycep on Tue Dec 06, 2016 1:40 pm, edited 1 time in total.
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: System calls problem

Post by Ch4ozz »

Then open your kernel in a disassembler like IDA to check if the generated code is completely right.
You should code all parts using inline asm and dont switch so much to normal code because the compiler might **** up some stuff.
Also what does "not properly" mean? Does it crash or wrong values?
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: System calls problem

Post by MollenOS »

You should really stop mixing inline assembly with C code in crucial functions like that. Also in a system call it would be beneficial not to push/pop eax so you can support return codes. Write that system call in pure assembly, and don't use static variables in a function that might be called from multiple threads
issamabd
Posts: 8
Joined: Tue Oct 25, 2016 1:57 am
Libera.chat IRC: issamabd
Location: Tunisia
Contact:

Re: System calls problem

Post by issamabd »

Your asm_ instruction doesn't have any "side effects"! The compiler can move it from its place during optimization. It can also delete it! So create some dependencies between it and the C code and use the "volatile" keyword.

How many level of protection your OS uses ? What does the callsy function ?

If you are using more than one level of protection/privilege, during the system call execution the DS,ES,FS,GS registers still point to the old address space!
"try to learn something about everything and everything about something"
My personal website: http://issamabd.com
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: System calls problem [Closed]

Post by Ycep »

Hell ye'eh! I fixed it myself.
Boris
Member
Member
Posts: 145
Joined: Sat Nov 07, 2015 3:12 pm

Re: System calls problem [Closed]

Post by Boris »

Can you describe how ? Nothing more frustrating for people to find your post while trying to resolve a similar problem and find no answers.

Thanks.
Post Reply