INF:Patches of Floating-Point Instructions at Run Time Normal

ID Number: Q42762

5.10 6.00 6.00a 6.00ax 7.00

MS-DOS

Summary:

SYMPTOMS

In Microsoft C versions 5.0, 5.1, 6.0, 6.0a, 6.0ax, and C/C++ version

7.0, memory overwrites occur in the library routine i8_input. While

debugging the program under CodeView with the assembler listing, you

may notice that after executing into the code, the first 2 bytes of

each instruction beginning with a hex CD are overwritten. The C

statement that generated the assembler code with the problem in it

was an fscanf() function call.

Below is an listing example of what is occurring:

Before

------

7E1F:4266 CD35C0 INT 35 ; FLD ST(0)

7E1F:4269 CD35E1 INT 35 ; FABS

7E1F:426C CD372E7425 INT 37 ; FLD TByte Ptr [__chbuf+5C (2574)]

After

-----

7E1F:4266 90 NOP

7E1F:4267 D9C0 FLD ST(0)

7E1F:4269 90 NOP

7E1F:426A D9E1 FABS

7E1F:426C 90 NOP

7E1F:426D DB2E7425 FLD TByte Ptr [__chbuf+5C (2574)]

CAUSE

This behavior is quite normal and is nothing to worry about. The

Microsoft C floating-point package works by generating the INT

instructions shown above. When these instructions are executed, the

routine they call replaces the INT instructions with either the

library calls to the emulator library or the actual 80x87

floating-point instructions, depending on whether or not a

coprocessor is installed.

When the instructions are executed again, there is no overhead for

determining whether on not a coprocessor is installed; the proper

instructions have been patched into place already. This patching

occurs even if the -FPi87 option has been selected.

More Information:

You can force in-line 8087 instructions to be put into your code. For

more information about this technique, query on the following keywords

in the Microsoft Knowledge Base:

in-line 8087 instructions

(There is no need to do this if your code is going to run under MS-DOS

or OS/2. Although this article mainly discusses FORTRAN, it applies to

C as well because the two languages use the same floating-point

library.)

This code modification occurs only under MS-DOS. Under OS/2, coprocessor

instructions (such as in the second listing) are always generated. If

a coprocessor is not present at execution, the instructions cause

exceptions that are handled by the floating-point emulator software.

Note: Such code modification is impossible under OS/2 because there is

no way to dynamically change a code segment under OS/2, although it is

possible to cause a data segment to be executed.

Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax 7.00