First public contribution.
2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
26 #include <sys/select.h>
28 #include <sys/types.h>
30 #include "ipcclient.h"
32 #include <sys/socket.h>
33 #include <stdapis/net/if.h>
35 #include <commdbconnpref.h>
39 #include <e32atomics.h>
41 #ifdef SYMBIAN_OE_POSIX_SIGNALS
42 #include "signalclient.h"
43 #include "tsignalmessage.h"
45 typedef void (*TSignalHandler)(int);
46 typedef void (*TSignalAction)(int, siginfo_t *, void *);
52 _LIT(KEstlibInit, "STDLIBS-INIT");
54 _LIT(KFDTransferSvr,"FDTrnsfrSvr");
55 //Forward declaration for references below
57 class CFileDesTransferServer;
58 class RFileDesTransferSession;
60 /* TODO: We don't have to do this in CFileTable. Move to methods */
61 class CFileSocketDesc;
73 // The underlying data for a TProcessId is a TUint64. GCC raises an error if this is intialised to a negative value. Consider changing for all platforms.
74 TChild(TInt aFid = -1, TProcessId aPid = 0) : iFid(aFid), iPid(aPid)
76 TChild(TInt aFid = -1, TProcessId aPid = -1) : iFid(aFid), iPid(aPid)
83 // The underlying data for a TProcessId is a TUint64. GCC raises an error if this is intialised to a negative value. Consider changing for all platforms.
84 TChild(RProcess &aProc, TProcessId aFid = 0) : iProc(aProc), iFid(aFid)
86 TChild(RProcess &aProc, TProcessId aFid = -1) : iProc(aProc), iFid(aFid)
93 static TBool MatchByFid(const TChild& aChild1, const TChild& aChild2)
95 if (aChild1.iFid == aChild2.iFid)
102 static TBool MatchByPid(const TChild& aChild1, const TChild& aChild2)
104 if (aChild1.iPid == aChild2.iPid)
118 void StorePtrs(RHeap* aHeap, RFs* aFs, RSocketServ* aSs, RCommServ* aCs, RFastLock* aSsLock, RFastLock* aCsLock,RFastLock* aDefConnLock,RFastLock* aAESelectLock,RFastLock* aTzServerLock)
126 iDefConnLock = aDefConnLock;
127 iAESelectLock = aAESelectLock;
128 iTzServerLock = aTzServerLock;
139 iDefConnLock->Close();
140 iAESelectLock->Close();
141 iTzServerLock->Close();
150 RFastLock* iDefConnLock;
151 RFastLock* iAESelectLock;
152 RFastLock* iTzServerLock;
156 class TFileTableCleanup
159 void SaveUserHeap(RHeap* aHeap)
166 User::SwitchHeap(iUserHeap);
174 class CFileTable // codescanner::missingcclass
183 TInt Init(RHeap* aHeap = NULL);
185 void Default(CFileDescBase* aRedirMedia, CFileDescBase* aStdErrMedia);
187 TInt Attach(TInt aFid, CFileDescBase* aFile);
188 TInt Detach(TInt aFid, CFileDescBase*& aDetached);
189 TInt At(TInt aFid, CFileDescBase*& aFound) const;
190 TInt Reserve(TInt aFids[3]);
191 TInt Detach(TInt aFids[3]);
193 int dup (int fid, int& anErrno);
194 int dup2 (int fid1, int fid2, int& anErrno);
195 int open (const wchar_t* name, int mode, int perms, int& anErrno);
196 int close (int fid, int& anErrno);
198 int UserClose (int fid, int& anErrno);
200 off_t lseek (int fid, off_t offset, int whence, int& anErrno);
201 int fstat (int fid, struct stat* st, int& anErrno);
202 int socket (int family, int style, int protocol, int& anErrno, RSocketServ& aSs);
203 int listen (int fd, int n, int& anErrno);
204 int bind (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno);
205 int sockname (int fd, struct sockaddr* address, unsigned long* aAddrLen,int anEnd, int& anErrno);
206 int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
207 int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
208 int ioctlcomplete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
209 int ioctlcancel (int fid, int& anErrno);
210 int fcntl (int aFid, int aCmd, long anArg, int& anErrno);
212 TInt Asynch (int fid, CFileDescBase*& aFile);
214 int popen (const wchar_t* file, const wchar_t* cmd,const char* mode, int& anErrno);
215 int pclose (int aFid, int& anErrno);
216 int popen3 (const wchar_t *file, const wchar_t *cmd, wchar_t** envp, int fids[3], int& anErrno);
217 int system (const wchar_t* aCmd, const wchar_t* aCmdArg, int& anErrno);
218 int waitpid (int pid, int* status, int options, int& anErrno);
220 int posix_spawn (int* pid, const wchar_t* wpath,
221 const posix_spawn_file_actions_t* file_actions,
222 const posix_spawnattr_t* attrp,
223 const wchar_t* wargs, wchar_t** wenvp);
225 void TransferToChild (RProcess& child, TInt aFds[], TInt aWhich, TInt aSlot);
226 void PassEnvToChild (RProcess& child, wchar_t** aEnvp);
227 void PassFileActionsToChild (RProcess& child,
228 const posix_spawn_file_actions_t* aFileActions);
230 #ifdef SYMBIAN_OE_POSIX_SIGNALS
231 void TransferSigMaskToChild(RProcess& childproc,TDes& sigmask);
232 void CheckOrigins (wchar_t**& wenvp, int& aCount, TUint64 & aSigMask);
234 void CheckOrigins (wchar_t**& wenvp, int& aCount);
236 TInt InheritFiles(CFileDesTransferServer* server);
237 int pipe (int fildes[2], int& anErrno);
238 int mkfifo (const wchar_t *pathname, mode_t mode, int& anErrno, RFs& aFs);
239 int CreatePipeDesc (int fildes, RPipe& aHandle, TUint16 aMode = 0);
240 void ClosePipe (int fds[2], int& err);
242 static CFileDescBase* FifoOpen (const wchar_t* pathName, mode_t mode, int perms, int& anErrno);
243 int link (const wchar_t *oldpathName, const wchar_t *newpathName, int& anErrno, RFs& aFs);
244 static CFileDescBase* LinkOpen (const wchar_t* pathName, mode_t mode, int perms, int& anErrno, RFs& aFs);
245 int unlink (RFs& aFs, const wchar_t *pathName, int& anErrno);
246 int AcceptFileSocket(CFileSocketDesc* pfs, const struct sockaddr_un* addr, int& anErrno, RFs& aFs);
247 TInt RConnectionCount();
248 TInt RConnectionAt (TInt aRcIndex, RConnection *&aRc);
249 TInt AddRConnectionPtr (RConnection *aRc, TInt &aRcIndex);
250 void RemoveRConnectionPtrAt (TInt aRcIndex);
251 void DeleteRConnectionList();
253 CFileDesTransferServer* NewFDTransferServerL(RSemaphore &sem);
254 void StartFDTransferServer(CFileDesTransferServer* pServer);
255 void CloseFDTransferServer(CFileDesTransferServer* pServer);
257 int SetEcho(int aFd, TUint8 aEcho, int& aErrno);
259 void DoTransferAll(RSemaphore &sem,TDesC& name);
260 TInt GetFileCount() const
262 return iFids.Count();
276 TFileTableCleanup iCleanup;
277 CArrayPtrSeg<CFileDescBase> iFids;
280 // invoked by both dup2 and fcntl with F_DUPFD
281 TInt Dup2(TInt aFid, TInt aFid2, TBool aCloseFid2);
283 TInt DupFd(TInt aFid1, TInt aFid2);
284 void Release(TInt aFid);
286 //Lock for protecting FIDs across threads
289 //stores pids of all children of this process
290 RArray<TChild> iChildren;
292 //Methods to manipulate iChildren
293 void AddChild(const TChild& aChild);
294 void RemoveChild(TInt aIdx);
296 void ExpandFTableL(TInt count);
298 const RArray<TChild>& GetChildren() const
303 TInt FindChild(const TInt aFid) const
305 return iChildren.Find(TChild(aFid),
306 TIdentityRelation<TChild>(TChild::MatchByFid));
309 TInt FindChild(const TProcessId aPid) const
311 return iChildren.Find(TChild(-1, aPid),
312 TIdentityRelation<TChild>(TChild::MatchByPid));
315 CArrayPtrSeg<RConnection> iRConnectionList;
316 //Lock for protecting iRConnectionList across threads
319 // A pointer to the private heap
321 friend class CFileDesTransferSession;
325 class PosixFilesystem
331 static wchar_t* getcwd(RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno);
332 static int chdir(RFs& aFs, const wchar_t* path, int& anErrno);
333 static int mkdir(RFs& aFs, const wchar_t* path, int perms, int& anErrno);
334 static int rmdir(RFs& aFs, const wchar_t* path, int& anErrno);
335 static int chmod(RFs& aFs, const wchar_t* path, int perms, int& anErrno);
336 static int reg_unlink(RFs& aFs, const wchar_t* path, int& anErrno);
337 static int statbackend(RFs& aFs, const wchar_t* name, struct stat* st, int& anErrno);
338 static int rename(RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno);
339 static TInt ResolvePath(TParse& aResult, const wchar_t* path, TDes* aFilename);
340 static TInt SetDefaultDir(RFs& aFs);
341 static TInt CreateDefaultPrivatePath(RFs& aFs);
342 static int utime(RFs& aFs, const wchar_t* name, const struct utimbuf* filetimes, int& anErrno);
346 class TAccessPointRecord
350 TBuf<KCommsDbSvrMaxColumnNameLength> iName;
354 TBuf<KCommsDbSvrMaxColumnNameLength> iServiceType;
356 TBuf<KCommsDbSvrMaxColumnNameLength> iBearerType;
358 TUint32 iNetworkWeighting;
361 TAccessPointRecord();
365 // This structure encapsulates an aselect request
366 NONSHARABLE_STRUCT ( TaselectRequestInfo )
373 struct timeval *itvptr;
374 TRequestStatus* iRequestStatus;
377 // Holds the information about aselect requests, this used required
378 // for cancellation of the aselect requests
379 NONSHARABLE_CLASS ( TASelectRequest )
382 // Thread id of the thread processing the aselect
384 // Request object used for the request
385 TRequestStatus* iRequestStatus;
388 NONSHARABLE_CLASS(CLocalSystemInterface) : public CBase
396 IMPORT_C CLocalSystemInterface();
397 IMPORT_C ~CLocalSystemInterface();
399 #ifdef __SYMBIAN_COMPILE_UNUSED__
400 CLocalSystemInterface& Clone();
402 void TerminateProcess(int status);
403 #endif //__SYMBIAN_COMPILE_UNUSED__
405 int AddToDirList(DIR *aDir);
406 int RemoveDirFromList(DIR* aDir);
407 int FindInDirList(DIR* aDir);
411 int dup (int fid, int& anErrno);
412 int dup2 (int fid, int fid2, int& anErrno);
413 int open (const wchar_t* name, int mode, int perms, int& anErrno);
414 int read (int fid, char* buf, unsigned long len, int& anErrno);
415 int write (int fid, const char* buf, unsigned long len, int& anErrno);
416 int fsync (int fid, int& anErrno);
417 int close (int fid, int& anErrno);
418 off_t lseek (int fid, off_t offset, int whence, int& anErrno);
419 int fstat (int fid, struct stat* st, int& anErrno);
420 int ioctl (int fid, int cmd, void* param, int& anErrno);
421 int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
422 int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
424 #ifdef __SYMBIAN_COMPILE_UNUSED__
425 int ioctl_cancel (int fid, int& anErrno);
426 #endif //__SYMBIAN_COMPILE_UNUSED__
428 wchar_t* getcwd (wchar_t* buf, unsigned long len, int& anErrno);
430 int chdir (const wchar_t* path, int& anErrno);
431 int mkdir (const wchar_t* path, int perms, int& anErrno);
432 int rmdir (const wchar_t* path, int& anErrno);
433 int chmod (const wchar_t* path, int perms, int& anErrno);
434 int stat (const wchar_t* name, struct stat* st, int& anErrno);
435 int lstat (const wchar_t* name, struct stat *st, int& anErrno);
436 int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno);
438 IMPORT_C TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename);
439 int socket (int family, int style, int protocol, int& anErrno);
440 int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno);
441 int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno);
442 int shutdown (int fd, int how, int& anErrno);
443 int listen (int fd, int n, int& anErrno);
444 int accept (int fd, struct sockaddr *addr, size_t *size, int& anErrno);
445 int bind (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno);
446 int connect (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno);
447 int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno);
448 int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
449 int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
451 int popen3 (const wchar_t *file, const wchar_t *cmd, wchar_t** envp, int fids[3], int& anErrno);
452 int waitpid (int pid, int* status, int options, int& anErrno);
454 int fcntl (int aFid, int aCmd, long anArg, int& anErrno);
455 int utime (const wchar_t* name, const struct utimbuf* filetimes, int& anErrno);
457 int popen (const wchar_t* file, const wchar_t* cmd, const char* mode, int& anErrno);
458 int pclose (int aFid, int& anErrno);
459 IMPORT_C void CheckOrigins (wchar_t**& wenvp, int& aCount);
460 #ifdef SYMBIAN_OE_POSIX_SIGNALS
461 TInt SignalHandler();
462 IMPORT_C void InitSignalHandler();
463 void RegisterExitNotification(TProcessId aPid);
465 inline TUint64 GetSigMask()const
470 int kill(pid_t pid, int sig, int& anErrno);
471 int raise(int sig, int& anErrno);
472 int sigqueue(pid_t pid, int sig, const union sigval val, int& anErrno);
474 int sigfillset(sigset_t *set, int& anErrno);
475 int sigaddset(sigset_t *set, int signo, int& anErrno);
476 int sigdelset(sigset_t *set, int signo, int& anErrno);
477 int sigismember(const sigset_t *set, int signo, int& anErrno);
478 int sigandset(sigset_t * set, const sigset_t * left, const sigset_t * right, int& anErrno);
479 int sigorset(sigset_t * set, const sigset_t * left, const sigset_t * right, int& anErrno);
480 int sigisemptyset(const sigset_t * set, int& anErrno);
481 int sigemptyset(sigset_t * set, int& anErrno);
483 int sigprocmask(int how, const sigset_t *set, sigset_t *oset, int& anErrno);
484 int sighold(int signo, int& anErrno);
485 int sigrelse(int signo, int& anErrno);
486 int sigpause(int signo, int& anErrno);
488 int sigwait(const sigset_t *set, int *sig, int& anErrno);
489 int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout, int& anErrno);
490 int sigwaitinfo(const sigset_t *set, siginfo_t *info, int& anErrno);
491 int sigaction(int sig, const struct sigaction *act, struct sigaction *oact, int& anErrno);
492 TSignalHandler sigset(int aSigNum, TSignalHandler disp, int& anErrno);
493 TSignalHandler bsd_signal(int aSigNum, TSignalHandler aFunc,int& anErrno);
494 TSignalHandler signal(int aSigNum, TSignalHandler aFunc,int& anErrno);
495 int sigignore(int aSigNum, int& anErrno);
496 unsigned int alarm(unsigned int seconds);
497 int sigpending(sigset_t *set,int& anErrno);
499 #ifdef SYMBIAN_OE_LIBRT
501 IMPORT_C TInt AddTimer(const TInt& aTimerId);
502 IMPORT_C TInt DeleteTimer(const TInt& aTimerId);
503 IMPORT_C TInt IncrementOverrun(const TInt& aTimerId);
504 IMPORT_C TInt ResetOverrun(const TInt& aTimerId);
505 IMPORT_C TInt Overrun(const TInt& aTimerId);
506 IMPORT_C TInt RaiseTimerSignal(int sig, int timerid);
508 #endif //SYMBIAN_OE_LIBRT
509 #endif // SYMBIAN_OE_POSIX_SIGNALS
510 int pipe (int fildes[2], int& anErrno );
511 int mkfifo (const wchar_t *pathname, mode_t mode, int& anErrno);
512 int link (const wchar_t *oldpathName, const wchar_t *newpathName, int& anErrno );
513 int unlink (const wchar_t *pathName, int& anErrno );
515 int select (int maxfd, fd_set* readfds,fd_set* writefds,fd_set* exceptfds, struct timeval* tvptr, int& anErrno);
517 int aselect(int maxfd, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *tvptr, TRequestStatus* requeststatus,int& anErrno);
519 int cancelaselect(TRequestStatus* requeststatus, int& anErrno, TBool perform_cleanup = EFalse);
521 int eselect(int maxfd, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *tvptr, int arraycount,TRequestStatus* waitarray,int& anErrno);
523 static TInt handleaselect(TAny* aPtr);
525 RArray<TASelectRequest>& ASelectRequest();
527 RFastLock& ASelectLock();
529 inline RFastLock& DefConnLock() { return iDefConnLock; }
531 inline TInt AddSocket(CSocketDesc* aPtr)
533 RHeap* oheap = User::SwitchHeap(iPrivateHeap);
534 TInt ret = iSocketArray.InsertInAddressOrder(aPtr);
535 User::SwitchHeap(oheap);
539 inline void RemoveSocket(CSocketDesc* aPtr)
541 TInt index = iSocketArray.FindInAddressOrder(aPtr);
544 RHeap* oheap = User::SwitchHeap(iPrivateHeap);
545 iSocketArray.Remove(index);
546 iSocketArray.Compress();
547 User::SwitchHeap(oheap);
551 int system (const wchar_t* aCmd, const wchar_t* aCmdArg, int& anErrno );
552 const wchar_t* GetDirName (int aFid);
553 IMPORT_C int Truncate (int aFid, off_t anOffset, int& anErrno);
554 int fchmod (int fd , mode_t perms, int& anErrno);
556 int posix_spawn (int* pid, const wchar_t* wpath,
557 const posix_spawn_file_actions_t* file_actions,
558 const posix_spawnattr_t* attrp,
559 const wchar_t* wargs, wchar_t** wenvp);
561 int SetEcho(int aFd, TUint8 aEcho, int& aErrno);
563 //Set the default interface for network operations
564 int setdefaultif(const struct ifreq* aIfReq);
565 int unsetdefaultif(TBool allow_bringup = ETrue);
567 IMPORT_C CFileDescBase* GetDesc(int aFid);
569 // functions returning session to File Server
570 IMPORT_C RFs& FileSession();
571 RCommServ& CommServSession();
572 RSocketServ& SockServSession();
574 //Dynamic Memory related APIs
575 IMPORT_C void* Alloc(size_t aNBytes);
576 IMPORT_C void* ReAlloc(void* aPtr, size_t aNBytes);
577 IMPORT_C void Free(void* aPtr);
578 IMPORT_C void* AllocTLD(TInt aSize);
580 //Return the private Heap memory
581 IMPORT_C RHeap* Heap();
583 //Return the Comms Server Lock
584 RFastLock& CommsSessionLock();
586 //Return reference to file table
587 const CFileTable& FileTable() const;
589 //Get the default connection (RConnection) instance
590 RConnection& GetDefaultConnection();
592 //Get the saved session path of the file server session
593 TInt GetSessionPath(TDes& aPath);
595 //Save the file server session path
596 TInt SaveSessionPath(const TDesC& aPath);
598 static void WaitForNRequest(TRequestStatus aStatusArray[], TInt aNum);
601 //Helper function to read a record from the IAP table
602 void ReadRecordFromIapTableL(CCommsDbTableView* aView, TAccessPointRecord &aRecord);
603 //Get the connection preferences from an IAP name
604 TInt GetConnectionPreferencesL(TBuf<KCommsDbSvrMaxColumnNameLength> aIapName,
605 TCommDbConnPref &aConnPref);
607 // Helper function used by "select" api.
608 // The function returns "True", if an ioctl call has been made and it is to be waited upon.
609 // The function returns "False", (if an ioctl call is not made)/(an ioctl call was made but is not to be waited upon, and will get cancelled).
610 TBool SelectPollIssueIoctl(fd_set** aInputFds, fd_set** aOutputFds,
611 TRequestStatus* aReqArray, TInt *aReqFds, TInt aNumReqs, TInt& nDescriptorsSet) ;
612 TInt CreateaselectThread(int maxfd, fd_set* readfds, fd_set* writefds,
613 fd_set* exceptfds, struct timeval* tvptr,
614 TRequestStatus* requeststatus, int& anErrno);
616 // Helper function for the setdefaultif() API to restart the
617 // default RConnection with the new settings.
618 TInt StartDefConnection();
620 // Helper function for doing an on-demand connection to RTz server
621 TInt OnDemandTZServerConnection();
623 // NOTE: iCleanup should be the first member of CLSI, since iPrivateHeap
624 // will be destroyed from within iCleanup destructor.
625 TCLSICleanup iCleanup;
629 //The backend file session for the application
631 //The current session path of the application.
632 TFileName iSessionPath;
633 //Lock to guard the session path
634 RFastLock iSessionPathLock;
639 //Lock for protecting Socket Session across threads
641 //Lock for protecting Comms Session across threads
644 //Private Heap which will be used by the library for all memory allocation
648 const static TInt KDirGran = 2;
649 RPointerArray<TAny> iOpenDirList;
652 const static TInt KTLDInfoListGran = 4;
653 const static TInt KPtrsGran = 2;
655 //Thread-TLS pointers mapping
659 TTLDInfo(TThreadId id, TAny* ptr) : iTid(id), iPtrs(CLocalSystemInterface::KPtrsGran)
663 void Close(RHeap* pHeap)
665 TInt nptrs = iPtrs.Count();
666 for (TInt j = 0; j < nptrs; ++j)
668 pHeap->Free(iPtrs[j]);
673 RPointerArray<TAny> iPtrs;
676 //Array of Thread-TLS pointers mappings
677 RArray<TTLDInfo> iTLDInfoList;
679 //Protect the array from concurrent access
680 RFastLock iTLDListLock;
681 //The default connection to be used for all network apis.
682 RConnection iDefConnection;
683 //Protect the iDefConnection from concurrent GetDefaultConnection calls
684 RFastLock iDefConnLock;
685 //Calling unsetdefaultif(), instead of setdefaultif(NULL) ensures that the torn down
686 //connection is not brought back up again, by subsequent socket/network calls.
687 //This variable enables this facility. It is reset to default (ETrue) by setdefaultif(<pref>)
688 TBool iDefConnResurrect;
689 //Lock for protecting iASelectRequest across threads
690 RFastLock iASelectLock;
692 // iASelectRequest holds the TASelectRequest objects of the aselect requests
693 RArray<TASelectRequest> iASelectRequest;
695 // Default connection settings, set/cleared using setdefaultif
696 TConnPref* iDefConnPref;
698 RFastLock iTzServerLock;
699 TBool iIsRTzConnected;
700 RPointerArray<CSocketDesc> iSocketArray;
701 #ifdef SYMBIAN_OE_POSIX_SIGNALS
702 // Signal handler thread
703 RThread iSignalHandlerThread;
704 RPipe iSignalReadPipe;
705 RPipe iSignalWritePipe;
706 TBool iSignalLoopRunning;
707 RSignalSession iSignalSession;
709 RArray<TSignalMessage> iBlockedSigArray;
710 RMutex iBlockedSAMutex;
711 TRequestStatus iPipeReadStatus;
713 // For thread(s) to wait till signals initialization happens
714 TInt iSigInitWaitCount;
715 RSemaphore iSigInitWaitSemaphore;
716 RMutex iSigInitWaitMutex;
717 TBool iSignalsInitialized;
719 RSemaphore iSignalInitSemaphore;
726 iWaiterStatus = KRequestPending;
730 virtual ~TChildWaiter() {}
732 TRequestStatus iWaiterStatus;
733 TProcessId iWaiterPid;
735 static TBool MatchByPid(const TChildWaiter& aWaiter1, const TChildWaiter& aWaiter2)
737 if((aWaiter1.iWaiterPid == aWaiter2.iWaiterPid) != 0)
743 static TBool MatchNotPending(const TChildWaiter& aWaiter1, const TChildWaiter& aWaiter2)
745 if(aWaiter1.iWaiterStatus == KRequestPending || aWaiter2.iWaiterStatus == KRequestPending)
752 class TSignalActionInfo
757 iSigHandler = SIG_DFL;
762 virtual ~TSignalActionInfo() {}
764 TSignalHandler iSigHandler;
765 TSignalAction iSigAction;
769 TFixedArray<TSignalActionInfo,SIGRTMAX> iSigActions;
770 RMutex iSigHandlerMutex;
772 TTime iAlarmStartTime;
773 TRequestStatus iAlarmStatus;
774 TBool iIsTimerActive;
775 TUint iCurrentTimeout;
777 void HandleSignal(TSignalMessage& aMsg, TBool aIsDequeued = EFalse);
778 void InitializeSignalHandlers();
779 void CallDefaultHandler(int aSigNum);
780 void WaitOrHandleSignal(TSignalMessage aMsg);
781 TInt SuspendOtherThreads();
782 TInt ResumeOtherThreads();
783 TInt EnsureSignalsInitialized();
784 TInt SigWaitInternal(TUint64 aWaitSet,TSignalMessage* aMsg,TInt aTimeout,TBool aTimeCheckFailed=EFalse);
789 TSignalWaiter(TUint64 aWaitMask, TSignalMessage* aMsgPtr)
791 iSigWaitSemaphore.CreateLocal(0);
792 iSigWaitMessagePtr = aMsgPtr;
793 iSigWaitMask = aWaitMask;
796 iSigWaitThreadId = lThread.Id();
800 virtual ~TSignalWaiter()
802 iSigWaitSemaphore.Close();
805 TUint64 iSigWaitMask;
806 RSemaphore iSigWaitSemaphore;
807 TSignalMessage* iSigWaitMessagePtr;
808 TThreadId iSigWaitThreadId;
810 static TBool MatchByMask(const TSignalWaiter& aWaiter1, const TSignalWaiter& aWaiter2)
812 if((aWaiter1.iSigWaitMask & aWaiter2.iSigWaitMask) != 0)
818 static TBool MatchByThreadId(const TSignalWaiter& aWaiter1, const TSignalWaiter& aWaiter2)
820 if(aWaiter1.iSigWaitThreadId == aWaiter2.iSigWaitThreadId)
827 RArray<TSignalWaiter> iSignalWaiterArray;
828 RArray<TChildWaiter> iChildWaiterArray;
829 RMutex iSignalWaiterMutex;
831 #ifdef SYMBIAN_OE_LIBRT
833 TInt FindTimer(const TInt& aTimerId);
837 TOverrun(const TInt& aTimerId):iTimerId(aTimerId), Overruns(0)
845 RArray<TOverrun> iTimerOverruns;
846 RMutex iTimerOverrunsMutex;
848 #endif // SYMBIAN_OE_LIBRT
850 #endif // SYMBIAN_OE_POSIX_SIGNALS
853 IMPORT_C RTz & TZServer(TInt& aStatus);
857 friend class RFileDesTransferSession;
862 * Return global backend object to libraries
864 IMPORT_C CLocalSystemInterface* Backend();
869 // LIBC-BACKEND specific Symbian Error Codes
870 const TInt KErrMaxFdOpened = -1025;
871 const TInt KErrDirectoryOpen = -1026;
875 // Directory enumeration
877 NONSHARABLE_STRUCT(__EPOC32_WDIR) : public CBase // aka "class __EPOC32_WDIR with everything public"
884 TInt Open(const TDesC& aPath);
885 TInt Open(const wchar_t *_path,int*);
886 virtual TInt UpdateNarrow();
889 TInt iIndex; // counting down, 0 means "finished"
890 struct wdirent iCurrent;
892 TBuf16<KMaxFileName> iCurrentName;
893 /* *****************************************************************
894 Overloading new and delete operators so that they will
895 allocate and deallocare memory from/to the private heap of backend
896 ********************************************************************/
897 inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
899 Mem::FillZ(aBase, aSize); return aBase;
902 inline TAny* operator new(TUint aSize) __NO_THROW
904 return Backend()->Alloc(aSize);
907 inline TAny* operator new(TUint aSize, TLeave)
909 TAny* ptr = Backend()->Alloc(aSize);
912 User::Leave(KErrNoMemory);
917 inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
919 return Backend()->Alloc(aSize + aExtraSize);
922 inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
924 TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
927 User::Leave(KErrNoMemory);
932 inline void operator delete(TAny *aPtr) __NO_THROW
934 Backend()->Free( aPtr );
938 NONSHARABLE_STRUCT(__EPOC32_DIR) : public __EPOC32_WDIR
944 virtual TInt UpdateNarrow();
945 struct dirent iCurrentNarrow;
946 TBuf8<KMaxFileName> iCurrentNarrowName;
949 NONSHARABLE_STRUCT (_iconv_t)
955 class TUSockAddr : public TSockAddr
957 Utility class for converting struct sockaddr to and from EPOC32 TSockAddr
962 TUSockAddr() : TSockAddr(), iError(0) {}
964 TUSockAddr(TAny* addr); // constructor form of Prepare
965 IMPORT_C TUSockAddr(const TAny* addr, TUint len); // constructor form of Set
967 void Prepare(TAny* addr);
968 void Set(const TAny* addr, TUint len);
970 IMPORT_C void Get(TAny* addr, unsigned long* len);
972 TInt iError; // To store error status of TUSockAddr functions, refers errno.h. Notebly not Symbian error codes.