I have seen this.  It appears to be a packing issue with respect to the
2-byte version value that is at the start of the function list.  By default
(I'm generalising here) a compiler will pack that on a 4-byte boundary, but
it must be packed on a 1- or 2-byte boundary.  So what happens is the
application starts reading the function pointers 2-bytes off, and hence the
addresses are incorrect.  The way I solved it was to put a "#pragm pack(1)"
(I'm using Visual C++) around the function pointer list.

Hope that helps.


"Carla Schaffner" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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.
>


_______________________________________________
mozilla-crypto mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-crypto

Reply via email to