Search code examples
multithreadingwindows-cewxwidgets

ARM Illegal instructions/access violations in Windows CE threading (C++)


I have a program which contains a thread implemented as a derived class of wxThread. Sometimes this program crashes with either illegal instructions or access violations but always somewhere in the code executed by the thread.

I have even tried to remove the thread and replace it with a trivial Win32 thread that looks like this:

DWORD WINAPI LoggerThread::winthread(void* arg) {
  while (true) { Sleep(2000); }
}

And it still crashes with an access violation on the Sleep(2000) line intermittently, but almost always after around 30 seconds.

Most recently, it crashes with illegal instructions (more specifically, undefined instructions), on a static function which the wxThread class calls:

void* LoggerThread::Entry() {
while(true) {
    if (queue->size() > 0) {

        SOCKET sd = LoggerThread::Init(); /* Crash on this line */ 
            /* ....... */
        }
    }
}

The output from the console is the following:

Undefined Instruction: Thread=8e823ac4 Proc=8c329400 'Opcode.exe' Undefined Instruction: Thread=8c69663c Proc=8c329400 'Opcode.exe'

AKY=00004001 PC=800003f8(???+0x800003f8) RA=006492bc(Opcode.exe+0x006392bc) BVA=05ffed24 >FSR=000000f5

AKY=00004001 PC=003ade44(Opcode.exe+0x0039de44) RA=004cc784(Opcode.exe+0x004bc784) >BVA=05ffed24 FSR=000000f5

Data Abort: Thread=8e823ac4 Proc=8c329400 'Opcode.exe'

AKY=00004001 PC=80188d03(NK.EXE+0x00008d03) RA=80000059(???+0x80000059) BVA=1e07807b >FSR=000000f3

Unhandled exception at 0x003ade44 in Opcode.exe: 0xC000001D: Illegal Instruction.

The thread 'public: static unsigned long __cdecl wxThreadInternal::WinThreadStart(void *)' >(0x2fb5e2c6) has exited with code -1073741795 (0xc000001d).

Unhandled exception at 0x80188d02 in Opcode.exe: 0x80000002: Datatype misalignment.

The project is VC++ (Visual Studio 2005), and I have also tried compiling with the Windows Mobile 5.0 SDK, the Standard SDK, and the Pocket PC 2003 SDK. I have been testing my code on the MC55 and the MC3090, both do the same, but I think perhaps the MC55 is quicker to crash.

It is worthy to note that if I compile my source as a Win32 program (it is wxWidgets based) it works without any issues.

Could anyone give me an idea of where I could look?


Solution

  • I don't know anything about wxWidgets, but I'd probably start by looking at this definition:

    DWORD WINAPI LoggerThread::winthread(void*)
    

    According to your console output, wxThreadInternal::WinThreadStart is

    __cdecl

    What calling convention does WINAPI specify on ARM? Maybe WINAPI specifies

    __stdcall?

    Sorry for the funky formatting :)