locked
Native exception : Excpetion code 0xc0000005 RRS feed

  • Question

  • Hi all, we're developing a C# Smart Device application that uses a DLL developed in C language.

    We're using Vs Prof 2008, CF 3.5 and the target platform is Windows Professional ARMV4I.

    The C DLL reads some binary files and loads in memory data structure (using malloc and realloc) concerning users data (username, password, name, id...).

    Then we have a C login function that uses these data to check the credentials.

    The GUI is in C#. So we have a login form to input username/password and the BL of the application (with P/Invoke) uses the C DLL to check the credentials.

    Our application works fine on the Windows Professional 6 Emulator but when we install it on the physical device (M3 Sky MC7700S with Intel PXA-270 - ARM920T processor - Windows Mobile 6.1) if you bring the application in the background and then try tu use it, you obtain a Native Exception (Exception code = 0xc0000005; access violation).

    Debbugging the C code, we see in the output window of the debug the following message:

    Prefetch Abort: Thread=85e5a920 Proc=805f2eb0 'PcmMobileApp.exe'

    AKY=00002001 PC=80000417(???+0x80000417) RA=7825da18(t2light.dll+0x0001da18) BVA=80000417 FSR=000004f0

    We obtain the error on random instruction. I mean that the error it's not on the same line of code. Sometime is a memset sometime is a return and so on..

    Does anybody have an idea of what is going on ? What are we doing wrong ? Maybe is the GC involved ? Why on the emulator we're not able to reproduce the problem ?

    Thanx a lot.

    Massimo Callegari
    Genoa - Italy
    Wednesday, August 4, 2010 10:50 AM

Answers

  • In the end we got it !

    The problem was in an incorrect linker switch in the C project. After all the tests we did, we understood that the problem wasn't related to the GC, nor .Net (because we did a test with a C++ project and we had the same exception..). So we started to investigate compiler and linker options of the C project.. We noticed that the linker was saying this : "corelibc.lib(crt0init.obj) : warning LNK4254: section '.CRT' (40000040) merged into '.data' (C0000040) with different attributes"

    We found this in the MSDN :

    Linker Tools Warning LNK4254

    Error Message

    section 'section1' (offset) merged into 'section2' (offset) with different attributes

    The contents of one section were merged into another, but the attributes of the two sections are different. Your program may give unexpected results . For example, data you wanted to be read only may now be in a writable section.

    So, we changed the Subsystem option in the System section of the linker (from "Not set" to "WindowsCE") the warning disappeared and the exception too...

    We noticed that if you create a new C++ Smart Device Project, the wizard puts this option ( /subsystem:windowsce,5.02) in the "Addional options" window of the "Command line" section of the Linker.. Evidently the person who set up the project made some mistakes.. who knows.. a question still remains: why the Windows Mobile 6 emulator didn't give the exception ? Finally a quote by a collegue of mine (i don't know if the english translation is correct) : "Sower warnings collects bugs !". ("chi semina warnings raccoglie bachi !")

    Thanks to all. Bye

    Massimo C.

    • Marked as answer by warrentang Wednesday, August 11, 2010 8:29 AM
    Wednesday, August 11, 2010 7:18 AM

All replies

  • Sounds like some data (or delegate) passed from managed to native is collected by GC and then used by native code.

    Whatever or not it would crash depends on what happened to the memory held by released object between release and access attempt.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by warrentang Monday, August 9, 2010 2:54 AM
    • Unmarked as answer by warrentang Wednesday, August 11, 2010 8:29 AM
    Wednesday, August 4, 2010 3:36 PM
  • In the end we got it !

    The problem was in an incorrect linker switch in the C project. After all the tests we did, we understood that the problem wasn't related to the GC, nor .Net (because we did a test with a C++ project and we had the same exception..). So we started to investigate compiler and linker options of the C project.. We noticed that the linker was saying this : "corelibc.lib(crt0init.obj) : warning LNK4254: section '.CRT' (40000040) merged into '.data' (C0000040) with different attributes"

    We found this in the MSDN :

    Linker Tools Warning LNK4254

    Error Message

    section 'section1' (offset) merged into 'section2' (offset) with different attributes

    The contents of one section were merged into another, but the attributes of the two sections are different. Your program may give unexpected results . For example, data you wanted to be read only may now be in a writable section.

    So, we changed the Subsystem option in the System section of the linker (from "Not set" to "WindowsCE") the warning disappeared and the exception too...

    We noticed that if you create a new C++ Smart Device Project, the wizard puts this option ( /subsystem:windowsce,5.02) in the "Addional options" window of the "Command line" section of the Linker.. Evidently the person who set up the project made some mistakes.. who knows.. a question still remains: why the Windows Mobile 6 emulator didn't give the exception ? Finally a quote by a collegue of mine (i don't know if the english translation is correct) : "Sower warnings collects bugs !". ("chi semina warnings raccoglie bachi !")

    Thanks to all. Bye

    Massimo C.

    • Marked as answer by warrentang Wednesday, August 11, 2010 8:29 AM
    Wednesday, August 11, 2010 7:18 AM