If I call the function C_Initialize with the pointer from C_FunctionList, it
doesn't find the function and throws the error Segmentation fault.
(example from the rsa PKCS#11 v2 Spec)
CK_FUNCTION_LIST_PTR pFunctionList;
CK_C_Initialize pC_Initialize;
CK_RV rv;
rv = C_GetFunctionList(&pFunctionList);
if (rv == CKR_OK) {
fprintf(stdout, "FunktionList OK!\n");
}
pC_Initialize = pFunctionList->C_Initialize;
// call C_Initalize funktion
rv = (*pC_Initialize)(NULL_PTR);
--------------------------------------
if I call the function C_Initialize without C_FunctionList pointer it works.
rv = C_Initialize(NULL_PTR);
where is th problem?
Jean-Marc Desperrier wrote:
> Carla Schaffner wrote:
>> Thanks for your answer!
>> But in this example (rsa security) it looks like it could be used without
>> a pointer...or am I wrong?
>
> This sample could be using some macro that hides the dereferencing of
> the pointer, but even that doesn't explain why it does not seem to call
> GetFunctionList first.
> Directly calling the function is very unusual.
>
> Despite that the PKCS#11 v2 says you should use C_GetFunctionList, in
> most implementations the PKCS#11 library still exports the sub-function
> so you could call them directly.
>
> But in most any case, you want your programm to interface with any
> pkcs#11 module, so you never statically link it with a given PKCS#11
> library which the only way to directly call the function.
>
> So whether you do it as it should be, using C_GetFunctionList, or use a
> dynamic library loading function to locate the function address, you
> always end up calling a pointer, so your sample is very strange and not
> really functionnal.