Mutex in a implicit linked DLL always returns that it exists

  • Hello


    I attached a C++ solution based sample where a executable just loads a implicit linked DLL, just to show my problem.
    The sample does export some small objects but just to get the DLL loaded when starting up the application, no snese behind.
    I let it run on a Netdcu8 as platform.


    The Problem:
    If I create a new Mutex in the DLL it always returns that it is already existing(see error code in DLL)
    If I create a new Mutex in the Executable, it works as expected, it is created new. You can try in the code, just remove the remarkes in the exe.
    Do you see the same results?
    It doesn´t matter if I change the mutex name in the DLL or cold reboot the device, it is always doing the same behaviour, telling me that the mutex is already there or created.
    Does anybody have an idea how to come behind the that?
    Is it forbidden to create mutex in DLL? I thought always it should be same as in executable, may be it is not?


    bye[attachment=0]<!-- ia0 -->TestMutexDllExe.zip<!-- ia0 -->[/attachment]

  • Hi again


    As attach there is a Word document where the difference between W32 and a device application is showed.
    As W32 on the PC it is working as expected but not as device Apllication.


    Main difference is that the adress of the testdll.dll is in a strange area, a mouse tootip says that it is not the standard area.
    Don´t know if this matters, but red sign is never good. Also the adress of the Handle, returned by CreateMutex is in very different area.
    Could be that PC locates the stuff in other areas as device?


    I do not know further please have a look. May be there is a solution for me.


    bye

  • I would assume that the DLL-Attach is executed twice, the first time from some other context, for example from kernel context. Then when you load the DLL again by using it in your application, you get the "already existing". And because the first call of CreateMutex was from kernel space, the mutex is in this "strange" address space.


    Do you load this DLL for example via the device manager as a builtin device driver? Try to give some debug message when the attach code is called, e.g with RETAILMSG(1, (_T("msg"))); This message then appears on the debug port. If the message appears twice, you have the reason why the mutex already exists the second time.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Are both messages appearing in the moment when the application is started? Or is one message already appearing when the board is booting and only the second, when the application is started? Is there a DLL_PROCESS_DETACH between these two messages?

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello
    I set a breakpoint right int the DLL_PROCESS_ATTACH switch case at the retail message.
    the output when program starts is follwing:


    DLL_PROCESS_ATTACH
    MUTEX CREATION OK
    DLL_PROCESS_DETACH
    DLL_PROCESS_ATTACH
    ERROR_ALREADY_EXISTS
    DLL_PROCESS_DETACH


    after the breakpoint (program runs) this:
    DLL_PROCESS_ATTACH
    ERROR_ALREADY_EXISTS


    When closing the program:
    DLL_PROCESS_DETACH


    Thanks for any help



  • Hmm, strange. How about printing the process ID that makes the calls to the debug port? Then we know at least which process is making the call by looking at the current process list, for example by using the remote process viewer.


    RETAILMSG(1, (_T("ProcessID: 0x%8x\r\n"), GetCurrentProcessId()));

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hi


    It is the conmanclient2.exe (0x83b94b76) that is calling this DLL. I use conmanclient2 to connect the Visual Studio to the target device.
    Now I understand the behaviour of another DLL that I use, in debugging environment...


    Here the output of the serial line:


    DLL_PROCESS_ATTACH, ProcessID: 0x83b94b76
    ERROR_ALREADY_EXISTS, ProcessID: 0x83b94b76
    DLL_PROCESS_DETACH, ProcessID: 0x83b94b76
    <LF>
    DLL_PROCESS_ATTACH, ProcessID: 0x63ac1276
    ERROR_ALREADY_EXISTS, ProcessID: 0x63ac1276
    <LF>
    DLL_PROCESS_DETACH, ProcessID: 0x63ac1276


    Is this possible to prevent or do I need to live with it?
    When I start the exe on the device, without conmanclient2 started, it is ok.


    bye

  • Hello


    after trying to workaround the problem, I found, that even when I just deploy the exe/dll to the device, the serial output shows me that(after power on the device, nothing was loaded before):


    DLL_PROCESS_ATTACH, ProcessID: 0x63c2423a
    Call from path \ffsdisk\conn\conmanclient2.exe
    Call from ConManClient2, do nothing
    DLL_PROCESS_DETACH, ProcessID: 0x63c2423a


    Then I start the application, having a breakpoint in the DLL_PROCESS_ATTACH swtich:
    DLL_PROCESS_ATTACH, ProcessID: 0x63c2423a
    Call from path \ffsdisk\conn\conmanclient2.exe
    Call from ConManClient2, do nothing
    DLL_PROCESS_DETACH, ProcessID: 0x63c2423a


    Then after the breakpoint this:
    DLL_PROCESS_ATTACH, ProcessID: 0x 3b626ae
    Call from path \ffsdisk\testEXE\testEXE.exe
    Call from EXE
    MUTEX CREATION OK, ProcessID: 0x 3b626ae



    The code in the attach section:


  • Isn't it easier to introduce a special init-function that must be called from the exe before any other operation may take place and then move the mutex creation code there? Then it is not important how often the PROCESS_ATTACH code is called.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello


    now a more heavy problem arised concerning this issue(seems one of Murphys laws has been proved again).


    I cannot debug anymore, from one moment to the other. Deployment still works, but when I start any NETDCU 8 application from VS2008
    then there appears a VS 2008 messsage box, that Debug is no more possible. I saw at the serial debug output the following:


    Data Abort: Thread=83ba2400 Proc=80eff0d0 'conmanclient2.exe'
    AKY=ffffffff PC=8015c300(NK.EXE+0x00023300) RA=8015c2a0(NK.EXE+0x000232a0) BVA=1800003c FSR=00000007


    So it depends to the conection manager conmanclient2. Can you give me any instructions what to do?


    bye

  • Reboot the device.

    F&amp;S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • The problem occured again:


    After start of the debugger from VS2008 there is the following ouput at the serial debug interface of the NETCDU8:
    Data Abort: Thread=83b13a78 Proc=80eff0d0 'conmanclient2.exe'
    AKY=ffffffff PC=8015c300(NK.EXE+0x00023300) RA=8015c2a0(NK.EXE+0x000232a0) BVA=1800003c FSR=00000007


    VS says that it cannot start application.


    Workarround, if s.o. has this problem, too:
    After you find such an error, when you start you application afterwards directly on the device(no VS debugger), then stop it, then you can debug again afterwards(don´t ask em why). At least here it was like this.


    @F&S: Are there fir this case descriptions about AKY, PC, RA BVA, FSR to make further investigation? (mapping Files ??)


    bye