🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #7056

malloc() and memory models

#7056
From: Terry Peterson
Date: Thu, 13 Jun 1991 03:47
33 lines
1662 bytes
Under the following conditions, malloc() returns to main(), not to its caller,
foo().-- Using TC V2.0

    1) The penultimate caller, main() is compiled as a small model program
    2) The caller of malloc(), foo(), is a library service compiled as a
       large model.

Graphically,

    main()    /* Part of a small model program */
      |
       ------->foo()    /* A library service compiled as a large model */
                |
                 -------> malloc()

When malloc() is called from within foo() the compiler pushes both the CS
register and the IP register on the stack as expected.  However, malloc() does
not return to the code segment where foo() resides, but rather to the code
segment where main() resides!  

Disassembly of the code shows why:  When malloc() is entered, foo()'s CS and
IP are found in their proper place on the stack.  However, when malloc() is
done a "RET" instruction is executed, not RETF.  Hence, only the IP is popped
and the code "returns" to whatever segment malloc() happened to be mapped
into.  In this case, the segment that also contained main()'s code.

How can I arrange to have malloc() return to the calling procedure, foo(), and
NOT to main()?

Thanks, in advance,

/mtp
Technical Details
Message-ID: <4432@polari.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!pilchuck!amc-gw!sumax!polari!empty

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!pilchuck!amc-gw!sumax!polari!empty
From: empty@polari.UUCP (Terry Peterson)
Newsgroups: comp.os.msdos.programmer
Subject: malloc() and memory models
Message-ID: <4432@polari.UUCP>
Date: 13 Jun 91 03:47:20 GMT
Distribution: comp.os.msdos.programmer
Organization: Seattle Online Public Unix (206) 328-4944
Lines: 33