os/kernelhwsrv/kernel/eka/include/win32atx.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/include/win32atx.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,116 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\include\win32atx.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @internalComponent
    1.24 +*/
    1.25 +
    1.26 +#ifndef __WIN32ATX_H__
    1.27 +#define __WIN32ATX_H__
    1.28 +
    1.29 +#if defined(__VC32__)
    1.30 +
    1.31 +#define	MAX_ATEXIT_HANDLERS	255
    1.32 +
    1.33 +#ifdef __KERNEL_MODE__
    1.34 +#define PANIC()	Kern::Fault("ATEXIT", __LINE__)
    1.35 +#else
    1.36 +_LIT(KLitAtExitPanic,"ATEXIT");
    1.37 +#define PANIC()	User::Panic(KLitAtExitPanic, __LINE__)
    1.38 +#endif
    1.39 +
    1.40 +extern "C" {
    1.41 +typedef void (__cdecl* TAtExit)(void);
    1.42 +static TUint sp=0;
    1.43 +static TAtExit handlers[MAX_ATEXIT_HANDLERS];
    1.44 +
    1.45 +int atexit(TAtExit aFunc)
    1.46 +	{
    1.47 +	if (sp>=MAX_ATEXIT_HANDLERS)
    1.48 +		PANIC();
    1.49 +	handlers[sp++]=aFunc;
    1.50 +	return 0;
    1.51 +	}
    1.52 +
    1.53 +void __call_atexit_handlers()
    1.54 +	{
    1.55 +	while(sp)
    1.56 +		(*handlers[--sp])();
    1.57 +	}
    1.58 +
    1.59 +#pragma data_seg(".CRT$XPU")
    1.60 +TAtExit __xp_a[] = { __call_atexit_handlers };
    1.61 +
    1.62 +}
    1.63 +
    1.64 +#elif defined(__CW32__)
    1.65 +
    1.66 +struct SDestructorEntry
    1.67 +	{
    1.68 +	SDestructorEntry* iNext;
    1.69 +	TAny* iDstrFn;
    1.70 +	TAny* iObj;
    1.71 +	};
    1.72 +
    1.73 +SDestructorEntry* DEListHead;
    1.74 +
    1.75 +extern "C" {
    1.76 +
    1.77 +void* __register_global_object(void* obj, void* dfn, void* entry)
    1.78 +	{
    1.79 +	SDestructorEntry* e = (SDestructorEntry*)entry;
    1.80 +	e->iNext = DEListHead;
    1.81 +	e->iDstrFn = dfn;
    1.82 +	e->iObj = obj;
    1.83 +	DEListHead = e;
    1.84 +	return obj;
    1.85 +	}
    1.86 +
    1.87 +__declspec(naked) void __destroy_global_chain(void)
    1.88 +	{
    1.89 +	_asm push ebp
    1.90 +	_asm mov ebp, esp
    1.91 +	_asm push ebx
    1.92 +	_asm lea ebx, DEListHead
    1.93 +	dgc1:
    1.94 +	_asm mov ebx, [ebx]
    1.95 +	_asm test ebx, ebx
    1.96 +	_asm jz dgc0
    1.97 +	_asm mov ecx, [ebx+8]
    1.98 +	_asm call dword ptr [ebx+4]
    1.99 +	_asm jmp dgc1
   1.100 +	dgc0:
   1.101 +	_asm lea ebx, DEListHead
   1.102 +	_asm mov [ebx], 0
   1.103 +	_asm pop ebx
   1.104 +	_asm mov esp, ebp
   1.105 +	_asm pop ebp
   1.106 +	_asm ret
   1.107 +	}
   1.108 +
   1.109 +#pragma data_seg(".CRT$XPU")
   1.110 +void (*__xp_a[])(void) = { &__destroy_global_chain };
   1.111 +}
   1.112 +
   1.113 +#elif defined(__GCC32__)
   1.114 +// todo: figure out what to do here
   1.115 +#else
   1.116 +#error Unknown X86 compiler
   1.117 +#endif
   1.118 +
   1.119 +#endif