sysheap.inc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by Free Pascal development team
  4. This file implements all the base types and limits required
  5. for a minimal POSIX compliant subset required to port the compiler
  6. to a new OS.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {*****************************************************************************
  14. Heap Management
  15. *****************************************************************************}
  16. function SysOSAlloc (size: ptruint): pointer;
  17. var
  18. regs : Registers;
  19. nb_para : longint;
  20. begin
  21. {$ifdef DEBUG_TINY_HEAP}
  22. writeln('SysOSAlloc called size=',size);
  23. {$endif}
  24. {$if defined(FPC_X86_DATA_FAR) or defined(FPC_X86_DATA_HUGE)}
  25. regs.ax:=$4800;
  26. nb_para:=size div 16;
  27. if nb_para > $ffff then
  28. begin
  29. {$ifdef DEBUG_TINY_HEAP}
  30. writeln('SysOSAlloc size too big = ',size);
  31. {$endif}
  32. result:=nil;
  33. end
  34. else
  35. begin
  36. regs.bx:=nb_para;
  37. msdos(regs);
  38. if (regs.Flags and fCarry) <> 0 then
  39. begin
  40. {$ifdef DEBUG_TINY_HEAP}
  41. writeln('SysOSAlloc failed, err = ',regs.AX);
  42. {$endif}
  43. { Do not set InOutRes if ReturnNilIfGrowHeapFails is set }
  44. if not ReturnNilIfGrowHeapFails then
  45. GetInOutRes(regs.AX);
  46. Result := nil;
  47. end
  48. else
  49. begin
  50. result:=ptr(regs.ax,0);
  51. {$ifdef DEBUG_TINY_HEAP}
  52. writeln('SysOSAlloc returned= $',hexstr(seg(result),4),':$',hexstr(ofs(result),4));
  53. {$endif}
  54. end;
  55. end;
  56. {$else not DATA_FAR}
  57. {$ifdef DEBUG_TINY_HEAP}
  58. writeln('SysOSAlloc cannot be used in small data models');
  59. {$endif}
  60. Result := nil;
  61. {$endif not DATA_FAR}
  62. end;
  63. procedure SysOSFree(p: pointer; size: ptruint);
  64. begin
  65. end;