sysheap.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001-2014 by Free Pascal development team
  4. This file implements heap management for OS/2.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {****************************************************************************
  12. Heap management releated routines.
  13. ****************************************************************************}
  14. {Get some memory.
  15. P = Pointer to memory will be returned here.
  16. Size = Number of bytes to get. The size is rounded up to a multiple
  17. of 4096. This is probably not the case on non-intel 386
  18. versions of OS/2.
  19. Flags = One or more of the mfXXXX constants.}
  20. function DosAllocMem(var P:pointer;Size,Flag:cardinal): cardinal; cdecl;
  21. external 'DOSCALLS' index 299;
  22. function DosSetMem(P:pointer;Size,Flag:cardinal): cardinal; cdecl;
  23. external 'DOSCALLS' index 305;
  24. function DosFreeMem (P: pointer): cardinal; cdecl;
  25. external 'DOSCALLS' index 304;
  26. {$IFDEF DUMPGROW}
  27. {$DEFINE EXTDUMPGROW}
  28. {$ENDIF DUMPGROW}
  29. {$IFDEF EXTDUMPGROW}
  30. var
  31. Int_HeapSize: cardinal;
  32. {$ENDIF EXTDUMPGROW}
  33. {function GetHeapSize: longint; assembler;
  34. asm
  35. movl Int_HeapSize, %eax
  36. end ['EAX'];
  37. }
  38. function SysOSAlloc (Size: ptruint): pointer;
  39. var
  40. P: pointer;
  41. RC: cardinal;
  42. begin
  43. {$IFDEF EXTDUMPGROW}
  44. if Int_HeapSize <> high (cardinal) then
  45. {
  46. if Int_HeapSize = high (cardinal) then
  47. WriteLn ('Trying to allocate first heap of size ', Size)
  48. else
  49. }
  50. WriteLn ('Trying to grow heap by ', Size, ' to ', Int_HeapSize);
  51. {$ENDIF}
  52. RC := DosAllocMem (P, Size, HeapAllocFlags);
  53. if RC = 0 then
  54. begin
  55. {$IFDEF EXTDUMPGROW}
  56. if Int_HeapSize <> high (cardinal) then
  57. WriteLn ('DosAllocMem returned memory at ', cardinal (P));
  58. {$ENDIF}
  59. SysOSAlloc := P;
  60. {$IFDEF EXTDUMPGROW}
  61. if Int_HeapSize = high (cardinal) then
  62. Int_HeapSize := Size
  63. else
  64. Inc (Int_HeapSize, Size);
  65. {$ENDIF EXTDUMPGROW}
  66. end
  67. else
  68. begin
  69. SysOSAlloc := nil;
  70. OSErrorWatch (RC);
  71. {$IFDEF EXTDUMPGROW}
  72. if Int_HeapSize <> high (cardinal) then
  73. begin
  74. WriteLn ('Error ', RC, ' during additional memory allocation (DosAllocMem)!');
  75. { if Int_HeapSize = high (cardinal) then
  76. WriteLn ('No memory allocated yet!')
  77. else
  78. }
  79. WriteLn ('Total allocated memory is ', Int_HeapSize);
  80. end;
  81. {$ENDIF EXTDUMPGROW}
  82. end;
  83. end;
  84. {$define HAS_SYSOSFREE}
  85. procedure SysOSFree (P: pointer; Size: ptruint);
  86. var
  87. RC: cardinal;
  88. begin
  89. {$IFDEF EXTDUMPGROW}
  90. WriteLn ('Trying to free memory!');
  91. WriteLn ('Total allocated memory is ', Int_HeapSize);
  92. Dec (Int_HeapSize, Size);
  93. {$ENDIF EXTDUMPGROW}
  94. RC := DosFreeMem (P);
  95. if RC <> 0 then
  96. begin
  97. OSErrorWatch (RC);
  98. {$IFDEF EXTDUMPGROW}
  99. WriteLn ('Error ', RC, ' during memory deallocation (DosFreeMem)!');
  100. WriteLn ('Total allocated memory is ', Int_HeapSize);
  101. {$ENDIF EXTDUMPGROW}
  102. end;
  103. end;
  104. function ReadUseHighMem: boolean;
  105. begin
  106. ReadUseHighMem := HeapAllocFlags and $400 = $400;
  107. end;
  108. procedure WriteUseHighMem (B: boolean);
  109. begin
  110. if B then
  111. HeapAllocFlags := HeapAllocFlags or $400
  112. else
  113. HeapAllocFlags := HeapAllocFlags and not ($400);
  114. end;