kernel/eka/euser/us_ksvr.cpp
changeset 0 a41df078684a
child 2 4122176ea935
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1995-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\euser\us_ksvr.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "us_std.h"
       
    19 #include "us_data.h"
       
    20 #include <e32svr.h>
       
    21 #include <e32uid.h>
       
    22 #include <e32ldr.h>	
       
    23 
       
    24 //#define __DEBUG_IMAGE__ 1
       
    25 #if defined(__DEBUG_IMAGE__) && defined (__EPOC32__)
       
    26 #define __IF_DEBUG(t) {RDebug::t;}
       
    27 #else
       
    28 #define __IF_DEBUG(t)
       
    29 #endif
       
    30 
       
    31 //
       
    32 // class RNotifier
       
    33 //
       
    34 
       
    35 /**
       
    36 Requests the extended notifier server to start the notifier identified by
       
    37 the specified UID.
       
    38 
       
    39 The request is synchronous; the call returns when the request is complete.
       
    40 
       
    41 The notifier may not be started immediately if a higher priority notifier is
       
    42 already active. In this case, the notifier is queued until it has the highest
       
    43 priority outstanding request for the channel(s) it operates on.
       
    44 
       
    45 @param aNotifierUid The UID identifying the notifier.
       
    46 @param aBuffer      Data that can be passed to the notifier; the format and meaning
       
    47                     of this depends on the notifier.
       
    48 
       
    49 @return KErrNone, if successful;
       
    50         KErrNotFound, if there is no notifier matching the specified UID;
       
    51         KErrAlreadyExists, if the notifier has already been started, or has
       
    52         an outstanding start request. It may also return with one of the other
       
    53         system-wide error codes, if the notifier cannot be started by
       
    54         the server due to low memory or it leaves from its server side
       
    55         call to StartL().
       
    56         
       
    57 @see CServer
       
    58 */
       
    59 EXPORT_C TInt RNotifier::StartNotifier(TUid aNotifierUid, const TDesC8& aBuffer)
       
    60 	{
       
    61 	return SendReceive(EStartNotifier, TIpcArgs(
       
    62 										(TInt)aNotifierUid.iUid,
       
    63 										&aBuffer,
       
    64 										(TAny*)NULL // No resonse required
       
    65 										));
       
    66 	}
       
    67 
       
    68 
       
    69 
       
    70 
       
    71 /**
       
    72 Requests the extended notifier server to start the notifier identified by
       
    73 the specified UID.
       
    74 
       
    75 The request is synchronous; the call returns when the request is complete.
       
    76 
       
    77 The notifier may not start immediately if a higher priority notifier is
       
    78 already active. In this case, the notifier is queued until it has the highest
       
    79 priority outstanding request for the channel(s) it operates on.
       
    80 This can also cause unexpected behaviour: the function can return
       
    81 before the notifier has been started with the added consequence that no response
       
    82 data is written.
       
    83 
       
    84 For this reason, this function has been deprecated. Instead, use
       
    85 RNotifier::StartNotifierAndGetResponse(), or if there is no need to wait for a
       
    86 response, use the two argument overload of RNotifier::StartNotifier().
       
    87 
       
    88 @param aNotifierUid The UID identifying the notifier.
       
    89 @param aBuffer      Data that can be passed to the notifier; the format and meaning
       
    90                     of this depends on the notifier.
       
    91 @param aResponse    Response data; the format
       
    92                     and meaning of this depends on the notifier.
       
    93 
       
    94 @return KErrNone, if successful;
       
    95         KErrNotFound, if there is no notifier matching the specified UID;
       
    96         KErrAlreadyExists, if the notifier has already been started, or has
       
    97         an outstanding start request. It may also return with one of the other
       
    98         system-wide error codes, if the notifier cannot be started by
       
    99         the server due to low memory or it leaves from its server side
       
   100         call to StartL().
       
   101         
       
   102 @see CServer
       
   103 
       
   104 @deprecated use RNotifier::StartNotifierAndGetResponse(), or if there is no
       
   105             need to wait for a response, use the two argument overload
       
   106             of RNotifier::StartNotifier()
       
   107 */
       
   108 EXPORT_C TInt RNotifier::StartNotifier(TUid aNotifierUid, const TDesC8& aBuffer, TDes8& aResponse)
       
   109 	{
       
   110 	return SendReceive(EStartNotifier, TIpcArgs(
       
   111 										(TInt)aNotifierUid.iUid,
       
   112 										&aBuffer,
       
   113 										&aResponse
       
   114 										));
       
   115 	}
       
   116 
       
   117 /*
       
   118 This function has never been implemented on any Symbian OS version.
       
   119 It always returns KErrNotSupported.
       
   120 @publishedPartner
       
   121 @removed
       
   122 */
       
   123 EXPORT_C TInt RNotifier::StartNotifier(TUid aNotifierDllUid,TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse)
       
   124 	{
       
   125 	return SendReceive(EStartNotifierFromSpecifiedDll, TIpcArgs(
       
   126 										(TInt)aNotifierUid.iUid,
       
   127 										&aBuffer,
       
   128 										&aResponse,
       
   129 										(TInt)aNotifierDllUid.iUid
       
   130 										));
       
   131 	}
       
   132 
       
   133 /**
       
   134 Requests the extended notifier server to cancel the notifier identified by
       
   135 the specified UID.
       
   136 
       
   137 The request is synchronous; the call returns when the request is complete.
       
   138 
       
   139 Any notifier that was queued pending the completion of aNotifierUid will be
       
   140 automatically started.
       
   141 
       
   142 @param  aNotifierUid The UID identifying the notifier.
       
   143 
       
   144 @return KErrNone, if successful;
       
   145         KErrNotFound, if there is no notifier matching the specified UID.
       
   146 */
       
   147 EXPORT_C TInt RNotifier::CancelNotifier(TUid aNotifierUid)
       
   148 	{
       
   149 	return SendReceive(ECancelNotifier, TIpcArgs( (TInt)aNotifierUid.iUid ));
       
   150 	}
       
   151 
       
   152 /**
       
   153 Requests the extended notifier server to update the active notifier identified by
       
   154 the specified UID.
       
   155 
       
   156 The request is synchronous; the call returns when the request is complete.
       
   157 
       
   158 @param aNotifierUid The UID identifying the notifier.
       
   159 @param aBuffer      Data that can be passed to the notifier; the format and meaning
       
   160                     of this depends on the notifier.
       
   161 @param aResponse    Reserved for future use.
       
   162 
       
   163 @return KErrNone, if successful;
       
   164         KErrNotFound, if there is no notifier matching the specified UID.
       
   165 */
       
   166 EXPORT_C TInt RNotifier::UpdateNotifier(TUid aNotifierUid, const TDesC8& aBuffer,TDes8& aResponse)
       
   167 	{
       
   168 	return SendReceive(EUpdateNotifier, TIpcArgs(
       
   169 										(TInt)aNotifierUid.iUid,
       
   170 										&aBuffer,
       
   171 										&aResponse
       
   172 										));
       
   173 	}
       
   174 
       
   175 /**
       
   176 Requests the extended notifier server to update the active notifier identified by
       
   177 the specified UID.
       
   178 
       
   179 This is an asynchronous request.It may be called multiple times for
       
   180 some notifier implementations; see specific notifier documentation for exact details.
       
   181 
       
   182 @param aRs          The request status. On request completion, contains:
       
   183                     KErrNone, if successful; otherwise, one of the other system
       
   184                     wide error codes.
       
   185 @param aNotifierUid The UID identifying the notifier.
       
   186 @param aBuffer      Data that can be passed to the notifier; the format and meaning
       
   187                     of this depends on the notifier.
       
   188 @param aResponse    Reserved for future use.
       
   189 
       
   190 */
       
   191 EXPORT_C void RNotifier::UpdateNotifierAndGetResponse(TRequestStatus& aRs, TUid aNotifierUid, const TDesC8& aBuffer, TDes8& aResponse)
       
   192 	{
       
   193 	SendReceive(EUpdateNotifierAndGetResponse, TIpcArgs(
       
   194 										(TInt)aNotifierUid.iUid,
       
   195 										&aBuffer,
       
   196 										&aResponse
       
   197 										), aRs);
       
   198 	}
       
   199 	
       
   200 /**
       
   201 Requests the extended notifier server to start the notifier identified by
       
   202 the specified UID.
       
   203 
       
   204 This is an asynchronous request.It may be called multiple times for
       
   205 some notifier implementations; see specific notifier documentation for exact details.
       
   206 
       
   207 @param aRs          The request status. On request completion, contains:
       
   208                     KErrNone, if successful; otherwise, one of the other system
       
   209                     wide error codes.
       
   210 @param aNotifierUid The UID identifying the notifier.
       
   211 @param aBuffer      Data that can be passed to the notifier; the format
       
   212                     and meaning of this depends on the notifier.
       
   213 @param aResponse    Response data; the format
       
   214                     and meaning of this depends on the notifier.
       
   215 */
       
   216 EXPORT_C void RNotifier::StartNotifierAndGetResponse(TRequestStatus& aRs,TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse)
       
   217 	{
       
   218 	SendReceive(EStartNotifierAndGetResponse, TIpcArgs(
       
   219 										(TInt)aNotifierUid.iUid,
       
   220 										&aBuffer,
       
   221 										&aResponse
       
   222 										), aRs);
       
   223 	}
       
   224 
       
   225 
       
   226 
       
   227 
       
   228 /**
       
   229 @publishedPartner
       
   230 @removed
       
   231 
       
   232 This function has never been implemented on any Symbian OS version.
       
   233 The request always completes with KErrNotSupported.
       
   234 */
       
   235 EXPORT_C void RNotifier::StartNotifierAndGetResponse(TRequestStatus& aRs,TUid aNotifierDllUid,TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse)
       
   236 	{
       
   237 	SendReceive(EStartNotifierFromSpecifiedDllAndGetResponse, TIpcArgs(
       
   238 										(TInt)aNotifierUid.iUid,
       
   239 										&aBuffer,
       
   240 										&aResponse,
       
   241 										(TInt)aNotifierDllUid.iUid
       
   242 										), aRs);
       
   243 	}
       
   244 
       
   245 
       
   246 
       
   247 
       
   248 /**
       
   249 @publishedPartner
       
   250 @removed
       
   251 
       
   252 This function has never been implemented on any Symbian OS version.
       
   253 It always returns KErrNotSupported.
       
   254 */
       
   255 EXPORT_C TInt RNotifier::UnloadNotifiers(TUid /*aNotifierUid*/)
       
   256 	{
       
   257 	return KErrNotSupported;
       
   258 	}
       
   259 
       
   260 
       
   261 
       
   262 
       
   263 /**
       
   264 @publishedPartner
       
   265 @removed
       
   266 
       
   267 This function has never been implemented on any Symbian OS version.
       
   268 It always returns KErrNotSupported.
       
   269 */
       
   270 EXPORT_C TInt RNotifier::LoadNotifiers(TUid /*aNotifierUid*/)
       
   271 	{
       
   272 	return KErrNotSupported;
       
   273 	}
       
   274 
       
   275 
       
   276 
       
   277 
       
   278 /**
       
   279 Default constructor.
       
   280 */		
       
   281 EXPORT_C RNotifier::RNotifier()
       
   282 	:	iButtonVal(NULL,0),
       
   283 		iCombinedBuffer(NULL)
       
   284 	{}
       
   285 
       
   286 
       
   287 
       
   288 
       
   289 /**
       
   290 Connects to the extended notifier server, creating a session with that server.
       
   291 Note: Notifier server is started during window server start-up sequence.
       
   292 
       
   293 The function must be called before any other function.
       
   294 
       
   295 @return KErrNone, if successful, otherwise one of the other system-wide error codes 
       
   296 */
       
   297 EXPORT_C TInt RNotifier::Connect()
       
   298 	{
       
   299 	return CreateSession(__NOTIFIER_NAME,TVersion(KNotifierMajorVersionNumber,KNotifierMinorVersionNumber,KNotifierBuildVersionNumber),-1);
       
   300 	}
       
   301 
       
   302 
       
   303 
       
   304 
       
   305 /**
       
   306 Launches a simple two line dialog that displays two lines of text.
       
   307 
       
   308 This is an asynchronous request that completes when the dialog exits.
       
   309 
       
   310 @param aLine1     A descriptor containing the first line of text to be displayed.
       
   311 @param aLine2     A descriptor containing the second line of text to be displayed.
       
   312 @param aBut1      A descriptor containing text to be displayed in the first button.
       
   313 @param aBut2      A descriptor containing text to be displayed in the (optional) second button.
       
   314 @param aButtonVal An integer value which is set when the dialog exits. It is set to:
       
   315                   0, if the first button is selected;
       
   316                   1, if the second button is selected.
       
   317 @param aStatus    The request status object. If the request completes normally, this is set to KErrNone.
       
   318 */
       
   319 EXPORT_C void RNotifier::Notify(const TDesC& aLine1,const TDesC& aLine2,const TDesC& aBut1,const TDesC& aBut2, TInt& aButtonVal, TRequestStatus& aStatus)
       
   320 	{
       
   321 	const TInt requiredLengthOfCombinedBuffer=aLine1.Length()+aLine2.Length()+aBut1.Length()+aBut2.Length();
       
   322 	if ((iCombinedBuffer!=NULL) && (iCombinedBuffer->Des().MaxLength()<requiredLengthOfCombinedBuffer))
       
   323 		{
       
   324 		delete iCombinedBuffer;
       
   325 		iCombinedBuffer=NULL;
       
   326 		}
       
   327 	if (iCombinedBuffer==NULL)
       
   328 		{
       
   329 		iCombinedBuffer=HBufC::New(requiredLengthOfCombinedBuffer);
       
   330 		}
       
   331 	if (iCombinedBuffer==NULL)
       
   332 		{
       
   333 		// report the error back via the TRequestStatus
       
   334 		TRequestStatus* status=&aStatus;
       
   335 		User::RequestComplete(status,KErrNoMemory);
       
   336 		}
       
   337 	else
       
   338 		{
       
   339 		TPtr combinedBufferForNotify(iCombinedBuffer->Des());
       
   340 		combinedBufferForNotify = aLine1;
       
   341 		combinedBufferForNotify.Append(aLine2);
       
   342 		combinedBufferForNotify.Append(aBut1);
       
   343 		combinedBufferForNotify.Append(aBut2);
       
   344 		iButtonVal.Set(REINTERPRET_CAST(TUint8*,&aButtonVal),sizeof(TInt),sizeof(TInt));
       
   345 		__ASSERT_ALWAYS(((aLine1.Length()|aLine2.Length()|aBut1.Length()|aBut2.Length())&~KMaxTUint16)==0,Panic(ENotifierTextTooLong)); // check that all of the descriptor lengths are less than or equal to KMaxTUint16
       
   346 		SendReceive(ENotifierNotify,TIpcArgs(&iButtonVal,iCombinedBuffer,(aLine1.Length()<<16)|aLine2.Length(),(aBut1.Length()<<16)|aBut2.Length()),aStatus);
       
   347 		}
       
   348 	}
       
   349 
       
   350 
       
   351 
       
   352 
       
   353 /**
       
   354 Not implemented by the server.
       
   355 */
       
   356 EXPORT_C void RNotifier::NotifyCancel()
       
   357 	{
       
   358 	SendReceive(ENotifierNotifyCancel,TIpcArgs()); // ignores any returned error
       
   359 	}
       
   360 
       
   361 
       
   362 
       
   363 
       
   364 /**
       
   365 Closes the notifier.
       
   366 */
       
   367 EXPORT_C void RNotifier::Close()
       
   368 	{
       
   369 	delete iCombinedBuffer;
       
   370 	iCombinedBuffer=NULL;
       
   371 	RSessionBase::Close();
       
   372 	}
       
   373 
       
   374 
       
   375 
       
   376 
       
   377 /**
       
   378 @internalAll
       
   379 */
       
   380 EXPORT_C TInt RNotifier::InfoPrint(const TDesC& aDes)
       
   381 	{
       
   382 	return SendReceive(ENotifierInfoPrint, TIpcArgs(&aDes));
       
   383 	}
       
   384 
       
   385 
       
   386 //
       
   387 // Class TChunkCreateInfo
       
   388 //
       
   389 
       
   390 /**
       
   391 Default constructor. 
       
   392 
       
   393 This defaults the chunk to be created to be local, to have no attributes set
       
   394 and to use the default clear byte.
       
   395 
       
   396 A local chunk is private to the process creating it and is not 
       
   397 intended for access by other user processes.
       
   398 */
       
   399 EXPORT_C TChunkCreateInfo::TChunkCreateInfo() :
       
   400 	// Specifing individual initialisers for members instead of using memclear
       
   401 	// so that Coverity doesn't complain about uninitialised local variables in
       
   402 	// calls to e.g., TChunkCreateInfo::SetPaging().
       
   403 	iVersionNumber(0),
       
   404 	iType(TChunkCreate::ENormal),
       
   405     iGlobal(EFalse),
       
   406     iMaxSize(0),
       
   407     iOwnerType(EOwnerProcess),
       
   408     iName(NULL),
       
   409     iInitialBottom(0),
       
   410     iInitialTop(0),
       
   411     iAttributes(TChunkCreate::EPagingUnspec),
       
   412 	iClearByte(KChunkClearByteDefault)
       
   413 	{
       
   414 	}
       
   415 
       
   416 
       
   417 /**	
       
   418 Sets the chunk to be created to have a committed region that always starts at the 
       
   419 bottom of the reserved region.
       
   420 
       
   421 
       
   422 @param aSize    The number of bytes committed to this chunk.
       
   423 @param aMaxSize The maximum size to which the reserved region of this chunk 
       
   424                 can grow.
       
   425 @param aType    An enumeration whose enumerators define the ownership of this 
       
   426                 chunk handle. If not explicitly specified, EOwnerProcess is
       
   427                 taken as default.
       
   428 @see RChunk::CreateLocal()
       
   429 */
       
   430 EXPORT_C void TChunkCreateInfo::SetNormal(TInt aInitialSize, TInt aMaxSize)
       
   431 	{
       
   432 	iType = TChunkCreate::ENormal | TChunkCreate::EData;
       
   433 	iInitialBottom = 0;
       
   434 	iInitialTop = aInitialSize;
       
   435 	iMaxSize = aMaxSize;
       
   436 	}
       
   437 
       
   438 
       
   439 /**
       
   440 Sets the chunk to be created to be user writable and to be marked by the kernel
       
   441 as containing code.
       
   442 This can only be set on local chunks.
       
   443 
       
   444 @param aInitialSize	The number of bytes committed to this chunk.
       
   445 @param aMaxSize 	The maximum size to which the reserved region of this chunk
       
   446                 	can grow.
       
   447 @see RChunk::CreateLocalCode()
       
   448 */
       
   449 EXPORT_C void TChunkCreateInfo::SetCode(TInt aInitialSize, TInt aMaxSize)
       
   450 	{
       
   451 	iType = TChunkCreate::ENormal | TChunkCreate::ECode;
       
   452 	iInitialBottom = 0;
       
   453 	iInitialTop = aInitialSize;
       
   454 	iMaxSize = aMaxSize;
       
   455 	}
       
   456 
       
   457 
       
   458 /**	
       
   459 Sets the chunk to be created to have a commited region that that can be any 
       
   460 contiguous subset of the reserved region.
       
   461 
       
   462 @param aInitialBottom The offset of the bottom of the new committed region 
       
   463                       from the base of the chunk's reserved region.
       
   464 @param aInitialTop    The offset of the top of the new committed region from
       
   465                       the  base of the chunk's reserved region. 
       
   466 @param aMaxSize       The maximum size to which the reserved region of
       
   467                       this chunk can grow.
       
   468 @see RChunk::CreateDoubleEndedLocal()
       
   469 */
       
   470 EXPORT_C void TChunkCreateInfo::SetDoubleEnded(TInt aInitialBottom, TInt aInitialTop, TInt aMaxSize)
       
   471 	{
       
   472 	iType = TChunkCreate::EDoubleEnded | TChunkCreate::EData;
       
   473 	iInitialBottom = aInitialBottom;
       
   474 	iInitialTop = aInitialTop;
       
   475 	iMaxSize = aMaxSize;
       
   476 	}
       
   477 
       
   478 /** 
       
   479 Set the chunk to be created to have a committed region consisting of an 
       
   480 arbitrary set of MMU pages within the reserved region.
       
   481 
       
   482 @param aInitialBottom 	The offset of the bottom of the new committed region 
       
   483                       	from the base of the chunk's reserved region.
       
   484 @param aInitialTop		The offset of the top of the new committed region 
       
   485 						from the  base of the chunk's reserved region. 
       
   486 @param aMaxSize       	The maximum size to which the reserved region of
       
   487                       	this chunk can grow.
       
   488 @see RChunk::CreateDisconnectedLocal()
       
   489 */
       
   490 EXPORT_C void TChunkCreateInfo::SetDisconnected(TInt aInitialBottom, TInt aInitialTop, TInt aMaxSize)
       
   491 	{
       
   492 	iType = TChunkCreate::EDisconnected | TChunkCreate::EData;
       
   493 	iInitialBottom = aInitialBottom;
       
   494 	iInitialTop = aInitialTop;
       
   495 	iMaxSize = aMaxSize;
       
   496 	}
       
   497 
       
   498 
       
   499 /**	
       
   500 Sets the chunk to be created to be a thread heap chunk.
       
   501 For internal use only.
       
   502 
       
   503 @param aInitialSize	The number of bytes committed to this chunk.
       
   504 @param aMaxSize 	The maximum size to which the reserved region of this chunk 
       
   505                 	can grow.
       
   506 @param aName		The name to be given to the chunk to be created
       
   507 @internalComponent
       
   508 */
       
   509 void TChunkCreateInfo::SetThreadHeap(TInt aInitialSize, TInt aMaxSize, const TDesC& aName)
       
   510 	{
       
   511 	iType = TChunkCreate::ENormal | TChunkCreate::EData;
       
   512 	iInitialBottom = 0;
       
   513 	iInitialTop = aInitialSize;
       
   514 	iMaxSize = aMaxSize;
       
   515 	iAttributes |= TChunkCreate::ELocalNamed;
       
   516 	iName = &aName;
       
   517 	iOwnerType = EOwnerThread;
       
   518 	}
       
   519 
       
   520 /** 
       
   521 Sets the owner of the chunk to be created.
       
   522 @param aType	The owner of the chunk to be created.
       
   523 */
       
   524 EXPORT_C void TChunkCreateInfo::SetOwner(TOwnerType aType)
       
   525 	{
       
   526 	iOwnerType = aType;
       
   527 	}
       
   528 
       
   529 /** 
       
   530 Sets the chunk to be created to be global, i.e. it is potentially visible
       
   531 to all processes and is intended for access by other user processes.
       
   532 
       
   533 @param aName          A reference to a descriptor containing the name to be
       
   534                       assigned to the global chunk. The length of
       
   535                       the descriptor must be no greater than that allowed for
       
   536                       a TKName type.
       
   537 */
       
   538 EXPORT_C void TChunkCreateInfo::SetGlobal(const TDesC& aName)
       
   539 	{
       
   540 	iName = &aName;
       
   541 	iGlobal = ETrue;
       
   542 	}
       
   543 
       
   544 /** 
       
   545 Sets the byte value that all memory committed to the chunk will be cleared to.
       
   546 @param TUint8 aClearByte.
       
   547 */
       
   548 EXPORT_C void TChunkCreateInfo::SetClearByte(TUint8 aClearByte)
       
   549 	{
       
   550 	iClearByte = aClearByte;
       
   551 	}
       
   552 
       
   553 
       
   554 /** 
       
   555 Sets the data paging attributes for the chunk to be created.  Any previous calls
       
   556 to this method will be overridden for this TChunkCreateInfo object.
       
   557 
       
   558 @param aPaging	The data paging attributes of the chunk to be created.
       
   559 
       
   560 @prototype
       
   561 */
       
   562 EXPORT_C void TChunkCreateInfo::SetPaging(const TChunkPagingAtt aPaging)
       
   563 	{
       
   564 	__ASSERT_COMPILE(TChunkCreate::EPagingUnspec == 0);
       
   565 	iAttributes &= ~TChunkCreate::EPagingMask;
       
   566 	if (aPaging == EPaged)
       
   567 		iAttributes |= TChunkCreate::EPaged;
       
   568 	if (aPaging == EUnpaged)
       
   569 		iAttributes |= TChunkCreate::EUnpaged;
       
   570 	}
       
   571 
       
   572 
       
   573 EXPORT_C void TChunkCreateInfo::SetCache(TInt aMaxSize)
       
   574 	{
       
   575 	iType = TChunkCreate::ECache | TChunkCreate::EData;
       
   576 	iInitialBottom = 0;
       
   577 	iInitialTop = 0;
       
   578 	iMaxSize = aMaxSize;
       
   579 	SetPaging(EUnpaged);
       
   580 	}
       
   581 
       
   582 
       
   583 //
       
   584 // class RChunk
       
   585 //
       
   586 
       
   587 EXPORT_C TInt RChunk::CreateLocal(TInt aSize,TInt aMaxSize,TOwnerType aType)
       
   588 /**
       
   589 Creates a local chunk.
       
   590 
       
   591 The chunk is local to the process creating it; i.e. it is private to the process 
       
   592 creating it and is not intended for access by other user processes.
       
   593 
       
   594 aMaxSize specifies the maximum size of the chunk and aSize specifies the number 
       
   595 of bytes to be committed on creation of the chunk. Both values are rounded 
       
   596 up to the next nearest processor page boundary value if they are not already 
       
   597 on a processor page boundary.
       
   598 
       
   599 The committed region always starts at the bottom of the reserved region.
       
   600 
       
   601 By default, ownership of this chunk handle is vested in the current process. 
       
   602 Ownership of the chunk handle can be vested in the current thread by passing 
       
   603 EOwnerThread as the third parameter to this function. 
       
   604 
       
   605 @param aSize    The number of bytes committed to this chunk.
       
   606 @param aMaxSize The maximum size to which the reserved region of this chunk 
       
   607                 can grow.
       
   608 @param aType    An enumeration whose enumerators define the ownership of this 
       
   609                 chunk handle. If not explicitly specified, EOwnerProcess is
       
   610                 taken as default.
       
   611 
       
   612 @return KErrNone if successful, otherwise another of the system-wide error 
       
   613         codes.
       
   614 
       
   615 @panic USER 99  if aMaxSize is negative.
       
   616 @panic USER 100 if aSize is negative.
       
   617 @panic USER 101 if aSize is greater than or equal to the supplied
       
   618        value of aMaxSize.
       
   619 */
       
   620 	{
       
   621 	TChunkCreateInfo createInfo;
       
   622 	createInfo.SetNormal(aSize, aMaxSize);
       
   623 	createInfo.SetOwner(aType);
       
   624 	return Create(createInfo);
       
   625 	}
       
   626 
       
   627 
       
   628 
       
   629 
       
   630 EXPORT_C TInt RChunk::CreateLocalCode(TInt aSize,TInt aMaxSize,TOwnerType aType)
       
   631 /**
       
   632 Creates a user writable chunk that is marked by the kernel as containing code.
       
   633 
       
   634 The chunk is local to the process creating it, i.e. it is private to the process 
       
   635 creating it and is not intended for access by other user processes.
       
   636 
       
   637 On systems using a Harvard cache, this type of chunk removes the need to flush 
       
   638 the instruction cache (I-Cache) on a context switch. However, the instruction 
       
   639 Translation Look-aside Buffer (ITLB) still needs to be flushed when switching 
       
   640 to or from a process with one of these chunks in its address space.  Systems with
       
   641 a dynamic branch predictor may also need to flush their branch target buffer when
       
   642 switching from one process using this type of chunk to another.
       
   643 
       
   644 @param aSize    The number of bytes committed to this chunk.
       
   645 @param aMaxSize The maximum size to which the reserved region of this chunk 
       
   646                 can grow. 
       
   647 @param aType    An enumeration whose enumerators define the ownership of this 
       
   648                 chunk handle. If not explicitly specified, EOwnerProcess is
       
   649                 taken as default.
       
   650 
       
   651 @return KErrNone if successful, otherwise another of the system-wide error 
       
   652         codes.
       
   653 
       
   654 @panic USER 99  if aMaxSize is negative.
       
   655 @panic USER 100 if aSize is negative.
       
   656 @panic USER 101 if aSize is greater than or equal to the supplied
       
   657        value of aMaxSize.
       
   658 
       
   659 @see UserHeap::ChunkHeap
       
   660 @see User::IMB_Range
       
   661 */
       
   662 	{
       
   663 	TChunkCreateInfo createInfo;
       
   664 	createInfo.SetCode(aSize, aMaxSize);
       
   665 	createInfo.SetOwner(aType);
       
   666 	return Create(createInfo);
       
   667 	}
       
   668 
       
   669 
       
   670 
       
   671 
       
   672 EXPORT_C TInt RChunk::CreateGlobal(const TDesC &aName,TInt aSize,TInt aMaxSize,TOwnerType aType)
       
   673 /**
       
   674 Creates a global chunk.
       
   675 
       
   676 The chunk is global; i.e. it is potentially visible to all processes and is
       
   677 intended for access by other user processes.
       
   678 
       
   679 aMaxSize specifies the maximum size of the chunk and aSize specifies the number 
       
   680 of bytes to be committed on creation of the chunk. Both values are rounded 
       
   681 up to the next nearest processor page boundary value ,if they are not already 
       
   682 on a processor page boundary value.
       
   683 
       
   684 The committed region always starts at the bottom of the reserved region.
       
   685 
       
   686 The descriptor aName contains the name to be assigned to this global chunk. If
       
   687 this name is empty, the chunk will be anonymous. Anonymous chunks cannot be
       
   688 accessed by other processes unless the creator explicitly passes them a handle
       
   689 to the chunk - this can be used to transfer large amounts of data between
       
   690 processes in a secure fashion.
       
   691 
       
   692 By default, ownership of this chunk handle is vested in the current process. 
       
   693 Ownership of the chunk handle can be vested in the current thread by passing 
       
   694 EOwnerThread as the third parameter to this function.
       
   695 
       
   696 @param aName    A reference to a descriptor containing the name to be assigned 
       
   697                 to this global chunk. The length of the descriptor must be no
       
   698                 greater than that allowed for a TKName type.
       
   699 @param aSize    The number of bytes committed to this chunk.
       
   700 @param aMaxSize The maximum size to which the reserved region of this chunk 
       
   701                 can grow. 
       
   702 @param aType    An enumeration whose enumerators define the ownership of this 
       
   703                 chunk handle. If not explicitly specified, EOwnerProcess is taken
       
   704                 as default.
       
   705 
       
   706 @return KErrNone if successful, otherwise another of the system error codes.
       
   707 
       
   708 @panic USER 99  if aMaxSize is negative.
       
   709 @panic USER 100 if aSize is negative.
       
   710 @panic USER 101 if aSize is greater than or equal to the supplied
       
   711        value of aMaxSize.
       
   712 */
       
   713 	{
       
   714 	TChunkCreateInfo createInfo;
       
   715 	createInfo.SetNormal(aSize, aMaxSize);
       
   716 	createInfo.SetGlobal(aName);
       
   717 	createInfo.SetOwner(aType);
       
   718 	return Create(createInfo);
       
   719 	}
       
   720 
       
   721 
       
   722 
       
   723 
       
   724 EXPORT_C TInt RChunk::CreateDoubleEndedLocal(TInt aInitialBottom, TInt aInitialTop,TInt aMaxSize,TOwnerType aType)
       
   725 /**
       
   726 Creates a local, double ended, chunk.
       
   727 
       
   728 The chunk is local to the process creating it; i.e. it is private to
       
   729 the process creating it and is not intended for access by other
       
   730 user processes.
       
   731 
       
   732 The committed region of a double ended chunk can be any contiguous subset 
       
   733 of the reserved region.
       
   734 
       
   735 aMaxSize specifies the maximum size of the chunk.
       
   736 
       
   737 The difference between aInitialTop and aInitialBottom gives the number of 
       
   738 bytes to be committed, on creation of the chunk; aInitialBottom gives the 
       
   739 offset of the bottom of the committed region from the base of the chunk's 
       
   740 reserved region; aInitialTop gives the offset of the top of the committed 
       
   741 region from the base of the chunk's reserved region.
       
   742 
       
   743 Both aInitialBottom and aInitialTop are rounded up to the next nearest
       
   744 processor page boundary value, if they are not already on
       
   745 a processor page boundary value.
       
   746 
       
   747 By default, ownership of this chunk handle is vested in the current process. 
       
   748 Ownership of the chunk handle can be vested in the current thread by passing 
       
   749 EOwnerThread as the third parameter to this function.
       
   750 
       
   751 Note that:
       
   752 
       
   753 1. the lowest valid address in a double ended chunk is the sum of the base of 
       
   754    the chunk's reserved region plus the adjusted value of aInitialBottom
       
   755 
       
   756 2. the highest valid address in a double ended chunk is the the sum of the base 
       
   757    of the chunk's reserved region plus the adjusted value of aInitialTop - 1.
       
   758 
       
   759 @param aInitialBottom The offset of the bottom of the new committed region 
       
   760                       from the base of the chunk's reserved region.
       
   761 @param aInitialTop    The offset of the top of the new committed region from
       
   762                       the  base of the chunk's reserved region. 
       
   763 @param aMaxSize       The maximum size to which the reserved region of
       
   764                       this chunk can grow.
       
   765 @param aType          An enumeration whose enumerators define the ownership of
       
   766                       this chunk handle. If not explicitly specified,
       
   767                       EOwnerProcess is taken as default.
       
   768                       
       
   769 @return KErrNone if successful, otherwise another of the system error codes.
       
   770 
       
   771 @panic USER 99  if aMaxSize is negative.
       
   772 @panic USER 120 if aInitialBottom is negative.
       
   773 @panic USER 121 if aInitialTop is negative.
       
   774 @panic USER 122 if aInitialBottom is greater than the supplied value
       
   775        of aInitialTop.
       
   776 @panic USER 123 if aInitialTop is greater than the supplied value of aMaxSize.
       
   777 */
       
   778 	{
       
   779 	TChunkCreateInfo createInfo;
       
   780 	createInfo.SetDoubleEnded(aInitialBottom, aInitialTop, aMaxSize);
       
   781 	createInfo.SetOwner(aType);
       
   782 	return Create(createInfo);
       
   783 	}
       
   784 
       
   785 
       
   786 
       
   787 
       
   788 EXPORT_C TInt RChunk::CreateDoubleEndedGlobal(const TDesC &aName,TInt aInitialBottom,TInt aInitialTop,TInt aMaxSize,TOwnerType aType)
       
   789 /**
       
   790 Creates a global, double ended, chunk.
       
   791 
       
   792 The chunk is global; i.e. it is visible to all processes and is intended
       
   793 for access by other user processes.
       
   794 
       
   795 The committed region of a double ended chunk can be any contiguous subset 
       
   796 of the reserved region.
       
   797 
       
   798 aMaxSize specifies the maximum size of the chunk.
       
   799 
       
   800 The difference between aInitialTop and aInitialBottom gives the number of 
       
   801 bytes to be committed, on creation of the chunk; aInitialBottom gives the 
       
   802 offset of the bottom of the committed region from the base of the chunk's 
       
   803 reserved region; aInitialTop gives the offset of the top of the committed 
       
   804 region from the base of the chunk's reserved region.
       
   805 
       
   806 Both aInitialBottom and aInitialTop are rounded up to the next nearest
       
   807 processor page boundary value, if they are not already on a processor page
       
   808 boundary value.
       
   809 
       
   810 The descriptor aName contains the name to be assigned to this global chunk.
       
   811 
       
   812 By default, ownership of this chunk handle is vested in the current process. 
       
   813 Ownership of the chunk handle can be vested in the current thread by passing 
       
   814 EOwnerThread as the third parameter to this function. 
       
   815 
       
   816 Note that:
       
   817 
       
   818 1. the lowest valid address in a double ended chunk is the sum of the base of 
       
   819    the chunk's reserved region plus the adjusted value of aInitialBottom
       
   820 
       
   821 2. the highest valid address in a double ended chunk is the the sum of the base 
       
   822    of the chunk's reserved region plus the adjusted value of aInitialTop - 1.
       
   823 
       
   824 @param aName          A reference to a descriptor containing the name to be
       
   825                       assigned to this global chunk. The length of
       
   826                       the descriptor must be no greater than that allowed for
       
   827                       a TKName type.
       
   828 @param aInitialBottom The offset of the bottom of the new committed region 
       
   829                       from the base of the chunk's reserved region.
       
   830 @param aInitialTop    The offset of the top of the new committed region from
       
   831                       the base of the chunk's reserved region. 
       
   832 @param aMaxSize       The maximum size to which the reserved region of
       
   833                       this chunk can grow. 
       
   834 @param aType          An enumeration whose enumerators define the ownership of
       
   835                       this chunk handle. If not explicitly specified,
       
   836                       EOwnerProcess is taken as default.
       
   837 
       
   838 @return KErrNone if successful, otherwise another of the system error codes.
       
   839 
       
   840 @panic USER 99  if aMaxSize is negative.
       
   841 @panic USER 120 if aInitialBottom is negative.
       
   842 @panic USER 121 if aInitialTop is negative.
       
   843 @panic USER 122 if aInitialBottom is greater than the supplied value
       
   844        of aInitialTop.
       
   845 @panic USER 123 if aInitialTop is greater than the supplied value of aMaxSize.
       
   846 @panic USER 163 if aName is empty.
       
   847 */
       
   848 	{
       
   849 	TChunkCreateInfo createInfo;
       
   850 	createInfo.SetDoubleEnded(aInitialBottom, aInitialTop, aMaxSize);
       
   851 	createInfo.SetGlobal(aName);
       
   852 	createInfo.SetOwner(aType);
       
   853 	return Create(createInfo);
       
   854 	}
       
   855 
       
   856 
       
   857 
       
   858 
       
   859 EXPORT_C TInt RChunk::CreateDisconnectedLocal(TInt aInitialBottom, TInt aInitialTop,TInt aMaxSize,TOwnerType aType)
       
   860 /**
       
   861 Creates a local, disconnected chunk.
       
   862 
       
   863 The chunk is local to the process creating it; i.e. it is private to
       
   864 the process creating it and is not intended for access by other
       
   865 user processes.
       
   866 
       
   867 A disconnected chunk has a committed region consisting of an arbitrary set
       
   868 of MMU pages within the reserved region, i.e. each page-sized address range
       
   869 within the reserved region which begins on a page boundary may be committed
       
   870 independently.
       
   871 
       
   872 aMaxSize specifies the maximum size of the chunk.
       
   873 
       
   874 The difference between aInitialTop and aInitialBottom gives the number of 
       
   875 bytes to be committed, on creation of the chunk; aInitialBottom gives the 
       
   876 offset of the bottom of the committed region from the base of the chunk's 
       
   877 reserved region; aInitialTop gives the offset of the top of the committed 
       
   878 region from the base of the chunk's reserved region.
       
   879 
       
   880 Both aInitialBottom and aInitialTop are rounded up to the next nearest
       
   881 processor page boundary value, if they are not already on
       
   882 a processor page boundary value.
       
   883 
       
   884 By default, ownership of this chunk handle is vested in the current process. 
       
   885 Ownership of the chunk handle can be vested in the current thread by passing 
       
   886 EOwnerThread as the third parameter to this function.
       
   887 
       
   888 @param aInitialBottom The offset of the bottom of the new committed region 
       
   889                       from the base of the chunk's reserved region.
       
   890 @param aInitialTop    The offset of the top of the new committed region from
       
   891                       the  base of the chunk's reserved region. 
       
   892 @param aMaxSize       The maximum size to which the reserved region of
       
   893                       this chunk can grow.
       
   894 @param aType          An enumeration whose enumerators define the ownership of
       
   895                       this chunk handle. If not explicitly specified,
       
   896                       EOwnerProcess is taken as default.
       
   897                       
       
   898 @return KErrNone if successful, otherwise another of the system error codes.
       
   899 
       
   900 @panic USER 99  if aMaxSize is negative.
       
   901 @panic USER 120 if aInitialBottom is negative.
       
   902 @panic USER 121 if aInitialTop is negative.
       
   903 @panic USER 122 if aInitialBottom is greater than the supplied value
       
   904        of aInitialTop.
       
   905 @panic USER 123 if aInitialTop is greater than the supplied value of aMaxSize.
       
   906 */
       
   907 	{
       
   908 	TChunkCreateInfo createInfo;
       
   909 	createInfo.SetDisconnected(aInitialBottom, aInitialTop, aMaxSize);
       
   910 	createInfo.SetOwner(aType);
       
   911 	return Create(createInfo);
       
   912 	}
       
   913 
       
   914 
       
   915 
       
   916 
       
   917 EXPORT_C TInt RChunk::CreateDisconnectedGlobal(const TDesC &aName,TInt aInitialBottom,TInt aInitialTop,TInt aMaxSize,TOwnerType aType)
       
   918 /**
       
   919 Creates a global, disconnected, chunk.
       
   920 
       
   921 The chunk is global; i.e. it is visible to all processes and is intended
       
   922 for access by other user processes.
       
   923 
       
   924 A disconnected chunk has a committed region consisting of an arbitrary set
       
   925 of MMU pages within the reserved region, i.e. each page-sized address range
       
   926 within the reserved region which begins on a page boundary may be committed
       
   927 independently.
       
   928 
       
   929 aMaxSize specifies the maximum size of the chunk.
       
   930 
       
   931 The difference between aInitialTop and aInitialBottom gives the number of 
       
   932 bytes to be committed, on creation of the chunk; aInitialBottom gives the 
       
   933 offset of the bottom of the committed region from the base of the chunk's 
       
   934 reserved region; aInitialTop gives the offset of the top of the committed 
       
   935 region from the base of the chunk's reserved region.
       
   936 
       
   937 Both aInitialBottom and aInitialTop are rounded up to the next nearest
       
   938 processor page boundary value, if they are not already on a processor page
       
   939 boundary value.
       
   940 
       
   941 The descriptor aName contains the name to be assigned to this global chunk.
       
   942 
       
   943 By default, ownership of this chunk handle is vested in the current process. 
       
   944 Ownership of the chunk handle can be vested in the current thread by passing 
       
   945 EOwnerThread as the third parameter to this function. 
       
   946 
       
   947 @param aName          A reference to a descriptor containing the name to be
       
   948                       assigned to this global chunk. The length of
       
   949                       the descriptor must be no greater than that allowed for
       
   950                       a TKName type.
       
   951 @param aInitialBottom The offset of the bottom of the new committed region 
       
   952                       from the base of the chunk's reserved region.
       
   953 @param aInitialTop    The offset of the top of the new committed region from
       
   954                       the base of the chunk's reserved region. 
       
   955 @param aMaxSize       The maximum size to which the reserved region of
       
   956                       this chunk can grow. 
       
   957 @param aType          An enumeration whose enumerators define the ownership of
       
   958                       this chunk handle. If not explicitly specified,
       
   959                       EOwnerProcess is taken as default.
       
   960 
       
   961 @return KErrNone if successful, otherwise another of the system error codes.
       
   962 
       
   963 @panic USER 99  if aMaxSize is negative.
       
   964 @panic USER 120 if aInitialBottom is negative.
       
   965 @panic USER 121 if aInitialTop is negative.
       
   966 @panic USER 122 if aInitialBottom is greater than the supplied value
       
   967        of aInitialTop.
       
   968 @panic USER 123 if aInitialTop is greater than the supplied value of aMaxSize.
       
   969 */
       
   970 	{
       
   971 	TChunkCreateInfo createInfo;
       
   972 	createInfo.SetDisconnected(aInitialBottom, aInitialTop, aMaxSize);
       
   973 	createInfo.SetGlobal(aName);
       
   974 	createInfo.SetOwner(aType);
       
   975 	return Create(createInfo);
       
   976 	}
       
   977 
       
   978 
       
   979 /**
       
   980 Creates a chunk of the type specified by the parameter aCreateInfo.
       
   981 
       
   982 @param aCreate	A reference to a TChunkCreateInfo object specifying the type of 
       
   983 				chunk to create.
       
   984 
       
   985 @return KErrNone on success, otherwise on of the system wide error codes.
       
   986 
       
   987 @panic USER 99  if the specified maximum size is negative.
       
   988 @panic USER 120 if any specified initial bottom is negative.
       
   989 @panic USER 121 if any specified initial top is negative.
       
   990 @panic USER 122 if any specified initial bottom is greater than the supplied value
       
   991        for the intial top.
       
   992 @panic USER 123 if any specified initial top is greater than the supplied value for the maximum size.
       
   993 @panic USER 214 if any of the specified attributes is invalid.
       
   994 @panic USER 215 if the version number of aCreateInfo is invalid.
       
   995 */
       
   996 EXPORT_C TInt RChunk::Create(TChunkCreateInfo& aCreateInfo)
       
   997 	{
       
   998 	// Verify the version number of TChunkCreateInfo is supported
       
   999 	__ASSERT_ALWAYS(aCreateInfo.iVersionNumber < TChunkCreateInfo::ESupportedVersions, 
       
  1000 					Panic(EChkCreateInvalidVersion));
       
  1001 
       
  1002 	TUint mapping = aCreateInfo.iType & ~TChunkCreate::ECode;
       
  1003 	TBool shouldBeNamed = 	aCreateInfo.iGlobal || 
       
  1004 							(aCreateInfo.iAttributes & TChunkCreate::ELocalNamed);
       
  1005 	__ASSERT_ALWAYS(mapping <= (TUint)TChunkCreate::ECache, Panic(EChkCreateInvalidType));
       
  1006 	__ASSERT_ALWAYS(!(aCreateInfo.iType & TChunkCreate::ECode) || !aCreateInfo.iGlobal, 
       
  1007 					Panic(EChkCreateInvalidType));
       
  1008 	__ASSERT_ALWAYS((!shouldBeNamed && aCreateInfo.iName == NULL) || 
       
  1009 					(shouldBeNamed && aCreateInfo.iName),
       
  1010 					Panic(EChkCreateInvalidName));
       
  1011 	__ASSERT_ALWAYS(aCreateInfo.iMaxSize >= 0, Panic(EChkCreateMaxSizeNegative));
       
  1012 	__ASSERT_ALWAYS(!(aCreateInfo.iAttributes & ~TChunkCreate::EChunkCreateAttMask), Panic(EChkCreateInvalidAttribute));
       
  1013 	if(mapping == TChunkCreate::ENormal)
       
  1014 		{
       
  1015 		// 'normal' chunks have different semantics for the meanings of
       
  1016 		// aInitialBottom and aInitialTop
       
  1017 		__ASSERT_ALWAYS(!aCreateInfo.iInitialBottom, Panic(EChkCreateInvalidBottom));
       
  1018 		__ASSERT_ALWAYS(aCreateInfo.iInitialTop >= 0, Panic(EChkCreateSizeNotPositive));
       
  1019 		__ASSERT_ALWAYS(aCreateInfo.iInitialTop <= aCreateInfo.iMaxSize, Panic(EChkCreateMaxLessThanMin));
       
  1020 		}
       
  1021 	else
       
  1022 		{
       
  1023 		__ASSERT_ALWAYS(aCreateInfo.iInitialBottom >= 0, Panic(EChkCreateBottomNegative));
       
  1024 		__ASSERT_ALWAYS(aCreateInfo.iInitialTop >= 0, Panic(EChkCreateTopNegative));
       
  1025 		__ASSERT_ALWAYS(aCreateInfo.iInitialTop >= aCreateInfo.iInitialBottom, Panic(EChkCreateTopLessThanBottom));
       
  1026 		__ASSERT_ALWAYS(aCreateInfo.iInitialTop <= aCreateInfo.iMaxSize, Panic(EChkCreateTopBiggerThanMax));
       
  1027 		}
       
  1028 
       
  1029 	TChunkCreate info;
       
  1030 	info.iAtt = aCreateInfo.iAttributes | (TUint)aCreateInfo.iType;
       
  1031 	info.iAtt |= (aCreateInfo.iGlobal)? TChunkCreate::EGlobal : TChunkCreate::ELocal;	// Add the global attribute
       
  1032 	info.iForceFixed = EFalse;
       
  1033 	info.iInitialBottom = aCreateInfo.iInitialBottom;
       
  1034 	info.iInitialTop = aCreateInfo.iInitialTop;
       
  1035 	info.iMaxSize = aCreateInfo.iMaxSize;
       
  1036 	info.iClearByte = aCreateInfo.iClearByte;
       
  1037 
       
  1038 	TDesC8* ptrName = NULL;
       
  1039 	TBuf8<KMaxKernelName> name8;
       
  1040 	if(aCreateInfo.iName)
       
  1041 		{
       
  1042 		TInt r = User::ValidateName(*aCreateInfo.iName);
       
  1043 		if(KErrNone!=r)
       
  1044 			return r;
       
  1045 		name8.Copy(*aCreateInfo.iName);
       
  1046 		ptrName = &name8;
       
  1047 		}
       
  1048 
       
  1049 	return SetReturnedHandle(Exec::ChunkCreate(aCreateInfo.iOwnerType, ptrName, info),*this);	
       
  1050 	}
       
  1051 
       
  1052 
       
  1053 EXPORT_C TInt RChunk::OpenGlobal(const TDesC &aName,TBool isReadOnly,TOwnerType aType)
       
  1054 /**
       
  1055 Opens a handle to a specific named global chunk.
       
  1056 
       
  1057 Full read/write access can be allowed or access can be limited to read only.
       
  1058 
       
  1059 By default, ownership of this process handle is vested in the current process, 
       
  1060 but can be vested in the current thread by passing EOwnerThread as the second 
       
  1061 parameter to this function.
       
  1062 
       
  1063 @param aName      A reference to the descriptor containing the name of
       
  1064                   the chunk to be opened.
       
  1065 @param isReadOnly This is currently not implemented and setting it to ETrue
       
  1066 				  will have no effect.
       
  1067 				  (Intended implementation will be as below:
       
  1068 				  Defines the type of access to the chunk: Specify ETrue if 
       
  1069                   access is limited to read only, otherwise specify EFalse
       
  1070                   for full read/write access.)
       
  1071 @param aType      An enumeration whose enumerators define ownership of
       
  1072                   this chunk handle. If not explicitly specified,
       
  1073                   EOwnerProcess is taken as default.
       
  1074 
       
  1075 @return KErrNone if successful, otherwise another of the system error codes.
       
  1076 */
       
  1077 	{
       
  1078 	(void) isReadOnly; // This is not currently used
       
  1079 	return OpenByName(aName,aType,EChunk);
       
  1080 	}
       
  1081 
       
  1082 
       
  1083 
       
  1084 
       
  1085 /**
       
  1086 Opens a handle to a chunk using a handle number sent by a client
       
  1087 to a server.
       
  1088 
       
  1089 This function is called by the server.
       
  1090 
       
  1091 @param aMessage   The message pointer.
       
  1092 @param aParam     An index specifying which of the four message arguments
       
  1093                   contains the handle number.
       
  1094 @param isReadOnly This is currently not implemented and setting it to ETrue
       
  1095 				  will have no effect.
       
  1096 				  (Intended implementation will be as below:
       
  1097 				  Defines the type of access to the chunk: Specify ETrue if 
       
  1098                   access is limited to read only, otherwise specify EFalse
       
  1099                   for full read/write access.)
       
  1100 @param aType      An enumeration whose enumerators define the ownership of this 
       
  1101                   chunk handle. If not explicitly specified, EOwnerProcess is
       
  1102                   taken as default. 
       
  1103                 
       
  1104 @return KErrNone, if successful;
       
  1105         KErrArgument, if the value of aParam is outside the range 0-3;
       
  1106         KErrBadHandle, if not a valid handle;
       
  1107         otherwise one of the other system-wide error codes.
       
  1108 */
       
  1109 EXPORT_C TInt RChunk::Open(RMessagePtr2 aMessage,TInt aParam,TBool isReadOnly,TOwnerType aType)
       
  1110 	{
       
  1111 	(void) isReadOnly; // This is not currently used
       
  1112 	return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),EChunk,aParam,aType));
       
  1113 	}
       
  1114 
       
  1115 
       
  1116 
       
  1117 
       
  1118 /**
       
  1119 Opens a handle to a chunk using a handle number passed as an
       
  1120 environment data item to the child process during the creation of
       
  1121 that child process.
       
  1122 
       
  1123 Note that this function can only be called successfully once.
       
  1124 
       
  1125 @param aArgumentIndex An index that identifies the slot in the process
       
  1126                       environment data that contains the handle number. This is
       
  1127                       a value relative to zero, i.e. 0 is the first item/slot.
       
  1128                       This can range from 0 to 15.
       
  1129 
       
  1130 @param aOwnerType     An enumeration whose enumerators define the ownership of
       
  1131                       this chunk handle. If not explicitly specified,
       
  1132                       EOwnerProcess is taken as default.
       
  1133 
       
  1134 @return KErrNone, if successful; 
       
  1135         KErrNotFound, if the slot indicated by aArgumentIndex is empty;
       
  1136         KErrArgument, if the slot does not contain a Semaphore handle;
       
  1137         otherwise one of the other system-wide error codes.
       
  1138         
       
  1139 @see RProcess::SetParameter()
       
  1140 */
       
  1141 EXPORT_C TInt RChunk::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
       
  1142 	{
       
  1143 	return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, EChunk, aOwnerType));
       
  1144 	}
       
  1145 
       
  1146 
       
  1147 
       
  1148 
       
  1149 
       
  1150 EXPORT_C TInt RChunk::SetRestrictions(TUint aFlags)
       
  1151 /**
       
  1152 Sets or removes restrictions on the ability of the chunk to change.
       
  1153 
       
  1154 For example, to adjust, commit etc
       
  1155 
       
  1156 @param aFlags One of the values defined by TRestrictions.
       
  1157 
       
  1158 @see RChunk::TRestrictions()
       
  1159 */
       
  1160 	{
       
  1161 	return Exec::ChunkSetRestrictions(iHandle,aFlags);
       
  1162 	}
       
  1163 
       
  1164 
       
  1165 
       
  1166 
       
  1167 EXPORT_C TInt RChunk::Adjust(TInt aNewSize) const
       
  1168 /**
       
  1169 Changes the number of bytes committed to the chunk.
       
  1170 
       
  1171 This value is always rounded up to the next nearest processor page boundary.
       
  1172 
       
  1173 @param aNewSize The number of bytes to be committed to this chunk.
       
  1174 
       
  1175 @return KErrNone if successful, otherwise another of the system error codes.
       
  1176 
       
  1177 @panic USER 102 if aNewSize is negative.
       
  1178 */
       
  1179 	{
       
  1180 
       
  1181 	__ASSERT_ALWAYS(aNewSize>=0,Panic(EChkAdjustNewSizeNegative));
       
  1182 	return Exec::ChunkAdjust(iHandle,EChunkAdjust,aNewSize,0);
       
  1183 	}
       
  1184 
       
  1185 
       
  1186 
       
  1187 
       
  1188 EXPORT_C TInt RChunk::AdjustDoubleEnded(TInt aBottom, TInt aTop) const
       
  1189 /**
       
  1190 Changes the number of bytes and the position of this double ended
       
  1191 chunk's committed region.
       
  1192 
       
  1193 The difference between aTop and aBottom gives the new size of the committed 
       
  1194 region; aBottom gives the offset of the bottom of the committed region from 
       
  1195 the base of the chunk's reserved region.
       
  1196 
       
  1197 Both aBottom and aTop are rounded up to the next nearest processor
       
  1198 page boundary.
       
  1199 
       
  1200 The function fails if this chunk is not a double ended chunk; for a standard 
       
  1201 chunk, use the Adjust() function.
       
  1202 
       
  1203 Note that if the initial and final committed regions intersect, the contents 
       
  1204 of the intersection are unchanged. Other parts of the committed region have 
       
  1205 undefined contents.
       
  1206 
       
  1207 Note also that:
       
  1208 
       
  1209 1. the lowest valid address in a double ended chunk is the sum of the base of 
       
  1210    the chunk's reserved region plus the adjusted value of aBottom
       
  1211 
       
  1212 2. the highest valid address in a double ended chunk is the the sum of the base 
       
  1213    of the chunk's reserved region plus the adjusted value of aTop - 1.
       
  1214 
       
  1215 @param aBottom The offset from the base of the chunk of the bottom of the 
       
  1216                committed region.
       
  1217 @param aTop    The offset from the base of the chunk of the top of the committed 
       
  1218                region.
       
  1219 
       
  1220 @return KErrNone if successful, otherwise another of the system error codes.
       
  1221 
       
  1222 @panic USER 124 if aBottom is negative.
       
  1223 @panic USER 125 if aTop is negative.
       
  1224 @panic USER 126 if aBottom is greater than the supplied value of aTop.
       
  1225 */
       
  1226 	{
       
  1227 	__ASSERT_ALWAYS(aBottom>=0,Panic(EChkAdjustBottomNegative));
       
  1228 	__ASSERT_ALWAYS(aTop>=0,Panic(EChkAdjustTopNegative));
       
  1229 	__ASSERT_ALWAYS(aTop>=aBottom,Panic(EChkAdjustTopLessThanBottom));
       
  1230 	return Exec::ChunkAdjust(iHandle,EChunkAdjustDoubleEnded,aBottom,aTop);
       
  1231 	}
       
  1232 
       
  1233 
       
  1234 
       
  1235 
       
  1236 EXPORT_C TInt RChunk::Commit(TInt aOffset, TInt aSize) const
       
  1237 /**
       
  1238 Commits memory to a disconnected chunk.
       
  1239 
       
  1240 Memory is committed in blocks of the MMU page size.
       
  1241 E.g. Commit(pageSize-1,2) which asks for the last byte of the first page
       
  1242 and the first byte of the second page and will result in the first 2 pages
       
  1243 in the chunk being committed.
       
  1244 For this reason it is best to only use values for aOffset and aSize which
       
  1245 are multiples of the MMU page size. This size can be obtained with the
       
  1246 following code.
       
  1247 @code
       
  1248 TInt pageSize;
       
  1249 HAL::Get(HAL::EMemoryPageSize,pageSize)
       
  1250 @endcode
       
  1251 
       
  1252 @param aOffset	The offset of the committed region from the base of the chunk's 
       
  1253                 reserved region.
       
  1254 @param aSize    The size of the committed region.
       
  1255 
       
  1256 @return KErrNone if successful, otherwise another of the system error codes.
       
  1257 
       
  1258 @panic USER 157 if anOffset is negative.
       
  1259 @panic USER 158 if aSize is negative.
       
  1260 */
       
  1261 	{
       
  1262 	__ASSERT_ALWAYS(aOffset>=0,Panic(EChkCommitOffsetNegative));
       
  1263 	__ASSERT_ALWAYS(aSize>=0,Panic(EChkCommitSizeNegative));
       
  1264 	return Exec::ChunkAdjust(iHandle,EChunkCommit,aOffset,aSize);
       
  1265 	}
       
  1266 
       
  1267 
       
  1268 
       
  1269 
       
  1270 EXPORT_C TInt RChunk::Allocate(TInt aSize) const
       
  1271 /**
       
  1272 Allocates and commits to a disconnected chunk.
       
  1273 
       
  1274 @param aSize The size of the committed region.
       
  1275 
       
  1276 @panic USER 159 if aSize is negative.
       
  1277 */
       
  1278 	{
       
  1279 	__ASSERT_ALWAYS(aSize>=0,Panic(EChkAllocateSizeNegative));
       
  1280 	return Exec::ChunkAdjust(iHandle,EChunkAllocate,aSize,0);
       
  1281 	}
       
  1282 
       
  1283 
       
  1284 
       
  1285 
       
  1286 EXPORT_C TInt RChunk::Decommit(TInt aOffset, TInt aSize) const
       
  1287 /**
       
  1288 Decommits memory from a disconnected chunk.
       
  1289 
       
  1290 Memory is decommitted in blocks of the MMU page size.
       
  1291 E.g. Decommit(pageSize-1,2) which asks for the last byte of the first page
       
  1292 and the first byte of the second page and will result in the first 2 pages
       
  1293 in the chunk being decommitted.
       
  1294 For this reason it is best to only use values for aOffset and aSize which
       
  1295 are multiples of the MMU page size. This size can be obtained with the
       
  1296 following code.
       
  1297 @code
       
  1298 TInt pageSize;
       
  1299 HAL::Get(HAL::EMemoryPageSize,pageSize)
       
  1300 @endcode
       
  1301 
       
  1302 @param aOffset The offset of the committed region from the base of the chunk's 
       
  1303                 reserved region;
       
  1304 @param aSize    The size of the committed region.
       
  1305 
       
  1306 @return KErrNone if successful, otherwise another of the system error codes.
       
  1307 
       
  1308 @panic USER 160 if anOffset is negative.
       
  1309 @panic USER 161 if aSize is negative.
       
  1310 */
       
  1311 	{
       
  1312 	__ASSERT_ALWAYS(aOffset>=0,Panic(EChkDecommitOffsetNegative));
       
  1313 	__ASSERT_ALWAYS(aSize>=0,Panic(EChkDecommitSizeNegative));
       
  1314 	return Exec::ChunkAdjust(iHandle,EChunkDecommit,aOffset,aSize);
       
  1315 	}
       
  1316 
       
  1317 
       
  1318 /* THIS IS A DELIBERATE NON DOXGEN STYLE TAG TO EXCLUDE THIS DOC FROM AUTO GENERATED DOCS
       
  1319 
       
  1320 Unlocks previously committed memory in a disconnected chunk.
       
  1321 
       
  1322 Unlocked memory is an intermediate state between committed and decommitted.
       
  1323 Whilst in this state, the memory must not be accessed in any way, and the
       
  1324 system is free to reclaim this RAM for other purposes, (it counts as free
       
  1325 system memory). A program may attempt to relock the memory with #Lock which,
       
  1326 when it succeeds, returns it to the committed state with its contents unchanged.
       
  1327 
       
  1328 This is intended for use in the implementation of memory caches for data
       
  1329 which can be regenerated from other sources. I.e. in situations when the
       
  1330 loss of cache contents is not a fatal condition.
       
  1331 
       
  1332 #Unlock may be used on memory which is already unlocked, in which case the memory
       
  1333 state is left unaltered. Attempting to unlock memory which is decommitted results
       
  1334 in an error.
       
  1335 
       
  1336 Unlocked memory may decommitted with #Decommit.
       
  1337 
       
  1338 Memory is unlocked in blocks of the MMU page size.
       
  1339 E.g. Unlock(pageSize-1,2) which asks for the last byte of the first page
       
  1340 and the first byte of the second page and will result in the first 2 pages
       
  1341 in the chunk being unlocked.
       
  1342 For this reason it is best to only use values for aOffset and aSize which
       
  1343 are multiples of the MMU page size. This size can be obtained with the
       
  1344 following code.
       
  1345 @code
       
  1346 TInt pageSize;
       
  1347 HAL::Get(HAL::EMemoryPageSize,pageSize)
       
  1348 @endcode
       
  1349 
       
  1350 @param aOffset The offset of the committed region from the base of the chunk's 
       
  1351                reserved region;
       
  1352 @param aSize   The size of the committed region.
       
  1353 
       
  1354 @return KErrNone if successful, otherwise another of the system error codes.
       
  1355 
       
  1356 @panic USER 160 if anOffset is negative.
       
  1357 @panic USER 161 if aSize is negative.
       
  1358 
       
  1359 @see RChunk::Lock
       
  1360 
       
  1361 @internalTechnology
       
  1362 */
       
  1363 EXPORT_C TInt RChunk::Unlock(TInt aOffset, TInt aSize)
       
  1364 	{
       
  1365 	__ASSERT_ALWAYS(aOffset>=0,Panic(EChkDecommitOffsetNegative));
       
  1366 	__ASSERT_ALWAYS(aSize>=0,Panic(EChkDecommitSizeNegative));
       
  1367 	return Exec::ChunkAdjust(iHandle,EChunkUnlock,aOffset,aSize);
       
  1368 	}
       
  1369 
       
  1370 /* THIS IS A DELIBERATE NON DOXGEN STYLE TAG TO EXCLUDE THIS DOC FROM AUTO GENERATED DOCS
       
  1371 
       
  1372 Locks memory in a disconnected chunk.
       
  1373 
       
  1374 This attempts to reverse the action of #Unlock and return memory to the committed
       
  1375 state. If any RAM in the region had been previously reclaimed by the system,
       
  1376 then this function fails with KErrNotFound and the whole region is decommited.
       
  1377 
       
  1378 #Lock may be used on memory which is already committed, in which case the memory
       
  1379 state is left unaltered. Attempting to lock memory which is decommitted results in an
       
  1380 error.
       
  1381 
       
  1382 Memory is locked in blocks of the MMU page size.
       
  1383 E.g. Lock(pageSize-1,2) which asks for the last byte of the first page
       
  1384 and the first byte of the second page and will result in the first 2 pages
       
  1385 in the chunk being locked.
       
  1386 For this reason it is best to only use values for aOffset and aSize which
       
  1387 are multiples of the MMU page size. This size can be obtained with the
       
  1388 following code.
       
  1389 @code
       
  1390 TInt pageSize;
       
  1391 HAL::Get(HAL::EMemoryPageSize,pageSize)
       
  1392 @endcode
       
  1393 
       
  1394 @param aOffset The offset of the unlocked region from the base of the chunk's 
       
  1395                reserved region.
       
  1396 @param aSize   The size of the unlocked region.
       
  1397 
       
  1398 @return KErrNone if successful, otherwise another of the system error codes.
       
  1399 
       
  1400 @panic USER 160 if anOffset is negative.
       
  1401 @panic USER 161 if aSize is negative.
       
  1402 
       
  1403 @see RChunk::Unlock
       
  1404 
       
  1405 @internalTechnology
       
  1406 */
       
  1407 EXPORT_C TInt RChunk::Lock(TInt aOffset, TInt aSize)
       
  1408 	{
       
  1409 	__ASSERT_ALWAYS(aOffset>=0,Panic(EChkDecommitOffsetNegative));
       
  1410 	__ASSERT_ALWAYS(aSize>=0,Panic(EChkDecommitSizeNegative));
       
  1411 	return Exec::ChunkAdjust(iHandle,EChunkLock,aOffset,aSize);
       
  1412 	}
       
  1413 
       
  1414 
       
  1415 /**
       
  1416 This can be used to determine whether the data for the chunk is demand paged
       
  1417 or not.
       
  1418 
       
  1419 @return ETrue if the data for the chunk is demand paged, EFalse otherwise.
       
  1420 */
       
  1421 EXPORT_C TBool RChunk::IsPaged() const
       
  1422 	{
       
  1423 	return Exec::ChunkIsPaged(iHandle);
       
  1424 	}
       
  1425 
       
  1426 
       
  1427 /**
       
  1428 Opens a handle to an LDD factory object by name.
       
  1429 
       
  1430 @param aName	The name of the LDD factory object to be opened.
       
  1431 @param aType	An enumeration whose enumerators define the ownership of this 
       
  1432 				LDD factory object handle.
       
  1433 
       
  1434 @return KErrNone, if successful; otherwise one of the other system wide error codes.
       
  1435 */
       
  1436 EXPORT_C TInt RDevice::Open(const TDesC &aName,TOwnerType aType)
       
  1437 	{
       
  1438 	return OpenByName(aName,aType,ELogicalDevice);
       
  1439 	}
       
  1440 
       
  1441 EXPORT_C TInt RBusLogicalChannel::DoCreate(const TDesC& aLogicalDevice, const TVersion& aVer, TInt aUnit, const TDesC* aPhysicalDevice, const TDesC8* anInfo, TInt aType)
       
  1442 //
       
  1443 // Call the kernel to create a channel on a device.
       
  1444 //
       
  1445 	{
       
  1446 	TInt r = User::ValidateName(aLogicalDevice);
       
  1447 	if(KErrNone!=r)
       
  1448 		return r;
       
  1449 	TBuf8<KMaxKernelName> name8;
       
  1450 	name8.Copy(aLogicalDevice);
       
  1451 
       
  1452 	TBuf8<KMaxKernelName> physicalDeviceName;
       
  1453 	TChannelCreateInfo8 info;
       
  1454 	info.iVersion=aVer;
       
  1455 	info.iUnit=aUnit;
       
  1456 	if(aPhysicalDevice)
       
  1457 		{
       
  1458 		physicalDeviceName.Copy(*aPhysicalDevice);
       
  1459 		info.iPhysicalDevice = &physicalDeviceName;
       
  1460 		}
       
  1461 	else
       
  1462 		info.iPhysicalDevice = NULL;
       
  1463 	info.iInfo=anInfo;
       
  1464 
       
  1465 	return SetReturnedHandle(Exec::ChannelCreate(name8, info, aType),*this);
       
  1466 	}
       
  1467 
       
  1468 
       
  1469 
       
  1470 
       
  1471 /**
       
  1472 Opens a handle to a logical channel using a handle number sent by a client
       
  1473 to a server.
       
  1474 
       
  1475 This function is called by the server.
       
  1476 
       
  1477 @param aMessage The message pointer.
       
  1478 @param aParam   An index specifying which of the four message arguments
       
  1479                 contains the handle number.
       
  1480 @param aType    An enumeration whose enumerators define the ownership of this 
       
  1481                 logical channel handle. If not explicitly specified,
       
  1482                 EOwnerProcess is taken as default. 
       
  1483                 
       
  1484 @return KErrNone, if successful;
       
  1485         KErrArgument, if the value of aParam is outside the range 0-3;
       
  1486         KErrBadHandle, if not a valid handle;
       
  1487         otherwise one of the other system-wide error codes.
       
  1488 */
       
  1489 EXPORT_C TInt RBusLogicalChannel::Open(RMessagePtr2 aMessage,TInt aParam,TOwnerType aType)
       
  1490 	{
       
  1491 	return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),ELogicalChannel,aParam,aType));
       
  1492 	}
       
  1493 
       
  1494 
       
  1495 
       
  1496 
       
  1497 /**
       
  1498 Opens a logical channel handle using a handle number passed as an
       
  1499 environment data item to the child process during the creation of
       
  1500 that child process.
       
  1501 
       
  1502 Note that this function can only be called successfully once.
       
  1503 
       
  1504 @param aArgumentIndex An index that identifies the slot in the process
       
  1505                       environment data that contains the handle number. This is
       
  1506                       a value relative to zero, i.e. 0 is the first item/slot.
       
  1507                       This can range from 0 to 15.
       
  1508 
       
  1509 @param aOwnerType     An enumeration whose enumerators define the ownership of
       
  1510                       this logical channel handle. If not explicitly specified,
       
  1511                       EOwnerProcess is taken as default.
       
  1512 
       
  1513 @return KErrNone, if successful; 
       
  1514         KErrNotFound, if the slot indicated by aArgumentIndex is empty;
       
  1515         KErrArgument, if the slot does not contain a logical channel handle;
       
  1516         otherwise one of the other system-wide error codes.
       
  1517 */
       
  1518 EXPORT_C TInt RBusLogicalChannel::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
       
  1519 	{
       
  1520 	return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ELogicalChannel, aOwnerType));
       
  1521 	}
       
  1522 
       
  1523 
       
  1524 
       
  1525 
       
  1526 EXPORT_C TInt RHandleBase::Duplicate(const RThread &aSrc,TOwnerType aType)
       
  1527 /**
       
  1528 Creates a valid handle to the kernel object for which the specified thread 
       
  1529 already has a handle.
       
  1530 	
       
  1531 The function assumes that this handle has been copy constructed from an existing 
       
  1532 handle (or the handle-number has been explicitly copied through calls to Handle() 
       
  1533 and SetHandle()).
       
  1534 	
       
  1535 By default, any thread in the process can use this handle to access the kernel 
       
  1536 side object that the handle represents. However, specifying EOwnerThread as 
       
  1537 the second parameter to this function, means that only the creating thread 
       
  1538 can use this handle to access the kernel side object; any other thread in 
       
  1539 this process that wants to access the kernel side object must, again, duplicate 
       
  1540 this handle.
       
  1541 	
       
  1542 @param aSrc  A reference to the thread containing the handle which is to be 
       
  1543              duplicated for this thread.
       
  1544 @param aType An enumeration whose enumerators define the ownership of this 
       
  1545              handle. If not explicitly specified, EOwnerProcess is taken
       
  1546              as default.
       
  1547              
       
  1548 @return KErrNone, if successful; otherwise, one of the other system wide error 
       
  1549         codes.
       
  1550 */
       
  1551 	{
       
  1552 	return Exec::HandleDuplicate(aSrc.Handle(), aType, iHandle);
       
  1553 	}
       
  1554 
       
  1555 
       
  1556 
       
  1557 
       
  1558 EXPORT_C TInt RHandleBase::Open(const TFindHandleBase& aFindHandle, TOwnerType aType)
       
  1559 /**
       
  1560 Opens a handle to a kernel side object found using a find-handle object.
       
  1561 
       
  1562 @param aFindHandle A find-handle object; an object that is used in searching
       
  1563                    for kernel side objects.
       
  1564 @param aType       An enumeration whose enumerators define the ownership of
       
  1565                    this handle. If not explicitly specified, EOwnerProcess
       
  1566                    is taken as default, and ownership is vested in the
       
  1567                    current process. Ownership can be vested in the current
       
  1568                    thread by passing the EOwnerThread enumerator.
       
  1569 @return KErrNone, if successful; otherwise one of the other system wide
       
  1570         error codes.
       
  1571 */
       
  1572 	{
       
  1573 	return SetReturnedHandle(Exec::FindHandleOpen(aType, aFindHandle), *this);
       
  1574 	}
       
  1575 
       
  1576 
       
  1577 
       
  1578 /**
       
  1579 	Implementation for RXxxxx::Open/OpenGlocbal(const TDesC &aName,,TOwnerType aType) functions
       
  1580 	@internalComponent
       
  1581 */
       
  1582 TInt RHandleBase::OpenByName(const TDesC &aName,TOwnerType aOwnerType,TInt aObjectType)
       
  1583 	{
       
  1584 	TBuf8<KMaxFullName> name8;
       
  1585 	name8.Copy(aName);
       
  1586 	return SetReturnedHandle(Exec::OpenObject((TObjectType)aObjectType,name8,aOwnerType));
       
  1587 	}
       
  1588 
       
  1589 TInt RHandleBase::SetReturnedHandle(TInt aHandleOrError,RHandleBase& aHandle)
       
  1590 //
       
  1591 // Set the handle value or return error
       
  1592 //
       
  1593 	{
       
  1594 	return aHandle.SetReturnedHandle(aHandleOrError);
       
  1595 	}
       
  1596 
       
  1597 
       
  1598 
       
  1599 
       
  1600 EXPORT_C void RHandleBase::Close()
       
  1601 /**
       
  1602 Closes the handle.
       
  1603 	
       
  1604 This has the effect of closing the associated kernel side object.
       
  1605 	
       
  1606 As the associated object is a reference counting object, it is destroyed if 
       
  1607 there are no other open references to it.
       
  1608 	
       
  1609 @see CObject
       
  1610 */
       
  1611 	{
       
  1612 
       
  1613 	__IF_DEBUG(Print(_L("RHandleBase::Close")));
       
  1614 	TInt h=iHandle;
       
  1615 	if (h!=KNullHandle)
       
  1616 		{
       
  1617 //
       
  1618 // We take a copy of the handle and set it to zero before the close in case this
       
  1619 // object is actually a Chunk created in its own heap in which case the close
       
  1620 // will destroy the object as well.
       
  1621 //
       
  1622 		iHandle=0;
       
  1623 		if ((h&CObjectIx::ENoClose)==0 && Exec::HandleClose(h)>0)
       
  1624 			DoExtendedClose();
       
  1625 		}
       
  1626 	}
       
  1627 
       
  1628 
       
  1629 
       
  1630 
       
  1631 void RHandleBase::DoExtendedClose()
       
  1632 //
       
  1633 // Call static data destructors following a library handle close
       
  1634 //
       
  1635 	{
       
  1636 	TRAPD(r,DoExtendedCloseL());	// catch attempts to leave from destructors
       
  1637 	__ASSERT_ALWAYS(r==KErrNone, Panic(EDllStaticDestructorLeave));
       
  1638 	}
       
  1639 
       
  1640 void RHandleBase::DoExtendedCloseL()
       
  1641 //
       
  1642 // Call static data destructors following a library handle close
       
  1643 //
       
  1644 	{
       
  1645 	TLinAddr ep[KMaxLibraryEntryPoints];
       
  1646 	TInt r=KErrNone;
       
  1647 	while (r!=KErrEof)
       
  1648 		{
       
  1649 		TInt numEps=KMaxLibraryEntryPoints;
       
  1650 		r=E32Loader::LibraryDetach(numEps, ep);
       
  1651 		if (r==KErrEof)
       
  1652 			break;
       
  1653 		TInt i;
       
  1654 		for (i=numEps-1; i>=0; --i)
       
  1655 			{
       
  1656 			TLibraryEntry f=(TLibraryEntry)ep[i];
       
  1657 			(*f)(KModuleEntryReasonProcessDetach);
       
  1658 			}
       
  1659 		r=E32Loader::LibraryDetached();
       
  1660 		}
       
  1661 	}
       
  1662 
       
  1663 
       
  1664 
       
  1665 
       
  1666 /**
       
  1667 Constructs an RMessage2 from an RMessagePtr2.
       
  1668 
       
  1669 @param aPtr A reference to an existing RMessagePtr2 object.
       
  1670 */
       
  1671 EXPORT_C RMessage2::RMessage2(const RMessagePtr2& aPtr)
       
  1672 	{
       
  1673 	iHandle = aPtr.Handle();
       
  1674 	Exec::MessageConstructFromPtr(iHandle, this);
       
  1675 	iFlags = 0;
       
  1676 	iSpare3 = 0;
       
  1677 	}
       
  1678 
       
  1679 /** Sets this message to an authorised state.  This is used only by
       
  1680 CPolicyServer.  This flags use by the policy server implies two things:
       
  1681 1) That the message has passed any appropriate security checks. (ie. one of the
       
  1682 static policy check, CustomSecurityCheckL, or CustomFailureActionL,
       
  1683 returned ETrue.)
       
  1684 2) That any leaves that occur subsequent to this flag being set happen _only_
       
  1685 in the session's ServiceL.  ie.  Nothing can leave between this flag being set
       
  1686 and the session's ServiceL being called.
       
  1687 
       
  1688 This is labelled as a const functions as everybody handles const RMessage2&'s.
       
  1689 The constness is actually referring to the underlying RMessagePtr2 not the
       
  1690 tranisent RMessage2 class.
       
  1691 
       
  1692 @internalComponent
       
  1693 */
       
  1694 void RMessage2::SetAuthorised() const
       
  1695 	{
       
  1696 	iFlags = ETrue;
       
  1697 	}
       
  1698 
       
  1699 /** Sets the authorised flag to a state of not authorised.  This is required as
       
  1700 there is a default constructor for RMessage2 and one cannot guarantee that
       
  1701 iFlags was initialised.  This is called from CPolicyServer::RunL.
       
  1702 
       
  1703 This is labelled as a const functions as everybody handles const RMessage2&'s.
       
  1704 The constness is actually referring to the underlying RMessagePtr2 not the
       
  1705 tranisent RMessage2 class.
       
  1706 
       
  1707 @internalComponent
       
  1708 */
       
  1709 void RMessage2::ClearAuthorised() const
       
  1710 	{
       
  1711 	iFlags = EFalse;
       
  1712 	}
       
  1713 
       
  1714 /** Returns whether this message has been authorised by CPolicyServer.  See
       
  1715 RMessage2::SetAuthorised for implications of this state.
       
  1716 @internalComponent
       
  1717 */
       
  1718 TBool RMessage2::Authorised() const
       
  1719 	{
       
  1720 	return iFlags;
       
  1721 	}
       
  1722 
       
  1723 
       
  1724 
       
  1725 
       
  1726 /**
       
  1727 Frees this message.
       
  1728 
       
  1729 @param aReason The completion code.
       
  1730 */
       
  1731 EXPORT_C void RMessagePtr2::Complete(TInt aReason) const
       
  1732 //
       
  1733 // Free this message. If it's a disconnect, need to switch to kernel context as we'll be
       
  1734 // freeing the DSession
       
  1735 //
       
  1736 	{
       
  1737 	TInt h=iHandle;
       
  1738 	const_cast<TInt&>(iHandle)=0;
       
  1739 	if (h)
       
  1740 		Exec::MessageComplete(h,aReason);
       
  1741 	else
       
  1742 		::Panic(ETMesCompletion);
       
  1743 	}
       
  1744 
       
  1745 
       
  1746 
       
  1747 
       
  1748 /**
       
  1749 Duplicates the specified handle in the client thread, and returns this
       
  1750 handle as a message completion code
       
  1751 
       
  1752 @param aHandle The handle to be duplicated.
       
  1753 */
       
  1754 EXPORT_C void RMessagePtr2::Complete(RHandleBase aHandle) const
       
  1755 	{
       
  1756 	TInt h=iHandle;
       
  1757 	const_cast<TInt&>(iHandle)=0;
       
  1758 	if (h)
       
  1759 		Exec::MessageCompleteWithHandle(h,aHandle.Handle());
       
  1760 	else
       
  1761 		::Panic(ETMesCompletion);
       
  1762 	}
       
  1763 
       
  1764 
       
  1765 
       
  1766 
       
  1767 /**
       
  1768 Gets the length of a descriptor argument in the client's process.
       
  1769 
       
  1770 @param aParam The index value identifying the argument.
       
  1771               This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1772               inclusive.
       
  1773               
       
  1774 @return The length of the descriptor, if successful.
       
  1775         KErrArgument, if aParam has a value outside the valid range.
       
  1776         KErrBadDescriptor, if the message argument is not a descriptor type.
       
  1777 */
       
  1778 EXPORT_C TInt RMessagePtr2::GetDesLength(TInt aParam) const
       
  1779 	{
       
  1780 	return Exec::MessageGetDesLength(iHandle,aParam);
       
  1781 	}
       
  1782 
       
  1783 
       
  1784 
       
  1785 
       
  1786 /**
       
  1787 Gets the length of a descriptor argument in the client's process,
       
  1788 leaving on failure.
       
  1789 
       
  1790 @param aParam The index value identifying the argument.
       
  1791               This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1792               inclusive.
       
  1793               
       
  1794 @return The length of the descriptor.
       
  1795 
       
  1796 @leave  KErrArgument if aParam has a value outside the valid range.
       
  1797 @leave  KErrBadDescriptor, if the message argument is not a descriptor type.
       
  1798 */
       
  1799 EXPORT_C TInt RMessagePtr2::GetDesLengthL(TInt aParam) const
       
  1800 	{
       
  1801 	return User::LeaveIfError(GetDesLength(aParam));
       
  1802 	}
       
  1803 
       
  1804 
       
  1805 
       
  1806 
       
  1807 /**
       
  1808 Gets the maximum length of a descriptor argument in the client's process.
       
  1809 
       
  1810 @param aParam The index value identifying the argument.
       
  1811               This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1812               inclusive.
       
  1813               
       
  1814 @return The maximum length of the descriptor, if successful.
       
  1815         KErrArgument, if aParam has a value outside the valid range.
       
  1816         KErrBadDescriptor, if the message argument is not a descriptor type.
       
  1817 */
       
  1818 EXPORT_C TInt RMessagePtr2::GetDesMaxLength(TInt aParam) const
       
  1819 	{
       
  1820 	return Exec::MessageGetDesMaxLength(iHandle,aParam);
       
  1821 	}
       
  1822 
       
  1823 
       
  1824 
       
  1825 
       
  1826 /**
       
  1827 Gets the maximum length of a descriptor argument in the client's process,
       
  1828 leaving on failure.
       
  1829 
       
  1830 @param aParam The index value identifying the argument.
       
  1831               This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1832               inclusive.
       
  1833               
       
  1834 @return The length of the descriptor.
       
  1835 
       
  1836 @leave  KErrArgument if aParam has a value outside the valid range.
       
  1837 @leave  KErrBadDescriptor, if the message argument is not a descriptor type.
       
  1838 */
       
  1839 EXPORT_C TInt RMessagePtr2::GetDesMaxLengthL(TInt aParam) const
       
  1840 	{
       
  1841 	return User::LeaveIfError(GetDesMaxLength(aParam));
       
  1842 	}
       
  1843 
       
  1844 
       
  1845 
       
  1846 
       
  1847 /**
       
  1848 Reads data from the specified offset within the 8-bit descriptor
       
  1849 argument, into the specified target descriptor, and leaving on failure.
       
  1850 
       
  1851 @param aParam  The index value identifying the argument.
       
  1852                This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1853                inclusive.
       
  1854 @param aDes    The target descriptor into which the client data is
       
  1855                to be written.
       
  1856 @param aOffset The offset from the start of the client's descriptor data.
       
  1857                If not explicitly specified, the offset defaults to zero.
       
  1858 
       
  1859 @leave  KErrArgument if aParam has a value outside the valid range, or
       
  1860                      if aOffset is negative.
       
  1861 @leave  KErrBadDescriptor, if the message argument is not an 8-bit descriptor.
       
  1862 */
       
  1863 EXPORT_C void RMessagePtr2::ReadL(TInt aParam,TDes8& aDes,TInt aOffset) const
       
  1864 	{
       
  1865 	TInt error = Read(aParam,aDes,aOffset);
       
  1866 	User::LeaveIfError(error);
       
  1867 	}
       
  1868 
       
  1869 
       
  1870 
       
  1871 
       
  1872 /**
       
  1873 Reads data from the specified offset within the 16-bit descriptor
       
  1874 argument, into the specified target descriptor, and leaving on failure.
       
  1875 
       
  1876 @param aParam  The index value identifying the argument.
       
  1877                This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1878                inclusive.
       
  1879 @param aDes    The target descriptor into which the client data is
       
  1880                to be written.
       
  1881 @param aOffset The offset from the start of the client's descriptor data.
       
  1882                If not explicitly specified, the offset defaults to zero.
       
  1883 
       
  1884 @leave  KErrArgument if aParam has a value outside the valid range, or
       
  1885                      if aOffset is negative.
       
  1886 @leave  KErrBadDescriptor, if the message argument is not a 16-bit descriptor.
       
  1887 */
       
  1888 EXPORT_C void RMessagePtr2::ReadL(TInt aParam,TDes16 &aDes,TInt aOffset) const
       
  1889 	{
       
  1890 	TInt error = Read(aParam,aDes,aOffset);
       
  1891 	User::LeaveIfError(error);
       
  1892 	}
       
  1893 
       
  1894 
       
  1895 
       
  1896 
       
  1897 /**
       
  1898 Writes data from the specified source descriptor to the specified offset within
       
  1899 the 8-bit descriptor argument, and leaving on failure.
       
  1900 
       
  1901 @param aParam  The index value identifying the argument.
       
  1902                This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1903                inclusive.
       
  1904 @param aDes    The source descriptor containing the data to be written.
       
  1905 @param aOffset The offset from the start of the client's descriptor.
       
  1906                If not explicitly specified, the offset defaults to zero.
       
  1907 
       
  1908 @leave  KErrArgument if aParam has a value outside the valid range, or
       
  1909                      if aOffset is negative.
       
  1910 @leave  KErrBadDescriptor, if the message argument is not an 8-bit descriptor.
       
  1911 */
       
  1912 EXPORT_C void RMessagePtr2::WriteL(TInt aParam,const TDesC8& aDes,TInt aOffset) const
       
  1913 	{
       
  1914 	TInt error = Write(aParam,aDes,aOffset);
       
  1915 	User::LeaveIfError(error);
       
  1916 	}
       
  1917 
       
  1918 
       
  1919 
       
  1920 
       
  1921 /**
       
  1922 Writes data from the specified source descriptor to the specified offset within
       
  1923 the 16-bit descriptor argument, and leaving on failure.
       
  1924 
       
  1925 @param aParam  The index value identifying the argument.
       
  1926                This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1927                inclusive.
       
  1928 @param aDes    The source descriptor containing the data to be written.
       
  1929 @param aOffset The offset from the start of the client's descriptor.
       
  1930                If not explicitly specified, the offset defaults to zero.
       
  1931 
       
  1932 @leave  KErrArgument if aParam has a value outside the valid range, or
       
  1933                      if aOffset is negative.
       
  1934 @leave  KErrBadDescriptor, if the message argument is not a 16-bit descriptor.
       
  1935 */
       
  1936 EXPORT_C void RMessagePtr2::WriteL(TInt aParam,const TDesC16& aDes,TInt aOffset) const
       
  1937 	{
       
  1938 	TInt error = Write(aParam,aDes,aOffset);
       
  1939 	User::LeaveIfError(error);
       
  1940 	}
       
  1941 
       
  1942 
       
  1943 
       
  1944 
       
  1945 /**
       
  1946 Reads data from the specified offset within the 8-bit descriptor
       
  1947 argument, into the specified target descriptor.
       
  1948 
       
  1949 @param aParam  The index value identifying the argument.
       
  1950                This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1951                inclusive.
       
  1952 @param aDes    The target descriptor into which the client data is
       
  1953                to be written.
       
  1954 @param aOffset The offset from the start of the client's descriptor data.
       
  1955                If not explicitly specified, the offset defaults to zero.
       
  1956 
       
  1957 @return KErrNone, if successful;
       
  1958         KErrArgument if aParam has a value outside the valid range, or
       
  1959                      if aOffset is negative.
       
  1960         KErrBadDescriptor, if the message argument is not an 8-bit descriptor.
       
  1961 */
       
  1962 EXPORT_C TInt RMessagePtr2::Read(TInt aParam,TDes8& aDes,TInt aOffset) const
       
  1963 	{
       
  1964 	SIpcCopyInfo info;
       
  1965 	info.iFlags=KChunkShiftBy0|KIpcDirRead;
       
  1966 	info.iLocalLen=aDes.MaxLength();
       
  1967 	info.iLocalPtr=(TUint8*)aDes.Ptr();
       
  1968 	TInt r=Exec::MessageIpcCopy(iHandle,aParam,info,aOffset);
       
  1969 	if (r<0)
       
  1970 		return r;
       
  1971 	aDes.SetLength(r);
       
  1972 	return KErrNone;
       
  1973 	}
       
  1974 
       
  1975 
       
  1976 
       
  1977 
       
  1978 /**
       
  1979 Reads data from the specified offset within the 16-bit descriptor
       
  1980 argument, into the specified target descriptor.
       
  1981 
       
  1982 @param aParam  The index value identifying the argument.
       
  1983                This is a value in the range 0 to (KMaxMessageArguments-1)
       
  1984                inclusive.
       
  1985 @param aDes    The target descriptor into which the client data is
       
  1986                to be written.
       
  1987 @param aOffset The offset from the start of the client's descriptor data.
       
  1988                If not explicitly specified, the offset defaults to zero.
       
  1989                
       
  1990 @return KErrNone, if successful;
       
  1991         KErrArgument if aParam has a value outside the valid range, or
       
  1992                      if aOffset is negative.
       
  1993         KErrBadDescriptor, if the message argument is not a 16-bit descriptor.
       
  1994 */
       
  1995 EXPORT_C TInt RMessagePtr2::Read(TInt aParam,TDes16 &aDes,TInt aOffset) const
       
  1996 	{
       
  1997 	SIpcCopyInfo info;
       
  1998 	info.iFlags=KChunkShiftBy1|KIpcDirRead;
       
  1999 	info.iLocalLen=aDes.MaxLength();
       
  2000 	info.iLocalPtr=(TUint8*)aDes.Ptr();
       
  2001 	TInt r=Exec::MessageIpcCopy(iHandle,aParam,info,aOffset);
       
  2002 	if (r<0)
       
  2003 		return r;
       
  2004 	aDes.SetLength(r);
       
  2005 	return KErrNone;
       
  2006 	}
       
  2007 
       
  2008 
       
  2009 
       
  2010 
       
  2011 /**
       
  2012 Writes data from the specified source descriptor to the specified offset within
       
  2013 the 8-bit descriptor argument.
       
  2014 
       
  2015 @param aParam  The index value identifying the argument.
       
  2016                This is a value in the range 0 to (KMaxMessageArguments-1)
       
  2017                inclusive.
       
  2018 @param aDes    The source descriptor containing the data to be written.
       
  2019 @param aOffset The offset from the start of the client's descriptor.
       
  2020                If not explicitly specified, the offset defaults to zero.
       
  2021                
       
  2022 @return KErrNone, if successful;
       
  2023         KErrArgument if aParam has a value outside the valid range, or
       
  2024                      if aOffset is negative.
       
  2025         KErrBadDescriptor, if the message argument is not an 8-bit descriptor;
       
  2026         KErrOverflow, if the target descriptor is too small
       
  2027                       to containt the data.
       
  2028 */
       
  2029 EXPORT_C TInt RMessagePtr2::Write(TInt aParam,const TDesC8& aDes,TInt aOffset) const
       
  2030 	{
       
  2031 	SIpcCopyInfo info;
       
  2032 	info.iFlags=KChunkShiftBy0|KIpcDirWrite;
       
  2033 	info.iLocalLen=aDes.Length();
       
  2034 	info.iLocalPtr=(TUint8*)aDes.Ptr();
       
  2035 	return Exec::MessageIpcCopy(iHandle,aParam,info,aOffset);
       
  2036 	}
       
  2037 
       
  2038 
       
  2039 
       
  2040 
       
  2041 /**
       
  2042 Writes data from the specified source descriptor to the specified offset within 
       
  2043 the 16-bit descriptor argument.
       
  2044 
       
  2045 @param aParam  The index value identifying the argument.
       
  2046                This is a value in the range 0 to (KMaxMessageArguments-1)
       
  2047                inclusive.
       
  2048 @param aDes    The source descriptor containing the data to be written.
       
  2049 @param aOffset The offset from the start of the client's descriptor.
       
  2050                If not explicitly specified, the offset defaults to zero.
       
  2051 
       
  2052 @return KErrNone, if successful;
       
  2053         KErrArgument if aParam has a value outside the valid range, or
       
  2054                      if aOffset is negative.
       
  2055         KErrBadDescriptor, if the message argument is not an 16-bit descriptor;
       
  2056         KErrOverflow, if the target descriptor is too small
       
  2057                       to containt the data.
       
  2058 */
       
  2059 EXPORT_C TInt RMessagePtr2::Write(TInt aParam,const TDesC16& aDes,TInt aOffset) const
       
  2060 	{
       
  2061 	SIpcCopyInfo info;
       
  2062 	info.iFlags=KChunkShiftBy1|KIpcDirWrite;
       
  2063 	info.iLocalLen=aDes.Length();
       
  2064 	info.iLocalPtr=(TUint8*)aDes.Ptr();
       
  2065 	return Exec::MessageIpcCopy(iHandle,aParam,info,aOffset);
       
  2066 	}
       
  2067 
       
  2068 
       
  2069 
       
  2070 
       
  2071 /**
       
  2072 Panics the client.
       
  2073 
       
  2074 The length of the category name should be no greater than 16; any name with 
       
  2075 a length greater than 16 is truncated to 16.
       
  2076 
       
  2077 Note that this method also completes the message. A subsequent call to Complete(TInt aReason) would cause a server panic.
       
  2078 
       
  2079 @param aCategory The panic category.
       
  2080 @param aReason   The panic code.
       
  2081 */
       
  2082 EXPORT_C void RMessagePtr2::Panic(const TDesC& aCategory,TInt aReason) const
       
  2083 	{
       
  2084 	TBuf8<KMaxExitCategoryName> cat;
       
  2085 	TInt length=aCategory.Length();
       
  2086 	if(length>KMaxExitCategoryName)
       
  2087 		{
       
  2088 		TPtr catPtr((TUint16*)aCategory.Ptr(),KMaxExitCategoryName,KMaxExitCategoryName);
       
  2089 		cat.Copy(catPtr);
       
  2090 		}
       
  2091 	else
       
  2092 		{
       
  2093 		cat.Copy(aCategory);
       
  2094 		}
       
  2095 	Exec::MessageKill(iHandle,EExitPanic,aReason,&cat);
       
  2096 	Complete(KErrNone);
       
  2097 	}
       
  2098 
       
  2099 
       
  2100 
       
  2101 
       
  2102 /**
       
  2103 Kills the client.
       
  2104 
       
  2105 Note that this method also completes the message. A subsequent call to Complete(TInt aReason) would cause a server panic.
       
  2106 
       
  2107 @param aReason The reason code associated with killing the client.
       
  2108 */
       
  2109 EXPORT_C void RMessagePtr2::Kill(TInt aReason) const
       
  2110 	{
       
  2111 	Exec::MessageKill(iHandle,EExitKill,aReason,NULL);
       
  2112 	Complete(KErrNone);
       
  2113 	}
       
  2114 
       
  2115 
       
  2116 
       
  2117 
       
  2118 /**
       
  2119 Terminates the client.
       
  2120 
       
  2121 Note that this method also completes the message. A subsequent call to Complete(TInt aReason) would cause a server panic.
       
  2122 
       
  2123 @param aReason The reason code associated with terminating the client.
       
  2124 */
       
  2125 EXPORT_C void RMessagePtr2::Terminate(TInt aReason) const
       
  2126 	{
       
  2127 	Exec::MessageKill(iHandle,EExitTerminate,aReason,NULL);
       
  2128 	Complete(KErrNone);
       
  2129 	}
       
  2130 
       
  2131 
       
  2132 
       
  2133 
       
  2134 /**
       
  2135 Sets the priority of the client's process.
       
  2136 
       
  2137 @param aPriority The priority value.
       
  2138 
       
  2139 @return KErrNone, if successful, otherwise one of the other system-wide error codes.
       
  2140 */
       
  2141 EXPORT_C TInt RMessagePtr2::SetProcessPriority(TProcessPriority aPriority) const
       
  2142 	{
       
  2143 	return Exec::MessageSetProcessPriority(iHandle,aPriority);
       
  2144 	}
       
  2145 
       
  2146 
       
  2147 
       
  2148 /**
       
  2149 Opens a handle on the client thread.
       
  2150 
       
  2151 @param aClient    On successful return, the handle to the client thread.
       
  2152 @param aOwnerType An enumeration whose enumerators define the ownership of
       
  2153                   the handle. If not explicitly specified,
       
  2154                   EOwnerProcess is taken as default.
       
  2155 
       
  2156 @return KErrNone.
       
  2157 */
       
  2158 EXPORT_C TInt RMessagePtr2::Client(RThread& aClient, TOwnerType aOwnerType) const
       
  2159 	{
       
  2160 	return aClient.SetReturnedHandle(Exec::MessageClient(iHandle,aOwnerType));
       
  2161 	}
       
  2162 
       
  2163 EXPORT_C TUint RMessagePtr2::ClientProcessFlags() const
       
  2164 	{
       
  2165 	return Exec::MessageClientProcessFlags(iHandle);
       
  2166 	}
       
  2167 
       
  2168 EXPORT_C TBool RMessagePtr2::ClientIsRealtime() const
       
  2169 	{
       
  2170 	return (Exec::MessageClientProcessFlags(iHandle) & KThreadFlagRealtime) != 0;
       
  2171 	}
       
  2172 
       
  2173 
       
  2174 
       
  2175 /**
       
  2176 Returns the pointer to the clients TRequestStatus associated with the message.
       
  2177 
       
  2178 The return value is intended to be used as a unique identifier (for example,
       
  2179 to uniquely identify an asynchronous message when cancelling the request).
       
  2180 The memory must never be accessed directly or completed.
       
  2181 
       
  2182 @return The clients TRequestStatus (returns NULL if the request is not asynchronous)
       
  2183 */
       
  2184 EXPORT_C const TRequestStatus* RMessagePtr2::ClientStatus() const
       
  2185 	{
       
  2186 	return Exec::MessageClientStatus(iHandle);
       
  2187 	}
       
  2188 
       
  2189 
       
  2190 
       
  2191 EXPORT_C TInt RServer2::CreateGlobal(const TDesC& aName, TInt aMode, TInt aRole, TInt aOpts)
       
  2192 //
       
  2193 // Create a new server.
       
  2194 //
       
  2195 	{
       
  2196 	TInt r = User::ValidateName(aName);
       
  2197 	if (r != KErrNone)
       
  2198 		return r;
       
  2199 	TBuf8<KMaxKernelName> name8;
       
  2200 	name8.Copy(aName);
       
  2201 	r = Exec::ServerCreateWithOptions(&name8, aMode, aRole, aOpts);
       
  2202 	return SetReturnedHandle(r, *this);
       
  2203 	}
       
  2204 
       
  2205 EXPORT_C TInt RServer2::CreateGlobal(const TDesC& aName, TInt aMode)
       
  2206 	{
       
  2207 	return CreateGlobal(aName, aMode, EServerRole_Default, 0);
       
  2208 	}
       
  2209 
       
  2210 EXPORT_C TInt RServer2::CreateGlobal(const TDesC& aName)
       
  2211 	{
       
  2212 	return CreateGlobal(aName, EIpcSession_Sharable);
       
  2213 	}
       
  2214 
       
  2215 TInt RSessionBase::DoConnect(const TVersion &aVersion,TRequestStatus* aStatus)
       
  2216 	{
       
  2217 	extern int TVersion_size_assert[sizeof(TVersion)==sizeof(TInt)?1:-1]; // Make sure TVersion is same size as int
       
  2218 	(void)TVersion_size_assert;
       
  2219 
       
  2220 	TIpcArgs p(*(TInt*)&aVersion);
       
  2221 	TInt r;
       
  2222 	if(aStatus==NULL)
       
  2223 		r = SendSync(RMessage2::EConnect, &p);
       
  2224 	else
       
  2225 		r = SendAsync(RMessage2::EConnect, &p, aStatus);
       
  2226 	if (r!=KErrNone)
       
  2227 		Close();
       
  2228 	return r;
       
  2229 	}
       
  2230 
       
  2231 
       
  2232 
       
  2233 
       
  2234 /**
       
  2235 Creates a session with a server.
       
  2236 
       
  2237 It should be called as part of session initialisation in the derived class.
       
  2238 
       
  2239 @param aServer   The name of the server with which a session is to
       
  2240                  be established.
       
  2241 @param aVersion  The lowest version of the server with which this client
       
  2242                  is compatible.
       
  2243 @param aAsyncMessageSlots The number of message slots available to this session.
       
  2244                  This determines the number of outstanding requests the client
       
  2245                  may have with the server at any one time.
       
  2246                  The maximum number of slots is 255.
       
  2247 				 If aAsyncMessageSlots==-1 then this indicates that the session should use
       
  2248 				 messages from the global free pool of messages.
       
  2249 @param aType     The type of session to create. See TIpcSessionType.
       
  2250 @param aPolicy   A pointer to a TSecurityPolicy object. If this pointer is not 0 (zero)
       
  2251 				 then the policy is applied to the process in which the server is running.
       
  2252 				 If that process doesn't pass this security policy check, then the session
       
  2253 				 creation will fail with the error KErrPermissionDenied.
       
  2254 				 This security check allows clients to verify that the server has the expected
       
  2255 				 Platform Security attributes.
       
  2256 
       
  2257 				When a check fails the action taken is determined by the system wide Platform Security
       
  2258 				configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
  2259 				If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
       
  2260 				check failed.
       
  2261 
       
  2262 @param aStatus   A pointer to TRequestStatus object which will be signalled when the session
       
  2263 				 has been created, or in the event of an error.
       
  2264 				 If aStatus==0 then session creation is done synchronously.
       
  2265 
       
  2266 @return          KErrNone if successful;
       
  2267                  KErrArgument, if an attempt is made to specify more
       
  2268                  than 255 message slots;
       
  2269                  otherwise one of the other system-wide error codes.
       
  2270 */
       
  2271 EXPORT_C TInt RSessionBase::CreateSession(const TDesC& aServer,const TVersion& aVersion,TInt aAsyncMessageSlots,TIpcSessionType aType,const TSecurityPolicy* aPolicy, TRequestStatus* aStatus)
       
  2272 	{
       
  2273 	TInt r = User::ValidateName(aServer);
       
  2274 	if(KErrNone!=r)
       
  2275 		return r;
       
  2276 	TBuf8<KMaxKernelName> name8;
       
  2277 	name8.Copy(aServer);
       
  2278 	r=SetReturnedHandle(Exec::SessionCreate(name8,aAsyncMessageSlots,aPolicy,aType));
       
  2279 	if(r==KErrNone)
       
  2280 		r=DoConnect(aVersion,aStatus);
       
  2281 	return r;
       
  2282 	}
       
  2283 
       
  2284 
       
  2285 
       
  2286 
       
  2287 /**
       
  2288 Creates a session with a server.
       
  2289 
       
  2290 It should be called as part of session initialisation in the derived class.
       
  2291 
       
  2292 @param aServer   The name of the server with which a session is to
       
  2293                  be established.
       
  2294 @param aVersion  The lowest version of the server with which this client
       
  2295                  is compatible.
       
  2296 @param aAsyncMessageSlots The number of message slots available to this session.
       
  2297                  This determines the number of outstanding requests the client
       
  2298                  may have with the server at any one time.
       
  2299                  The maximum number of slots is 255.
       
  2300 				 If aAsyncMessageSlots==-1 then this indicates that the session should use
       
  2301 				 messages from the global free pool of messages.
       
  2302                  
       
  2303 @return          KErrNone if successful;
       
  2304                  KErrArgument, if an attempt is made to specify more
       
  2305                  than 255 message slots;
       
  2306                  otherwise one of the other system-wide error codes.
       
  2307 */
       
  2308 EXPORT_C TInt RSessionBase::CreateSession(const TDesC &aServer, const TVersion &aVersion, TInt aAsyncMessageSlots)
       
  2309 	{
       
  2310 	return RSessionBase::CreateSession(aServer,aVersion,aAsyncMessageSlots,EIpcSession_Unsharable,NULL,0);
       
  2311 	}
       
  2312 
       
  2313 
       
  2314 
       
  2315 
       
  2316 /**
       
  2317 Creates a session with a server.
       
  2318 
       
  2319 It should be called as part of session initialisation in the derived class.
       
  2320 
       
  2321 @param aServer   A handle to a server with which a session is to be established.	 
       
  2322 @param aVersion  The lowest version of the server with which this client
       
  2323                  is compatible.
       
  2324 @param aAsyncMessageSlots The number of message slots available to this session.
       
  2325                  This determines the number of outstanding requests the client
       
  2326                  may have with the server at any one time.
       
  2327                  The maximum number of slots is 255.
       
  2328 				 If aAsyncMessageSlots==-1 then this indicates that the session should use
       
  2329 				 messages from the global free pool of messages.
       
  2330 @param aType     The type of session to create. See TIpcSessionType.
       
  2331 @param aPolicy   A pointer to a TSecurityPolicy object. If this pointer is not 0 (zero)
       
  2332 				 then the policy is applied to the process in which the server is running.
       
  2333 				 If that process doesn't pass this security policy check, then the session
       
  2334 				 creation will fail with the error KErrPermissionDenied.
       
  2335 				 This security check allows clients to verify that the server has the expected
       
  2336 				 Platform Security attributes.
       
  2337 
       
  2338 				When a check fails the action taken is determined by the system wide Platform Security
       
  2339 				configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
  2340 				If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
       
  2341 				check failed.
       
  2342 
       
  2343 @param aStatus   A pointer to TRequestStatus object which will be signalled when the session
       
  2344 				 has been created, or in the event of an error.
       
  2345 				 If aStatus==0 then session creation is done synchronously.
       
  2346 
       
  2347 @return          KErrNone if successful;
       
  2348                  KErrArgument, if an attempt is made to specify more
       
  2349                  than 255 message slots;
       
  2350                  otherwise one of the other system-wide error codes.
       
  2351 */
       
  2352 EXPORT_C TInt RSessionBase::CreateSession(RServer2 aServer,const TVersion& aVersion,TInt aAsyncMessageSlots,TIpcSessionType aType,const TSecurityPolicy* aPolicy, TRequestStatus* aStatus)
       
  2353 	{
       
  2354 	TInt r;
       
  2355 	r=SetReturnedHandle(Exec::SessionCreateFromHandle(aServer.Handle(),aAsyncMessageSlots,aPolicy,aType));
       
  2356 	if(r==KErrNone)
       
  2357 		r=DoConnect(aVersion,aStatus);
       
  2358 	return r;
       
  2359 	}
       
  2360 
       
  2361 
       
  2362 
       
  2363 
       
  2364 /**
       
  2365 Creates a session with a server.
       
  2366 
       
  2367 It should be called as part of session initialisation in the derived class.
       
  2368 
       
  2369 @param aServer   A handle to a server with which a session is to be established.                
       
  2370 @param aVersion  The lowest version of the server with which this client
       
  2371                  is compatible.
       
  2372 @param aAsyncMessageSlots The number of message slots available to this session.
       
  2373                  This determines the number of outstanding requests the client
       
  2374                  may have with the server at any one time.
       
  2375                  The maximum number of slots is 255.
       
  2376 				 If aAsyncMessageSlots==-1 then this indicates that the session should use
       
  2377 				 messages from the global free pool of messages.
       
  2378 
       
  2379 @return          KErrNone if successful;
       
  2380                  KErrArgument, if an attempt is made to specify more
       
  2381                  than 255 message slots;
       
  2382                  otherwise one of the other system-wide error codes.
       
  2383 */
       
  2384 EXPORT_C TInt RSessionBase::CreateSession(RServer2 aServer, const TVersion &aVersion, TInt aAsyncMessageSlots)
       
  2385 	{
       
  2386 	return RSessionBase::CreateSession(aServer,aVersion,aAsyncMessageSlots,EIpcSession_Unsharable,NULL,0);
       
  2387 	}
       
  2388 
       
  2389 
       
  2390 
       
  2391 
       
  2392 /**
       
  2393 Opens a handle to a session using a handle number sent by a client
       
  2394 to a server.
       
  2395 
       
  2396 This function is called by the server.
       
  2397 
       
  2398 @param aMessage The message pointer.
       
  2399 @param aParam   An index specifying which of the four message arguments
       
  2400                 contains the handle number.
       
  2401 @param aType    An enumeration whose enumerators define the ownership of this 
       
  2402                 session handle. If not explicitly specified, EOwnerProcess
       
  2403 				is taken as default.
       
  2404                 
       
  2405 @return KErrNone, if successful;
       
  2406         KErrArgument, if the value of aParam is outside the range 0-3;
       
  2407         KErrBadHandle, if not a valid handle;
       
  2408         otherwise one of the other system-wide error codes.
       
  2409 */
       
  2410 EXPORT_C TInt RSessionBase::Open(RMessagePtr2 aMessage,TInt aParam,TOwnerType aType)
       
  2411 	{
       
  2412 	return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),ESession,aParam,aType));
       
  2413 	}
       
  2414 
       
  2415 
       
  2416 
       
  2417 
       
  2418 /**
       
  2419 Opens a handle to a session using a handle number sent by a client
       
  2420 to a server, and validate that the session's server passes a given
       
  2421 security policy.
       
  2422 
       
  2423 This function is called by the server.
       
  2424 
       
  2425 @param aMessage 		The message pointer.
       
  2426 @param aParam   		An index specifying which of the four message arguments
       
  2427                 		contains the handle number.
       
  2428 @param aServerPolicy	The policy to validate the session's server against.
       
  2429 @param aType    		An enumeration whose enumerators define the ownership of this 
       
  2430                 		session handle. If not explicitly specified, EOwnerProcess
       
  2431 						is taken as default.
       
  2432                 
       
  2433 @return KErrNone, if successful;
       
  2434         KErrArgument, if the value of aParam is outside the range 0-3;
       
  2435         KErrBadHandle, if not a valid handle;
       
  2436 		KErrServerTerminating, if the session is no longer connected to a server;
       
  2437 		KErrPermissionDenied, if the session's server does not pass the given security policy;
       
  2438         otherwise one of the other system-wide error codes.
       
  2439 */
       
  2440 EXPORT_C TInt RSessionBase::Open(RMessagePtr2 aMessage,TInt aParam,const TSecurityPolicy& aServerPolicy,TOwnerType aType)
       
  2441 	{
       
  2442 	return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),ESession,aParam,aType),aServerPolicy);
       
  2443 	}
       
  2444 
       
  2445 
       
  2446 
       
  2447 /**
       
  2448 Sets the handle-number of this session handle to the specified value after
       
  2449 validating that the session's server passes a given security policy.
       
  2450 
       
  2451 The function can take a (zero or positive) handle-number,
       
  2452 or a (negative) error number.
       
  2453 
       
  2454 If aHandleOrError represents a handle-number, then the handle-number of this handle
       
  2455 is set to that value, as long as the session's server passes the security policy.
       
  2456 If aHandleOrError represents an error number, then the handle-number of this handle is set to zero
       
  2457 and the negative value is returned.
       
  2458 
       
  2459 @param aHandleOrError A handle-number, if zero or positive; an error value, if negative.
       
  2460 @param aServerPolicy  The policy to validate the session's server against.
       
  2461 
       
  2462 @return KErrNone, if aHandle is a handle-number; KErrPermissionDenied, if the session's server
       
  2463         does not pass the security policy; the value of aHandleOrError, otherwise.
       
  2464 */
       
  2465 EXPORT_C TInt RSessionBase::SetReturnedHandle(TInt aHandleOrError,const TSecurityPolicy& aServerPolicy)
       
  2466 	{
       
  2467 	if(aHandleOrError<0)
       
  2468 		return aHandleOrError;
       
  2469 	
       
  2470 	TInt r = aServerPolicy.CheckPolicy((RSessionBase&)aHandleOrError);
       
  2471 	if (r!=KErrNone)
       
  2472 		{
       
  2473 		((RHandleBase&)aHandleOrError).Close();
       
  2474 		return r;
       
  2475 		}
       
  2476 
       
  2477 	iHandle=aHandleOrError;
       
  2478 	return KErrNone;
       
  2479 	}
       
  2480 
       
  2481 
       
  2482 
       
  2483 
       
  2484 /**
       
  2485 Opens a handle to a session using a handle number passed as an
       
  2486 environment data item to the child process during the creation of
       
  2487 that child process.
       
  2488 
       
  2489 Note that this function can only be called successfully once.
       
  2490 
       
  2491 @param aArgumentIndex An index that identifies the slot in the process
       
  2492                       environment data that contains the handle number. This is
       
  2493                       a value relative to zero, i.e. 0 is the first item/slot.
       
  2494                       This can range from 0 to 15.
       
  2495                       
       
  2496 @param aOwnerType     An enumeration whose enumerators define the ownership of
       
  2497                       this session handle. If not explicitly specified,
       
  2498                       EOwnerProcess is taken as default.
       
  2499                       
       
  2500 @return KErrNone, if successful; 
       
  2501         KErrNotFound, if the slot indicated by aArgumentIndex is empty;
       
  2502         KErrArgument, if the slot does not contain a session handle;
       
  2503         otherwise one of the other system-wide error codes.                      
       
  2504 */
       
  2505 EXPORT_C TInt RSessionBase::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
       
  2506 	{
       
  2507 	return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ESession, aOwnerType));
       
  2508 	}
       
  2509 
       
  2510 
       
  2511 /**
       
  2512 Opens a handle to a session using a handle number passed as an
       
  2513 environment data item to the child process during the creation of
       
  2514 that child process, after validating that the session's server passes
       
  2515 the given security policy.
       
  2516 
       
  2517 Note that this function can only be called successfully once.
       
  2518 
       
  2519 @param aArgumentIndex An index that identifies the slot in the process
       
  2520                       environment data that contains the handle number. This is
       
  2521                       a value relative to zero, i.e. 0 is the first item/slot.
       
  2522                       This can range from 0 to 15.
       
  2523 @param aServerPolicy  The policy to validate the session's server against.
       
  2524 @param aOwnerType     An enumeration whose enumerators define the ownership of
       
  2525                       this session handle. If not explicitly specified,
       
  2526                       EOwnerProcess is taken as default.
       
  2527                       
       
  2528 @return KErrNone, if successful; 
       
  2529         KErrNotFound, if the slot indicated by aArgumentIndex is empty;
       
  2530         KErrArgument, if the slot does not contain a session handle;
       
  2531 		KErrServerTerminating, if the session is no longer connected to a server;
       
  2532 		KErrPermissionDenied, if the session's server does not pass the given security policy;
       
  2533         otherwise one of the other system-wide error codes.                      
       
  2534 */
       
  2535 EXPORT_C TInt RSessionBase::Open(TInt aArgumentIndex, const TSecurityPolicy& aServerPolicy, TOwnerType aOwnerType)
       
  2536 	{
       
  2537 	return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ESession, aOwnerType), aServerPolicy);
       
  2538 	}
       
  2539 
       
  2540 
       
  2541 EXPORT_C TInt RSessionBase::DoShare(TInt aMode)
       
  2542 //
       
  2543 // Make the session accessible to all threads in this process
       
  2544 //
       
  2545 	{
       
  2546 	return Exec::SessionShare(iHandle, (aMode&KCreateProtectedObject) ? EIpcSession_GlobalSharable : EIpcSession_Sharable);
       
  2547 	}
       
  2548 
       
  2549 
       
  2550 
       
  2551 
       
  2552 TInt RSessionBase::SendSync(TInt aFunction,const TIpcArgs* aArgs) const
       
  2553 //
       
  2554 // Send a synchronous message.
       
  2555 //
       
  2556 	{
       
  2557 	TRequestStatus s=KRequestPending;
       
  2558 	TInt r=Exec::SessionSendSync(iHandle,aFunction,(TAny*)aArgs,&s);
       
  2559 	if (r==KErrNone)
       
  2560 		{
       
  2561 		User::WaitForRequest(s);
       
  2562 		r=s.Int();
       
  2563 		}
       
  2564 	return r;
       
  2565 	}
       
  2566 
       
  2567 TInt RSessionBase::SendAsync(TInt aFunction,const TIpcArgs* aArgs,TRequestStatus *aStatus) const
       
  2568 //
       
  2569 // Send an asynchronous message.
       
  2570 //
       
  2571 	{
       
  2572 	if (aStatus)
       
  2573 		*aStatus=KRequestPending;
       
  2574 	return Exec::SessionSend(iHandle,aFunction,(TAny*)aArgs,aStatus);
       
  2575 	}
       
  2576 
       
  2577 
       
  2578 
       
  2579 
       
  2580 EXPORT_C TInt RMutex::CreateLocal(TOwnerType aType)
       
  2581 /**
       
  2582 Creates a mutex and opens this handle to the mutex.
       
  2583 
       
  2584 The kernel side object representing the mutex is unnamed. This means that 
       
  2585 it is not possible to search for the mutex, which makes it local to the current 
       
  2586 process.
       
  2587 
       
  2588 By default, any thread in the process can use this instance of RMutex to access 
       
  2589 the mutex. However, specifying EOwnerThread as the parameter to this function, 
       
  2590 means that only the creating thread can use this instance of RMutex to access 
       
  2591 the mutex; any other thread in this process that wants to access the mutex 
       
  2592 must duplicate this handle.
       
  2593 
       
  2594 @param aType An enumeration whose enumerators define the ownership of this 
       
  2595              mutex handle. If not explicitly specified, EOwnerProcess is taken
       
  2596              as default.
       
  2597              
       
  2598 @return KErrNone if successful, otherwise one of the system wide error codes.
       
  2599 
       
  2600 @see RHandleBase::Duplicate()
       
  2601 */
       
  2602 	{
       
  2603 	return SetReturnedHandle(Exec::MutexCreate(NULL,aType),*this);
       
  2604 	}
       
  2605 
       
  2606 
       
  2607 
       
  2608 
       
  2609 EXPORT_C TInt RMutex::CreateGlobal(const TDesC &aName,TOwnerType aType)
       
  2610 /**
       
  2611 Creates a global mutex and opens this handle to the mutex.
       
  2612 
       
  2613 The kernel side object representing the mutex is given the name contained 
       
  2614 in the specified descriptor, which makes it global. This means that any thread 
       
  2615 in any process can search for the mutex, using TFindMutex, and open a handle 
       
  2616 to it. If the specified name is empty the kernel side object representing the
       
  2617 mutex is unnamed and so cannot be opened by name. It can however be passed
       
  2618 to another process as a process parameter or via IPC.
       
  2619 
       
  2620 By default, any thread in the process can use this instance of RMutex to access 
       
  2621 the mutex. However, specifying EOwnerThread as the second parameter to this 
       
  2622 function, means that only the creating thread can use this instance of RMutex 
       
  2623 to access the mutex; any other thread in this process that wants to access 
       
  2624 the mutex must either duplicate this handle or use OpenGlobal().
       
  2625 
       
  2626 @param aName The name to be assigned to this global mutex.
       
  2627 @param aType An enumeration whose enumerators define the ownership of this 
       
  2628              mutex handle. If not explicitly specified, EOwnerProcess is
       
  2629              taken as default. 
       
  2630              
       
  2631 @return KErrNone if successful, otherwise one of the other system wide error 
       
  2632         codes. 
       
  2633         
       
  2634 @see OpenGlobal
       
  2635 @see RHandleBase::Duplicate()
       
  2636 @see TFindMutex
       
  2637 */
       
  2638 	{
       
  2639 	TInt r = User::ValidateName(aName);
       
  2640 	if(KErrNone!=r)
       
  2641 		return r;
       
  2642 	TBuf8<KMaxKernelName> name8;
       
  2643 	name8.Copy(aName);
       
  2644 	return SetReturnedHandle(Exec::MutexCreate(&name8,aType),*this);
       
  2645 	}
       
  2646 
       
  2647 
       
  2648 
       
  2649 
       
  2650 EXPORT_C TInt RMutex::OpenGlobal(const TDesC &aName,TOwnerType aType)
       
  2651 /**
       
  2652 Opens a handle to a global mutex.
       
  2653 
       
  2654 Global mutexes are identified by name.
       
  2655 
       
  2656 By default, any thread in the process can use this instance of RMutex to access 
       
  2657 the mutex. However, specifying EOwnerThread as the second parameter to this 
       
  2658 function, means that only the opening thread can use this instance of RMutex 
       
  2659 to access the mutex; any other thread in this process that wants to access 
       
  2660 the mutex must either duplicate the handle or use OpenGlobal() again.
       
  2661 
       
  2662 @param aName The name of the global mutex which is to be opened. 
       
  2663 @param aType An enumeration whose enumerators define the ownership of this 
       
  2664              mutex handle. If not explicitly specified, EOwnerProcess 
       
  2665              is taken as default. 
       
  2666              
       
  2667 @return KErrNone if successful, otherwise another of the system wide error 
       
  2668         codes. 
       
  2669 @see RHandleBase::Duplicate()
       
  2670 */
       
  2671 	{
       
  2672 	return OpenByName(aName,aType,EMutex);
       
  2673 	}
       
  2674 
       
  2675 
       
  2676 
       
  2677 
       
  2678 EXPORT_C TInt RMutex::Open(RMessagePtr2 aMessage,TInt aParam,TOwnerType aType)
       
  2679 /**
       
  2680 Opens a handle to a mutex using a handle number sent by a client
       
  2681 to a server.
       
  2682 
       
  2683 This function is called by the server.
       
  2684 
       
  2685 @param aMessage The message pointer.
       
  2686 @param aParam   An index specifying which of the four message arguments
       
  2687                 contains the handle number.
       
  2688 @param aType    An enumeration whose enumerators define the ownership of this 
       
  2689                 mutex handle. If not explicitly specified, EOwnerProcess is
       
  2690                 taken as default. 
       
  2691                 
       
  2692 @return KErrNone, if successful;
       
  2693         KErrArgument, if the value of aParam is outside the range 0-3;
       
  2694         KErrBadHandle, if not a valid handle;
       
  2695         otherwise one of the other system-wide error codes.
       
  2696 */
       
  2697 	{
       
  2698 	return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),EMutex,aParam,aType));
       
  2699 	}
       
  2700 
       
  2701 
       
  2702 
       
  2703 
       
  2704 EXPORT_C TInt RMutex::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
       
  2705 /**
       
  2706 Opens a handle to a mutex using a handle number passed as an
       
  2707 environment data item to the child process during the creation of
       
  2708 that child process.
       
  2709 
       
  2710 Note that this function can only be called successfully once.
       
  2711 
       
  2712 @param aArgumentIndex An index that identifies the slot in the process
       
  2713                       environment data that contains the handle number. This is
       
  2714                       a value relative to zero, i.e. 0 is the first item/slot.
       
  2715                       This can range from 0 to 15.
       
  2716 
       
  2717 @param aOwnerType     An enumeration whose enumerators define the ownership of
       
  2718                       this mutex handle. If not explicitly specified,
       
  2719                       EOwnerProcess is taken as default.
       
  2720 
       
  2721 @return KErrNone, if successful; 
       
  2722         KErrNotFound, if the slot indicated by aArgumentIndex is empty;
       
  2723         KErrArgument, if the slot does not contain a mutex handle;
       
  2724         otherwise one of the other system-wide error codes.
       
  2725         
       
  2726 @see RProcess::SetParameter()
       
  2727 */
       
  2728 	{
       
  2729 	return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, EMutex, aOwnerType));
       
  2730 	}
       
  2731 
       
  2732 
       
  2733 
       
  2734 EXPORT_C TInt RCondVar::CreateLocal(TOwnerType aType)
       
  2735 /**
       
  2736 Creates a condition variable and opens this handle to it.
       
  2737 
       
  2738 The kernel side object representing the condition variable is unnamed and so
       
  2739 the condition variable cannot be found by name and hence it is local to the
       
  2740 current process.
       
  2741 
       
  2742 By default, any thread in the process can use this instance of RCondVar to access
       
  2743 the condition variable. However, specifying EOwnerThread as the parameter to this
       
  2744 function means that only the creating thread can use this instance of RCondVar
       
  2745 to access the condition variable; any other thread in this process that wants to
       
  2746 access the condition variable must duplicate this handle.
       
  2747 
       
  2748 @param aType	An enumeration whose enumerators define the ownership of this 
       
  2749 				condition variable handle. If not explicitly specified, EOwnerProcess
       
  2750 				is taken as default.
       
  2751              
       
  2752 @return KErrNone if successful, otherwise one of the system wide error codes.
       
  2753 
       
  2754 @see RHandleBase::Duplicate()
       
  2755 */
       
  2756 	{
       
  2757 	return SetReturnedHandle(Exec::CondVarCreate(NULL, aType), *this);
       
  2758 	}
       
  2759 
       
  2760 
       
  2761 
       
  2762 
       
  2763 EXPORT_C TInt RCondVar::CreateGlobal(const TDesC& aName, TOwnerType aType)
       
  2764 /**
       
  2765 Creates a global condition variable and opens this handle to it.
       
  2766 
       
  2767 If the specified name is a non-empty string the kernel side object representing
       
  2768 the condition variable is given the specified name and is therefore global. It
       
  2769 may subsequently be opened by name using the RCondVar::OpenGlobal function.
       
  2770 If the specified name is empty the kernel side object representing the condition
       
  2771 variable is unnamed and so cannot be opened by name. It can however be passed
       
  2772 to another process as a process parameter or via IPC.
       
  2773 
       
  2774 If the specified name is non-empty it must consist entirely of printable ASCII
       
  2775 characters (codes 0x20 to 0x7e inclusive) and may not contain : * or ?.
       
  2776 
       
  2777 By default, any thread in the process can use this instance of RCondVar to access
       
  2778 the condition variable. However, specifying EOwnerThread as the parameter to this
       
  2779 function means that only the creating thread can use this instance of RCondVar
       
  2780 to access the condition variable; any other thread in this process that wants to
       
  2781 access the condition variable must duplicate this handle.
       
  2782 
       
  2783 @param aName	The name to be assigned to this condition variable.
       
  2784 @param aType	An enumeration whose enumerators define the ownership of this 
       
  2785 				condition variable handle. If not explicitly specified, EOwnerProcess
       
  2786 				is taken as default.
       
  2787                           
       
  2788 @return KErrNone if successful, otherwise one of the other system wide error 
       
  2789         codes. 
       
  2790         
       
  2791 @see RCondVar::OpenGlobal()
       
  2792 @see RHandleBase::Duplicate()
       
  2793 @see RProcess::SetParameter(TInt, RHandleBase)
       
  2794 @see TIpcArgs::Set(TInt, RHandleBase)
       
  2795 @see RMessagePtr2::Complete(RHandleBase)
       
  2796 */
       
  2797 	{
       
  2798 	TInt r = User::ValidateName(aName);
       
  2799 	if (KErrNone!=r)
       
  2800 		return r;
       
  2801 	TBuf8<KMaxKernelName> name8;
       
  2802 	name8.Copy(aName);
       
  2803 	return SetReturnedHandle(Exec::CondVarCreate(&name8, aType), *this);
       
  2804 	}
       
  2805 
       
  2806 
       
  2807 
       
  2808 
       
  2809 EXPORT_C TInt RCondVar::OpenGlobal(const TDesC& aName, TOwnerType aType)
       
  2810 /**
       
  2811 Opens a handle to a global condition variable.
       
  2812 
       
  2813 Global condition variables are identified by name.
       
  2814 
       
  2815 By default, any thread in the process can use this instance of RCondVar to access
       
  2816 the condition variable. However, specifying EOwnerThread as the parameter to this
       
  2817 function means that only the creating thread can use this instance of RCondVar
       
  2818 to access the condition variable; any other thread in this process that wants to
       
  2819 access the condition variable must either duplicate this handle or use OpenGlobal
       
  2820 again.
       
  2821 
       
  2822 @param aName The name of the global condition variable which is to be opened. 
       
  2823 @param aType An enumeration whose enumerators define the ownership of this 
       
  2824              condition variable handle. If not explicitly specified, EOwnerProcess
       
  2825              is taken as default. 
       
  2826              
       
  2827 @return KErrNone if successful, otherwise another of the system wide error 
       
  2828         codes. 
       
  2829         
       
  2830 @see RHandleBase::Duplicate()
       
  2831 */
       
  2832 	{
       
  2833 	return OpenByName(aName, aType, ECondVar);
       
  2834 	}
       
  2835 
       
  2836 
       
  2837 
       
  2838 
       
  2839 EXPORT_C TInt RCondVar::Open(RMessagePtr2 aMessage, TInt aParam, TOwnerType aType)
       
  2840 /**
       
  2841 Opens a handle to a condition variable using a handle number sent by a client
       
  2842 to a server.
       
  2843 
       
  2844 This function is called by the server.
       
  2845 
       
  2846 @param aMessage The message pointer.
       
  2847 @param aParam   An index specifying which of the four message arguments
       
  2848                 contains the handle number.
       
  2849 @param aType    An enumeration whose enumerators define the ownership of this 
       
  2850                 condition variable handle. If not explicitly specified, EOwnerProcess
       
  2851 				is taken as default.
       
  2852                 
       
  2853 @return KErrNone, if successful;
       
  2854         KErrArgument, if the value of aParam is outside the range 0-3;
       
  2855         KErrBadHandle, if not a valid handle;
       
  2856         otherwise one of the other system-wide error codes.
       
  2857 */
       
  2858 	{
       
  2859 	return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(), ECondVar, aParam, aType));
       
  2860 	}
       
  2861 
       
  2862 
       
  2863 
       
  2864 
       
  2865 EXPORT_C TInt RCondVar::Open(TInt aArgumentIndex, TOwnerType aType)
       
  2866 /**
       
  2867 Opens a handle to a condition variable using a handle number passed as an
       
  2868 environment data item to the child process during the creation of
       
  2869 that child process.
       
  2870 
       
  2871 Note that this function can only be called successfully once.
       
  2872 
       
  2873 @param aArgumentIndex An index that identifies the slot in the process
       
  2874                       environment data that contains the handle number. This is
       
  2875                       a value relative to zero, i.e. 0 is the first item/slot.
       
  2876                       This can range from 0 to 15.
       
  2877 
       
  2878 @param aType          An enumeration whose enumerators define the ownership of
       
  2879                       this condition variable handle. If not explicitly specified,
       
  2880                       EOwnerProcess is taken as default.
       
  2881 
       
  2882 @return KErrNone, if successful; 
       
  2883         KErrNotFound, if the slot indicated by aArgumentIndex is empty;
       
  2884         KErrArgument, if the slot does not contain a condition variable handle;
       
  2885         otherwise one of the other system-wide error codes.
       
  2886         
       
  2887 @see RProcess::SetParameter()
       
  2888 */
       
  2889 	{
       
  2890 	return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ECondVar, aType));
       
  2891 	}
       
  2892 
       
  2893 
       
  2894 
       
  2895 
       
  2896 EXPORT_C TInt RSemaphore::CreateLocal(TInt aCount,TOwnerType aType)
       
  2897 /**
       
  2898 Creates a semaphore, setting its initial count, and opens this handle to the 
       
  2899 semaphore.
       
  2900 
       
  2901 The kernel side object representing the semaphore is unnamed. This means that 
       
  2902 it is not possible to search for the semaphore, which makes it local to the 
       
  2903 current process.
       
  2904 
       
  2905 By default, any thread in the process can use this instance of RSemaphore 
       
  2906 to access the semaphore. However, specifying EOwnerThread as the second parameter 
       
  2907 to this function, means that only the creating thread can use this instance 
       
  2908 of RSemaphore to access the semaphore; any other thread in this process that 
       
  2909 wants to access the semaphore must duplicate this handle.
       
  2910 
       
  2911 @param aCount The initial value of the semaphore count. 
       
  2912 @param aType  An enumeration whose enumerators define the ownership of this 
       
  2913               semaphore handle. If not explicitly specified, EOwnerProcess is
       
  2914               taken as default. 
       
  2915 
       
  2916 @return KErrNone if successful, otherwise another of the system wide error 
       
  2917         codes. 
       
  2918         
       
  2919 @panic USER 105 if aCount is negative.
       
  2920 
       
  2921 @see RHandleBase::Duplicate()
       
  2922 */
       
  2923 	{
       
  2924 
       
  2925 	__ASSERT_ALWAYS(aCount>=0,Panic(ESemCreateCountNegative));
       
  2926 	return SetReturnedHandle(Exec::SemaphoreCreate(NULL,aCount,aType),*this);
       
  2927 	}
       
  2928 
       
  2929 
       
  2930 
       
  2931 
       
  2932 EXPORT_C TInt RSemaphore::CreateGlobal(const TDesC &aName,TInt aCount,TOwnerType aType)
       
  2933 /**
       
  2934 Creates a global semaphore, setting its initial count, and opens this handle
       
  2935 to the semaphore.
       
  2936 
       
  2937 The kernel side object representing the semaphore is given the name contained 
       
  2938 in the specified descriptor, which makes it global. This means that any thread 
       
  2939 in any process can search for the semaphore, using TFindSemaphore, and open 
       
  2940 a handle to it. If the specified name is empty the kernel side object
       
  2941 representing the semaphore is unnamed and so cannot be opened by name. It can
       
  2942 however be passed to another process as a process parameter or via IPC.
       
  2943 
       
  2944 By default, any thread in the process can use this instance of RSemaphore 
       
  2945 to access the semaphore. However, specifying EOwnerThread as the third
       
  2946 parameter to this function, means that only the creating thread can use
       
  2947 this instance of RSemaphore to access the semaphore; any other thread in
       
  2948 this process that wants to access the semaphore must either duplicate this
       
  2949 handle or use OpenGlobal().
       
  2950 
       
  2951 @param aName  A reference to the descriptor containing the name to be assigned 
       
  2952               to this global semaphore. 
       
  2953 @param aCount The initial value of the semaphore count.
       
  2954 @param aType  An enumeration whose enumerators define the ownership of this 
       
  2955               semaphore handle. If not explicitly specified, EOwnerProcess is
       
  2956               taken as default. 
       
  2957 
       
  2958 @return KErrNone if successful otherwise another of the system wide error
       
  2959         codes. 
       
  2960 
       
  2961 @panic USER 105 if aCount is negative.
       
  2962 
       
  2963 @see RSemaphore::OpenGlobal()
       
  2964 @see RHandleBase::Duplicate()
       
  2965 @see TFindSemaphore
       
  2966 */
       
  2967 	{
       
  2968 
       
  2969 	__ASSERT_ALWAYS(aCount>=0,Panic(ESemCreateCountNegative));
       
  2970 	TInt r = User::ValidateName(aName);
       
  2971 	if(KErrNone!=r)
       
  2972 		return r;
       
  2973 	TBuf8<KMaxKernelName> name8;
       
  2974 	name8.Copy(aName);
       
  2975 	return SetReturnedHandle(Exec::SemaphoreCreate(&name8,aCount,aType),*this);
       
  2976 	}
       
  2977 
       
  2978 
       
  2979 
       
  2980 
       
  2981 EXPORT_C TInt RSemaphore::OpenGlobal(const TDesC &aName,TOwnerType aType)
       
  2982 /**
       
  2983 Opens a handle to a global semaphore.
       
  2984 
       
  2985 Global semaphores are identified by name.
       
  2986 
       
  2987 By default, any thread in the process can use this instance of RSemaphore 
       
  2988 to access the semaphore. However, specifying EOwnerThread as the second parameter 
       
  2989 to this function, means that only the opening thread can use this instance 
       
  2990 of RSemaphore to access the semaphore; any other thread in this process that 
       
  2991 wants to access the semaphore must either duplicate the handle or use OpenGlobal() 
       
  2992 again.
       
  2993 
       
  2994 @param aName A reference to the descriptor containing the name of the global 
       
  2995              semaphore  to be opened. 
       
  2996 @param aType An enumeration whose enumerators define the ownership of this 
       
  2997              semaphore handle. If not explicitly specified, EOwnerProcess is
       
  2998              taken as default. 
       
  2999 
       
  3000 @return KErrNone if successful otherwise another of the system wide error
       
  3001         codes. 
       
  3002 
       
  3003 @see RHandleBase::Duplicate()
       
  3004 */
       
  3005 	{
       
  3006 	return OpenByName(aName,aType,ESemaphore);
       
  3007 	}
       
  3008 
       
  3009 
       
  3010 
       
  3011 
       
  3012 EXPORT_C TInt RSemaphore::Open(RMessagePtr2 aMessage,TInt aParam,TOwnerType aType)
       
  3013 /**
       
  3014 Opens a handle to a semaphore using a handle number sent by a client
       
  3015 to a server.
       
  3016 
       
  3017 This function is called by the server.
       
  3018 
       
  3019 @param aMessage The message pointer.
       
  3020 @param aParam   An index specifying which of the four message arguments
       
  3021                 contains the handle number.
       
  3022 @param aType    An enumeration whose enumerators define the ownership of this 
       
  3023                 semaphore handle. If not explicitly specified, EOwnerProcess is
       
  3024                 taken as default. 
       
  3025                 
       
  3026 @return KErrNone, if successful;
       
  3027         KErrArgument, if the value of aParam is outside the range 0-3;
       
  3028         KErrBadHandle, if not a valid handle;
       
  3029         otherwise one of the other system-wide error codes.
       
  3030 */
       
  3031 	{
       
  3032 	return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),ESemaphore,aParam,aType));
       
  3033 	}
       
  3034 
       
  3035 
       
  3036 
       
  3037 
       
  3038 EXPORT_C TInt RSemaphore::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
       
  3039 /**
       
  3040 Opens a handle to a semaphore using a handle number passed as an
       
  3041 environment data item to the child process during the creation of
       
  3042 that child process.
       
  3043 
       
  3044 Note that this function can only be called successfully once.
       
  3045 
       
  3046 @param aArgumentIndex An index that identifies the slot in the process
       
  3047                       environment data that contains the handle number. This is
       
  3048                       a value relative to zero, i.e. 0 is the first item/slot.
       
  3049                       This can range from 0 to 15.
       
  3050 
       
  3051 @param aOwnerType     An enumeration whose enumerators define the ownership of
       
  3052                       this semaphore handle. If not explicitly specified,
       
  3053                       EOwnerProcess is taken as default.
       
  3054 
       
  3055 @return KErrNone, if successful; 
       
  3056         KErrNotFound, if the slot indicated by aArgumentIndex is empty;
       
  3057         KErrArgument, if the slot does not contain a Semaphore handle;
       
  3058         otherwise one of the other system-wide error codes.
       
  3059         
       
  3060 @see RProcess::SetParameter()
       
  3061 */
       
  3062 	{
       
  3063 	return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ESemaphore, aOwnerType));
       
  3064 	}
       
  3065 
       
  3066 
       
  3067 
       
  3068 
       
  3069 EXPORT_C TInt RCriticalSection::CreateLocal(TOwnerType aType)
       
  3070 /**
       
  3071 Creates a critical section and opens this handle to the critical section.
       
  3072 
       
  3073 The kernel side object representing the critical section is unnamed. This 
       
  3074 means that it is not possible to search for the critical section, which makes 
       
  3075 it local to the current process.
       
  3076 
       
  3077 By default, any thread in the process can use this instance of RCriticalSection 
       
  3078 to access the critical section. However, specifying EOwnerThread as the parameter 
       
  3079 to this function, means that only the creating thread can use this instance 
       
  3080 of RCriticalSection to access the critical section; any other thread in this 
       
  3081 process that wants to access the critical section must duplicate this handle.
       
  3082 
       
  3083 @param aType An enumeration whose enumerators define the ownership of this 
       
  3084              critical section handle. If not explicitly specified,
       
  3085              EOwnerProcess is taken as default. 
       
  3086              
       
  3087 @return KErrNone if successful otherwise another of the system wide error codes.
       
  3088 
       
  3089 @see RHandleBase::Duplicate()
       
  3090 */
       
  3091 	{
       
  3092 
       
  3093 	iBlocked=1;
       
  3094 	return(RSemaphore::CreateLocal(0,aType));
       
  3095 	}
       
  3096 
       
  3097 
       
  3098 
       
  3099 /**
       
  3100 Creates a local fast semaphore, and opens this handle to the 
       
  3101 semaphore.
       
  3102 
       
  3103 @param aType  An enumeration whose enumerators define the ownership of this 
       
  3104               semaphore handle. If not explicitly specified, EOwnerProcess is
       
  3105               taken as default. 
       
  3106 
       
  3107 @return KErrNone if successful, otherwise one of the system wide error 
       
  3108         codes. 
       
  3109 
       
  3110 @see RSemaphore::CreateLocal()
       
  3111 */
       
  3112 EXPORT_C TInt RFastLock::CreateLocal(TOwnerType aType)
       
  3113 	{
       
  3114 
       
  3115 	iCount=0;
       
  3116 	return RSemaphore::CreateLocal(0,aType);
       
  3117 	}
       
  3118 
       
  3119 
       
  3120 
       
  3121 
       
  3122 EXPORT_C TInt RTimer::CreateLocal()
       
  3123 //
       
  3124 // Create a local timer.
       
  3125 //
       
  3126 /**
       
  3127 Creates a thread-relative timer.
       
  3128 
       
  3129 @return KErrNone if successful, otherwise another of the
       
  3130         system-wide error codes.
       
  3131 */
       
  3132 	{
       
  3133 	return SetReturnedHandle(Exec::TimerCreate(),*this);
       
  3134 	}
       
  3135 
       
  3136 
       
  3137 
       
  3138 
       
  3139 EXPORT_C TInt RProcess::Open(const TDesC &aName,TOwnerType aType)
       
  3140 /**
       
  3141 Opens a handle to a specifically named process.
       
  3142 
       
  3143 By default, ownership of this process handle is vested in the current process, 
       
  3144 but can be vested in the current thread by passing EOwnerThread as the second 
       
  3145 parameter to this function.
       
  3146 
       
  3147 @param aName A reference to the descriptor containing the name of the process 
       
  3148              to be opened.
       
  3149 @param aType An enumeration whose enumerators define the ownership of this 
       
  3150              thread handle. If not explicitly specified, EOwnerProcess is
       
  3151              taken as default.
       
  3152              
       
  3153 @return KErrNone, if successful, otherwise one of the other system-wide error 
       
  3154         codes.
       
  3155 */
       
  3156 	{
       
  3157 	return OpenByName(aName,aType,EProcess);
       
  3158 	}
       
  3159 
       
  3160 
       
  3161 
       
  3162 
       
  3163 EXPORT_C TInt RProcess::Open(TProcessId aId,TOwnerType aType)
       
  3164 /**
       
  3165 Opens a handle to the process whose process Id matches
       
  3166 the specified process ID.
       
  3167 
       
  3168 By default, ownership of this process handle is vested in the current process, 
       
  3169 but can be vested in the current thread by passing EOwnerThread as the second 
       
  3170 parameter to this function.
       
  3171 
       
  3172 @param aId   The process Id used to find the process.
       
  3173 @param aType An enumeration whose enumerators define the ownership of this 
       
  3174              process handle. If not explicitly specified, EOwnerProcess is
       
  3175              taken as default.
       
  3176              
       
  3177 @return KErrNone, if successful, otherwise one of the other system-wide error
       
  3178         codes.
       
  3179 */
       
  3180 	{
       
  3181 
       
  3182 	TUint id=*(TUint*)&aId;
       
  3183 	return SetReturnedHandle(Exec::ProcessOpenById(id,aType),*this);
       
  3184 	}
       
  3185 
       
  3186 
       
  3187 
       
  3188 
       
  3189 EXPORT_C TInt User::RenameProcess(const TDesC &aName)
       
  3190 /**
       
  3191 Assigns a new name to the current process, replacing any existing name.
       
  3192 
       
  3193 When a process is created, its default name is the name portion of the filename 
       
  3194 from which the executable is loaded.
       
  3195 
       
  3196 The new name must be a valid name and it must also be such that the process's 
       
  3197 new fullname remains unique amongst processes. 
       
  3198 
       
  3199 @param aName A reference to the descriptor containing the new name of the 
       
  3200              process.
       
  3201              
       
  3202 @return KErrNone, if successful, or if the new and old names are identical;
       
  3203         KErrBadName, if aName is an invalid;
       
  3204         otherwise one of the other system-wide error codes.
       
  3205 */
       
  3206 	{
       
  3207 	TBuf8<KMaxKernelName> name8;
       
  3208 	name8.Copy(aName);
       
  3209 	return Exec::ProcessRename(KCurrentProcessHandle,name8);
       
  3210 	}
       
  3211 
       
  3212 
       
  3213 
       
  3214 
       
  3215 /**
       
  3216 Ends this process, and all of its threads, specifying a reason code.
       
  3217 
       
  3218 This function is intended to be used if a process is exiting under normal
       
  3219 conditions.
       
  3220 
       
  3221 If the process is system permanent, the entire system is rebooted.
       
  3222 
       
  3223 @param aReason The reason to be associated with the ending of this process.
       
  3224 
       
  3225 @capability PowerMgmt  except when one of the following situations is true:
       
  3226 					   1. the process calling this function is the same as the 
       
  3227 					      process to be terminated.
       
  3228 					   2. the process calling this function created the process
       
  3229 					      to be terminated, but has not yet resumed that process.
       
  3230 
       
  3231 @see User::SetProcessCritical()
       
  3232 @see User::ProcessCritical()
       
  3233 */
       
  3234 EXPORT_C void RProcess::Kill(TInt aReason)
       
  3235 	{
       
  3236 	Exec::ProcessKill(iHandle,EExitKill,aReason,NULL);
       
  3237 	}
       
  3238 
       
  3239 
       
  3240 /**
       
  3241 Ends this process, and all of its threads, specifying a reason code.
       
  3242 
       
  3243 This function is intended to be used if a process is exiting under abnormal
       
  3244 conditions, for example if an error condition has been detected.
       
  3245 
       
  3246 If the process is system critical or system permanent, the entire system is
       
  3247 rebooted.
       
  3248 
       
  3249 @param aReason The reason to be associated with the ending of this process.
       
  3250 
       
  3251 @capability PowerMgmt  except when one of the following situations is true:
       
  3252 					   1. the process calling this function is the same as the 
       
  3253 					      process to be terminated.
       
  3254 					   2. the process calling this function created the process
       
  3255 					      to be terminated, but has not yet resumed that process.
       
  3256 
       
  3257 @see User::SetProcessCritical()
       
  3258 @see User::ProcessCritical()
       
  3259 */
       
  3260 EXPORT_C void RProcess::Terminate(TInt aReason)
       
  3261 	{
       
  3262 	Exec::ProcessKill(iHandle,EExitTerminate,aReason,NULL);
       
  3263 	}
       
  3264 
       
  3265 
       
  3266 
       
  3267 /**
       
  3268 Panics the process and all of its owned threads, specifying the panic category
       
  3269 name and reason code.
       
  3270 
       
  3271 The length of the category name should be no greater than 16; any name with 
       
  3272 a length greater than 16 is truncated to 16.
       
  3273 
       
  3274 If the process is system critical or system permanent, the entire system is
       
  3275 rebooted.
       
  3276 
       
  3277 @param aCategory A reference to the descriptor containing the text which
       
  3278                  defines the category name for this panic.
       
  3279 @param aReason   The panic number.
       
  3280 
       
  3281 @capability PowerMgmt  except when one of the following situations is true:
       
  3282 					   1. the process calling this function is the same as the 
       
  3283 					      process to be terminated.
       
  3284 					   2. the process calling this function created the process
       
  3285 					      to be terminated, but has not yet resumed that process.
       
  3286 
       
  3287 @see User::SetProcessCritical()
       
  3288 @see User::ProcessCritical()
       
  3289 */
       
  3290 EXPORT_C void RProcess::Panic(const TDesC &aCategory,TInt aReason)
       
  3291 	{
       
  3292 	TBuf8<KMaxExitCategoryName> name8;
       
  3293 	TInt length=aCategory.Length();
       
  3294 	if(length>KMaxExitCategoryName)
       
  3295 		{
       
  3296 		TPtr catPtr((TUint16*)aCategory.Ptr(),KMaxExitCategoryName,KMaxExitCategoryName);
       
  3297 		name8.Copy(catPtr);
       
  3298 		}
       
  3299 	else
       
  3300 		{
       
  3301 		name8.Copy(aCategory);
       
  3302 		}
       
  3303 	Exec::ProcessKill(iHandle,EExitPanic,aReason,&name8);
       
  3304 	}
       
  3305 
       
  3306 
       
  3307 
       
  3308 
       
  3309 EXPORT_C void RProcess::Logon(TRequestStatus &aStatus) const
       
  3310 /**
       
  3311 Requests notification when this process dies, normally or otherwise.
       
  3312 
       
  3313 A request for notification is an asynchronous request, and completes:
       
  3314 
       
  3315 - when the process terminates
       
  3316 - if the outstanding request is cancelled by a call to RProcess::LogonCancel().
       
  3317 
       
  3318 A request for notification requires memory to be allocated; if this is
       
  3319 unavailable, then the call to Logon() returns, and the asynchronous request
       
  3320 completes immediately.
       
  3321 
       
  3322 @param aStatus A reference to the request status object.
       
  3323                This contains the reason code describing the reason for  
       
  3324                the termination of the process, i.e. the value returned by a call to RProcess::ExitReason().
       
  3325                Alternatively, this is set to:
       
  3326                KErrCancel, if an outstanding request is cancelled;
       
  3327                KErrNoMemory, if there is insufficient memory to deal with the request. 
       
  3328 
       
  3329 @see RProcess::LogonCancel()
       
  3330 @see RProcess::ExitReason()
       
  3331 */
       
  3332 	{
       
  3333 
       
  3334 	aStatus=KRequestPending;
       
  3335 	Exec::ProcessLogon(iHandle,&aStatus,EFalse);
       
  3336 	}
       
  3337 
       
  3338 
       
  3339 
       
  3340 
       
  3341 EXPORT_C TInt RProcess::LogonCancel(TRequestStatus &aStatus) const
       
  3342 /**
       
  3343 Cancels an outstanding request for notification of the death of this process.
       
  3344 
       
  3345 A request for notification must previously have been made, otherwise the function 
       
  3346 returns KErrGeneral.
       
  3347 
       
  3348 The caller passes a reference to the same request status object as was passed 
       
  3349 in the original call to Logon().
       
  3350 
       
  3351 @param aStatus A reference to the same request status object used in
       
  3352                the original call to Logon().
       
  3353                
       
  3354 @return KErrGeneral, if there is no outstanding request; KErrNone otherwise.
       
  3355 
       
  3356 @see RProcess::Logon()
       
  3357 */
       
  3358 	{
       
  3359 	return Exec::ProcessLogonCancel(iHandle,&aStatus,EFalse);
       
  3360 	}
       
  3361 
       
  3362 
       
  3363 
       
  3364 
       
  3365 /**
       
  3366 Creates a Rendezvous request with the process.
       
  3367 
       
  3368 The request is an asynchronous request, and completes:
       
  3369 
       
  3370 - when a call is made to RProcess::Rendezvous(TInt aReason).
       
  3371 - if the outstanding request is cancelled by a call to RProcess::RendezvousCancel()
       
  3372 - if the process exits
       
  3373 - if the process panics.
       
  3374 
       
  3375 Note that a request requires memory to be allocated; if this is unavailable,
       
  3376 then this call to Rendezvous() returns, and the asynchronous request
       
  3377 completes immediately.
       
  3378 
       
  3379 @param aStatus A reference to the request status object.
       
  3380                The Rendezvous completes normally when 
       
  3381                RProcess::Rendezvous(TInt aReason) is called, and this 
       
  3382                request status object will contain this reason code.
       
  3383                If the process exits or panics, then this is the process exit
       
  3384                reason value, i.e. the same value returned by RProcess::ExitReason().
       
  3385                Alternatively, this is set to:
       
  3386                KErrCancel, if an outstanding request is cancelled;
       
  3387                KErrNoMemory, if there is insufficient memory to deal with the request.
       
  3388 
       
  3389 @see RProcess::Rendezvous(TInt aReason)
       
  3390 @see RProcess::RendezvousCancel(TRequestStatus& aStatus)
       
  3391 */
       
  3392 EXPORT_C void RProcess::Rendezvous(TRequestStatus& aStatus) const
       
  3393 	{
       
  3394 	aStatus=KRequestPending;
       
  3395 	Exec::ProcessLogon(iHandle,&aStatus,ETrue);
       
  3396 	}
       
  3397 
       
  3398 
       
  3399 
       
  3400 
       
  3401 /**
       
  3402 Cancels a previously requested Rendezvous with the process.
       
  3403 
       
  3404 The request completes with the value KErrCancel (if it was still outstanding).
       
  3405 
       
  3406 @param aStatus A reference to the same request status object used in
       
  3407                the original call to Rendezvous(TRequestStatus& aStatus).
       
  3408 
       
  3409 @return KErrGeneral, if there is no outstanding request, KErrNone otherwise.
       
  3410 
       
  3411 @see RProcess::Rendezvous(TRequestStatus &aStatus)
       
  3412 */
       
  3413 EXPORT_C TInt RProcess::RendezvousCancel(TRequestStatus& aStatus) const
       
  3414 	{
       
  3415 	return Exec::ProcessLogonCancel(iHandle,&aStatus,ETrue);
       
  3416 	}
       
  3417 
       
  3418 
       
  3419 
       
  3420 
       
  3421 /**
       
  3422 Completes all Rendezvous' with the current process.
       
  3423 
       
  3424 @param aReason The reason code used to complete all rendezvous requests
       
  3425 
       
  3426 @see RProcess::Rendezvous(TRequestStatus& aStatus)
       
  3427 */
       
  3428 EXPORT_C void RProcess::Rendezvous(TInt aReason)
       
  3429 	{
       
  3430 	Exec::ProcessRendezvous(aReason);
       
  3431 	}
       
  3432 
       
  3433 
       
  3434 /**
       
  3435 This can be used to determine whether the data for the process is demand paged
       
  3436 by default or not.
       
  3437 
       
  3438 @return ETrue if the default for the process's data is to be demand paged, 
       
  3439 		EFalse otherwise.
       
  3440 
       
  3441 @prototype
       
  3442 */
       
  3443 EXPORT_C TBool RProcess::DefaultDataPaged() const
       
  3444 	{
       
  3445 	return Exec::ProcessDefaultDataPaged(iHandle);
       
  3446 	}
       
  3447 
       
  3448 
       
  3449 //
       
  3450 // Class TThreadCreateInfo
       
  3451 //
       
  3452 
       
  3453 /**
       
  3454 Constructor where the basic properties of the thread to be created are specified.
       
  3455 
       
  3456 NOTE - TThreadCreateInfo::SetCreateHeap() or TThreadCreateInfo::SetUseHeap() must
       
  3457 be invoked on this TThreadCreateInfo to set the type of the thread to be created
       
  3458 before being passed as a paramter to RThread::Create().
       
  3459 
       
  3460 @param aName        The name to be assigned to the thread.
       
  3461 					KNullDesC, to create an anonymous thread.
       
  3462 @param aFunction    A pointer to a function. Control passes to this function
       
  3463                     when the thread is first resumed, i.e. when the thread
       
  3464                     is initially scheduled to run.
       
  3465 @param aStackSize   The size of the new thread's stack.
       
  3466 @param aPtr         A pointer to data to be passed as a parameter to
       
  3467                     the thread function when the thread is initially scheduled
       
  3468                     to run. If the thread function does not need any data then
       
  3469                     this pointer can be NULL.
       
  3470 */
       
  3471 EXPORT_C TThreadCreateInfo::TThreadCreateInfo(const TDesC &aName, TThreadFunction aFunction, 
       
  3472 											TInt aStackSize, TAny* aPtr) :
       
  3473 	iVersionNumber(EVersion0), iName(&aName), iFunction(aFunction), 
       
  3474 	iStackSize(aStackSize),	iParameter(aPtr), iOwner(EOwnerProcess), iHeap(NULL), 
       
  3475 	iHeapMinSize(0), iHeapMaxSize(0), iAttributes(0)
       
  3476 	{
       
  3477 	};
       
  3478 
       
  3479 
       
  3480 /**
       
  3481 Sets the thread to be created to create its own heap.
       
  3482 
       
  3483 @param aHeapMinSize The minimum size for the new thread's heap.
       
  3484 @param aHeapMaxSize The maximum size for the new thread's heap.
       
  3485 */
       
  3486 EXPORT_C void TThreadCreateInfo::SetCreateHeap(TInt aHeapMinSize, TInt aHeapMaxSize)
       
  3487 	{
       
  3488 	iHeapMinSize = aHeapMinSize;
       
  3489 	iHeapMaxSize = aHeapMaxSize;
       
  3490 	}
       
  3491 
       
  3492 
       
  3493 /**
       
  3494 Sets the thread to be created to use the heap whose handle is pointed to by 
       
  3495 aAllocator. If this is NULL, then the thread uses the heap of the creating thread.
       
  3496 
       
  3497 @param aAllocator A pointer to the handle of the heap belonging to another thread 
       
  3498                   which this thread is to use.
       
  3499 */
       
  3500 EXPORT_C void TThreadCreateInfo::SetUseHeap(const RAllocator *aAllocator)
       
  3501 	{
       
  3502 	iHeap = (aAllocator)? (RAllocator*)aAllocator : GetHeap();
       
  3503 	}
       
  3504 
       
  3505 
       
  3506 /**
       
  3507 Sets the owner the thread to be created. Any previous calls 
       
  3508 to this method will be overridden for this TThreadCreateInfo object.
       
  3509 
       
  3510 @param aOwner	The owner of the thread to be created.
       
  3511 */
       
  3512 EXPORT_C void TThreadCreateInfo::SetOwner(const TOwnerType aOwner)
       
  3513 	{
       
  3514 	iOwner = aOwner;
       
  3515 	}
       
  3516 
       
  3517 
       
  3518 /**
       
  3519 Sets the data paging attributes of the thread to be created. Any previous calls 
       
  3520 to this method will be overridden for this TThreadCreateInfo object.
       
  3521 
       
  3522 @param aPaging	The paging attributes for the thread to be created.
       
  3523 */
       
  3524 EXPORT_C void TThreadCreateInfo::SetPaging(const TThreadPagingAtt aPaging)
       
  3525 	{
       
  3526 	iAttributes &= ~EThreadCreateFlagPagingMask;
       
  3527 	if (aPaging == EPaged)
       
  3528 		iAttributes |= EThreadCreateFlagPaged;
       
  3529 	if (aPaging == EUnpaged)
       
  3530 		iAttributes |= EThreadCreateFlagUnpaged;
       
  3531 	}
       
  3532 
       
  3533 
       
  3534 /**
       
  3535 Creates a thread belonging to the current process, and opens this handle
       
  3536 to that thread.  The thread will have the properties as defined by the parameter
       
  3537 aCreateInfo.
       
  3538 
       
  3539 @param 	aCreateInfo		A reference to a TThreadCreateInfo object specifying 
       
  3540 						the properties of thread to create.
       
  3541 
       
  3542 @return KErrNone if successful, otherwise one of the other system-wide error codes.
       
  3543         KErrAlreadyExists will be returned if there is another thread in this process with the
       
  3544         specified name.
       
  3545 
       
  3546 @panic USER 109 if the stack size specified for the thread is negative.
       
  3547 @panic USER 110 if the specified minimum heap size is less than KMinHeapSize.
       
  3548 @panic USER 111 if the specified maximum heap size is less than the specified minimum heap size.
       
  3549 */
       
  3550 EXPORT_C TInt RThread::Create(const TThreadCreateInfo& aCreateInfo)
       
  3551 	{
       
  3552 	__ASSERT_ALWAYS(aCreateInfo.iStackSize >= 0, ::Panic(EThrdStackSizeNegative));
       
  3553 	if (!aCreateInfo.iHeap)
       
  3554 		{// Creating a new heap so verify the parameters.
       
  3555 		__ASSERT_ALWAYS(aCreateInfo.iHeapMinSize >= KMinHeapSize,::Panic(EThrdHeapMinTooSmall));
       
  3556 		__ASSERT_ALWAYS(aCreateInfo.iHeapMaxSize >= aCreateInfo.iHeapMinSize,::Panic(EThrdHeapMaxLessThanMin));
       
  3557 		}
       
  3558 
       
  3559 	TInt r = User::ValidateName(*aCreateInfo.iName);
       
  3560 	if(KErrNone!=r)
       
  3561 		return r;	
       
  3562 
       
  3563 	SStdEpocThreadCreateInfo8 info;
       
  3564 	info.iFunction = aCreateInfo.iFunction;
       
  3565 	info.iUserStackSize = aCreateInfo.iStackSize;
       
  3566 	info.iUserStack = NULL;
       
  3567 	info.iAllocator = aCreateInfo.iHeap;
       
  3568 	info.iHeapInitialSize = aCreateInfo.iHeapMinSize;
       
  3569 	info.iHeapMaxSize = aCreateInfo.iHeapMaxSize;
       
  3570 	info.iPtr = aCreateInfo.iParameter;
       
  3571 	info.iTotalSize = sizeof(info);
       
  3572 	info.iFlags = aCreateInfo.iAttributes;
       
  3573 
       
  3574 	TBuf8<KMaxKernelName> n;
       
  3575 	n.Copy(*aCreateInfo.iName);
       
  3576 
       
  3577 	return SetReturnedHandle(Exec::ThreadCreate(n, aCreateInfo.iOwner, info),*this);
       
  3578 	}
       
  3579 
       
  3580 
       
  3581 EXPORT_C TInt RThread::Create(const TDesC &aName,TThreadFunction aFunction,TInt aStackSize,TInt aHeapMinSize,TInt aHeapMaxSize,TAny *aPtr,TOwnerType aType)
       
  3582 /**
       
  3583 Creates a thread belonging to the current process, and opens this handle
       
  3584 to that thread.
       
  3585 
       
  3586 A new heap is created for this thread.
       
  3587 
       
  3588 By default, ownership of this thread handle is vested in the current process,
       
  3589 but can be vested in the current thread by passing EOwnerThread as
       
  3590 the second parameter to this function.
       
  3591 
       
  3592 If KNullDesC is specified for the name, then an anonymous thread will be created.
       
  3593 Anonymous threads are not global, and cannot be opened by other processes.
       
  3594 
       
  3595 @param aName        The name to be assigned to this thread.
       
  3596 					KNullDesC, to create an anonymous thread.
       
  3597 @param aFunction    A pointer to a function.. Control passes to this function
       
  3598                     when the thread is first resumed, i.e. when the thread
       
  3599                     is initially scheduled to run.
       
  3600 @param aStackSize   The size of the new thread's stack.
       
  3601 @param aHeapMinSize The minimum size for the new thread's heap.
       
  3602 @param aHeapMaxSize The maximum size for the new thread's heap.
       
  3603 @param aPtr         A pointer to data to be passed as a parameter to
       
  3604                     the thread function when the thread is initially scheduled
       
  3605                     to run. If the thread function does not need any data then
       
  3606                     this pointer can be NULL. It must be ensured that the memory 
       
  3607                     pointed to by this pointer is still valid when accessed by 
       
  3608                     the new thread, e.g. if aPtr points to data on the stack.
       
  3609 @param aType        An enumeration whose enumerators define the ownership of
       
  3610                     this thread handle. If not explicitly specified,
       
  3611                     EOwnerProcess is taken as default.
       
  3612 
       
  3613 @return KErrNone if successful, otherwise one of the other system-wide error codes.
       
  3614         KErrAlreadyExists will be returned if there is another thread in this process with the
       
  3615         specified name.
       
  3616 
       
  3617 @panic USER 109 if aStackSize is negative.
       
  3618 @panic USER 110 if aHeapMinSize is less than KMinHeapSize.
       
  3619 @panic USER 111 if aHeapMaxSize is less than aHeapMinSize.
       
  3620 */
       
  3621 	{
       
  3622 	TThreadCreateInfo createInfo(aName, aFunction, aStackSize, aPtr);
       
  3623 	createInfo.SetOwner(aType);
       
  3624 	createInfo.SetCreateHeap(aHeapMinSize, aHeapMaxSize);
       
  3625 	return Create(createInfo);
       
  3626 	}
       
  3627 
       
  3628 
       
  3629 
       
  3630 
       
  3631 EXPORT_C TInt RThread::Create(const TDesC& aName, TThreadFunction aFunction, TInt aStackSize, RAllocator* aAllocator, TAny* aPtr, TOwnerType aType)
       
  3632 /**
       
  3633 Creates a thread belonging to the current process, and opens this handle to 
       
  3634 that thread.
       
  3635 	
       
  3636 This thread uses the heap whose handle is pointed to by 
       
  3637 aAllocator. If this is NULL, then the thread uses the heap of the creating thread.
       
  3638 	
       
  3639 By default, ownership of this thread handle is vested in the current process, 
       
  3640 but can be vested in the current thread by passing EOwnerThread as the second 
       
  3641 parameter to this function.
       
  3642 
       
  3643 If KNullDesC is specified for the name, then an anonymous thread will be created.
       
  3644 Anonymous threads are not global, and cannot be opened by other processes.
       
  3645 
       
  3646 @param aName      The name to be assigned to this thread.
       
  3647 				  KNullDesC, to create an anonymous thread.
       
  3648 @param aFunction  A pointer to a function. Control passes to this function when 
       
  3649 	              the thread is first resumed, i.e. when the thread is
       
  3650 	              initially scheduled to run.
       
  3651 @param aStackSize The size of the new thread's stack.
       
  3652 @param aAllocator A pointer to the handle of the heap belonging to another thread 
       
  3653                   which this thread is to use.
       
  3654 @param aPtr       A pointer to data to be passed as a parameter to the thread
       
  3655                   function when the thread is initially scheduled to run.
       
  3656                   If the thread function does not need any data,
       
  3657                   then this pointer can be NULL. It must be ensured that the 
       
  3658                   memory pointed to by this pointer is still valid when accessed 
       
  3659                   by the new thread, e.g. if aPtr points to data on the stack.
       
  3660 @param aType      An enumeration whose enumerators define the ownership of this 
       
  3661                   thread handle. If not explicitly specified, EOwnerProcess is
       
  3662                   taken as default.
       
  3663 
       
  3664 @return KErrNone if successful otherwise one of the other system-wide error codes.
       
  3665         KErrAlreadyExists will be returned if there is another thread in this process with the
       
  3666         specified name.
       
  3667 
       
  3668 @panic USER 109 if aStackSize is negative.
       
  3669 */
       
  3670 	{
       
  3671 	TThreadCreateInfo createInfo(aName, aFunction, aStackSize, aPtr);
       
  3672 	createInfo.SetOwner(aType);
       
  3673 	createInfo.SetUseHeap(aAllocator);
       
  3674 	return Create(createInfo);
       
  3675 	}
       
  3676 
       
  3677 
       
  3678 
       
  3679 
       
  3680 EXPORT_C TInt RThread::Open(const TDesC &aName,TOwnerType aType)
       
  3681 /**
       
  3682 Opens a handle to specifically named thread.
       
  3683 
       
  3684 By default, ownership of this thread handle is vested in the
       
  3685 current process, but can be vested in the current thread by passing
       
  3686 EOwnerThread as the second parameter to this function.
       
  3687 
       
  3688 @param aName A reference to the descriptor containing the full name of the
       
  3689 			 thread that is already running.
       
  3690 @param aType An enumeration whose enumerators define the ownership of this
       
  3691              thread handle. If not explicitly specified, EOwnerProcess is taken
       
  3692              as default.
       
  3693 
       
  3694 @return KErrNone, if successful, otherwise one of the other	system-wide
       
  3695         error codes.
       
  3696 */
       
  3697 	{
       
  3698 	return OpenByName(aName,aType,EThread);
       
  3699 	}
       
  3700 
       
  3701 
       
  3702 
       
  3703 
       
  3704 EXPORT_C TInt RThread::Open(TThreadId aId,TOwnerType aType)
       
  3705 /**
       
  3706 Opens a handle to the thread with a specific thread Id.
       
  3707 
       
  3708 By default, ownership of this thread handle is vested in the
       
  3709 current process, but can be vested in the current thread by passing
       
  3710 EOwnerThread as the second parameter to this function.
       
  3711 
       
  3712 @param aId   The thread Id used to find the thread.
       
  3713 @param aType An enumeration whose enumerators define the ownership of this
       
  3714              thread handle. If not explicitly specified, EOwnerProcess is taken
       
  3715              as default.
       
  3716 
       
  3717 @return KErrNone, if successful, otherwise one of the other	system-wide
       
  3718         error codes.
       
  3719 */
       
  3720 //
       
  3721 // Open an already running thread in any process.
       
  3722 //
       
  3723 	{
       
  3724 
       
  3725 	TUint id=*(TUint*)&aId;
       
  3726 	return SetReturnedHandle(Exec::ThreadOpenById(id,aType),*this);
       
  3727 	}
       
  3728 
       
  3729 
       
  3730 
       
  3731 
       
  3732 EXPORT_C TInt RThread::Process(RProcess &aProcess) const
       
  3733 /**
       
  3734 Opens a process-relative handle to the process which owns this thread.
       
  3735 
       
  3736 The caller must construct a default RProcess object and pass this to
       
  3737 the function. 
       
  3738 On return, aProcess is the open process-relative handle to the process owning 
       
  3739 this thread.
       
  3740 
       
  3741 The return value indicates the success or failure of this function.
       
  3742 
       
  3743 @param aProcess A reference to a default RProcess handle; on successful return 
       
  3744                 from this function, this is the process-relative handle
       
  3745                 to the process which owns this thread.
       
  3746                 
       
  3747 @return KErrNone, if successful, otherwise one of the other system-wide error 
       
  3748         codes.
       
  3749 */
       
  3750 	{
       
  3751 	return SetReturnedHandle(Exec::ThreadProcess(iHandle),aProcess);
       
  3752 	}
       
  3753 
       
  3754 
       
  3755 
       
  3756 
       
  3757 EXPORT_C TInt User::RenameThread(const TDesC &aName)
       
  3758 /**
       
  3759 Assigns a new name to the current thread, replacing any existing name that
       
  3760 may have been set.
       
  3761 
       
  3762 The new name must be a valid name and it must also be such that the thread's 
       
  3763 new fullname remains unique amongst threads. 
       
  3764 The length of the new name must be less than or equal to 80 (maximum length of 
       
  3765 kernel objects) otherwise a panic is raised.  
       
  3766 
       
  3767 @param aName A reference to the descriptor containing the new name for the 
       
  3768              thread.
       
  3769              
       
  3770 @return KErrNone if successful, otherwise one of the other system-wide error 
       
  3771         codes.
       
  3772 */
       
  3773 	{
       
  3774 	TBuf8<KMaxKernelName> name8;
       
  3775 	name8.Copy(aName);
       
  3776 	return Exec::ThreadRename(KCurrentThreadHandle,name8);
       
  3777 	}
       
  3778 
       
  3779 
       
  3780 
       
  3781 
       
  3782 EXPORT_C void RThread::Kill(TInt aReason)
       
  3783 /**
       
  3784 Ends the thread, specifying a reason code. 
       
  3785 
       
  3786 This function is dangerous and should be used only in cases where the target 
       
  3787 thread cannot end itself via the normal methods of calling User::Exit() or 
       
  3788 completing its thread function. A hypothetical example might be where a thread 
       
  3789 gets 'stuck' in a third-party DLL.
       
  3790 
       
  3791 The target thread gets no opportunity to execute any clean-up code, therefore 
       
  3792 incautious use of this function may lead to memory leaks. 
       
  3793 
       
  3794 It is functionally identical to RThread::Terminate(), the only difference 
       
  3795 between the two is a legacy distinction between a 'normal' reason for exiting
       
  3796 (use Kill) and an 'abnormal' reason (use Terminate). The choice of function 
       
  3797 is reflected in the return value of RThread::ExitType().
       
  3798 
       
  3799 The thread must be in the current process otherwise a panic is raised.
       
  3800 
       
  3801 If the thread is process permanent, or the thread is the last thread in the
       
  3802 process, then the process is also killed.  If the thread is system permanent, 
       
  3803 the entire system is rebooted.
       
  3804 
       
  3805 WARNING: If the target thread uses a shared heap then use of this function will 
       
  3806 cause an internal array used for thread-local storage (TLS) to be leaked. This 
       
  3807 leak is specific to ARM platforms which implement the CP15 feature and will
       
  3808 not occur on other platforms.
       
  3809 
       
  3810 @param aReason The reason to be associated with the ending of this thread.
       
  3811 
       
  3812 @see User::Exit()
       
  3813 @see User::SetCritical()
       
  3814 @see User::Critical()
       
  3815 @see RThread::Terminate()
       
  3816 @see RThread::ExitType()
       
  3817 */
       
  3818 	{
       
  3819 
       
  3820 	Exec::ThreadKill(iHandle,EExitKill,aReason,NULL);
       
  3821 	}
       
  3822 
       
  3823 
       
  3824 
       
  3825 
       
  3826 EXPORT_C void RThread::Terminate(TInt aReason)
       
  3827 /**
       
  3828 Ends the thread, specifying a reason code. 
       
  3829 
       
  3830 This function is dangerous and should be used only in cases where the target 
       
  3831 thread cannot end itself via the normal methods of calling User::Exit() or 
       
  3832 completing its thread function. A hypothetical example might be where a thread 
       
  3833 gets 'stuck' in a third-party DLL.
       
  3834 
       
  3835 The target thread gets no opportunity to execute any clean-up code, therefore 
       
  3836 incautious use of this function may lead to memory leaks. 
       
  3837 
       
  3838 It is functionally identical to RThread::Kill(), the only difference 
       
  3839 between the two is a legacy distinction between a 'normal' reason for exiting
       
  3840 (use Kill) and an 'abnormal' reason (use Terminate). The choice of function 
       
  3841 is reflected in the return value of RThread::ExitType().
       
  3842 
       
  3843 The thread must be in the current process otherwise a panic is raised.
       
  3844 
       
  3845 If the thread is process critical or process permanent, or the thread is the 
       
  3846 last thread in the process, then the process is also terminated.  If the thread
       
  3847 is system critical or system permanent, the entire system is rebooted.
       
  3848 
       
  3849 WARNING: If the target thread uses a shared heap then use of this function will 
       
  3850 cause an internal array used for thread-local storage (TLS) to be leaked. This 
       
  3851 leak is specific to ARM platforms which implement the CP15 feature and will
       
  3852 not occur on other platforms.
       
  3853 
       
  3854 @param aReason The reason to be associated with the ending of this thread.
       
  3855 
       
  3856 @see User::Exit()
       
  3857 @see User::SetCritical()
       
  3858 @see User::Critical()
       
  3859 @see RThread::Kill()
       
  3860 @see RThread::ExitType()
       
  3861 */
       
  3862 	{
       
  3863 
       
  3864 	Exec::ThreadKill(iHandle,EExitTerminate,aReason,NULL);
       
  3865 	}
       
  3866 
       
  3867 
       
  3868 
       
  3869 
       
  3870 EXPORT_C void RThread::Panic(const TDesC &aCategory,TInt aReason)
       
  3871 /**
       
  3872 Panics this thread, specifying the panic category name and reason.
       
  3873 
       
  3874 The length of the category name should be no greater than 16; any name with 
       
  3875 a length greater than 16 is truncated to 16.
       
  3876 
       
  3877 The calling thread, i.e. the thread in which this function is called, must be
       
  3878 in the same process as this target thread, otherwise the calling thread
       
  3879 is itself panicked.
       
  3880 
       
  3881 If the thread is process critical or process permanent, the process also panics.
       
  3882 If the thread is system critical or system permanent, the entire system is
       
  3883 rebooted.
       
  3884 
       
  3885 @param aCategory A reference to the descriptor containing the text which defines 
       
  3886                  the category name for this panic.
       
  3887 @param aReason The panic number.
       
  3888 
       
  3889 @panic KERN-EXEC 46 if this target thread's process is not the same as the
       
  3890                     calling thread's process. 
       
  3891 
       
  3892 @see User::SetCritical()
       
  3893 @see User::Critical()
       
  3894 */
       
  3895 	{
       
  3896 	
       
  3897 	TBuf8<KMaxExitCategoryName> cat;
       
  3898 	TInt len = aCategory.Length();
       
  3899 	if(len>KMaxExitCategoryName)
       
  3900 		{
       
  3901 		TPtr aCatPtr((TUint16*)aCategory.Ptr(),KMaxExitCategoryName,KMaxExitCategoryName);
       
  3902 		cat.Copy(aCatPtr);
       
  3903 		}
       
  3904 	else
       
  3905 		cat.Copy(aCategory);
       
  3906 	Exec::ThreadKill(iHandle,EExitPanic,aReason,&cat);
       
  3907 	}
       
  3908 
       
  3909 
       
  3910 
       
  3911 
       
  3912 EXPORT_C void RThread::Logon(TRequestStatus &aStatus) const
       
  3913 /**
       
  3914 Requests notification when this thread dies, normally or otherwise.
       
  3915 
       
  3916 A request for notification is an asynchronous request, and completes:
       
  3917 
       
  3918 - when the thread terminates
       
  3919 - if the outstanding request is cancelled by a call to RThread::LogonCancel().
       
  3920 
       
  3921 A request for notification requires memory to be allocated; if this is
       
  3922 unavailable, then the call to Logon() returns, and the asynchronous request
       
  3923 completes immediately.
       
  3924 
       
  3925 Note that even when a thread has died, it is not possible to create a new thread with the same name
       
  3926 until all handles on the dead thread have been closed.  If this is attempted, the call to
       
  3927 RThread::Create will fail with KErrAlreadyExists.
       
  3928 
       
  3929 @param aStatus A reference to the request status object.
       
  3930                This contains the reason code describing the reason for  
       
  3931                the termination of the thread, i.e. the value returned by a call to RThread::ExitReason().
       
  3932                Alternatively, this is set to:
       
  3933                KErrCancel, if an outstanding request is cancelled;
       
  3934                KErrNoMemory, if there is insufficient memory to deal with the request. 
       
  3935 
       
  3936 @see RThread::LogonCancel()
       
  3937 @see RThread::ExitReason()
       
  3938 @see RThread::Create()
       
  3939 */
       
  3940 	{
       
  3941 
       
  3942 	aStatus=KRequestPending;
       
  3943 	Exec::ThreadLogon(iHandle,&aStatus,EFalse);
       
  3944 	}
       
  3945 
       
  3946 
       
  3947 
       
  3948 
       
  3949 EXPORT_C TInt RThread::LogonCancel(TRequestStatus &aStatus) const
       
  3950 /**
       
  3951 Cancels an outstanding request for notification of the death of this thread.
       
  3952 
       
  3953 A request for notification must previously have been made, otherwise
       
  3954 the function returns KErrGeneral.
       
  3955 
       
  3956 The caller passes a reference to the same request status object as was passed 
       
  3957 in the original call to Logon().
       
  3958 
       
  3959 @param aStatus A reference to the same request status object used in
       
  3960                the original call to Logon().
       
  3961                
       
  3962 @return KErrGeneral, if there is no outstanding request, KErrNone otherwise.
       
  3963 */
       
  3964 	{
       
  3965 	return Exec::ThreadLogonCancel(iHandle,&aStatus,EFalse);
       
  3966 	}
       
  3967 
       
  3968 
       
  3969 
       
  3970 
       
  3971 /**
       
  3972 Creates a Rendezvous request with the thread.
       
  3973 
       
  3974 The request is an asynchronous request, and completes:
       
  3975 
       
  3976 - when the thread next calls RThread::Rendezvous(TInt aReason)
       
  3977 - if the outstanding request is cancelled by a call to RThread::RendezvousCancel()
       
  3978 - if the thread exits
       
  3979 - if the thread panics.
       
  3980 
       
  3981 Note that a request requires memory to be allocated; if this is unavailable,
       
  3982 then this call to Rendezvous() returns, and the asynchronous request
       
  3983 completes immediately.
       
  3984 
       
  3985 @param aStatus A reference to the request status object.
       
  3986                The Rendezvous completes normally when 
       
  3987                RThread::Rendezvous(TInt aReason) is called, and this 
       
  3988                request status object will contain this reason code.               
       
  3989                If the thread exits or panics, then this is the thread exit
       
  3990                reason value, i.e. the same value returned by RThread::ExitReason().
       
  3991                Alternatively, this is set to:
       
  3992                KErrCancel, if an outstanding request is cancelled;
       
  3993                KErrNoMemory, if there is insufficient memory to deal with the request.
       
  3994 
       
  3995 @see RThread::Rendezvous(TInt aReason)
       
  3996 @see RThread::RendezvousCancel(TRequestStatus& aStatus)
       
  3997 */
       
  3998 EXPORT_C void RThread::Rendezvous(TRequestStatus& aStatus) const
       
  3999 
       
  4000 	{
       
  4001 	aStatus=KRequestPending;
       
  4002 	Exec::ThreadLogon(iHandle,&aStatus,ETrue);
       
  4003 	}
       
  4004 
       
  4005 
       
  4006 
       
  4007 
       
  4008 /**
       
  4009 Cancels a previously requested Rendezvous with the thread
       
  4010 
       
  4011 The request completes with the value KErrCancel (if it was still outstanding).
       
  4012 
       
  4013 @param aStatus A reference to the same request status object used in
       
  4014                the original call to Rendezvous(TRequestStatus& aStatus).
       
  4015 
       
  4016 @return KErrGeneral, if there is no outstanding request, KErrNone otherwise.
       
  4017 
       
  4018 @see RThread::Rendezvous(TRequestStatus& aStatus)
       
  4019 */
       
  4020 EXPORT_C TInt RThread::RendezvousCancel(TRequestStatus& aStatus) const
       
  4021 	{
       
  4022 	return Exec::ThreadLogonCancel(iHandle,&aStatus,ETrue);
       
  4023 	}
       
  4024 
       
  4025 
       
  4026 
       
  4027 
       
  4028 /**
       
  4029 Completes all Rendezvous' with the current thread.
       
  4030 
       
  4031 @param aReason The reason code used to complete all rendezvous requests
       
  4032 
       
  4033 @see RThread::Rendezvous(TRequestStatus& aStatus)
       
  4034 */
       
  4035 EXPORT_C void RThread::Rendezvous(TInt aReason)
       
  4036 	{
       
  4037 	Exec::ThreadRendezvous(aReason);
       
  4038 	}
       
  4039 
       
  4040 
       
  4041 
       
  4042 
       
  4043 EXPORT_C TBusLocalDrive::TBusLocalDrive()
       
  4044 //
       
  4045 // Constructor
       
  4046 //
       
  4047 	: iStatus(KErrNotReady)
       
  4048 	{}
       
  4049 
       
  4050 
       
  4051 
       
  4052 
       
  4053 EXPORT_C TInt TBusLocalDrive::Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt aOffset,TInt aFlags)
       
  4054 //
       
  4055 // Read from the connected drive, and pass flags to driver
       
  4056 //
       
  4057 	{
       
  4058 	return RLocalDrive::Read(aPos,aLength,aTrg,aThreadHandle,aOffset,aFlags);
       
  4059 	}
       
  4060 
       
  4061 
       
  4062 
       
  4063 
       
  4064 EXPORT_C TInt TBusLocalDrive::Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt anOffset)
       
  4065 //
       
  4066 // Read from the connected drive.
       
  4067 //
       
  4068 	{
       
  4069 
       
  4070 	return RLocalDrive::Read(aPos,aLength,aTrg,aThreadHandle,anOffset);
       
  4071 	}
       
  4072 
       
  4073 
       
  4074 
       
  4075 
       
  4076 EXPORT_C TInt TBusLocalDrive::Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt aOffset,TInt aFlags)
       
  4077 //
       
  4078 // Write to the connected drive and pass flags to driver
       
  4079 //
       
  4080 	{
       
  4081 
       
  4082 	return RLocalDrive::Write(aPos,aLength,aSrc,aThreadHandle,aOffset,aFlags);
       
  4083 	}
       
  4084 
       
  4085 
       
  4086 
       
  4087 
       
  4088 EXPORT_C TInt TBusLocalDrive::Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt anOffset)
       
  4089 //
       
  4090 // Write to the connected drive.
       
  4091 //
       
  4092 	{
       
  4093 
       
  4094 	return RLocalDrive::Write(aPos,aLength,aSrc,aThreadHandle,anOffset);
       
  4095 	}
       
  4096 
       
  4097 
       
  4098 
       
  4099 
       
  4100 EXPORT_C TInt TBusLocalDrive::Read(TInt64 aPos,TInt aLength,TDes8& aTrg)
       
  4101 //
       
  4102 // Read from the connected drive.
       
  4103 //
       
  4104 	{
       
  4105 
       
  4106 	return RLocalDrive::Read(aPos,aLength,aTrg);
       
  4107 	}
       
  4108 
       
  4109 
       
  4110 
       
  4111 
       
  4112 EXPORT_C TInt TBusLocalDrive::Write(TInt64 aPos,const TDesC8& aSrc)
       
  4113 //
       
  4114 // Write to the connected drive.
       
  4115 //
       
  4116 	{
       
  4117 
       
  4118 	return RLocalDrive::Write(aPos,aSrc);
       
  4119 	}
       
  4120 
       
  4121 
       
  4122 
       
  4123 
       
  4124 EXPORT_C TInt TBusLocalDrive::Caps(TDes8& anInfo)
       
  4125 //
       
  4126 // Get the connected drive's capabilities info.
       
  4127 //
       
  4128 	{
       
  4129 
       
  4130 	return RLocalDrive::Caps(anInfo);
       
  4131 	}
       
  4132 
       
  4133 
       
  4134 
       
  4135 
       
  4136 const TInt KDefaultMaxBytesPerFormat=0x00004000;// 16K
       
  4137 const TInt KFormatSectorSize=0x00000200;		// 512
       
  4138 const TInt KFormatSectorShift=9;	
       
  4139 
       
  4140 EXPORT_C TInt TBusLocalDrive::Format(TFormatInfo &anInfo)
       
  4141 //
       
  4142 // Format the connected drive.
       
  4143 //
       
  4144 	{
       
  4145 	if (anInfo.i512ByteSectorsFormatted<0)
       
  4146 		return KErrArgument;
       
  4147 	if (!anInfo.iFormatIsCurrent)
       
  4148 		{
       
  4149 		anInfo.iFormatIsCurrent=ETrue;
       
  4150 		anInfo.i512ByteSectorsFormatted=0;
       
  4151 		anInfo.iMaxBytesPerFormat=KDefaultMaxBytesPerFormat;
       
  4152 
       
  4153 		// Get the capabilities of the drive.  If extra info is supported,
       
  4154 		// Then overrise the default KMaxBytesPerFormat
       
  4155 		TLocalDriveCapsV3Buf caps;
       
  4156 		Caps(caps);
       
  4157 		anInfo.iMaxBytesPerFormat = caps().iMaxBytesPerFormat ? caps().iMaxBytesPerFormat : KDefaultMaxBytesPerFormat;
       
  4158 		}
       
  4159 	TInt64 pos=TInt64(anInfo.i512ByteSectorsFormatted)<<KFormatSectorShift;
       
  4160 	TInt length=anInfo.iMaxBytesPerFormat;
       
  4161 	TInt r=RLocalDrive::Format(pos,length);
       
  4162 
       
  4163 	// A positive return code specifies that the format step
       
  4164 	// has been adjusted (possibly to account for the partition offset)
       
  4165 	if(r > 0)
       
  4166 		{
       
  4167 		length = r;
       
  4168 		r = KErrNone;
       
  4169 		}
       
  4170 
       
  4171 	if (r==KErrNone)
       
  4172 		{
       
  4173 		length+=KFormatSectorSize-1;
       
  4174 		length>>=KFormatSectorShift;
       
  4175 		anInfo.i512ByteSectorsFormatted+=length;
       
  4176 		}
       
  4177 	
       
  4178 	if (r==KErrEof)
       
  4179 		anInfo.iFormatIsCurrent=EFalse;
       
  4180 
       
  4181 	return r;
       
  4182 	}
       
  4183 
       
  4184 
       
  4185 
       
  4186 
       
  4187 EXPORT_C TInt TBusLocalDrive::Format(TInt64 aPos, TInt aLength)
       
  4188 //
       
  4189 // Format the connected drive.
       
  4190 //
       
  4191 	{
       
  4192 	TInt r = KErrNone;
       
  4193 
       
  4194 	do
       
  4195 		{
       
  4196 		if((r = RLocalDrive::Format(aPos, aLength)) > 0)
       
  4197 			{
       
  4198 			aPos += r;
       
  4199 			aLength -= r;
       
  4200 			if (aLength == 0)
       
  4201 				r = KErrNone;
       
  4202 			}
       
  4203 		}		
       
  4204 	while(r > 0);
       
  4205 	return(r);
       
  4206 	}
       
  4207 
       
  4208 
       
  4209 
       
  4210 
       
  4211 EXPORT_C TInt TBusLocalDrive::ControlIO(TInt aCommand, TAny* aParam1, TAny* aParam2)
       
  4212 //
       
  4213 // Control IO
       
  4214 // NB: If in a data-paging environment and this drive is the data-paging drive, this API will 
       
  4215 // return KErrNotSupported if either aParam1 or aParam2 are non-NULL to avoid the possibility
       
  4216 // of taking a data paging fault in the media driver's thread.
       
  4217 // For this reason, this function has been deprecated
       
  4218 
       
  4219 // @deprecated Callers of this function should use one of the other overloads 
       
  4220 //
       
  4221 	{
       
  4222 	return(RLocalDrive::ControlIO(aCommand,aParam1,aParam2));
       
  4223 	}
       
  4224 
       
  4225 
       
  4226 EXPORT_C TInt TBusLocalDrive::ControlIO(TInt aCommand, TDes8& aBuf, TInt aParam)
       
  4227 //
       
  4228 // Control IO 
       
  4229 // In a data-paging environment, this API allows the passed descriptor to be pinned in the context 
       
  4230 // of the client's thread to avoid taking a data paging fault in the media driver's thread
       
  4231 //
       
  4232 	{
       
  4233 	if (aBuf.MaxLength() == 0)
       
  4234 		return KErrArgument;
       
  4235 	return(RLocalDrive::ControlIO(aCommand, aBuf, aParam));
       
  4236 	}
       
  4237 
       
  4238 
       
  4239 EXPORT_C TInt TBusLocalDrive::ControlIO(TInt aCommand, TDesC8& aBuf, TInt aParam)
       
  4240 //
       
  4241 // Control IO 
       
  4242 // In a data-paging environment, this API allows the passed descriptor to be pinned in the context 
       
  4243 // of the client's thread to avoid taking a data paging fault in the media driver's thread
       
  4244 //
       
  4245 	{
       
  4246 	if (aBuf.Length() == 0)
       
  4247 		return KErrArgument;
       
  4248 	return(RLocalDrive::ControlIO(aCommand, aBuf, aParam));
       
  4249 	}
       
  4250 
       
  4251 EXPORT_C TInt TBusLocalDrive::ControlIO(TInt aCommand, TInt aParam1, TInt aParam2)
       
  4252 	{
       
  4253 	return(RLocalDrive::ControlIO(aCommand, aParam1, aParam2));
       
  4254 	}
       
  4255 
       
  4256 
       
  4257 
       
  4258 EXPORT_C TInt TBusLocalDrive::SetMountInfo(const TDesC8* aMountInfo,TInt aMessageHandle)
       
  4259 //
       
  4260 // Set the mount information on the local drive
       
  4261 //
       
  4262 	{
       
  4263 
       
  4264 	return RLocalDrive::SetMountInfo(aMountInfo,aMessageHandle);
       
  4265 	}
       
  4266 
       
  4267 
       
  4268 
       
  4269 
       
  4270 EXPORT_C TInt TBusLocalDrive::ForceRemount(TUint aFlags)
       
  4271 //
       
  4272 // Force a remount on the local drive
       
  4273 //
       
  4274 	{
       
  4275 
       
  4276 	TInt err = RLocalDrive::ForceMediaChange(aFlags);
       
  4277 	if(err != KErrNone)
       
  4278 		return err;
       
  4279 
       
  4280 	if(aFlags & ELocDrvRemountForceMediaChange)
       
  4281 		err = CheckMount();
       
  4282 
       
  4283 	return err;
       
  4284 	}
       
  4285 
       
  4286 
       
  4287 
       
  4288 
       
  4289 EXPORT_C TInt TBusLocalDrive::GetLastErrorInfo(TDes8& aErrorInfo)
       
  4290 //
       
  4291 // Get information on the local drives last error
       
  4292 //
       
  4293 	{
       
  4294 	
       
  4295 	return RLocalDrive::GetLastErrorInfo(aErrorInfo);
       
  4296 	}
       
  4297 
       
  4298 
       
  4299 
       
  4300 
       
  4301 EXPORT_C TLocalDriveCaps::TLocalDriveCaps()
       
  4302 //
       
  4303 // Constructor
       
  4304 //
       
  4305 	:	iSize(0),
       
  4306 		iType(EMediaNotPresent),
       
  4307 		iBattery(EBatNotSupported),
       
  4308 		iDriveAtt(0),
       
  4309 		iMediaAtt(0),
       
  4310 		iBaseAddress(NULL),
       
  4311 		iFileSystemId(0)
       
  4312 	{}
       
  4313 
       
  4314 
       
  4315 
       
  4316 
       
  4317 /**
       
  4318 @capability TCB
       
  4319 */
       
  4320 EXPORT_C TInt TBusLocalDrive::Connect(TInt aDriveNumber,TBool &aChangedFlag)
       
  4321 //
       
  4322 // Connect to the drive.
       
  4323 //
       
  4324 	{
       
  4325 
       
  4326 	return RLocalDrive::Connect(aDriveNumber, aChangedFlag);
       
  4327 	}
       
  4328 
       
  4329 
       
  4330 
       
  4331 
       
  4332 EXPORT_C void TBusLocalDrive::Disconnect()
       
  4333 //
       
  4334 // Disconnect from the drive.
       
  4335 //
       
  4336 	{
       
  4337 
       
  4338 	Close();
       
  4339 	}
       
  4340 
       
  4341 
       
  4342 
       
  4343 
       
  4344 EXPORT_C TInt TBusLocalDrive::Enlarge(TInt aLength)
       
  4345 //
       
  4346 // Increase the size of the connected drive by the specified length (in bytes).
       
  4347 //
       
  4348 	{
       
  4349 
       
  4350 	return RLocalDrive::Enlarge(aLength);
       
  4351 	}
       
  4352 
       
  4353 
       
  4354 
       
  4355 
       
  4356 EXPORT_C TInt TBusLocalDrive::ReduceSize(TInt aPos,TInt aLength)
       
  4357 //
       
  4358 // Reduce the size of the connected drive by removing the specified length
       
  4359 // (in bytes) starting at the specified position.
       
  4360 //
       
  4361 	{
       
  4362 
       
  4363 	return RLocalDrive::Reduce(aPos, aLength);
       
  4364 	}
       
  4365 
       
  4366 
       
  4367 
       
  4368 
       
  4369 /**
       
  4370 Attempt to unlock a password-enabled drive and optionally store the password in the password store.
       
  4371 
       
  4372 @param aPassword A descriptor containing the password data.
       
  4373 @param aStorePassword If ETrue, the password is added to the password store.
       
  4374 
       
  4375 @return KErrNone, if successful.
       
  4376 		KErrAlreadyExists, if the drive is already unlocked.
       
  4377 		KErrAccessDenied, if the drive unlock operation fails.
       
  4378 
       
  4379 @see TBusLocalDrive::SetPassword
       
  4380 @see TBusLocalDrive::Clear
       
  4381 @see TBusLocalDrive::ErasePassword
       
  4382 */
       
  4383 EXPORT_C TInt TBusLocalDrive::Unlock(const TDesC8& aPassword, TBool aStorePassword)
       
  4384    	{
       
  4385 	TInt err = CheckMount();
       
  4386 	if (err != KErrNone)
       
  4387 		return err;
       
  4388 
       
  4389 	if (!(Status() & KMediaAttLocked))
       
  4390 		return KErrAlreadyExists;
       
  4391 
       
  4392 	err = RLocalDrive::Unlock(aPassword, aStorePassword);
       
  4393 
       
  4394 	if(err == KErrLocked)
       
  4395 		err = KErrAccessDenied;
       
  4396 
       
  4397 	return err;
       
  4398    	}
       
  4399 
       
  4400 
       
  4401 
       
  4402 
       
  4403 /**
       
  4404 Attempt to lock password-enabled drive and optionally store the new password in the password store.
       
  4405 
       
  4406 @param aOldPassword A descriptor containing old password.
       
  4407 @param aNewPassword A descriptor containing new password.
       
  4408 @param aStorePassword If ETrue, the password is added to the password store.
       
  4409 
       
  4410 @return KErrNone, if successful.
       
  4411 		KErrAccessDenied, if the drive is already locked or the old password is incorrect.
       
  4412 
       
  4413 @see TBusLocalDrive::Unlock
       
  4414 @see TBusLocalDrive::Clear
       
  4415 @see TBusLocalDrive::ErasePassword
       
  4416 */
       
  4417 EXPORT_C TInt TBusLocalDrive::SetPassword(const TDesC8& aOldPassword, const TDesC8& aNewPassword, TBool aStorePassword)
       
  4418    	{
       
  4419 	TInt err = CheckMount();
       
  4420 	if (err != KErrNone)
       
  4421 		return err;
       
  4422 
       
  4423 	if (Status() & KMediaAttLocked)
       
  4424 		return KErrAccessDenied;
       
  4425 
       
  4426 	err = RLocalDrive::SetPassword(aOldPassword, aNewPassword, aStorePassword);
       
  4427 	if(err == KErrLocked)
       
  4428 		err = KErrAccessDenied;
       
  4429 
       
  4430 	return err;
       
  4431 	}
       
  4432 
       
  4433 
       
  4434 
       
  4435 
       
  4436 /**
       
  4437 Clears a password from a card - controller sets password to null.
       
  4438 volume will not be password-enabled next time it is powered up.
       
  4439 The password is cleared from the password store.
       
  4440 
       
  4441 @param aPassword A descriptor containing the password.
       
  4442 
       
  4443 @return KErrNone, if successful.
       
  4444 		KErrAccessDenied, if the drive is already locked or the password is incorrect.
       
  4445 
       
  4446 @see TBusLocalDrive::Unlock
       
  4447 @see TBusLocalDrive::SetPassword
       
  4448 @see TBusLocalDrive::ErasePassword
       
  4449 */
       
  4450 EXPORT_C TInt TBusLocalDrive::Clear(const TDesC8& aPassword)
       
  4451    	{
       
  4452 	TInt err = CheckMount();
       
  4453 	if (err != KErrNone)
       
  4454 		return err;
       
  4455 
       
  4456 	if (Status() & KMediaAttLocked)
       
  4457 		return KErrAccessDenied;
       
  4458 
       
  4459 	err = RLocalDrive::Clear(aPassword);
       
  4460 	if(err == KErrLocked)
       
  4461 		err = KErrAccessDenied;
       
  4462 
       
  4463 	return err;
       
  4464    	}
       
  4465 
       
  4466 
       
  4467 
       
  4468 
       
  4469 /**
       
  4470 Forcibly unlock a password-enabled drive.
       
  4471 KErrAccessDenied is returned if the drive is already mounted (and therefore unlocked)
       
  4472 or if the drive is not already mounted and the operation fails.
       
  4473 
       
  4474 @return KErrNone, if successful.
       
  4475 		KErrAccessDenied, if the drive is not locked or the operation is not supported.
       
  4476 
       
  4477 @see TBusLocalDrive::Unlock
       
  4478 @see TBusLocalDrive::SetPassword
       
  4479 @see TBusLocalDrive::ErasePassword
       
  4480 */
       
  4481 EXPORT_C TInt TBusLocalDrive::ErasePassword()
       
  4482    	{
       
  4483 	TInt err = CheckMount();
       
  4484 	if (err != KErrNone)
       
  4485 		return err;
       
  4486 
       
  4487 	if (!(Status() & KMediaAttLocked))
       
  4488 		return KErrAccessDenied;
       
  4489 
       
  4490 	err = RLocalDrive::ErasePassword();
       
  4491 	if(err != KErrNone)
       
  4492 		err = KErrAccessDenied;
       
  4493 
       
  4494 	return err;
       
  4495    	}
       
  4496 
       
  4497 
       
  4498 
       
  4499 
       
  4500 TInt TBusLocalDrive::CheckMount()
       
  4501 //
       
  4502 // Check the local drive can be, or is mounted
       
  4503 //
       
  4504 	{
       
  4505 	TLocalDriveCaps caps;
       
  4506 	TPckg<TLocalDriveCaps> capsPckg(caps);
       
  4507 	TInt err = RLocalDrive::Caps(capsPckg);
       
  4508 	iStatus = caps.iMediaAtt;
       
  4509 	return err;
       
  4510 	}
       
  4511 
       
  4512 
       
  4513 
       
  4514 /**
       
  4515 Write the password store to the peripheral bus controller.
       
  4516 
       
  4517 @return
       
  4518 	- KErrNone if Successful
       
  4519 	- KErrOverflow If aBuf is longer than TPasswordStore::EMaxPasswordLength
       
  4520 	- KErrCorrupt If store in aBuf is malformed. 
       
  4521 
       
  4522 @param aBuf Data to replace the current password store.
       
  4523 */
       
  4524 EXPORT_C TInt TBusLocalDrive::WritePasswordData(const TDesC8& aBuf)
       
  4525    	{
       
  4526 	return RLocalDrive::WritePasswordData(aBuf);
       
  4527 	}
       
  4528 
       
  4529 
       
  4530 
       
  4531 
       
  4532 EXPORT_C TInt TBusLocalDrive::ReadPasswordData(TDes8& aBuf)
       
  4533 //
       
  4534 // Read the entire password store from the peripheral bus controller.
       
  4535 //
       
  4536 	{
       
  4537 	return RLocalDrive::ReadPasswordData(aBuf);
       
  4538    	}
       
  4539 
       
  4540 
       
  4541 
       
  4542 
       
  4543 EXPORT_C TInt TBusLocalDrive::PasswordStoreLengthInBytes()
       
  4544 //
       
  4545 // Return the number of bytes used by peripheral bus controller password store.
       
  4546 //
       
  4547 	{
       
  4548 	return RLocalDrive::PasswordStoreLengthInBytes();
       
  4549 	}
       
  4550 
       
  4551 
       
  4552 
       
  4553 
       
  4554 EXPORT_C TInt TBusLocalDrive::DeleteNotify(TInt64 aPos, TInt aLength)
       
  4555 //
       
  4556 // Notify the media driver that an area of the partition has been deleted.
       
  4557 // This is used by certain media (e.g NAND flash) for garbage collection.
       
  4558 //
       
  4559 	{
       
  4560 	return RLocalDrive::DeleteNotify(aPos, aLength);
       
  4561 	}
       
  4562 
       
  4563 
       
  4564 /**
       
  4565 Query a property of the media device
       
  4566 
       
  4567 @prototype
       
  4568 @internalTechnology
       
  4569 */
       
  4570 EXPORT_C TInt TBusLocalDrive::QueryDevice(TQueryDevice aQueryDevice, TDes8 &aBuf)
       
  4571 	{
       
  4572 	return RLocalDrive::QueryDevice(aQueryDevice, aBuf);
       
  4573 	}
       
  4574 
       
  4575 
       
  4576 EXPORT_C void User::__DbgMarkStart(TBool aKernel)
       
  4577 /**
       
  4578 Marks the start of heap cell checking for the current thread's default heap,
       
  4579 or for the kernel heap.
       
  4580 	
       
  4581 If earlier calls to __DbgMarkStart() have been made, then this
       
  4582 call to __DbgMarkStart() marks the start of a new nested level of
       
  4583 heap cell checking.
       
  4584 	
       
  4585 Every call to __DbgMarkStart() should be matched by a later call
       
  4586 to __DbgMarkEnd() to verify that the number of heap cells allocated, at
       
  4587 the current nested level, is as expected.
       
  4588 This expected number of heap cells is passed to __DbgMarkEnd() 
       
  4589 as a parameter; however, the most common expected number is zero, reflecting 
       
  4590 the fact that the most common requirement is to check that all memory allocated
       
  4591 since a previous call to __DbgStartCheck() has been freed.
       
  4592 	
       
  4593 @param aKernel ETrue, if checking is being done for the kernel heap;
       
  4594                EFalse, if checking is being done for the current thread's
       
  4595                default heap.
       
  4596 */
       
  4597 	{
       
  4598 
       
  4599 	if (aKernel)
       
  4600 		Exec::KernelHeapDebug(EDbgMarkStart,0,NULL);
       
  4601 	else
       
  4602 		GetHeap()->__DbgMarkStart();
       
  4603 	}
       
  4604 
       
  4605 
       
  4606 
       
  4607 
       
  4608 EXPORT_C void User::__DbgMarkCheck(TBool aKernel, TBool aCountAll, TInt aCount, const TUint8* aFileName, TInt aLineNum)
       
  4609 //
       
  4610 // Call CheckNum for the default heap
       
  4611 //
       
  4612 /**
       
  4613 Checks the current number of allocated heap cells for the current thread's default 
       
  4614 heap, or the kernel heap.
       
  4615 
       
  4616 If aCountAll is true, the function checks that the total number of
       
  4617 allocated cells on the heap is the same as aCount. If aCountAll is false,
       
  4618 the function checks that the number of allocated cells at the current nested
       
  4619 level is the same as aCount.
       
  4620 
       
  4621 If checking fails, the function raises a panic. Information about the failure 
       
  4622 is put into the panic category, which takes the form:
       
  4623 
       
  4624 ALLOC COUNT\\rExpected aaa\\rAllocated bbb\\rLn: ccc ddd
       
  4625 
       
  4626 Where aaa is the value aCount, bbb is the number of allocated heap cells, 
       
  4627 ccc is a line number, copied from aLineNum, and ddd is a file name, copied 
       
  4628 from the descriptor aFileName.
       
  4629 
       
  4630 Note that the panic number is 1.
       
  4631 
       
  4632 @param aKernel   ETrue, if checking is being done for the kernel heap;
       
  4633                  EFalse, if checking is being done for the current thread's
       
  4634                  default heap.
       
  4635 @param aCountAll If true, the function checks that the total number of
       
  4636                  allocated cells on the heap is the same as aCount.
       
  4637                  If false, the function checks that the number of allocated
       
  4638                  cells at the current nested level is the same as aCount.
       
  4639 @param aCount    The expected number of allocated cells.
       
  4640 @param aFileName A filename; this is displayed as part of the panic category, 
       
  4641                  if the check fails.
       
  4642 @param aLineNum  A line number; this is displayed as part of the panic category, 
       
  4643                  if the check fails.
       
  4644 */
       
  4645 	{
       
  4646 
       
  4647 	if (!aKernel)
       
  4648 		GetHeap()->__DbgMarkCheck(aCountAll,aCount,aFileName,aLineNum);
       
  4649 	else
       
  4650 		{
       
  4651 		TPtrC8 filename(aFileName);
       
  4652 		TKernelHeapMarkCheckInfo info;
       
  4653 		info.iCountAll=aCountAll;
       
  4654 		info.iFileName=&filename;
       
  4655 		info.iLineNum=aLineNum;
       
  4656 		Exec::KernelHeapDebug(EDbgMarkCheck,aCount,&info);
       
  4657 		}
       
  4658 	}
       
  4659 
       
  4660 
       
  4661 
       
  4662 
       
  4663 EXPORT_C TUint32 User::__DbgMarkEnd(TBool aKernel, TInt aCount)
       
  4664 //
       
  4665 // Call CheckHeap for the default heap
       
  4666 //
       
  4667 /**
       
  4668 Marks the end of heap cell checking at the current nested level for the current
       
  4669 thread's default heap, or the kernel heap.
       
  4670 
       
  4671 The function checks that the number of heap cells allocated, at the current
       
  4672 nested level, is aCount. The most common value for aCount is zero, reflecting
       
  4673 the fact that the most common requirement is to check that all memory allocated
       
  4674 since a previous call to __DbgStartCheck() has been freed.
       
  4675 
       
  4676 A call to this function should match an earlier call to __DbgMarkStart().
       
  4677 If there are more calls to this function than calls to __DbgMarkStart(), then
       
  4678 this function raises a USER 51 panic.
       
  4679 
       
  4680 If the check fails for a user heap, the function raises an ALLOC: nnnnnnnn
       
  4681 panic, where nnnnnnnn is a hexadecimal pointer to the first orphaned heap
       
  4682 cell.
       
  4683 
       
  4684 If the check fails for the kernel heap, the kernel server raises a KERN-EXEC 17
       
  4685 panic.
       
  4686 
       
  4687 @param aKernel   ETrue, if checking is being done for the kernel heap;
       
  4688                  EFalse, if checking is being done for the current thread's
       
  4689                  default heap.
       
  4690 @param aCount    The number of allocated heap cells expected.
       
  4691 
       
  4692 @return Zero always.
       
  4693 */
       
  4694 	{
       
  4695 
       
  4696 	if (!aKernel)
       
  4697 		{
       
  4698 		TUint32 badCell=GetHeap()->__DbgMarkEnd(aCount);
       
  4699 		if (badCell!=0)
       
  4700 			{
       
  4701 			TBuf<0x10> info=_L("ALLOC: ");
       
  4702 			info.AppendFormat(_L("%x\n"), badCell);
       
  4703 			User::Panic(info,0);
       
  4704 			}
       
  4705 		return(badCell);
       
  4706 		}
       
  4707 	else
       
  4708 		Exec::KernelHeapDebug(EDbgMarkEnd,aCount,NULL);
       
  4709 	return(0);
       
  4710 	}
       
  4711 
       
  4712 
       
  4713 
       
  4714 
       
  4715 EXPORT_C void User::__DbgSetAllocFail(TBool aKernel, RAllocator::TAllocFail aType, TInt aRate)
       
  4716 //
       
  4717 // Set the failure rate for allocating from the default user heap
       
  4718 //
       
  4719 /**
       
  4720 Simulates a heap allocation failure for the current thread's default heap,
       
  4721 or the kernel heap.
       
  4722 
       
  4723 The failure occurs on subsequent calls to new or any of the functions which
       
  4724 allocate memory from the heap.
       
  4725 
       
  4726 The timing of the allocation failure depends on the type of allocation failure
       
  4727 requested, i.e. on the value of aType.
       
  4728 
       
  4729 The simulation of heap allocation failure is cancelled if aType is given
       
  4730 the value RAllocator::ENone.
       
  4731 
       
  4732 Notes:
       
  4733 
       
  4734 1. If the failure type is RHeap::EFailNext, the next attempt to allocate from
       
  4735    the heap fails; however, no further failures will occur.
       
  4736 
       
  4737 2. For failure types RHeap::EFailNext and RHeap::ENone, set aRate to 1.
       
  4738 
       
  4739 @param aKernel   ETrue, if checking is being done for the kernel heap;
       
  4740                  EFalse, if checking is being done for the current thread's
       
  4741                  default heap.
       
  4742 @param aType     An enumeration which indicates how to simulate heap
       
  4743                  allocation failure.
       
  4744 @param aRate     The rate of failure; when aType is RAllocator::EDeterministic,
       
  4745                  heap allocation fails every aRate attempts.
       
  4746 */
       
  4747 	{
       
  4748 
       
  4749 	if (aKernel)
       
  4750 		Exec::KernelHeapDebug(EDbgSetAllocFail,aType,(TAny*)aRate);
       
  4751 	else
       
  4752 		GetHeap()->__DbgSetAllocFail(aType,aRate);
       
  4753 	}
       
  4754 
       
  4755 /**
       
  4756 Simulates a heap allocation failure for the current thread's default heap,
       
  4757 or the kernel heap.
       
  4758 
       
  4759 The aBurst failures will occur after subsequent calls to new or any of the 
       
  4760 functions which allocate memory from the heap.
       
  4761 
       
  4762 The timing of the allocation failures will depend on the type of allocation failure
       
  4763 requested, i.e. on the value of aType.
       
  4764 
       
  4765 The simulation of heap allocation failure is cancelled if aType is given
       
  4766 the value RAllocator::ENone.
       
  4767 
       
  4768 
       
  4769 @param aKernel   ETrue, if checking is being done for the kernel heap;
       
  4770                  EFalse, if checking is being done for the current thread's
       
  4771                  default heap.
       
  4772 @param aType     An enumeration which indicates how to simulate heap
       
  4773                  allocation failure.
       
  4774 @param aRate     The rate of failure; when aType is RAllocator::EDeterministic,
       
  4775                  heap allocation fails every aRate attempts.
       
  4776 @param aBurst    The number of consecutive allocations that should fail.
       
  4777 
       
  4778 */
       
  4779 EXPORT_C void User::__DbgSetBurstAllocFail(TBool aKernel, RAllocator::TAllocFail aType, TUint aRate, TUint aBurst)
       
  4780 	{
       
  4781 	if (aKernel)
       
  4782 		{
       
  4783 		SRAllocatorBurstFail burstFail;
       
  4784 		burstFail.iRate = aRate;
       
  4785 		burstFail.iBurst = aBurst;
       
  4786 		Exec::KernelHeapDebug(EDbgSetBurstAllocFail, aType, (TAny*)&burstFail);
       
  4787 		}
       
  4788 	else
       
  4789 		GetHeap()->__DbgSetBurstAllocFail(aType, aRate, aBurst);	
       
  4790 	}
       
  4791 
       
  4792 
       
  4793 /**
       
  4794 Returns the number of heap allocation failures the current debug allocator fail
       
  4795 function has caused so far.
       
  4796 
       
  4797 This is intended to only be used with fail types RAllocator::EFailNext,
       
  4798 RAllocator::EBurstFailNext, RAllocator::EDeterministic and
       
  4799 RAllocator::EBurstDeterministic.  The return value is unreliable for 
       
  4800 all other fail types.
       
  4801 
       
  4802 @return The number of heap allocation failures the current debug fail 
       
  4803 function has caused.
       
  4804 
       
  4805 @see RAllocator::TAllocFail
       
  4806 */
       
  4807 EXPORT_C TUint User::__DbgCheckFailure(TBool aKernel)
       
  4808 	{
       
  4809 	TUint r;
       
  4810 	if (aKernel)
       
  4811 		Exec::KernelHeapDebug(EDbgCheckFailure, 0, (TAny*)&r);
       
  4812 	else
       
  4813 		r = GetHeap()->__DbgCheckFailure();
       
  4814 	return r;
       
  4815 	}
       
  4816 
       
  4817 EXPORT_C TInt RProcess::Create(const TDesC &aFileName,const TDesC &aCommand,TOwnerType aType)
       
  4818 /**
       
  4819 Starts a new process, loading the specified executable.
       
  4820 
       
  4821 The executable can be in ROM or RAM.
       
  4822 
       
  4823 By default, ownership of this process handle is vested in the current process, 
       
  4824 but can be vested in the current thread by specifying EOwnerThread as the 
       
  4825 third parameter to this function.
       
  4826 
       
  4827 @param aFileName A descriptor containing the full path name of the executable 
       
  4828                  to be loaded. If this name has no file extension,
       
  4829                  an extension of .EXE is appended. The length of the resulting
       
  4830                  full path name must not be greater than KMaxFileName.
       
  4831                  The length of the file name itself must not be greater
       
  4832                  than KMaxProcessName. If no path is specified, the system will 
       
  4833 				 look in \\sys\\bin on all drives.
       
  4834 @param aCommand  A descriptor containing data passed as an argument to
       
  4835                  the thread function of the new process's main thread,
       
  4836                  when it is first scheduled.
       
  4837 @param aType     Defines the ownership of this process handle. If not
       
  4838                  specified, EOwnerProcess is the default.
       
  4839                 
       
  4840 @return KErrNone if successful, otherwise one of the other system-wide error codes.
       
  4841 */
       
  4842 	{
       
  4843 
       
  4844 	return Create(aFileName, aCommand, TUidType(), aType);
       
  4845 	}
       
  4846 
       
  4847 
       
  4848 
       
  4849 
       
  4850 EXPORT_C TInt RProcess::Create(const TDesC &aFileName,const TDesC &aCommand,const TUidType &aUidType, TOwnerType aType)
       
  4851 /**
       
  4852 Starts a new process, loading the specified executable which matches
       
  4853 the specified UID type.
       
  4854 
       
  4855 The executable can be in ROM or RAM.
       
  4856 
       
  4857 By default, ownership of this process handle is vested in the current process, 
       
  4858 but can be vested in the current thread by specifying EOwnerThread as the 
       
  4859 fourth parameter.
       
  4860 
       
  4861 @param aFileName A descriptor containing the full path name of the executable 
       
  4862                  to be loaded. If this name has no file extension,
       
  4863                  an extension of .EXE is appended. The length of the resulting
       
  4864                  full path name must not be greater than KMaxFileName.
       
  4865                  The length of the file name itself must not be greater
       
  4866                  than KMaxProcessName. If no path is specified, the system will 
       
  4867 				 look in \\sys\\bin on all drives.
       
  4868 @param aCommand  A descriptor containing data passed as an argument to
       
  4869                  the thread function of the new process's main thread,
       
  4870                  when it is first scheduled.
       
  4871 @param aUidType  A UID type (a triplet of UIDs) which the executable must match. 
       
  4872 @param aType     Defines the ownership of this process handle. If not specified, 
       
  4873                  EOwnerProcess is the default.
       
  4874 				 
       
  4875 @return KErrNone if successful, otherwise one of the other system-wide error
       
  4876         codes.
       
  4877 */
       
  4878 	{
       
  4879 
       
  4880 	RLoader loader;
       
  4881 	TInt r=loader.Connect();
       
  4882 	if (r==KErrNone)
       
  4883 		r=loader.LoadProcess(iHandle,aFileName,aCommand,aUidType,aType);
       
  4884 	loader.Close();
       
  4885 	return r;
       
  4886 	}
       
  4887 
       
  4888 
       
  4889 EXPORT_C TInt RProcess::CreateWithStackOverride(const TDesC& aFileName,const TDesC& aCommand, const TUidType &aUidType, TInt aMinStackSize, TOwnerType aType)
       
  4890 /**
       
  4891 Starts a new process, loading the specified executable which matches
       
  4892 the specified UID type and the minimum stack size is the specified value.
       
  4893 
       
  4894 The executable can be in ROM or RAM.
       
  4895 
       
  4896 By default, ownership of this process handle is vested in the current process, 
       
  4897 but can be vested in the current thread by specifying EOwnerThread as the 
       
  4898 fourth parameter.
       
  4899 
       
  4900 
       
  4901 @param aFileName A descriptor containing the full path name of the executable 
       
  4902                  to be loaded. If this name has no file extension,
       
  4903                  an extension of .EXE is appended. The length of the resulting
       
  4904                  full path name must not be greater than KMaxFileName.
       
  4905                  The length of the file name itself must not be greater
       
  4906                  than KMaxProcessName. If no path is specified, the system will 
       
  4907 				 look in \\sys\\bin on all drives.
       
  4908 @param aCommand  A descriptor containing data passed as an argument to
       
  4909                  the thread function of the new process's main thread,
       
  4910                  when it is first scheduled.
       
  4911 @param aUidType  A UID type (a triplet of UIDs) which the executable must match. 
       
  4912 @param aMinStackSize Minimum stack size of the new process.
       
  4913 @param aType     Defines the ownership of this process handle. If not specified, 
       
  4914                  EOwnerProcess is the default.
       
  4915                  
       
  4916 @return KErrNone if successful, otherwise one of the other system-wide error
       
  4917         codes.
       
  4918 */
       
  4919 	{
       
  4920 
       
  4921 	RLoader loader;
       
  4922 	TInt r=loader.Connect();
       
  4923 	if (r==KErrNone)
       
  4924 	{
       
  4925 		r=loader.LoadProcess(iHandle,aFileName,aCommand,aUidType,aMinStackSize,aType);
       
  4926 	}
       
  4927 	loader.Close();
       
  4928 	return r;
       
  4929 	} 
       
  4930 
       
  4931 
       
  4932 
       
  4933 EXPORT_C TInt User::LoadLogicalDevice(const TDesC &aFileName)
       
  4934 /**
       
  4935 Loads the logical device driver (LDD) DLL with the specified filename.
       
  4936 
       
  4937 The function searches the system path for the LDD DLL, and loads it. It then 
       
  4938 makes a kernel server call that:
       
  4939 
       
  4940 1. creates the LDD factory object, an instance of a DLogicalDevice derived
       
  4941    class; this involves checking the first UID value to make sure that the DLL
       
  4942    is a  valid LDD before proceeding to call the exported function at
       
  4943    ordinal 1, which  creates the LDD factory object on the kernel heap
       
  4944 
       
  4945 2. calls the LDD factory object's Install() function to complete the installation
       
  4946 
       
  4947 3. adds the new LDD factory object to the kernel's list of LDD factory objects.
       
  4948 
       
  4949 @param aFileName A reference to the descriptor containing the name of the 
       
  4950                  physical device driver DLL. If the filename has no extension,
       
  4951                  .LDD is assumed by default.
       
  4952                  
       
  4953 @return KErrNone if successful or one of the system-wide error codes.
       
  4954 */
       
  4955 	{
       
  4956 	RLoader loader;
       
  4957 	return loader.LoadDeviceDriver(aFileName, 0);
       
  4958 	}
       
  4959 
       
  4960 
       
  4961 
       
  4962 
       
  4963 EXPORT_C TInt User::FreeLogicalDevice(const TDesC &aDeviceName)
       
  4964 /**
       
  4965 Frees the logical device driver DLL associated with a specified driver name.
       
  4966 
       
  4967 @param aDeviceName The name of the logical device driver object. This must 
       
  4968                    match the name set during installation of the logical
       
  4969                    device. Typically, this is done in an implementation
       
  4970                    of DLogicalDevice::Install() through a call to SetName().
       
  4971                    Note that the name is rarely the same as the device's
       
  4972                    filename. The name of a logical device driver object
       
  4973                    can be discovered by using TFindLogicalDevice.
       
  4974                    
       
  4975 @return KErrNone if successful or one of the system-wide error codes.  KErrNone
       
  4976 		will be	returned if the device is not found as it may have already been 
       
  4977 		freed.
       
  4978 */
       
  4979 	{
       
  4980 	TBuf8<KMaxFullName> aDeviceName8;
       
  4981 	aDeviceName8.Copy(aDeviceName);
       
  4982 	return Exec::DeviceFree(aDeviceName8,0);
       
  4983 	}
       
  4984 
       
  4985 
       
  4986 
       
  4987 
       
  4988 EXPORT_C TInt User::LoadPhysicalDevice(const TDesC &aFileName)
       
  4989 /**
       
  4990 Loads the physical device driver (PDD) DLL with the specified filename.
       
  4991 
       
  4992 The function searches the system path for the PDD DLL, and loads it. It then 
       
  4993 makes a kernel server call that:
       
  4994 
       
  4995 1. creates the PDD factory object, an instance of a DPhysicalDevice derived class;
       
  4996    this involves checking the first UID value to make sure that the DLL is a 
       
  4997    valid PDD before proceeding to call the exported function at ordinal 1, which 
       
  4998    creates the PDD factory object on the kernel heap
       
  4999 
       
  5000 2. calls the PDD factory object's Install() function to complete the installation
       
  5001 
       
  5002 2. adds the new PDD factory object to the kernel's list of PDD factory objects.
       
  5003 
       
  5004 @param aFileName A reference to the descriptor containing the name of the 
       
  5005                  physical device driver DLL. If the filename has no extension,
       
  5006                  .PDD is assumed by default.
       
  5007                  
       
  5008 @return KErrNone if successful or one of the system-wide error codes.
       
  5009 */
       
  5010 	{
       
  5011 	RLoader loader;
       
  5012 	return loader.LoadDeviceDriver(aFileName, 1);
       
  5013 	}
       
  5014 
       
  5015 
       
  5016 
       
  5017 
       
  5018 /**
       
  5019 Frees the physical device driver DLL associated with a specified driver name.
       
  5020 	
       
  5021 @param aDeviceName The name of the physical device driver object. This must 
       
  5022                    match the name set during installation of the physical
       
  5023                    device. Typically, this is done in an implementation of
       
  5024                    DPhysicalDevice::Install() through a call to SetName().
       
  5025                    Note that the name is rarely the same as the device's
       
  5026                    filename. The name of a physical device driver object can
       
  5027                    be discovered by using TFindPhysicalDevice.
       
  5028                    
       
  5029 @return KErrNone if successful or one of the system-wide error codes.  KErrNone 
       
  5030 		will be	returned if the device is not found as it may have already 
       
  5031 		been freed.
       
  5032 */
       
  5033 EXPORT_C TInt User::FreePhysicalDevice(const TDesC &aDeviceName)
       
  5034 
       
  5035 	{
       
  5036 	TBuf8<KMaxFullName> aDeviceName8;
       
  5037 	aDeviceName8.Copy(aDeviceName);
       
  5038 	return Exec::DeviceFree(aDeviceName8,1);
       
  5039 	}
       
  5040 
       
  5041 
       
  5042 
       
  5043 
       
  5044 EXPORT_C TInt RLoader::Connect()
       
  5045 //
       
  5046 // Connect with the loader.
       
  5047 //
       
  5048 	{
       
  5049 	_LIT(KLoaderServerName,"!Loader");
       
  5050 	return CreateSession(KLoaderServerName,Version(),0);
       
  5051 	}
       
  5052 
       
  5053 TVersion RLoader::Version() const
       
  5054 //
       
  5055 // Return the client side version number.
       
  5056 //
       
  5057 	{
       
  5058 
       
  5059 	return TVersion(KLoaderMajorVersionNumber,KLoaderMinorVersionNumber,KE32BuildVersionNumber);
       
  5060 	}
       
  5061 
       
  5062 TInt RLoader::LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TOwnerType aType)
       
  5063 //
       
  5064 // Execute another process.
       
  5065 //
       
  5066 	{
       
  5067 
       
  5068 	return (LoadProcess(aHandle, aFileName, aCommand, aUidType, KDefaultStackSize, aType)); 
       
  5069 		
       
  5070 	}
       
  5071 
       
  5072 
       
  5073 /**
       
  5074 	Execute another process.
       
  5075 
       
  5076 	@param aHandle
       
  5077 	@param aFileName
       
  5078 	@param aCommand
       
  5079 	@param aUidType
       
  5080 	@param aMinStackSize
       
  5081 	@param aType
       
  5082 
       
  5083 	@return
       
  5084 		KErrNone		if process created
       
  5085 		KErrBadName		if aFileName.Length() > KMaxFileName
       
  5086 		KErrArgument	if aMinStackSize < 0
       
  5087 			
       
  5088 */
       
  5089 TInt RLoader::LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TInt aMinStackSize, TOwnerType aType)
       
  5090 	{
       
  5091 		
       
  5092 	__IF_DEBUG(Print(_L("RLoader::LoadProcess started with %d bytes stack.\n"), aMinStackSize));
       
  5093 	
       
  5094 	if( 0 > aMinStackSize )
       
  5095 		return KErrArgument;
       
  5096 
       
  5097 	TLdrInfo info;
       
  5098 	info.iRequestedUids=aUidType; // match these uids only
       
  5099 	info.iOwnerType=aType;
       
  5100 	
       
  5101 	info.iMinStackSize=aMinStackSize;  	
       
  5102 		
       
  5103 	if (aFileName.Length()>KMaxFileName)
       
  5104 		return KErrBadName;
       
  5105 	
       
  5106 	TPckg<TLdrInfo> infoBuf(info);
       
  5107 	
       
  5108 	TInt r = SendReceive(ELoadProcess, TIpcArgs((TDes8*)&infoBuf, (const TDesC*)&aFileName, (const TDesC*)&aCommand) );
       
  5109 	aHandle = info.iHandle;
       
  5110 	__IF_DEBUG(Print(_L("LoadProcess returning %d"),r));
       
  5111 	return r;
       
  5112 	}
       
  5113 
       
  5114 /**
       
  5115     Check if the hash for the given library exists and optionally validate it.
       
  5116 
       
  5117     @param aFileName		the same as for RLoader::LoadLibrary
       
  5118     @param aValidateHash	if ETrue this function will validate library hash if it exists. Requires fully specified aFileName.
       
  5119 
       
  5120     @return
       
  5121 	    KErrNotSupported 	this feature is not supported by the emulator
       
  5122 	    KErrNone     		if aValidateHash=EFalse, it means that the hash exists; if  aValidateHash=ETrue, hash exists and valid, 
       
  5123 	    KErrCorrupt	        if aValidateHash=ETrue, the library hash exists but NOT valid, 
       
  5124 	    KErrNotFound	    no hash found
       
  5125         KErrArgument		bad file name
       
  5126 
       
  5127 */
       
  5128 EXPORT_C TInt RLoader::CheckLibraryHash(const TDesC& aFileName, TBool aValidateHash/*=EFalse*/)
       
  5129     {
       
  5130     __IF_DEBUG(Print(_L("RLoader::CheckLibraryHash")));
       
  5131 
       
  5132 	TLdrInfo info;
       
  5133 	TPckg<TLdrInfo> infoBuf(info);
       
  5134 	info.iOwnerType=EOwnerThread;
       
  5135 
       
  5136     TInt r = SendReceive(ECheckLibraryHash, TIpcArgs((TDes8*)&infoBuf, (const TDesC*)&aFileName, aValidateHash) );
       
  5137 
       
  5138 	return r;
       
  5139     }
       
  5140 
       
  5141 EXPORT_C TInt RLoader::LoadLibrary(TInt& aHandle, const TDesC& aFileName, const TDesC& aPath, const TUidType& aUidType, TUint32 aModuleVersion)
       
  5142 //
       
  5143 // Load a DLL
       
  5144 //
       
  5145 	{
       
  5146 
       
  5147 	__IF_DEBUG(Print(_L("RLoader::LoadLibrary")));
       
  5148 	TLdrInfo info;
       
  5149 	TPckg<TLdrInfo> infoBuf(info);
       
  5150 	info.iRequestedUids=aUidType; // match these uids only
       
  5151 	info.iOwnerType=EOwnerThread;
       
  5152 	info.iRequestedVersion=aModuleVersion;
       
  5153 	if (aFileName.Length()>KMaxFileName)
       
  5154 		return KErrBadName;
       
  5155 	aHandle=0;
       
  5156 
       
  5157 	TInt r=E32Loader::WaitDllLock();
       
  5158 	if (r==KErrNone)
       
  5159 		{
       
  5160 		r = SendReceive(ELoadLibrary, TIpcArgs((TDes8*)&infoBuf, (const TDesC*)&aFileName, (const TDesC*)&aPath) );
       
  5161 		aHandle=info.iHandle;
       
  5162 		if (r!=KErrNone)
       
  5163 			E32Loader::ReleaseDllLock();
       
  5164 		}
       
  5165 	__IF_DEBUG(Print(_L("LoadLibrary returning %d"),r));
       
  5166 	return r;
       
  5167 	}
       
  5168 
       
  5169 
       
  5170 EXPORT_C TInt RLoader::GetInfo(const TDesC& aFileName, TDes8& aInfoBuf)
       
  5171 //
       
  5172 // Get capabilities of a DLL
       
  5173 //
       
  5174 	{
       
  5175 	__IF_DEBUG(Print(_L("RLoader::GetInfo")));
       
  5176 	TLdrInfo info;
       
  5177 	TPckg<TLdrInfo> infoBuf(info);
       
  5178 	info.iOwnerType=EOwnerThread;
       
  5179 	if (aFileName.Length()>KMaxFileName)
       
  5180 		return KErrBadName;
       
  5181 	TInt r = SendReceive(EGetInfo, TIpcArgs((TDes8*)&infoBuf, (const TDesC*)&aFileName, (TDes8*)&aInfoBuf) );
       
  5182 	__IF_DEBUG(Print(_L("GetInfo returning %d"),r));
       
  5183 	return r;
       
  5184 	}
       
  5185 
       
  5186 
       
  5187 EXPORT_C TInt RLoader::Delete(const TDesC& aFileName)
       
  5188 /**
       
  5189 	Ask the loader to delete a file.  This function should be used instead
       
  5190 	of RFs::Delete where the supplied file may be a paged executable, although
       
  5191 	it can be used for any file.  A file that is currently paged may be moved
       
  5192 	by the system, and deleted later, when the file is no longer needed. This means
       
  5193 	that using this function may not immediately release the disk space associated
       
  5194 	with the file.
       
  5195 
       
  5196 	@param	aFileName		Fully-qualified filename.
       
  5197 	@return					Symbian OS error code.  Additionally, KErrBadName is
       
  5198 							returned if the supplied filename is not fully qualified..
       
  5199 	@capability Tcb
       
  5200 	@capability AllFiles
       
  5201  */
       
  5202 	{
       
  5203 	__IF_DEBUG(Printf(">RLoader::Delete,%S", &aFileName));
       
  5204 	TInt r = SendReceive(ELdrDelete, TIpcArgs(0, &aFileName));
       
  5205 	__IF_DEBUG(Printf("<RLoader::Delete,%d", r));
       
  5206 	return r;
       
  5207 	}
       
  5208 
       
  5209 #ifdef __WINS__
       
  5210 
       
  5211 #include <emulator.h>
       
  5212 
       
  5213 TInt RLoader::GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf)
       
  5214 	{
       
  5215 	__IF_DEBUG(Print(_L("RLoader::GetInfoFromHeader")));
       
  5216 
       
  5217 	TInt r = KErrNone;
       
  5218 
       
  5219 	Emulator::TModule module;
       
  5220 	module.iBase = aHeader.Ptr();
       
  5221 	TProcessCreateInfo info;
       
  5222 	module.GetInfo(info);
       
  5223 
       
  5224 	RLibrary::TInfoV2 ret_info;
       
  5225 	memclr(&ret_info,sizeof(ret_info));
       
  5226 	ret_info.iModuleVersion = info.iModuleVersion;
       
  5227 	ret_info.iUids = info.iUids;
       
  5228 	*(SSecurityInfo*)&ret_info.iSecurityInfo = info.iS;
       
  5229 	ret_info.iHardwareFloatingPoint = EFpTypeNone;
       
  5230 	TPckg<RLibrary::TInfoV2> ret_pckg(ret_info);
       
  5231 	if (aInfoBuf.MaxLength() < ret_pckg.Length())
       
  5232 		ret_pckg.SetLength(aInfoBuf.MaxLength());
       
  5233 	aInfoBuf=ret_pckg;
       
  5234 
       
  5235 	__IF_DEBUG(Print(_L("GetInfoFromHeader returning %d"),r));
       
  5236 	return r;
       
  5237 	}
       
  5238 
       
  5239 #else // not __WINS__ ...
       
  5240 
       
  5241 TInt RLoader::GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf)
       
  5242 	{
       
  5243 	__IF_DEBUG(Print(_L("RLoader::GetInfoFromHeader")));
       
  5244 	TInt r = SendReceive(EGetInfoFromHeader, TIpcArgs(&aHeader, &aInfoBuf) );
       
  5245 	__IF_DEBUG(Print(_L("GetInfoFromHeader returning %d"),r));
       
  5246 	return r;
       
  5247 	}
       
  5248 
       
  5249 #endif // __WINS__
       
  5250 
       
  5251 TInt RLoader::LoadDeviceDriver(const TDesC& aFileName, TInt aDeviceType)
       
  5252 	{
       
  5253 	TInt r=Connect();
       
  5254 	if (r==KErrNone)
       
  5255 		{
       
  5256 		TInt m = aDeviceType ? ELoadPhysicalDevice : ELoadLogicalDevice;
       
  5257 		r = SendReceive(m, TIpcArgs(0, (const TDesC*)&aFileName, 0) );
       
  5258 		Close();
       
  5259 		}
       
  5260 	return r;
       
  5261 	}
       
  5262 
       
  5263 TInt RLoader::LoadLocale(const TDesC& aLocaleDllName, TLibraryFunction* aExportList)
       
  5264 	{
       
  5265 	TInt r=Connect();
       
  5266 	if (r==KErrNone)
       
  5267 		{
       
  5268 		TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
       
  5269 		TPtr8 functionListBuf((TUint8*)aExportList, size, size);
       
  5270 		r = SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aLocaleDllName, &functionListBuf) );
       
  5271 		Close();
       
  5272 		}
       
  5273 	return r;
       
  5274 	}
       
  5275 
       
  5276 EXPORT_C TInt RLoader::DebugFunction(TInt aFunction, TInt a1, TInt a2, TInt a3)
       
  5277 	{
       
  5278 	return SendReceive(ELoaderDebugFunction, TIpcArgs(aFunction, a1, a2, a3) );
       
  5279 	}
       
  5280 
       
  5281 EXPORT_C TInt RLoader::CancelLazyDllUnload()
       
  5282 	{
       
  5283 	return SendReceive(ELoaderCancelLazyDllUnload, TIpcArgs() );
       
  5284 	}
       
  5285 
       
  5286 #ifdef __USERSIDE_THREAD_DATA__
       
  5287 
       
  5288 EXPORT_C TInt UserSvr::DllSetTls(TInt aHandle, TAny* aPtr)
       
  5289 //
       
  5290 // Set the value of the Thread Local Storage variable.
       
  5291 //
       
  5292 	{
       
  5293 	return LocalThreadData()->DllSetTls(aHandle, KDllUid_Default, aPtr);
       
  5294 	}
       
  5295 
       
  5296 EXPORT_C TInt UserSvr::DllSetTls(TInt aHandle, TInt aDllUid, TAny* aPtr)
       
  5297 //
       
  5298 // Set the value of the Thread Local Storage variable.
       
  5299 //
       
  5300 	{
       
  5301 	return LocalThreadData()->DllSetTls(aHandle, aDllUid, aPtr);
       
  5302 	}
       
  5303 
       
  5304 EXPORT_C void UserSvr::DllFreeTls(TInt aHandle)
       
  5305 //
       
  5306 // Remove the Thread Local Storage variable.
       
  5307 //
       
  5308 	{
       
  5309 	return LocalThreadData()->DllFreeTls(aHandle);
       
  5310 	}
       
  5311 
       
  5312 #else
       
  5313 
       
  5314 EXPORT_C TInt UserSvr::DllSetTls(TInt aHandle, TAny* aPtr)
       
  5315 //
       
  5316 // Set the value of the Thread Local Storage variable.
       
  5317 //
       
  5318 	{
       
  5319 	return Exec::DllSetTls(aHandle, KDllUid_Default, aPtr);
       
  5320 	}
       
  5321 
       
  5322 EXPORT_C TInt UserSvr::DllSetTls(TInt aHandle, TInt aDllUid, TAny* aPtr)
       
  5323 //
       
  5324 // Set the value of the Thread Local Storage variable.
       
  5325 //
       
  5326 	{
       
  5327 	return Exec::DllSetTls(aHandle, aDllUid, aPtr);
       
  5328 	}
       
  5329 
       
  5330 EXPORT_C void UserSvr::DllFreeTls(TInt aHandle)
       
  5331 //
       
  5332 // Remove the Thread Local Storage variable.
       
  5333 //
       
  5334 	{
       
  5335 	Exec::DllFreeTls(aHandle);
       
  5336 	}
       
  5337 
       
  5338 #endif
       
  5339 
       
  5340 
       
  5341 
       
  5342 
       
  5343 EXPORT_C TInt RChangeNotifier::Create()
       
  5344 /**
       
  5345 Creates a change notifier, and opens this handle to that change notifier.
       
  5346 
       
  5347 Ownership of this change notifier is vested in the current process.
       
  5348 
       
  5349 @return KErrNone if successful, otherwise one of the other system-wide error codes.
       
  5350 */
       
  5351 	{
       
  5352 	return SetReturnedHandle(Exec::ChangeNotifierCreate(EOwnerProcess),*this);
       
  5353 	}
       
  5354 
       
  5355 
       
  5356 
       
  5357 
       
  5358 EXPORT_C TInt RUndertaker::Create()
       
  5359 /**
       
  5360 Creates a thread-death notifier, and opens this handle to
       
  5361 that thread-death notifier.
       
  5362 
       
  5363 Ownership of this thread-death notifier is vested in the current process.
       
  5364 
       
  5365 @return KErrNone, if successful; otherwise one of
       
  5366         the other system-wide error codes.
       
  5367 */
       
  5368 	{
       
  5369 	return SetReturnedHandle(Exec::UndertakerCreate(EOwnerProcess),*this);
       
  5370 	}
       
  5371 
       
  5372 
       
  5373 
       
  5374 
       
  5375 EXPORT_C TInt RUndertaker::Logon(TRequestStatus& aStatus, TInt& aThreadHandle) const
       
  5376 /**
       
  5377 Issues a request for notification of the death of a thread.
       
  5378 
       
  5379 When another thread dies, the request completes and the TRequestStatus object
       
  5380 contains the value KErrDied; in addition, aThreadHandle contains
       
  5381 the handle-number of the dying thread.
       
  5382 
       
  5383 The requesting thread can construct a proper handle for the dying thread
       
  5384 using the code:
       
  5385 
       
  5386 @code
       
  5387 {
       
  5388 RThread r;
       
  5389 r.SetHandle(aThreadHandle);
       
  5390 ...r.Close();
       
  5391 }
       
  5392 @endcode
       
  5393 
       
  5394 Alternatively, if an outstanding request is cancelled by a call
       
  5395 to LogonCancel(), then the request completes with the value KErrCancel.
       
  5396 
       
  5397 Note that if a request completes normally, i.e. not as a result of
       
  5398 a LogonCancel(), then the handle to the dying thread must be closed
       
  5399 when there is no further interest in it.
       
  5400 
       
  5401 @param aStatus       A reference to the request status object.
       
  5402 @param aThreadHandle The handle-number representing the dying thread.
       
  5403 
       
  5404 @return KErrInUse if there is an outstanding request; KErrNone otherwise.
       
  5405 
       
  5406 @see RUndertaker::LogonCancel()
       
  5407 */
       
  5408 	{
       
  5409 	aStatus=KRequestPending;
       
  5410 	return Exec::UndertakerLogon(iHandle,aStatus,aThreadHandle);
       
  5411 	}
       
  5412 
       
  5413 
       
  5414 
       
  5415 
       
  5416 EXPORT_C TInt RUndertaker::LogonCancel() const
       
  5417 /**
       
  5418 Cancels an outstanding notification request to the thread-death notifier.
       
  5419 
       
  5420 @return KErrGeneral, if there is no outstanding notification request; KErrNone otherwise.
       
  5421 
       
  5422 @see RUndertaker::Logon()
       
  5423 */
       
  5424 	{
       
  5425 	return Exec::UndertakerLogonCancel(iHandle);
       
  5426 	}
       
  5427 
       
  5428 
       
  5429 
       
  5430 
       
  5431 /**
       
  5432 Sets the machine configuration.
       
  5433 
       
  5434 @param aConfig Descriptor containing the machine configuration data
       
  5435 
       
  5436 @return KErrNone, if sucessful, otherwise one of the other system-wide
       
  5437         error codes.
       
  5438 
       
  5439 @capability WriteDeviceData
       
  5440 */
       
  5441 EXPORT_C TInt User::SetMachineConfiguration(const TDesC8& aConfig)
       
  5442     {
       
  5443 	return Exec::SetMachineConfiguration(aConfig);
       
  5444     }
       
  5445 
       
  5446 
       
  5447 
       
  5448 
       
  5449 EXPORT_C TInt User::CompressAllHeaps()
       
  5450 /**
       
  5451 Compresses all the chunks containing heaps.
       
  5452 
       
  5453 @deprecated This function is no longer supported, and calling it has no effect.
       
  5454 
       
  5455 @return KErrNone
       
  5456 */
       
  5457 	{
       
  5458 
       
  5459 	return KErrNone;	// don't do this any more
       
  5460 	}
       
  5461 
       
  5462 
       
  5463 
       
  5464 
       
  5465 EXPORT_C TInt UserSvr::ChangeLocale(const TDesC& aLocaleDllName)
       
  5466 	{
       
  5467 	if(aLocaleDllName.Length() == 0)
       
  5468 		{
       
  5469 		//support reverting to defaults
       
  5470 		TInt r = UserSvr::LocalePropertiesSetDefaults();
       
  5471 		if(r == KErrNone)
       
  5472 			Exec::SetUTCTimeAndOffset(0,0,ETimeSetOffset,EChangesLocale);
       
  5473 		return r;
       
  5474 		}
       
  5475 	TExtendedLocale locale;
       
  5476 	TInt r = locale.LoadLocale(aLocaleDllName);
       
  5477 	if(r == KErrNone)
       
  5478 		{
       
  5479 		r = locale.SaveSystemSettings();
       
  5480 		}
       
  5481 	return r;
       
  5482 	}
       
  5483 
       
  5484 EXPORT_C TInt UserSvr::ResetMachine(TMachineStartupType aType)
       
  5485 //
       
  5486 //	Reset the machine. Currently only aType==EStartupWarmReset is supported.
       
  5487 //
       
  5488 	{
       
  5489 
       
  5490 	return Exec::ResetMachine(aType);
       
  5491 	}
       
  5492