exec() and spawn() with P_OVERLAY Ignore Max Allocation

ID: Q48793


The information in this article applies to:
  • The C Run-Time (CRT), included with:
    • Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, 6.0ax
    • Microsoft C/C++ for MS-DOS, version 7.0
    • Microsoft Visual C++ for Windows, versions 1.0, 1.5


SUMMARY

The Microsoft C Run-time functions exec() and spawn() with P_OVERLAY ignore the maximum memory allocation information in the .EXE file header. If you exec or spawn with P_OVERLAY, a program whose maximum allocation is set equal to the minimum allocation (through EXEMOD or the LINK option /CP:1), the program is allocated the full 64K DGROUP.


MORE INFORMATION

The effective maximum allocation for any exec'ed (or spawn'ed with P_OVERLAY) program is 0xffff (whatever MS-DOS has available), regardless of the maximum allocation number in the program's .EXE header. When run from the MS-DOS prompt, the maximum allocation information of the same program is honored.

This behavior occurs because the exec() and spawn() functions with P_OVERLAY do not invoke COMMAND.COM, which looks at the minalloc and maxalloc fields in the .EXE file header. This is expected behavior for exec() and spawn() with P_OVERLAY. This is documented in the C run-time reference documentation for the exec() functions.

Alternatives

Instead of calling a program with exec() or spawn() with P_OVERLAY, call COMMAND.COM with the desired child program as an argument using exec() or spawn() with P_OVERLAY, as follows:

   spawnl(P_OVERLAY,"c:\\command.com","command.com",
          "/cchild.exe",NULL); 
COMMAND.COM then loads your application as if it was from the MS-DOS prompt. Note, however, that the COMMAND.COM shell itself requires approximately 4K. Also, consecutive exec() or spawn() with P_OVERLAY calls using this method run additional shells of COMMAND.COM, accumulating one 4K shell per generation, as illustrated below:

          +------+    +------+    +------+    +------+
          |  P1  |--> |__P2__|--> |__P3__|--> |__P4__|
          +------+    | .COM |    |_.COM_|    |_.COM_|
                      +------+    | .COM |    |_.COM_|
                                  +------+    | .COM |
                                              +------+ 
Another option is to call your program with the system() function, but this does not overlay the child process.

Additional query words: 1.00 1.50 6.00 6.00a 6.00ax 7.00 kbinf execl execle execlp execlpe execcv execve execvp execvpe spawnl spawnle spawnlp spawnlpe spawnv spawnve spawnvp spawnvpe

Keywords : kb16bitonly
Version : winnt:
Platform : winnt
Issue type :


Last Reviewed: January 4, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.