summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/CRYPTO_set_locking_callback.3
diff options
context:
space:
mode:
authorschwarze <>2015-11-11 21:15:15 +0000
committerschwarze <>2015-11-11 21:15:15 +0000
commit22f89c8c27130dce389c2cba215b4cdd0deadd22 (patch)
treedf165a08270ef8df757ccda21dbd1c609633bd3f /src/lib/libcrypto/man/CRYPTO_set_locking_callback.3
parent0241f6701aac0e95428b9f0899b07ba086aa7e71 (diff)
downloadopenbsd-22f89c8c27130dce389c2cba215b4cdd0deadd22.tar.gz
openbsd-22f89c8c27130dce389c2cba215b4cdd0deadd22.tar.bz2
openbsd-22f89c8c27130dce389c2cba215b4cdd0deadd22.zip
Convert five more manuals from POD to mdoc.
I found drafts of these in my tree, probably originally from Max Fillinger, that just needed minor polishing.
Diffstat (limited to 'src/lib/libcrypto/man/CRYPTO_set_locking_callback.3')
-rw-r--r--src/lib/libcrypto/man/CRYPTO_set_locking_callback.3321
1 files changed, 321 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/CRYPTO_set_locking_callback.3 b/src/lib/libcrypto/man/CRYPTO_set_locking_callback.3
new file mode 100644
index 0000000000..d6290852b5
--- /dev/null
+++ b/src/lib/libcrypto/man/CRYPTO_set_locking_callback.3
@@ -0,0 +1,321 @@
1.Dd $Mdocdate: November 11 2015 $
2.Dt CRYPTO_SET_LOCKING_CALLBACK 3
3.Os
4.Sh NAME
5.Nm CRYPTO_THREADID_set_callback ,
6.Nm CRYPTO_THREADID_get_callback ,
7.Nm CRYPTO_THREADID_current ,
8.Nm CRYPTO_THREADID_cmp ,
9.Nm CRYPTO_THREADID_cpy ,
10.Nm CRYPTO_THREADID_hash ,
11.Nm CRYPTO_set_locking_callback ,
12.Nm CRYPTO_num_locks ,
13.Nm CRYPTO_set_dynlock_create_callback ,
14.Nm CRYPTO_set_dynlock_lock_callback ,
15.Nm CRYPTO_set_dynlock_destroy_callback ,
16.Nm CRYPTO_get_new_dynlockid ,
17.Nm CRYPTO_destroy_dynlockid ,
18.Nm CRYPTO_lock
19.Nd OpenSSL thread support
20.Sh SYNOPSIS
21.In openssl/crypto.h
22.Bd -literal
23/* Don't use this structure directly. */
24typedef struct crypto_threadid_st {
25 void *ptr;
26 unsigned long val;
27} CRYPTO_THREADID;
28/* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */
29.Ed
30.Pp
31.Ft void
32.Fo CRYPTO_THREADID_set_numeric
33.Fa "CRYPTO_THREADID *id"
34.Fa "unsigned long val"
35.Fc
36.Ft void
37.Fo CRYPTO_THREADID_set_pointer
38.Fa "CRYPTO_THREADID *id"
39.Fa "void *ptr"
40.Fc
41.Ft int
42.Fo CRYPTO_THREADID_set_callback
43.Fa "void (*threadid_func)(CRYPTO_THREADID *)"
44.Fc
45.Ft void
46.Fo "(*CRYPTO_THREADID_get_callback(void))"
47.Fa "CRYPTO_THREADID *"
48.Fc
49.Ft void
50.Fo CRYPTO_THREADID_current
51.Fa "CRYPTO_THREADID *id"
52.Fc
53.Ft int
54.Fo CRYPTO_THREADID_cmp
55.Fa "const CRYPTO_THREADID *a"
56.Fa "const CRYPTO_THREADID *b"
57.Fc
58.Ft void
59.Fo CRYPTO_THREADID_cpy
60.Fa "CRYPTO_THREADID *dest"
61.Fa "const CRYPTO_THREADID *src"
62.Fc
63.Ft unsigned long
64.Fo CRYPTO_THREADID_hash
65.Fa "const CRYPTO_THREADID *id"
66.Fc
67.Ft int
68.Fo CRYPTO_num_locks
69.Fa void
70.Fc
71.Bd -literal
72/* struct CRYPTO_dynlock_value needs to be defined by the user */
73struct CRYPTO_dynlock_value;
74.Ed
75.Pp
76.Ft void
77.Fo CRYPTO_set_dynlock_create_callback
78.Fa "struct CRYPTO_dynlock_value *"
79.Fa "(*dyn_create_function)(char *file, int line)"
80.Fc
81.Ft void
82.Fo CRYPTO_set_dynlock_lock_callback
83.Fa "void (*dyn_lock_function)(int mode, struct CRYPTO_dynlock_value *l,\
84 const char *file, int line)"
85.Fc
86.Ft void
87.Fo CRYPTO_set_dynlock_destroy_callback
88.Fa "void (*dyn_destroy_function)(struct CRYPTO_dynlock_value *l,\
89 const char *file, int line)"
90.Fc
91.Ft int
92.Fo CRYPTO_get_new_dynlockid
93.Fa void
94.Fc
95.Ft void
96.Fo CRYPTO_destroy_dynlockid
97.Fa "int i"
98.Fc
99.Ft void
100.Fo CRYPTO_lock
101.Fa "int mode"
102.Fa "int n"
103.Fa "const char *file"
104.Fa "int line"
105.Fc
106.Bd -literal
107#define CRYPTO_w_lock(type) \e
108 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE, type, __FILE__, __LINE__)
109#define CRYPTO_w_unlock(type) \e
110 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE, type, __FILE__, __LINE__)
111#define CRYPTO_r_lock(type) \e
112 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ, type, __FILE__, __LINE__)
113#define CRYPTO_r_unlock(type) \e
114 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ, type, __FILE__, __LINE__)
115#define CRYPTO_add(addr,amount,type) \e
116 CRYPTO_add_lock(addr, amount, type, __FILE__, __LINE__)
117.Ed
118.Sh DESCRIPTION
119OpenSSL can safely be used in multi-threaded applications provided that
120at least two callback functions are set,
121.Fn locking_function
122and
123.Fn threadid_func .
124.Pp
125.Fo locking_function
126.Fa "int mode"
127.Fa "int n"
128.Fa "const char *file"
129.Fa "int line"
130.Fc
131is needed to perform locking on shared data structures.
132Note that OpenSSL uses a number of global data structures that will be
133implicitly shared whenever multiple threads use OpenSSL.
134Multi-threaded applications will crash at random if it is not set.
135.Pp
136.Fn locking_function
137must be able to handle up to
138.Fn CRYPTO_num_locks
139different mutex locks.
140It sets the
141.Fa n Ns -th
142lock if
143.Fa mode
144includes
145.Dv CRYPTO_LOCK ,
146and releases it otherwise.
147.Pp
148.Fa file
149and
150.Fa line
151are the file number of the function setting the lock.
152They can be useful for debugging.
153.Pp
154.Fo threadid_func
155.Fa "CRYPTO_THREADID *id"
156.Fc
157is needed to record the currently-executing thread's identifier into
158.Fa id .
159The implementation of this callback should not fill in
160.Fa id
161directly, but should use
162.Fn CRYPTO_THREADID_set_numeric
163if thread IDs are numeric, or
164.Fn CRYPTO_THREADID_set_pointer
165if they are pointer-based.
166If the application does not register such a callback using
167.Fn CRYPTO_THREADID_set_callback ,
168then a default implementation is used - on Windows and BeOS this uses
169the system's default thread identifying APIs, and on all other platforms
170it uses the address of
171.Va errno .
172The latter is satisfactory for thread-safety if and only if the platform
173has a thread-local error number facility.
174.Pp
175Once
176.Fn threadid_func
177is registered, or if the built-in default implementation is to be used,
178.Bl -bullet
179.It
180.Fn CRYPTO_THREADID_current
181records the currently-executing thread ID into the given
182.Fa id
183object.
184.It
185.Fn CRYPTO_THREADID_cmp
186compares two thread IDs (returning zero for equality, i.e. the same
187semantics as
188.Xr memcmp 3 ) .
189.It
190.Fn CRYPTO_THREADID_cpy
191duplicates a thread ID value.
192.It
193.Fn CRYPTO_THREADID_hash
194returns a numeric value usable as a hash-table key.
195This is usually the exact numeric or pointer-based thread ID used
196internally, however this also handles the unusual case where pointers
197are larger than
198.Vt long
199variables and the platform's thread IDs are pointer-based \(em in
200this case, mixing is done to attempt to produce a unique numeric
201value even though it is not as wide as the platform's true thread
202IDs.
203.El
204.Pp
205Additionally, OpenSSL supports dynamic locks, and sometimes, some parts
206of OpenSSL need it for better performance.
207To enable this, the following is required:
208.Bl -bullet
209.It
210Three additional callback functions,
211.Fn dyn_create_function ,
212.Fn dyn_lock_function ,
213and
214.Fn dyn_destroy_function .
215.It
216A structure defined with the data that each lock needs to handle.
217.El
218.Pp
219.Vt struct CRYPTO_dynlock_value
220has to be defined to contain whatever structure is needed to handle locks.
221.Pp
222.Fo dyn_create_function
223.Fa "const char *file"
224.Fa "int line"
225.Fc
226is needed to create a lock.
227Multi-threaded applications might crash at random if it is not set.
228.Pp
229.Fo dyn_lock_function
230.Fa "int mode"
231.Fa "CRYPTO_dynlock *l"
232.Fa "const char *file"
233.Fa "int line"
234.Fc
235is needed to perform locking off dynamic lock numbered n.
236Multi-threaded applications might crash at random if it is not set.
237.Pp
238.Fo dyn_destroy_function
239.Fa "CRYPTO_dynlock *l"
240.Fa "const char *file"
241.Fa "int line"
242.Fc
243is needed to destroy the lock
244.Fa l .
245Multi-threaded applications might crash at random if it is not set.
246.Pp
247.Fn CRYPTO_get_new_dynlockid
248is used to create locks.
249It will call
250.Fn dyn_create_function
251for the actual creation.
252.Pp
253.Fn CRYPTO_destroy_dynlockid
254is used to destroy locks.
255It will call
256.Fn dyn_destroy_function
257for the actual destruction.
258.Pp
259.Fn CRYPTO_lock
260is used to lock and unlock the locks.
261.Fa mode
262is a bitfield describing what should be done with the lock.
263.Fa n
264is the number of the lock as returned from
265.Fn CRYPTO_get_new_dynlockid .
266.Fa mode
267can be combined from the following values.
268These values are pairwise exclusive, with undefined behaviour if misused
269(for example,
270.Dv CRYPTO_READ
271and
272.Dv CRYPTO_WRITE
273should not be used together):
274.Bd -literal -offset indent
275CRYPTO_LOCK 0x01
276CRYPTO_UNLOCK 0x02
277CRYPTO_READ 0x04
278CRYPTO_WRITE 0x08
279.Ed
280.Sh RETURN VALUES
281.Fn CRYPTO_num_locks
282returns the required number of locks.
283.Pp
284.Fn CRYPTO_get_new_dynlockid
285returns the index to the newly created lock.
286.Pp
287The other functions return no values.
288.Sh NOTES
289You can find out if OpenSSL was configured with thread support:
290.Bd -literal -offset indent
291#define OPENSSL_THREAD_DEFINES
292#include <openssl/opensslconf.h>
293#if defined(OPENSSL_THREADS)
294 /* thread support enabled */
295#else
296 /* no thread support */
297#endif
298.Ed
299.Pp
300Also, dynamic locks are currently not used internally by OpenSSL, but
301may do so in the future.
302.Sh EXAMPLES
303.Pa crypto/threads/mttest.c
304shows examples of the callback functions on Solaris, Irix and Win32.
305.Sh SEE ALSO
306.Xr crypto 3
307.Sh HISTORY
308.Fn CRYPTO_set_locking_callback
309is available in all versions of SSLeay and OpenSSL.
310.Fn CRYPTO_num_locks
311was added in OpenSSL 0.9.4.
312All functions dealing with dynamic locks were added in OpenSSL 0.9.5b-dev.
313.Vt CRYPTO_THREADID
314and associated functions were introduced in OpenSSL 1.0.0 to replace
315(actually, deprecate) the previous
316.Fn CRYPTO_set_id_callback ,
317.Fn CRYPTO_get_id_callback ,
318and
319.Fn CRYPTO_thread_id
320functions which assumed thread IDs to always be represented by
321.Vt unsigned long .