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.

366 lines
9.9 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. sesport.h
  5. Abstract:
  6. Author:
  7. Ellen Aycock-Wright (ellena) Sept-15-1991
  8. Revision History:
  9. --*/
  10. #ifndef _SESPORT_
  11. #define _SESPORT_
  12. #include <posix/sys/types.h>
  13. #include <posix/termios.h>
  14. #include <stdio.h>
  15. #define MAX_SESSION_PATH 256
  16. // it's very important that this string matches exactly like the SESSION_ROOT in \nt\private\csr\server
  17. // if this string doesn't then NtConnectPort will fail with an error code of c00003a - path not found
  18. #define SESSION_ROOT_W L"\\Sessions"
  19. #define SESSION_ROOT_A "\\Sessions"
  20. #define DOSDEVICE_X_W L"\\DosDevices\\X:\\"
  21. #define DOSDEVICE_X_A "\\DosDevices\\X:\\"
  22. #define DOSDEVICE_X2_A "\\DosDevices\\X:"
  23. #define DOSDEVICE_A "\\DosDevices\\"
  24. #define DOSDEVICE_W L"\\DosDevices\\"
  25. #define DEV_TTY L"\\DosDevices\\X:\\dev\\tty"
  26. #define DEV_NULL L"\\DosDevices\\X:\\dev\\null"
  27. #define PSX_SS_SESSION_PORT_NAME L"\\PSXSS\\SESPORT"
  28. #define PSX_SES_BASE_PORT_NAME "\\PSXSS\\PSXSES"
  29. #define PSX_SES_BASE_PORT_NAME_LENGTH 256
  30. #define PSX_SES_BASE_PORT_PREFIX 'P'
  31. #define PSX_SES_BASE_DATA_PREFIX 'D'
  32. #define PSX_CON_PORT_DATA_SIZE 0x1000L
  33. #define PSX_GET_WCSLEN(SourceString,Length) \
  34. if (NtCurrentPeb()->SessionId) { \
  35. WCHAR buf[MAX_SESSION_PATH]; \
  36. swprintf(buf, L"\\%ld", NtCurrentPeb()->SessionId);\
  37. Length = wcslen(SESSION_ROOT_W)+wcslen(buf)+wcslen(SourceString);\
  38. }else{\
  39. Length = wcslen(SourceString);\
  40. }
  41. #define PSX_GET_STRLEN(SourceString,Length) \
  42. if (NtCurrentPeb()->SessionId) { \
  43. CHAR buf[MAX_SESSION_PATH]; \
  44. sprintf(buf, "\\%d", NtCurrentPeb()->SessionId);\
  45. Length = (USHORT)(strlen(SESSION_ROOT_A)+strlen(buf)+strlen(SourceString));\
  46. }else{\
  47. Length = (USHORT)strlen(SourceString);\
  48. }
  49. // this needs to get tested
  50. #define PSX_GET_SIZEOF(SourceString,Length) \
  51. if (NtCurrentPeb()->SessionId) { \
  52. WCHAR buf[MAX_SESSION_PATH]; \
  53. swprintf(buf, L"\\%ld", NtCurrentPeb()->SessionId);\
  54. Length = sizeof(SESSION_ROOT_W)+(wcslen(buf)*sizeof(WCHAR))+sizeof(SourceString)-2;\
  55. }else{\
  56. Length = sizeof(SourceString);\
  57. }
  58. #define CONSTRUCT_PSX_SES_NAME(Name, t, id) \
  59. if (NtCurrentPeb()->SessionId) { \
  60. sprintf(Name, "%s\\%d%s\\%c%d", SESSION_ROOT_A, NtCurrentPeb()->SessionId,PSX_SES_BASE_PORT_NAME,t,id); \
  61. }else{ \
  62. char *p; \
  63. \
  64. strcpy(Name, PSX_SES_BASE_PORT_NAME); \
  65. p = &Name[sizeof(PSX_SES_BASE_PORT_NAME)-1]; \
  66. *(p++) = '\\'; \
  67. \
  68. *(p++) = t; \
  69. \
  70. RtlIntegerToChar(id, 10, 16, p); \
  71. }
  72. #define PSX_GET_SESSION_PORT_NAME(SessionName, Id) \
  73. if (NtCurrentPeb()->SessionId) { \
  74. sprintf(SessionName, "%s\\%d%s\\%c%d", SESSION_ROOT_A, NtCurrentPeb()->SessionId, \
  75. PSX_SES_BASE_PORT_NAME, \
  76. PSX_SES_BASE_PORT_PREFIX, \
  77. Id); \
  78. }else{ \
  79. sprintf(SessionName, "%s\\%c%d", PSX_SES_BASE_PORT_NAME, \
  80. PSX_SES_BASE_PORT_PREFIX, \
  81. Id); \
  82. }
  83. #define PSX_GET_SESSION_DATA_NAME(SessionName, Id) \
  84. if (NtCurrentPeb()->SessionId) { \
  85. sprintf(SessionName, "%s\\%d%s\\%c%d", SESSION_ROOT_A, NtCurrentPeb()->SessionId, \
  86. PSX_SES_BASE_PORT_NAME, \
  87. PSX_SES_BASE_DATA_PREFIX, \
  88. Id); \
  89. }else{ \
  90. sprintf(SessionName, "%s\\%c%d", PSX_SES_BASE_PORT_NAME, \
  91. PSX_SES_BASE_DATA_PREFIX, \
  92. Id);\
  93. }
  94. #define PSX_GET_SESSION_OBJECT_NAME(DestinationString, SourceString) \
  95. { \
  96. WCHAR SessionDirectory[MAX_SESSION_PATH]; \
  97. if (NtCurrentPeb()->SessionId) { \
  98. swprintf(SessionDirectory,L"%ws\\%ld%ws",SESSION_ROOT_W,NtCurrentPeb()->SessionId,SourceString); \
  99. RtlInitUnicodeString( DestinationString, SessionDirectory ); \
  100. }else{ \
  101. RtlInitUnicodeString( DestinationString, SourceString ); \
  102. }\
  103. }
  104. #define PSX_GET_CREATE_UNICODE_STRING_FROM_ASCIIZ(DestinationString, SourceString, bValue) \
  105. { \
  106. CHAR SessionDirectory[MAX_SESSION_PATH]; \
  107. if (NtCurrentPeb()->SessionId) { \
  108. sprintf(SessionDirectory,"%s\\%d%s",SESSION_ROOT_A,NtCurrentPeb()->SessionId,SourceString); \
  109. bValue = RtlCreateUnicodeStringFromAsciiz (DestinationString, SessionDirectory);\
  110. }else{ \
  111. bValue = RtlCreateUnicodeStringFromAsciiz (DestinationString, SourceString);\
  112. }\
  113. }
  114. // this is a special case where we need it to be single char
  115. #define PSX_GET_SESSION_NAME_A(DestinationString, SourceString) \
  116. { \
  117. if (NtCurrentPeb()->SessionId) { \
  118. sprintf(DestinationString,"%s\\%d%s",SESSION_ROOT_A,NtCurrentPeb()->SessionId,SourceString); \
  119. }else{ \
  120. strcpy(DestinationString,SourceString); \
  121. } \
  122. }
  123. /*
  124. * Session Console ConnectInfo struct
  125. */
  126. typedef struct _SCCONNECTINFO {
  127. int dummy;
  128. } SCCONNECTINFO, *PSCCONNECTINFO;
  129. /*
  130. * Console requests
  131. * these are mapped 1-1 to the win32 Console services
  132. */
  133. typedef enum {
  134. ScCreateFile,
  135. ScOpenFile,
  136. ScCloseFile,
  137. ScReadFile,
  138. ScWriteFile,
  139. ScKbdCharIn,
  140. ScIsatty,
  141. ScIsatty2
  142. } SCCONREQUESTNUMBER;
  143. typedef struct _CONFILEREQUEST {
  144. HANDLE Handle;
  145. LONG Len;
  146. ULONG Flags;
  147. } CONFILEREQUEST;
  148. //
  149. // bits for CONFILEREQUEST.Flags
  150. //
  151. #define PSXSES_NONBLOCK 0x1
  152. typedef struct _SCCONREQUEST {
  153. SCCONREQUESTNUMBER Request;
  154. union {
  155. CONFILEREQUEST IoBuf;
  156. CHAR AsciiChar;
  157. } d;
  158. } SCCONREQUEST, *PSCCONREQUEST;
  159. /* -------- End of Console Requests section -------- */
  160. /*
  161. * TaskManager requests
  162. */
  163. typedef enum {
  164. TmExit,
  165. TmTitle
  166. } SCTMREQUESTNUMBER;
  167. typedef struct {
  168. SCTMREQUESTNUMBER Request;
  169. ULONG ExitStatus; // for TmExit
  170. } SCTMREQUEST, *PSCTMREQUEST;
  171. /* -------- End of TaskManager Requests section -------- */
  172. /*
  173. * Termios control requests
  174. */
  175. typedef enum {
  176. TcGetAttr,
  177. TcSetAttr,
  178. TcDrain,
  179. TcFlow,
  180. TcFlush,
  181. TcGetPGrp,
  182. TcSetPGrp,
  183. TcSendBreak
  184. } SCTCREQUESTNUMBER;
  185. typedef struct _SCTCREQUEST {
  186. SCTCREQUESTNUMBER Request;
  187. LONG FileDes;
  188. struct termios Termios;
  189. LONG OptionalActions;
  190. } SCTCREQUEST, *PSCTCREQUEST;
  191. /*
  192. * PsxSes requests:
  193. * Request for CONSOLE services from PSX SS and PSX clients to the console
  194. * process
  195. */
  196. typedef enum _SCREQUESTNUMBER {
  197. ConRequest,
  198. TaskManRequest,
  199. TcRequest
  200. } SCREQUESTNUMBER;
  201. #ifdef NTPSX_ONLY
  202. typedef struct _SCREQUESTMSG {
  203. PORT_MESSAGE h;
  204. union {
  205. SCCONNECTINFO ConnectionRequest;
  206. struct {
  207. SCREQUESTNUMBER Request;
  208. NTSTATUS Status; // returned status for the request.
  209. union {
  210. SCCONREQUEST Con;
  211. SCTMREQUEST Tm;
  212. SCTCREQUEST Tc;
  213. } d;
  214. };
  215. };
  216. } SCREQUESTMSG, *PSCREQUESTMSG;
  217. /*
  218. * PSX SS Session ConnectInfo struct
  219. */
  220. typedef union _PSXSESCONNECTINFO {
  221. struct {
  222. int SessionUniqueId;
  223. } In;
  224. struct {
  225. HANDLE SessionPortHandle;
  226. } Out;
  227. } PSXSESCONNECTINFO, *PPSXSESCONNECTINFO;
  228. /*
  229. * Psx SS Session requests
  230. * Requests from the session console process (PSXSES.EXE) to the PSX SS
  231. * e.g. Create session, CtrlBreak, etc.
  232. */
  233. typedef enum _PSXSESREQUESTNUMBER {
  234. SesConCreate,
  235. SesConSignal
  236. } PSXSESREQUESTNUMBER;
  237. #endif // NTPSX_ONLY
  238. typedef struct {
  239. ULONG SessionUniqueId;
  240. HANDLE SessionPort;
  241. HANDLE ConsoleProcessHandle;
  242. int OpenFiles;
  243. int PgmNameOffset;
  244. int CurrentDirOffset;
  245. int ArgsOffset;
  246. int EnvironmentOffset;
  247. PVOID Buffer; // for io and foreign process args
  248. } SCREQ_CREATE, *PSCREQ_CREATE;
  249. typedef struct {
  250. int Type;
  251. } SCREQ_SIGNAL;
  252. //
  253. // Values for SCREQ_SIGNAL.Type
  254. //
  255. #define PSX_SIGINT 0
  256. #define PSX_SIGQUIT 1
  257. #define PSX_SIGKILL 2
  258. #define PSX_SIGTSTP 3
  259. typedef struct {
  260. ULONG Status;
  261. HANDLE Session;
  262. } SCREQ_REPLY, *PSCREQ_REPLY;
  263. #ifdef NTPSX_ONLY
  264. typedef struct _PSXSESREQUESTMSG {
  265. PORT_MESSAGE h;
  266. union {
  267. PSXSESCONNECTINFO ConnectionRequest;
  268. struct {
  269. HANDLE Session;
  270. PSXSESREQUESTNUMBER Request;
  271. NTSTATUS Status;
  272. ULONG UniqueId;
  273. union {
  274. SCREQ_CREATE Create;
  275. SCREQ_SIGNAL Signal;
  276. // SCREQ_REPLY Reply;
  277. } d;
  278. };
  279. };
  280. } PSXSESREQUESTMSG, *PPSXSESREQUESTMSG;
  281. /*
  282. * Common macros to access PORT_MESSAGE fields
  283. */
  284. #define PORT_MSG_TYPE(m) ((m).h.u2.s2.Type)
  285. #define PORT_MSG_DATA_LENGTH(m) ((m).h.u1.s1.DataLength)
  286. #define PORT_MSG_TOTAL_LENGTH(m) ((m).h.u1.s1.TotalLength)
  287. #define PORT_MSG_ZERO_INIT(m) ((m).h.u2.ZeroInit)
  288. #endif // NTPSX_ONLY
  289. #endif