Update contrib.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\us_ksvr.cpp
24 //#define __DEBUG_IMAGE__ 1
25 #if defined(__DEBUG_IMAGE__) && defined (__EPOC32__)
26 #define __IF_DEBUG(t) {RDebug::t;}
36 Requests the extended notifier server to start the notifier identified by
39 The request is synchronous; the call returns when the request is complete.
41 The notifier may not be started immediately if a higher priority notifier is
42 already active. In this case, the notifier is queued until it has the highest
43 priority outstanding request for the channel(s) it operates on.
45 @param aNotifierUid The UID identifying the notifier.
46 @param aBuffer Data that can be passed to the notifier; the format and meaning
47 of this depends on the notifier.
49 @return KErrNone, if successful;
50 KErrNotFound, if there is no notifier matching the specified UID;
51 KErrAlreadyExists, if the notifier has already been started, or has
52 an outstanding start request. It may also return with one of the other
53 system-wide error codes, if the notifier cannot be started by
54 the server due to low memory or it leaves from its server side
59 EXPORT_C TInt RNotifier::StartNotifier(TUid aNotifierUid, const TDesC8& aBuffer)
61 return SendReceive(EStartNotifier, TIpcArgs(
62 (TInt)aNotifierUid.iUid,
64 (TAny*)NULL // No resonse required
72 Requests the extended notifier server to start the notifier identified by
75 The request is synchronous; the call returns when the request is complete.
77 The notifier may not start immediately if a higher priority notifier is
78 already active. In this case, the notifier is queued until it has the highest
79 priority outstanding request for the channel(s) it operates on.
80 This can also cause unexpected behaviour: the function can return
81 before the notifier has been started with the added consequence that no response
84 For this reason, this function has been deprecated. Instead, use
85 RNotifier::StartNotifierAndGetResponse(), or if there is no need to wait for a
86 response, use the two argument overload of RNotifier::StartNotifier().
88 @param aNotifierUid The UID identifying the notifier.
89 @param aBuffer Data that can be passed to the notifier; the format and meaning
90 of this depends on the notifier.
91 @param aResponse Response data; the format
92 and meaning of this depends on the notifier.
94 @return KErrNone, if successful;
95 KErrNotFound, if there is no notifier matching the specified UID;
96 KErrAlreadyExists, if the notifier has already been started, or has
97 an outstanding start request. It may also return with one of the other
98 system-wide error codes, if the notifier cannot be started by
99 the server due to low memory or it leaves from its server side
104 @deprecated use RNotifier::StartNotifierAndGetResponse(), or if there is no
105 need to wait for a response, use the two argument overload
106 of RNotifier::StartNotifier()
108 EXPORT_C TInt RNotifier::StartNotifier(TUid aNotifierUid, const TDesC8& aBuffer, TDes8& aResponse)
110 return SendReceive(EStartNotifier, TIpcArgs(
111 (TInt)aNotifierUid.iUid,
118 This function has never been implemented on any Symbian OS version.
119 It always returns KErrNotSupported.
123 EXPORT_C TInt RNotifier::StartNotifier(TUid aNotifierDllUid,TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse)
125 return SendReceive(EStartNotifierFromSpecifiedDll, TIpcArgs(
126 (TInt)aNotifierUid.iUid,
129 (TInt)aNotifierDllUid.iUid
134 Requests the extended notifier server to cancel the notifier identified by
137 The request is synchronous; the call returns when the request is complete.
139 Any notifier that was queued pending the completion of aNotifierUid will be
140 automatically started.
142 @param aNotifierUid The UID identifying the notifier.
144 @return KErrNone, if successful;
145 KErrNotFound, if there is no notifier matching the specified UID.
147 EXPORT_C TInt RNotifier::CancelNotifier(TUid aNotifierUid)
149 return SendReceive(ECancelNotifier, TIpcArgs( (TInt)aNotifierUid.iUid ));
153 Requests the extended notifier server to update the active notifier identified by
156 The request is synchronous; the call returns when the request is complete.
158 @param aNotifierUid The UID identifying the notifier.
159 @param aBuffer Data that can be passed to the notifier; the format and meaning
160 of this depends on the notifier.
161 @param aResponse Reserved for future use.
163 @return KErrNone, if successful;
164 KErrNotFound, if there is no notifier matching the specified UID.
166 EXPORT_C TInt RNotifier::UpdateNotifier(TUid aNotifierUid, const TDesC8& aBuffer,TDes8& aResponse)
168 return SendReceive(EUpdateNotifier, TIpcArgs(
169 (TInt)aNotifierUid.iUid,
176 Requests the extended notifier server to update the active notifier identified by
179 This is an asynchronous request.It may be called multiple times for
180 some notifier implementations; see specific notifier documentation for exact details.
182 @param aRs The request status. On request completion, contains:
183 KErrNone, if successful; otherwise, one of the other system
185 @param aNotifierUid The UID identifying the notifier.
186 @param aBuffer Data that can be passed to the notifier; the format and meaning
187 of this depends on the notifier.
188 @param aResponse Reserved for future use.
191 EXPORT_C void RNotifier::UpdateNotifierAndGetResponse(TRequestStatus& aRs, TUid aNotifierUid, const TDesC8& aBuffer, TDes8& aResponse)
193 SendReceive(EUpdateNotifierAndGetResponse, TIpcArgs(
194 (TInt)aNotifierUid.iUid,
201 Requests the extended notifier server to start the notifier identified by
204 This is an asynchronous request.It may be called multiple times for
205 some notifier implementations; see specific notifier documentation for exact details.
207 @param aRs The request status. On request completion, contains:
208 KErrNone, if successful; otherwise, one of the other system
210 @param aNotifierUid The UID identifying the notifier.
211 @param aBuffer Data that can be passed to the notifier; the format
212 and meaning of this depends on the notifier.
213 @param aResponse Response data; the format
214 and meaning of this depends on the notifier.
216 EXPORT_C void RNotifier::StartNotifierAndGetResponse(TRequestStatus& aRs,TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse)
218 SendReceive(EStartNotifierAndGetResponse, TIpcArgs(
219 (TInt)aNotifierUid.iUid,
232 This function has never been implemented on any Symbian OS version.
233 The request always completes with KErrNotSupported.
235 EXPORT_C void RNotifier::StartNotifierAndGetResponse(TRequestStatus& aRs,TUid aNotifierDllUid,TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse)
237 SendReceive(EStartNotifierFromSpecifiedDllAndGetResponse, TIpcArgs(
238 (TInt)aNotifierUid.iUid,
241 (TInt)aNotifierDllUid.iUid
252 This function has never been implemented on any Symbian OS version.
253 It always returns KErrNotSupported.
255 EXPORT_C TInt RNotifier::UnloadNotifiers(TUid /*aNotifierUid*/)
257 return KErrNotSupported;
267 This function has never been implemented on any Symbian OS version.
268 It always returns KErrNotSupported.
270 EXPORT_C TInt RNotifier::LoadNotifiers(TUid /*aNotifierUid*/)
272 return KErrNotSupported;
281 EXPORT_C RNotifier::RNotifier()
282 : iButtonVal(NULL,0),
283 iCombinedBuffer(NULL)
290 Connects to the extended notifier server, creating a session with that server.
291 Note: Notifier server is started during window server start-up sequence.
293 The function must be called before any other function.
295 @return KErrNone, if successful, otherwise one of the other system-wide error codes
297 EXPORT_C TInt RNotifier::Connect()
299 return CreateSession(__NOTIFIER_NAME,TVersion(KNotifierMajorVersionNumber,KNotifierMinorVersionNumber,KNotifierBuildVersionNumber),-1);
306 Launches a simple two line dialog that displays two lines of text.
308 This is an asynchronous request that completes when the dialog exits.
310 @param aLine1 A descriptor containing the first line of text to be displayed.
311 @param aLine2 A descriptor containing the second line of text to be displayed.
312 @param aBut1 A descriptor containing text to be displayed in the first button.
313 @param aBut2 A descriptor containing text to be displayed in the (optional) second button.
314 @param aButtonVal An integer value which is set when the dialog exits. It is set to:
315 0, if the first button is selected;
316 1, if the second button is selected.
317 @param aStatus The request status object. If the request completes normally, this is set to KErrNone.
319 EXPORT_C void RNotifier::Notify(const TDesC& aLine1,const TDesC& aLine2,const TDesC& aBut1,const TDesC& aBut2, TInt& aButtonVal, TRequestStatus& aStatus)
321 const TInt requiredLengthOfCombinedBuffer=aLine1.Length()+aLine2.Length()+aBut1.Length()+aBut2.Length();
322 if ((iCombinedBuffer!=NULL) && (iCombinedBuffer->Des().MaxLength()<requiredLengthOfCombinedBuffer))
324 delete iCombinedBuffer;
325 iCombinedBuffer=NULL;
327 if (iCombinedBuffer==NULL)
329 iCombinedBuffer=HBufC::New(requiredLengthOfCombinedBuffer);
331 if (iCombinedBuffer==NULL)
333 // report the error back via the TRequestStatus
334 TRequestStatus* status=&aStatus;
335 User::RequestComplete(status,KErrNoMemory);
339 TPtr combinedBufferForNotify(iCombinedBuffer->Des());
340 combinedBufferForNotify = aLine1;
341 combinedBufferForNotify.Append(aLine2);
342 combinedBufferForNotify.Append(aBut1);
343 combinedBufferForNotify.Append(aBut2);
344 iButtonVal.Set(REINTERPRET_CAST(TUint8*,&aButtonVal),sizeof(TInt),sizeof(TInt));
345 __ASSERT_ALWAYS(((aLine1.Length()|aLine2.Length()|aBut1.Length()|aBut2.Length())&~KMaxTUint16)==0,Panic(ENotifierTextTooLong)); // check that all of the descriptor lengths are less than or equal to KMaxTUint16
346 SendReceive(ENotifierNotify,TIpcArgs(&iButtonVal,iCombinedBuffer,(aLine1.Length()<<16)|aLine2.Length(),(aBut1.Length()<<16)|aBut2.Length()),aStatus);
354 Not implemented by the server.
356 EXPORT_C void RNotifier::NotifyCancel()
358 SendReceive(ENotifierNotifyCancel,TIpcArgs()); // ignores any returned error
367 EXPORT_C void RNotifier::Close()
369 delete iCombinedBuffer;
370 iCombinedBuffer=NULL;
371 RSessionBase::Close();
380 EXPORT_C TInt RNotifier::InfoPrint(const TDesC& aDes)
382 return SendReceive(ENotifierInfoPrint, TIpcArgs(&aDes));
387 // Class TChunkCreateInfo
393 This defaults the chunk to be created to be local, to have no attributes set
394 and to use the default clear byte.
396 A local chunk is private to the process creating it and is not
397 intended for access by other user processes.
399 EXPORT_C TChunkCreateInfo::TChunkCreateInfo() :
400 // Specifing individual initialisers for members instead of using memclear
401 // so that Coverity doesn't complain about uninitialised local variables in
402 // calls to e.g., TChunkCreateInfo::SetPaging().
404 iType(TChunkCreate::ENormal),
407 iOwnerType(EOwnerProcess),
411 iAttributes(TChunkCreate::EPagingUnspec),
412 iClearByte(KChunkClearByteDefault)
418 Sets the chunk to be created to have a committed region that always starts at the
419 bottom of the reserved region.
422 @param aSize The number of bytes committed to this chunk.
423 @param aMaxSize The maximum size to which the reserved region of this chunk
425 @see RChunk::CreateLocal()
427 EXPORT_C void TChunkCreateInfo::SetNormal(TInt aInitialSize, TInt aMaxSize)
429 iType = TChunkCreate::ENormal | TChunkCreate::EData;
431 iInitialTop = aInitialSize;
437 Sets the chunk to be created to be user writable and to be marked by the kernel
439 This can only be set on local chunks.
441 @param aInitialSize The number of bytes committed to this chunk.
442 @param aMaxSize The maximum size to which the reserved region of this chunk
444 @see RChunk::CreateLocalCode()
446 EXPORT_C void TChunkCreateInfo::SetCode(TInt aInitialSize, TInt aMaxSize)
448 iType = TChunkCreate::ENormal | TChunkCreate::ECode;
450 iInitialTop = aInitialSize;
456 Sets the chunk to be created to have a commited region that that can be any
457 contiguous subset of the reserved region.
459 @param aInitialBottom The offset of the bottom of the new committed region
460 from the base of the chunk's reserved region.
461 @param aInitialTop The offset of the top of the new committed region from
462 the base of the chunk's reserved region.
463 @param aMaxSize The maximum size to which the reserved region of
465 @see RChunk::CreateDoubleEndedLocal()
467 EXPORT_C void TChunkCreateInfo::SetDoubleEnded(TInt aInitialBottom, TInt aInitialTop, TInt aMaxSize)
469 iType = TChunkCreate::EDoubleEnded | TChunkCreate::EData;
470 iInitialBottom = aInitialBottom;
471 iInitialTop = aInitialTop;
476 Set the chunk to be created to have a committed region consisting of an
477 arbitrary set of MMU pages within the reserved region.
479 @param aInitialBottom The offset of the bottom of the new committed region
480 from the base of the chunk's reserved region.
481 @param aInitialTop The offset of the top of the new committed region
482 from the base of the chunk's reserved region.
483 @param aMaxSize The maximum size to which the reserved region of
485 @see RChunk::CreateDisconnectedLocal()
487 EXPORT_C void TChunkCreateInfo::SetDisconnected(TInt aInitialBottom, TInt aInitialTop, TInt aMaxSize)
489 iType = TChunkCreate::EDisconnected | TChunkCreate::EData;
490 iInitialBottom = aInitialBottom;
491 iInitialTop = aInitialTop;
497 Sets the chunk to be created to be a thread heap chunk.
498 For internal use only.
500 @param aInitialSize The number of bytes committed to this chunk.
501 @param aMaxSize The maximum size to which the reserved region of this chunk
503 @param aName The name to be given to the chunk to be created
506 void TChunkCreateInfo::SetThreadHeap(TInt aInitialSize, TInt aMaxSize, const TDesC& aName)
508 iType = TChunkCreate::ENormal | TChunkCreate::EData;
510 iInitialTop = aInitialSize;
512 iAttributes |= TChunkCreate::ELocalNamed;
514 iOwnerType = EOwnerThread;
518 Sets the owner of the chunk to be created.
519 @param aType The owner of the chunk to be created.
521 EXPORT_C void TChunkCreateInfo::SetOwner(TOwnerType aType)
527 Sets the chunk to be created to be global, i.e. it is potentially visible
528 to all processes and is intended for access by other user processes.
530 @param aName A reference to a descriptor containing the name to be
531 assigned to the global chunk. The length of
532 the descriptor must be no greater than that allowed for
535 EXPORT_C void TChunkCreateInfo::SetGlobal(const TDesC& aName)
542 Sets the byte value that all memory committed to the chunk will be cleared to.
543 @param TUint8 aClearByte.
545 EXPORT_C void TChunkCreateInfo::SetClearByte(TUint8 aClearByte)
547 iClearByte = aClearByte;
552 Sets the data paging attributes for the chunk to be created. Any previous calls
553 to this method will be overridden for this TChunkCreateInfo object.
555 @param aPaging The data paging attributes of the chunk to be created.
559 EXPORT_C void TChunkCreateInfo::SetPaging(const TChunkPagingAtt aPaging)
561 __ASSERT_COMPILE(TChunkCreate::EPagingUnspec == 0);
562 iAttributes &= ~TChunkCreate::EPagingMask;
563 if (aPaging == EPaged)
564 iAttributes |= TChunkCreate::EPaged;
565 if (aPaging == EUnpaged)
566 iAttributes |= TChunkCreate::EUnpaged;
570 Sets the global chunk to be created to be read only. Only the creating process
571 will be able to write to it, not other processes.
573 Read-Only chunks are currently only available on the Flexible Memory Model.
575 Chunk must be global.
577 EXPORT_C void TChunkCreateInfo::SetReadOnly()
579 iAttributes |= TChunkCreate::EReadOnly;
583 EXPORT_C void TChunkCreateInfo::SetCache(TInt aMaxSize)
585 iType = TChunkCreate::ECache | TChunkCreate::EData;
597 EXPORT_C TInt RChunk::CreateLocal(TInt aSize,TInt aMaxSize,TOwnerType aType)
599 Creates a local chunk.
601 The chunk is local to the process creating it; i.e. it is private to the process
602 creating it and is not intended for access by other user processes.
604 aMaxSize specifies the maximum size of the chunk and aSize specifies the number
605 of bytes to be committed on creation of the chunk. Both values are rounded
606 up to the next nearest processor page boundary value if they are not already
607 on a processor page boundary.
609 The committed region always starts at the bottom of the reserved region.
611 By default, ownership of this chunk handle is vested in the current process.
612 Ownership of the chunk handle can be vested in the current thread by passing
613 EOwnerThread as the third parameter to this function.
615 @param aSize The number of bytes committed to this chunk.
616 @param aMaxSize The maximum size to which the reserved region of this chunk
618 @param aType An enumeration whose enumerators define the ownership of this
619 chunk handle. If not explicitly specified, EOwnerProcess is
622 @return KErrNone if successful, otherwise another of the system-wide error
625 @panic USER 99 if aMaxSize is negative.
626 @panic USER 100 if aSize is negative.
627 @panic USER 101 if aSize is greater than or equal to the supplied
631 TChunkCreateInfo createInfo;
632 createInfo.SetNormal(aSize, aMaxSize);
633 createInfo.SetOwner(aType);
634 return Create(createInfo);
640 EXPORT_C TInt RChunk::CreateLocalCode(TInt aSize,TInt aMaxSize,TOwnerType aType)
642 Creates a user writable chunk that is marked by the kernel as containing code.
644 The chunk is local to the process creating it, i.e. it is private to the process
645 creating it and is not intended for access by other user processes.
647 On systems using a Harvard cache, this type of chunk removes the need to flush
648 the instruction cache (I-Cache) on a context switch. However, the instruction
649 Translation Look-aside Buffer (ITLB) still needs to be flushed when switching
650 to or from a process with one of these chunks in its address space. Systems with
651 a dynamic branch predictor may also need to flush their branch target buffer when
652 switching from one process using this type of chunk to another.
654 @param aSize The number of bytes committed to this chunk.
655 @param aMaxSize The maximum size to which the reserved region of this chunk
657 @param aType An enumeration whose enumerators define the ownership of this
658 chunk handle. If not explicitly specified, EOwnerProcess is
661 @return KErrNone if successful, otherwise another of the system-wide error
664 @panic USER 99 if aMaxSize is negative.
665 @panic USER 100 if aSize is negative.
666 @panic USER 101 if aSize is greater than or equal to the supplied
669 @see UserHeap::ChunkHeap
673 TChunkCreateInfo createInfo;
674 createInfo.SetCode(aSize, aMaxSize);
675 createInfo.SetOwner(aType);
676 return Create(createInfo);
682 EXPORT_C TInt RChunk::CreateGlobal(const TDesC &aName,TInt aSize,TInt aMaxSize,TOwnerType aType)
684 Creates a global chunk.
686 The chunk is global; i.e. it is potentially visible to all processes and is
687 intended for access by other user processes.
689 aMaxSize specifies the maximum size of the chunk and aSize specifies the number
690 of bytes to be committed on creation of the chunk. Both values are rounded
691 up to the next nearest processor page boundary value ,if they are not already
692 on a processor page boundary value.
694 The committed region always starts at the bottom of the reserved region.
696 The descriptor aName contains the name to be assigned to this global chunk. If
697 this name is empty, the chunk will be anonymous. Anonymous chunks cannot be
698 accessed by other processes unless the creator explicitly passes them a handle
699 to the chunk - this can be used to transfer large amounts of data between
700 processes in a secure fashion.
702 By default, ownership of this chunk handle is vested in the current process.
703 Ownership of the chunk handle can be vested in the current thread by passing
704 EOwnerThread as the third parameter to this function.
706 @param aName A reference to a descriptor containing the name to be assigned
707 to this global chunk. The length of the descriptor must be no
708 greater than that allowed for a TKName type.
709 @param aSize The number of bytes committed to this chunk.
710 @param aMaxSize The maximum size to which the reserved region of this chunk
712 @param aType An enumeration whose enumerators define the ownership of this
713 chunk handle. If not explicitly specified, EOwnerProcess is taken
716 @return KErrNone if successful, otherwise another of the system error codes.
718 @panic USER 99 if aMaxSize is negative.
719 @panic USER 100 if aSize is negative.
720 @panic USER 101 if aSize is greater than or equal to the supplied
724 TChunkCreateInfo createInfo;
725 createInfo.SetNormal(aSize, aMaxSize);
726 createInfo.SetGlobal(aName);
727 createInfo.SetOwner(aType);
728 return Create(createInfo);
734 EXPORT_C TInt RChunk::CreateDoubleEndedLocal(TInt aInitialBottom, TInt aInitialTop,TInt aMaxSize,TOwnerType aType)
736 Creates a local, double ended, chunk.
738 The chunk is local to the process creating it; i.e. it is private to
739 the process creating it and is not intended for access by other
742 The committed region of a double ended chunk can be any contiguous subset
743 of the reserved region.
745 aMaxSize specifies the maximum size of the chunk.
747 The difference between aInitialTop and aInitialBottom gives the number of
748 bytes to be committed, on creation of the chunk; aInitialBottom gives the
749 offset of the bottom of the committed region from the base of the chunk's
750 reserved region; aInitialTop gives the offset of the top of the committed
751 region from the base of the chunk's reserved region.
753 Both aInitialBottom and aInitialTop are rounded up to the next nearest
754 processor page boundary value, if they are not already on
755 a processor page boundary value.
757 By default, ownership of this chunk handle is vested in the current process.
758 Ownership of the chunk handle can be vested in the current thread by passing
759 EOwnerThread as the third parameter to this function.
763 1. the lowest valid address in a double ended chunk is the sum of the base of
764 the chunk's reserved region plus the adjusted value of aInitialBottom
766 2. the highest valid address in a double ended chunk is the the sum of the base
767 of the chunk's reserved region plus the adjusted value of aInitialTop - 1.
769 @param aInitialBottom The offset of the bottom of the new committed region
770 from the base of the chunk's reserved region.
771 @param aInitialTop The offset of the top of the new committed region from
772 the base of the chunk's reserved region.
773 @param aMaxSize The maximum size to which the reserved region of
775 @param aType An enumeration whose enumerators define the ownership of
776 this chunk handle. If not explicitly specified,
777 EOwnerProcess is taken as default.
779 @return KErrNone if successful, otherwise another of the system error codes.
781 @panic USER 99 if aMaxSize is negative.
782 @panic USER 120 if aInitialBottom is negative.
783 @panic USER 121 if aInitialTop is negative.
784 @panic USER 122 if aInitialBottom is greater than the supplied value
786 @panic USER 123 if aInitialTop is greater than the supplied value of aMaxSize.
789 TChunkCreateInfo createInfo;
790 createInfo.SetDoubleEnded(aInitialBottom, aInitialTop, aMaxSize);
791 createInfo.SetOwner(aType);
792 return Create(createInfo);
798 EXPORT_C TInt RChunk::CreateDoubleEndedGlobal(const TDesC &aName,TInt aInitialBottom,TInt aInitialTop,TInt aMaxSize,TOwnerType aType)
800 Creates a global, double ended, chunk.
802 The chunk is global; i.e. it is visible to all processes and is intended
803 for access by other user processes.
805 The committed region of a double ended chunk can be any contiguous subset
806 of the reserved region.
808 aMaxSize specifies the maximum size of the chunk.
810 The difference between aInitialTop and aInitialBottom gives the number of
811 bytes to be committed, on creation of the chunk; aInitialBottom gives the
812 offset of the bottom of the committed region from the base of the chunk's
813 reserved region; aInitialTop gives the offset of the top of the committed
814 region from the base of the chunk's reserved region.
816 Both aInitialBottom and aInitialTop are rounded up to the next nearest
817 processor page boundary value, if they are not already on a processor page
820 The descriptor aName contains the name to be assigned to this global chunk.
822 By default, ownership of this chunk handle is vested in the current process.
823 Ownership of the chunk handle can be vested in the current thread by passing
824 EOwnerThread as the third parameter to this function.
828 1. the lowest valid address in a double ended chunk is the sum of the base of
829 the chunk's reserved region plus the adjusted value of aInitialBottom
831 2. the highest valid address in a double ended chunk is the the sum of the base
832 of the chunk's reserved region plus the adjusted value of aInitialTop - 1.
834 @param aName A reference to a descriptor containing the name to be
835 assigned to this global chunk. The length of
836 the descriptor must be no greater than that allowed for
838 @param aInitialBottom The offset of the bottom of the new committed region
839 from the base of the chunk's reserved region.
840 @param aInitialTop The offset of the top of the new committed region from
841 the base of the chunk's reserved region.
842 @param aMaxSize The maximum size to which the reserved region of
844 @param aType An enumeration whose enumerators define the ownership of
845 this chunk handle. If not explicitly specified,
846 EOwnerProcess is taken as default.
848 @return KErrNone if successful, otherwise another of the system error codes.
850 @panic USER 99 if aMaxSize is negative.
851 @panic USER 120 if aInitialBottom is negative.
852 @panic USER 121 if aInitialTop is negative.
853 @panic USER 122 if aInitialBottom is greater than the supplied value
855 @panic USER 123 if aInitialTop is greater than the supplied value of aMaxSize.
856 @panic USER 163 if aName is empty.
859 TChunkCreateInfo createInfo;
860 createInfo.SetDoubleEnded(aInitialBottom, aInitialTop, aMaxSize);
861 createInfo.SetGlobal(aName);
862 createInfo.SetOwner(aType);
863 return Create(createInfo);
869 EXPORT_C TInt RChunk::CreateDisconnectedLocal(TInt aInitialBottom, TInt aInitialTop,TInt aMaxSize,TOwnerType aType)
871 Creates a local, disconnected chunk.
873 The chunk is local to the process creating it; i.e. it is private to
874 the process creating it and is not intended for access by other
877 A disconnected chunk has a committed region consisting of an arbitrary set
878 of MMU pages within the reserved region, i.e. each page-sized address range
879 within the reserved region which begins on a page boundary may be committed
882 aMaxSize specifies the maximum size of the chunk.
884 The difference between aInitialTop and aInitialBottom gives the number of
885 bytes to be committed, on creation of the chunk; aInitialBottom gives the
886 offset of the bottom of the committed region from the base of the chunk's
887 reserved region; aInitialTop gives the offset of the top of the committed
888 region from the base of the chunk's reserved region.
890 Both aInitialBottom and aInitialTop are rounded up to the next nearest
891 processor page boundary value, if they are not already on
892 a processor page boundary value.
894 By default, ownership of this chunk handle is vested in the current process.
895 Ownership of the chunk handle can be vested in the current thread by passing
896 EOwnerThread as the third parameter to this function.
898 @param aInitialBottom The offset of the bottom of the new committed region
899 from the base of the chunk's reserved region.
900 @param aInitialTop The offset of the top of the new committed region from
901 the base of the chunk's reserved region.
902 @param aMaxSize The maximum size to which the reserved region of
904 @param aType An enumeration whose enumerators define the ownership of
905 this chunk handle. If not explicitly specified,
906 EOwnerProcess is taken as default.
908 @return KErrNone if successful, otherwise another of the system error codes.
910 @panic USER 99 if aMaxSize is negative.
911 @panic USER 120 if aInitialBottom is negative.
912 @panic USER 121 if aInitialTop is negative.
913 @panic USER 122 if aInitialBottom is greater than the supplied value
915 @panic USER 123 if aInitialTop is greater than the supplied value of aMaxSize.
918 TChunkCreateInfo createInfo;
919 createInfo.SetDisconnected(aInitialBottom, aInitialTop, aMaxSize);
920 createInfo.SetOwner(aType);
921 return Create(createInfo);
927 EXPORT_C TInt RChunk::CreateDisconnectedGlobal(const TDesC &aName,TInt aInitialBottom,TInt aInitialTop,TInt aMaxSize,TOwnerType aType)
929 Creates a global, disconnected, chunk.
931 The chunk is global; i.e. it is visible to all processes and is intended
932 for access by other user processes.
934 A disconnected chunk has a committed region consisting of an arbitrary set
935 of MMU pages within the reserved region, i.e. each page-sized address range
936 within the reserved region which begins on a page boundary may be committed
939 aMaxSize specifies the maximum size of the chunk.
941 The difference between aInitialTop and aInitialBottom gives the number of
942 bytes to be committed, on creation of the chunk; aInitialBottom gives the
943 offset of the bottom of the committed region from the base of the chunk's
944 reserved region; aInitialTop gives the offset of the top of the committed
945 region from the base of the chunk's reserved region.
947 Both aInitialBottom and aInitialTop are rounded up to the next nearest
948 processor page boundary value, if they are not already on a processor page
951 The descriptor aName contains the name to be assigned to this global chunk.
953 By default, ownership of this chunk handle is vested in the current process.
954 Ownership of the chunk handle can be vested in the current thread by passing
955 EOwnerThread as the third parameter to this function.
957 @param aName A reference to a descriptor containing the name to be
958 assigned to this global chunk. The length of
959 the descriptor must be no greater than that allowed for
961 @param aInitialBottom The offset of the bottom of the new committed region
962 from the base of the chunk's reserved region.
963 @param aInitialTop The offset of the top of the new committed region from
964 the base of the chunk's reserved region.
965 @param aMaxSize The maximum size to which the reserved region of
967 @param aType An enumeration whose enumerators define the ownership of
968 this chunk handle. If not explicitly specified,
969 EOwnerProcess is taken as default.
971 @return KErrNone if successful, otherwise another of the system error codes.
973 @panic USER 99 if aMaxSize is negative.
974 @panic USER 120 if aInitialBottom is negative.
975 @panic USER 121 if aInitialTop is negative.
976 @panic USER 122 if aInitialBottom is greater than the supplied value
978 @panic USER 123 if aInitialTop is greater than the supplied value of aMaxSize.
981 TChunkCreateInfo createInfo;
982 createInfo.SetDisconnected(aInitialBottom, aInitialTop, aMaxSize);
983 createInfo.SetGlobal(aName);
984 createInfo.SetOwner(aType);
985 return Create(createInfo);
990 Creates a chunk of the type specified by the parameter aCreateInfo.
992 @param aCreate A reference to a TChunkCreateInfo object specifying the type of
995 @return KErrNone on success, otherwise on of the system wide error codes.
997 @panic USER 99 if the specified maximum size is negative.
998 @panic USER 120 if any specified initial bottom is negative.
999 @panic USER 121 if any specified initial top is negative.
1000 @panic USER 122 if any specified initial bottom is greater than the supplied value
1002 @panic USER 123 if any specified initial top is greater than the supplied value for the maximum size.
1003 @panic USER 214 if any of the specified attributes is invalid.
1004 @panic USER 215 if the version number of aCreateInfo is invalid.
1006 EXPORT_C TInt RChunk::Create(TChunkCreateInfo& aCreateInfo)
1008 // Verify the version number of TChunkCreateInfo is supported
1009 __ASSERT_ALWAYS(aCreateInfo.iVersionNumber < TChunkCreateInfo::ESupportedVersions,
1010 Panic(EChkCreateInvalidVersion));
1012 TUint mapping = aCreateInfo.iType & ~TChunkCreate::ECode;
1013 TBool shouldBeNamed = aCreateInfo.iGlobal ||
1014 (aCreateInfo.iAttributes & TChunkCreate::ELocalNamed);
1015 __ASSERT_ALWAYS(mapping <= (TUint)TChunkCreate::ECache, Panic(EChkCreateInvalidType));
1016 __ASSERT_ALWAYS(!(aCreateInfo.iType & TChunkCreate::ECode) || !aCreateInfo.iGlobal,
1017 Panic(EChkCreateInvalidType));
1018 __ASSERT_ALWAYS((!shouldBeNamed && aCreateInfo.iName == NULL) ||
1019 (shouldBeNamed && aCreateInfo.iName),
1020 Panic(EChkCreateInvalidName));
1021 __ASSERT_ALWAYS(aCreateInfo.iMaxSize >= 0, Panic(EChkCreateMaxSizeNegative));
1022 __ASSERT_ALWAYS(!(aCreateInfo.iAttributes & ~TChunkCreate::EChunkCreateAttMask), Panic(EChkCreateInvalidAttribute));
1023 if(mapping == TChunkCreate::ENormal)
1025 // 'normal' chunks have different semantics for the meanings of
1026 // aInitialBottom and aInitialTop
1027 __ASSERT_ALWAYS(!aCreateInfo.iInitialBottom, Panic(EChkCreateInvalidBottom));
1028 __ASSERT_ALWAYS(aCreateInfo.iInitialTop >= 0, Panic(EChkCreateSizeNotPositive));
1029 __ASSERT_ALWAYS(aCreateInfo.iInitialTop <= aCreateInfo.iMaxSize, Panic(EChkCreateMaxLessThanMin));
1033 __ASSERT_ALWAYS(aCreateInfo.iInitialBottom >= 0, Panic(EChkCreateBottomNegative));
1034 __ASSERT_ALWAYS(aCreateInfo.iInitialTop >= 0, Panic(EChkCreateTopNegative));
1035 __ASSERT_ALWAYS(aCreateInfo.iInitialTop >= aCreateInfo.iInitialBottom, Panic(EChkCreateTopLessThanBottom));
1036 __ASSERT_ALWAYS(aCreateInfo.iInitialTop <= aCreateInfo.iMaxSize, Panic(EChkCreateTopBiggerThanMax));
1040 info.iAtt = aCreateInfo.iAttributes | (TUint)aCreateInfo.iType;
1041 info.iAtt |= (aCreateInfo.iGlobal)? TChunkCreate::EGlobal : TChunkCreate::ELocal; // Add the global attribute
1042 info.iForceFixed = EFalse;
1043 info.iInitialBottom = aCreateInfo.iInitialBottom;
1044 info.iInitialTop = aCreateInfo.iInitialTop;
1045 info.iMaxSize = aCreateInfo.iMaxSize;
1046 info.iClearByte = aCreateInfo.iClearByte;
1048 TDesC8* ptrName = NULL;
1049 TBuf8<KMaxKernelName> name8;
1050 if(aCreateInfo.iName)
1052 TInt r = User::ValidateName(*aCreateInfo.iName);
1055 name8.Copy(*aCreateInfo.iName);
1059 return SetReturnedHandle(Exec::ChunkCreate(aCreateInfo.iOwnerType, ptrName, info),*this);
1063 EXPORT_C TInt RChunk::OpenGlobal(const TDesC &aName,TBool isReadOnly,TOwnerType aType)
1065 Opens a handle to a specific named global chunk.
1067 Full read/write access can be allowed or access can be limited to read only.
1069 By default, ownership of this process handle is vested in the current process,
1070 but can be vested in the current thread by passing EOwnerThread as the second
1071 parameter to this function.
1073 @param aName A reference to the descriptor containing the name of
1074 the chunk to be opened.
1075 @param isReadOnly This is currently not implemented and setting it to ETrue
1076 will have no effect.
1077 (Intended implementation will be as below:
1078 Defines the type of access to the chunk: Specify ETrue if
1079 access is limited to read only, otherwise specify EFalse
1080 for full read/write access.)
1081 @param aType An enumeration whose enumerators define ownership of
1082 this chunk handle. If not explicitly specified,
1083 EOwnerProcess is taken as default.
1085 @return KErrNone if successful, otherwise another of the system error codes.
1088 (void) isReadOnly; // This is not currently used
1089 return OpenByName(aName,aType,EChunk);
1096 Opens a handle to a chunk using a handle number sent by a client
1099 This function is called by the server.
1101 @param aMessage The message pointer.
1102 @param aParam An index specifying which of the four message arguments
1103 contains the handle number.
1104 @param isReadOnly This is currently not implemented and setting it to ETrue
1105 will have no effect.
1106 (Intended implementation will be as below:
1107 Defines the type of access to the chunk: Specify ETrue if
1108 access is limited to read only, otherwise specify EFalse
1109 for full read/write access.)
1110 @param aType An enumeration whose enumerators define the ownership of this
1111 chunk handle. If not explicitly specified, EOwnerProcess is
1114 @return KErrNone, if successful;
1115 KErrArgument, if the value of aParam is outside the range 0-3;
1116 KErrBadHandle, if not a valid handle;
1117 otherwise one of the other system-wide error codes.
1119 EXPORT_C TInt RChunk::Open(RMessagePtr2 aMessage,TInt aParam,TBool isReadOnly,TOwnerType aType)
1121 (void) isReadOnly; // This is not currently used
1122 return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),EChunk,aParam,aType));
1129 Opens a handle to a chunk using a handle number passed as an
1130 environment data item to the child process during the creation of
1133 Note that this function can only be called successfully once.
1135 @param aArgumentIndex An index that identifies the slot in the process
1136 environment data that contains the handle number. This is
1137 a value relative to zero, i.e. 0 is the first item/slot.
1138 This can range from 0 to 15.
1140 @param aOwnerType An enumeration whose enumerators define the ownership of
1141 this chunk handle. If not explicitly specified,
1142 EOwnerProcess is taken as default.
1144 @return KErrNone, if successful;
1145 KErrNotFound, if the slot indicated by aArgumentIndex is empty;
1146 KErrArgument, if the slot does not contain a Semaphore handle;
1147 otherwise one of the other system-wide error codes.
1149 @see RProcess::SetParameter()
1151 EXPORT_C TInt RChunk::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
1153 return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, EChunk, aOwnerType));
1160 EXPORT_C TInt RChunk::SetRestrictions(TUint aFlags)
1162 Sets or removes restrictions on the ability of the chunk to change.
1164 For example, to adjust, commit etc
1166 @param aFlags One of the values defined by TRestrictions.
1168 @return KErrNone if successful, otherwise another of the system error codes.
1170 @see RChunk::TRestrictions()
1173 return Exec::ChunkSetRestrictions(iHandle,aFlags);
1179 EXPORT_C TInt RChunk::Adjust(TInt aNewSize) const
1181 Changes the number of bytes committed to the chunk.
1183 This value is always rounded up to the next nearest processor page boundary.
1185 @param aNewSize The number of bytes to be committed to this chunk.
1187 @return KErrNone if successful, otherwise another of the system error codes.
1189 @panic USER 102 if aNewSize is negative.
1193 __ASSERT_ALWAYS(aNewSize>=0,Panic(EChkAdjustNewSizeNegative));
1194 return Exec::ChunkAdjust(iHandle,EChunkAdjust,aNewSize,0);
1200 EXPORT_C TInt RChunk::AdjustDoubleEnded(TInt aBottom, TInt aTop) const
1202 Changes the number of bytes and the position of this double ended
1203 chunk's committed region.
1205 The difference between aTop and aBottom gives the new size of the committed
1206 region; aBottom gives the offset of the bottom of the committed region from
1207 the base of the chunk's reserved region.
1209 Both aBottom and aTop are rounded up to the next nearest processor
1212 The function fails if this chunk is not a double ended chunk; for a standard
1213 chunk, use the Adjust() function.
1215 Note that if the initial and final committed regions intersect, the contents
1216 of the intersection are unchanged. Other parts of the committed region have
1221 1. the lowest valid address in a double ended chunk is the sum of the base of
1222 the chunk's reserved region plus the adjusted value of aBottom
1224 2. the highest valid address in a double ended chunk is the the sum of the base
1225 of the chunk's reserved region plus the adjusted value of aTop - 1.
1227 @param aBottom The offset from the base of the chunk of the bottom of the
1229 @param aTop The offset from the base of the chunk of the top of the committed
1232 @return KErrNone if successful, otherwise another of the system error codes.
1234 @panic USER 124 if aBottom is negative.
1235 @panic USER 125 if aTop is negative.
1236 @panic USER 126 if aBottom is greater than the supplied value of aTop.
1239 __ASSERT_ALWAYS(aBottom>=0,Panic(EChkAdjustBottomNegative));
1240 __ASSERT_ALWAYS(aTop>=0,Panic(EChkAdjustTopNegative));
1241 __ASSERT_ALWAYS(aTop>=aBottom,Panic(EChkAdjustTopLessThanBottom));
1242 return Exec::ChunkAdjust(iHandle,EChunkAdjustDoubleEnded,aBottom,aTop);
1248 EXPORT_C TInt RChunk::Commit(TInt aOffset, TInt aSize) const
1250 Commits memory to a disconnected chunk.
1252 Memory is committed in blocks of the MMU page size.
1253 E.g. Commit(pageSize-1,2) which asks for the last byte of the first page
1254 and the first byte of the second page and will result in the first 2 pages
1255 in the chunk being committed.
1256 For this reason it is best to only use values for aOffset and aSize which
1257 are multiples of the MMU page size. This size can be obtained with the
1261 HAL::Get(HAL::EMemoryPageSize,pageSize)
1264 @param aOffset The offset of the committed region from the base of the chunk's
1266 @param aSize The size of the committed region.
1268 @return KErrNone if successful, otherwise another of the system error codes.
1270 @panic USER 157 if anOffset is negative.
1271 @panic USER 158 if aSize is negative.
1274 __ASSERT_ALWAYS(aOffset>=0,Panic(EChkCommitOffsetNegative));
1275 __ASSERT_ALWAYS(aSize>=0,Panic(EChkCommitSizeNegative));
1276 return Exec::ChunkAdjust(iHandle,EChunkCommit,aOffset,aSize);
1282 EXPORT_C TInt RChunk::Allocate(TInt aSize) const
1284 Allocates and commits to a disconnected chunk.
1286 @param aSize The size of the committed region.
1288 @panic USER 159 if aSize is negative.
1291 __ASSERT_ALWAYS(aSize>=0,Panic(EChkAllocateSizeNegative));
1292 return Exec::ChunkAdjust(iHandle,EChunkAllocate,aSize,0);
1298 EXPORT_C TInt RChunk::Decommit(TInt aOffset, TInt aSize) const
1300 Decommits memory from a disconnected chunk.
1302 Memory is decommitted in blocks of the MMU page size.
1303 E.g. Decommit(pageSize-1,2) which asks for the last byte of the first page
1304 and the first byte of the second page and will result in the first 2 pages
1305 in the chunk being decommitted.
1306 For this reason it is best to only use values for aOffset and aSize which
1307 are multiples of the MMU page size. This size can be obtained with the
1311 HAL::Get(HAL::EMemoryPageSize,pageSize)
1314 @param aOffset The offset of the committed region from the base of the chunk's
1316 @param aSize The size of the committed region.
1318 @return KErrNone if successful, otherwise another of the system error codes.
1320 @panic USER 160 if anOffset is negative.
1321 @panic USER 161 if aSize is negative.
1324 __ASSERT_ALWAYS(aOffset>=0,Panic(EChkDecommitOffsetNegative));
1325 __ASSERT_ALWAYS(aSize>=0,Panic(EChkDecommitSizeNegative));
1326 return Exec::ChunkAdjust(iHandle,EChunkDecommit,aOffset,aSize);
1330 /* THIS IS A DELIBERATE NON DOXGEN STYLE TAG TO EXCLUDE THIS DOC FROM AUTO GENERATED DOCS
1332 Unlocks previously committed memory in a disconnected chunk.
1334 Unlocked memory is an intermediate state between committed and decommitted.
1335 Whilst in this state, the memory must not be accessed in any way, and the
1336 system is free to reclaim this RAM for other purposes, (it counts as free
1337 system memory). A program may attempt to relock the memory with #Lock which,
1338 when it succeeds, returns it to the committed state with its contents unchanged.
1340 This is intended for use in the implementation of memory caches for data
1341 which can be regenerated from other sources. I.e. in situations when the
1342 loss of cache contents is not a fatal condition.
1344 #Unlock may be used on memory which is already unlocked, in which case the memory
1345 state is left unaltered. Attempting to unlock memory which is decommitted results
1348 Unlocked memory may decommitted with #Decommit.
1350 Memory is unlocked in blocks of the MMU page size.
1351 E.g. Unlock(pageSize-1,2) which asks for the last byte of the first page
1352 and the first byte of the second page and will result in the first 2 pages
1353 in the chunk being unlocked.
1354 For this reason it is best to only use values for aOffset and aSize which
1355 are multiples of the MMU page size. This size can be obtained with the
1359 HAL::Get(HAL::EMemoryPageSize,pageSize)
1362 @param aOffset The offset of the committed region from the base of the chunk's
1364 @param aSize The size of the committed region.
1366 @return KErrNone if successful, otherwise another of the system error codes.
1368 @panic USER 160 if anOffset is negative.
1369 @panic USER 161 if aSize is negative.
1375 EXPORT_C TInt RChunk::Unlock(TInt aOffset, TInt aSize)
1377 __ASSERT_ALWAYS(aOffset>=0,Panic(EChkDecommitOffsetNegative));
1378 __ASSERT_ALWAYS(aSize>=0,Panic(EChkDecommitSizeNegative));
1379 return Exec::ChunkAdjust(iHandle,EChunkUnlock,aOffset,aSize);
1382 /* THIS IS A DELIBERATE NON DOXGEN STYLE TAG TO EXCLUDE THIS DOC FROM AUTO GENERATED DOCS
1384 Locks memory in a disconnected chunk.
1386 This attempts to reverse the action of #Unlock and return memory to the committed
1387 state. If any RAM in the region had been previously reclaimed by the system,
1388 then this function fails with KErrNotFound and the whole region is decommited.
1390 #Lock may be used on memory which is already committed, in which case the memory
1391 state is left unaltered. Attempting to lock memory which is decommitted results in an
1394 Memory is locked in blocks of the MMU page size.
1395 E.g. Lock(pageSize-1,2) which asks for the last byte of the first page
1396 and the first byte of the second page and will result in the first 2 pages
1397 in the chunk being locked.
1398 For this reason it is best to only use values for aOffset and aSize which
1399 are multiples of the MMU page size. This size can be obtained with the
1403 HAL::Get(HAL::EMemoryPageSize,pageSize)
1406 @param aOffset The offset of the unlocked region from the base of the chunk's
1408 @param aSize The size of the unlocked region.
1410 @return KErrNone if successful, otherwise another of the system error codes.
1412 @panic USER 160 if anOffset is negative.
1413 @panic USER 161 if aSize is negative.
1419 EXPORT_C TInt RChunk::Lock(TInt aOffset, TInt aSize)
1421 __ASSERT_ALWAYS(aOffset>=0,Panic(EChkDecommitOffsetNegative));
1422 __ASSERT_ALWAYS(aSize>=0,Panic(EChkDecommitSizeNegative));
1423 return Exec::ChunkAdjust(iHandle,EChunkLock,aOffset,aSize);
1428 This can be used to determine whether the data for the chunk is demand paged
1431 @return ETrue if the data for the chunk is demand paged, EFalse otherwise.
1433 EXPORT_C TBool RChunk::IsPaged() const
1435 return Exec::ChunkIsPaged(iHandle);
1440 Opens a handle to an LDD factory object by name.
1442 @param aName The name of the LDD factory object to be opened.
1443 @param aType An enumeration whose enumerators define the ownership of this
1444 LDD factory object handle.
1446 @return KErrNone, if successful; otherwise one of the other system wide error codes.
1448 EXPORT_C TInt RDevice::Open(const TDesC &aName,TOwnerType aType)
1450 return OpenByName(aName,aType,ELogicalDevice);
1453 EXPORT_C TInt RBusLogicalChannel::DoCreate(const TDesC& aLogicalDevice, const TVersion& aVer, TInt aUnit, const TDesC* aPhysicalDevice, const TDesC8* anInfo, TInt aType)
1455 // Call the kernel to create a channel on a device.
1458 TInt r = User::ValidateName(aLogicalDevice);
1461 TBuf8<KMaxKernelName> name8;
1462 name8.Copy(aLogicalDevice);
1464 TBuf8<KMaxKernelName> physicalDeviceName;
1465 TChannelCreateInfo8 info;
1470 physicalDeviceName.Copy(*aPhysicalDevice);
1471 info.iPhysicalDevice = &physicalDeviceName;
1474 info.iPhysicalDevice = NULL;
1477 return SetReturnedHandle(Exec::ChannelCreate(name8, info, aType),*this);
1484 Opens a handle to a logical channel using a handle number sent by a client
1487 This function is called by the server.
1489 @param aMessage The message pointer.
1490 @param aParam An index specifying which of the four message arguments
1491 contains the handle number.
1492 @param aType An enumeration whose enumerators define the ownership of this
1493 logical channel handle. If not explicitly specified,
1494 EOwnerProcess is taken as default.
1496 @return KErrNone, if successful;
1497 KErrArgument, if the value of aParam is outside the range 0-3;
1498 KErrBadHandle, if not a valid handle;
1499 otherwise one of the other system-wide error codes.
1501 EXPORT_C TInt RBusLogicalChannel::Open(RMessagePtr2 aMessage,TInt aParam,TOwnerType aType)
1503 return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),ELogicalChannel,aParam,aType));
1510 Opens a logical channel handle using a handle number passed as an
1511 environment data item to the child process during the creation of
1514 Note that this function can only be called successfully once.
1516 @param aArgumentIndex An index that identifies the slot in the process
1517 environment data that contains the handle number. This is
1518 a value relative to zero, i.e. 0 is the first item/slot.
1519 This can range from 0 to 15.
1521 @param aOwnerType An enumeration whose enumerators define the ownership of
1522 this logical channel handle. If not explicitly specified,
1523 EOwnerProcess is taken as default.
1525 @return KErrNone, if successful;
1526 KErrNotFound, if the slot indicated by aArgumentIndex is empty;
1527 KErrArgument, if the slot does not contain a logical channel handle;
1528 otherwise one of the other system-wide error codes.
1530 EXPORT_C TInt RBusLogicalChannel::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
1532 return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ELogicalChannel, aOwnerType));
1538 EXPORT_C TInt RHandleBase::Duplicate(const RThread &aSrc,TOwnerType aType)
1540 Creates a valid handle to the kernel object for which the specified thread
1541 already has a handle.
1543 The function assumes that this handle has been copy constructed from an existing
1544 handle (or the handle-number has been explicitly copied through calls to Handle()
1547 By default, any thread in the process can use this handle to access the kernel
1548 side object that the handle represents. However, specifying EOwnerThread as
1549 the second parameter to this function, means that only the creating thread
1550 can use this handle to access the kernel side object; any other thread in
1551 this process that wants to access the kernel side object must, again, duplicate
1554 @param aSrc A reference to the thread containing the handle which is to be
1555 duplicated for this thread.
1556 @param aType An enumeration whose enumerators define the ownership of this
1557 handle. If not explicitly specified, EOwnerProcess is taken
1560 @return KErrNone, if successful; otherwise, one of the other system wide error
1564 return Exec::HandleDuplicate(aSrc.Handle(), aType, iHandle);
1570 EXPORT_C TInt RHandleBase::Open(const TFindHandleBase& aFindHandle, TOwnerType aType)
1572 Opens a handle to a kernel side object found using a find-handle object.
1574 @param aFindHandle A find-handle object; an object that is used in searching
1575 for kernel side objects.
1576 @param aType An enumeration whose enumerators define the ownership of
1577 this handle. If not explicitly specified, EOwnerProcess
1578 is taken as default, and ownership is vested in the
1579 current process. Ownership can be vested in the current
1580 thread by passing the EOwnerThread enumerator.
1581 @return KErrNone, if successful; otherwise one of the other system wide
1585 return SetReturnedHandle(Exec::FindHandleOpen(aType, aFindHandle), *this);
1591 Implementation for RXxxxx::Open/OpenGlocbal(const TDesC &aName,,TOwnerType aType) functions
1594 TInt RHandleBase::OpenByName(const TDesC &aName,TOwnerType aOwnerType,TInt aObjectType)
1596 TBuf8<KMaxFullName> name8;
1598 return SetReturnedHandle(Exec::OpenObject((TObjectType)aObjectType,name8,aOwnerType));
1601 TInt RHandleBase::SetReturnedHandle(TInt aHandleOrError,RHandleBase& aHandle)
1603 // Set the handle value or return error
1606 return aHandle.SetReturnedHandle(aHandleOrError);
1612 EXPORT_C void RHandleBase::Close()
1616 This has the effect of closing the associated kernel side object.
1618 As the associated object is a reference counting object, it is destroyed if
1619 there are no other open references to it.
1625 __IF_DEBUG(Print(_L("RHandleBase::Close")));
1630 // We take a copy of the handle and set it to zero before the close in case this
1631 // object is actually a Chunk created in its own heap in which case the close
1632 // will destroy the object as well.
1635 if ((h&CObjectIx::ENoClose)==0 && Exec::HandleClose(h)>0)
1643 void RHandleBase::DoExtendedClose()
1645 // Call static data destructors following a library handle close
1648 TRAPD(r,DoExtendedCloseL()); // catch attempts to leave from destructors
1649 __ASSERT_ALWAYS(r==KErrNone, Panic(EDllStaticDestructorLeave));
1652 void RHandleBase::DoExtendedCloseL()
1654 // Call static data destructors following a library handle close
1657 TLinAddr ep[KMaxLibraryEntryPoints];
1661 TInt numEps=KMaxLibraryEntryPoints;
1662 r=E32Loader::LibraryDetach(numEps, ep);
1666 for (i=numEps-1; i>=0; --i)
1668 TLibraryEntry f=(TLibraryEntry)ep[i];
1669 (*f)(KModuleEntryReasonProcessDetach);
1671 r=E32Loader::LibraryDetached();
1679 Constructs an RMessage2 from an RMessagePtr2.
1681 @param aPtr A reference to an existing RMessagePtr2 object.
1683 EXPORT_C RMessage2::RMessage2(const RMessagePtr2& aPtr)
1685 iHandle = aPtr.Handle();
1686 Exec::MessageConstructFromPtr(iHandle, this);
1691 /** Sets this message to an authorised state. This is used only by
1692 CPolicyServer. This flags use by the policy server implies two things:
1693 1) That the message has passed any appropriate security checks. (ie. one of the
1694 static policy check, CustomSecurityCheckL, or CustomFailureActionL,
1696 2) That any leaves that occur subsequent to this flag being set happen _only_
1697 in the session's ServiceL. ie. Nothing can leave between this flag being set
1698 and the session's ServiceL being called.
1700 This is labelled as a const functions as everybody handles const RMessage2&'s.
1701 The constness is actually referring to the underlying RMessagePtr2 not the
1702 tranisent RMessage2 class.
1706 void RMessage2::SetAuthorised() const
1711 /** Sets the authorised flag to a state of not authorised. This is required as
1712 there is a default constructor for RMessage2 and one cannot guarantee that
1713 iFlags was initialised. This is called from CPolicyServer::RunL.
1715 This is labelled as a const functions as everybody handles const RMessage2&'s.
1716 The constness is actually referring to the underlying RMessagePtr2 not the
1717 tranisent RMessage2 class.
1721 void RMessage2::ClearAuthorised() const
1726 /** Returns whether this message has been authorised by CPolicyServer. See
1727 RMessage2::SetAuthorised for implications of this state.
1730 TBool RMessage2::Authorised() const
1741 @param aReason The completion code.
1743 EXPORT_C void RMessagePtr2::Complete(TInt aReason) const
1745 // Free this message. If it's a disconnect, need to switch to kernel context as we'll be
1746 // freeing the DSession
1750 const_cast<TInt&>(iHandle)=0;
1752 Exec::MessageComplete(h,aReason);
1754 ::Panic(ETMesCompletion);
1761 Duplicates the specified handle in the client thread, and returns this
1762 handle as a message completion code
1764 @param aHandle The handle to be duplicated.
1766 EXPORT_C void RMessagePtr2::Complete(RHandleBase aHandle) const
1769 const_cast<TInt&>(iHandle)=0;
1771 Exec::MessageCompleteWithHandle(h,aHandle.Handle());
1773 ::Panic(ETMesCompletion);
1780 Gets the length of a descriptor argument in the client's process.
1782 @param aParam The index value identifying the argument.
1783 This is a value in the range 0 to (KMaxMessageArguments-1)
1786 @return The length of the descriptor, if successful.
1787 KErrArgument, if aParam has a value outside the valid range.
1788 KErrBadDescriptor, if the message argument is not a descriptor type.
1790 EXPORT_C TInt RMessagePtr2::GetDesLength(TInt aParam) const
1792 return Exec::MessageGetDesLength(iHandle,aParam);
1799 Gets the length of a descriptor argument in the client's process,
1802 @param aParam The index value identifying the argument.
1803 This is a value in the range 0 to (KMaxMessageArguments-1)
1806 @return The length of the descriptor.
1808 @leave KErrArgument if aParam has a value outside the valid range.
1809 @leave KErrBadDescriptor, if the message argument is not a descriptor type.
1811 EXPORT_C TInt RMessagePtr2::GetDesLengthL(TInt aParam) const
1813 return User::LeaveIfError(GetDesLength(aParam));
1820 Gets the maximum length of a descriptor argument in the client's process.
1822 @param aParam The index value identifying the argument.
1823 This is a value in the range 0 to (KMaxMessageArguments-1)
1826 @return The maximum length of the descriptor, if successful.
1827 KErrArgument, if aParam has a value outside the valid range.
1828 KErrBadDescriptor, if the message argument is not a descriptor type.
1830 EXPORT_C TInt RMessagePtr2::GetDesMaxLength(TInt aParam) const
1832 return Exec::MessageGetDesMaxLength(iHandle,aParam);
1839 Gets the maximum length of a descriptor argument in the client's process,
1842 @param aParam The index value identifying the argument.
1843 This is a value in the range 0 to (KMaxMessageArguments-1)
1846 @return The length of the descriptor.
1848 @leave KErrArgument if aParam has a value outside the valid range.
1849 @leave KErrBadDescriptor, if the message argument is not a descriptor type.
1851 EXPORT_C TInt RMessagePtr2::GetDesMaxLengthL(TInt aParam) const
1853 return User::LeaveIfError(GetDesMaxLength(aParam));
1860 Reads data from the specified offset within the 8-bit descriptor
1861 argument, into the specified target descriptor, and leaving on failure.
1863 @param aParam The index value identifying the argument.
1864 This is a value in the range 0 to (KMaxMessageArguments-1)
1866 @param aDes The target descriptor into which the client data is
1868 @param aOffset The offset from the start of the client's descriptor data.
1869 If not explicitly specified, the offset defaults to zero.
1871 @leave KErrArgument if aParam has a value outside the valid range, or
1872 if aOffset is negative.
1873 @leave KErrBadDescriptor, if the message argument is not an 8-bit descriptor.
1875 EXPORT_C void RMessagePtr2::ReadL(TInt aParam,TDes8& aDes,TInt aOffset) const
1877 TInt error = Read(aParam,aDes,aOffset);
1878 User::LeaveIfError(error);
1885 Reads data from the specified offset within the 16-bit descriptor
1886 argument, into the specified target descriptor, and leaving on failure.
1888 @param aParam The index value identifying the argument.
1889 This is a value in the range 0 to (KMaxMessageArguments-1)
1891 @param aDes The target descriptor into which the client data is
1893 @param aOffset The offset from the start of the client's descriptor data.
1894 If not explicitly specified, the offset defaults to zero.
1896 @leave KErrArgument if aParam has a value outside the valid range, or
1897 if aOffset is negative.
1898 @leave KErrBadDescriptor, if the message argument is not a 16-bit descriptor.
1900 EXPORT_C void RMessagePtr2::ReadL(TInt aParam,TDes16 &aDes,TInt aOffset) const
1902 TInt error = Read(aParam,aDes,aOffset);
1903 User::LeaveIfError(error);
1910 Writes data from the specified source descriptor to the specified offset within
1911 the 8-bit descriptor argument, and leaving on failure.
1913 @param aParam The index value identifying the argument.
1914 This is a value in the range 0 to (KMaxMessageArguments-1)
1916 @param aDes The source descriptor containing the data to be written.
1917 @param aOffset The offset from the start of the client's descriptor.
1918 If not explicitly specified, the offset defaults to zero.
1920 @leave KErrArgument if aParam has a value outside the valid range, or
1921 if aOffset is negative.
1922 @leave KErrBadDescriptor, if the message argument is not an 8-bit descriptor.
1924 EXPORT_C void RMessagePtr2::WriteL(TInt aParam,const TDesC8& aDes,TInt aOffset) const
1926 TInt error = Write(aParam,aDes,aOffset);
1927 User::LeaveIfError(error);
1934 Writes data from the specified source descriptor to the specified offset within
1935 the 16-bit descriptor argument, and leaving on failure.
1937 @param aParam The index value identifying the argument.
1938 This is a value in the range 0 to (KMaxMessageArguments-1)
1940 @param aDes The source descriptor containing the data to be written.
1941 @param aOffset The offset from the start of the client's descriptor.
1942 If not explicitly specified, the offset defaults to zero.
1944 @leave KErrArgument if aParam has a value outside the valid range, or
1945 if aOffset is negative.
1946 @leave KErrBadDescriptor, if the message argument is not a 16-bit descriptor.
1948 EXPORT_C void RMessagePtr2::WriteL(TInt aParam,const TDesC16& aDes,TInt aOffset) const
1950 TInt error = Write(aParam,aDes,aOffset);
1951 User::LeaveIfError(error);
1958 Reads data from the specified offset within the 8-bit descriptor
1959 argument, into the specified target descriptor.
1961 @param aParam The index value identifying the argument.
1962 This is a value in the range 0 to (KMaxMessageArguments-1)
1964 @param aDes The target descriptor into which the client data is
1966 @param aOffset The offset from the start of the client's descriptor data.
1967 If not explicitly specified, the offset defaults to zero.
1969 @return KErrNone, if successful;
1970 KErrArgument if aParam has a value outside the valid range, or
1971 if aOffset is negative.
1972 KErrBadDescriptor, if the message argument is not an 8-bit descriptor.
1974 EXPORT_C TInt RMessagePtr2::Read(TInt aParam,TDes8& aDes,TInt aOffset) const
1977 info.iFlags=KChunkShiftBy0|KIpcDirRead;
1978 info.iLocalLen=aDes.MaxLength();
1979 info.iLocalPtr=(TUint8*)aDes.Ptr();
1980 TInt r=Exec::MessageIpcCopy(iHandle,aParam,info,aOffset);
1991 Reads data from the specified offset within the 16-bit descriptor
1992 argument, into the specified target descriptor.
1994 @param aParam The index value identifying the argument.
1995 This is a value in the range 0 to (KMaxMessageArguments-1)
1997 @param aDes The target descriptor into which the client data is
1999 @param aOffset The offset from the start of the client's descriptor data.
2000 If not explicitly specified, the offset defaults to zero.
2002 @return KErrNone, if successful;
2003 KErrArgument if aParam has a value outside the valid range, or
2004 if aOffset is negative.
2005 KErrBadDescriptor, if the message argument is not a 16-bit descriptor.
2007 EXPORT_C TInt RMessagePtr2::Read(TInt aParam,TDes16 &aDes,TInt aOffset) const
2010 info.iFlags=KChunkShiftBy1|KIpcDirRead;
2011 info.iLocalLen=aDes.MaxLength();
2012 info.iLocalPtr=(TUint8*)aDes.Ptr();
2013 TInt r=Exec::MessageIpcCopy(iHandle,aParam,info,aOffset);
2024 Writes data from the specified source descriptor to the specified offset within
2025 the 8-bit descriptor argument.
2027 @param aParam The index value identifying the argument.
2028 This is a value in the range 0 to (KMaxMessageArguments-1)
2030 @param aDes The source descriptor containing the data to be written.
2031 @param aOffset The offset from the start of the client's descriptor.
2032 If not explicitly specified, the offset defaults to zero.
2034 @return KErrNone, if successful;
2035 KErrArgument if aParam has a value outside the valid range, or
2036 if aOffset is negative.
2037 KErrBadDescriptor, if the message argument is not an 8-bit descriptor;
2038 KErrOverflow, if the target descriptor is too small
2039 to containt the data.
2041 EXPORT_C TInt RMessagePtr2::Write(TInt aParam,const TDesC8& aDes,TInt aOffset) const
2044 info.iFlags=KChunkShiftBy0|KIpcDirWrite;
2045 info.iLocalLen=aDes.Length();
2046 info.iLocalPtr=(TUint8*)aDes.Ptr();
2047 return Exec::MessageIpcCopy(iHandle,aParam,info,aOffset);
2054 Writes data from the specified source descriptor to the specified offset within
2055 the 16-bit descriptor argument.
2057 @param aParam The index value identifying the argument.
2058 This is a value in the range 0 to (KMaxMessageArguments-1)
2060 @param aDes The source descriptor containing the data to be written.
2061 @param aOffset The offset from the start of the client's descriptor.
2062 If not explicitly specified, the offset defaults to zero.
2064 @return KErrNone, if successful;
2065 KErrArgument if aParam has a value outside the valid range, or
2066 if aOffset is negative.
2067 KErrBadDescriptor, if the message argument is not an 16-bit descriptor;
2068 KErrOverflow, if the target descriptor is too small
2069 to containt the data.
2071 EXPORT_C TInt RMessagePtr2::Write(TInt aParam,const TDesC16& aDes,TInt aOffset) const
2074 info.iFlags=KChunkShiftBy1|KIpcDirWrite;
2075 info.iLocalLen=aDes.Length();
2076 info.iLocalPtr=(TUint8*)aDes.Ptr();
2077 return Exec::MessageIpcCopy(iHandle,aParam,info,aOffset);
2086 The length of the category name should be no greater than 16; any name with
2087 a length greater than 16 is truncated to 16.
2089 Note that this method also completes the message. A subsequent call to Complete(TInt aReason) would cause a server panic.
2091 @param aCategory The panic category.
2092 @param aReason The panic code.
2094 EXPORT_C void RMessagePtr2::Panic(const TDesC& aCategory,TInt aReason) const
2096 TBuf8<KMaxExitCategoryName> cat;
2097 TInt length=aCategory.Length();
2098 if(length>KMaxExitCategoryName)
2100 TPtr catPtr((TUint16*)aCategory.Ptr(),KMaxExitCategoryName,KMaxExitCategoryName);
2105 cat.Copy(aCategory);
2107 Exec::MessageKill(iHandle,EExitPanic,aReason,&cat);
2117 Note that this method also completes the message. A subsequent call to Complete(TInt aReason) would cause a server panic.
2119 @param aReason The reason code associated with killing the client.
2121 EXPORT_C void RMessagePtr2::Kill(TInt aReason) const
2123 Exec::MessageKill(iHandle,EExitKill,aReason,NULL);
2131 Terminates the client.
2133 Note that this method also completes the message. A subsequent call to Complete(TInt aReason) would cause a server panic.
2135 @param aReason The reason code associated with terminating the client.
2137 EXPORT_C void RMessagePtr2::Terminate(TInt aReason) const
2139 Exec::MessageKill(iHandle,EExitTerminate,aReason,NULL);
2147 Sets the priority of the client's process.
2149 @param aPriority The priority value.
2151 @return KErrNone, if successful, otherwise one of the other system-wide error codes.
2153 EXPORT_C TInt RMessagePtr2::SetProcessPriority(TProcessPriority aPriority) const
2155 return Exec::MessageSetProcessPriority(iHandle,aPriority);
2161 Opens a handle on the client thread.
2163 @param aClient On successful return, the handle to the client thread.
2164 @param aOwnerType An enumeration whose enumerators define the ownership of
2165 the handle. If not explicitly specified,
2166 EOwnerProcess is taken as default.
2170 EXPORT_C TInt RMessagePtr2::Client(RThread& aClient, TOwnerType aOwnerType) const
2172 return aClient.SetReturnedHandle(Exec::MessageClient(iHandle,aOwnerType));
2175 EXPORT_C TUint RMessagePtr2::ClientProcessFlags() const
2177 return Exec::MessageClientProcessFlags(iHandle);
2180 EXPORT_C TBool RMessagePtr2::ClientIsRealtime() const
2182 return (Exec::MessageClientProcessFlags(iHandle) & KThreadFlagRealtime) != 0;
2188 Returns the pointer to the clients TRequestStatus associated with the message.
2190 The return value is intended to be used as a unique identifier (for example,
2191 to uniquely identify an asynchronous message when cancelling the request).
2192 The memory must never be accessed directly or completed.
2194 @return The clients TRequestStatus (returns NULL if the request is not asynchronous)
2196 EXPORT_C const TRequestStatus* RMessagePtr2::ClientStatus() const
2198 return Exec::MessageClientStatus(iHandle);
2203 EXPORT_C TInt RServer2::CreateGlobal(const TDesC& aName, TInt aMode, TInt aRole, TInt aOpts)
2205 // Create a new server.
2208 TInt r = User::ValidateName(aName);
2211 TBuf8<KMaxKernelName> name8;
2213 r = Exec::ServerCreateWithOptions(&name8, aMode, aRole, aOpts);
2214 return SetReturnedHandle(r, *this);
2217 EXPORT_C TInt RServer2::CreateGlobal(const TDesC& aName, TInt aMode)
2219 return CreateGlobal(aName, aMode, EServerRole_Default, 0);
2222 EXPORT_C TInt RServer2::CreateGlobal(const TDesC& aName)
2224 return CreateGlobal(aName, EIpcSession_Sharable);
2227 TInt RSessionBase::DoConnect(const TVersion &aVersion,TRequestStatus* aStatus)
2229 extern int TVersion_size_assert[sizeof(TVersion)==sizeof(TInt)?1:-1]; // Make sure TVersion is same size as int
2230 (void)TVersion_size_assert;
2232 TIpcArgs p(*(TInt*)&aVersion);
2235 r = SendSync(RMessage2::EConnect, &p);
2237 r = SendAsync(RMessage2::EConnect, &p, aStatus);
2247 Creates a session with a server.
2249 It should be called as part of session initialisation in the derived class.
2251 @param aServer The name of the server with which a session is to
2253 @param aVersion The lowest version of the server with which this client
2255 @param aAsyncMessageSlots The number of message slots available to this session.
2256 This determines the number of outstanding requests the client
2257 may have with the server at any one time.
2258 The maximum number of slots is 255.
2259 If aAsyncMessageSlots==-1 then this indicates that the session should use
2260 messages from the global free pool of messages.
2261 @param aType The type of session to create. See TIpcSessionType.
2262 @param aPolicy A pointer to a TSecurityPolicy object. If this pointer is not 0 (zero)
2263 then the policy is applied to the process in which the server is running.
2264 If that process doesn't pass this security policy check, then the session
2265 creation will fail with the error KErrPermissionDenied.
2266 This security check allows clients to verify that the server has the expected
2267 Platform Security attributes.
2269 When a check fails the action taken is determined by the system wide Platform Security
2270 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
2271 If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
2274 @param aStatus A pointer to TRequestStatus object which will be signalled when the session
2275 has been created, or in the event of an error.
2276 If aStatus==0 then session creation is done synchronously.
2278 @return KErrNone if successful;
2279 KErrArgument, if an attempt is made to specify more
2280 than 255 message slots;
2281 otherwise one of the other system-wide error codes.
2283 EXPORT_C TInt RSessionBase::CreateSession(const TDesC& aServer,const TVersion& aVersion,TInt aAsyncMessageSlots,TIpcSessionType aType,const TSecurityPolicy* aPolicy, TRequestStatus* aStatus)
2285 TInt r = User::ValidateName(aServer);
2288 TBuf8<KMaxKernelName> name8;
2289 name8.Copy(aServer);
2290 r=SetReturnedHandle(Exec::SessionCreate(name8,aAsyncMessageSlots,aPolicy,aType));
2292 r=DoConnect(aVersion,aStatus);
2300 Creates a session with a server.
2302 It should be called as part of session initialisation in the derived class.
2304 @param aServer The name of the server with which a session is to
2306 @param aVersion The lowest version of the server with which this client
2308 @param aAsyncMessageSlots The number of message slots available to this session.
2309 This determines the number of outstanding requests the client
2310 may have with the server at any one time.
2311 The maximum number of slots is 255.
2312 If aAsyncMessageSlots==-1 then this indicates that the session should use
2313 messages from the global free pool of messages.
2315 @return KErrNone if successful;
2316 KErrArgument, if an attempt is made to specify more
2317 than 255 message slots;
2318 otherwise one of the other system-wide error codes.
2320 EXPORT_C TInt RSessionBase::CreateSession(const TDesC &aServer, const TVersion &aVersion, TInt aAsyncMessageSlots)
2322 return RSessionBase::CreateSession(aServer,aVersion,aAsyncMessageSlots,EIpcSession_Unsharable,NULL,0);
2329 Creates a session with a server.
2331 It should be called as part of session initialisation in the derived class.
2333 @param aServer A handle to a server with which a session is to be established.
2334 @param aVersion The lowest version of the server with which this client
2336 @param aAsyncMessageSlots The number of message slots available to this session.
2337 This determines the number of outstanding requests the client
2338 may have with the server at any one time.
2339 The maximum number of slots is 255.
2340 If aAsyncMessageSlots==-1 then this indicates that the session should use
2341 messages from the global free pool of messages.
2342 @param aType The type of session to create. See TIpcSessionType.
2343 @param aPolicy A pointer to a TSecurityPolicy object. If this pointer is not 0 (zero)
2344 then the policy is applied to the process in which the server is running.
2345 If that process doesn't pass this security policy check, then the session
2346 creation will fail with the error KErrPermissionDenied.
2347 This security check allows clients to verify that the server has the expected
2348 Platform Security attributes.
2350 When a check fails the action taken is determined by the system wide Platform Security
2351 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
2352 If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
2355 @param aStatus A pointer to TRequestStatus object which will be signalled when the session
2356 has been created, or in the event of an error.
2357 If aStatus==0 then session creation is done synchronously.
2359 @return KErrNone if successful;
2360 KErrArgument, if an attempt is made to specify more
2361 than 255 message slots;
2362 otherwise one of the other system-wide error codes.
2364 EXPORT_C TInt RSessionBase::CreateSession(RServer2 aServer,const TVersion& aVersion,TInt aAsyncMessageSlots,TIpcSessionType aType,const TSecurityPolicy* aPolicy, TRequestStatus* aStatus)
2367 r=SetReturnedHandle(Exec::SessionCreateFromHandle(aServer.Handle(),aAsyncMessageSlots,aPolicy,aType));
2369 r=DoConnect(aVersion,aStatus);
2377 Creates a session with a server.
2379 It should be called as part of session initialisation in the derived class.
2381 @param aServer A handle to a server with which a session is to be established.
2382 @param aVersion The lowest version of the server with which this client
2384 @param aAsyncMessageSlots The number of message slots available to this session.
2385 This determines the number of outstanding requests the client
2386 may have with the server at any one time.
2387 The maximum number of slots is 255.
2388 If aAsyncMessageSlots==-1 then this indicates that the session should use
2389 messages from the global free pool of messages.
2391 @return KErrNone if successful;
2392 KErrArgument, if an attempt is made to specify more
2393 than 255 message slots;
2394 otherwise one of the other system-wide error codes.
2396 EXPORT_C TInt RSessionBase::CreateSession(RServer2 aServer, const TVersion &aVersion, TInt aAsyncMessageSlots)
2398 return RSessionBase::CreateSession(aServer,aVersion,aAsyncMessageSlots,EIpcSession_Unsharable,NULL,0);
2405 Opens a handle to a session using a handle number sent by a client
2408 This function is called by the server.
2410 @param aMessage The message pointer.
2411 @param aParam An index specifying which of the four message arguments
2412 contains the handle number.
2413 @param aType An enumeration whose enumerators define the ownership of this
2414 session handle. If not explicitly specified, EOwnerProcess
2415 is taken as default.
2417 @return KErrNone, if successful;
2418 KErrArgument, if the value of aParam is outside the range 0-3;
2419 KErrBadHandle, if not a valid handle;
2420 otherwise one of the other system-wide error codes.
2422 EXPORT_C TInt RSessionBase::Open(RMessagePtr2 aMessage,TInt aParam,TOwnerType aType)
2424 return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),ESession,aParam,aType));
2431 Opens a handle to a session using a handle number sent by a client
2432 to a server, and validate that the session's server passes a given
2435 This function is called by the server.
2437 @param aMessage The message pointer.
2438 @param aParam An index specifying which of the four message arguments
2439 contains the handle number.
2440 @param aServerPolicy The policy to validate the session's server against.
2441 @param aType An enumeration whose enumerators define the ownership of this
2442 session handle. If not explicitly specified, EOwnerProcess
2443 is taken as default.
2445 @return KErrNone, if successful;
2446 KErrArgument, if the value of aParam is outside the range 0-3;
2447 KErrBadHandle, if not a valid handle;
2448 KErrServerTerminating, if the session is no longer connected to a server;
2449 KErrPermissionDenied, if the session's server does not pass the given security policy;
2450 otherwise one of the other system-wide error codes.
2452 EXPORT_C TInt RSessionBase::Open(RMessagePtr2 aMessage,TInt aParam,const TSecurityPolicy& aServerPolicy,TOwnerType aType)
2454 return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),ESession,aParam,aType),aServerPolicy);
2460 Sets the handle-number of this session handle to the specified value after
2461 validating that the session's server passes a given security policy.
2463 The function can take a (zero or positive) handle-number,
2464 or a (negative) error number.
2466 If aHandleOrError represents a handle-number, then the handle-number of this handle
2467 is set to that value, as long as the session's server passes the security policy.
2468 If aHandleOrError represents an error number, then the handle-number of this handle is set to zero
2469 and the negative value is returned.
2471 @param aHandleOrError A handle-number, if zero or positive; an error value, if negative.
2472 @param aServerPolicy The policy to validate the session's server against.
2474 @return KErrNone, if aHandle is a handle-number; KErrPermissionDenied, if the session's server
2475 does not pass the security policy; the value of aHandleOrError, otherwise.
2477 EXPORT_C TInt RSessionBase::SetReturnedHandle(TInt aHandleOrError,const TSecurityPolicy& aServerPolicy)
2479 if(aHandleOrError<0)
2480 return aHandleOrError;
2482 TInt r = aServerPolicy.CheckPolicy((RSessionBase&)aHandleOrError);
2485 ((RHandleBase&)aHandleOrError).Close();
2489 iHandle=aHandleOrError;
2497 Opens a handle to a session using a handle number passed as an
2498 environment data item to the child process during the creation of
2501 Note that this function can only be called successfully once.
2503 @param aArgumentIndex An index that identifies the slot in the process
2504 environment data that contains the handle number. This is
2505 a value relative to zero, i.e. 0 is the first item/slot.
2506 This can range from 0 to 15.
2508 @param aOwnerType An enumeration whose enumerators define the ownership of
2509 this session handle. If not explicitly specified,
2510 EOwnerProcess is taken as default.
2512 @return KErrNone, if successful;
2513 KErrNotFound, if the slot indicated by aArgumentIndex is empty;
2514 KErrArgument, if the slot does not contain a session handle;
2515 otherwise one of the other system-wide error codes.
2517 EXPORT_C TInt RSessionBase::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
2519 return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ESession, aOwnerType));
2524 Opens a handle to a session using a handle number passed as an
2525 environment data item to the child process during the creation of
2526 that child process, after validating that the session's server passes
2527 the given security policy.
2529 Note that this function can only be called successfully once.
2531 @param aArgumentIndex An index that identifies the slot in the process
2532 environment data that contains the handle number. This is
2533 a value relative to zero, i.e. 0 is the first item/slot.
2534 This can range from 0 to 15.
2535 @param aServerPolicy The policy to validate the session's server against.
2536 @param aOwnerType An enumeration whose enumerators define the ownership of
2537 this session handle. If not explicitly specified,
2538 EOwnerProcess is taken as default.
2540 @return KErrNone, if successful;
2541 KErrNotFound, if the slot indicated by aArgumentIndex is empty;
2542 KErrArgument, if the slot does not contain a session handle;
2543 KErrServerTerminating, if the session is no longer connected to a server;
2544 KErrPermissionDenied, if the session's server does not pass the given security policy;
2545 otherwise one of the other system-wide error codes.
2547 EXPORT_C TInt RSessionBase::Open(TInt aArgumentIndex, const TSecurityPolicy& aServerPolicy, TOwnerType aOwnerType)
2549 return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ESession, aOwnerType), aServerPolicy);
2553 EXPORT_C TInt RSessionBase::DoShare(TInt aMode)
2555 // Make the session accessible to all threads in this process
2558 return Exec::SessionShare(iHandle, (aMode&KCreateProtectedObject) ? EIpcSession_GlobalSharable : EIpcSession_Sharable);
2564 TInt RSessionBase::SendSync(TInt aFunction,const TIpcArgs* aArgs) const
2566 // Send a synchronous message.
2569 TRequestStatus s=KRequestPending;
2570 TInt r=Exec::SessionSendSync(iHandle,aFunction,(TAny*)aArgs,&s);
2573 User::WaitForRequest(s);
2579 TInt RSessionBase::SendAsync(TInt aFunction,const TIpcArgs* aArgs,TRequestStatus *aStatus) const
2581 // Send an asynchronous message.
2585 *aStatus=KRequestPending;
2586 return Exec::SessionSend(iHandle,aFunction,(TAny*)aArgs,aStatus);
2592 EXPORT_C TInt RMutex::CreateLocal(TOwnerType aType)
2594 Creates a mutex and opens this handle to the mutex.
2596 The kernel side object representing the mutex is unnamed. This means that
2597 it is not possible to search for the mutex, which makes it local to the current
2600 By default, any thread in the process can use this instance of RMutex to access
2601 the mutex. However, specifying EOwnerThread as the parameter to this function,
2602 means that only the creating thread can use this instance of RMutex to access
2603 the mutex; any other thread in this process that wants to access the mutex
2604 must duplicate this handle.
2606 @param aType An enumeration whose enumerators define the ownership of this
2607 mutex handle. If not explicitly specified, EOwnerProcess is taken
2610 @return KErrNone if successful, otherwise one of the system wide error codes.
2612 @see RHandleBase::Duplicate()
2615 return SetReturnedHandle(Exec::MutexCreate(NULL,aType),*this);
2621 EXPORT_C TInt RMutex::CreateGlobal(const TDesC &aName,TOwnerType aType)
2623 Creates a global mutex and opens this handle to the mutex.
2625 The kernel side object representing the mutex is given the name contained
2626 in the specified descriptor, which makes it global. This means that any thread
2627 in any process can search for the mutex, using TFindMutex, and open a handle
2628 to it. If the specified name is empty the kernel side object representing the
2629 mutex is unnamed and so cannot be opened by name. It can however be passed
2630 to another process as a process parameter or via IPC.
2632 By default, any thread in the process can use this instance of RMutex to access
2633 the mutex. However, specifying EOwnerThread as the second parameter to this
2634 function, means that only the creating thread can use this instance of RMutex
2635 to access the mutex; any other thread in this process that wants to access
2636 the mutex must either duplicate this handle or use OpenGlobal().
2638 @param aName The name to be assigned to this global mutex.
2639 @param aType An enumeration whose enumerators define the ownership of this
2640 mutex handle. If not explicitly specified, EOwnerProcess is
2643 @return KErrNone if successful, otherwise one of the other system wide error
2647 @see RHandleBase::Duplicate()
2651 TInt r = User::ValidateName(aName);
2654 TBuf8<KMaxKernelName> name8;
2656 return SetReturnedHandle(Exec::MutexCreate(&name8,aType),*this);
2662 EXPORT_C TInt RMutex::OpenGlobal(const TDesC &aName,TOwnerType aType)
2664 Opens a handle to a global mutex.
2666 Global mutexes are identified by name.
2668 By default, any thread in the process can use this instance of RMutex to access
2669 the mutex. However, specifying EOwnerThread as the second parameter to this
2670 function, means that only the opening thread can use this instance of RMutex
2671 to access the mutex; any other thread in this process that wants to access
2672 the mutex must either duplicate the handle or use OpenGlobal() again.
2674 @param aName The name of the global mutex which is to be opened.
2675 @param aType An enumeration whose enumerators define the ownership of this
2676 mutex handle. If not explicitly specified, EOwnerProcess
2677 is taken as default.
2679 @return KErrNone if successful, otherwise another of the system wide error
2681 @see RHandleBase::Duplicate()
2684 return OpenByName(aName,aType,EMutex);
2690 EXPORT_C TInt RMutex::Open(RMessagePtr2 aMessage,TInt aParam,TOwnerType aType)
2692 Opens a handle to a mutex using a handle number sent by a client
2695 This function is called by the server.
2697 @param aMessage The message pointer.
2698 @param aParam An index specifying which of the four message arguments
2699 contains the handle number.
2700 @param aType An enumeration whose enumerators define the ownership of this
2701 mutex handle. If not explicitly specified, EOwnerProcess is
2704 @return KErrNone, if successful;
2705 KErrArgument, if the value of aParam is outside the range 0-3;
2706 KErrBadHandle, if not a valid handle;
2707 otherwise one of the other system-wide error codes.
2710 return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),EMutex,aParam,aType));
2716 EXPORT_C TInt RMutex::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
2718 Opens a handle to a mutex using a handle number passed as an
2719 environment data item to the child process during the creation of
2722 Note that this function can only be called successfully once.
2724 @param aArgumentIndex An index that identifies the slot in the process
2725 environment data that contains the handle number. This is
2726 a value relative to zero, i.e. 0 is the first item/slot.
2727 This can range from 0 to 15.
2729 @param aOwnerType An enumeration whose enumerators define the ownership of
2730 this mutex handle. If not explicitly specified,
2731 EOwnerProcess is taken as default.
2733 @return KErrNone, if successful;
2734 KErrNotFound, if the slot indicated by aArgumentIndex is empty;
2735 KErrArgument, if the slot does not contain a mutex handle;
2736 otherwise one of the other system-wide error codes.
2738 @see RProcess::SetParameter()
2741 return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, EMutex, aOwnerType));
2746 EXPORT_C TInt RCondVar::CreateLocal(TOwnerType aType)
2748 Creates a condition variable and opens this handle to it.
2750 The kernel side object representing the condition variable is unnamed and so
2751 the condition variable cannot be found by name and hence it is local to the
2754 By default, any thread in the process can use this instance of RCondVar to access
2755 the condition variable. However, specifying EOwnerThread as the parameter to this
2756 function means that only the creating thread can use this instance of RCondVar
2757 to access the condition variable; any other thread in this process that wants to
2758 access the condition variable must duplicate this handle.
2760 @param aType An enumeration whose enumerators define the ownership of this
2761 condition variable handle. If not explicitly specified, EOwnerProcess
2762 is taken as default.
2764 @return KErrNone if successful, otherwise one of the system wide error codes.
2766 @see RHandleBase::Duplicate()
2769 return SetReturnedHandle(Exec::CondVarCreate(NULL, aType), *this);
2775 EXPORT_C TInt RCondVar::CreateGlobal(const TDesC& aName, TOwnerType aType)
2777 Creates a global condition variable and opens this handle to it.
2779 If the specified name is a non-empty string the kernel side object representing
2780 the condition variable is given the specified name and is therefore global. It
2781 may subsequently be opened by name using the RCondVar::OpenGlobal function.
2782 If the specified name is empty the kernel side object representing the condition
2783 variable is unnamed and so cannot be opened by name. It can however be passed
2784 to another process as a process parameter or via IPC.
2786 If the specified name is non-empty it must consist entirely of printable ASCII
2787 characters (codes 0x20 to 0x7e inclusive) and may not contain : * or ?.
2789 By default, any thread in the process can use this instance of RCondVar to access
2790 the condition variable. However, specifying EOwnerThread as the parameter to this
2791 function means that only the creating thread can use this instance of RCondVar
2792 to access the condition variable; any other thread in this process that wants to
2793 access the condition variable must duplicate this handle.
2795 @param aName The name to be assigned to this condition variable.
2796 @param aType An enumeration whose enumerators define the ownership of this
2797 condition variable handle. If not explicitly specified, EOwnerProcess
2798 is taken as default.
2800 @return KErrNone if successful, otherwise one of the other system wide error
2803 @see RCondVar::OpenGlobal()
2804 @see RHandleBase::Duplicate()
2805 @see RProcess::SetParameter(TInt, RHandleBase)
2806 @see TIpcArgs::Set(TInt, RHandleBase)
2807 @see RMessagePtr2::Complete(RHandleBase)
2810 TInt r = User::ValidateName(aName);
2813 TBuf8<KMaxKernelName> name8;
2815 return SetReturnedHandle(Exec::CondVarCreate(&name8, aType), *this);
2821 EXPORT_C TInt RCondVar::OpenGlobal(const TDesC& aName, TOwnerType aType)
2823 Opens a handle to a global condition variable.
2825 Global condition variables are identified by name.
2827 By default, any thread in the process can use this instance of RCondVar to access
2828 the condition variable. However, specifying EOwnerThread as the parameter to this
2829 function means that only the creating thread can use this instance of RCondVar
2830 to access the condition variable; any other thread in this process that wants to
2831 access the condition variable must either duplicate this handle or use OpenGlobal
2834 @param aName The name of the global condition variable which is to be opened.
2835 @param aType An enumeration whose enumerators define the ownership of this
2836 condition variable handle. If not explicitly specified, EOwnerProcess
2837 is taken as default.
2839 @return KErrNone if successful, otherwise another of the system wide error
2842 @see RHandleBase::Duplicate()
2845 return OpenByName(aName, aType, ECondVar);
2851 EXPORT_C TInt RCondVar::Open(RMessagePtr2 aMessage, TInt aParam, TOwnerType aType)
2853 Opens a handle to a condition variable using a handle number sent by a client
2856 This function is called by the server.
2858 @param aMessage The message pointer.
2859 @param aParam An index specifying which of the four message arguments
2860 contains the handle number.
2861 @param aType An enumeration whose enumerators define the ownership of this
2862 condition variable handle. If not explicitly specified, EOwnerProcess
2863 is taken as default.
2865 @return KErrNone, if successful;
2866 KErrArgument, if the value of aParam is outside the range 0-3;
2867 KErrBadHandle, if not a valid handle;
2868 otherwise one of the other system-wide error codes.
2871 return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(), ECondVar, aParam, aType));
2877 EXPORT_C TInt RCondVar::Open(TInt aArgumentIndex, TOwnerType aType)
2879 Opens a handle to a condition variable using a handle number passed as an
2880 environment data item to the child process during the creation of
2883 Note that this function can only be called successfully once.
2885 @param aArgumentIndex An index that identifies the slot in the process
2886 environment data that contains the handle number. This is
2887 a value relative to zero, i.e. 0 is the first item/slot.
2888 This can range from 0 to 15.
2890 @param aType An enumeration whose enumerators define the ownership of
2891 this condition variable handle. If not explicitly specified,
2892 EOwnerProcess is taken as default.
2894 @return KErrNone, if successful;
2895 KErrNotFound, if the slot indicated by aArgumentIndex is empty;
2896 KErrArgument, if the slot does not contain a condition variable handle;
2897 otherwise one of the other system-wide error codes.
2899 @see RProcess::SetParameter()
2902 return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ECondVar, aType));
2908 EXPORT_C TInt RSemaphore::CreateLocal(TInt aCount,TOwnerType aType)
2910 Creates a semaphore, setting its initial count, and opens this handle to the
2913 The kernel side object representing the semaphore is unnamed. This means that
2914 it is not possible to search for the semaphore, which makes it local to the
2917 By default, any thread in the process can use this instance of RSemaphore
2918 to access the semaphore. However, specifying EOwnerThread as the second parameter
2919 to this function, means that only the creating thread can use this instance
2920 of RSemaphore to access the semaphore; any other thread in this process that
2921 wants to access the semaphore must duplicate this handle.
2923 @param aCount The initial value of the semaphore count.
2924 @param aType An enumeration whose enumerators define the ownership of this
2925 semaphore handle. If not explicitly specified, EOwnerProcess is
2928 @return KErrNone if successful, otherwise another of the system wide error
2931 @panic USER 105 if aCount is negative.
2933 @see RHandleBase::Duplicate()
2937 __ASSERT_ALWAYS(aCount>=0,Panic(ESemCreateCountNegative));
2938 return SetReturnedHandle(Exec::SemaphoreCreate(NULL,aCount,aType),*this);
2944 EXPORT_C TInt RSemaphore::CreateGlobal(const TDesC &aName,TInt aCount,TOwnerType aType)
2946 Creates a global semaphore, setting its initial count, and opens this handle
2949 The kernel side object representing the semaphore is given the name contained
2950 in the specified descriptor, which makes it global. This means that any thread
2951 in any process can search for the semaphore, using TFindSemaphore, and open
2952 a handle to it. If the specified name is empty the kernel side object
2953 representing the semaphore is unnamed and so cannot be opened by name. It can
2954 however be passed to another process as a process parameter or via IPC.
2956 By default, any thread in the process can use this instance of RSemaphore
2957 to access the semaphore. However, specifying EOwnerThread as the third
2958 parameter to this function, means that only the creating thread can use
2959 this instance of RSemaphore to access the semaphore; any other thread in
2960 this process that wants to access the semaphore must either duplicate this
2961 handle or use OpenGlobal().
2963 @param aName A reference to the descriptor containing the name to be assigned
2964 to this global semaphore.
2965 @param aCount The initial value of the semaphore count.
2966 @param aType An enumeration whose enumerators define the ownership of this
2967 semaphore handle. If not explicitly specified, EOwnerProcess is
2970 @return KErrNone if successful otherwise another of the system wide error
2973 @panic USER 105 if aCount is negative.
2975 @see RSemaphore::OpenGlobal()
2976 @see RHandleBase::Duplicate()
2981 __ASSERT_ALWAYS(aCount>=0,Panic(ESemCreateCountNegative));
2982 TInt r = User::ValidateName(aName);
2985 TBuf8<KMaxKernelName> name8;
2987 return SetReturnedHandle(Exec::SemaphoreCreate(&name8,aCount,aType),*this);
2993 EXPORT_C TInt RSemaphore::OpenGlobal(const TDesC &aName,TOwnerType aType)
2995 Opens a handle to a global semaphore.
2997 Global semaphores are identified by name.
2999 By default, any thread in the process can use this instance of RSemaphore
3000 to access the semaphore. However, specifying EOwnerThread as the second parameter
3001 to this function, means that only the opening thread can use this instance
3002 of RSemaphore to access the semaphore; any other thread in this process that
3003 wants to access the semaphore must either duplicate the handle or use OpenGlobal()
3006 @param aName A reference to the descriptor containing the name of the global
3007 semaphore to be opened.
3008 @param aType An enumeration whose enumerators define the ownership of this
3009 semaphore handle. If not explicitly specified, EOwnerProcess is
3012 @return KErrNone if successful otherwise another of the system wide error
3015 @see RHandleBase::Duplicate()
3018 return OpenByName(aName,aType,ESemaphore);
3024 EXPORT_C TInt RSemaphore::Open(RMessagePtr2 aMessage,TInt aParam,TOwnerType aType)
3026 Opens a handle to a semaphore using a handle number sent by a client
3029 This function is called by the server.
3031 @param aMessage The message pointer.
3032 @param aParam An index specifying which of the four message arguments
3033 contains the handle number.
3034 @param aType An enumeration whose enumerators define the ownership of this
3035 semaphore handle. If not explicitly specified, EOwnerProcess is
3038 @return KErrNone, if successful;
3039 KErrArgument, if the value of aParam is outside the range 0-3;
3040 KErrBadHandle, if not a valid handle;
3041 otherwise one of the other system-wide error codes.
3044 return SetReturnedHandle(Exec::MessageOpenObject(aMessage.Handle(),ESemaphore,aParam,aType));
3050 EXPORT_C TInt RSemaphore::Open(TInt aArgumentIndex, TOwnerType aOwnerType)
3052 Opens a handle to a semaphore using a handle number passed as an
3053 environment data item to the child process during the creation of
3056 Note that this function can only be called successfully once.
3058 @param aArgumentIndex An index that identifies the slot in the process
3059 environment data that contains the handle number. This is
3060 a value relative to zero, i.e. 0 is the first item/slot.
3061 This can range from 0 to 15.
3063 @param aOwnerType An enumeration whose enumerators define the ownership of
3064 this semaphore handle. If not explicitly specified,
3065 EOwnerProcess is taken as default.
3067 @return KErrNone, if successful;
3068 KErrNotFound, if the slot indicated by aArgumentIndex is empty;
3069 KErrArgument, if the slot does not contain a Semaphore handle;
3070 otherwise one of the other system-wide error codes.
3072 @see RProcess::SetParameter()
3075 return SetReturnedHandle(Exec::ProcessGetHandleParameter(aArgumentIndex, ESemaphore, aOwnerType));
3081 EXPORT_C TInt RCriticalSection::CreateLocal(TOwnerType aType)
3083 Creates a critical section and opens this handle to the critical section.
3085 The kernel side object representing the critical section is unnamed. This
3086 means that it is not possible to search for the critical section, which makes
3087 it local to the current process.
3089 By default, any thread in the process can use this instance of RCriticalSection
3090 to access the critical section. However, specifying EOwnerThread as the parameter
3091 to this function, means that only the creating thread can use this instance
3092 of RCriticalSection to access the critical section; any other thread in this
3093 process that wants to access the critical section must duplicate this handle.
3095 @param aType An enumeration whose enumerators define the ownership of this
3096 critical section handle. If not explicitly specified,
3097 EOwnerProcess is taken as default.
3099 @return KErrNone if successful otherwise another of the system wide error codes.
3101 @see RHandleBase::Duplicate()
3106 return(RSemaphore::CreateLocal(0,aType));
3112 Creates a local fast semaphore, and opens this handle to the
3115 @param aType An enumeration whose enumerators define the ownership of this
3116 semaphore handle. If not explicitly specified, EOwnerProcess is
3119 @return KErrNone if successful, otherwise one of the system wide error
3122 @see RSemaphore::CreateLocal()
3124 EXPORT_C TInt RFastLock::CreateLocal(TOwnerType aType)
3128 return RSemaphore::CreateLocal(0,aType);
3134 EXPORT_C TInt RTimer::CreateLocal()
3136 // Create a local timer.
3139 Creates a thread-relative timer.
3141 @return KErrNone if successful, otherwise another of the
3142 system-wide error codes.
3145 return SetReturnedHandle(Exec::TimerCreate(),*this);
3151 EXPORT_C TInt RProcess::Open(const TDesC &aName,TOwnerType aType)
3153 Opens a handle to a specifically named process.
3155 By default, ownership of this process handle is vested in the current process,
3156 but can be vested in the current thread by passing EOwnerThread as the second
3157 parameter to this function.
3159 @param aName A reference to the descriptor containing the name of the process
3161 @param aType An enumeration whose enumerators define the ownership of this
3162 thread handle. If not explicitly specified, EOwnerProcess is
3165 @return KErrNone, if successful, otherwise one of the other system-wide error
3169 return OpenByName(aName,aType,EProcess);
3175 EXPORT_C TInt RProcess::Open(TProcessId aId,TOwnerType aType)
3177 Opens a handle to the process whose process Id matches
3178 the specified process ID.
3180 By default, ownership of this process handle is vested in the current process,
3181 but can be vested in the current thread by passing EOwnerThread as the second
3182 parameter to this function.
3184 @param aId The process Id used to find the process.
3185 @param aType An enumeration whose enumerators define the ownership of this
3186 process handle. If not explicitly specified, EOwnerProcess is
3189 @return KErrNone, if successful, otherwise one of the other system-wide error
3194 TUint id=*(TUint*)&aId;
3195 return SetReturnedHandle(Exec::ProcessOpenById(id,aType),*this);
3201 EXPORT_C TInt User::RenameProcess(const TDesC &aName)
3203 Assigns a new name to the current process, replacing any existing name.
3205 When a process is created, its default name is the name portion of the filename
3206 from which the executable is loaded.
3208 The new name must be a valid name and it must also be such that the process's
3209 new fullname remains unique amongst processes.
3211 @param aName A reference to the descriptor containing the new name of the
3214 @return KErrNone, if successful, or if the new and old names are identical;
3215 KErrBadName, if aName is an invalid;
3216 otherwise one of the other system-wide error codes.
3219 TBuf8<KMaxKernelName> name8;
3221 return Exec::ProcessRename(KCurrentProcessHandle,name8);
3228 Ends this process, and all of its threads, specifying a reason code.
3230 This function is intended to be used if a process is exiting under normal
3233 If the process is system permanent, the entire system is rebooted.
3235 @param aReason The reason to be associated with the ending of this process.
3237 @capability PowerMgmt except when one of the following situations is true:
3238 1. the process calling this function is the same as the
3239 process to be terminated.
3240 2. the process calling this function created the process
3241 to be terminated, but has not yet resumed that process.
3243 @see User::SetProcessCritical()
3244 @see User::ProcessCritical()
3246 EXPORT_C void RProcess::Kill(TInt aReason)
3248 Exec::ProcessKill(iHandle,EExitKill,aReason,NULL);
3253 Ends this process, and all of its threads, specifying a reason code.
3255 This function is intended to be used if a process is exiting under abnormal
3256 conditions, for example if an error condition has been detected.
3258 If the process is system critical or system permanent, the entire system is
3261 @param aReason The reason to be associated with the ending of this process.
3263 @capability PowerMgmt except when one of the following situations is true:
3264 1. the process calling this function is the same as the
3265 process to be terminated.
3266 2. the process calling this function created the process
3267 to be terminated, but has not yet resumed that process.
3269 @see User::SetProcessCritical()
3270 @see User::ProcessCritical()
3272 EXPORT_C void RProcess::Terminate(TInt aReason)
3274 Exec::ProcessKill(iHandle,EExitTerminate,aReason,NULL);
3280 Panics the process and all of its owned threads, specifying the panic category
3281 name and reason code.
3283 The length of the category name should be no greater than 16; any name with
3284 a length greater than 16 is truncated to 16.
3286 If the process is system critical or system permanent, the entire system is
3289 @param aCategory A reference to the descriptor containing the text which
3290 defines the category name for this panic.
3291 @param aReason The panic number.
3293 @capability PowerMgmt except when one of the following situations is true:
3294 1. the process calling this function is the same as the
3295 process to be terminated.
3296 2. the process calling this function created the process
3297 to be terminated, but has not yet resumed that process.
3299 @see User::SetProcessCritical()
3300 @see User::ProcessCritical()
3302 EXPORT_C void RProcess::Panic(const TDesC &aCategory,TInt aReason)
3304 TBuf8<KMaxExitCategoryName> name8;
3305 TInt length=aCategory.Length();
3306 if(length>KMaxExitCategoryName)
3308 TPtr catPtr((TUint16*)aCategory.Ptr(),KMaxExitCategoryName,KMaxExitCategoryName);
3313 name8.Copy(aCategory);
3315 Exec::ProcessKill(iHandle,EExitPanic,aReason,&name8);
3321 EXPORT_C void RProcess::Logon(TRequestStatus &aStatus) const
3323 Requests notification when this process dies, normally or otherwise.
3325 A request for notification is an asynchronous request, and completes:
3327 - when the process terminates
3328 - if the outstanding request is cancelled by a call to RProcess::LogonCancel().
3330 A request for notification requires memory to be allocated; if this is
3331 unavailable, then the call to Logon() returns, and the asynchronous request
3332 completes immediately.
3334 @param aStatus A reference to the request status object.
3335 This contains the reason code describing the reason for
3336 the termination of the process, i.e. the value returned by a call to RProcess::ExitReason().
3337 Alternatively, this is set to:
3338 KErrCancel, if an outstanding request is cancelled;
3339 KErrNoMemory, if there is insufficient memory to deal with the request.
3341 @see RProcess::LogonCancel()
3342 @see RProcess::ExitReason()
3346 aStatus=KRequestPending;
3347 Exec::ProcessLogon(iHandle,&aStatus,EFalse);
3353 EXPORT_C TInt RProcess::LogonCancel(TRequestStatus &aStatus) const
3355 Cancels an outstanding request for notification of the death of this process.
3357 A request for notification must previously have been made, otherwise the function
3358 returns KErrGeneral.
3360 The caller passes a reference to the same request status object as was passed
3361 in the original call to Logon().
3363 @param aStatus A reference to the same request status object used in
3364 the original call to Logon().
3366 @return KErrGeneral, if there is no outstanding request; KErrNone otherwise.
3368 @see RProcess::Logon()
3371 return Exec::ProcessLogonCancel(iHandle,&aStatus,EFalse);
3378 Creates a Rendezvous request with the process.
3380 The request is an asynchronous request, and completes:
3382 - when a call is made to RProcess::Rendezvous(TInt aReason).
3383 - if the outstanding request is cancelled by a call to RProcess::RendezvousCancel()
3384 - if the process exits
3385 - if the process panics.
3387 Note that a request requires memory to be allocated; if this is unavailable,
3388 then this call to Rendezvous() returns, and the asynchronous request
3389 completes immediately.
3391 @param aStatus A reference to the request status object.
3392 The Rendezvous completes normally when
3393 RProcess::Rendezvous(TInt aReason) is called, and this
3394 request status object will contain this reason code.
3395 If the process exits or panics, then this is the process exit
3396 reason value, i.e. the same value returned by RProcess::ExitReason().
3397 Alternatively, this is set to:
3398 KErrCancel, if an outstanding request is cancelled;
3399 KErrNoMemory, if there is insufficient memory to deal with the request.
3401 @see RProcess::Rendezvous(TInt aReason)
3402 @see RProcess::RendezvousCancel(TRequestStatus& aStatus)
3404 EXPORT_C void RProcess::Rendezvous(TRequestStatus& aStatus) const
3406 aStatus=KRequestPending;
3407 Exec::ProcessLogon(iHandle,&aStatus,ETrue);
3414 Cancels a previously requested Rendezvous with the process.
3416 The request completes with the value KErrCancel (if it was still outstanding).
3418 @param aStatus A reference to the same request status object used in
3419 the original call to Rendezvous(TRequestStatus& aStatus).
3421 @return KErrGeneral, if there is no outstanding request, KErrNone otherwise.
3423 @see RProcess::Rendezvous(TRequestStatus &aStatus)
3425 EXPORT_C TInt RProcess::RendezvousCancel(TRequestStatus& aStatus) const
3427 return Exec::ProcessLogonCancel(iHandle,&aStatus,ETrue);
3434 Completes all Rendezvous' with the current process.
3436 @param aReason The reason code used to complete all rendezvous requests
3438 @see RProcess::Rendezvous(TRequestStatus& aStatus)
3440 EXPORT_C void RProcess::Rendezvous(TInt aReason)
3442 Exec::ProcessRendezvous(aReason);
3447 This can be used to determine whether the data for the process is demand paged
3450 @return ETrue if the default for the process's data is to be demand paged,
3455 EXPORT_C TBool RProcess::DefaultDataPaged() const
3457 return Exec::ProcessDefaultDataPaged(iHandle);
3462 // Class TThreadCreateInfo
3466 Constructor where the basic properties of the thread to be created are specified.
3468 NOTE - TThreadCreateInfo::SetCreateHeap() or TThreadCreateInfo::SetUseHeap() must
3469 be invoked on this TThreadCreateInfo to set the type of the thread to be created
3470 before being passed as a paramter to RThread::Create().
3472 @param aName The name to be assigned to the thread.
3473 KNullDesC, to create an anonymous thread.
3474 @param aFunction A pointer to a function. Control passes to this function
3475 when the thread is first resumed, i.e. when the thread
3476 is initially scheduled to run.
3477 @param aStackSize The size of the new thread's stack.
3478 @param aPtr A pointer to data to be passed as a parameter to
3479 the thread function when the thread is initially scheduled
3480 to run. If the thread function does not need any data then
3481 this pointer can be NULL.
3483 EXPORT_C TThreadCreateInfo::TThreadCreateInfo(const TDesC &aName, TThreadFunction aFunction,
3484 TInt aStackSize, TAny* aPtr) :
3485 iVersionNumber(EVersion0), iName(&aName), iFunction(aFunction),
3486 iStackSize(aStackSize), iParameter(aPtr), iOwner(EOwnerProcess), iHeap(NULL),
3487 iHeapMinSize(0), iHeapMaxSize(0), iAttributes(0)
3493 Sets the thread to be created to create its own heap.
3495 @param aHeapMinSize The minimum size for the new thread's heap.
3496 @param aHeapMaxSize The maximum size for the new thread's heap.
3498 EXPORT_C void TThreadCreateInfo::SetCreateHeap(TInt aHeapMinSize, TInt aHeapMaxSize)
3500 iHeapMinSize = aHeapMinSize;
3501 iHeapMaxSize = aHeapMaxSize;
3506 Sets the thread to be created to use the heap whose handle is pointed to by
3507 aAllocator. If this is NULL, then the thread uses the heap of the creating thread.
3509 @param aAllocator A pointer to the handle of the heap belonging to another thread
3510 which this thread is to use.
3512 EXPORT_C void TThreadCreateInfo::SetUseHeap(const RAllocator *aAllocator)
3514 iHeap = (aAllocator)? (RAllocator*)aAllocator : GetHeap();
3519 Sets the owner the thread to be created. Any previous calls
3520 to this method will be overridden for this TThreadCreateInfo object.
3522 @param aOwner The owner of the thread to be created.
3524 EXPORT_C void TThreadCreateInfo::SetOwner(const TOwnerType aOwner)
3531 Sets the data paging attributes of the thread to be created. Any previous calls
3532 to this method will be overridden for this TThreadCreateInfo object.
3534 @param aPaging The paging attributes for the thread to be created.
3536 EXPORT_C void TThreadCreateInfo::SetPaging(const TThreadPagingAtt aPaging)
3538 iAttributes &= ~EThreadCreateFlagPagingMask;
3539 if (aPaging == EPaged)
3540 iAttributes |= EThreadCreateFlagPaged;
3541 if (aPaging == EUnpaged)
3542 iAttributes |= EThreadCreateFlagUnpaged;
3547 Creates a thread belonging to the current process, and opens this handle
3548 to that thread. The thread will have the properties as defined by the parameter
3551 @param aCreateInfo A reference to a TThreadCreateInfo object specifying
3552 the properties of thread to create.
3554 @return KErrNone if successful, otherwise one of the other system-wide error codes.
3555 KErrAlreadyExists will be returned if there is another thread in this process with the
3558 @panic USER 109 if the stack size specified for the thread is negative.
3559 @panic USER 110 if the specified minimum heap size is less than KMinHeapSize.
3560 @panic USER 111 if the specified maximum heap size is less than the specified minimum heap size.
3562 EXPORT_C TInt RThread::Create(const TThreadCreateInfo& aCreateInfo)
3564 __ASSERT_ALWAYS(aCreateInfo.iStackSize >= 0, ::Panic(EThrdStackSizeNegative));
3565 if (!aCreateInfo.iHeap)
3566 {// Creating a new heap so verify the parameters.
3567 __ASSERT_ALWAYS(aCreateInfo.iHeapMinSize >= KMinHeapSize,::Panic(EThrdHeapMinTooSmall));
3568 __ASSERT_ALWAYS(aCreateInfo.iHeapMaxSize >= aCreateInfo.iHeapMinSize,::Panic(EThrdHeapMaxLessThanMin));
3571 TInt r = User::ValidateName(*aCreateInfo.iName);
3575 SStdEpocThreadCreateInfo8 info;
3576 info.iFunction = aCreateInfo.iFunction;
3577 info.iUserStackSize = aCreateInfo.iStackSize;
3578 info.iUserStack = NULL;
3579 info.iAllocator = aCreateInfo.iHeap;
3580 info.iHeapInitialSize = aCreateInfo.iHeapMinSize;
3581 info.iHeapMaxSize = aCreateInfo.iHeapMaxSize;
3582 info.iPtr = aCreateInfo.iParameter;
3583 info.iTotalSize = sizeof(info);
3584 info.iFlags = aCreateInfo.iAttributes;
3586 TBuf8<KMaxKernelName> n;
3587 n.Copy(*aCreateInfo.iName);
3589 return SetReturnedHandle(Exec::ThreadCreate(n, aCreateInfo.iOwner, info),*this);
3593 EXPORT_C TInt RThread::Create(const TDesC &aName,TThreadFunction aFunction,TInt aStackSize,TInt aHeapMinSize,TInt aHeapMaxSize,TAny *aPtr,TOwnerType aType)
3595 Creates a thread belonging to the current process, and opens this handle
3598 A new heap is created for this thread.
3600 By default, ownership of this thread handle is vested in the current process,
3601 but can be vested in the current thread by passing EOwnerThread as
3602 the second parameter to this function.
3604 If KNullDesC is specified for the name, then an anonymous thread will be created.
3605 Anonymous threads are not global, and cannot be opened by other processes.
3607 @param aName The name to be assigned to this thread.
3608 KNullDesC, to create an anonymous thread.
3609 @param aFunction A pointer to a function.. Control passes to this function
3610 when the thread is first resumed, i.e. when the thread
3611 is initially scheduled to run.
3612 @param aStackSize The size of the new thread's stack.
3613 @param aHeapMinSize The minimum size for the new thread's heap.
3614 @param aHeapMaxSize The maximum size for the new thread's heap.
3615 @param aPtr A pointer to data to be passed as a parameter to
3616 the thread function when the thread is initially scheduled
3617 to run. If the thread function does not need any data then
3618 this pointer can be NULL. It must be ensured that the memory
3619 pointed to by this pointer is still valid when accessed by
3620 the new thread, e.g. if aPtr points to data on the stack.
3621 @param aType An enumeration whose enumerators define the ownership of
3622 this thread handle. If not explicitly specified,
3623 EOwnerProcess is taken as default.
3625 @return KErrNone if successful, otherwise one of the other system-wide error codes.
3626 KErrAlreadyExists will be returned if there is another thread in this process with the
3629 @panic USER 109 if aStackSize is negative.
3630 @panic USER 110 if aHeapMinSize is less than KMinHeapSize.
3631 @panic USER 111 if aHeapMaxSize is less than aHeapMinSize.
3634 TThreadCreateInfo createInfo(aName, aFunction, aStackSize, aPtr);
3635 createInfo.SetOwner(aType);
3636 createInfo.SetCreateHeap(aHeapMinSize, aHeapMaxSize);
3637 return Create(createInfo);
3643 EXPORT_C TInt RThread::Create(const TDesC& aName, TThreadFunction aFunction, TInt aStackSize, RAllocator* aAllocator, TAny* aPtr, TOwnerType aType)
3645 Creates a thread belonging to the current process, and opens this handle to
3648 This thread uses the heap whose handle is pointed to by
3649 aAllocator. If this is NULL, then the thread uses the heap of the creating thread.
3651 By default, ownership of this thread handle is vested in the current process,
3652 but can be vested in the current thread by passing EOwnerThread as the second
3653 parameter to this function.
3655 If KNullDesC is specified for the name, then an anonymous thread will be created.
3656 Anonymous threads are not global, and cannot be opened by other processes.
3658 @param aName The name to be assigned to this thread.
3659 KNullDesC, to create an anonymous thread.
3660 @param aFunction A pointer to a function. Control passes to this function when
3661 the thread is first resumed, i.e. when the thread is
3662 initially scheduled to run.
3663 @param aStackSize The size of the new thread's stack.
3664 @param aAllocator A pointer to the handle of the heap belonging to another thread
3665 which this thread is to use.
3666 @param aPtr A pointer to data to be passed as a parameter to the thread
3667 function when the thread is initially scheduled to run.
3668 If the thread function does not need any data,
3669 then this pointer can be NULL. It must be ensured that the
3670 memory pointed to by this pointer is still valid when accessed
3671 by the new thread, e.g. if aPtr points to data on the stack.
3672 @param aType An enumeration whose enumerators define the ownership of this
3673 thread handle. If not explicitly specified, EOwnerProcess is
3676 @return KErrNone if successful otherwise one of the other system-wide error codes.
3677 KErrAlreadyExists will be returned if there is another thread in this process with the
3680 @panic USER 109 if aStackSize is negative.
3683 TThreadCreateInfo createInfo(aName, aFunction, aStackSize, aPtr);
3684 createInfo.SetOwner(aType);
3685 createInfo.SetUseHeap(aAllocator);
3686 return Create(createInfo);
3692 EXPORT_C TInt RThread::Open(const TDesC &aName,TOwnerType aType)
3694 Opens a handle to specifically named thread.
3696 By default, ownership of this thread handle is vested in the
3697 current process, but can be vested in the current thread by passing
3698 EOwnerThread as the second parameter to this function.
3700 @param aName A reference to the descriptor containing the full name of the
3701 thread that is already running.
3702 @param aType An enumeration whose enumerators define the ownership of this
3703 thread handle. If not explicitly specified, EOwnerProcess is taken
3706 @return KErrNone, if successful, otherwise one of the other system-wide
3710 return OpenByName(aName,aType,EThread);
3716 EXPORT_C TInt RThread::Open(TThreadId aId,TOwnerType aType)
3718 Opens a handle to the thread with a specific thread Id.
3720 By default, ownership of this thread handle is vested in the
3721 current process, but can be vested in the current thread by passing
3722 EOwnerThread as the second parameter to this function.
3724 @param aId The thread Id used to find the thread.
3725 @param aType An enumeration whose enumerators define the ownership of this
3726 thread handle. If not explicitly specified, EOwnerProcess is taken
3729 @return KErrNone, if successful, otherwise one of the other system-wide
3733 // Open an already running thread in any process.
3737 TUint id=*(TUint*)&aId;
3738 return SetReturnedHandle(Exec::ThreadOpenById(id,aType),*this);
3744 EXPORT_C TInt RThread::Process(RProcess &aProcess) const
3746 Opens a process-relative handle to the process which owns this thread.
3748 The caller must construct a default RProcess object and pass this to
3750 On return, aProcess is the open process-relative handle to the process owning
3753 The return value indicates the success or failure of this function.
3755 @param aProcess A reference to a default RProcess handle; on successful return
3756 from this function, this is the process-relative handle
3757 to the process which owns this thread.
3759 @return KErrNone, if successful, otherwise one of the other system-wide error
3763 return SetReturnedHandle(Exec::ThreadProcess(iHandle),aProcess);
3769 EXPORT_C TInt User::RenameThread(const TDesC &aName)
3771 Assigns a new name to the current thread, replacing any existing name that
3774 The new name must be a valid name and it must also be such that the thread's
3775 new fullname remains unique amongst threads.
3776 The length of the new name must be less than or equal to 80 (maximum length of
3777 kernel objects) otherwise a panic is raised.
3779 @param aName A reference to the descriptor containing the new name for the
3782 @return KErrNone if successful, otherwise one of the other system-wide error
3786 TBuf8<KMaxKernelName> name8;
3788 return Exec::ThreadRename(KCurrentThreadHandle,name8);
3794 EXPORT_C void RThread::Kill(TInt aReason)
3796 Ends the thread, specifying a reason code.
3798 This function is dangerous and should be used only in cases where the target
3799 thread cannot end itself via the normal methods of calling User::Exit() or
3800 completing its thread function. A hypothetical example might be where a thread
3801 gets 'stuck' in a third-party DLL.
3803 The target thread gets no opportunity to execute any clean-up code, therefore
3804 incautious use of this function may lead to memory leaks.
3806 It is functionally identical to RThread::Terminate(), the only difference
3807 between the two is a legacy distinction between a 'normal' reason for exiting
3808 (use Kill) and an 'abnormal' reason (use Terminate). The choice of function
3809 is reflected in the return value of RThread::ExitType().
3811 The thread must be in the current process otherwise a panic is raised.
3813 If the thread is process permanent, or the thread is the last thread in the
3814 process, then the process is also killed. If the thread is system permanent,
3815 the entire system is rebooted.
3817 WARNING: If the target thread uses a shared heap then use of this function will
3818 cause an internal array used for thread-local storage (TLS) to be leaked. This
3819 leak is specific to ARM platforms which implement the CP15 feature and will
3820 not occur on other platforms.
3822 @param aReason The reason to be associated with the ending of this thread.
3825 @see User::SetCritical()
3826 @see User::Critical()
3827 @see RThread::Terminate()
3828 @see RThread::ExitType()
3832 Exec::ThreadKill(iHandle,EExitKill,aReason,NULL);
3838 EXPORT_C void RThread::Terminate(TInt aReason)
3840 Ends the thread, specifying a reason code.
3842 This function is dangerous and should be used only in cases where the target
3843 thread cannot end itself via the normal methods of calling User::Exit() or
3844 completing its thread function. A hypothetical example might be where a thread
3845 gets 'stuck' in a third-party DLL.
3847 The target thread gets no opportunity to execute any clean-up code, therefore
3848 incautious use of this function may lead to memory leaks.
3850 It is functionally identical to RThread::Kill(), the only difference
3851 between the two is a legacy distinction between a 'normal' reason for exiting
3852 (use Kill) and an 'abnormal' reason (use Terminate). The choice of function
3853 is reflected in the return value of RThread::ExitType().
3855 The thread must be in the current process otherwise a panic is raised.
3857 If the thread is process critical or process permanent, or the thread is the
3858 last thread in the process, then the process is also terminated. If the thread
3859 is system critical or system permanent, the entire system is rebooted.
3861 WARNING: If the target thread uses a shared heap then use of this function will
3862 cause an internal array used for thread-local storage (TLS) to be leaked. This
3863 leak is specific to ARM platforms which implement the CP15 feature and will
3864 not occur on other platforms.
3866 @param aReason The reason to be associated with the ending of this thread.
3869 @see User::SetCritical()
3870 @see User::Critical()
3871 @see RThread::Kill()
3872 @see RThread::ExitType()
3876 Exec::ThreadKill(iHandle,EExitTerminate,aReason,NULL);
3882 EXPORT_C void RThread::Panic(const TDesC &aCategory,TInt aReason)
3884 Panics this thread, specifying the panic category name and reason.
3886 The length of the category name should be no greater than 16; any name with
3887 a length greater than 16 is truncated to 16.
3889 The calling thread, i.e. the thread in which this function is called, must be
3890 in the same process as this target thread, otherwise the calling thread
3893 If the thread is process critical or process permanent, the process also panics.
3894 If the thread is system critical or system permanent, the entire system is
3897 @param aCategory A reference to the descriptor containing the text which defines
3898 the category name for this panic.
3899 @param aReason The panic number.
3901 @panic KERN-EXEC 46 if this target thread's process is not the same as the
3902 calling thread's process.
3904 @see User::SetCritical()
3905 @see User::Critical()
3909 TBuf8<KMaxExitCategoryName> cat;
3910 TInt len = aCategory.Length();
3911 if(len>KMaxExitCategoryName)
3913 TPtr aCatPtr((TUint16*)aCategory.Ptr(),KMaxExitCategoryName,KMaxExitCategoryName);
3917 cat.Copy(aCategory);
3918 Exec::ThreadKill(iHandle,EExitPanic,aReason,&cat);
3924 EXPORT_C void RThread::Logon(TRequestStatus &aStatus) const
3926 Requests notification when this thread dies, normally or otherwise.
3928 A request for notification is an asynchronous request, and completes:
3930 - when the thread terminates
3931 - if the outstanding request is cancelled by a call to RThread::LogonCancel().
3933 A request for notification requires memory to be allocated; if this is
3934 unavailable, then the call to Logon() returns, and the asynchronous request
3935 completes immediately.
3937 Note that even when a thread has died, it is not possible to create a new thread with the same name
3938 until all handles on the dead thread have been closed. If this is attempted, the call to
3939 RThread::Create will fail with KErrAlreadyExists.
3941 @param aStatus A reference to the request status object.
3942 This contains the reason code describing the reason for
3943 the termination of the thread, i.e. the value returned by a call to RThread::ExitReason().
3944 Alternatively, this is set to:
3945 KErrCancel, if an outstanding request is cancelled;
3946 KErrNoMemory, if there is insufficient memory to deal with the request.
3948 @see RThread::LogonCancel()
3949 @see RThread::ExitReason()
3950 @see RThread::Create()
3954 aStatus=KRequestPending;
3955 Exec::ThreadLogon(iHandle,&aStatus,EFalse);
3961 EXPORT_C TInt RThread::LogonCancel(TRequestStatus &aStatus) const
3963 Cancels an outstanding request for notification of the death of this thread.
3965 A request for notification must previously have been made, otherwise
3966 the function returns KErrGeneral.
3968 The caller passes a reference to the same request status object as was passed
3969 in the original call to Logon().
3971 @param aStatus A reference to the same request status object used in
3972 the original call to Logon().
3974 @return KErrGeneral, if there is no outstanding request, KErrNone otherwise.
3977 return Exec::ThreadLogonCancel(iHandle,&aStatus,EFalse);
3984 Creates a Rendezvous request with the thread.
3986 The request is an asynchronous request, and completes:
3988 - when the thread next calls RThread::Rendezvous(TInt aReason)
3989 - if the outstanding request is cancelled by a call to RThread::RendezvousCancel()
3990 - if the thread exits
3991 - if the thread panics.
3993 Note that a request requires memory to be allocated; if this is unavailable,
3994 then this call to Rendezvous() returns, and the asynchronous request
3995 completes immediately.
3997 @param aStatus A reference to the request status object.
3998 The Rendezvous completes normally when
3999 RThread::Rendezvous(TInt aReason) is called, and this
4000 request status object will contain this reason code.
4001 If the thread exits or panics, then this is the thread exit
4002 reason value, i.e. the same value returned by RThread::ExitReason().
4003 Alternatively, this is set to:
4004 KErrCancel, if an outstanding request is cancelled;
4005 KErrNoMemory, if there is insufficient memory to deal with the request.
4007 @see RThread::Rendezvous(TInt aReason)
4008 @see RThread::RendezvousCancel(TRequestStatus& aStatus)
4010 EXPORT_C void RThread::Rendezvous(TRequestStatus& aStatus) const
4013 aStatus=KRequestPending;
4014 Exec::ThreadLogon(iHandle,&aStatus,ETrue);
4021 Cancels a previously requested Rendezvous with the thread
4023 The request completes with the value KErrCancel (if it was still outstanding).
4025 @param aStatus A reference to the same request status object used in
4026 the original call to Rendezvous(TRequestStatus& aStatus).
4028 @return KErrGeneral, if there is no outstanding request, KErrNone otherwise.
4030 @see RThread::Rendezvous(TRequestStatus& aStatus)
4032 EXPORT_C TInt RThread::RendezvousCancel(TRequestStatus& aStatus) const
4034 return Exec::ThreadLogonCancel(iHandle,&aStatus,ETrue);
4041 Completes all Rendezvous' with the current thread.
4043 @param aReason The reason code used to complete all rendezvous requests
4045 @see RThread::Rendezvous(TRequestStatus& aStatus)
4047 EXPORT_C void RThread::Rendezvous(TInt aReason)
4049 Exec::ThreadRendezvous(aReason);
4055 EXPORT_C TBusLocalDrive::TBusLocalDrive()
4059 : iStatus(KErrNotReady)
4065 EXPORT_C TInt TBusLocalDrive::Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt aOffset,TInt aFlags)
4067 // Read from the connected drive, and pass flags to driver
4070 return RLocalDrive::Read(aPos,aLength,aTrg,aThreadHandle,aOffset,aFlags);
4076 EXPORT_C TInt TBusLocalDrive::Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt anOffset)
4078 // Read from the connected drive.
4082 return RLocalDrive::Read(aPos,aLength,aTrg,aThreadHandle,anOffset);
4088 EXPORT_C TInt TBusLocalDrive::Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt aOffset,TInt aFlags)
4090 // Write to the connected drive and pass flags to driver
4094 return RLocalDrive::Write(aPos,aLength,aSrc,aThreadHandle,aOffset,aFlags);
4100 EXPORT_C TInt TBusLocalDrive::Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt anOffset)
4102 // Write to the connected drive.
4106 return RLocalDrive::Write(aPos,aLength,aSrc,aThreadHandle,anOffset);
4112 EXPORT_C TInt TBusLocalDrive::Read(TInt64 aPos,TInt aLength,TDes8& aTrg)
4114 // Read from the connected drive.
4118 return RLocalDrive::Read(aPos,aLength,aTrg);
4124 EXPORT_C TInt TBusLocalDrive::Write(TInt64 aPos,const TDesC8& aSrc)
4126 // Write to the connected drive.
4130 return RLocalDrive::Write(aPos,aSrc);
4136 EXPORT_C TInt TBusLocalDrive::Caps(TDes8& anInfo)
4138 // Get the connected drive's capabilities info.
4142 return RLocalDrive::Caps(anInfo);
4148 const TInt KDefaultMaxBytesPerFormat=0x00004000;// 16K
4149 const TInt KFormatSectorSize=0x00000200; // 512
4150 const TInt KFormatSectorShift=9;
4152 EXPORT_C TInt TBusLocalDrive::Format(TFormatInfo &anInfo)
4154 // Format the connected drive.
4157 if (anInfo.i512ByteSectorsFormatted<0)
4158 return KErrArgument;
4159 if (!anInfo.iFormatIsCurrent)
4161 anInfo.iFormatIsCurrent=ETrue;
4162 anInfo.i512ByteSectorsFormatted=0;
4163 anInfo.iMaxBytesPerFormat=KDefaultMaxBytesPerFormat;
4165 // Get the capabilities of the drive. If extra info is supported,
4166 // Then overrise the default KMaxBytesPerFormat
4167 TLocalDriveCapsV3Buf caps;
4169 anInfo.iMaxBytesPerFormat = caps().iMaxBytesPerFormat ? caps().iMaxBytesPerFormat : KDefaultMaxBytesPerFormat;
4171 TInt64 pos=TInt64(anInfo.i512ByteSectorsFormatted)<<KFormatSectorShift;
4172 TInt length=anInfo.iMaxBytesPerFormat;
4173 TInt r=RLocalDrive::Format(pos,length);
4175 // A positive return code specifies that the format step
4176 // has been adjusted (possibly to account for the partition offset)
4185 length+=KFormatSectorSize-1;
4186 length>>=KFormatSectorShift;
4187 anInfo.i512ByteSectorsFormatted+=length;
4191 anInfo.iFormatIsCurrent=EFalse;
4199 EXPORT_C TInt TBusLocalDrive::Format(TInt64 aPos, TInt aLength)
4201 // Format the connected drive.
4208 if((r = RLocalDrive::Format(aPos, aLength)) > 0)
4223 EXPORT_C TInt TBusLocalDrive::ControlIO(TInt aCommand, TAny* aParam1, TAny* aParam2)
4226 // NB: If in a data-paging environment and this drive is the data-paging drive, this API will
4227 // return KErrNotSupported if either aParam1 or aParam2 are non-NULL to avoid the possibility
4228 // of taking a data paging fault in the media driver's thread.
4229 // For this reason, this function has been deprecated
4231 // @deprecated Callers of this function should use one of the other overloads
4234 return(RLocalDrive::ControlIO(aCommand,aParam1,aParam2));
4238 EXPORT_C TInt TBusLocalDrive::ControlIO(TInt aCommand, TDes8& aBuf, TInt aParam)
4241 // In a data-paging environment, this API allows the passed descriptor to be pinned in the context
4242 // of the client's thread to avoid taking a data paging fault in the media driver's thread
4245 if (aBuf.MaxLength() == 0)
4246 return KErrArgument;
4247 return(RLocalDrive::ControlIO(aCommand, aBuf, aParam));
4251 EXPORT_C TInt TBusLocalDrive::ControlIO(TInt aCommand, TDesC8& aBuf, TInt aParam)
4254 // In a data-paging environment, this API allows the passed descriptor to be pinned in the context
4255 // of the client's thread to avoid taking a data paging fault in the media driver's thread
4258 if (aBuf.Length() == 0)
4259 return KErrArgument;
4260 return(RLocalDrive::ControlIO(aCommand, aBuf, aParam));
4263 EXPORT_C TInt TBusLocalDrive::ControlIO(TInt aCommand, TInt aParam1, TInt aParam2)
4265 return(RLocalDrive::ControlIO(aCommand, aParam1, aParam2));
4270 EXPORT_C TInt TBusLocalDrive::SetMountInfo(const TDesC8* aMountInfo,TInt aMessageHandle)
4272 // Set the mount information on the local drive
4276 return RLocalDrive::SetMountInfo(aMountInfo,aMessageHandle);
4282 EXPORT_C TInt TBusLocalDrive::ForceRemount(TUint aFlags)
4284 // Force a remount on the local drive
4288 TInt err = RLocalDrive::ForceMediaChange(aFlags);
4292 if(aFlags & ELocDrvRemountForceMediaChange)
4301 EXPORT_C TInt TBusLocalDrive::GetLastErrorInfo(TDes8& aErrorInfo)
4303 // Get information on the local drives last error
4307 return RLocalDrive::GetLastErrorInfo(aErrorInfo);
4313 EXPORT_C TLocalDriveCaps::TLocalDriveCaps()
4318 iType(EMediaNotPresent),
4319 iConnectionBusType(EConnectionBusInternal),
4332 EXPORT_C TInt TBusLocalDrive::Connect(TInt aDriveNumber,TBool &aChangedFlag)
4334 // Connect to the drive.
4338 return RLocalDrive::Connect(aDriveNumber, aChangedFlag);
4344 EXPORT_C void TBusLocalDrive::Disconnect()
4346 // Disconnect from the drive.
4356 EXPORT_C TInt TBusLocalDrive::Enlarge(TInt aLength)
4358 // Increase the size of the connected drive by the specified length (in bytes).
4362 return RLocalDrive::Enlarge(aLength);
4368 EXPORT_C TInt TBusLocalDrive::ReduceSize(TInt aPos,TInt aLength)
4370 // Reduce the size of the connected drive by removing the specified length
4371 // (in bytes) starting at the specified position.
4375 return RLocalDrive::Reduce(aPos, aLength);
4382 Attempt to unlock a password-enabled drive and optionally store the password in the password store.
4384 @param aPassword A descriptor containing the password data.
4385 @param aStorePassword If ETrue, the password is added to the password store.
4387 @return KErrNone, if successful.
4388 KErrAlreadyExists, if the drive is already unlocked.
4389 KErrAccessDenied, if the drive unlock operation fails.
4391 @see TBusLocalDrive::SetPassword
4392 @see TBusLocalDrive::Clear
4393 @see TBusLocalDrive::ErasePassword
4395 EXPORT_C TInt TBusLocalDrive::Unlock(const TDesC8& aPassword, TBool aStorePassword)
4397 TInt err = CheckMount();
4398 if (err != KErrNone)
4401 if (!(Status() & KMediaAttLocked))
4402 return KErrAlreadyExists;
4404 err = RLocalDrive::Unlock(aPassword, aStorePassword);
4406 if(err == KErrLocked)
4407 err = KErrAccessDenied;
4416 Attempt to lock password-enabled drive and optionally store the new password in the password store.
4418 @param aOldPassword A descriptor containing old password.
4419 @param aNewPassword A descriptor containing new password.
4420 @param aStorePassword If ETrue, the password is added to the password store.
4422 @return KErrNone, if successful.
4423 KErrAccessDenied, if the drive is already locked or the old password is incorrect.
4425 @see TBusLocalDrive::Unlock
4426 @see TBusLocalDrive::Clear
4427 @see TBusLocalDrive::ErasePassword
4429 EXPORT_C TInt TBusLocalDrive::SetPassword(const TDesC8& aOldPassword, const TDesC8& aNewPassword, TBool aStorePassword)
4431 TInt err = CheckMount();
4432 if (err != KErrNone)
4435 if (Status() & KMediaAttLocked)
4436 return KErrAccessDenied;
4438 err = RLocalDrive::SetPassword(aOldPassword, aNewPassword, aStorePassword);
4439 if(err == KErrLocked)
4440 err = KErrAccessDenied;
4449 Clears a password from a card - controller sets password to null.
4450 volume will not be password-enabled next time it is powered up.
4451 The password is cleared from the password store.
4453 @param aPassword A descriptor containing the password.
4455 @return KErrNone, if successful.
4456 KErrAccessDenied, if the drive is already locked or the password is incorrect.
4458 @see TBusLocalDrive::Unlock
4459 @see TBusLocalDrive::SetPassword
4460 @see TBusLocalDrive::ErasePassword
4462 EXPORT_C TInt TBusLocalDrive::Clear(const TDesC8& aPassword)
4464 TInt err = CheckMount();
4465 if (err != KErrNone)
4468 if (Status() & KMediaAttLocked)
4469 return KErrAccessDenied;
4471 err = RLocalDrive::Clear(aPassword);
4472 if(err == KErrLocked)
4473 err = KErrAccessDenied;
4482 Forcibly unlock a password-enabled drive.
4483 KErrAccessDenied is returned if the drive is already mounted (and therefore unlocked)
4484 or if the drive is not already mounted and the operation fails.
4486 @return KErrNone, if successful.
4487 KErrAccessDenied, if the drive is not locked or the operation is not supported.
4489 @see TBusLocalDrive::Unlock
4490 @see TBusLocalDrive::SetPassword
4491 @see TBusLocalDrive::ErasePassword
4493 EXPORT_C TInt TBusLocalDrive::ErasePassword()
4495 TInt err = CheckMount();
4496 if (err != KErrNone)
4499 if (!(Status() & KMediaAttLocked))
4500 return KErrAccessDenied;
4502 err = RLocalDrive::ErasePassword();
4504 err = KErrAccessDenied;
4512 TInt TBusLocalDrive::CheckMount()
4514 // Check the local drive can be, or is mounted
4517 TLocalDriveCaps caps;
4518 TPckg<TLocalDriveCaps> capsPckg(caps);
4519 TInt err = RLocalDrive::Caps(capsPckg);
4520 iStatus = caps.iMediaAtt;
4527 Write the password store to the peripheral bus controller.
4530 - KErrNone if Successful
4531 - KErrOverflow If aBuf is longer than TPasswordStore::EMaxPasswordLength
4532 - KErrCorrupt If store in aBuf is malformed.
4534 @param aBuf Data to replace the current password store.
4536 EXPORT_C TInt TBusLocalDrive::WritePasswordData(const TDesC8& aBuf)
4538 return RLocalDrive::WritePasswordData(aBuf);
4544 EXPORT_C TInt TBusLocalDrive::ReadPasswordData(TDes8& aBuf)
4546 // Read the entire password store from the peripheral bus controller.
4549 return RLocalDrive::ReadPasswordData(aBuf);
4555 EXPORT_C TInt TBusLocalDrive::PasswordStoreLengthInBytes()
4557 // Return the number of bytes used by peripheral bus controller password store.
4560 return RLocalDrive::PasswordStoreLengthInBytes();
4566 EXPORT_C TInt TBusLocalDrive::DeleteNotify(TInt64 aPos, TInt aLength)
4568 // Notify the media driver that an area of the partition has been deleted.
4569 // This is used by certain media (e.g NAND flash) for garbage collection.
4572 return RLocalDrive::DeleteNotify(aPos, aLength);
4577 Query a property of the media device
4582 EXPORT_C TInt TBusLocalDrive::QueryDevice(TQueryDevice aQueryDevice, TDes8 &aBuf)
4584 return RLocalDrive::QueryDevice(aQueryDevice, aBuf);
4588 EXPORT_C void User::__DbgMarkStart(TBool aKernel)
4590 Marks the start of heap cell checking for the current thread's default heap,
4591 or for the kernel heap.
4593 If earlier calls to __DbgMarkStart() have been made, then this
4594 call to __DbgMarkStart() marks the start of a new nested level of
4597 Every call to __DbgMarkStart() should be matched by a later call
4598 to __DbgMarkEnd() to verify that the number of heap cells allocated, at
4599 the current nested level, is as expected.
4600 This expected number of heap cells is passed to __DbgMarkEnd()
4601 as a parameter; however, the most common expected number is zero, reflecting
4602 the fact that the most common requirement is to check that all memory allocated
4603 since a previous call to __DbgStartCheck() has been freed.
4605 @param aKernel ETrue, if checking is being done for the kernel heap;
4606 EFalse, if checking is being done for the current thread's
4612 Exec::KernelHeapDebug(EDbgMarkStart,0,NULL);
4614 GetHeap()->__DbgMarkStart();
4620 EXPORT_C void User::__DbgMarkCheck(TBool aKernel, TBool aCountAll, TInt aCount, const TUint8* aFileName, TInt aLineNum)
4622 // Call CheckNum for the default heap
4625 Checks the current number of allocated heap cells for the current thread's default
4626 heap, or the kernel heap.
4628 If aCountAll is true, the function checks that the total number of
4629 allocated cells on the heap is the same as aCount. If aCountAll is false,
4630 the function checks that the number of allocated cells at the current nested
4631 level is the same as aCount.
4633 If checking fails, the function raises a panic. Information about the failure
4634 is put into the panic category, which takes the form:
4636 ALLOC COUNT\\rExpected aaa\\rAllocated bbb\\rLn: ccc ddd
4638 Where aaa is the value aCount, bbb is the number of allocated heap cells,
4639 ccc is a line number, copied from aLineNum, and ddd is a file name, copied
4640 from the descriptor aFileName.
4642 Note that the panic number is 1.
4644 @param aKernel ETrue, if checking is being done for the kernel heap;
4645 EFalse, if checking is being done for the current thread's
4647 @param aCountAll If true, the function checks that the total number of
4648 allocated cells on the heap is the same as aCount.
4649 If false, the function checks that the number of allocated
4650 cells at the current nested level is the same as aCount.
4651 @param aCount The expected number of allocated cells.
4652 @param aFileName A filename; this is displayed as part of the panic category,
4654 @param aLineNum A line number; this is displayed as part of the panic category,
4660 GetHeap()->__DbgMarkCheck(aCountAll,aCount,aFileName,aLineNum);
4663 TPtrC8 filename(aFileName);
4664 TKernelHeapMarkCheckInfo info;
4665 info.iCountAll=aCountAll;
4666 info.iFileName=&filename;
4667 info.iLineNum=aLineNum;
4668 Exec::KernelHeapDebug(EDbgMarkCheck,aCount,&info);
4675 EXPORT_C TUint32 User::__DbgMarkEnd(TBool aKernel, TInt aCount)
4677 // Call CheckHeap for the default heap
4680 Marks the end of heap cell checking at the current nested level for the current
4681 thread's default heap, or the kernel heap.
4683 The function checks that the number of heap cells allocated, at the current
4684 nested level, is aCount. The most common value for aCount is zero, reflecting
4685 the fact that the most common requirement is to check that all memory allocated
4686 since a previous call to __DbgStartCheck() has been freed.
4688 A call to this function should match an earlier call to __DbgMarkStart().
4689 If there are more calls to this function than calls to __DbgMarkStart(), then
4690 this function raises a USER 51 panic.
4692 If the check fails for a user heap, the function raises an ALLOC: nnnnnnnn
4693 panic, where nnnnnnnn is a hexadecimal pointer to the first orphaned heap
4696 If the check fails for the kernel heap, the kernel server raises a KERN-EXEC 17
4699 @param aKernel ETrue, if checking is being done for the kernel heap;
4700 EFalse, if checking is being done for the current thread's
4702 @param aCount The number of allocated heap cells expected.
4704 @return Zero always.
4710 TUint32 badCell=GetHeap()->__DbgMarkEnd(aCount);
4713 TBuf<0x10> info=_L("ALLOC: ");
4714 info.AppendFormat(_L("%x\n"), badCell);
4715 User::Panic(info,0);
4720 Exec::KernelHeapDebug(EDbgMarkEnd,aCount,NULL);
4727 EXPORT_C void User::__DbgSetAllocFail(TBool aKernel, RAllocator::TAllocFail aType, TInt aRate)
4729 // Set the failure rate for allocating from the default user heap
4732 Simulates a heap allocation failure for the current thread's default heap,
4735 The failure occurs on subsequent calls to new or any of the functions which
4736 allocate memory from the heap.
4738 The timing of the allocation failure depends on the type of allocation failure
4739 requested, i.e. on the value of aType.
4741 The simulation of heap allocation failure is cancelled if aType is given
4742 the value RAllocator::ENone.
4746 1. If the failure type is RHeap::EFailNext, the next attempt to allocate from
4747 the heap fails; however, no further failures will occur.
4749 2. For failure types RHeap::EFailNext and RHeap::ENone, set aRate to 1.
4751 @param aKernel ETrue, if checking is being done for the kernel heap;
4752 EFalse, if checking is being done for the current thread's
4754 @param aType An enumeration which indicates how to simulate heap
4756 @param aRate The rate of failure; when aType is RAllocator::EDeterministic,
4757 heap allocation fails every aRate attempts.
4762 Exec::KernelHeapDebug(EDbgSetAllocFail,aType,(TAny*)aRate);
4764 GetHeap()->__DbgSetAllocFail(aType,aRate);
4768 Simulates a heap allocation failure for the current thread's default heap,
4771 The aBurst failures will occur after subsequent calls to new or any of the
4772 functions which allocate memory from the heap.
4774 The timing of the allocation failures will depend on the type of allocation failure
4775 requested, i.e. on the value of aType.
4777 The simulation of heap allocation failure is cancelled if aType is given
4778 the value RAllocator::ENone.
4781 @param aKernel ETrue, if checking is being done for the kernel heap;
4782 EFalse, if checking is being done for the current thread's
4784 @param aType An enumeration which indicates how to simulate heap
4786 @param aRate The rate of failure; when aType is RAllocator::EDeterministic,
4787 heap allocation fails every aRate attempts.
4788 @param aBurst The number of consecutive allocations that should fail.
4791 EXPORT_C void User::__DbgSetBurstAllocFail(TBool aKernel, RAllocator::TAllocFail aType, TUint aRate, TUint aBurst)
4795 SRAllocatorBurstFail burstFail;
4796 burstFail.iRate = aRate;
4797 burstFail.iBurst = aBurst;
4798 Exec::KernelHeapDebug(EDbgSetBurstAllocFail, aType, (TAny*)&burstFail);
4801 GetHeap()->__DbgSetBurstAllocFail(aType, aRate, aBurst);
4806 Returns the number of heap allocation failures the current debug allocator fail
4807 function has caused so far.
4809 This is intended to only be used with fail types RAllocator::EFailNext,
4810 RAllocator::EBurstFailNext, RAllocator::EDeterministic and
4811 RAllocator::EBurstDeterministic. The return value is unreliable for
4812 all other fail types.
4814 @return The number of heap allocation failures the current debug fail
4815 function has caused.
4817 @see RAllocator::TAllocFail
4819 EXPORT_C TUint User::__DbgCheckFailure(TBool aKernel)
4823 Exec::KernelHeapDebug(EDbgCheckFailure, 0, (TAny*)&r);
4825 r = GetHeap()->__DbgCheckFailure();
4829 EXPORT_C TInt RProcess::Create(const TDesC &aFileName,const TDesC &aCommand,TOwnerType aType)
4831 Starts a new process, loading the specified executable.
4833 The executable can be in ROM or RAM.
4835 By default, ownership of this process handle is vested in the current process,
4836 but can be vested in the current thread by specifying EOwnerThread as the
4837 third parameter to this function.
4839 @param aFileName A descriptor containing the full path name of the executable
4840 to be loaded. If this name has no file extension,
4841 an extension of .EXE is appended. The length of the resulting
4842 full path name must not be greater than KMaxFileName.
4843 The length of the file name itself must not be greater
4844 than KMaxProcessName. If no path is specified, the system will
4845 look in \\sys\\bin on all drives.
4846 @param aCommand A descriptor containing data passed as an argument to
4847 the thread function of the new process's main thread,
4848 when it is first scheduled.
4849 @param aType Defines the ownership of this process handle. If not
4850 specified, EOwnerProcess is the default.
4852 @return KErrNone if successful, otherwise one of the other system-wide error codes.
4856 return Create(aFileName, aCommand, TUidType(), aType);
4862 EXPORT_C TInt RProcess::Create(const TDesC &aFileName,const TDesC &aCommand,const TUidType &aUidType, TOwnerType aType)
4864 Starts a new process, loading the specified executable which matches
4865 the specified UID type.
4867 The executable can be in ROM or RAM.
4869 By default, ownership of this process handle is vested in the current process,
4870 but can be vested in the current thread by specifying EOwnerThread as the
4873 @param aFileName A descriptor containing the full path name of the executable
4874 to be loaded. If this name has no file extension,
4875 an extension of .EXE is appended. The length of the resulting
4876 full path name must not be greater than KMaxFileName.
4877 The length of the file name itself must not be greater
4878 than KMaxProcessName. If no path is specified, the system will
4879 look in \\sys\\bin on all drives.
4880 @param aCommand A descriptor containing data passed as an argument to
4881 the thread function of the new process's main thread,
4882 when it is first scheduled.
4883 @param aUidType A UID type (a triplet of UIDs) which the executable must match.
4884 @param aType Defines the ownership of this process handle. If not specified,
4885 EOwnerProcess is the default.
4887 @return KErrNone if successful, otherwise one of the other system-wide error
4893 TInt r=loader.Connect();
4895 r=loader.LoadProcess(iHandle,aFileName,aCommand,aUidType,aType);
4901 EXPORT_C TInt RProcess::CreateWithStackOverride(const TDesC& aFileName,const TDesC& aCommand, const TUidType &aUidType, TInt aMinStackSize, TOwnerType aType)
4903 Starts a new process, loading the specified executable which matches
4904 the specified UID type and the minimum stack size is the specified value.
4906 The executable can be in ROM or RAM.
4908 By default, ownership of this process handle is vested in the current process,
4909 but can be vested in the current thread by specifying EOwnerThread as the
4913 @param aFileName A descriptor containing the full path name of the executable
4914 to be loaded. If this name has no file extension,
4915 an extension of .EXE is appended. The length of the resulting
4916 full path name must not be greater than KMaxFileName.
4917 The length of the file name itself must not be greater
4918 than KMaxProcessName. If no path is specified, the system will
4919 look in \\sys\\bin on all drives.
4920 @param aCommand A descriptor containing data passed as an argument to
4921 the thread function of the new process's main thread,
4922 when it is first scheduled.
4923 @param aUidType A UID type (a triplet of UIDs) which the executable must match.
4924 @param aMinStackSize Minimum stack size of the new process. If this is less than
4925 than the stack size set in the image header of the executable,
4926 the minimum stack size will be set to the image header stack
4928 @param aType Defines the ownership of this process handle. If not specified,
4929 EOwnerProcess is the default.
4931 @return KErrNone if successful, otherwise one of the other system-wide error
4937 TInt r=loader.Connect();
4940 r=loader.LoadProcess(iHandle,aFileName,aCommand,aUidType,aMinStackSize,aType);
4948 EXPORT_C TInt User::LoadLogicalDevice(const TDesC &aFileName)
4950 Loads the logical device driver (LDD) DLL with the specified filename.
4952 The function searches the system path for the LDD DLL, and loads it. It then
4953 makes a kernel server call that:
4955 1. creates the LDD factory object, an instance of a DLogicalDevice derived
4956 class; this involves checking the first UID value to make sure that the DLL
4957 is a valid LDD before proceeding to call the exported function at
4958 ordinal 1, which creates the LDD factory object on the kernel heap
4960 2. calls the LDD factory object's Install() function to complete the installation
4962 3. adds the new LDD factory object to the kernel's list of LDD factory objects.
4964 @param aFileName A reference to the descriptor containing the name of the
4965 physical device driver DLL. If the filename has no extension,
4966 .LDD is assumed by default.
4968 @return KErrNone if successful or one of the system-wide error codes.
4972 return loader.LoadDeviceDriver(aFileName, 0);
4978 EXPORT_C TInt User::FreeLogicalDevice(const TDesC &aDeviceName)
4980 Frees the logical device driver DLL associated with a specified driver name.
4982 @param aDeviceName The name of the logical device driver object. This must
4983 match the name set during installation of the logical
4984 device. Typically, this is done in an implementation
4985 of DLogicalDevice::Install() through a call to SetName().
4986 Note that the name is rarely the same as the device's
4987 filename. The name of a logical device driver object
4988 can be discovered by using TFindLogicalDevice.
4990 @return KErrNone if successful or one of the system-wide error codes. KErrNone
4991 will be returned if the device is not found as it may have already been
4995 TBuf8<KMaxFullName> aDeviceName8;
4996 aDeviceName8.Copy(aDeviceName);
4997 return Exec::DeviceFree(aDeviceName8,0);
5003 EXPORT_C TInt User::LoadPhysicalDevice(const TDesC &aFileName)
5005 Loads the physical device driver (PDD) DLL with the specified filename.
5007 The function searches the system path for the PDD DLL, and loads it. It then
5008 makes a kernel server call that:
5010 1. creates the PDD factory object, an instance of a DPhysicalDevice derived class;
5011 this involves checking the first UID value to make sure that the DLL is a
5012 valid PDD before proceeding to call the exported function at ordinal 1, which
5013 creates the PDD factory object on the kernel heap
5015 2. calls the PDD factory object's Install() function to complete the installation
5017 2. adds the new PDD factory object to the kernel's list of PDD factory objects.
5019 @param aFileName A reference to the descriptor containing the name of the
5020 physical device driver DLL. If the filename has no extension,
5021 .PDD is assumed by default.
5023 @return KErrNone if successful or one of the system-wide error codes.
5027 return loader.LoadDeviceDriver(aFileName, 1);
5034 Frees the physical device driver DLL associated with a specified driver name.
5036 @param aDeviceName The name of the physical device driver object. This must
5037 match the name set during installation of the physical
5038 device. Typically, this is done in an implementation of
5039 DPhysicalDevice::Install() through a call to SetName().
5040 Note that the name is rarely the same as the device's
5041 filename. The name of a physical device driver object can
5042 be discovered by using TFindPhysicalDevice.
5044 @return KErrNone if successful or one of the system-wide error codes. KErrNone
5045 will be returned if the device is not found as it may have already
5048 EXPORT_C TInt User::FreePhysicalDevice(const TDesC &aDeviceName)
5051 TBuf8<KMaxFullName> aDeviceName8;
5052 aDeviceName8.Copy(aDeviceName);
5053 return Exec::DeviceFree(aDeviceName8,1);
5059 EXPORT_C TInt RLoader::Connect()
5061 // Connect with the loader.
5064 _LIT(KLoaderServerName,"!Loader");
5065 return CreateSession(KLoaderServerName,Version(),0);
5068 TVersion RLoader::Version() const
5070 // Return the client side version number.
5074 return TVersion(KLoaderMajorVersionNumber,KLoaderMinorVersionNumber,KE32BuildVersionNumber);
5077 TInt RLoader::LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TOwnerType aType)
5079 // Execute another process.
5083 return (LoadProcess(aHandle, aFileName, aCommand, aUidType, KDefaultStackSize, aType));
5089 Execute another process.
5095 @param aMinStackSize
5099 KErrNone if process created
5100 KErrBadName if aFileName.Length() > KMaxFileName
5101 KErrArgument if aMinStackSize < 0
5104 TInt RLoader::LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TInt aMinStackSize, TOwnerType aType)
5107 __IF_DEBUG(Print(_L("RLoader::LoadProcess started with %d bytes stack.\n"), aMinStackSize));
5109 if( 0 > aMinStackSize )
5110 return KErrArgument;
5113 info.iRequestedUids=aUidType; // match these uids only
5114 info.iOwnerType=aType;
5116 info.iMinStackSize=aMinStackSize;
5118 if (aFileName.Length()>KMaxFileName)
5121 TPckg<TLdrInfo> infoBuf(info);
5123 TInt r = SendReceive(ELoadProcess, TIpcArgs((TDes8*)&infoBuf, (const TDesC*)&aFileName, (const TDesC*)&aCommand) );
5124 aHandle = info.iHandle;
5125 __IF_DEBUG(Print(_L("LoadProcess returning %d"),r));
5130 Check if the hash for the given library exists and optionally validate it.
5132 @param aFileName the same as for RLoader::LoadLibrary
5133 @param aValidateHash if ETrue this function will validate library hash if it exists. Requires fully specified aFileName.
5136 KErrNotSupported this feature is not supported by the emulator
5137 KErrNone if aValidateHash=EFalse, it means that the hash exists; if aValidateHash=ETrue, hash exists and valid,
5138 KErrCorrupt if aValidateHash=ETrue, the library hash exists but NOT valid,
5139 KErrNotFound no hash found
5140 KErrArgument bad file name
5143 EXPORT_C TInt RLoader::CheckLibraryHash(const TDesC& aFileName, TBool aValidateHash/*=EFalse*/)
5145 __IF_DEBUG(Print(_L("RLoader::CheckLibraryHash")));
5148 TPckg<TLdrInfo> infoBuf(info);
5149 info.iOwnerType=EOwnerThread;
5151 TInt r = SendReceive(ECheckLibraryHash, TIpcArgs((TDes8*)&infoBuf, (const TDesC*)&aFileName, aValidateHash) );
5156 EXPORT_C TInt RLoader::LoadLibrary(TInt& aHandle, const TDesC& aFileName, const TDesC& aPath, const TUidType& aUidType, TUint32 aModuleVersion)
5162 __IF_DEBUG(Print(_L("RLoader::LoadLibrary")));
5164 TPckg<TLdrInfo> infoBuf(info);
5165 info.iRequestedUids=aUidType; // match these uids only
5166 info.iOwnerType=EOwnerThread;
5167 info.iRequestedVersion=aModuleVersion;
5168 if (aFileName.Length()>KMaxFileName)
5172 TInt r=E32Loader::WaitDllLock();
5175 r = SendReceive(ELoadLibrary, TIpcArgs((TDes8*)&infoBuf, (const TDesC*)&aFileName, (const TDesC*)&aPath) );
5176 aHandle=info.iHandle;
5178 E32Loader::ReleaseDllLock();
5180 __IF_DEBUG(Print(_L("LoadLibrary returning %d"),r));
5185 EXPORT_C TInt RLoader::GetInfo(const TDesC& aFileName, TDes8& aInfoBuf)
5187 // Get capabilities of a DLL
5190 __IF_DEBUG(Print(_L("RLoader::GetInfo")));
5192 TPckg<TLdrInfo> infoBuf(info);
5193 info.iOwnerType=EOwnerThread;
5194 if (aFileName.Length()>KMaxFileName)
5196 TInt r = SendReceive(EGetInfo, TIpcArgs((TDes8*)&infoBuf, (const TDesC*)&aFileName, (TDes8*)&aInfoBuf) );
5197 __IF_DEBUG(Print(_L("GetInfo returning %d"),r));
5202 EXPORT_C TInt RLoader::Delete(const TDesC& aFileName)
5204 Ask the loader to delete a file. This function should be used instead
5205 of RFs::Delete where the supplied file may be a paged executable, although
5206 it can be used for any file. A file that is currently paged may be moved
5207 by the system, and deleted later, when the file is no longer needed. This means
5208 that using this function may not immediately release the disk space associated
5211 @param aFileName Fully-qualified filename.
5212 @return Symbian OS error code. Additionally, KErrBadName is
5213 returned if the supplied filename is not fully qualified..
5215 @capability AllFiles
5218 __IF_DEBUG(Printf(">RLoader::Delete,%S", &aFileName));
5219 TInt r = SendReceive(ELdrDelete, TIpcArgs(0, &aFileName));
5220 __IF_DEBUG(Printf("<RLoader::Delete,%d", r));
5226 #include <emulator.h>
5228 TInt RLoader::GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf)
5230 __IF_DEBUG(Print(_L("RLoader::GetInfoFromHeader")));
5234 Emulator::TModule module;
5235 module.iBase = aHeader.Ptr();
5236 TProcessCreateInfo info;
5237 module.GetInfo(info);
5239 RLibrary::TInfoV2 ret_info;
5240 memclr(&ret_info,sizeof(ret_info));
5241 ret_info.iModuleVersion = info.iModuleVersion;
5242 ret_info.iUids = info.iUids;
5243 *(SSecurityInfo*)&ret_info.iSecurityInfo = info.iS;
5244 ret_info.iHardwareFloatingPoint = EFpTypeNone;
5245 TPckg<RLibrary::TInfoV2> ret_pckg(ret_info);
5246 if (aInfoBuf.MaxLength() < ret_pckg.Length())
5247 ret_pckg.SetLength(aInfoBuf.MaxLength());
5250 __IF_DEBUG(Print(_L("GetInfoFromHeader returning %d"),r));
5254 #else // not __WINS__ ...
5256 TInt RLoader::GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf)
5258 __IF_DEBUG(Print(_L("RLoader::GetInfoFromHeader")));
5259 TInt r = SendReceive(EGetInfoFromHeader, TIpcArgs(&aHeader, &aInfoBuf) );
5260 __IF_DEBUG(Print(_L("GetInfoFromHeader returning %d"),r));
5266 TInt RLoader::LoadDeviceDriver(const TDesC& aFileName, TInt aDeviceType)
5271 TInt m = aDeviceType ? ELoadPhysicalDevice : ELoadLogicalDevice;
5272 r = SendReceive(m, TIpcArgs(0, (const TDesC*)&aFileName, 0) );
5278 TInt RLoader::LoadLocale(const TDesC& aLocaleDllName, TLibraryFunction* aExportList)
5283 TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
5284 TPtr8 functionListBuf((TUint8*)aExportList, size, size);
5285 r = SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aLocaleDllName, &functionListBuf) );
5291 EXPORT_C TInt RLoader::DebugFunction(TInt aFunction, TInt a1, TInt a2, TInt a3)
5293 return SendReceive(ELoaderDebugFunction, TIpcArgs(aFunction, a1, a2, a3) );
5296 EXPORT_C TInt RLoader::CancelLazyDllUnload()
5298 return SendReceive(ELoaderCancelLazyDllUnload, TIpcArgs() );
5301 #ifdef __USERSIDE_THREAD_DATA__
5303 EXPORT_C TInt UserSvr::DllSetTls(TInt aHandle, TAny* aPtr)
5305 // Set the value of the Thread Local Storage variable.
5308 return LocalThreadData()->DllSetTls(aHandle, KDllUid_Default, aPtr);
5311 EXPORT_C TInt UserSvr::DllSetTls(TInt aHandle, TInt aDllUid, TAny* aPtr)
5313 // Set the value of the Thread Local Storage variable.
5316 return LocalThreadData()->DllSetTls(aHandle, aDllUid, aPtr);
5319 EXPORT_C void UserSvr::DllFreeTls(TInt aHandle)
5321 // Remove the Thread Local Storage variable.
5324 return LocalThreadData()->DllFreeTls(aHandle);
5329 EXPORT_C TInt UserSvr::DllSetTls(TInt aHandle, TAny* aPtr)
5331 // Set the value of the Thread Local Storage variable.
5334 return Exec::DllSetTls(aHandle, KDllUid_Default, aPtr);
5337 EXPORT_C TInt UserSvr::DllSetTls(TInt aHandle, TInt aDllUid, TAny* aPtr)
5339 // Set the value of the Thread Local Storage variable.
5342 return Exec::DllSetTls(aHandle, aDllUid, aPtr);
5345 EXPORT_C void UserSvr::DllFreeTls(TInt aHandle)
5347 // Remove the Thread Local Storage variable.
5350 Exec::DllFreeTls(aHandle);
5358 EXPORT_C TInt RChangeNotifier::Create()
5360 Creates a change notifier, and opens this handle to that change notifier.
5362 Ownership of this change notifier is vested in the current process.
5364 @return KErrNone if successful, otherwise one of the other system-wide error codes.
5367 return SetReturnedHandle(Exec::ChangeNotifierCreate(EOwnerProcess),*this);
5373 EXPORT_C TInt RUndertaker::Create()
5375 Creates a thread-death notifier, and opens this handle to
5376 that thread-death notifier.
5378 Ownership of this thread-death notifier is vested in the current process.
5380 @return KErrNone, if successful; otherwise one of
5381 the other system-wide error codes.
5384 return SetReturnedHandle(Exec::UndertakerCreate(EOwnerProcess),*this);
5390 EXPORT_C TInt RUndertaker::Logon(TRequestStatus& aStatus, TInt& aThreadHandle) const
5392 Issues a request for notification of the death of a thread.
5394 When another thread dies, the request completes and the TRequestStatus object
5395 contains the value KErrDied; in addition, aThreadHandle contains
5396 the handle-number of the dying thread.
5398 The requesting thread can construct a proper handle for the dying thread
5404 r.SetHandle(aThreadHandle);
5409 Alternatively, if an outstanding request is cancelled by a call
5410 to LogonCancel(), then the request completes with the value KErrCancel.
5412 Note that if a request completes normally, i.e. not as a result of
5413 a LogonCancel(), then the handle to the dying thread must be closed
5414 when there is no further interest in it.
5416 @param aStatus A reference to the request status object.
5417 @param aThreadHandle The handle-number representing the dying thread.
5419 @return KErrInUse if there is an outstanding request; KErrNone otherwise.
5421 @see RUndertaker::LogonCancel()
5424 aStatus=KRequestPending;
5425 return Exec::UndertakerLogon(iHandle,aStatus,aThreadHandle);
5431 EXPORT_C TInt RUndertaker::LogonCancel() const
5433 Cancels an outstanding notification request to the thread-death notifier.
5435 @return KErrGeneral, if there is no outstanding notification request; KErrNone otherwise.
5437 @see RUndertaker::Logon()
5440 return Exec::UndertakerLogonCancel(iHandle);
5447 Sets the machine configuration.
5449 @param aConfig Descriptor containing the machine configuration data
5451 @return KErrNone, if sucessful, otherwise one of the other system-wide
5454 @capability WriteDeviceData
5456 EXPORT_C TInt User::SetMachineConfiguration(const TDesC8& aConfig)
5458 return Exec::SetMachineConfiguration(aConfig);
5464 EXPORT_C TInt User::CompressAllHeaps()
5466 Compresses all the chunks containing heaps.
5468 @deprecated This function is no longer supported, and calling it has no effect.
5474 return KErrNone; // don't do this any more
5480 EXPORT_C TInt UserSvr::ChangeLocale(const TDesC& aLocaleDllName)
5482 if(aLocaleDllName.Length() == 0)
5484 //support reverting to defaults
5485 TInt r = UserSvr::LocalePropertiesSetDefaults();
5487 Exec::SetUTCTimeAndOffset(0,0,ETimeSetOffset,EChangesLocale);
5490 TExtendedLocale locale;
5491 TInt r = locale.LoadLocale(aLocaleDllName);
5494 r = locale.SaveSystemSettings();
5499 EXPORT_C TInt UserSvr::ResetMachine(TMachineStartupType aType)
5501 // Reset the machine. Currently only aType==EStartupWarmReset is supported.
5505 return Exec::ResetMachine(aType);