sl@0: // Copyright (c) 1999-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: // f32test\loader\security\dllt.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "dllt.h" sl@0: #include sl@0: sl@0: #ifdef __VC32__ sl@0: #pragma warning(disable:4706) sl@0: #endif sl@0: sl@0: extern "C" TInt _E32Dll(TInt); sl@0: sl@0: extern "C" __MODULE_EXPORT TInt INITFUNC(MDllList&); sl@0: extern "C" __MODULE_EXPORT TInt CHKCFUNC(); sl@0: extern "C" __MODULE_EXPORT TInt RBLKIFUNC(TInt, TInt); sl@0: sl@0: extern "C" __MODULE_IMPORT TInt BLKIFUNC(TInt); sl@0: sl@0: #ifdef __DLL_LINK_TO_EXE sl@0: extern "C" IMPORT_C void RegisterConstructorCall(TInt aDllNum); sl@0: extern "C" IMPORT_C void RegisterInitCall(TInt aDllNum); sl@0: extern "C" IMPORT_C void RegisterDestructorCall(TInt aDllNum); sl@0: #endif sl@0: sl@0: void GetDllInfo(SDllInfo& aInfo) sl@0: { sl@0: aInfo.iDllNum=DLLNUM; sl@0: aInfo.iEntryPointAddress=((TInt)&_E32Dll); sl@0: RLdrTest ldd; sl@0: ldd.Open(); sl@0: aInfo.iModuleHandle=ldd.ModuleHandleFromAddr((TInt)&_E32Dll); sl@0: ldd.Close(); sl@0: } sl@0: sl@0: #ifdef __MODULE_HAS_DATA sl@0: class TDllData sl@0: { sl@0: public: sl@0: TDllData(); sl@0: ~TDllData(); sl@0: public: sl@0: TTime iStartTime; sl@0: TTime iInitTime; sl@0: TInt iTest1; sl@0: TFileName iFileName; sl@0: RLibrary iLib; sl@0: }; sl@0: sl@0: class TDllData2 sl@0: { sl@0: public: sl@0: TDllData2(); sl@0: ~TDllData2(); sl@0: public: sl@0: TInt iTest2; sl@0: }; sl@0: sl@0: TInt Bss[16]; sl@0: TInt DllNum=DLLNUM; sl@0: TInt Generation=0; sl@0: TInt InitFlag=0; sl@0: TInt CDFlag=0; sl@0: TFullName StartThread=RThread().FullName(); sl@0: TName StartProcess=RProcess().Name(); sl@0: TDllData TheDllDataObject; sl@0: TDllData2 TheDllDataObject2; sl@0: sl@0: void AddToCDList() sl@0: { sl@0: MDllList* pM=(MDllList*)UserSvr::DllTls(TLS_INDEX); sl@0: if (pM) sl@0: { sl@0: SDllInfo di; sl@0: GetDllInfo(di); sl@0: pM->Add(di); sl@0: } sl@0: } sl@0: sl@0: TDllData::TDllData() sl@0: { sl@0: CDFlag|=1; sl@0: if (CDFlag==3) sl@0: AddToCDList(); sl@0: #ifndef __DLL_IN_CYCLE sl@0: TInt r; sl@0: CHKDEPS(r); // Check our dependencies are initialised sl@0: if (r!=KErrNone) sl@0: User::Panic(_L("CHKDEPS"),r); sl@0: #endif sl@0: iStartTime.HomeTime(); sl@0: iTest1=299792458; sl@0: Dll::FileName(iFileName); sl@0: #ifdef __DLL_LINK_TO_EXE sl@0: RegisterConstructorCall(DLLNUM); sl@0: #endif sl@0: } sl@0: sl@0: TDllData::~TDllData() sl@0: { sl@0: CDFlag|=4; sl@0: if (CDFlag==15) sl@0: AddToCDList(); sl@0: #ifdef __DLL_LINK_TO_EXE sl@0: RegisterDestructorCall(DLLNUM); sl@0: #endif sl@0: iLib.Close(); sl@0: } sl@0: sl@0: TDllData2::TDllData2() sl@0: { sl@0: CDFlag|=2; sl@0: if (CDFlag==3) sl@0: AddToCDList(); sl@0: iTest2=DLLNUM^0x3bb; sl@0: iTest2*=iTest2; sl@0: } sl@0: sl@0: TDllData2::~TDllData2() sl@0: { sl@0: CDFlag|=8; sl@0: if (CDFlag==15) sl@0: AddToCDList(); sl@0: } sl@0: #endif sl@0: sl@0: #ifdef __MODULE_HAS_DATA sl@0: void RecordInitCall() sl@0: { sl@0: TheDllDataObject.iInitTime.HomeTime(); sl@0: } sl@0: #endif sl@0: sl@0: extern "C" __MODULE_EXPORT TInt INITFUNC(MDllList& aList) sl@0: { sl@0: TInt r=KErrNone; sl@0: SDllInfo info; sl@0: GetDllInfo(info); sl@0: if (!aList.IsPresent(info)) sl@0: { sl@0: TInt pos=aList.Add(info); sl@0: INITDEPS(r,aList); // Call Init on our dependencies sl@0: aList.MoveToEnd(pos); sl@0: #ifdef __MODULE_HAS_DATA sl@0: if (r==KErrNone) sl@0: r=CHKCFUNC(); // Check initial values for .data/.bss and check constructors have been called sl@0: if (r==KErrNone) sl@0: RecordInitCall(); sl@0: #endif sl@0: #ifdef __DLL_LINK_TO_EXE sl@0: RegisterInitCall(DLLNUM); sl@0: #endif sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: extern "C" __MODULE_EXPORT TInt CHKCFUNC() sl@0: { sl@0: #ifdef __MODULE_HAS_DATA sl@0: TInt i; sl@0: TInt x=0; sl@0: for (i=0; i<16; ++i) x|=Bss[i]; sl@0: if (x) sl@0: return 0x425353; sl@0: if (DllNum!=DLLNUM) sl@0: return 0x44415441; sl@0: if (TheDllDataObject.iTest1!=299792458) sl@0: return 0x54455354; sl@0: x=DLLNUM^0x3bb; sl@0: x*=x; sl@0: if (x!=TheDllDataObject2.iTest2) sl@0: return 0x54535432; sl@0: TInt init_mark=~((DLLNUM+DLLNUMOFFSET)*(DLLNUM+DLLNUMOFFSET)); sl@0: if (InitFlag==init_mark) sl@0: return KErrNone; sl@0: if (InitFlag!=0) sl@0: return 0x494e4946; sl@0: if (Generation!=0) sl@0: return 0x47454e; sl@0: if (StartProcess!=RProcess().Name()) sl@0: return 0x535450; sl@0: TFileName fn; sl@0: Dll::FileName(fn); sl@0: if (fn!=TheDllDataObject.iFileName) sl@0: return 0x464e414d; sl@0: InitFlag=init_mark; sl@0: RDebug::Print(_L("ChkC %S OK"),&fn); sl@0: #endif sl@0: return KErrNone; sl@0: } sl@0: sl@0: extern "C" __MODULE_EXPORT TInt GetGeneration() sl@0: { sl@0: #ifdef __MODULE_HAS_DATA sl@0: return Generation; sl@0: #else sl@0: return 0; sl@0: #endif sl@0: } sl@0: sl@0: extern "C" __MODULE_EXPORT TInt RBLKIFUNC(TInt aInput, TInt aGeneration) sl@0: { sl@0: (void)aGeneration; sl@0: #ifdef __MODULE_HAS_DATA sl@0: TInt r=aInput; sl@0: if (aGeneration!=Generation) sl@0: { sl@0: Generation=aGeneration; sl@0: r=BLKIFUNC(aInput); sl@0: RBLKIFUNC_DEPS(r,aGeneration); sl@0: } sl@0: return r; sl@0: #else sl@0: return aInput; sl@0: #endif sl@0: } sl@0: sl@0: extern "C" __MODULE_EXPORT void SetCloseLib(TInt aLibHandle) sl@0: { sl@0: (void)aLibHandle; sl@0: #ifdef __MODULE_HAS_DATA sl@0: TheDllDataObject.iLib.SetHandle(aLibHandle); sl@0: #endif sl@0: }