First public contribution.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\system\t_prot2.cpp
21 const TInt KHeapSize=0x1000;
23 _LIT(KSecondProcessName,"T_PROT2A");
24 _LIT(KSecondProcessDataChunkName,"T_PROT2A*$DAT");
26 RTest test(_L("T_PROT2"));
28 LOCAL_C TInt WatcherThread(TAny* aSemaphoreHandle)
30 RTest wtest(_L("Watcher Thread"));
32 RThread().SetPriority(EPriorityMuchMore);
33 wtest.Start(_L("Create undertaker"));
39 me.Panic(_L("UNDERTAKER"),r);
42 sem.SetHandle((TInt)aSemaphoreHandle);
49 User::WaitForRequest(s);
52 const TDesC& fn=t.FullName();
53 wtest.Printf(_L("Thread %S exited\n"),&fn);
54 const TDesC& cat=t.ExitCategory();
55 wtest.Printf(_L("Exit type %d,%d,%S\n"),t.ExitType(),t.ExitReason(),&cat);
60 LOCAL_C void StartWatcherThread()
62 test.Next(_L("Start watcher thread"));
64 TInt r=s.CreateLocal(0);
67 r=t.Create(_L("WatcherThread"),WatcherThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)s.Handle());
74 void ExceptionHandler(TExcType)
76 User::Leave(KErrAbort);
79 LOCAL_C TInt RogueThread1(TAny*)
85 User::SetExceptionHandler(ExceptionHandler,KExceptionFault);
88 User::AfterHighRes(1000); // wait 1ms
91 TFindChunk fc(KSecondProcessDataChunkName);
99 p=(TUint*)c.Base(); // second process is fixed
109 TRAPD(r,Mem::Fill(p,0x1000,0xc9));
113 User::Panic(_L("NOTFOUND"),m);
117 LOCAL_C void TestLoaderProtection()
119 test.Next(_L("Create rogue thread"));
121 TInt r=t.Create(_L("RogueThread1"),RogueThread1,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
123 t.SetPriority(EPriorityRealTime); // this should be above the loader
126 test(s==KRequestPending);
127 test.Next(_L("Resume rogue thread"));
130 test.Next(_L("Create second process"));
132 r=p.Create(KSecondProcessName,KNullDesC);
136 test(s2==KRequestPending);
137 test.Next(_L("Resume second process"));
140 test.Next(_L("Wait for second process to exit"));
141 User::WaitForRequest(s2);
142 const TDesC& pcat=p.ExitCategory();
143 test.Printf(_L("Exit type %d,%d,%S\n"),p.ExitType(),p.ExitReason(),&pcat);
146 test.Next(_L("Wait for rogue thread to exit"));
147 User::WaitForRequest(s);
148 const TDesC& tcat=t.ExitCategory();
149 test.Printf(_L("Exit type %d,%d,%S\n"),t.ExitType(),t.ExitReason(),&tcat);
153 GLDEF_C TInt E32Main()
156 test.Start(_L("Testing protection against errant user threads"));
157 RProcess().SetPriority(EPriorityHigh);
159 StartWatcherThread();
160 TestLoaderProtection();