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. anywhere
authorStephane Lenclud <tortoisehg@lenclud.com>
Tue, 27 Apr 2010 20:22:55 +0200
branchanywhere
changeset 95 f561f9ae805b
parent 94 f36eb4948686
child 96 428c5911a502
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++.
kernel/eka/CMakeLists.txt
kernel/eka/euser/CMakeLists.txt
kernel/eka/euser/epoc/symc/uc_exec.cpp
kernel/eka/euser/epoc/win32/uc_epoc.cpp
--- 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)
 
 
 
--- 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
--- 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)
--- 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 <e32std.h>
-#include <e32std_private.h>
-#include <e32wins.h>
-
-//#include <e32cmn.h>
-#include <nwdl.h>
-
-#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 <e32std.h>
+#include <e32std_private.h>
+#include <e32wins.h>
+
+//#include <e32cmn.h>
+#include <nwdl.h>
+
+#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
+