INF: exec and spawn (P_OVERLAY) Will Fail When Bound

ID Number: Q43319

5.10 6.00 6.00a 6.00ax | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

The Microsoft C run-time library functions exec() and spawn() (with a

P_OVERLAY attribute) do not work correctly when run in a bound

application under MS-DOS. This is briefly documented on page 24 of the

"Microsoft C for MS OS/2 and MS-DOS Operating Systems: Version 5.1

Update" manual. The execution fails and the program returns the

following error message:

run-time error R6006

- bad format on exec

This occurs only when the dual-mode program is running under MS-DOS. A

spawn with the P_WAIT attribute works properly.

More Information:

Examining the DosExecPgm() API reveals that there is no option to

overlay the currently running program. OS/2's protection scheme does

not support overwriting the code segment; therefore, to exec another

program, it is necessary to actually spawn the program in a different

area of memory and terminate the current process.

To create a bound program that uses overlays, not only would a

remapping of the FAPI (Family API) function be necessary, but also a

complete reprogramming to allow for loading over the current code

segment. At this time, BIND does not support this.

The following functions do not work properly when run under MS-DOS in

a bound application:

execl execle execlp execlpe execv execve execvp

execvpe spawnl spawnl spawnle spawnlp spawnlpe spawnv

spawnve spawnvp spawnvpe

Note: The spawn() functions fail only with the P_OVERLAY attribute.

The following program fails to spawn PROG.EXE from MS-DOS:

Sample Code

-----------

/* Program: spawn.c */

/* */

/* Compile and bind from OS/2 with: */

/* */

/* cl /Lp spawn.c */

/* bind spawn /c/lib/api.lib /c/lib/doscalls.lib */

#include <stdio.h>

#include <process.h>

void main(void)

{

spawnl(P_OVERLAY,"c:\\tmp\\prog.exe","prog",NULL);

}

Additional reference words: 6.0 6.00 6.0a 6.00a 6.0ax 6.00ax