KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q58098: Cannot Use a Pointer to Call Function in a Static Overlay

Article: Q58098
Product(s): Microsoft Programming Utilities
Version(s): MS-DOS:2.x,3.x,4.x,5.0x,5.1,5.11,5.13,5.15,5.2,5.3x,5.5,5.6
Operating System(s): 
Keyword(s): kb16bitonly
Last Modified: 30-OCT-1999

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft LINK for MS-DOS, versions 2.x, 3.x, 4.x, 5.0x, 5.1, 5.11, 5.13, 5.15, 5.2, 5.3x, 5.5, 5.6 
-------------------------------------------------------------------------------

SUMMARY
=======

Microsoft LINK does not support using a function pointer to call a function in a
static overlay unless the function is called from the same overlay. If an
overlaid function is called from the root or from a different overlay, it cannot
be called through a pointer.

MORE INFORMATION
================

Static overlays do not support calling an overlaid function indirectly through a
pointer because the loader determines the address of the indirect function at
load time.

Versions of Microsoft LINK prior to version 5.3 support only static overlays.
LINK version 5.3 introduced MOVE (Microsoft Overlaid Virtual Environment)
dynamic overlays that do support calling an overlaid function through a pointer.
Microsoft LINK versions 5.3x, 5.5, and 5.6 can still generate static overlays
using the /OLD[OVERLAY] command line switch. The same issue of lack of support
for calling an overlaid function through a function pointer still applies to
these later versions.

In an application with static overlays, the linker recognizes a normal function
call (one that does not take place through a pointer) and places an interrupt
call into the executable file instead of the function call. At run time, the
interrupt gives control to the overlay manager which determines if the correct
overlay is loaded in memory, loads the overlay if necessary, and calls the
function. Because the object module contains a fixup record for the function
call, the linker can set the interrupts as required.

On the other hand, when an application uses a function pointer, the compiler
creates a fixup record for the address to which the pointer refers. However, the
fixup record does not indicate that the record provides the address for a
function. Therefore, if the function is linked as an overlay, the linker does
not call the overlay manager but performs a standard fixup.

Consequently, if an application calls a function located in an overlay that is
not loaded in memory, the overlay manager is not called to load the overlay.
Instead, the application passes control to the random data located at the
destination address and disaster can easily result.

Additional query words: kbinf 4.06 4.07 4.10 5.01.20 5.01.21 5.02 5.03 5.05 5.10 5.11 5.13 5.15 5.20 5.30 5.31.009 5.50 5.60

======================================================================
Keywords          : kb16bitonly 
Technology        : kbAudDeveloper kbZNotKeyword3 kbLINKSearch kbLINK2xDOSSearch kbLINK3xDOSSearch kbLINK4xDOSSearch kbLINK50xDOSSearch kbLINK530xDOSSearch kbLINK510DOS kbLINK511DOS kbLINK513DOS kbLINK515DOS kbLINK520DOS kbLINK550DOS kbLINK560DOS
Version           : MS-DOS:2.x,3.x,4.x,5.0x,5.1,5.11,5.13,5.15,5.2,5.3x,5.5,5.6

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.