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.

103 lines
2.0 KiB

  1. /*
  2. * xms.c - Main Module of XMS DLL.
  3. *
  4. * Sudeepb 15-May-1991 Craeted
  5. * williamh 25-Sept-1992 added UMB support
  6. * williamh 10-10-1992 added A20 line support
  7. */
  8. #include <xms.h>
  9. #include <suballoc.h>
  10. #include "umb.h"
  11. #include "memapi.h"
  12. /* XMSInit - XMS Initialiazation routine. (This name may change when XMS is
  13. * converted to DLL).
  14. *
  15. * Entry
  16. * None
  17. *
  18. * Exit
  19. * None
  20. */
  21. ULONG xmsMemorySize = (ULONG)0; // Total XMS meory in K
  22. extern BOOL VDMForWOW;
  23. PVOID ExtMemSA;
  24. BOOL XMSInit (int argc, char *argv[])
  25. {
  26. DWORD Size;
  27. PVOID Address;
  28. ULONG VdmAddress, XmsSize;
  29. NTSTATUS Status;
  30. if (!xmsMemorySize)
  31. return FALSE;
  32. Size = 0;
  33. Address = NULL;
  34. // commit all free UMBs.
  35. ReserveUMB(UMB_OWNER_RAM, &Address, &Size);
  36. XmsSize = xmsMemorySize * 1024 - (64*1024);
  37. #ifndef i386
  38. Status = VdmAllocateVirtualMemory(&VdmAddress,
  39. XmsSize,
  40. FALSE);
  41. if (Status == STATUS_NOT_IMPLEMENTED) {
  42. // Old emulator, just assume base address
  43. #endif ; //i386
  44. //
  45. // Initialize the sub allocator
  46. //
  47. ExtMemSA = SAInitialize(
  48. 1024 * 1024 + 64*1024,
  49. XmsSize,
  50. xmsCommitBlock,
  51. xmsDecommitBlock,
  52. xmsMoveMemory
  53. );
  54. #ifndef i386
  55. } else {
  56. //
  57. // New emulator. Make sure the reserve worked
  58. //
  59. if (!NT_SUCCESS(Status)) {
  60. ASSERT(FALSE);
  61. return FALSE;
  62. }
  63. //
  64. // We only work correctly if emulator returned this value
  65. //
  66. if (VdmAddress != (1024 * 1024 + 64*1024)) {
  67. ASSERT(FALSE);
  68. return FALSE;
  69. }
  70. ExtMemSA = SAInitialize(
  71. VdmAddress,
  72. XmsSize,
  73. VdmCommitVirtualMemory,
  74. VdmDeCommitVirtualMemory,
  75. xmsMoveMemory
  76. );
  77. }
  78. #endif // i386
  79. if (ExtMemSA == NULL) {
  80. return FALSE;
  81. }
  82. return TRUE;
  83. }