6

I have a question about this function that has bugged me for years, so I decided to let this community a try :) So, this function supposedly locks a XMS extended memory block in place, and returns an address (or pointer) to it. The problem is that according to the XMS 2.0 specification, a linear address is returned, but according to XMS 3.0, the returned address is physical (which means that it can't be used as a pointer).

My question is, does somebody know how to tell if the returned address is linear or physical? I have read on the internet the following advice:

When there is no EMM386 (or other EMM) or enhanced mode Windows and the CPU is in real mode, there is no difference between linear and physical addresses;

when the CPU is in V86 mode and EMM386 is present, but no enhanced mode Windows, then the returned address is physical (so it can be used directly by a VCPI client);

when the CPU is in V86 mode and enhanced mode Windows is present, then physical addresses are only available to the Windows kernel itself, and the function returns a linear address.

The book "The Old New Thing: Practical Development Throughout the Evolution of Windows" by Raymond Chen says that there is no way to determine if the returned address is linear or physical, and the author's advice is to not use this function at all.

Any thoughts? Thanks in advance.

6
  • Great question. Welcome :)
    – knol
    Apr 26, 2022 at 13:17
  • 1
    For readers: luckily, the pages from Chen's book about locking XMS memory are available in a free bonus chapter here ptgmedia.pearsoncmg.com/images/9780321440303/samplechapter/… , page 44 mentions 0Ch.
    – knol
    Apr 26, 2022 at 13:43
  • If it only depends on XMS version, would you accept "By checking the XMS version" as an answer? What would be the point of knowing if address returned by XMS is physical or linear? And shouldn't it still be best to leave the memory handling to DOS Extender, so it can use DPMI/VCPI or any other system under the hood for best operation?
    – Justme
    Apr 26, 2022 at 14:15
  • @ Justme: "If it only depends on XMS version, would you accept "By checking the XMS version" as an answer?" Unfortunately, it might be not as simple. Yes, I would take it as an answer if I'm sure that it's true. But the version of the specification might be not the same as the version of the actual XMS driver. Apr 26, 2022 at 14:25
  • 1
    @ Justme: "What would be the point of knowing if address returned by XMS is physical or linear?" To know how can I use it. "And shouldn't it still be best to leave the memory handling to DOS Extender, so it can use DPMI/VCPI or any other system under the hood for best operation?" Probably, but what if I'm writing a real mode program and don't use a DOS extender at all? And by the way, for example, VCPI memory allocation is rather awkward; allocating memory with XMS seems much more convenient, provided it works. Apr 26, 2022 at 14:33

1 Answer 1

1

XMS driver function AH = 00h queries the XMS version.

The function is mainly used to get the version of which XMS specification the driver implements and it is returned in AX.

So that can be used to detect which type of addresses the lock function returns.

In addition, the version of the driver itself is returned in BX, but it is mainly used for debugging, as the program can't determine which XMS driver from which manufacturer it is.

6
  • Unfortunately, according to Raymond Chen's book as quoted earlier by @knol, XMS memory managers don't reliably follow the spec anyway: "Moreover, third-party extended memory managers themselves disagree on whether to return a linear or physical address, so even if you checked the version of the XMS provider, you still don’t know whether you got a linear or physical address."
    – john_e
    Apr 26, 2022 at 18:12
  • @john_e Then you need to use the other methods, such as detecting of program is running under Standard or Enhaced Mode Windows or not in Windows at all. Another way is to assume or require a certain memory managers from certain manufacturers which works according to standards.
    – Justme
    Apr 26, 2022 at 20:17
  • @john_e : If a piece of software claims to follow some standard then plainly does not follow said standard, it's buggy and should not be relied upon. Surely there are some other XMS memory managers that are more reliable?
    – paxdiablo
    Apr 27, 2022 at 1:48
  • 1
    Depends how widely compatible the program needs to be. In this day and age when the set of known memory managers is more or less fixed, then maintaining a list of usable or unusable memory managers and limiting compatibility to only usable ones sounds more feasible than it would have been in 1995. It doesn't help that in this case, at least in Raymond Chen's opinion, the 3.0 specification made the wrong choice, so those memory managers that don't follow the spec may be more useful than those that do.
    – john_e
    Apr 27, 2022 at 11:29
  • And, as Chen says, there is not much that the program can do with the locked address. The virtual memory environment can likely be checked. Even if it is a physical address, what useful things can be done with it? Use it as DMA buffer? What if only free memory is available at physical address beyond access of DMA controller, above 16 MB?
    – Justme
    Apr 27, 2022 at 11:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .