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.

1423 lines
34 KiB

  1. //--------------------------------------------------------------------------;
  2. //
  3. // File: dsvxd.c
  4. //
  5. // Copyright (c) 1995 Microsoft Corporation. All Rights Reserved.
  6. //
  7. // Abstract:
  8. //
  9. // Contents:
  10. //
  11. // History:
  12. // 06/15/95 FrankYe
  13. //
  14. //--------------------------------------------------------------------------;
  15. #define WANTVXDWRAPS
  16. #define INITGUID
  17. #include <windows.h>
  18. extern "C" {
  19. #include <vmm.h>
  20. #include <vxdldr.h>
  21. #include <vwin32.h>
  22. #include <vxdwraps.h>
  23. #include <configmg.h>
  24. #include <verinfo.h>
  25. }
  26. #define NODSOUNDWRAPS
  27. #include <mmsystem.h>
  28. #include <dsound.h>
  29. #include <dsdrvi.h>
  30. #include "dsvxd.h"
  31. #include "dsvxdi.h"
  32. #pragma VxD_LOCKED_CODE_SEG
  33. #pragma VxD_LOCKED_DATA_SEG
  34. //--------------------------------------------------------------------------;
  35. //
  36. // Why is there no wrapper for VMM's _lstrcmpi??? I'll make my own...
  37. //
  38. //--------------------------------------------------------------------------;
  39. int VXDINLINE VMM_lstrcmpi(char *pString1, char *pString2)
  40. {
  41. int iReturn;
  42. Touch_Register(eax);
  43. Touch_Register(ecx);
  44. Touch_Register(edx);
  45. _asm push pString1;
  46. _asm push pString2;
  47. VMMCall(_lstrcmpi);
  48. _asm add esp, 2*4;
  49. _asm mov iReturn, eax;
  50. return iReturn;
  51. }
  52. LPVOID VXDINLINE VMM_GetCurrentContext()
  53. {
  54. LPVOID pCD;
  55. Touch_Register(eax);
  56. VMMCall(_GetCurrentContext);
  57. _asm mov pCD, eax;
  58. return pCD;
  59. }
  60. BOOL VXDINLINE VMM_PageAttach(ULONG pagesrc, LPVOID hcontextsrc, ULONG pagedst, ULONG cpages)
  61. {
  62. int iReturn;
  63. Touch_Register(eax);
  64. Touch_Register(ecx);
  65. Touch_Register(edx);
  66. _asm push cpages;
  67. _asm push pagedst;
  68. _asm push hcontextsrc;
  69. _asm push pagesrc;
  70. VMMCall(_PageAttach);
  71. _asm add esp, 4*4;
  72. _asm mov iReturn, eax;
  73. return (0 != iReturn);
  74. }
  75. BOOL VXDINLINE VMM_PageFree(PVOID pPage, ULONG flags)
  76. {
  77. return _PageFree(pPage, flags);
  78. }
  79. void VXDINLINE VMM_EnterMustComplete()
  80. {
  81. Touch_Register(eax);
  82. Touch_Register(ecx);
  83. Touch_Register(edx);
  84. VMMCall(_EnterMustComplete);
  85. return;
  86. }
  87. void VXDINLINE VMM_LeaveMustComplete()
  88. {
  89. Touch_Register(eax);
  90. Touch_Register(ecx);
  91. Touch_Register(edx);
  92. VMMCall(_LeaveMustComplete);
  93. return;
  94. }
  95. BOOL VXDINLINE VWIN32_CloseVxDHandle(DWORD vxdh)
  96. {
  97. int iReturn;
  98. Touch_Register(ecx);
  99. Touch_Register(edx);
  100. _asm mov eax, vxdh;
  101. VxDCall(_VWIN32_CloseVxDHandle);
  102. _asm mov iReturn, eax;
  103. return (0 != iReturn);
  104. }
  105. /*
  106. BOOL VXDINLINE VMM_PageLock(ULONG pagestrt, ULONG cpages, ULONG dwflags)
  107. {
  108. int iReturn;
  109. Touch_Register(eax);
  110. Touch_Register(ecx);
  111. Touch_Register(edx);
  112. _asm push dwflags;
  113. _asm push cpages;
  114. _asm push pagestrt;
  115. VMMCall(_LinPageLock);
  116. _asm add esp, 3*4;
  117. _asm mov iReturn, eax;
  118. return (0 != iReturn);
  119. }
  120. BOOL VXDINLINE VMM_PageUnlock(ULONG pagestrt, ULONG cpages, ULONG dwflags)
  121. {
  122. int iReturn;
  123. Touch_Register(eax);
  124. Touch_Register(ecx);
  125. Touch_Register(edx);
  126. _asm push dwflags;
  127. _asm push cpages;
  128. _asm push pagestrt;
  129. VMMCall(_LinPageUnlock);
  130. _asm add esp, 3*4;
  131. _asm mov iReturn, eax;
  132. return (0 != iReturn);
  133. }
  134. */
  135. //--------------------------------------------------------------------------;
  136. //
  137. // Filescope data
  138. //
  139. //--------------------------------------------------------------------------;
  140. static LPVOID gpGarbagePage = NULL;
  141. //--------------------------------------------------------------------------;
  142. //
  143. // VxD Device control functions
  144. //
  145. //--------------------------------------------------------------------------;
  146. int ctrlDynamicDeviceInit(void)
  147. {
  148. DPF(("ctrlDynamicDeviceInit"));
  149. return ctrlDrvInit();
  150. }
  151. int ctrlDynamicDeviceExit(void)
  152. {
  153. DPF(("ctrlDynamicDeviceExit"));
  154. return ctrlDrvExit();
  155. }
  156. #pragma VxD_PAGEABLE_CODE_SEG
  157. #pragma VxD_PAGEABLE_DATA_SEG
  158. //--------------------------------------------------------------------------;
  159. //
  160. // IOCTL handlers
  161. //
  162. //--------------------------------------------------------------------------;
  163. int ioctlDsvxdInitialize(PDIOCPARAMETERS pdiocp)
  164. {
  165. DSVAL dsv;
  166. IOSTART(0*4);
  167. //
  168. // The only thing we need to do is allocate one page of fixed
  169. // memory to which we will commit alias buffer pointers when
  170. // we don't want them to point at the real buffer anymore.
  171. //
  172. gpGarbagePage = _PageAllocate(1, PG_VM, Get_Sys_VM_Handle(), 0, 0, 0, 0, PAGEFIXED);
  173. if (NULL != gpGarbagePage) {
  174. dsv = DS_OK;
  175. } else {
  176. dsv = DSERR_OUTOFMEMORY;
  177. }
  178. IOOUTPUT(dsv, DSVAL);
  179. IORETURN;
  180. return 0;
  181. }
  182. int ioctlDsvxdShutdown(PDIOCPARAMETERS pdiocp)
  183. {
  184. DSVAL dsv;
  185. IOSTART(0*4);
  186. if (NULL != gpGarbagePage) _PageFree(gpGarbagePage, 0);
  187. dsv = DS_OK;
  188. IOOUTPUT(dsv, DSVAL);
  189. IORETURN;
  190. return 0;
  191. }
  192. int ioctlDsvxd_PageFile_Get_Version(PDIOCPARAMETERS pdiocp)
  193. {
  194. PDWORD pVersion;
  195. PDWORD pMaxSize;
  196. PDWORD pPagerType;
  197. IOSTART(3*4);
  198. IOINPUT(pVersion, PDWORD);
  199. IOINPUT(pMaxSize, PDWORD);
  200. IOINPUT(pPagerType, PDWORD);
  201. Dsvxd_PageFile_Get_Version(pVersion, pMaxSize, pPagerType);
  202. IORETURN;
  203. return 0;
  204. }
  205. int ioctlDsvxd_VMM_Test_Debug_Installed(PDIOCPARAMETERS pdiocp)
  206. {
  207. BOOL fInstalled;
  208. IOSTART(0*4);
  209. fInstalled = Dsvxd_VMM_Test_Debug_Installed();
  210. IOOUTPUT(fInstalled, BOOL);
  211. IORETURN;
  212. return 0;
  213. }
  214. int ioctlDsvxd_VMCPD_Get_Version(PDIOCPARAMETERS pdiocp)
  215. {
  216. PLONG pMajorVersion;
  217. PLONG pMinorVersion;
  218. PLONG pLevel;
  219. IOSTART(3*4);
  220. IOINPUT(pMajorVersion, PLONG);
  221. IOINPUT(pMinorVersion, PLONG);
  222. IOINPUT(pLevel, PLONG);
  223. Dsvxd_VMCPD_Get_Version(pMajorVersion, pMinorVersion, pLevel);
  224. IORETURN;
  225. return 0;
  226. }
  227. //--------------------------------------------------------------------------;
  228. //
  229. //
  230. //
  231. //--------------------------------------------------------------------------;
  232. int ioctlDrvGetNextDescFromGuid(PDIOCPARAMETERS pdiocp)
  233. {
  234. LPCGUID pGuidLast;
  235. LPGUID pGuid;
  236. PDSDRIVERDESC pDrvDesc;
  237. HRESULT hr;
  238. IOSTART(3*4);
  239. IOINPUT(pGuidLast, LPCGUID);
  240. IOINPUT(pGuid, LPGUID);
  241. IOINPUT(pDrvDesc, PDSDRIVERDESC);
  242. hr = CDrv::GetNextDescFromGuid(pGuidLast, pGuid, pDrvDesc);
  243. IOOUTPUT(hr, HRESULT);
  244. IORETURN;
  245. return 0;
  246. }
  247. int ioctlDrvGetDescFromGuid(PDIOCPARAMETERS pdiocp)
  248. {
  249. LPCGUID pGuid;
  250. PDSDRIVERDESC pDrvDesc;
  251. DSVAL dsv;
  252. IOSTART(2*4);
  253. IOINPUT(pGuid, LPCGUID);
  254. IOINPUT(pDrvDesc, PDSDRIVERDESC);
  255. dsv = CDrv::GetDescFromGuid(*pGuid, pDrvDesc);
  256. IOOUTPUT(dsv, DSVAL);
  257. IORETURN;
  258. return 0;
  259. }
  260. int ioctlDrvOpenFromGuid(PDIOCPARAMETERS pdiocp)
  261. {
  262. LPCGUID pGuid;
  263. IDsDriver **ppIDsDriver;
  264. HRESULT hr;
  265. IOSTART(2*4);
  266. IOINPUT(pGuid, LPCGUID);
  267. IOINPUT(ppIDsDriver, IDsDriver**);
  268. hr = CDrv::OpenFromGuid(*pGuid, ppIDsDriver);
  269. IOOUTPUT(hr, HRESULT);
  270. IORETURN;
  271. return 0;
  272. }
  273. //--------------------------------------------------------------------------;
  274. //
  275. //
  276. //
  277. //--------------------------------------------------------------------------;
  278. int ioctlIUnknown_QueryInterface(PDIOCPARAMETERS pdiocp)
  279. {
  280. LPUNKNOWN pIUnknown;
  281. LPIID riid;
  282. PVOID *ppv;
  283. HRESULT hr;
  284. IOSTART(3*4);
  285. IOINPUT(pIUnknown, LPUNKNOWN);
  286. IOINPUT(riid, LPIID);
  287. IOINPUT(ppv, PVOID*);
  288. hr = pIUnknown->QueryInterface((REFIID)(*riid), ppv);
  289. IOOUTPUT(hr, HRESULT);
  290. IORETURN;
  291. return 0;
  292. }
  293. //--------------------------------------------------------------------------;
  294. //
  295. //
  296. //
  297. //--------------------------------------------------------------------------;
  298. int ioctlIUnknown_AddRef(PDIOCPARAMETERS pdiocp)
  299. {
  300. LPUNKNOWN pIUnknown;
  301. ULONG result;
  302. IOSTART(1*4);
  303. IOINPUT(pIUnknown, LPUNKNOWN);
  304. result = pIUnknown->AddRef();
  305. IOOUTPUT(result, ULONG);
  306. IORETURN;
  307. return 0;
  308. }
  309. //--------------------------------------------------------------------------;
  310. //
  311. //
  312. //
  313. //--------------------------------------------------------------------------;
  314. int ioctlIUnknown_Release(PDIOCPARAMETERS pdiocp)
  315. {
  316. LPUNKNOWN pIUnknown;
  317. ULONG result;
  318. IOSTART(1*4);
  319. IOINPUT(pIUnknown, LPUNKNOWN);
  320. result = pIUnknown->Release();
  321. IOOUTPUT(result, ULONG);
  322. IORETURN;
  323. return 0;
  324. }
  325. //--------------------------------------------------------------------------;
  326. //
  327. //
  328. //
  329. //--------------------------------------------------------------------------;
  330. //
  331. // This should really be ioctlIUnknown_QueryInterface, if I would take the time
  332. // to fix up the IOCTLs to DSVXD
  333. //
  334. int ioctlIDsDriver_QueryInterface(PDIOCPARAMETERS pdiocp)
  335. {
  336. IDsDriver *pIDsDriver;
  337. const IID *piid;
  338. PVOID *ppv;
  339. HRESULT hr;
  340. IOSTART(3*4);
  341. IOINPUT(pIDsDriver, IDsDriver*);
  342. IOINPUT(piid, const IID *);
  343. IOINPUT(ppv, PVOID*);
  344. hr = pIDsDriver->QueryInterface((REFIID)(*piid), ppv);
  345. IOOUTPUT(hr, HRESULT);
  346. IORETURN;
  347. return 0;
  348. }
  349. //--------------------------------------------------------------------------;
  350. //
  351. //
  352. //
  353. //--------------------------------------------------------------------------;
  354. int ioctlIDsDriver_Close(PDIOCPARAMETERS pdiocp)
  355. {
  356. IDsDriver *pIDsDriver;
  357. HRESULT hr;
  358. IOSTART(1*4);
  359. IOINPUT(pIDsDriver, IDsDriver*);
  360. hr = pIDsDriver->Close();
  361. IOOUTPUT(hr, HRESULT);
  362. IORETURN;
  363. return 0;
  364. }
  365. //--------------------------------------------------------------------------;
  366. //
  367. //
  368. //
  369. //--------------------------------------------------------------------------;
  370. int ioctlIDsDriver_GetCaps(PDIOCPARAMETERS pdiocp)
  371. {
  372. IDsDriver *pIDsDriver;
  373. PDSDRIVERCAPS pDrvCaps;
  374. HRESULT hr;
  375. IOSTART(2*4);
  376. IOINPUT(pIDsDriver, IDsDriver*);
  377. IOINPUT(pDrvCaps, PDSDRIVERCAPS);
  378. hr = pIDsDriver->GetCaps(pDrvCaps);
  379. IOOUTPUT(hr, HRESULT);
  380. IORETURN;
  381. return 0;
  382. }
  383. //--------------------------------------------------------------------------;
  384. //
  385. //
  386. //
  387. //--------------------------------------------------------------------------;
  388. int ioctlIDsDriver_CreateSoundBuffer(PDIOCPARAMETERS pdiocp)
  389. {
  390. IDsDriver *pIDsDriver;
  391. LPWAVEFORMATEX pwfx;
  392. DWORD dwFlags;
  393. DWORD dwCardAddress;
  394. LPDWORD pdwcbBufferSize;
  395. LPBYTE *ppBuffer;
  396. PVOID *ppvObj;
  397. HRESULT hr;
  398. IOSTART(7*4);
  399. IOINPUT(pIDsDriver, IDsDriver*);
  400. IOINPUT(pwfx, LPWAVEFORMATEX);
  401. IOINPUT(dwFlags, DWORD);
  402. IOINPUT(dwCardAddress, DWORD);
  403. IOINPUT(pdwcbBufferSize, LPDWORD);
  404. IOINPUT(ppBuffer, LPBYTE*);
  405. IOINPUT(ppvObj, PVOID*);
  406. hr = pIDsDriver->CreateSoundBuffer(pwfx, dwFlags, dwCardAddress,
  407. pdwcbBufferSize, ppBuffer, ppvObj);
  408. IOOUTPUT(hr, HRESULT);
  409. IORETURN;
  410. return 0;
  411. }
  412. //--------------------------------------------------------------------------;
  413. //
  414. //
  415. //
  416. //--------------------------------------------------------------------------;
  417. int ioctlIDsDriver_DuplicateSoundBuffer(PDIOCPARAMETERS pdiocp)
  418. {
  419. IDsDriver *pIDsDriver;
  420. IDsDriverBuffer *pIDsDriverBuffer;
  421. PVOID *ppv;
  422. HRESULT hr;
  423. IOSTART(3*4);
  424. IOINPUT(pIDsDriver, IDsDriver*);
  425. IOINPUT(pIDsDriverBuffer, IDsDriverBuffer*);
  426. IOINPUT(ppv, PVOID*);
  427. hr = pIDsDriver->DuplicateSoundBuffer(pIDsDriverBuffer, ppv);
  428. IOOUTPUT(hr, HRESULT);
  429. IORETURN;
  430. return 0;
  431. }
  432. //--------------------------------------------------------------------------;
  433. //
  434. //
  435. //
  436. //--------------------------------------------------------------------------;
  437. //--------------------------------------------------------------------------;
  438. //
  439. //
  440. //
  441. //--------------------------------------------------------------------------;
  442. int ioctlBufferRelease(PDIOCPARAMETERS pdiocp)
  443. {
  444. PIDSDRIVERBUFFER pBuf;
  445. DSVAL dsv;
  446. IOSTART(1*4);
  447. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  448. dsv = pBuf->Release();
  449. IOOUTPUT(dsv, DSVAL);
  450. IORETURN;
  451. return 0;
  452. }
  453. //--------------------------------------------------------------------------;
  454. //
  455. //
  456. //
  457. //--------------------------------------------------------------------------;
  458. int ioctlBufferLock(PDIOCPARAMETERS pdiocp)
  459. {
  460. PIDSDRIVERBUFFER pBuf;
  461. LPVOID * ppvAudio1;
  462. LPDWORD pdwLen1;
  463. LPVOID * ppvAudio2;
  464. LPDWORD pdwLen2;
  465. DWORD dwWritePosition;
  466. DWORD dwWriteBytes;
  467. DWORD dwFlags;
  468. DSVAL dsv;
  469. IOSTART(8*4);
  470. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  471. IOINPUT(ppvAudio1, LPVOID *);
  472. IOINPUT(pdwLen1, LPDWORD);
  473. IOINPUT(ppvAudio2, LPVOID *);
  474. IOINPUT(pdwLen2, LPDWORD);
  475. IOINPUT(dwWritePosition, DWORD);
  476. IOINPUT(dwWriteBytes, DWORD);
  477. IOINPUT(dwFlags, DWORD);
  478. dsv = pBuf->Lock( ppvAudio1,
  479. pdwLen1,
  480. ppvAudio2,
  481. pdwLen2,
  482. dwWritePosition,
  483. dwWriteBytes,
  484. dwFlags );
  485. IOOUTPUT(dsv, DSVAL);
  486. IORETURN;
  487. return 0;
  488. }
  489. int ioctlBufferUnlock(PDIOCPARAMETERS pdiocp)
  490. {
  491. PIDSDRIVERBUFFER pBuf;
  492. PVOID pvAudio1;
  493. DWORD dwLen1;
  494. PVOID pvAudio2;
  495. DWORD dwLen2;
  496. DSVAL dsv;
  497. IOSTART(5*4);
  498. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  499. IOINPUT(pvAudio1, PVOID);
  500. IOINPUT(dwLen1, DWORD);
  501. IOINPUT(pvAudio2, PVOID);
  502. IOINPUT(dwLen2, DWORD);
  503. dsv = pBuf->Unlock( pvAudio1,
  504. dwLen1,
  505. pvAudio2,
  506. dwLen2 );
  507. IOOUTPUT(dsv, DSVAL);
  508. IORETURN;
  509. return 0;
  510. }
  511. //--------------------------------------------------------------------------;
  512. //
  513. //
  514. //
  515. //--------------------------------------------------------------------------;
  516. int ioctlBufferSetFormat(PDIOCPARAMETERS pdiocp)
  517. {
  518. PIDSDRIVERBUFFER pBuf;
  519. LPWAVEFORMATEX pwfxToSet;
  520. DSVAL dsv;
  521. IOSTART(2*4);
  522. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  523. IOINPUT(pwfxToSet, LPWAVEFORMATEX);
  524. dsv = pBuf->SetFormat(pwfxToSet);
  525. IOOUTPUT(dsv, DSVAL);
  526. IORETURN;
  527. return 0;
  528. }
  529. //--------------------------------------------------------------------------;
  530. //
  531. //
  532. //
  533. //--------------------------------------------------------------------------;
  534. int ioctlBufferSetFrequency(PDIOCPARAMETERS pdiocp)
  535. {
  536. PIDSDRIVERBUFFER pBuf;
  537. DWORD dwFrequency;
  538. DSVAL dsv;
  539. IOSTART(2*4);
  540. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  541. IOINPUT(dwFrequency, DWORD);
  542. dsv = pBuf->SetFrequency(dwFrequency);
  543. IOOUTPUT(dsv, DSVAL);
  544. IORETURN;
  545. return 0;
  546. }
  547. //--------------------------------------------------------------------------;
  548. //
  549. //
  550. //
  551. //--------------------------------------------------------------------------;
  552. int ioctlBufferSetVolumePan(PDIOCPARAMETERS pdiocp)
  553. {
  554. PIDSDRIVERBUFFER pBuf;
  555. PDSVOLUMEPAN pVolPan;
  556. DSVAL dsv;
  557. IOSTART(2*4);
  558. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  559. IOINPUT(pVolPan, PDSVOLUMEPAN);
  560. dsv = pBuf->SetVolumePan(pVolPan);
  561. IOOUTPUT(dsv, DSVAL);
  562. IORETURN;
  563. return 0;
  564. }
  565. //--------------------------------------------------------------------------;
  566. //
  567. //
  568. //
  569. //--------------------------------------------------------------------------;
  570. int ioctlBufferSetPosition(PDIOCPARAMETERS pdiocp)
  571. {
  572. PIDSDRIVERBUFFER pBuf;
  573. DWORD dwNewPosition;
  574. DSVAL dsv;
  575. IOSTART(2*4);
  576. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  577. IOINPUT(dwNewPosition, DWORD);
  578. dsv = pBuf->SetPosition(dwNewPosition);
  579. IOOUTPUT(dsv, DSVAL);
  580. IORETURN;
  581. return 0;
  582. }
  583. int ioctlBufferGetPosition(PDIOCPARAMETERS pdiocp)
  584. {
  585. PIDSDRIVERBUFFER pBuf;
  586. LPDWORD lpdwCurrentPlayCursor;
  587. LPDWORD lpdwCurrentWriteCursor;
  588. DSVAL dsv;
  589. IOSTART(3*4);
  590. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  591. IOINPUT(lpdwCurrentPlayCursor, LPDWORD);
  592. IOINPUT(lpdwCurrentWriteCursor, LPDWORD);
  593. dsv = pBuf->GetPosition( lpdwCurrentPlayCursor,
  594. lpdwCurrentWriteCursor );
  595. IOOUTPUT(dsv, DSVAL);
  596. IORETURN;
  597. return 0;
  598. }
  599. //--------------------------------------------------------------------------;
  600. //
  601. //
  602. //
  603. //--------------------------------------------------------------------------;
  604. int ioctlBufferPlay(PDIOCPARAMETERS pdiocp)
  605. {
  606. PIDSDRIVERBUFFER pBuf;
  607. DWORD dwReserved1;
  608. DWORD dwReserved2;
  609. DWORD dwFlags;
  610. DSVAL dsv;
  611. IOSTART(4*4);
  612. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  613. IOINPUT(dwReserved1, DWORD);
  614. IOINPUT(dwReserved2, DWORD);
  615. IOINPUT(dwFlags, DWORD);
  616. dsv = pBuf->Play(dwReserved1, dwReserved2, dwFlags);
  617. IOOUTPUT(dsv, DSVAL);
  618. IORETURN;
  619. return 0;
  620. }
  621. int ioctlBufferStop(PDIOCPARAMETERS pdiocp)
  622. {
  623. PIDSDRIVERBUFFER pBuf;
  624. DSVAL dsv;
  625. IOSTART(1*4);
  626. IOINPUT(pBuf, PIDSDRIVERBUFFER);
  627. dsv = pBuf->Stop();
  628. IOOUTPUT(dsv, DSVAL);
  629. IORETURN;
  630. return 0;
  631. }
  632. //--------------------------------------------------------------------------;
  633. //
  634. //
  635. //
  636. //--------------------------------------------------------------------------;
  637. int ioctlIDirectSoundPropertySet_GetProperty(PDIOCPARAMETERS pdiocp)
  638. {
  639. PIDSDRIVERPROPERTYSET pIDsPropertySet;
  640. PDSPROPERTY pProperty;
  641. PVOID pParams;
  642. ULONG cbParams;
  643. PVOID pData;
  644. ULONG cbData;
  645. PULONG pcbReturnedData;
  646. HRESULT hr;
  647. IOSTART(7*4);
  648. IOINPUT(pIDsPropertySet, PIDSDRIVERPROPERTYSET);
  649. IOINPUT(pProperty, PDSPROPERTY);
  650. IOINPUT(pParams, PVOID);
  651. IOINPUT(cbParams, ULONG);
  652. IOINPUT(pData, PVOID);
  653. IOINPUT(cbData, ULONG);
  654. IOINPUT(pcbReturnedData, PULONG);
  655. hr = pIDsPropertySet->Get(pProperty, pParams, cbParams, pData, cbData, pcbReturnedData);
  656. IOOUTPUT(hr, HRESULT);
  657. IORETURN;
  658. return 0;
  659. }
  660. //--------------------------------------------------------------------------;
  661. //
  662. //
  663. //
  664. //--------------------------------------------------------------------------;
  665. int ioctlIDirectSoundPropertySet_SetProperty(PDIOCPARAMETERS pdiocp)
  666. {
  667. PIDSDRIVERPROPERTYSET pIDsPropertySet;
  668. PDSPROPERTY pProperty;
  669. PVOID pParams;
  670. ULONG cbParams;
  671. PVOID pData;
  672. ULONG cbData;
  673. HRESULT hr;
  674. IOSTART(6*4);
  675. IOINPUT(pIDsPropertySet, PIDSDRIVERPROPERTYSET);
  676. IOINPUT(pProperty, PDSPROPERTY);
  677. IOINPUT(pParams, PVOID);
  678. IOINPUT(cbParams, ULONG);
  679. IOINPUT(pData, PVOID);
  680. IOINPUT(cbData, ULONG);
  681. hr = pIDsPropertySet->Set(pProperty, pParams, cbParams, pData, cbData);
  682. IOOUTPUT(hr, HRESULT);
  683. IORETURN;
  684. return 0;
  685. }
  686. //--------------------------------------------------------------------------;
  687. //
  688. //
  689. //
  690. //--------------------------------------------------------------------------;
  691. int ioctlIDirectSoundPropertySet_QuerySupport(PDIOCPARAMETERS pdiocp)
  692. {
  693. PIDSDRIVERPROPERTYSET pIDsPropertySet;
  694. LPGUID rPropSetId;
  695. ULONG ulPropertyId;
  696. PULONG pulSupport;
  697. HRESULT hr;
  698. IOSTART(4*4);
  699. IOINPUT(pIDsPropertySet, PIDSDRIVERPROPERTYSET);
  700. IOINPUT(rPropSetId, LPGUID);
  701. IOINPUT(ulPropertyId, ULONG);
  702. IOINPUT(pulSupport, PULONG);
  703. hr = pIDsPropertySet->QuerySupport((REFGUID)(*rPropSetId), ulPropertyId, pulSupport);
  704. IOOUTPUT(hr, HRESULT);
  705. IORETURN;
  706. return 0;
  707. }
  708. //--------------------------------------------------------------------------;
  709. //
  710. //
  711. //
  712. //--------------------------------------------------------------------------;
  713. int ioctlEventScheduleWin32Event(PDIOCPARAMETERS pdiocp)
  714. {
  715. DWORD vxdhEvent;
  716. DWORD dwDelay;
  717. BOOL fReturn;
  718. IOSTART(2*4);
  719. IOINPUT(vxdhEvent, DWORD);
  720. IOINPUT(dwDelay, DWORD);
  721. fReturn = eventScheduleWin32Event(vxdhEvent, dwDelay);
  722. // REMIND should implement something to cancel outstanding timeouts
  723. // and events when we shutdown.
  724. IOOUTPUT(fReturn, BOOL);
  725. IORETURN;
  726. return 0;
  727. }
  728. int ioctlEventCloseVxDHandle(PDIOCPARAMETERS pdiocp)
  729. {
  730. DWORD vxdh;
  731. BOOL fReturn;
  732. IOSTART(1*4);
  733. IOINPUT(vxdh, DWORD);
  734. fReturn = VWIN32_CloseVxDHandle(vxdh);
  735. IOOUTPUT(fReturn, BOOL);
  736. IORETURN;
  737. return 0;
  738. }
  739. //--------------------------------------------------------------------------;
  740. //
  741. // ioctlMemReserveAlias
  742. //
  743. // Given a ptr to a buffer and length, this function will reserve linear
  744. // address space to be used as an alias ptr to the same buffer. The reserved
  745. // linear space does not have the buffer memory committed to it. That is done
  746. // by ioctlMemCommitAlias.
  747. //
  748. //--------------------------------------------------------------------------;
  749. int ioctlMemReserveAlias(PDIOCPARAMETERS pdiocp)
  750. {
  751. LPBYTE pBuffer;
  752. DWORD cbBuffer;
  753. LPBYTE pAlias;
  754. LPBYTE pBufferAligned;
  755. DWORD cbBufferAligned;
  756. int cPages;
  757. LPBYTE pAliasAligned;
  758. IOSTART(2*4);
  759. IOINPUT(pBuffer, LPBYTE);
  760. IOINPUT(cbBuffer, DWORD);
  761. DPF(("ioctlMemReserveAlias pBuffer=%08Xh cbBuffer=%d", pBuffer, cbBuffer));
  762. pBufferAligned = (LPBYTE)(((DWORD)pBuffer) & ~(P_SIZE-1));
  763. cPages = (pBuffer+cbBuffer - pBufferAligned+ P_SIZE-1) / P_SIZE;
  764. cbBufferAligned = cPages * P_SIZE;
  765. DPF((" pBufferAligned=%08Xh cPages=%d cbBufferAligned=%d",
  766. pBufferAligned, cPages, cbBufferAligned));
  767. //
  768. // Reserve linear address space
  769. //
  770. pAliasAligned = (LPBYTE)_PageReserve(PR_SHARED, cPages, PR_FIXED);
  771. if (((LPBYTE)(-1) == pAliasAligned) || (NULL == pAliasAligned)) {
  772. pAlias = NULL;
  773. } else {
  774. pAlias = pAliasAligned + (pBuffer - pBufferAligned);
  775. }
  776. DPF((" pAliasAligned=%08Xh pAlias=%08Xh", pAliasAligned, pAlias));
  777. IOOUTPUT(pAlias, LPBYTE);
  778. IORETURN;
  779. return 0;
  780. }
  781. //--------------------------------------------------------------------------;
  782. //
  783. //
  784. //
  785. //--------------------------------------------------------------------------;
  786. int ioctlMemCommitAlias(PDIOCPARAMETERS pdiocp)
  787. {
  788. LPBYTE pAlias;
  789. LPBYTE pBuffer;
  790. DWORD cbBuffer;
  791. BOOL fSuccess;
  792. LPBYTE pBufferAligned;
  793. LPBYTE pAliasAligned;
  794. ULONG nPageBuffer;
  795. ULONG nPageAlias;
  796. int cPages;
  797. IOSTART(3*4);
  798. IOINPUT(pAlias, LPBYTE);
  799. IOINPUT(pBuffer, LPBYTE);
  800. IOINPUT(cbBuffer, DWORD);
  801. // DPF(("ioctlMemCommitAlias pBuffer=%08Xh cbBuffer=%d pAlias=%08Xh",
  802. // pBuffer, cbBuffer, pAlias));
  803. pBufferAligned = (LPBYTE)(((DWORD)pBuffer) & ~(P_SIZE-1));
  804. pAliasAligned = (LPBYTE)(((DWORD)pAlias) & ~(P_SIZE-1));
  805. cPages = (pBuffer+cbBuffer - pBufferAligned+ P_SIZE-1) / P_SIZE;
  806. nPageBuffer = ((ULONG)pBufferAligned) / P_SIZE;
  807. nPageAlias = ((ULONG)pAliasAligned) / P_SIZE;
  808. // DPF((" pBufferAligned=%08Xh pAliasAligned=%08Xh cPages=%d",
  809. // pBufferAligned, pAliasAligned, cPages));
  810. fSuccess = VMM_PageAttach(nPageBuffer, VMM_GetCurrentContext(),
  811. nPageAlias, cPages);
  812. IOOUTPUT(fSuccess, BOOL);
  813. IORETURN;
  814. return 0;
  815. }
  816. //--------------------------------------------------------------------------;
  817. //
  818. //
  819. //
  820. //--------------------------------------------------------------------------;
  821. int ioctlMemDecommitAlias(PDIOCPARAMETERS pdiocp)
  822. {
  823. LPBYTE pAlias;
  824. DWORD cbBuffer;
  825. BOOL fSuccess;
  826. int cPages;
  827. LPBYTE pAliasAligned;
  828. LPBYTE pPageAlias;
  829. ULONG nPageAlias;
  830. IOSTART(2*4);
  831. IOINPUT(pAlias, LPBYTE);
  832. IOINPUT(cbBuffer, DWORD);
  833. // DPF(("iocltMemDecommitAlias pAlias=%08Xh", pAlias));
  834. pAliasAligned = (LPBYTE)(((DWORD)pAlias) & ~(P_SIZE-1));
  835. cPages = (pAlias + cbBuffer - pAliasAligned+ P_SIZE-1) / P_SIZE;
  836. pPageAlias = pAliasAligned;
  837. nPageAlias = ((ULONG)pPageAlias) / P_SIZE;
  838. // DPF((" nPageAlias=%08Xh nPages=%d", nPageAlias, cPages));
  839. fSuccess = (0 != _PageDecommit(nPageAlias, cPages, 0));
  840. ASSERT(fSuccess);
  841. IOOUTPUT(fSuccess, BOOL);
  842. IORETURN;
  843. return 0;
  844. }
  845. //--------------------------------------------------------------------------;
  846. //
  847. //
  848. //
  849. //--------------------------------------------------------------------------;
  850. int ioctlMemRedirectAlias(PDIOCPARAMETERS pdiocp)
  851. {
  852. LPBYTE pAlias;
  853. DWORD cbBuffer;
  854. BOOL fSuccess;
  855. LPBYTE pAliasAligned;
  856. ULONG nPageAlias;
  857. ULONG nPageGarbage;
  858. int cPages;
  859. IOSTART(2*4);
  860. IOINPUT(pAlias, LPBYTE);
  861. IOINPUT(cbBuffer, DWORD);
  862. DPF(("ioctlMemRedirectAlias pAlias=%08Xh cbBuffer=%d", pAlias, cbBuffer));
  863. pAliasAligned = (LPBYTE)(((DWORD)pAlias) & ~(P_SIZE-1));
  864. cPages = (pAlias+cbBuffer - pAliasAligned + P_SIZE-1) / P_SIZE;
  865. nPageAlias = ((ULONG)pAliasAligned) / P_SIZE;
  866. nPageGarbage = ((ULONG)gpGarbagePage) / P_SIZE;
  867. // DPF((" pAliasAligned=%08Xh cPages=%d pGarbagePage=%08Xh",
  868. // pAliasAligned, cPages, gpGarbagePage));
  869. // We point every alias page at the same garbage page. This is
  870. // MustComplete since the app's thread that is using the alias
  871. // pointer might not be this current thread and may be writing
  872. // thru the alias pointer. We wouldn't want the app's thread to
  873. // run while the alias pages are decommitted.
  874. VMM_EnterMustComplete();
  875. fSuccess = (0 != _PageDecommit(nPageAlias, cPages, 0));
  876. while (fSuccess && cPages--) {
  877. fSuccess = VMM_PageAttach(nPageGarbage, VMM_GetCurrentContext(),
  878. nPageAlias++, 1);
  879. }
  880. VMM_LeaveMustComplete();
  881. IOOUTPUT(fSuccess, BOOL);
  882. IORETURN;
  883. return 0;
  884. }
  885. //--------------------------------------------------------------------------;
  886. //
  887. //
  888. //
  889. //--------------------------------------------------------------------------;
  890. int ioctlMemFreeAlias(PDIOCPARAMETERS pdiocp)
  891. {
  892. LPBYTE pAlias;
  893. DWORD cbBuffer;
  894. BOOL fSuccess;
  895. LPBYTE pAliasAligned;
  896. LPBYTE pPageAlias;
  897. IOSTART(2*4);
  898. IOINPUT(pAlias, LPBYTE);
  899. IOINPUT(cbBuffer, DWORD);
  900. DPF(("iocltMemFreeAlias pAlias=%08Xh", pAlias));
  901. pAliasAligned = (LPBYTE)(((DWORD)pAlias) & ~(P_SIZE-1));
  902. pPageAlias = pAliasAligned;
  903. DPF((" pPageAlias=%08Xh", pPageAlias));
  904. fSuccess = VMM_PageFree(pPageAlias, 0);
  905. ASSERT(fSuccess);
  906. IOOUTPUT(fSuccess, BOOL);
  907. IORETURN;
  908. return 0;
  909. }
  910. //--------------------------------------------------------------------------;
  911. //
  912. //
  913. //
  914. //--------------------------------------------------------------------------;
  915. int ioctlMemPageLock(PDIOCPARAMETERS pdiocp)
  916. {
  917. LPBYTE pMem;
  918. DWORD cbBuffer;
  919. DWORD dwFlags;
  920. BOOL fSuccess;
  921. LPBYTE pMemAligned;
  922. ULONG nPageMem;
  923. int cPages;
  924. LPDWORD pdwTable;
  925. LPVOID *ppTable;
  926. DWORD cPagesTable;
  927. IOSTART(5*4);
  928. IOINPUT(pMem, LPBYTE);
  929. IOINPUT(cbBuffer, DWORD);
  930. IOINPUT(dwFlags, DWORD);
  931. IOINPUT(pdwTable, LPDWORD);
  932. IOINPUT(ppTable, LPVOID*);
  933. pMemAligned = (LPBYTE)(((DWORD)pMem) & ~(P_SIZE-1));
  934. cPages = (pMem+cbBuffer - pMemAligned+ P_SIZE-1) / P_SIZE;
  935. nPageMem = ((ULONG)pMemAligned) / P_SIZE;
  936. // Allocate the physical table
  937. cPagesTable = (cPages-1)/1024 + 1;
  938. *pdwTable = 0;
  939. // Make sure that it is contiguous (requires FIXED & USEALIGN)
  940. *ppTable = _PageAllocate(cPagesTable, PG_SYS,
  941. Get_Sys_VM_Handle(), 0, 0, 0xffffff, (LPVOID *) pdwTable,
  942. dwFlags | PAGEUSEALIGN | PAGEFIXED | PAGECONTIG);
  943. if (*pdwTable == 0)
  944. fSuccess = 0;
  945. else
  946. fSuccess = 1;
  947. if (fSuccess)
  948. {
  949. /*
  950. * Mask off the stuff that Intel gives us in the page table's physical address
  951. */
  952. *pdwTable = (*pdwTable) & 0xfffff000;
  953. fSuccess = _LinPageLock(nPageMem, cPages, dwFlags);
  954. if (!fSuccess)
  955. {
  956. _PageFree((LPVOID)*ppTable, 0);
  957. *ppTable = 0;
  958. *pdwTable = 0;
  959. }
  960. }
  961. if (fSuccess)
  962. {
  963. fSuccess = _CopyPageTable(nPageMem, cPages, (LPDWORD)*ppTable, 0);
  964. if (!fSuccess)
  965. {
  966. _LinPageUnLock(nPageMem, cPages, dwFlags);
  967. _PageFree((LPVOID)*ppTable, 0);
  968. *ppTable = 0;
  969. *pdwTable = 0;
  970. }
  971. }
  972. IOOUTPUT(fSuccess, BOOL);
  973. IORETURN;
  974. return 0;
  975. }
  976. //--------------------------------------------------------------------------;
  977. //
  978. //
  979. //
  980. //--------------------------------------------------------------------------;
  981. int ioctlMemPageUnlock(PDIOCPARAMETERS pdiocp)
  982. {
  983. LPBYTE pMem;
  984. DWORD cbBuffer;
  985. DWORD dwFlags;
  986. BOOL fSuccess;
  987. LPBYTE pMemAligned;
  988. ULONG nPageMem;
  989. int cPages;
  990. LPDWORD pTable;
  991. IOSTART(4*4);
  992. IOINPUT(pMem, LPBYTE);
  993. IOINPUT(cbBuffer, DWORD);
  994. IOINPUT(dwFlags, DWORD);
  995. IOINPUT(pTable, LPDWORD);
  996. pMemAligned = (LPBYTE)(((DWORD)pMem) & ~(P_SIZE-1));
  997. cPages = (pMem + cbBuffer - pMemAligned + P_SIZE-1) / P_SIZE;
  998. nPageMem = ((ULONG)pMemAligned) / P_SIZE;
  999. fSuccess = _LinPageUnLock(nPageMem, cPages, dwFlags);
  1000. if (fSuccess)
  1001. {
  1002. _PageFree((LPVOID)pTable, 0);
  1003. }
  1004. IOOUTPUT(fSuccess, BOOL);
  1005. IORETURN;
  1006. return 0;
  1007. }
  1008. //--------------------------------------------------------------------------;
  1009. //
  1010. //
  1011. //
  1012. //--------------------------------------------------------------------------;
  1013. int ioctlMemCommitPhysAlias(PDIOCPARAMETERS pdiocp)
  1014. {
  1015. LPBYTE pAlias;
  1016. LPBYTE pBuffer;
  1017. DWORD cbBuffer;
  1018. BOOL fSuccess;
  1019. LPBYTE pBufferAligned;
  1020. LPBYTE pAliasAligned;
  1021. LPBYTE pEndOfBuffer;
  1022. ULONG nPageBuffer;
  1023. ULONG nPageAlias;
  1024. ULONG nPhysPage;
  1025. int cPages;
  1026. DWORD dwPTE;
  1027. IOSTART(3*4);
  1028. IOINPUT(pAlias, LPBYTE);
  1029. IOINPUT(pBuffer, LPBYTE);
  1030. IOINPUT(cbBuffer, DWORD);
  1031. DPF(("ioctlMemCommitAlias pBuffer=%08Xh cbBuffer=%d pAlias=%08Xh",
  1032. pBuffer, cbBuffer, pAlias));
  1033. pEndOfBuffer = pBuffer + cbBuffer;
  1034. pBufferAligned = (LPBYTE)(((DWORD)pBuffer) & ~(P_SIZE-1));
  1035. pAliasAligned = (LPBYTE)(((DWORD)pAlias) & ~(P_SIZE-1));
  1036. cPages = (pEndOfBuffer - pBufferAligned + P_SIZE-1) / P_SIZE;
  1037. nPageBuffer = ((ULONG)pBufferAligned) / P_SIZE;
  1038. nPageAlias = ((ULONG)pAliasAligned) / P_SIZE;
  1039. DPF((" pBufferAligned=%08Xh pAliasAligned=%08Xh cPages=%d",
  1040. pBufferAligned, pAliasAligned, cPages));
  1041. // ALERT: A really very nasty hack. We DO NOT want to commit the alias
  1042. // to the given memory if the memory really is system rather than video
  1043. // memory (the pages could change the physical pages and we will be left
  1044. // pointing at garbage). Therefore, we need to make sure this is physical
  1045. // memory outside the memory managers control and not system memory. The
  1046. // problem is how to do this. Well, we really want to test the internal
  1047. // memory manage PT_PHYS bit but this is undocumented so instead I try
  1048. // to simply use VMM_PageAttach() as we know this will fail if you give it
  1049. // physical pages. Hence if the PageAttach() works we have system memory
  1050. // and we do NOT want to commit the alias. However, if it fails all should
  1051. // be well and we can commit the memory.
  1052. //
  1053. // Told you it was ugly (CMcC)
  1054. fSuccess = VMM_PageAttach(nPageBuffer, VMM_GetCurrentContext(),
  1055. nPageAlias, cPages);
  1056. if (fSuccess)
  1057. {
  1058. DPF((" Heap memory is system memory. Not commiting the alias" ));
  1059. _PageDecommit(nPageAlias, cPages, 0);
  1060. IOOUTPUT(FALSE, BOOL);
  1061. IORETURN;
  1062. return 0;
  1063. }
  1064. VMM_EnterMustComplete();
  1065. fSuccess = TRUE;
  1066. while (fSuccess && cPages--) {
  1067. fSuccess = _CopyPageTable(nPageBuffer++, 1UL, &dwPTE, 0UL);
  1068. if (fSuccess) {
  1069. nPhysPage = (dwPTE >> 12UL) & 0x000FFFFF;
  1070. fSuccess = _PageCommitPhys(nPageAlias++, 1, nPhysPage, PC_USER | PC_WRITEABLE);
  1071. }
  1072. }
  1073. VMM_LeaveMustComplete();
  1074. IOOUTPUT(fSuccess, BOOL);
  1075. IORETURN;
  1076. return 0;
  1077. }
  1078. //--------------------------------------------------------------------------;
  1079. //
  1080. //
  1081. //
  1082. //--------------------------------------------------------------------------;
  1083. int ioctlMemRedirectPhysAlias(PDIOCPARAMETERS pdiocp)
  1084. {
  1085. LPBYTE pAlias;
  1086. DWORD cbBuffer;
  1087. BOOL fSuccess;
  1088. LPBYTE pAliasAligned;
  1089. ULONG nPageAlias;
  1090. ULONG nPageGarbage;
  1091. int cPages;
  1092. IOSTART(2*4);
  1093. IOINPUT(pAlias, LPBYTE);
  1094. IOINPUT(cbBuffer, DWORD);
  1095. DPF(("ioctlMemRedirectPhysAlias pAlias=%08Xh cbBuffer=%d", pAlias, cbBuffer));
  1096. pAliasAligned = (LPBYTE)(((DWORD)pAlias) & ~(P_SIZE-1));
  1097. cPages = (pAlias+cbBuffer - pAliasAligned + P_SIZE-1) / P_SIZE;
  1098. nPageAlias = ((ULONG)pAliasAligned) / P_SIZE;
  1099. nPageGarbage = (ULONG)_GetNulPageHandle();
  1100. // DPF((" pAliasAligned=%08Xh cPages=%d pGarbagePage=%08Xh",
  1101. // pAliasAligned, cPages, gpGarbagePage));
  1102. // We point every alias page at the same garbage page. This is
  1103. // MustComplete since the app's thread that is using the alias
  1104. // pointer might not be this current thread and may be writing
  1105. // thru the alias pointer. We wouldn't want the app's thread to
  1106. // run while the alias pages are decommitted.
  1107. VMM_EnterMustComplete();
  1108. fSuccess = (0 != _PageDecommit(nPageAlias, cPages, 0));
  1109. if (fSuccess)
  1110. fSuccess = _PageCommitPhys(nPageAlias, cPages, nPageGarbage, PC_USER | PC_WRITEABLE);
  1111. VMM_LeaveMustComplete();
  1112. IOOUTPUT(fSuccess, BOOL);
  1113. IORETURN;
  1114. return 0;
  1115. }
  1116. //--------------------------------------------------------------------------;
  1117. //
  1118. //
  1119. //
  1120. //--------------------------------------------------------------------------;
  1121. int ioctlGetInternalVersionNumber(PDIOCPARAMETERS pdiocp)
  1122. {
  1123. #ifndef VER_PRODUCTVERSION_DW
  1124. #define VER_PRODUCTVERSION_DW MAKELONG(MAKEWORD(MANVERSION, MANREVISION), MAKEWORD(MANMINORREV, BUILD_NUMBER))
  1125. #endif // VER_PRODUCTVERSION_DW
  1126. IOSTART(0*4);
  1127. IOOUTPUT(VER_PRODUCTVERSION_DW, DWORD);
  1128. IORETURN;
  1129. return 0;
  1130. }