Leaked source code of windows server 2003
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.

578 lines
15 KiB

  1. page ,132
  2. if 0
  3. /*++
  4. Copyright (c) 1991 Microsoft Corporation
  5. Module Name:
  6. namepipe.asm
  7. Abstract:
  8. This module contains the resident code part of the stub redir TSR for NT
  9. VDM net support. The routines contained herein are the named pipe API
  10. stubs:
  11. DosQNmPipeInfo
  12. DosQNmpHandState
  13. DosSetNmpHandState
  14. DosPeekNmPipe
  15. DosTransactNmPipe
  16. DosCallNmPipe
  17. DosWaitNmPipe
  18. NetHandleGetInfo
  19. NetHandleSetInfo
  20. DosReadAsyncNmPipe
  21. DosWriteAsyncNmPipe
  22. DosReadAsyncNmPipe2
  23. DosWriteAsyncNmPipe2
  24. (MapNtHandle)
  25. Author:
  26. Richard L Firth (rfirth) 05-Sep-1991
  27. Environment:
  28. Dos mode only
  29. Revision History:
  30. 05-Sep-1991 rfirth
  31. Created
  32. --*/
  33. endif
  34. .xlist ; don't list these include files
  35. .xcref ; turn off cross-reference listing
  36. include dosmac.inc ; Break macro etc (for following include files only)
  37. include dossym.inc ; User_<Reg> defines
  38. include mult.inc ; MultNET
  39. include error.inc ; DOS errors - ERROR_INVALID_FUNCTION
  40. include syscall.inc ; DOS system call numbers
  41. include rdrint2f.inc ; redirector Int 2f numbers
  42. include segorder.inc ; segments
  43. include enumapis.inc ; dispatch codes
  44. include debugmac.inc ; DosCallBack macro
  45. include localmac.inc ; DbgPrint macro
  46. include rdrsvc.inc ; BOP and SVC macros/dispatch codes
  47. include sf.inc ; SFT definitions/structure
  48. .cref ; switch cross-reference back on
  49. .list ; switch listing back on
  50. subttl ; kill subtitling started in include file
  51. .286 ; all code in this module 286 compatible
  52. ResidentCodeStart
  53. assume cs:ResidentCode
  54. assume ds:nothing
  55. ; *** DosQNmPipeInfo
  56. ; *
  57. ; * Implements the DosQNmPipeInfo call by vectoring into the VdmRedir
  58. ; * dispatcher which calls a 32-bit function to do the work
  59. ; *
  60. ; * Function = 5F32h
  61. ; *
  62. ; * ENTRY BX = Pipe handle
  63. ; * CX = Buffer size
  64. ; * DX = Info level
  65. ; * DS:SI = Buffer
  66. ; *
  67. ; * EXIT CF = 1
  68. ; * AX = Error code
  69. ; *
  70. ; * CF = 0
  71. ; * no error
  72. ; * AX = undefined
  73. ; *
  74. ; * USES ax, flags
  75. ; *
  76. ; * ASSUMES nothing
  77. ; *
  78. ; ***
  79. public DosQNmPipeInfo
  80. DosQNmPipeInfo proc near
  81. call MapNtHandle
  82. jc @f ; bad handle: ax = error code, cf = 1
  83. SVC SVC_RDRQNMPIPEINFO ; BP:BX is 32-bit handle
  84. @@: ret
  85. DosQNmPipeInfo endp
  86. ; *** DosQNmpHandState
  87. ; *
  88. ; * Implements the DosQNmpHandState call by vectoring into the VdmRedir
  89. ; * dispatcher which calls a 32-bit function to do the work
  90. ; *
  91. ; * Function = 5F33h
  92. ; *
  93. ; * ENTRY BX = Pipe handle
  94. ; *
  95. ; * EXIT CF = 1
  96. ; * AX = Error code
  97. ; *
  98. ; * CF = 0
  99. ; * AX = Pipe mode:
  100. ; * BSxxxWxRIIIIIIII
  101. ; *
  102. ; * where:
  103. ; * B = Blocking mode. If B=1 the pipe is non blocking
  104. ; * S = Server end of pipe if 1
  105. ; * W = Pipe is written in message mode if 1 (else byte mode)
  106. ; * R = Pipe is read in message mode if 1 (else byte mode)
  107. ; * I = Pipe instances. Unlimited if 0xFF
  108. ; *
  109. ; * USES ax, flags
  110. ; *
  111. ; * ASSUMES nothing
  112. ; *
  113. ; ***
  114. public DosQNmpHandState
  115. DosQNmpHandState proc near
  116. call MapNtHandle
  117. jc @f ; bad handle: ax = error code, cf = 1
  118. SVC SVC_RDRQNMPHANDSTATE
  119. @@: ret
  120. DosQNmpHandState endp
  121. ; *** DosSetNmpHandState
  122. ; *
  123. ; * Implements the DosSetNmpHandState call by vectoring into the VdmRedir
  124. ; * dispatcher which calls a 32-bit function to do the work
  125. ; *
  126. ; * Function = 5F34h
  127. ; *
  128. ; * ENTRY BX = Pipe handle
  129. ; * CX = Pipe mode to set
  130. ; *
  131. ; * EXIT CF = 1
  132. ; * AX = Error code
  133. ; *
  134. ; * CF = 0
  135. ; * AX = Pipe mode set
  136. ; *
  137. ; * USES ax, flags
  138. ; *
  139. ; * ASSUMES nothing
  140. ; *
  141. ; ***
  142. public DosSetNmpHandState
  143. DosSetNmpHandState proc near
  144. call MapNtHandle
  145. jc @f ; bad handle: ax = error code, cf = 1
  146. SVC SVC_RDRSETNMPHANDSTATE
  147. @@: ret
  148. DosSetNmpHandState endp
  149. ; *** DosPeekNmPipe
  150. ; *
  151. ; * Implements the DosPeekNmPipe call by vectoring into the VdmRedir
  152. ; * dispatcher which calls a 32-bit function to do the work
  153. ; *
  154. ; * Function = 5F35h
  155. ; *
  156. ; * ENTRY BX = Pipe handle
  157. ; * CX = Size of buffer for peek
  158. ; * DS:SI = Buffer address
  159. ; *
  160. ; * EXIT CF = 1
  161. ; * AX = Error code
  162. ; *
  163. ; * CF = 0
  164. ; * AX = Pipe status
  165. ; * BX = Number of bytes peeked into buffer
  166. ; * CX = Number of bytes in pipe
  167. ; * DX = Number of bytes in message
  168. ; * DI = Pipe status
  169. ; * DS:SI = Data peeked
  170. ; *
  171. ; * USES ax, bx, cx, dx, si, di, ds, flags
  172. ; *
  173. ; * ASSUMES nothing
  174. ; *
  175. ; ***
  176. public DosPeekNmPipe
  177. DosPeekNmPipe proc near
  178. call MapNtHandle
  179. jc @f ; bad handle: ax = error code, cf = 1
  180. SVC SVC_RDRPEEKNMPIPE ; do the 'bop' (makes the lambada look tame)
  181. jc @f ; error returned from protect mode
  182. ;
  183. ; success - set the user's registers to values returned
  184. ;
  185. push ax ; pipe status
  186. DosCallBack GET_USER_STACK ; Get_User_Stack
  187. pop [si].User_Ax ; copy saved return code into user's copy
  188. mov [si].User_Bx,bx
  189. mov [si].User_Cx,cx
  190. mov [si].User_Dx,dx
  191. mov [si].User_Di,di
  192. clc ; reset cf, just in case
  193. @@: ret
  194. DosPeekNmPipe endp
  195. ; *** DosTransactNmPipe
  196. ; *
  197. ; * Implements the DosTransactNmPipe call by vectoring into the VdmRedir
  198. ; * dispatcher which calls a 32-bit function to do the work
  199. ; *
  200. ; * Function = 5F36h
  201. ; *
  202. ; * ENTRY BX = Pipe handle
  203. ; * CX = Transmit buffer length
  204. ; * DX = Receive buffer length
  205. ; * DS:SI = Transmit buffer
  206. ; * ES:DI = Receive buffer
  207. ; *
  208. ; * EXIT CF = 1
  209. ; * AX = Error code
  210. ; *
  211. ; * CF = 0
  212. ; * CX = Number of bytes in Receive buffer
  213. ; *
  214. ; * USES ax, flags
  215. ; *
  216. ; * ASSUMES nothing
  217. ; *
  218. ; ***
  219. public DosTransactNmPipe
  220. DosTransactNmPipe proc near
  221. call MapNtHandle
  222. jc @f ; bad handle: ax = error code, cf = 1
  223. SVC SVC_RDRTRANSACTNMPIPE
  224. jc @f ; error from protect-mode side
  225. ;
  226. ; success - copy returned cx value to user's registers in Dos stack seg
  227. ;
  228. DosCallBack GET_USER_STACK
  229. mov [si].User_Cx,cx
  230. clc ; reset carry flag, just in case
  231. @@: ret
  232. DosTransactNmPipe endp
  233. ; *** DosCallNmPipe
  234. ; *
  235. ; * Implements the DosCallNmPipe call by vectoring into the VdmRedir
  236. ; * dispatcher which calls a 32-bit function to do the work
  237. ; *
  238. ; * Function = 5F37h
  239. ; *
  240. ; * ENTRY DS:SI = Pointer to CallNmPipe structure:
  241. ; * DWORD Timeout; +0
  242. ; * LPWORD lpBytesRead; +4
  243. ; * WORD OutputBufferLen; +8
  244. ; * LPBYTE OutputBuffer; +10
  245. ; * WORD InputBufferLength; +14
  246. ; * LPBYTE InputBuffer; +16
  247. ; * LPSTR PipeName; +20
  248. ; *
  249. ; * EXIT CF = 1
  250. ; * AX = Error code
  251. ; *
  252. ; * CF = 0
  253. ; * CX = Bytes received
  254. ; *
  255. ; * USES ax, flags
  256. ; *
  257. ; * ASSUMES nothing
  258. ; *
  259. ; ***
  260. public DosCallNmPipe
  261. DosCallNmPipe proc near
  262. SVC SVC_RDRCALLNMPIPE
  263. jc @f ; oops - error
  264. ;
  265. ; success - copy returned ByteRead count in cx to user's cx in Dos stack seg
  266. ;
  267. DosCallBack GET_USER_STACK
  268. mov [si].User_Cx,cx
  269. clc ; reset carry flag, just in case
  270. @@: ret
  271. DosCallNmPipe endp
  272. ; *** DosWaitNmPipe
  273. ; *
  274. ; * Implements the DosWaitNmPipe call by vectoring into the VdmRedir
  275. ; * dispatcher which calls a 32-bit function to do the work
  276. ; *
  277. ; * Function = 5F38h
  278. ; *
  279. ; * ENTRY BX:CX = Timeout
  280. ; * DS:DX = Pipe name
  281. ; *
  282. ; * EXIT CF = 1
  283. ; * AX = Error code
  284. ; *
  285. ; * CF = 0
  286. ; * No error
  287. ; *
  288. ; * USES ax, flags
  289. ; *
  290. ; * ASSUMES nothing
  291. ; *
  292. ; ***
  293. public DosWaitNmPipe
  294. DosWaitNmPipe proc near
  295. SVC SVC_RDRWAITNMPIPE
  296. ret
  297. DosWaitNmPipe endp
  298. ; *** NetHandleSetInfo
  299. ; *
  300. ; * Function = 5F3Bh
  301. ; *
  302. ; * ENTRY BX = Pipe handle
  303. ; * CX = Buffer length
  304. ; * SI = Level (1)
  305. ; * DI = Parmnum
  306. ; * DS:DX = Buffer
  307. ; *
  308. ; * EXIT CF = 1
  309. ; * AX = Error code
  310. ; *
  311. ; * CF = 0
  312. ; * Stuff from buffer set
  313. ; *
  314. ; * USES ax, flags
  315. ; *
  316. ; * ASSUMES nothing
  317. ; *
  318. ; ***
  319. public NetHandleSetInfo
  320. NetHandleSetInfo proc
  321. call MapNtHandle
  322. jc @f
  323. SVC SVC_RDRHANDLESETINFO
  324. @@: ret
  325. NetHandleSetInfo endp
  326. ; *** NetHandleGetInfo
  327. ; *
  328. ; * Function = 5F3Ch
  329. ; *
  330. ; * ENTRY BX = Pipe handle
  331. ; * CX = Buffer length
  332. ; * SI = Level (1)
  333. ; * DS:DX = Buffer
  334. ; *
  335. ; * EXIT CX = size of required buffer (whether we got it or not)
  336. ; * CF = 1
  337. ; * AX = Error code
  338. ; *
  339. ; * CF = 0
  340. ; * indicated stuff put in buffer
  341. ; *
  342. ; * USES ax, flags
  343. ; *
  344. ; * ASSUMES nothing
  345. ; *
  346. ; ***
  347. public NetHandleGetInfo
  348. NetHandleGetInfo proc
  349. call MapNtHandle
  350. jc @f
  351. SVC SVC_RDRHANDLEGETINFO
  352. jc @f
  353. DosCallBack GET_USER_STACK
  354. mov [si].User_Cx,cx
  355. clc
  356. @@: ret
  357. NetHandleGetInfo endp
  358. ; *** DosReadAsyncNmPipe/DosReadAsyncNmPipe2
  359. ; * DosWriteAsyncNmPipe/DosWriteAsyncNmPipe2
  360. ; *
  361. ; * Implements the AsyncNmPipe calls. 32-bit DLL does all the work
  362. ; *
  363. ; * Function = int 2fh/ax=1186h (DosReadAsyncNmPipe)
  364. ; * Function = int 2fh/ax=1190h (DosReadAsyncNmPipe2)
  365. ; * Function = int 2fh/ax=118fh (DosWriteAsyncNmPipe)
  366. ; * Function = int 2fh/ax=1191h (DosWriteAsyncNmPipe2)
  367. ; *
  368. ; * ENTRY DS:SI = DosAsyncNmPipeStruct:
  369. ; * DD pBytesRead +0
  370. ; * DW buflen +4
  371. ; * DD pBuffer +6
  372. ; * DD pError +10
  373. ; * DD pAnr +14
  374. ; * DW hPipe +18
  375. ; *
  376. ; * + For DosReadAsyncNmPipe2/DosWriteAsyncNmPipe2
  377. ; * DD pSemaphore +20
  378. ; *
  379. ; * EXIT CF = 1
  380. ; * AX = Error code
  381. ; *
  382. ; * CF = 0
  383. ; * No error
  384. ; *
  385. ; * USES ax, flags
  386. ; *
  387. ; * ASSUMES nothing
  388. ; *
  389. ; ***
  390. public DosReadAsyncNmPipe
  391. DosReadAsyncNmPipe proc near
  392. Int2fNumber DosReadAsyncNmPipe
  393. async_read_write_common:
  394. ;
  395. ; since the async named pipe calls arrive via int 2f, we don't have the safety
  396. ; blanket of DOS saving our registers
  397. ;
  398. push bp
  399. push bx
  400. mov bx,word ptr [si+18] ; pipe handle
  401. call MapNtHandle
  402. jc @f
  403. SVC SVC_RDRREADASYNCNMPIPE ; same for Read & Write
  404. @@: pop bx
  405. pop bp
  406. ret
  407. public DosReadAsyncNmPipe2
  408. DosReadAsyncNmPipe2:
  409. Int2fNumber DosReadAsyncNmPipe2
  410. jmp short async_read_write_common
  411. public DosWriteAsyncNmPipe
  412. DosWriteAsyncNmPipe:
  413. Int2fNumber DosWriteAsyncNmPipe
  414. jmp short async_read_write_common
  415. public DosWriteAsyncNmPipe2
  416. DosWriteAsyncNmPipe2:
  417. Int2fNumber DosWriteAsyncNmPipe2
  418. jmp short async_read_write_common
  419. DosReadAsyncNmPipe endp
  420. ; *** MapNtHandle
  421. ; *
  422. ; * Given a handle in BX, map it to a 32-bit Nt handle from the SFT in
  423. ; * BP:BX
  424. ; *
  425. ; * ENTRY bx = handle to map
  426. ; *
  427. ; * EXIT Success - BP:BX = 32-bit Nt handle from SFT
  428. ; *
  429. ; * RETURNS Success - CF = 0
  430. ; * Failure - CF = 1, ax = ERROR_INVALID_HANDLE
  431. ; *
  432. ; * USES ax, bp, bx, flags
  433. ; *
  434. ; * ASSUMES nothing
  435. ; *
  436. ; ***
  437. MapNtHandle proc near
  438. push ax ; save regs used by Dos call back
  439. push cx
  440. push dx
  441. push ds
  442. push si
  443. push es
  444. push di
  445. ;
  446. ; call back to Dos to get the pointer to the JFN in our caller's JFT. Remember
  447. ; the handle (BX) is an index into the JFT. The byte at this offset in the JFT
  448. ; contains the index of the SFT structure we want in the system file table
  449. ;
  450. DosCallBack PJFN_FROM_HANDLE ; pJfnFromHamdle
  451. jc @f ; bad handle
  452. ;
  453. ; we retrieved a pointer to the required byte in the JFT. The byte at this
  454. ; pointer is the SFT index which describes our 'file' (named pipe in this
  455. ; case). We use this as an argument to the next call back function - get
  456. ; Sft from System File Number
  457. ;
  458. mov bl,es:[di]
  459. xor bh,bh
  460. DosCallBack SF_FROM_SFN ; SfFromSfn
  461. jc @f ; oops - bad handle
  462. ;
  463. ; Ok. We have a pointer to the SFT which describes this named pipe. Get the
  464. ; 32-bit Nt handle
  465. ;
  466. mov bx,word ptr es:[di].sf_NtHandle
  467. mov bp,word ptr es:[di].sf_NtHandle[2]
  468. ;
  469. ; restore all registers used by Dos call back. BX at this point is either
  470. ; the low 16-bits of the 32-bit Nt handle or junk. Carry flag is set
  471. ; appropriately
  472. ;
  473. @@: pop di
  474. pop es
  475. pop si
  476. pop ds
  477. pop dx
  478. pop cx
  479. pop ax
  480. jnc @f
  481. ;
  482. ; finally, if there was an error then return a bad handle indication in ax
  483. ;
  484. mov ax,ERROR_INVALID_HANDLE
  485. @@: ret
  486. MapNtHandle endp
  487. ResidentCodeEnd
  488. end