sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\include\win32atx.h sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: sl@0: #ifndef __WIN32ATX_H__ sl@0: #define __WIN32ATX_H__ sl@0: sl@0: #if defined(__VC32__) sl@0: sl@0: #define MAX_ATEXIT_HANDLERS 255 sl@0: sl@0: #ifdef __KERNEL_MODE__ sl@0: #define PANIC() Kern::Fault("ATEXIT", __LINE__) sl@0: #else sl@0: _LIT(KLitAtExitPanic,"ATEXIT"); sl@0: #define PANIC() User::Panic(KLitAtExitPanic, __LINE__) sl@0: #endif sl@0: sl@0: extern "C" { sl@0: typedef void (__cdecl* TAtExit)(void); sl@0: static TUint sp=0; sl@0: static TAtExit handlers[MAX_ATEXIT_HANDLERS]; sl@0: sl@0: int atexit(TAtExit aFunc) sl@0: { sl@0: if (sp>=MAX_ATEXIT_HANDLERS) sl@0: PANIC(); sl@0: handlers[sp++]=aFunc; sl@0: return 0; sl@0: } sl@0: sl@0: void __call_atexit_handlers() sl@0: { sl@0: while(sp) sl@0: (*handlers[--sp])(); sl@0: } sl@0: sl@0: #pragma data_seg(".CRT$XPU") sl@0: TAtExit __xp_a[] = { __call_atexit_handlers }; sl@0: sl@0: } sl@0: sl@0: #elif defined(__CW32__) sl@0: sl@0: struct SDestructorEntry sl@0: { sl@0: SDestructorEntry* iNext; sl@0: TAny* iDstrFn; sl@0: TAny* iObj; sl@0: }; sl@0: sl@0: SDestructorEntry* DEListHead; sl@0: sl@0: extern "C" { sl@0: sl@0: void* __register_global_object(void* obj, void* dfn, void* entry) sl@0: { sl@0: SDestructorEntry* e = (SDestructorEntry*)entry; sl@0: e->iNext = DEListHead; sl@0: e->iDstrFn = dfn; sl@0: e->iObj = obj; sl@0: DEListHead = e; sl@0: return obj; sl@0: } sl@0: sl@0: __declspec(naked) void __destroy_global_chain(void) sl@0: { sl@0: _asm push ebp sl@0: _asm mov ebp, esp sl@0: _asm push ebx sl@0: _asm lea ebx, DEListHead sl@0: dgc1: sl@0: _asm mov ebx, [ebx] sl@0: _asm test ebx, ebx sl@0: _asm jz dgc0 sl@0: _asm mov ecx, [ebx+8] sl@0: _asm call dword ptr [ebx+4] sl@0: _asm jmp dgc1 sl@0: dgc0: sl@0: _asm lea ebx, DEListHead sl@0: _asm mov [ebx], 0 sl@0: _asm pop ebx sl@0: _asm mov esp, ebp sl@0: _asm pop ebp sl@0: _asm ret sl@0: } sl@0: sl@0: #pragma data_seg(".CRT$XPU") sl@0: void (*__xp_a[])(void) = { &__destroy_global_chain }; sl@0: } sl@0: sl@0: #elif defined(__GCC32__) sl@0: // todo: figure out what to do here sl@0: #else sl@0: #error Unknown X86 compiler sl@0: #endif sl@0: sl@0: #endif