1

I´m experiencing an weird issue that I have never seen before, in Delphi 2010 sometimes when using the routine CopyMemory (Which internally calls Move) I get an Invalid Float Point Operation exception, when such thing could happen when using Move??

I have a debug information in assembler, I have checked the source code of Move and the problem happens in FILD instruction, I found that FILD converts an integer value from memory to float point in a register and it could trigger that invalid operation, but why that happens? I´m stuck with this for 2 days now

Assembler Information:
; System.Move (Line=0 - Offset=1)
;
00404E0C cmp eax, edx
00404E0E jz System.Move
00404E10 cmp ecx, +$20
00404E13 jnbe System.Move
00404E15 sub ecx, +$08
00404E18 jnle System.Move
00404E1A jmp dword ptr [System.Move+ecx*4]
00404E21 fild qword ptr [ecx+eax]
00404E24 fild qword ptr [eax] ; <-- EXCEPTION
00404E26 cmp ecx, +$08
00404E29 jle System.Move
00404E2B fild qword ptr [eax+$08]
00404E2E cmp ecx, +$10
00404E31 jle System.Move
00404E33 fild qword ptr [eax+$10]
00404E36 fistp qword ptr [edx+$10]
00404E39 fistp qword ptr [edx+$08]
00404E3C fistp qword ptr [edx]
00404E3E fistp qword ptr [ecx+edx]

Registers:
EAX: 0E3A4694 EDI: 0000000D
EBX: 00001B5C ESI: 0ECF7928
ECX: 00000005 ESP: 0612FC1C
EDX: 0E3A2B38 EIP: 00404E24

What could cause that error?

Eric
  • 552
  • 3
  • 14
  • 3
    What is the value of your floating point control word when the exception occurs? – David Heffernan Jul 06 '12 at 14:30
  • Unfortunally I don´t know, because this erros is catch by EurekaLog at my customer site, I have no more information than this :( – Eric Jul 06 '12 at 16:40

2 Answers2

6

I have seen this problem before. The problem was that before entering into the Move method the stack of the x87 registers contained some invalid floating point values instead of beging empty. This was due to an exception that occured earlier and left the x87 stack like that.

The Move command uses the x87 registers because they allow for fast movement of data without depending on SSE instructions but it assumes the stack is empty.

Finding the solution:

  • set a breakpoint on the start of the Move command and use the FPU debug window to validate that the FPU stack is indeed trashed.
  • From here: backtrace where in your application was the cause of this trashed FPU stack using the same window. This is the cause of your problem.
Ritsaert Hornstra
  • 5,013
  • 1
  • 33
  • 51
  • Thanks for the directions... I believe that some external exception in my H.264 decoding library may be doing that, because this error starts to happen when I try to decode some broken H.264 stream, I will investigate it further – Eric Jul 06 '12 at 16:46
1

Seems similar to a problem I had before: Memory corruption in System.Move due to changed 8087CW mode (png + stretchblt)

My fix was to disable SSE/MMX stuff in FastMove.pas, so it did not (mis)use the FPU anymore (and not vulnerable to FPU corruption)

Community
  • 1
  • 1
André
  • 8,920
  • 1
  • 24
  • 24