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