Pelle,
Bill says:
The naked attribute affects only the nature of the compilers code generation for the functions prolog and epilog sequences. It does not affect the code that is generated for calling such functions. Thus, the naked attribute is not considered part of the functions type, and function pointers cannot have the naked attribute. Furthermore, the naked attribute cannot be applied to a data definition.
(Link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/_clang_naked_functions.asp)
As far I can understand we don't have to worry about parameters and local variables handling, just produce code as per the specific function definition, the duty of placing the values at the right place is a programmer problem. It's coder responsability, in the custom epilog code, to move the function parameters to the right registers, if __fastcall convention declared, or on the stack, if _cdecl or __stdcall. Also the cleaning duty upon function exit is programmer responsability, He/she have to clean around and make code consistent.
As I have already told to me this is a very unsafe option, where the user knows that the compiler control is limited and that any problem remains to user charge.
The compiler could check just some basic errors, as you have already done, all the rest is programmer responsability (to cross-check with assembler generated code and similiar low level tracing).
Moreover in the documentation you will see that is uncorrect to put the naked attribute in the function prototype, meaning that when you declare a naked functions you can choose how the "C" code will handle the parameters, the other points: register and context saving, stack consistency, cleaning and so on are programmer responsability.
The programmer when declare a naked function knows what the generated "C" code will expect for parameters and variables handling, and MUST insert code for this requirements. The reverse is not true: the code generator CANNOT know from where, and in which ways, parameters, stack and context will be organized, so simply don't care about.
As an example immagine following function as an exception handler:
[code__declspec(naked) void __fastcall PageFault(DWORD address, DWORD code)
{
/*
USER PROLOGUE
*/
__asm pusha
__asm push ebp;
__asm mov ebp,esp;
__asm sub esp,8
__asm mov ecx,cr2 //page fault address
__asm mov edx,[ebp+ERROR_CODE]
/*
USER CODE
*/
switch (code)
{
case 0:
...............
break;
case 1:
...............
break;
...................
...................
default:
...............
break;
}
/*
USER EPILOGUE
*/
__asm mov esp,ebp
__asm pop ebp
__asm popa
__asm add esp,+4 //Skip error code
__asm iret
}
[/code]
It is surely not correct becouse I wrote it on the fly but should give you the sense.
Thank-you
F.