开发者

Symbian: kern-exec 3 panic on RLibrary::Load

I have troubles with dynamic loading of libraries - my code panics with Kern-Exec 3. The code is as follows:

TFileName dllName = _L("mydll.dll");
TFileName dllPath = _L("c:\\sys\\bin\\");
RLibrary dll;
TInt res = dll.Load(dllName, dllPath); // Kern-Exec 3!
TLibraryFunction f = dll.Lookup(1);
if (f)
    f();

I receive panic on TInt res = dll.Load(dllName, dllPath); What can I do to get rid of this panic? mydll.dll is really my dll, which has only 1 exported function (for test purposes). Maybe something wrong with the DLL? Here's what it is:

def file:

EXPORTS
_ZN4Init4InitEv @ 1 NONAME

pkg file:

#{"mydll DLL"},(0xED3F400D),1,0,0


;Localised Vendor name
%{"Vendor-EN"}

;Unique Vendor name
:"Vendor"

"$(EPOCROOT)Epoc32开发者_StackOverflow中文版\release\$(PLATFORM)\$(TARGET)\mydll.dll"-"!:\sys\bin\mydll.dll"

mmp file:

TARGET        mydll.dll
TARGETTYPE    dll
UID          0x1000008d 0xED3F400D

USERINCLUDE  ..\inc
SYSTEMINCLUDE   \epoc32\include

SOURCEPATH    ..\src

SOURCE        mydllDllMain.cpp
LIBRARY      euser.lib

#ifdef ENABLE_ABIV2_MODE
DEBUGGABLE_UDEBONLY
#endif

EPOCALLOWDLLDATA

CAPABILITY CommDD LocalServices Location MultimediaDD NetworkControl NetworkServices PowerMgmt ProtServ ReadDeviceData ReadUserData SurroundingsDD SwEvent TrustedUI UserEnvironment WriteDeviceData WriteUserData

source code:

//  Exported Functions
namespace Init
    {
    EXPORT_C TInt Init()
        {
        // no implementation required
        return 0;
        }
    }

header file:

#ifndef __MYDLL_H__
#define __MYDLL_H__

//  Include Files

namespace Init
{
    IMPORT_C TInt Init();
}

#endif  // __MYDLL_H__

I have no ideas about this... Any help is greatly appreciated.

P.S. I'm trying to do RLibrary::Load because I have troubles with static linkage. When I do static linkage, my main program doesn't start at all. I decided to check what happens and discovered this issue with RLibrary::Load.


A KERN-EXEC 3 panic is caused by an unhandled exception (CPU fault) generated by trying to invalidly access a region of memory. This invalid memory access can be for both code (for example, bad PC by stack corruption) or data (for example, accessing freed memory). As such these are typically observed when dereferencing a NULL pointer (it is equivalent to a segfault).

Certainly the call to RLibrary::Load should never raise a KERN-EXEC 3 due to programmatic error, it is likely to be an environmental issue. As such I have to speculate on what is happening.

I believe the issue that is observed is due to stack overflow. Your MMP file does not specify the stack or heap size the initial thread should use. As such the default of 4Kb (if I remember correctly) will be used. Equally you are using TFileName - use of these on the stack is generally not recommended to avoid... stack overflow.

You would be better off using the _LIT() macro instead - this will allow you to provide the RLibrary::Load function with a descriptor directly referencing the constant strings as located in the constant data section of the binary.

As a side note, you should check the error value to determine the success of the function call.

_LIT(KMyDllName, "mydll.dll");
_LIT(KMyDllPath, "c:\\sys\\bin\\");
RLibrary dll;
TInt res = dll.Load(KMyDllName, MyDllPath); // Hopefully no Kern-Exec 3!
if(err == KErrNone)
    {
    TLibraryFunction f = dll.Lookup(1);
    if (f)
        f();
    }
// else handle error


The case that you can't use static linkage should be a strong warning to you. It shows that there is something wrong with your DLL and using dynamic linking won't change anything.

Usually in these cases the problem is in mismatched capabilities. DLL must have at least the same set of capabilities that your main program has. And all those capabilities should be covered by your developer cert.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜