1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 */
4
5 /* Copyright (c) 2002 Graz University of Technology. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * 3. The end-user documentation included with the redistribution, if any, must
18 * include the following acknowledgment:
19 *
20 * "This product includes software developed by IAIK of Graz University of
21 * Technology."
22 *
78 CK_C_INITIALIZE_ARGS_PTR ckpInitArgs;
79 jclass jInitArgsClass;
80 jfieldID fieldID;
81 jlong jFlags;
82 jobject jReserved;
83 CK_ULONG ckReservedLength;
84 #ifndef NO_CALLBACKS
85 jobject jMutexHandler;
86 #endif /* NO_CALLBACKS */
87
88 if(jInitArgs == NULL) {
89 return NULL_PTR;
90 }
91
92 /* convert the Java InitArgs object to a pointer to a CK_C_INITIALIZE_ARGS structure */
93 ckpInitArgs = (CK_C_INITIALIZE_ARGS_PTR) malloc(sizeof(CK_C_INITIALIZE_ARGS));
94 if (ckpInitArgs == NULL) {
95 throwOutOfMemoryError(env, 0);
96 return NULL_PTR;
97 }
98
99 /* Set the mutex functions that will call the Java mutex functions, but
100 * only set it, if the field is not null.
101 */
102 jInitArgsClass = (*env)->FindClass(env, CLASS_C_INITIALIZE_ARGS);
103 if (jInitArgsClass == NULL) {
104 free(ckpInitArgs);
105 return NULL;
106 }
107
108 #ifdef NO_CALLBACKS
109 ckpInitArgs->CreateMutex = NULL_PTR;
110 ckpInitArgs->DestroyMutex = NULL_PTR;
111 ckpInitArgs->LockMutex = NULL_PTR;
112 ckpInitArgs->UnlockMutex = NULL_PTR;
113 #else
114 fieldID = (*env)->GetFieldID(env, jInitArgsClass, "CreateMutex", "Lsun/security/pkcs11/wrapper/CK_CREATEMUTEX;");
115 if (fieldID == NULL) {
116 free(ckpInitArgs);
117 return NULL;
|
1 /*
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3 */
4
5 /* Copyright (c) 2002 Graz University of Technology. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * 3. The end-user documentation included with the redistribution, if any, must
18 * include the following acknowledgment:
19 *
20 * "This product includes software developed by IAIK of Graz University of
21 * Technology."
22 *
78 CK_C_INITIALIZE_ARGS_PTR ckpInitArgs;
79 jclass jInitArgsClass;
80 jfieldID fieldID;
81 jlong jFlags;
82 jobject jReserved;
83 CK_ULONG ckReservedLength;
84 #ifndef NO_CALLBACKS
85 jobject jMutexHandler;
86 #endif /* NO_CALLBACKS */
87
88 if(jInitArgs == NULL) {
89 return NULL_PTR;
90 }
91
92 /* convert the Java InitArgs object to a pointer to a CK_C_INITIALIZE_ARGS structure */
93 ckpInitArgs = (CK_C_INITIALIZE_ARGS_PTR) malloc(sizeof(CK_C_INITIALIZE_ARGS));
94 if (ckpInitArgs == NULL) {
95 throwOutOfMemoryError(env, 0);
96 return NULL_PTR;
97 }
98 ckpInitArgs->flags = (CK_FLAGS)0;
99 ckpInitArgs->pReserved = (CK_VOID_PTR)NULL;
100
101 /* Set the mutex functions that will call the Java mutex functions, but
102 * only set it, if the field is not null.
103 */
104 jInitArgsClass = (*env)->FindClass(env, CLASS_C_INITIALIZE_ARGS);
105 if (jInitArgsClass == NULL) {
106 free(ckpInitArgs);
107 return NULL;
108 }
109
110 #ifdef NO_CALLBACKS
111 ckpInitArgs->CreateMutex = NULL_PTR;
112 ckpInitArgs->DestroyMutex = NULL_PTR;
113 ckpInitArgs->LockMutex = NULL_PTR;
114 ckpInitArgs->UnlockMutex = NULL_PTR;
115 #else
116 fieldID = (*env)->GetFieldID(env, jInitArgsClass, "CreateMutex", "Lsun/security/pkcs11/wrapper/CK_CREATEMUTEX;");
117 if (fieldID == NULL) {
118 free(ckpInitArgs);
119 return NULL;
|