os/kernelhwsrv/kernel/eka/include/win32atx.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32\include\win32atx.h
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @internalComponent
    21 */
    22 
    23 #ifndef __WIN32ATX_H__
    24 #define __WIN32ATX_H__
    25 
    26 #if defined(__VC32__)
    27 
    28 #define	MAX_ATEXIT_HANDLERS	255
    29 
    30 #ifdef __KERNEL_MODE__
    31 #define PANIC()	Kern::Fault("ATEXIT", __LINE__)
    32 #else
    33 _LIT(KLitAtExitPanic,"ATEXIT");
    34 #define PANIC()	User::Panic(KLitAtExitPanic, __LINE__)
    35 #endif
    36 
    37 extern "C" {
    38 typedef void (__cdecl* TAtExit)(void);
    39 static TUint sp=0;
    40 static TAtExit handlers[MAX_ATEXIT_HANDLERS];
    41 
    42 int atexit(TAtExit aFunc)
    43 	{
    44 	if (sp>=MAX_ATEXIT_HANDLERS)
    45 		PANIC();
    46 	handlers[sp++]=aFunc;
    47 	return 0;
    48 	}
    49 
    50 void __call_atexit_handlers()
    51 	{
    52 	while(sp)
    53 		(*handlers[--sp])();
    54 	}
    55 
    56 #pragma data_seg(".CRT$XPU")
    57 TAtExit __xp_a[] = { __call_atexit_handlers };
    58 
    59 }
    60 
    61 #elif defined(__CW32__)
    62 
    63 struct SDestructorEntry
    64 	{
    65 	SDestructorEntry* iNext;
    66 	TAny* iDstrFn;
    67 	TAny* iObj;
    68 	};
    69 
    70 SDestructorEntry* DEListHead;
    71 
    72 extern "C" {
    73 
    74 void* __register_global_object(void* obj, void* dfn, void* entry)
    75 	{
    76 	SDestructorEntry* e = (SDestructorEntry*)entry;
    77 	e->iNext = DEListHead;
    78 	e->iDstrFn = dfn;
    79 	e->iObj = obj;
    80 	DEListHead = e;
    81 	return obj;
    82 	}
    83 
    84 __declspec(naked) void __destroy_global_chain(void)
    85 	{
    86 	_asm push ebp
    87 	_asm mov ebp, esp
    88 	_asm push ebx
    89 	_asm lea ebx, DEListHead
    90 	dgc1:
    91 	_asm mov ebx, [ebx]
    92 	_asm test ebx, ebx
    93 	_asm jz dgc0
    94 	_asm mov ecx, [ebx+8]
    95 	_asm call dword ptr [ebx+4]
    96 	_asm jmp dgc1
    97 	dgc0:
    98 	_asm lea ebx, DEListHead
    99 	_asm mov [ebx], 0
   100 	_asm pop ebx
   101 	_asm mov esp, ebp
   102 	_asm pop ebp
   103 	_asm ret
   104 	}
   105 
   106 #pragma data_seg(".CRT$XPU")
   107 void (*__xp_a[])(void) = { &__destroy_global_chain };
   108 }
   109 
   110 #elif defined(__GCC32__)
   111 // todo: figure out what to do here
   112 #else
   113 #error Unknown X86 compiler
   114 #endif
   115 
   116 #endif