Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1879 lines
32 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. psxsrv.h
  5. Abstract:
  6. Main include file for POSIX Subsystem Server
  7. Author:
  8. Steve Wood (stevewo) 22-Aug-1989
  9. Revision History:
  10. Ellen Aycock-Wright 15-Jul-91 Modify for POSIX subsystem
  11. --*/
  12. #ifndef _PSXP_
  13. #define _PSXP_
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <types.h>
  18. #include <string.h>
  19. #include <limits.h>
  20. #include <signal.h>
  21. #include <errno.h>
  22. #include <fcntl.h>
  23. #include <unistd.h>
  24. #include <sys\wait.h>
  25. #include <ntsm.h>
  26. #include "psxmsg.h"
  27. #if DBG
  28. #define PSX_DEBUG_INIT 0x0000001
  29. #define PSX_DEBUG_LPC 0x0000002
  30. #define PSX_DEBUG_MSGDUMP 0x0000004
  31. #define PSX_DEBUG_EXEC 0x0000008
  32. extern ULONG PsxDebug;
  33. #define IF_PSX_DEBUG(ComponentFlag ) \
  34. if (PsxDebug & (PSX_DEBUG_ ## ComponentFlag))
  35. #else
  36. #define IF_PSX_DEBUG( ComponentFlag ) if (FALSE)
  37. #endif //DBG
  38. BOOLEAN PsxpDebuggerActive;
  39. HANDLE PsxpDebugPort;
  40. ULONG PsxpApiMsgSize;
  41. int
  42. __NullPosixApi();
  43. VOID
  44. Panic(
  45. IN PSZ PanicString
  46. );
  47. //
  48. // Constants for Posix ID / Sid mapping
  49. //
  50. #define SHARE_ALL (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)
  51. //
  52. // This is the name of the directory used to store open files that have
  53. // been unlinked.
  54. //
  55. #define PSX_JUNK_DIR L"$$psxjunk"
  56. //
  57. // Posix Process types constants and data structures
  58. //
  59. #define CIDHASHSIZE 256
  60. #define CIDTOHASHINDEX(pcid) (ULONG)(\
  61. ((ULONG_PTR)((pcid)->UniqueProcess))&(CIDHASHSIZE-1))
  62. #define PIDINDEXBITS 0xffff
  63. #define PIDSEQSHIFT 16
  64. #define SPECIALPID 1
  65. // #define SPECIALPID 0xff000000
  66. #define PIDTOPROCESS(pid) \
  67. &FirstProcess[(pid) & PIDINDEXBITS]
  68. #define MAKEPID(pid,seq,index) \
  69. (pid) = (seq) & 0xff;\
  70. (pid) <<= PIDSEQSHIFT;\
  71. (pid) |= ((index)&PIDINDEXBITS)
  72. #define ISFILEDESINRANGE(fd) (\
  73. ( (ULONG)(fd) < OPEN_MAX ) )
  74. typedef struct _FILEDESCRIPTOR {
  75. struct _SYSTEMOPENFILE *SystemOpenFileDesc;
  76. ULONG Flags; // descriptor flags (FD_CLOEXEC)
  77. } FILEDESCRIPTOR;
  78. typedef FILEDESCRIPTOR *PFILEDESCRIPTOR;
  79. //
  80. // Flags for FILEDESCRIPTOR.Flags
  81. //
  82. #define PSX_FD_CLOSE_ON_EXEC 0x00000001
  83. typedef enum _PSX_INTERRUPTREASON {
  84. SignalInterrupt,
  85. WaitSatisfyInterrupt,
  86. IoCompletionInterrupt,
  87. SleepComplete
  88. } PSX_INTERRUPTREASON;
  89. struct _PSX_PROCESS; //Make mips compiler happy
  90. struct _INTCB;
  91. typedef void (* INTHANDLER)(
  92. IN struct _PSX_PROCESS *p,
  93. IN struct _INTCB *IntControlBlock,
  94. IN PSX_INTERRUPTREASON InterruptReason,
  95. IN int Signal
  96. );
  97. typedef struct _INTCB {
  98. INTHANDLER IntHandler;
  99. PPSX_API_MSG IntMessage;
  100. PVOID IntContext;
  101. LIST_ENTRY Links;
  102. } INTCB, *PINTCB;
  103. #define _SIGNULLSET 0x0
  104. #define _SIGFULLSET 0x7ffff // ((1<<SIGTTOU) - 1)
  105. #define _SIGMAXSIGNO SIGTTOU
  106. #define _SIGSTOPSIGNALS ((1l<<SIGSTOP) | (1l<<SIGTSTP) | (1l<<SIGTTIN)| (1l<<SIGTTOU) )
  107. #define SIGEMPTYSET(set) \
  108. *(set) = _SIGNULLSET
  109. #define SIGFILLSET(set) \
  110. *(set) = _SIGFULLSET
  111. #define SIGADDSET(set, signo) \
  112. *(set) |= ( (1l << (ULONG)((signo)-1)) & _SIGFULLSET )
  113. #define SIGDELSET(set, signo) \
  114. *(set) &= ~( (1l << (ULONG)((signo)-1)) & _SIGFULLSET )
  115. #define SIGISMEMBER(set, signo) \
  116. ( *(set) & ( (1l << (ULONG)((signo)-1)) & _SIGFULLSET ) )
  117. #define ISSIGNOINRANGE(signo) \
  118. ( (signo) <= _SIGMAXSIGNO )
  119. typedef struct sigaction SIGACTION;
  120. typedef SIGACTION *PSIGACTION;
  121. //
  122. // Each signal has an associated signal disposition.
  123. // when a handler is dispatched, the blocked signal mask
  124. // of the process is saved (as part of signal dispatch), and
  125. // a new mask is calculated by oring in the BlockMask bits. When
  126. // (if) the signal handler returns, the previous block mask is restored.
  127. //
  128. typedef struct sigaction SIGDISP;
  129. typedef SIGDISP *PSIGDISP;
  130. //
  131. // Each process has a signal database. The process lock of the
  132. // owning process must be held to change information in the
  133. // signal database
  134. //
  135. typedef struct _SIGDB {
  136. sigset_t BlockedSignalMask;
  137. sigset_t PendingSignalMask;
  138. sigset_t SigSuspendMask;
  139. SIGDISP SignalDisposition[_SIGMAXSIGNO];
  140. } SIGDB;
  141. typedef SIGDB *PSIGDB;
  142. typedef enum _PSX_PROCESSSTATE {
  143. Unconnected,
  144. Active,
  145. Stopped,
  146. Exited,
  147. Waiting
  148. } PSX_PROCESSSTATE;
  149. typedef struct _PSX_CONTROLLING_TTY {
  150. LIST_ENTRY Links;
  151. RTL_CRITICAL_SECTION Lock;
  152. //
  153. // There is a reference to this terminal for every file descriptor
  154. // that is open on it and every session that has it as a controlling
  155. // tty.
  156. ULONG ReferenceCount;
  157. pid_t ForegroundProcessGroup;
  158. HANDLE ConsolePort;
  159. HANDLE ConsoleCommPort;
  160. ULONG UniqueId;
  161. PVOID IoBuffer; // mapped in server addr space
  162. struct _PSX_SESSION *Session;
  163. } PSX_CONTROLLING_TTY, *PPSX_CONTROLLING_TTY;
  164. typedef struct _PSX_SESSION {
  165. ULONG ReferenceCount;
  166. PPSX_CONTROLLING_TTY Terminal;
  167. pid_t SessionLeader;
  168. } PSX_SESSION, *PPSX_SESSION;
  169. #define IS_DIRECTORY_PREFIX_REMOTE(p) ( (ULONG_PTR)(p) & 0x1 )
  170. #define MAKE_DIRECTORY_PREFIX_REMOTE(p) ( (PPSX_DIRECTORY_PREFIX)((ULONG_PTR)(p) | 0x1) )
  171. #define MAKE_DIRECTORY_PREFIX_VALID(p) ( (PPSX_DIRECTORY_PREFIX)((ULONG_PTR)(p) & ~0x1) )
  172. typedef struct _PSX_PROCESS {
  173. LIST_ENTRY ClientIdHashLinks;
  174. ULONG Flags;
  175. HANDLE Process;
  176. HANDLE Thread;
  177. HANDLE AlarmTimer;
  178. PSIGNALDELIVERER SignalDeliverer;
  179. PNULLAPICALLER NullApiCaller;
  180. PPSX_DIRECTORY_PREFIX DirectoryPrefix;
  181. ULONG ExitStatus;
  182. mode_t FileModeCreationMask;
  183. FILEDESCRIPTOR ProcessFileTable[OPEN_MAX];
  184. RTL_CRITICAL_SECTION ProcessLock;
  185. PSX_PROCESSSTATE State;
  186. //
  187. // InPsx is a count of the number of times *this* process is in
  188. // the subsystem. For instance, if he calls sigsuspend and blocks,
  189. // the count should be 1. If he then executes a signal handler as
  190. // a result of a signal, and the signal handler makes a syscall, the
  191. // count gets bumped to 2.
  192. //
  193. ULONG InPsx;
  194. PINTCB IntControlBlock;
  195. ULONG SequenceNumber;
  196. uid_t EffectiveUid;
  197. uid_t RealUid;
  198. gid_t EffectiveGid;
  199. gid_t RealGid;
  200. pid_t Pid;
  201. pid_t ParentPid;
  202. pid_t ProcessGroupId;
  203. LIST_ENTRY GroupLinks;
  204. PPSX_SESSION PsxSession;
  205. HANDLE ClientPort;
  206. PCH ClientViewBase;
  207. PCH ClientViewBounds;
  208. CLIENT_ID ClientId;
  209. PEB_PSX_DATA InitialPebPsxData;
  210. BOOLEAN ProcessIsBeingDebugged;
  211. CLIENT_ID DebugUiClientId;
  212. SIGDB SignalDataBase;
  213. struct tms ProcessTimes;
  214. //
  215. // When the posix server needs to make a call on behalf of a client
  216. // that could block, we create a thread to endure the blocking for
  217. // us. This happens when we've execed a windows program and we want
  218. // to know when he exits, and for some blocking sockets calls.
  219. //
  220. HANDLE BlockingThread;
  221. } PSX_PROCESS;
  222. typedef PSX_PROCESS *PPSX_PROCESS;
  223. //
  224. // Valid bits for the PSX_PROCESS 'Flags' word:
  225. //
  226. #define P_FREE 0x00000001 // process slot is free
  227. #define P_HAS_EXECED 0x00000002 // process successfully execed
  228. #define P_FOREIGN_EXEC 0x00000004 // this is a windows program
  229. #define P_SOCKET_BLOCK 0x00000008 // called blocking sockets call
  230. #define P_WAITED 0x00000010 // process has been waited on
  231. #define P_NO_FORK 0x00000020 // process fork forbidden
  232. #define AcquireProcessLock( p ) RtlEnterCriticalSection( &(p)->ProcessLock )
  233. #define ReleaseProcessLock( p ) RtlLeaveCriticalSection( &(p)->ProcessLock )
  234. //
  235. // Process is stoppable if it is not part of an orphaned process group.
  236. //
  237. #define ISPROCESSSTOPABLE(p) (TRUE)
  238. #define ISPOINTERVALID_CLIENT(pprocess, p, length) \
  239. (((ULONG_PTR)(p) >= (ULONG_PTR)(pprocess)->ClientViewBase) && \
  240. ((char *)(p) + (length)) < (pprocess)->ClientViewBounds)
  241. LIST_ENTRY DefaultBlockList;
  242. RTL_CRITICAL_SECTION BlockLock;
  243. //
  244. // The process Table.
  245. //
  246. // This table contains the array of processes. The array is dynamically
  247. // allocated at PSX initialization time. very few operations use a table scan
  248. // to locate processes. Since pids direct map to a process, and since ClientIds
  249. // hash to a process, table scans are only needed to locate groups of processes.
  250. //
  251. // A single lock (PsxProcessStructureLock) guards the process table and
  252. // ClientIdHashTable. This lock is needed to add or delete an entry in the
  253. // PsxProcessTable or ClientIdHashTable.
  254. //
  255. PSX_PROCESS PsxProcessTable[32];
  256. PPSX_PROCESS FirstProcess,LastProcess;
  257. //
  258. // Client Id Hash Table.
  259. //
  260. // Given a client id, the corresponding process is located by indexing into this
  261. // table and then searching the list head at the index.
  262. //
  263. LIST_ENTRY ClientIdHashTable[CIDHASHSIZE];
  264. RTL_CRITICAL_SECTION PsxProcessStructureLock;
  265. #define AcquireProcessStructureLock() RtlEnterCriticalSection( &PsxProcessStructureLock )
  266. #define ReleaseProcessStructureLock() RtlLeaveCriticalSection( &PsxProcessStructureLock )
  267. typedef struct _PSX_EXEC_INFO {
  268. ANSI_STRING Path;
  269. ANSI_STRING CWD;
  270. ANSI_STRING Argv;
  271. ANSI_STRING Envp;
  272. ANSI_STRING LibPath;
  273. } PSX_EXEC_INFO;
  274. typedef PSX_EXEC_INFO *PPSX_EXEC_INFO;
  275. //
  276. // Routines defined in process.c
  277. //
  278. NTSTATUS
  279. PsxInitializeProcess(
  280. IN PPSX_PROCESS NewProcess,
  281. IN PPSX_PROCESS ForkProcess OPTIONAL,
  282. IN ULONG SessionId,
  283. IN HANDLE ProcessHandle,
  284. IN HANDLE ThreadHandle,
  285. IN PPSX_SESSION Session OPTIONAL
  286. );
  287. NTSTATUS
  288. PsxInitializeProcessStructure( VOID );
  289. PPSX_PROCESS
  290. PsxAllocateProcess (
  291. IN PCLIENT_ID ClientId
  292. );
  293. BOOLEAN
  294. PsxCreateProcess(
  295. IN PPSX_EXEC_INFO ExecInfo,
  296. OUT PPSX_PROCESS *NewProcess,
  297. IN HANDLE ParentProc,
  298. IN PPSX_SESSION Session
  299. );
  300. PPSX_PROCESS
  301. PsxLocateProcessByClientId (
  302. IN PCLIENT_ID ClientId
  303. );
  304. PPSX_PROCESS
  305. PsxLocateProcessBySession(
  306. IN PPSX_SESSION Session
  307. );
  308. PPSX_SESSION
  309. PsxLocateSessionByUniqueId(
  310. IN ULONG UniqueId
  311. );
  312. BOOLEAN
  313. PsxStopProcess(
  314. IN PPSX_PROCESS p,
  315. IN PPSX_API_MSG m,
  316. IN ULONG Signal,
  317. IN sigset_t *RestoreBlockSigset OPTIONAL
  318. );
  319. VOID
  320. PsxStopProcessHandler(
  321. IN PPSX_PROCESS p,
  322. IN PINTCB IntControlBlock,
  323. IN PSX_INTERRUPTREASON InterruptReason,
  324. IN int Signal
  325. );
  326. BOOLEAN
  327. PsxInitializeDirectories(
  328. IN PPSX_PROCESS Process,
  329. IN PANSI_STRING pCwd
  330. );
  331. BOOLEAN
  332. PsxPropagateDirectories(
  333. IN PPSX_PROCESS Process
  334. );
  335. //
  336. // Routines defined in procblk.c
  337. //
  338. NTSTATUS
  339. BlockProcess(
  340. IN PPSX_PROCESS p,
  341. IN PVOID Context,
  342. IN INTHANDLER Handler,
  343. IN PPSX_API_MSG m,
  344. IN PLIST_ENTRY BlockList OPTIONAL,
  345. IN PRTL_CRITICAL_SECTION CriticalSectionToRelease OPTIONAL
  346. );
  347. BOOLEAN
  348. UnblockProcess(
  349. IN PPSX_PROCESS p,
  350. IN PSX_INTERRUPTREASON InterruptReason,
  351. IN BOOLEAN BlockLockHeld,
  352. IN int Signal // or 0 if not awakened by signal
  353. );
  354. //
  355. // Routines defined in srvinit.c
  356. //
  357. NTSTATUS
  358. PsxInitializeIO( VOID );
  359. //
  360. // Routines defined in sigsup.c
  361. //
  362. int
  363. PsxCheckPendingSignals(
  364. IN PPSX_PROCESS p
  365. );
  366. VOID
  367. PsxTerminateProcessBySignal(
  368. IN PPSX_PROCESS p,
  369. IN PPSX_API_MSG m,
  370. IN ULONG Signal
  371. );
  372. VOID
  373. PsxDeliverSignal(
  374. IN PPSX_PROCESS p,
  375. IN ULONG Signal,
  376. IN sigset_t *RestoreBlockSigset OPTIONAL
  377. );
  378. VOID
  379. PsxSigSuspendHandler(
  380. IN PPSX_PROCESS p,
  381. IN PINTCB IntControlBlock,
  382. IN PSX_INTERRUPTREASON InterruptReason,
  383. IN int Signal
  384. );
  385. VOID
  386. PsxSignalProcess(
  387. IN PPSX_PROCESS p,
  388. IN ULONG Signal
  389. );
  390. VOID
  391. Exit (
  392. IN PPSX_PROCESS p,
  393. IN ULONG ExitStatus
  394. );
  395. //
  396. // Psx Session Primitives
  397. //
  398. PPSX_SESSION
  399. PsxAllocateSession(
  400. IN PPSX_CONTROLLING_TTY Terminal OPTIONAL,
  401. IN pid_t SessionLeader
  402. );
  403. VOID
  404. PsxDeallocateSession(
  405. IN PPSX_SESSION Session
  406. );
  407. //
  408. // Psx Session Macros
  409. //
  410. #define REFERENCE_PSX_SESSION(ppsxsession) \
  411. RtlEnterCriticalSection(&PsxNtSessionLock); \
  412. (ppsxsession)->ReferenceCount++; \
  413. RtlLeaveCriticalSection(&PsxNtSessionLock)
  414. //
  415. // Dereferences the session. If reference count goes to zero, the session
  416. // is deallocated.
  417. //
  418. #define DEREFERENCE_PSX_SESSION(ppsxsession, status) \
  419. RtlEnterCriticalSection(&PsxNtSessionLock); \
  420. if (--((ppsxsession)->ReferenceCount) == 0) { \
  421. PsxTerminateConSession((ppsxsession), (status));\
  422. PsxDeallocateSession((ppsxsession)); \
  423. } else { \
  424. RtlLeaveCriticalSection(&PsxNtSessionLock); \
  425. }
  426. //
  427. // Routines defined in sbapi.c
  428. //
  429. BOOLEAN
  430. PsxSbCreateSession(
  431. IN PSBAPIMSG Msg
  432. );
  433. BOOLEAN
  434. PsxSbTerminateSession(
  435. IN PSBAPIMSG Msg
  436. );
  437. BOOLEAN
  438. PsxSbForeignSessionComplete(
  439. IN PSBAPIMSG Msg
  440. );
  441. //
  442. // Routines defined in sbinit.c
  443. //
  444. NTSTATUS PsxSbApiPortInitialize ( VOID );
  445. //
  446. // Routines defined in sbreqst.c
  447. //
  448. typedef BOOLEAN (*PSB_API_ROUTINE)( IN PSBAPIMSG SbApiMsg );
  449. NTSTATUS
  450. PsxSbApiRequestThread(
  451. IN PVOID Parameter
  452. );
  453. //
  454. // Routines defined in coninit.c
  455. //
  456. NTSTATUS
  457. PsxInitializeConsolePort( VOID );
  458. NTSTATUS
  459. PsxCreateDirectoryObject( PUNICODE_STRING pUnicodeDirectoryName );
  460. //
  461. // Routines defined in conthrds.c
  462. //
  463. NTSTATUS
  464. PsxSessionRequestThread(
  465. IN PVOID Parameter
  466. );
  467. //
  468. // Routines defined in concreat.c
  469. //
  470. VOID SetDefaultLibPath(
  471. OUT PANSI_STRING LibPath,
  472. IN PCHAR EnvStrings
  473. );
  474. NTSTATUS
  475. PsxCreateConSession(
  476. IN OUT PVOID RequestMsg
  477. );
  478. //
  479. // Routines defined in consignl.c
  480. //
  481. NTSTATUS
  482. PsxCtrlSignalHandler(
  483. IN OUT PVOID RequestMsg
  484. );
  485. NTSTATUS
  486. PsxTerminateConSession(
  487. IN PPSX_SESSION Session,
  488. IN ULONG ExitStatus
  489. );
  490. //
  491. // Routines defined in session.c
  492. //
  493. RTL_CRITICAL_SECTION PsxNtSessionLock;
  494. #define LockNtSessionList() RtlEnterCriticalSection( &PsxNtSessionLock )
  495. #define UnlockNtSessionList() RtlLeaveCriticalSection( &PsxNtSessionLock )
  496. NTSTATUS
  497. PsxInitializeNtSessionList( VOID );
  498. //
  499. // Routines defined in apiinit.c
  500. //
  501. NTSTATUS PsxApiPortInitialize ( VOID );
  502. //
  503. // Global data accessed by Client-Server Runtime Server
  504. //
  505. PVOID PsxHeap;
  506. #define PSX_SS_ROOT_OBJECT_DIRECTORY L"\\PSXSS"
  507. #define PSX_SS_SBAPI_PORT_NAME L"\\PSXSS\\SbApiPort"
  508. UNICODE_STRING PsxApiPortName;
  509. ANSI_STRING PsxSbApiPortName;
  510. UNICODE_STRING PsxSbApiPortName_U;
  511. STRING PsxRootDirectoryName;
  512. HANDLE PsxRootDirectory;
  513. HANDLE PsxApiPort;
  514. HANDLE PsxSbApiPort;
  515. HANDLE PsxSmApiPort;
  516. ULONG PsxNumberApiRequestThreads;
  517. /*
  518. * Port and threads for Console Session globals.
  519. */
  520. HANDLE PsxSessionPort;
  521. HANDLE PsxSessionRequestThreadHandle;
  522. #define PSX_SS_SBAPI_REQUEST_THREAD 0
  523. #define PSX_SS_FIRST_API_REQUEST_THREAD 1
  524. #define PSX_SS_MAX_THREADS 64
  525. HANDLE PsxServerThreadHandles[ PSX_SS_MAX_THREADS ];
  526. CLIENT_ID PsxServerThreadClientIds[ PSX_SS_MAX_THREADS ];
  527. //
  528. // file descriptor IO types constants and data structures
  529. //
  530. #define IONODEHASHSIZE 256
  531. #define SERIALNUMBERTOHASHINDEX(DeviceSerialNumber,FileSerialNumber) (\
  532. (FileSerialNumber) & (IONODEHASHSIZE-1) )
  533. //
  534. // IoRoutines
  535. //
  536. //
  537. // This function is called when a new handle is created as a result of
  538. // an open
  539. //
  540. typedef
  541. BOOLEAN
  542. (*PPSXOPEN_NEW_HANDLE_ROUTINE) (
  543. IN PPSX_PROCESS p,
  544. IN PFILEDESCRIPTOR Fd,
  545. IN PPSX_API_MSG m
  546. );
  547. //
  548. // This function is called when a new handle is created as a result of
  549. // a pipe, dup, or fork
  550. //
  551. typedef
  552. VOID
  553. (*PPSXNEW_HANDLE_ROUTINE) (
  554. IN PPSX_PROCESS p,
  555. IN PFILEDESCRIPTOR Fd
  556. );
  557. //
  558. // This function is called whever a handle is closed (close, exec, _exit)
  559. //
  560. typedef
  561. VOID
  562. (*PPSXCLOSE_ROUTINE) (
  563. IN PPSX_PROCESS p,
  564. IN PFILEDESCRIPTOR Fd
  565. );
  566. typedef
  567. VOID
  568. (*PPSXLAST_CLOSE_ROUTINE) (
  569. IN PPSX_PROCESS p,
  570. IN struct _SYSTEMOPENFILE *SystemOpenFile
  571. );
  572. struct _IONODE;
  573. typedef
  574. VOID
  575. (*PPSXIONODE_CLOSE_ROUTINE) (
  576. IN struct _IONODE *IoNode
  577. );
  578. //
  579. // This function is called to do a read
  580. //
  581. typedef
  582. BOOLEAN
  583. (*PPSXREAD_ROUTINE) (
  584. IN PPSX_PROCESS p,
  585. IN OUT PPSX_API_MSG m,
  586. IN PFILEDESCRIPTOR Fd
  587. );
  588. //
  589. // This function is called to do a write
  590. //
  591. typedef
  592. BOOLEAN
  593. (*PPSXWRITE_ROUTINE) (
  594. IN PPSX_PROCESS p,
  595. IN OUT PPSX_API_MSG m,
  596. IN PFILEDESCRIPTOR Fd
  597. );
  598. //
  599. // This function is called to do a dup or dup2
  600. //
  601. typedef
  602. BOOLEAN
  603. (*PPSXDUP_ROUTINE) (
  604. IN PPSX_PROCESS p,
  605. IN OUT PPSX_API_MSG m,
  606. IN PFILEDESCRIPTOR Fd,
  607. IN PFILEDESCRIPTOR FdDup
  608. );
  609. //
  610. // This function is called to do a Lseek
  611. //
  612. typedef
  613. BOOLEAN
  614. (*PPSXLSEEK_ROUTINE) (
  615. IN PPSX_PROCESS p,
  616. IN OUT PPSX_API_MSG m,
  617. IN PFILEDESCRIPTOR Fd
  618. );
  619. //
  620. // This function is called to fill in an Ionode so that a call to
  621. // stat or fstat can be completed.
  622. //
  623. typedef
  624. BOOLEAN
  625. (*PPSXSTAT_ROUTINE) (
  626. IN struct _IONODE *IoNode,
  627. IN HANDLE FileHandle,
  628. OUT struct stat *StatBuf,
  629. OUT NTSTATUS *pStatus
  630. );
  631. typedef struct _PSXIO_VECTORS {
  632. PPSXOPEN_NEW_HANDLE_ROUTINE OpenNewHandleRoutine;
  633. PPSXNEW_HANDLE_ROUTINE NewHandleRoutine;
  634. PPSXCLOSE_ROUTINE CloseRoutine;
  635. PPSXLAST_CLOSE_ROUTINE LastCloseRoutine;
  636. PPSXIONODE_CLOSE_ROUTINE IoNodeCloseRoutine;
  637. PPSXREAD_ROUTINE ReadRoutine;
  638. PPSXWRITE_ROUTINE WriteRoutine;
  639. PPSXDUP_ROUTINE DupRoutine;
  640. PPSXLSEEK_ROUTINE LseekRoutine;
  641. PPSXSTAT_ROUTINE StatRoutine;
  642. } PSXIO_VECTORS, *PPSXIO_VECTORS;
  643. BOOLEAN
  644. IoOpenNewHandle (
  645. IN PPSX_PROCESS p,
  646. IN PFILEDESCRIPTOR Fd,
  647. IN PPSX_API_MSG m
  648. );
  649. VOID
  650. IoNewHandle (
  651. IN PPSX_PROCESS p,
  652. IN PFILEDESCRIPTOR Fd
  653. );
  654. VOID
  655. IoClose (
  656. IN PPSX_PROCESS p,
  657. IN PFILEDESCRIPTOR Fd
  658. );
  659. VOID
  660. IoLastClose (
  661. IN PPSX_PROCESS p,
  662. IN struct _SYSTEMOPENFILE *SystemOpenFile
  663. );
  664. //
  665. // Each unique open file in the system results in the creation of an Input
  666. // Output Node (IONODE). Multiple opens in the same file may result in
  667. // different file descriptors and system open files, but as long as they refer
  668. // to the same file, only one IONODE will be created. IONODES track the the
  669. // status of a file and keep track of its owner, mode, times. A single lock
  670. // (IoNodeLock) guards all reference count operations on IONODES. A hash table
  671. // IoNodeHashTable is capable of locating an IONODE based on the device and
  672. // inode number of the file the IONODE is refered to. IONODEs are created on
  673. // file open. Once the file is opened, a query of the file is made to
  674. // determine its device and inode number. An IONODE is searched for in the
  675. // InNodeHashTable, if one is found, then its reference count is incremented,
  676. // otherwise one is created and initialized.
  677. //
  678. typedef struct _IONODE {
  679. LIST_ENTRY IoNodeHashLinks;
  680. RTL_CRITICAL_SECTION IoNodeLock;
  681. ULONG ReferenceCount;
  682. //
  683. // The file mode is created during file open.
  684. // The protection portion of the mode is created by reading the file's
  685. // SECURITY_DESCRIPTOR and collapsing it into POSIX rwxrwxrwx values.
  686. //
  687. // The file type portion is created using the file attributes, device type,
  688. // and extended attributes of a file
  689. //
  690. mode_t Mode;
  691. //
  692. // For regular files,
  693. // DeviceSerialNumber == Counter. Per filesystem number that does
  694. // not conflict w/ device type.
  695. // FileSerialNumber == IndexNumber
  696. // For device files
  697. // DeviceSerialNumber == DeviceType
  698. // FileSerialNumber == Device Object Address (IndexNumber ?)
  699. //
  700. dev_t DeviceSerialNumber;
  701. ULONG_PTR FileSerialNumber;
  702. uid_t OwnerId;
  703. gid_t GroupId;
  704. //
  705. // The time fields are magical. When the file is opened, the access time
  706. // and modified times returned from the file system are stored in the
  707. // IONODE. The change time is set equal to the modified time. Each Psx
  708. // IONODE operation sets the appropriate time fields.
  709. //
  710. time_t AccessDataTime;
  711. time_t ModifyDataTime;
  712. time_t ModifyIoNodeTime;
  713. //
  714. // The Io Vectors
  715. //
  716. PVOID Context;
  717. PPSXIO_VECTORS IoVectors;
  718. //
  719. // File record locks, sorted by the starting position of the lock.
  720. // See fcntl(). And a list of those processes blocked while locking
  721. // a region (with F_SETLKW).
  722. //
  723. LIST_ENTRY Flocks;
  724. LIST_ENTRY Waiters;
  725. // Length of path to ionode, if applicable. For fpathconf(PATH_MAX).
  726. ULONG PathLength;
  727. //
  728. // If the file has been unlinked or renamed over while still open,
  729. // we move it to the junkyard and set the "junked" flag. When the
  730. // last close occurs for this file, it should be deleted.
  731. //
  732. BOOLEAN Junked;
  733. } IONODE, *PIONODE;
  734. //
  735. // Each unique open of a file results in the creation of a system open file.
  736. // These descriptors are dynamically allocated. There is no limit on the number
  737. // of these in the system. Dups of file descriptors, or forking result in a
  738. // reference count increment, not a new system open file. Only explicit opens,
  739. // creates, or pipe() calls result in a new system open file. A global lock
  740. // (SystemOpenFileLock) guards all reference count adjustments. As long as a
  741. // reference exists, all fields in this structure can be used without any
  742. // locking.
  743. //
  744. typedef struct _SYSTEMOPENFILE {
  745. ULONG HandleCount;
  746. ULONG ReadHandleCount;
  747. ULONG WriteHandleCount;
  748. HANDLE NtIoHandle;
  749. PIONODE IoNode;
  750. ULONG Flags; // file description flags
  751. //
  752. // If a file descriptor is open on a console, we need to keep a
  753. // reference to that console so we can do io even if the process
  754. // changes sessions. 'Terminal' is the reference.
  755. //
  756. PPSX_CONTROLLING_TTY Terminal;
  757. } SYSTEMOPENFILE;
  758. typedef SYSTEMOPENFILE *PSYSTEMOPENFILE;
  759. //
  760. // Flags for SYSTEMOPENFILE.Flags
  761. //
  762. #define PSX_FD_READ 0x00000001
  763. #define PSX_FD_WRITE 0x00000002
  764. #define PSX_FD_NOBLOCK 0x00000004
  765. #define PSX_FD_APPEND 0x00000008
  766. extern RTL_CRITICAL_SECTION SystemOpenFileLock;
  767. extern RTL_CRITICAL_SECTION IoNodeHashTableLock;
  768. extern LIST_ENTRY IoNodeHashTable[];
  769. //
  770. // IoNode Primitives
  771. //
  772. BOOLEAN
  773. ReferenceOrCreateIoNode (
  774. IN dev_t DeviceSerialNumber,
  775. IN ULONG_PTR FileSerialNumber,
  776. IN BOOLEAN FindOnly,
  777. OUT PIONODE *IoNode
  778. );
  779. BOOLEAN
  780. LocateIoNode (
  781. IN HANDLE FileHandle,
  782. OUT PIONODE *IoNode
  783. );
  784. VOID
  785. DereferenceIoNode (
  786. IN PIONODE IoNode
  787. );
  788. //
  789. // Fd Primitives
  790. //
  791. PFILEDESCRIPTOR
  792. AllocateFd(
  793. IN PPSX_PROCESS p,
  794. IN ULONG Start,
  795. OUT PULONG Index
  796. );
  797. BOOLEAN
  798. DeallocateFd(
  799. IN PPSX_PROCESS p,
  800. IN ULONG Index
  801. );
  802. PFILEDESCRIPTOR
  803. FdIndexToFd(
  804. IN PPSX_PROCESS p,
  805. IN ULONG Index
  806. );
  807. //
  808. // System Open File Primitives
  809. //
  810. PSYSTEMOPENFILE
  811. AllocateSystemOpenFile();
  812. VOID
  813. DeallocateSystemOpenFile(
  814. IN PPSX_PROCESS p,
  815. IN PSYSTEMOPENFILE SystemOpenFile
  816. );
  817. //
  818. // System Open File Macros
  819. //
  820. #define REFERENCE_SYSTEMOPENFILE(systemopenfile) \
  821. RtlEnterCriticalSection(&SystemOpenFileLock); \
  822. (systemopenfile)->HandleCount++; \
  823. RtlLeaveCriticalSection(&SystemOpenFileLock)
  824. VOID
  825. ForkProcessFileTable(
  826. IN PPSX_PROCESS ForkProcess,
  827. IN PPSX_PROCESS NewProcess
  828. );
  829. VOID
  830. ExecProcessFileTable(
  831. IN PPSX_PROCESS p
  832. );
  833. VOID
  834. CloseProcessFileTable(
  835. IN PPSX_PROCESS p
  836. );
  837. //
  838. // Per-Device Type Io structures, types... Filesystems
  839. // are numbered 'A'..'Z'.
  840. //
  841. #define PSX_LOCAL_PIPE 1
  842. #define PSX_CONSOLE_DEV 2
  843. #define PSX_NULL_DEV 3
  844. //
  845. // Local Pipes
  846. //
  847. typedef struct _LOCAL_PIPE {
  848. ULONG ReadHandleCount;
  849. ULONG WriteHandleCount;
  850. LIST_ENTRY WaitingWriters;
  851. LIST_ENTRY WaitingReaders;
  852. RTL_CRITICAL_SECTION CriticalSection;
  853. LONG BufferSize;
  854. LONG DataInPipe;
  855. PUCHAR WritePointer;
  856. PUCHAR ReadPointer;
  857. UCHAR Buffer[PIPE_BUF];
  858. } LOCAL_PIPE, *PLOCAL_PIPE;
  859. extern PSXIO_VECTORS LocalPipeVectors;
  860. extern PSXIO_VECTORS NamedPipeVectors;
  861. VOID
  862. InitializeLocalPipe(
  863. IN PLOCAL_PIPE Pipe
  864. );
  865. //
  866. // Files
  867. //
  868. extern PSXIO_VECTORS FileVectors;
  869. //
  870. // Console
  871. //
  872. extern PSXIO_VECTORS ConVectors;
  873. //
  874. // Null device
  875. //
  876. extern PSXIO_VECTORS NullVectors;
  877. NTSTATUS
  878. PsxApiHandleConnectionRequest(
  879. IN PPSX_API_MSG Message
  880. );
  881. BOOLEAN
  882. PendingSignalHandledInside(
  883. IN PPSX_PROCESS p,
  884. IN PPSX_API_MSG m,
  885. IN sigset_t *RestoreBlockSigset OPTIONAL
  886. );
  887. NTSTATUS
  888. PsxApiRequestThread(
  889. IN PVOID ThreadParameter
  890. );
  891. VOID
  892. ApiReply(
  893. IN PPSX_PROCESS p,
  894. IN PPSX_API_MSG m,
  895. IN sigset_t *RestoreBlockSigset OPTIONAL
  896. );
  897. ULONG
  898. PsxDetermineFileClass(
  899. IN HANDLE FileHandle
  900. );
  901. ULONG
  902. PsxStatusToErrno(
  903. IN NTSTATUS Status
  904. );
  905. ULONG
  906. PsxStatusToErrnoPath(
  907. IN PUNICODE_STRING Path
  908. );
  909. //
  910. // Stuff for file record locking
  911. //
  912. typedef struct _SYSFLOCK {
  913. LIST_ENTRY Links;
  914. SHORT Type; // F_RDLCK or F_WRLCK
  915. SHORT Whence; // SEEK_SET, etc.
  916. off_t Start; // Starting offset
  917. off_t Len; // Length of region
  918. pid_t Pid; // Pid of lock owner
  919. } SYSFLOCK, *PSYSFLOCK;
  920. //
  921. // hack types
  922. //
  923. typedef struct _SYSTEMMSG {
  924. LIST_ENTRY Links;
  925. PORT_MESSAGE PortMsg;
  926. } SYSTEMMSG, *PSYSTEMMSG;
  927. typedef
  928. BOOLEAN
  929. (* PPSX_API_ROUTINE)(
  930. IN PPSX_PROCESS p,
  931. IN PPSX_API_MSG m
  932. );
  933. //
  934. // Api Prototypes
  935. //
  936. BOOLEAN
  937. PsxFork(
  938. IN PPSX_PROCESS p,
  939. IN PPSX_API_MSG m
  940. );
  941. BOOLEAN
  942. PsxExec(
  943. IN PPSX_PROCESS p,
  944. IN PPSX_API_MSG m
  945. );
  946. BOOLEAN
  947. PsxWaitPid(
  948. IN PPSX_PROCESS p,
  949. IN PPSX_API_MSG m
  950. );
  951. BOOLEAN
  952. PsxExit(
  953. IN PPSX_PROCESS p,
  954. IN PPSX_API_MSG m
  955. );
  956. BOOLEAN
  957. PsxKill(
  958. IN PPSX_PROCESS p,
  959. IN PPSX_API_MSG m
  960. );
  961. BOOLEAN
  962. PsxSigAction(
  963. IN PPSX_PROCESS p,
  964. IN PPSX_API_MSG m
  965. );
  966. BOOLEAN
  967. PsxSigProcMask(
  968. IN PPSX_PROCESS p,
  969. IN PPSX_API_MSG m
  970. );
  971. BOOLEAN
  972. PsxSigPending(
  973. IN PPSX_PROCESS p,
  974. IN PPSX_API_MSG m
  975. );
  976. BOOLEAN
  977. PsxSigSuspend(
  978. IN PPSX_PROCESS p,
  979. IN PPSX_API_MSG m
  980. );
  981. BOOLEAN
  982. PsxAlarm(
  983. IN PPSX_PROCESS p,
  984. IN PPSX_API_MSG m
  985. );
  986. BOOLEAN
  987. PsxSleep(
  988. IN PPSX_PROCESS p,
  989. IN PPSX_API_MSG m
  990. );
  991. BOOLEAN
  992. PsxGetIds(
  993. IN PPSX_PROCESS p,
  994. IN PPSX_API_MSG m
  995. );
  996. BOOLEAN
  997. PsxSetUid(
  998. IN PPSX_PROCESS p,
  999. IN PPSX_API_MSG m
  1000. );
  1001. BOOLEAN
  1002. PsxSetGid(
  1003. IN PPSX_PROCESS p,
  1004. IN PPSX_API_MSG m
  1005. );
  1006. BOOLEAN
  1007. PsxGetGroups(
  1008. IN PPSX_PROCESS p,
  1009. IN PPSX_API_MSG m
  1010. );
  1011. BOOLEAN
  1012. PsxGetLogin(
  1013. IN PPSX_PROCESS p,
  1014. IN PPSX_API_MSG m
  1015. );
  1016. BOOLEAN
  1017. PsxCUserId(
  1018. IN PPSX_PROCESS p,
  1019. IN PPSX_API_MSG m
  1020. );
  1021. BOOLEAN
  1022. PsxSetSid(
  1023. IN PPSX_PROCESS p,
  1024. IN PPSX_API_MSG m
  1025. );
  1026. BOOLEAN
  1027. PsxSetPGroupId(
  1028. IN PPSX_PROCESS p,
  1029. IN PPSX_API_MSG m
  1030. );
  1031. BOOLEAN
  1032. PsxUname(
  1033. IN PPSX_PROCESS p,
  1034. IN PPSX_API_MSG m
  1035. );
  1036. BOOLEAN
  1037. PsxTime(
  1038. IN PPSX_PROCESS p,
  1039. IN PPSX_API_MSG m
  1040. );
  1041. BOOLEAN
  1042. PsxGetProcessTimes(
  1043. IN PPSX_PROCESS p,
  1044. IN PPSX_API_MSG m
  1045. );
  1046. BOOLEAN
  1047. PsxTtyName(
  1048. IN PPSX_PROCESS p,
  1049. IN PPSX_API_MSG m
  1050. );
  1051. BOOLEAN
  1052. PsxIsatty(
  1053. IN PPSX_PROCESS p,
  1054. IN PPSX_API_MSG m
  1055. );
  1056. BOOLEAN
  1057. PsxSysconf(
  1058. IN PPSX_PROCESS p,
  1059. IN PPSX_API_MSG m
  1060. );
  1061. BOOLEAN
  1062. PsxOpenDir(
  1063. IN PPSX_PROCESS p,
  1064. IN PPSX_API_MSG m
  1065. );
  1066. BOOLEAN
  1067. PsxReadDir(
  1068. IN PPSX_PROCESS p,
  1069. IN PPSX_API_MSG m
  1070. );
  1071. BOOLEAN
  1072. PsxRewindDir(
  1073. IN PPSX_PROCESS p,
  1074. IN PPSX_API_MSG m
  1075. );
  1076. BOOLEAN
  1077. PsxCloseDir(
  1078. IN PPSX_PROCESS p,
  1079. IN PPSX_API_MSG m
  1080. );
  1081. BOOLEAN
  1082. PsxChDir(
  1083. IN PPSX_PROCESS p,
  1084. IN PPSX_API_MSG m
  1085. );
  1086. BOOLEAN
  1087. PsxGetCwd(
  1088. IN PPSX_PROCESS p,
  1089. IN PPSX_API_MSG m
  1090. );
  1091. BOOLEAN
  1092. PsxOpen(
  1093. IN PPSX_PROCESS p,
  1094. IN PPSX_API_MSG m
  1095. );
  1096. BOOLEAN
  1097. PsxCreat(
  1098. IN PPSX_PROCESS p,
  1099. IN PPSX_API_MSG m
  1100. );
  1101. BOOLEAN
  1102. PsxUmask(
  1103. IN PPSX_PROCESS p,
  1104. IN PPSX_API_MSG m
  1105. );
  1106. BOOLEAN
  1107. PsxLink(
  1108. IN PPSX_PROCESS p,
  1109. IN PPSX_API_MSG m
  1110. );
  1111. BOOLEAN
  1112. PsxMkDir(
  1113. IN PPSX_PROCESS p,
  1114. IN PPSX_API_MSG m
  1115. );
  1116. BOOLEAN
  1117. PsxMkFifo(
  1118. IN PPSX_PROCESS p,
  1119. IN PPSX_API_MSG m
  1120. );
  1121. BOOLEAN
  1122. PsxRmDir(
  1123. IN PPSX_PROCESS p,
  1124. IN PPSX_API_MSG m
  1125. );
  1126. BOOLEAN
  1127. PsxRename(
  1128. IN PPSX_PROCESS p,
  1129. IN PPSX_API_MSG m
  1130. );
  1131. BOOLEAN
  1132. PsxStat(
  1133. IN PPSX_PROCESS p,
  1134. IN PPSX_API_MSG m
  1135. );
  1136. BOOLEAN
  1137. PsxFStat(
  1138. IN PPSX_PROCESS p,
  1139. IN PPSX_API_MSG m
  1140. );
  1141. BOOLEAN
  1142. PsxAccess(
  1143. IN PPSX_PROCESS p,
  1144. IN PPSX_API_MSG m
  1145. );
  1146. BOOLEAN
  1147. PsxChmod(
  1148. IN PPSX_PROCESS p,
  1149. IN PPSX_API_MSG m
  1150. );
  1151. BOOLEAN
  1152. PsxChown(
  1153. IN PPSX_PROCESS p,
  1154. IN PPSX_API_MSG m
  1155. );
  1156. BOOLEAN
  1157. PsxUtime(
  1158. IN PPSX_PROCESS p,
  1159. IN PPSX_API_MSG m
  1160. );
  1161. BOOLEAN
  1162. PsxPathConf(
  1163. IN PPSX_PROCESS p,
  1164. IN PPSX_API_MSG m
  1165. );
  1166. BOOLEAN
  1167. PsxFPathConf(
  1168. IN PPSX_PROCESS p,
  1169. IN PPSX_API_MSG m
  1170. );
  1171. BOOLEAN
  1172. PsxPipe(
  1173. IN PPSX_PROCESS p,
  1174. IN PPSX_API_MSG m
  1175. );
  1176. BOOLEAN
  1177. PsxClose(
  1178. IN PPSX_PROCESS p,
  1179. IN PPSX_API_MSG m
  1180. );
  1181. BOOLEAN
  1182. PsxRead(
  1183. IN PPSX_PROCESS p,
  1184. IN PPSX_API_MSG m
  1185. );
  1186. BOOLEAN
  1187. PsxWrite(
  1188. IN PPSX_PROCESS p,
  1189. IN PPSX_API_MSG m
  1190. );
  1191. BOOLEAN
  1192. PsxFcntl(
  1193. IN PPSX_PROCESS p,
  1194. IN PPSX_API_MSG m
  1195. );
  1196. BOOLEAN
  1197. PsxDup(
  1198. IN PPSX_PROCESS p,
  1199. IN PPSX_API_MSG m
  1200. );
  1201. BOOLEAN
  1202. PsxDup2(
  1203. IN PPSX_PROCESS p,
  1204. IN PPSX_API_MSG m
  1205. );
  1206. BOOLEAN
  1207. PsxLseek(
  1208. IN PPSX_PROCESS p,
  1209. IN PPSX_API_MSG m
  1210. );
  1211. BOOLEAN
  1212. PsxTcGetAttr(
  1213. IN PPSX_PROCESS p,
  1214. IN PPSX_API_MSG m
  1215. );
  1216. BOOLEAN
  1217. PsxTcSetAttr(
  1218. IN PPSX_PROCESS p,
  1219. IN PPSX_API_MSG m
  1220. );
  1221. BOOLEAN
  1222. PsxTcSendBreak(
  1223. IN PPSX_PROCESS p,
  1224. IN PPSX_API_MSG m
  1225. );
  1226. BOOLEAN
  1227. PsxTcDrain(
  1228. IN PPSX_PROCESS p,
  1229. IN PPSX_API_MSG m
  1230. );
  1231. BOOLEAN
  1232. PsxTcFlush(
  1233. IN PPSX_PROCESS p,
  1234. IN PPSX_API_MSG m
  1235. );
  1236. BOOLEAN
  1237. PsxTcFlow(
  1238. IN PPSX_PROCESS p,
  1239. IN PPSX_API_MSG m
  1240. );
  1241. BOOLEAN
  1242. PsxTcGetPGrp(
  1243. IN PPSX_PROCESS p,
  1244. IN PPSX_API_MSG m
  1245. );
  1246. BOOLEAN
  1247. PsxTcSetPGrp(
  1248. IN PPSX_PROCESS p,
  1249. IN PPSX_API_MSG m
  1250. );
  1251. BOOLEAN
  1252. PsxGetPwUid(
  1253. IN PPSX_PROCESS p,
  1254. IN PPSX_API_MSG m
  1255. );
  1256. BOOLEAN
  1257. PsxGetPwNam(
  1258. IN PPSX_PROCESS p,
  1259. IN PPSX_API_MSG m
  1260. );
  1261. BOOLEAN
  1262. PsxGetGrGid(
  1263. IN PPSX_PROCESS p,
  1264. IN PPSX_API_MSG m
  1265. );
  1266. BOOLEAN
  1267. PsxGetGrNam(
  1268. IN PPSX_PROCESS p,
  1269. IN PPSX_API_MSG m
  1270. );
  1271. BOOLEAN
  1272. PsxUnlink(
  1273. IN PPSX_PROCESS p,
  1274. IN PPSX_API_MSG m
  1275. );
  1276. BOOLEAN
  1277. PsxFtruncate(
  1278. IN PPSX_PROCESS p,
  1279. IN PPSX_API_MSG m
  1280. );
  1281. BOOLEAN
  1282. PsxNull(
  1283. IN PPSX_PROCESS p,
  1284. IN PPSX_API_MSG m
  1285. );
  1286. #ifdef PSX_SOCKET
  1287. BOOLEAN
  1288. PsxSocket(
  1289. IN PPSX_PROCESS p,
  1290. IN PPSX_API_MSG m
  1291. );
  1292. BOOLEAN
  1293. PsxAccept(
  1294. IN PPSX_PROCESS p,
  1295. IN PPSX_API_MSG m
  1296. );
  1297. BOOLEAN
  1298. PsxBind(
  1299. IN PPSX_PROCESS p,
  1300. IN PPSX_API_MSG m
  1301. );
  1302. BOOLEAN
  1303. PsxConnect(
  1304. IN PPSX_PROCESS p,
  1305. IN PPSX_API_MSG m
  1306. );
  1307. BOOLEAN
  1308. PsxGetPeerName(
  1309. IN PPSX_PROCESS p,
  1310. IN PPSX_API_MSG m
  1311. );
  1312. BOOLEAN
  1313. PsxGetSockName(
  1314. IN PPSX_PROCESS p,
  1315. IN PPSX_API_MSG m
  1316. );
  1317. BOOLEAN
  1318. PsxGetSockOpt(
  1319. IN PPSX_PROCESS p,
  1320. IN PPSX_API_MSG m
  1321. );
  1322. BOOLEAN
  1323. PsxListen(
  1324. IN PPSX_PROCESS p,
  1325. IN PPSX_API_MSG m
  1326. );
  1327. BOOLEAN
  1328. PsxRecv(
  1329. IN PPSX_PROCESS p,
  1330. IN PPSX_API_MSG m
  1331. );
  1332. BOOLEAN
  1333. PsxRecvFrom(
  1334. IN PPSX_PROCESS p,
  1335. IN PPSX_API_MSG m
  1336. );
  1337. BOOLEAN
  1338. PsxSend(
  1339. IN PPSX_PROCESS p,
  1340. IN PPSX_API_MSG m
  1341. );
  1342. BOOLEAN
  1343. PsxSendTo(
  1344. IN PPSX_PROCESS p,
  1345. IN PPSX_API_MSG m
  1346. );
  1347. BOOLEAN
  1348. PsxSetSockOpt(
  1349. IN PPSX_PROCESS p,
  1350. IN PPSX_API_MSG m
  1351. );
  1352. BOOLEAN
  1353. PsxShutdown(
  1354. IN PPSX_PROCESS p,
  1355. IN PPSX_API_MSG m
  1356. );
  1357. #endif // PSX_SOCKET
  1358. PVOID
  1359. PsxViewSessionData(
  1360. IN ULONG SessionId,
  1361. OUT PHANDLE Section
  1362. );
  1363. ULONG
  1364. GetOffsetBySid(
  1365. PSID Sid
  1366. );
  1367. PSID
  1368. GetSidByOffset(
  1369. ULONG Offset
  1370. );
  1371. VOID
  1372. MapSidToOffset(
  1373. PSID Sid,
  1374. ULONG Offset
  1375. );
  1376. VOID
  1377. InitSidList(
  1378. VOID
  1379. );
  1380. VOID
  1381. ModeToAccessMask(
  1382. mode_t Mode,
  1383. PACCESS_MASK UserAccess,
  1384. PACCESS_MASK GroupAccess,
  1385. PACCESS_MASK OtherAccess
  1386. );
  1387. mode_t
  1388. AccessMaskToMode(
  1389. ACCESS_MASK UserAccess,
  1390. ACCESS_MASK GroupAccess,
  1391. ACCESS_MASK OtherAccess
  1392. );
  1393. VOID
  1394. AlarmThreadRoutine(
  1395. VOID
  1396. );
  1397. HANDLE AlarmThreadHandle;
  1398. PSID
  1399. MakeSid(
  1400. PSID DomainSid,
  1401. ULONG RelativeId
  1402. );
  1403. VOID
  1404. EndImpersonation(
  1405. VOID
  1406. );
  1407. uid_t
  1408. MakePosixId(
  1409. PSID Sid
  1410. );
  1411. NTSTATUS
  1412. RtlInterpretPosixAcl(
  1413. IN ULONG AclRevision,
  1414. IN PSID UserSid,
  1415. IN PSID GroupSid,
  1416. IN PACL Acl,
  1417. OUT PACCESS_MASK UserAccess,
  1418. OUT PACCESS_MASK GroupAccess,
  1419. OUT PACCESS_MASK OtherAccess
  1420. );
  1421. NTSTATUS
  1422. RtlMakePosixAcl(
  1423. IN ULONG AclRevision,
  1424. IN PSID UserSid,
  1425. IN PSID GroupSid,
  1426. IN ACCESS_MASK UserAccess,
  1427. IN ACCESS_MASK GroupAccess,
  1428. IN ACCESS_MASK OtherAccess,
  1429. IN ULONG AclLength,
  1430. OUT PACL Acl,
  1431. OUT PULONG ReturnLength
  1432. );
  1433. VOID
  1434. ReleaseFlocksByPid(
  1435. PIONODE IoNode,
  1436. pid_t pid
  1437. );
  1438. BOOLEAN
  1439. DoFlockStuff(
  1440. PPSX_PROCESS Proc,
  1441. PPSX_API_MSG m,
  1442. int command,
  1443. IN PFILEDESCRIPTOR Fd,
  1444. IN OUT struct flock *new,
  1445. OUT int *error
  1446. );
  1447. #if DBG
  1448. VOID
  1449. DumpFlockList(
  1450. PIONODE IoNode
  1451. );
  1452. #endif // DBG
  1453. NTSTATUS
  1454. InitConnectingTerminalList(
  1455. VOID
  1456. );
  1457. NTSTATUS
  1458. AddConnectingTerminal(
  1459. int Id,
  1460. HANDLE CommPort,
  1461. HANDLE ReqPort
  1462. );
  1463. PPSX_CONTROLLING_TTY
  1464. GetConnectingTerminal(
  1465. int Id
  1466. );
  1467. ULONG
  1468. OpenTty(
  1469. PPSX_PROCESS p,
  1470. PFILEDESCRIPTOR Fd,
  1471. ULONG DesiredAccess,
  1472. ULONG Flags,
  1473. BOOLEAN NewOpen
  1474. );
  1475. ULONG
  1476. OpenDevNull(
  1477. PPSX_PROCESS p,
  1478. PFILEDESCRIPTOR Fd,
  1479. ULONG DesiredAccess,
  1480. ULONG Flags
  1481. );
  1482. dev_t
  1483. GetFileDeviceNumber(
  1484. PUNICODE_STRING Path
  1485. );
  1486. NTSTATUS
  1487. InitSecurityDescriptor(
  1488. IN OUT PSECURITY_DESCRIPTOR pSD,
  1489. IN PUNICODE_STRING pFileName,
  1490. IN HANDLE Process,
  1491. IN mode_t Mode,
  1492. OUT PVOID *pvSaveMem
  1493. );
  1494. VOID
  1495. DeInitSecurityDescriptor(
  1496. IN PSECURITY_DESCRIPTOR pSD,
  1497. IN PVOID *pvSaveMem
  1498. );
  1499. BOOLEAN
  1500. IsGroupOrphaned(
  1501. IN pid_t ProcessGroup
  1502. );
  1503. NTSTATUS
  1504. ExecForeignImage(
  1505. PPSX_PROCESS p,
  1506. PPSX_API_MSG m,
  1507. PUNICODE_STRING Image,
  1508. PUNICODE_STRING CurDir
  1509. );
  1510. #endif // _PSXP_