sl@0: /* sl@0: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #ifndef SYSIF_H sl@0: #define SYSIF_H sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "ipcclient.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #ifdef SYMBIAN_OE_POSIX_SIGNALS sl@0: #include "signalclient.h" sl@0: #include "tsignalmessage.h" sl@0: sl@0: typedef void (*TSignalHandler)(int); sl@0: typedef void (*TSignalAction)(int, siginfo_t *, void *); sl@0: #endif sl@0: sl@0: /* sl@0: @internalComponent sl@0: */ sl@0: _LIT(KEstlibInit, "STDLIBS-INIT"); sl@0: sl@0: _LIT(KFDTransferSvr,"FDTrnsfrSvr"); sl@0: //Forward declaration for references below sl@0: class RPipe; sl@0: class CFileDesTransferServer; sl@0: class RFileDesTransferSession; sl@0: class CFileDescBase; sl@0: /* TODO: We don't have to do this in CFileTable. Move to methods */ sl@0: class CFileSocketDesc; sl@0: class CSocketDesc; sl@0: struct TChild sl@0: /* sl@0: @internalComponent sl@0: */ sl@0: { sl@0: TInt iFid; sl@0: TProcessId iPid; sl@0: RProcess iProc; sl@0: sl@0: #ifdef __X86GCC__ sl@0: // 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. sl@0: TChild(TInt aFid = -1, TProcessId aPid = 0) : iFid(aFid), iPid(aPid) sl@0: #else sl@0: TChild(TInt aFid = -1, TProcessId aPid = -1) : iFid(aFid), iPid(aPid) sl@0: #endif //__X86GCC__ sl@0: { sl@0: // nada sl@0: } sl@0: sl@0: #ifdef __X86GCC__ sl@0: // 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. sl@0: TChild(RProcess &aProc, TProcessId aFid = 0) : iProc(aProc), iFid(aFid) sl@0: #else sl@0: TChild(RProcess &aProc, TProcessId aFid = -1) : iProc(aProc), iFid(aFid) sl@0: #endif //__X86GCC__ sl@0: { sl@0: iPid = aProc.Id(); sl@0: } sl@0: sl@0: sl@0: static TBool MatchByFid(const TChild& aChild1, const TChild& aChild2) sl@0: { sl@0: if (aChild1.iFid == aChild2.iFid) sl@0: { sl@0: return ETrue; sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: static TBool MatchByPid(const TChild& aChild1, const TChild& aChild2) sl@0: { sl@0: if (aChild1.iPid == aChild2.iPid) sl@0: { sl@0: return ETrue; sl@0: } sl@0: return EFalse; sl@0: } sl@0: }; sl@0: sl@0: class TCLSICleanup sl@0: /* sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: void StorePtrs(RHeap* aHeap, RFs* aFs, RSocketServ* aSs, RCommServ* aCs, RFastLock* aSsLock, RFastLock* aCsLock,RFastLock* aDefConnLock,RFastLock* aAESelectLock,RFastLock* aTzServerLock) sl@0: { sl@0: iHeap = aHeap; sl@0: iFs = aFs; sl@0: iSs = aSs; sl@0: iCs = aCs; sl@0: iSsLock = aSsLock; sl@0: iCsLock = aCsLock; sl@0: iDefConnLock = aDefConnLock; sl@0: iAESelectLock = aAESelectLock; sl@0: iTzServerLock = aTzServerLock; sl@0: } sl@0: sl@0: ~TCLSICleanup() sl@0: { sl@0: iFs->Close(); sl@0: iSs->Close(); sl@0: iSsLock->Close(); sl@0: iCs->Close(); sl@0: iCsLock->Close(); sl@0: iHeap->Close(); sl@0: iDefConnLock->Close(); sl@0: iAESelectLock->Close(); sl@0: iTzServerLock->Close(); sl@0: } sl@0: private: sl@0: RHeap* iHeap; sl@0: RFs* iFs; sl@0: RSocketServ* iSs; sl@0: RCommServ* iCs; sl@0: RFastLock* iSsLock; sl@0: RFastLock* iCsLock; sl@0: RFastLock* iDefConnLock; sl@0: RFastLock* iAESelectLock; sl@0: RFastLock* iTzServerLock; sl@0: }; sl@0: sl@0: sl@0: class TFileTableCleanup sl@0: { sl@0: public: sl@0: void SaveUserHeap(RHeap* aHeap) sl@0: { sl@0: iUserHeap = aHeap; sl@0: } sl@0: sl@0: ~TFileTableCleanup() sl@0: { sl@0: User::SwitchHeap(iUserHeap); sl@0: } sl@0: sl@0: private: sl@0: RHeap* iUserHeap; sl@0: }; sl@0: sl@0: sl@0: class CFileTable // codescanner::missingcclass sl@0: /* sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: CFileTable(); sl@0: ~CFileTable(); sl@0: sl@0: TInt Init(RHeap* aHeap = NULL); sl@0: void Close(); sl@0: void Default(CFileDescBase* aRedirMedia, CFileDescBase* aStdErrMedia); sl@0: TInt Reserve(); sl@0: TInt Attach(TInt aFid, CFileDescBase* aFile); sl@0: TInt Detach(TInt aFid, CFileDescBase*& aDetached); sl@0: TInt At(TInt aFid, CFileDescBase*& aFound) const; sl@0: TInt Reserve(TInt aFids[3]); sl@0: TInt Detach(TInt aFids[3]); sl@0: sl@0: int dup (int fid, int& anErrno); sl@0: int dup2 (int fid1, int fid2, int& anErrno); sl@0: int open (const wchar_t* name, int mode, int perms, int& anErrno); sl@0: int close (int fid, int& anErrno); sl@0: sl@0: int UserClose (int fid, int& anErrno); sl@0: sl@0: off_t lseek (int fid, off_t offset, int whence, int& anErrno); sl@0: int fstat (int fid, struct stat* st, int& anErrno); sl@0: int socket (int family, int style, int protocol, int& anErrno, RSocketServ& aSs); sl@0: int listen (int fd, int n, int& anErrno); sl@0: int bind (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno); sl@0: int sockname (int fd, struct sockaddr* address, unsigned long* aAddrLen,int anEnd, int& anErrno); sl@0: int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno); sl@0: int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno); sl@0: int ioctlcomplete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno); sl@0: int ioctlcancel (int fid, int& anErrno); sl@0: int fcntl (int aFid, int aCmd, long anArg, int& anErrno); sl@0: sl@0: TInt Asynch (int fid, CFileDescBase*& aFile); sl@0: sl@0: int popen (const wchar_t* file, const wchar_t* cmd,const char* mode, int& anErrno); sl@0: int pclose (int aFid, int& anErrno); sl@0: int popen3 (const wchar_t *file, const wchar_t *cmd, wchar_t** envp, int fids[3], int& anErrno); sl@0: int system (const wchar_t* aCmd, const wchar_t* aCmdArg, int& anErrno); sl@0: int waitpid (int pid, int* status, int options, int& anErrno); sl@0: sl@0: int posix_spawn (int* pid, const wchar_t* wpath, sl@0: const posix_spawn_file_actions_t* file_actions, sl@0: const posix_spawnattr_t* attrp, sl@0: const wchar_t* wargs, wchar_t** wenvp); sl@0: sl@0: void TransferToChild (RProcess& child, TInt aFds[], TInt aWhich, TInt aSlot); sl@0: void PassEnvToChild (RProcess& child, wchar_t** aEnvp); sl@0: void PassFileActionsToChild (RProcess& child, sl@0: const posix_spawn_file_actions_t* aFileActions); sl@0: sl@0: #ifdef SYMBIAN_OE_POSIX_SIGNALS sl@0: void TransferSigMaskToChild(RProcess& childproc,TDes& sigmask); sl@0: void CheckOrigins (wchar_t**& wenvp, int& aCount, TUint64 & aSigMask); sl@0: #else sl@0: void CheckOrigins (wchar_t**& wenvp, int& aCount); sl@0: #endif sl@0: TInt InheritFiles(CFileDesTransferServer* server); sl@0: int pipe (int fildes[2], int& anErrno); sl@0: int mkfifo (const wchar_t *pathname, mode_t mode, int& anErrno, RFs& aFs); sl@0: int CreatePipeDesc (int fildes, RPipe& aHandle, TUint16 aMode = 0); sl@0: void ClosePipe (int fds[2], int& err); sl@0: sl@0: static CFileDescBase* FifoOpen (const wchar_t* pathName, mode_t mode, int perms, int& anErrno); sl@0: int link (const wchar_t *oldpathName, const wchar_t *newpathName, int& anErrno, RFs& aFs); sl@0: static CFileDescBase* LinkOpen (const wchar_t* pathName, mode_t mode, int perms, int& anErrno, RFs& aFs); sl@0: int unlink (RFs& aFs, const wchar_t *pathName, int& anErrno); sl@0: int AcceptFileSocket(CFileSocketDesc* pfs, const struct sockaddr_un* addr, int& anErrno, RFs& aFs); sl@0: TInt RConnectionCount(); sl@0: TInt RConnectionAt (TInt aRcIndex, RConnection *&aRc); sl@0: TInt AddRConnectionPtr (RConnection *aRc, TInt &aRcIndex); sl@0: void RemoveRConnectionPtrAt (TInt aRcIndex); sl@0: void DeleteRConnectionList(); sl@0: sl@0: CFileDesTransferServer* NewFDTransferServerL(RSemaphore &sem); sl@0: void StartFDTransferServer(CFileDesTransferServer* pServer); sl@0: void CloseFDTransferServer(CFileDesTransferServer* pServer); sl@0: sl@0: int SetEcho(int aFd, TUint8 aEcho, int& aErrno); sl@0: sl@0: void DoTransferAll(RSemaphore &sem,TDesC& name); sl@0: TInt GetFileCount() const sl@0: { sl@0: return iFids.Count(); sl@0: } sl@0: sl@0: void Lock() sl@0: { sl@0: iFidLock.Wait(); sl@0: } sl@0: sl@0: void Unlock() sl@0: { sl@0: iFidLock.Signal(); sl@0: } sl@0: sl@0: private: sl@0: TFileTableCleanup iCleanup; sl@0: CArrayPtrSeg iFids; sl@0: // invoked by dup sl@0: TInt Dup(TInt aFid); sl@0: // invoked by both dup2 and fcntl with F_DUPFD sl@0: TInt Dup2(TInt aFid, TInt aFid2, TBool aCloseFid2); sl@0: // the real dup-er. sl@0: TInt DupFd(TInt aFid1, TInt aFid2); sl@0: void Release(TInt aFid); sl@0: sl@0: //Lock for protecting FIDs across threads sl@0: RFastLock iFidLock; sl@0: sl@0: //stores pids of all children of this process sl@0: RArray iChildren; sl@0: sl@0: //Methods to manipulate iChildren sl@0: void AddChild(const TChild& aChild); sl@0: void RemoveChild(TInt aIdx); sl@0: sl@0: void ExpandFTableL(TInt count); sl@0: sl@0: const RArray& GetChildren() const sl@0: { sl@0: return iChildren; sl@0: } sl@0: sl@0: TInt FindChild(const TInt aFid) const sl@0: { sl@0: return iChildren.Find(TChild(aFid), sl@0: TIdentityRelation(TChild::MatchByFid)); sl@0: } sl@0: sl@0: TInt FindChild(const TProcessId aPid) const sl@0: { sl@0: return iChildren.Find(TChild(-1, aPid), sl@0: TIdentityRelation(TChild::MatchByPid)); sl@0: } sl@0: sl@0: CArrayPtrSeg iRConnectionList; sl@0: //Lock for protecting iRConnectionList across threads sl@0: RFastLock iRcLock; sl@0: sl@0: // A pointer to the private heap sl@0: RHeap* iPrivateHeap; sl@0: friend class CFileDesTransferSession; sl@0: }; sl@0: sl@0: sl@0: class PosixFilesystem sl@0: /* sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: static wchar_t* getcwd(RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno); sl@0: static int chdir(RFs& aFs, const wchar_t* path, int& anErrno); sl@0: static int mkdir(RFs& aFs, const wchar_t* path, int perms, int& anErrno); sl@0: static int rmdir(RFs& aFs, const wchar_t* path, int& anErrno); sl@0: static int chmod(RFs& aFs, const wchar_t* path, int perms, int& anErrno); sl@0: static int reg_unlink(RFs& aFs, const wchar_t* path, int& anErrno); sl@0: static int statbackend(RFs& aFs, const wchar_t* name, struct stat* st, int& anErrno); sl@0: static int rename(RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno); sl@0: static TInt ResolvePath(TParse& aResult, const wchar_t* path, TDes* aFilename); sl@0: static TInt SetDefaultDir(RFs& aFs); sl@0: static TInt CreateDefaultPrivatePath(RFs& aFs); sl@0: static int utime(RFs& aFs, const wchar_t* name, const struct utimbuf* filetimes, int& anErrno); sl@0: }; sl@0: sl@0: sl@0: class TAccessPointRecord sl@0: { sl@0: public: sl@0: TUint32 iId; sl@0: TBuf iName; sl@0: TUint32 iDialogPref; sl@0: TUint32 iDirection; sl@0: TUint32 iService; sl@0: TBuf iServiceType; sl@0: TUint32 iBearer; sl@0: TBuf iBearerType; sl@0: TUint32 iNetwork; sl@0: TUint32 iNetworkWeighting; sl@0: TUint32 iLocation; sl@0: public: sl@0: TAccessPointRecord(); sl@0: sl@0: }; sl@0: sl@0: // This structure encapsulates an aselect request sl@0: NONSHARABLE_STRUCT ( TaselectRequestInfo ) sl@0: { sl@0: TThreadId iId; sl@0: int iMaxFd; sl@0: fd_set* iReadFds; sl@0: fd_set* iWriteFds; sl@0: fd_set* iExceptFds; sl@0: struct timeval *itvptr; sl@0: TRequestStatus* iRequestStatus; sl@0: }; sl@0: sl@0: // Holds the information about aselect requests, this used required sl@0: // for cancellation of the aselect requests sl@0: NONSHARABLE_CLASS ( TASelectRequest ) sl@0: { sl@0: public: sl@0: // Thread id of the thread processing the aselect sl@0: TThreadId iThreadId; sl@0: // Request object used for the request sl@0: TRequestStatus* iRequestStatus; sl@0: }; sl@0: sl@0: NONSHARABLE_CLASS(CLocalSystemInterface) : public CBase sl@0: /* sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: sl@0: sl@0: IMPORT_C CLocalSystemInterface(); sl@0: IMPORT_C ~CLocalSystemInterface(); sl@0: sl@0: #ifdef __SYMBIAN_COMPILE_UNUSED__ sl@0: CLocalSystemInterface& Clone(); sl@0: void Release(); sl@0: void TerminateProcess(int status); sl@0: #endif //__SYMBIAN_COMPILE_UNUSED__ sl@0: sl@0: int AddToDirList(DIR *aDir); sl@0: int RemoveDirFromList(DIR* aDir); sl@0: int FindInDirList(DIR* aDir); sl@0: sl@0: void Exit(int code); sl@0: sl@0: int dup (int fid, int& anErrno); sl@0: int dup2 (int fid, int fid2, int& anErrno); sl@0: int open (const wchar_t* name, int mode, int perms, int& anErrno); sl@0: int read (int fid, char* buf, unsigned long len, int& anErrno); sl@0: int write (int fid, const char* buf, unsigned long len, int& anErrno); sl@0: int fsync (int fid, int& anErrno); sl@0: int close (int fid, int& anErrno); sl@0: off_t lseek (int fid, off_t offset, int whence, int& anErrno); sl@0: int fstat (int fid, struct stat* st, int& anErrno); sl@0: int ioctl (int fid, int cmd, void* param, int& anErrno); sl@0: int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno); sl@0: int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno); sl@0: sl@0: #ifdef __SYMBIAN_COMPILE_UNUSED__ sl@0: int ioctl_cancel (int fid, int& anErrno); sl@0: #endif //__SYMBIAN_COMPILE_UNUSED__ sl@0: sl@0: wchar_t* getcwd (wchar_t* buf, unsigned long len, int& anErrno); sl@0: sl@0: int chdir (const wchar_t* path, int& anErrno); sl@0: int mkdir (const wchar_t* path, int perms, int& anErrno); sl@0: int rmdir (const wchar_t* path, int& anErrno); sl@0: int chmod (const wchar_t* path, int perms, int& anErrno); sl@0: int stat (const wchar_t* name, struct stat* st, int& anErrno); sl@0: int lstat (const wchar_t* name, struct stat *st, int& anErrno); sl@0: int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno); sl@0: sl@0: IMPORT_C TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename); sl@0: int socket (int family, int style, int protocol, int& anErrno); sl@0: int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno); sl@0: int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno); sl@0: int shutdown (int fd, int how, int& anErrno); sl@0: int listen (int fd, int n, int& anErrno); sl@0: int accept (int fd, struct sockaddr *addr, size_t *size, int& anErrno); sl@0: int bind (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno); sl@0: int connect (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno); sl@0: int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno); sl@0: int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno); sl@0: int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno); sl@0: sl@0: int popen3 (const wchar_t *file, const wchar_t *cmd, wchar_t** envp, int fids[3], int& anErrno); sl@0: int waitpid (int pid, int* status, int options, int& anErrno); sl@0: sl@0: int fcntl (int aFid, int aCmd, long anArg, int& anErrno); sl@0: int utime (const wchar_t* name, const struct utimbuf* filetimes, int& anErrno); sl@0: sl@0: int popen (const wchar_t* file, const wchar_t* cmd, const char* mode, int& anErrno); sl@0: int pclose (int aFid, int& anErrno); sl@0: IMPORT_C void CheckOrigins (wchar_t**& wenvp, int& aCount); sl@0: #ifdef SYMBIAN_OE_POSIX_SIGNALS sl@0: TInt SignalHandler(); sl@0: IMPORT_C void InitSignalHandler(); sl@0: void RegisterExitNotification(TProcessId aPid); sl@0: sl@0: inline TUint64 GetSigMask()const sl@0: { sl@0: return iSigMask; sl@0: } sl@0: sl@0: int kill(pid_t pid, int sig, int& anErrno); sl@0: int raise(int sig, int& anErrno); sl@0: int sigqueue(pid_t pid, int sig, const union sigval val, int& anErrno); sl@0: sl@0: int sigfillset(sigset_t *set, int& anErrno); sl@0: int sigaddset(sigset_t *set, int signo, int& anErrno); sl@0: int sigdelset(sigset_t *set, int signo, int& anErrno); sl@0: int sigismember(const sigset_t *set, int signo, int& anErrno); sl@0: int sigandset(sigset_t * set, const sigset_t * left, const sigset_t * right, int& anErrno); sl@0: int sigorset(sigset_t * set, const sigset_t * left, const sigset_t * right, int& anErrno); sl@0: int sigisemptyset(const sigset_t * set, int& anErrno); sl@0: int sigemptyset(sigset_t * set, int& anErrno); sl@0: sl@0: int sigprocmask(int how, const sigset_t *set, sigset_t *oset, int& anErrno); sl@0: int sighold(int signo, int& anErrno); sl@0: int sigrelse(int signo, int& anErrno); sl@0: int sigpause(int signo, int& anErrno); sl@0: sl@0: int sigwait(const sigset_t *set, int *sig, int& anErrno); sl@0: int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout, int& anErrno); sl@0: int sigwaitinfo(const sigset_t *set, siginfo_t *info, int& anErrno); sl@0: int sigaction(int sig, const struct sigaction *act, struct sigaction *oact, int& anErrno); sl@0: TSignalHandler sigset(int aSigNum, TSignalHandler disp, int& anErrno); sl@0: TSignalHandler bsd_signal(int aSigNum, TSignalHandler aFunc,int& anErrno); sl@0: TSignalHandler signal(int aSigNum, TSignalHandler aFunc,int& anErrno); sl@0: int sigignore(int aSigNum, int& anErrno); sl@0: unsigned int alarm(unsigned int seconds); sl@0: int sigpending(sigset_t *set,int& anErrno); sl@0: sl@0: #ifdef SYMBIAN_OE_LIBRT sl@0: //start timers... sl@0: IMPORT_C TInt AddTimer(const TInt& aTimerId); sl@0: IMPORT_C TInt DeleteTimer(const TInt& aTimerId); sl@0: IMPORT_C TInt IncrementOverrun(const TInt& aTimerId); sl@0: IMPORT_C TInt ResetOverrun(const TInt& aTimerId); sl@0: IMPORT_C TInt Overrun(const TInt& aTimerId); sl@0: IMPORT_C TInt RaiseTimerSignal(int sig, int timerid); sl@0: //end timers sl@0: #endif //SYMBIAN_OE_LIBRT sl@0: #endif // SYMBIAN_OE_POSIX_SIGNALS sl@0: int pipe (int fildes[2], int& anErrno ); sl@0: int mkfifo (const wchar_t *pathname, mode_t mode, int& anErrno); sl@0: int link (const wchar_t *oldpathName, const wchar_t *newpathName, int& anErrno ); sl@0: int unlink (const wchar_t *pathName, int& anErrno ); sl@0: sl@0: int select (int maxfd, fd_set* readfds,fd_set* writefds,fd_set* exceptfds, struct timeval* tvptr, int& anErrno); sl@0: sl@0: int aselect(int maxfd, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *tvptr, TRequestStatus* requeststatus,int& anErrno); sl@0: sl@0: int cancelaselect(TRequestStatus* requeststatus, int& anErrno, TBool perform_cleanup = EFalse); sl@0: sl@0: int eselect(int maxfd, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *tvptr, int arraycount,TRequestStatus* waitarray,int& anErrno); sl@0: sl@0: static TInt handleaselect(TAny* aPtr); sl@0: sl@0: RArray& ASelectRequest(); sl@0: sl@0: RFastLock& ASelectLock(); sl@0: sl@0: inline RFastLock& DefConnLock() { return iDefConnLock; } sl@0: sl@0: inline TInt AddSocket(CSocketDesc* aPtr) sl@0: { sl@0: RHeap* oheap = User::SwitchHeap(iPrivateHeap); sl@0: TInt ret = iSocketArray.InsertInAddressOrder(aPtr); sl@0: User::SwitchHeap(oheap); sl@0: return ret; sl@0: } sl@0: sl@0: inline void RemoveSocket(CSocketDesc* aPtr) sl@0: { sl@0: TInt index = iSocketArray.FindInAddressOrder(aPtr); sl@0: if (index != -1) sl@0: { sl@0: RHeap* oheap = User::SwitchHeap(iPrivateHeap); sl@0: iSocketArray.Remove(index); sl@0: iSocketArray.Compress(); sl@0: User::SwitchHeap(oheap); sl@0: } sl@0: } sl@0: sl@0: int system (const wchar_t* aCmd, const wchar_t* aCmdArg, int& anErrno ); sl@0: const wchar_t* GetDirName (int aFid); sl@0: IMPORT_C int Truncate (int aFid, off_t anOffset, int& anErrno); sl@0: int fchmod (int fd , mode_t perms, int& anErrno); sl@0: sl@0: int posix_spawn (int* pid, const wchar_t* wpath, sl@0: const posix_spawn_file_actions_t* file_actions, sl@0: const posix_spawnattr_t* attrp, sl@0: const wchar_t* wargs, wchar_t** wenvp); sl@0: sl@0: int SetEcho(int aFd, TUint8 aEcho, int& aErrno); sl@0: sl@0: //Set the default interface for network operations sl@0: int setdefaultif(const struct ifreq* aIfReq); sl@0: int unsetdefaultif(TBool allow_bringup = ETrue); sl@0: sl@0: IMPORT_C CFileDescBase* GetDesc(int aFid); sl@0: sl@0: // functions returning session to File Server sl@0: IMPORT_C RFs& FileSession(); sl@0: RCommServ& CommServSession(); sl@0: RSocketServ& SockServSession(); sl@0: sl@0: //Dynamic Memory related APIs sl@0: IMPORT_C void* Alloc(size_t aNBytes); sl@0: IMPORT_C void* ReAlloc(void* aPtr, size_t aNBytes); sl@0: IMPORT_C void Free(void* aPtr); sl@0: IMPORT_C void* AllocTLD(TInt aSize); sl@0: sl@0: //Return the private Heap memory sl@0: IMPORT_C RHeap* Heap(); sl@0: sl@0: //Return the Comms Server Lock sl@0: RFastLock& CommsSessionLock(); sl@0: sl@0: //Return reference to file table sl@0: const CFileTable& FileTable() const; sl@0: sl@0: //Get the default connection (RConnection) instance sl@0: RConnection& GetDefaultConnection(); sl@0: sl@0: //Get the saved session path of the file server session sl@0: TInt GetSessionPath(TDes& aPath); sl@0: sl@0: //Save the file server session path sl@0: TInt SaveSessionPath(const TDesC& aPath); sl@0: sl@0: static void WaitForNRequest(TRequestStatus aStatusArray[], TInt aNum); sl@0: sl@0: private: sl@0: //Helper function to read a record from the IAP table sl@0: void ReadRecordFromIapTableL(CCommsDbTableView* aView, TAccessPointRecord &aRecord); sl@0: //Get the connection preferences from an IAP name sl@0: TInt GetConnectionPreferencesL(TBuf aIapName, sl@0: TCommDbConnPref &aConnPref); sl@0: sl@0: // Helper function used by "select" api. sl@0: // The function returns "True", if an ioctl call has been made and it is to be waited upon. sl@0: // 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). sl@0: TBool SelectPollIssueIoctl(fd_set** aInputFds, fd_set** aOutputFds, sl@0: TRequestStatus* aReqArray, TInt *aReqFds, TInt aNumReqs, TInt& nDescriptorsSet) ; sl@0: TInt CreateaselectThread(int maxfd, fd_set* readfds, fd_set* writefds, sl@0: fd_set* exceptfds, struct timeval* tvptr, sl@0: TRequestStatus* requeststatus, int& anErrno); sl@0: sl@0: // Helper function for the setdefaultif() API to restart the sl@0: // default RConnection with the new settings. sl@0: TInt StartDefConnection(); sl@0: sl@0: // Helper function for doing an on-demand connection to RTz server sl@0: TInt OnDemandTZServerConnection(); sl@0: private: sl@0: // NOTE: iCleanup should be the first member of CLSI, since iPrivateHeap sl@0: // will be destroyed from within iCleanup destructor. sl@0: TCLSICleanup iCleanup; sl@0: sl@0: CFileTable iFids; sl@0: sl@0: //The backend file session for the application sl@0: RFs iFs; sl@0: //The current session path of the application. sl@0: TFileName iSessionPath; sl@0: //Lock to guard the session path sl@0: RFastLock iSessionPathLock; sl@0: sl@0: RSocketServ iSs; sl@0: RCommServ iCs; sl@0: sl@0: //Lock for protecting Socket Session across threads sl@0: RFastLock iSSLock; sl@0: //Lock for protecting Comms Session across threads sl@0: RFastLock iCSLock; sl@0: sl@0: //Private Heap which will be used by the library for all memory allocation sl@0: RHeap* iPrivateHeap; sl@0: sl@0: //used for Opendir sl@0: const static TInt KDirGran = 2; sl@0: RPointerArray iOpenDirList; sl@0: sl@0: //in class consts sl@0: const static TInt KTLDInfoListGran = 4; sl@0: const static TInt KPtrsGran = 2; sl@0: sl@0: //Thread-TLS pointers mapping sl@0: class TTLDInfo sl@0: { sl@0: public: sl@0: TTLDInfo(TThreadId id, TAny* ptr) : iTid(id), iPtrs(CLocalSystemInterface::KPtrsGran) sl@0: { sl@0: iPtrs.Append(ptr); sl@0: } sl@0: void Close(RHeap* pHeap) sl@0: { sl@0: TInt nptrs = iPtrs.Count(); sl@0: for (TInt j = 0; j < nptrs; ++j) sl@0: { sl@0: pHeap->Free(iPtrs[j]); sl@0: } sl@0: iPtrs.Close(); sl@0: } sl@0: TThreadId iTid; sl@0: RPointerArray iPtrs; sl@0: }; sl@0: sl@0: //Array of Thread-TLS pointers mappings sl@0: RArray iTLDInfoList; sl@0: sl@0: //Protect the array from concurrent access sl@0: RFastLock iTLDListLock; sl@0: //The default connection to be used for all network apis. sl@0: RConnection iDefConnection; sl@0: //Protect the iDefConnection from concurrent GetDefaultConnection calls sl@0: RFastLock iDefConnLock; sl@0: //Calling unsetdefaultif(), instead of setdefaultif(NULL) ensures that the torn down sl@0: //connection is not brought back up again, by subsequent socket/network calls. sl@0: //This variable enables this facility. It is reset to default (ETrue) by setdefaultif() sl@0: TBool iDefConnResurrect; sl@0: //Lock for protecting iASelectRequest across threads sl@0: RFastLock iASelectLock; sl@0: sl@0: // iASelectRequest holds the TASelectRequest objects of the aselect requests sl@0: RArray iASelectRequest; sl@0: sl@0: // Default connection settings, set/cleared using setdefaultif sl@0: TConnPref* iDefConnPref; sl@0: RTz iTzServer; sl@0: RFastLock iTzServerLock; sl@0: TBool iIsRTzConnected; sl@0: RPointerArray iSocketArray; sl@0: #ifdef SYMBIAN_OE_POSIX_SIGNALS sl@0: // Signal handler thread sl@0: RThread iSignalHandlerThread; sl@0: RPipe iSignalReadPipe; sl@0: RPipe iSignalWritePipe; sl@0: TBool iSignalLoopRunning; sl@0: RSignalSession iSignalSession; sl@0: TUint64 iSigMask; sl@0: RArray iBlockedSigArray; sl@0: RMutex iBlockedSAMutex; sl@0: TRequestStatus iPipeReadStatus; sl@0: sl@0: // For thread(s) to wait till signals initialization happens sl@0: TInt iSigInitWaitCount; sl@0: RSemaphore iSigInitWaitSemaphore; sl@0: RMutex iSigInitWaitMutex; sl@0: TBool iSignalsInitialized; sl@0: sl@0: RSemaphore iSignalInitSemaphore; sl@0: sl@0: class TChildWaiter sl@0: { sl@0: public: sl@0: TChildWaiter() sl@0: { sl@0: iWaiterStatus = KRequestPending; sl@0: iWaiterPid = 0; sl@0: } sl@0: sl@0: virtual ~TChildWaiter() {} sl@0: sl@0: TRequestStatus iWaiterStatus; sl@0: TProcessId iWaiterPid; sl@0: sl@0: static TBool MatchByPid(const TChildWaiter& aWaiter1, const TChildWaiter& aWaiter2) sl@0: { sl@0: if((aWaiter1.iWaiterPid == aWaiter2.iWaiterPid) != 0) sl@0: return ETrue; sl@0: else sl@0: return EFalse; sl@0: } sl@0: sl@0: static TBool MatchNotPending(const TChildWaiter& aWaiter1, const TChildWaiter& aWaiter2) sl@0: { sl@0: if(aWaiter1.iWaiterStatus == KRequestPending || aWaiter2.iWaiterStatus == KRequestPending) sl@0: return EFalse; sl@0: else sl@0: return ETrue; sl@0: } sl@0: }; sl@0: sl@0: class TSignalActionInfo sl@0: { sl@0: public: sl@0: TSignalActionInfo() sl@0: { sl@0: iSigHandler = SIG_DFL; sl@0: iSigAction = 0; sl@0: iSigFlags = 0; sl@0: } sl@0: sl@0: virtual ~TSignalActionInfo() {} sl@0: sl@0: TSignalHandler iSigHandler; sl@0: TSignalAction iSigAction; sl@0: TUint32 iSigFlags; sl@0: }; sl@0: sl@0: TFixedArray iSigActions; sl@0: RMutex iSigHandlerMutex; sl@0: RTimer iAlarmTimer; sl@0: TTime iAlarmStartTime; sl@0: TRequestStatus iAlarmStatus; sl@0: TBool iIsTimerActive; sl@0: TUint iCurrentTimeout; sl@0: sl@0: void HandleSignal(TSignalMessage& aMsg, TBool aIsDequeued = EFalse); sl@0: void InitializeSignalHandlers(); sl@0: void CallDefaultHandler(int aSigNum); sl@0: void WaitOrHandleSignal(TSignalMessage aMsg); sl@0: TInt SuspendOtherThreads(); sl@0: TInt ResumeOtherThreads(); sl@0: TInt EnsureSignalsInitialized(); sl@0: TInt SigWaitInternal(TUint64 aWaitSet,TSignalMessage* aMsg,TInt aTimeout,TBool aTimeCheckFailed=EFalse); sl@0: sl@0: class TSignalWaiter sl@0: { sl@0: public: sl@0: TSignalWaiter(TUint64 aWaitMask, TSignalMessage* aMsgPtr) sl@0: { sl@0: iSigWaitSemaphore.CreateLocal(0); sl@0: iSigWaitMessagePtr = aMsgPtr; sl@0: iSigWaitMask = aWaitMask; sl@0: sl@0: RThread lThread; sl@0: iSigWaitThreadId = lThread.Id(); sl@0: lThread.Close(); sl@0: } sl@0: sl@0: virtual ~TSignalWaiter() sl@0: { sl@0: iSigWaitSemaphore.Close(); sl@0: } sl@0: sl@0: TUint64 iSigWaitMask; sl@0: RSemaphore iSigWaitSemaphore; sl@0: TSignalMessage* iSigWaitMessagePtr; sl@0: TThreadId iSigWaitThreadId; sl@0: sl@0: static TBool MatchByMask(const TSignalWaiter& aWaiter1, const TSignalWaiter& aWaiter2) sl@0: { sl@0: if((aWaiter1.iSigWaitMask & aWaiter2.iSigWaitMask) != 0) sl@0: return ETrue; sl@0: else sl@0: return EFalse; sl@0: } sl@0: sl@0: static TBool MatchByThreadId(const TSignalWaiter& aWaiter1, const TSignalWaiter& aWaiter2) sl@0: { sl@0: if(aWaiter1.iSigWaitThreadId == aWaiter2.iSigWaitThreadId) sl@0: return ETrue; sl@0: else sl@0: return EFalse; sl@0: } sl@0: }; sl@0: sl@0: RArray iSignalWaiterArray; sl@0: RArray iChildWaiterArray; sl@0: RMutex iSignalWaiterMutex; sl@0: sl@0: #ifdef SYMBIAN_OE_LIBRT sl@0: //timers.. sl@0: TInt FindTimer(const TInt& aTimerId); sl@0: class TOverrun sl@0: { sl@0: public: sl@0: TOverrun(const TInt& aTimerId):iTimerId(aTimerId), Overruns(0) sl@0: { sl@0: } sl@0: sl@0: TInt iTimerId; sl@0: TInt Overruns; sl@0: }; sl@0: sl@0: RArray iTimerOverruns; sl@0: RMutex iTimerOverrunsMutex; sl@0: //timers.. sl@0: #endif // SYMBIAN_OE_LIBRT sl@0: sl@0: #endif // SYMBIAN_OE_POSIX_SIGNALS sl@0: public: sl@0: sl@0: IMPORT_C RTz & TZServer(TInt& aStatus); sl@0: sl@0: //ipc server session sl@0: RIpcSession iIpcS; sl@0: friend class RFileDesTransferSession; sl@0: }; sl@0: sl@0: sl@0: /* sl@0: * Return global backend object to libraries sl@0: */ sl@0: IMPORT_C CLocalSystemInterface* Backend(); sl@0: sl@0: sl@0: sl@0: sl@0: // LIBC-BACKEND specific Symbian Error Codes sl@0: const TInt KErrMaxFdOpened = -1025; sl@0: const TInt KErrDirectoryOpen = -1026; sl@0: sl@0: sl@0: sl@0: // Directory enumeration sl@0: sl@0: NONSHARABLE_STRUCT(__EPOC32_WDIR) : public CBase // aka "class __EPOC32_WDIR with everything public" sl@0: { sl@0: public: sl@0: __EPOC32_WDIR() {} sl@0: ~__EPOC32_WDIR(); sl@0: sl@0: TInt Open(); sl@0: TInt Open(const TDesC& aPath); sl@0: TInt Open(const wchar_t *_path,int*); sl@0: virtual TInt UpdateNarrow(); sl@0: HBufC* iPath; sl@0: CDir* iEntries; sl@0: TInt iIndex; // counting down, 0 means "finished" sl@0: struct wdirent iCurrent; sl@0: TInt iCount ; sl@0: TBuf16 iCurrentName; sl@0: /* ***************************************************************** sl@0: Overloading new and delete operators so that they will sl@0: allocate and deallocare memory from/to the private heap of backend sl@0: ********************************************************************/ sl@0: inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW sl@0: { sl@0: Mem::FillZ(aBase, aSize); return aBase; sl@0: } sl@0: sl@0: inline TAny* operator new(TUint aSize) __NO_THROW sl@0: { sl@0: return Backend()->Alloc(aSize); sl@0: } sl@0: sl@0: inline TAny* operator new(TUint aSize, TLeave) sl@0: { sl@0: TAny* ptr = Backend()->Alloc(aSize); sl@0: if (ptr == NULL) sl@0: { sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: return ptr; sl@0: } sl@0: sl@0: inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW sl@0: { sl@0: return Backend()->Alloc(aSize + aExtraSize); sl@0: } sl@0: sl@0: inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize) sl@0: { sl@0: TAny* ptr = Backend()->Alloc(aSize + aExtraSize); sl@0: if (ptr == NULL) sl@0: { sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: return ptr; sl@0: } sl@0: sl@0: inline void operator delete(TAny *aPtr) __NO_THROW sl@0: { sl@0: Backend()->Free( aPtr ); sl@0: } sl@0: }; sl@0: sl@0: NONSHARABLE_STRUCT(__EPOC32_DIR) : public __EPOC32_WDIR sl@0: { sl@0: public: sl@0: __EPOC32_DIR(){} sl@0: ~__EPOC32_DIR(){} sl@0: sl@0: virtual TInt UpdateNarrow(); sl@0: struct dirent iCurrentNarrow; sl@0: TBuf8 iCurrentNarrowName; sl@0: }; sl@0: sl@0: NONSHARABLE_STRUCT (_iconv_t) sl@0: { sl@0: TUint toCode; sl@0: TUint fromCode; sl@0: }; sl@0: sl@0: class TUSockAddr : public TSockAddr sl@0: /* sl@0: Utility class for converting struct sockaddr to and from EPOC32 TSockAddr sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: TUSockAddr() : TSockAddr(), iError(0) {} sl@0: sl@0: TUSockAddr(TAny* addr); // constructor form of Prepare sl@0: IMPORT_C TUSockAddr(const TAny* addr, TUint len); // constructor form of Set sl@0: private: sl@0: void Prepare(TAny* addr); sl@0: void Set(const TAny* addr, TUint len); sl@0: public: sl@0: IMPORT_C void Get(TAny* addr, unsigned long* len); sl@0: public: sl@0: TInt iError; // To store error status of TUSockAddr functions, refers errno.h. Notebly not Symbian error codes. sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: #endif //SYSIF_H sl@0: