# HG changeset patch # User Stephane Lenclud # Date 1272392575 -7200 # Node ID f561f9ae805b168c49f7548b51253b91a4ea5413 # Parent f36eb49486864699acfa48768f3ff75a8a707ec4 Trying to get trap/leave to work properly but the whole WINS stuff seems over complicated with a lot of assembly in the middle and it's not working on my compiler. When the throw happens the debugger complains about uncaught exception when I'm definitly inside a catch implemented by our TRAP. I think I'm going to come up with a much simplified trap/leave implementation for SYMC. On my prototype all that stuff was working fine in like 20 lines of C++. diff -r f36eb4948686 -r f561f9ae805b kernel/eka/CMakeLists.txt --- a/kernel/eka/CMakeLists.txt Tue Apr 27 17:12:11 2010 +0200 +++ b/kernel/eka/CMakeLists.txt Tue Apr 27 20:22:55 2010 +0200 @@ -36,7 +36,7 @@ add_custom_target(genexec) add_subdirectory(./euser) -add_subdirectory(./kernel) +#add_subdirectory(./kernel) diff -r f36eb4948686 -r f561f9ae805b kernel/eka/euser/CMakeLists.txt --- a/kernel/eka/euser/CMakeLists.txt Tue Apr 27 17:12:11 2010 +0200 +++ b/kernel/eka/euser/CMakeLists.txt Tue Apr 27 20:22:55 2010 +0200 @@ -27,6 +27,7 @@ add_definitions(-D__VC32__) add_definitions(-D_UNICODE) add_definitions(-D__LEAVE_EQUALS_THROW__) +add_definitions(-D__SUPPORT_CPP_EXCEPTIONS__) add_definitions(-D__WINS__) #__CPU_X86 is declared by __WINS__ #add_definitions(-D__CPU_X86) @@ -77,6 +78,7 @@ set (sourcepath ../common/win32/) add_source( atomics.cpp +seh.cpp ) #Adding the sources from maths @@ -94,7 +96,8 @@ set (sourcepath ../euser/epoc/win32/) add_source( uc_i64.cpp uc_realx.cpp -uc_trp.cpp uc_utl.cpp +uc_trp.cpp +uc_utl.cpp uc_dll.cpp #uc_exec.cpp ) @@ -246,7 +249,14 @@ add_library (euser SHARED ${source}) add_dependencies(euser genexec emulator scppnwdl) target_link_libraries(euser emulator) -set_target_properties(euser PROPERTIES COMPILE_DEFINITIONS "__DLL__") +#set_target_properties(euser PROPERTIES COMPILE_DEFINITIONS "__DLL__") + +set_property( + TARGET euser + PROPERTY COMPILE_DEFINITIONS __DLL__ + ) + + ### ESTUB: not sure why need that yet diff -r f36eb4948686 -r f561f9ae805b kernel/eka/euser/epoc/symc/uc_exec.cpp --- a/kernel/eka/euser/epoc/symc/uc_exec.cpp Tue Apr 27 17:12:11 2010 +0200 +++ b/kernel/eka/euser/epoc/symc/uc_exec.cpp Tue Apr 27 20:22:55 2010 +0200 @@ -354,8 +354,27 @@ // #ifndef __GEN_USER_EXEC_CODE__ +const TInt KTrapStackSize=256; + +/* + +*/ +class TThread + { +public: + +public: + RSemaphore iRequestSemaphore; + CActiveScheduler* iActiveScheduler; //Current active scheduler for this thread. Used. + TTrapHandler* iHandler; //This is our cleanup stack. Used. + //No idea why we need that trap stack + TTrap* iTrapStack[KTrapStackSize]; + TInt iTrapCount; + }; + /* Object used to store process globals for our pseudo kernel. +That's typically going to be a singleton. */ class TProcess { @@ -366,14 +385,20 @@ public: RHeap* iAllocator; TAny* iBase; + TThread iThread; //Single thread for now }; + void TProcess::CreateHeap() { + iThread.iTrapCount=0; + //Define the size of our heap + const TInt KHeapMaxSize=1024*1024*10; // 10 Mo for now __ASSERT_ALWAYS(iAllocator==NULL && iBase==NULL,Panic(ESymcExecPanicHeapAlreadyExists)); - iBase=malloc(1024*10); + iBase=malloc(KHeapMaxSize); __ASSERT_ALWAYS(iBase!=NULL,Panic(ESymcExecPanicCreateHeapFailed)); - iAllocator=UserHeap::FixedHeap(iBase,1024*10); + //TODO: is there anyway we could use variable size heap? + iAllocator=UserHeap::FixedHeap(iBase,KHeapMaxSize); __ASSERT_ALWAYS(iAllocator!=NULL,Panic(ESymcExecPanicCreateHeapFailed)); } @@ -406,14 +431,19 @@ FAST_EXEC1(EFastExecHeapSwitch); } -__EXECDECL__ TTrapHandler* Exec::PushTrapFrame(TTrap*) +__EXECDECL__ TTrapHandler* Exec::PushTrapFrame(TTrap* aTrap) { - FAST_EXEC1(EFastExecPushTrapFrame); + //FAST_EXEC1(EFastExecPushTrapFrame); + ASSERT(gProcess.iThread.iTrapCount<=KTrapStackSize); + gProcess.iThread.iTrapStack[gProcess.iThread.iTrapCount++]=aTrap; + return gProcess.iThread.iHandler; } __EXECDECL__ TTrap* Exec::PopTrapFrame() { - FAST_EXEC0(EFastExecPopTrapFrame); + //FAST_EXEC0(EFastExecPopTrapFrame); + ASSERT(gProcess.iThread.iTrapCount>0); + return gProcess.iThread.iTrapStack[gProcess.iThread.iTrapCount--]; } __EXECDECL__ CActiveScheduler* Exec::ActiveScheduler() @@ -433,12 +463,16 @@ __EXECDECL__ TTrapHandler* Exec::TrapHandler() { - FAST_EXEC0(EFastExecTrapHandler); + //FAST_EXEC0(EFastExecTrapHandler); + return gProcess.iThread.iHandler; } -__EXECDECL__ TTrapHandler* Exec::SetTrapHandler(TTrapHandler*) - { - FAST_EXEC1(EFastExecSetTrapHandler); +__EXECDECL__ TTrapHandler* Exec::SetTrapHandler(TTrapHandler* aHandler) + { + //FAST_EXEC1(EFastExecSetTrapHandler); + TTrapHandler* prev=gProcess.iThread.iHandler; + gProcess.iThread.iHandler=aHandler; + return prev; } __EXECDECL__ TUint32 Exec::DebugMask() @@ -1657,12 +1691,13 @@ __EXECDECL__ TTrapHandler* Exec::LeaveStart() { - SLOW_EXEC0(EExecLeaveStart); + //SLOW_EXEC0(EExecLeaveStart); + return gProcess.iThread.iHandler; } __EXECDECL__ void Exec::LeaveEnd() { - SLOW_EXEC0(EExecLeaveEnd); + //SLOW_EXEC0(EExecLeaveEnd); } __EXECDECL__ void Exec::SetDebugMaskIndex(TUint32, TUint) diff -r f36eb4948686 -r f561f9ae805b kernel/eka/euser/epoc/win32/uc_epoc.cpp --- a/kernel/eka/euser/epoc/win32/uc_epoc.cpp Tue Apr 27 17:12:11 2010 +0200 +++ b/kernel/eka/euser/epoc/win32/uc_epoc.cpp Tue Apr 27 20:22:55 2010 +0200 @@ -1,60 +1,97 @@ -// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). -// All rights reserved. -// This component and the accompanying materials are made available -// under the terms of the License "Eclipse Public License v1.0" -// which accompanies this distribution, and is available -// at the URL "http://www.eclipse.org/legal/epl-v10.html". -// -// Initial Contributors: -// Nokia Corporation - initial contribution. -// -// Contributors: -// -// Description: -// e32\euser\epoc\win32\uc_epoc.cpp -// -// - -#include -#include -#include - -//#include -#include - -#if defined __SYMC__ - -//SL: Empty on FCL ? - - -GLDEF_C TInt E32Main() - { - //What do we do then - - __UHEAP_MARK; - - //CBase* base=new(ELeave) CBase(); - CBase* base=new CBase(); - delete base; - - TUint8* test=new TUint8[1024*9]; - delete[] test; - - __UHEAP_MARKEND; - - return KErrNone; - } - - -TInt main() - { - User::InitProcess(); - //BootEpoc(ETrue); - E32Main(); - - User::Exit(0); - return 0; - } - -#endif - +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// e32\euser\epoc\win32\uc_epoc.cpp +// +// + +#include +#include +#include + +//#include +#include + +#if defined __SYMC__ + +//SL: Empty on FCL ? +//For now we use this for basic testing on our SYMC implementation + + +GLDEF_C void MainL() + { + + CBase* base=new(ELeave) CBase(); + delete base; + + //Testing cleanup stack + TRAPD(err, + base=new(ELeave) CBase(); + CleanupStack::PushL(base); + User::Leave(KErrCancel); + ); + + ASSERT(err==KErrCancel); + + //Testing alloc failure + TRAP(err, + TUint8* test=new(ELeave) TUint8[1024*1024*10]; + delete[] test; + ); + + ASSERT(err==KErrNoMemory); + + } + + +GLDEF_C TInt E32Main() + { + //What do we do then + + __UHEAP_MARK; + + //CBase* base=new(ELeave) CBase(); + CBase* base=new CBase(); + delete base; + + TUint8* test=new TUint8[1024*9]; + delete[] test; + + CTrapCleanup* cleanupStack = CTrapCleanup::New(); + if (!cleanupStack) + { + return KErrNoMemory; + } + + TRAPD(err,MainL()); + + delete cleanupStack; + + __UHEAP_MARKEND; + + return err; + } + + +TInt main() + { + User::InitProcess(); + //BootEpoc(ETrue); + E32Main(); + + User::Exit(0); + return 0; + } + +#endif +