]> git.ipfire.org Git - thirdparty/openssl.git/blob - doc/man3/OSSL_ERR_STATE_save.pod
QUIC TLS: Rethink error handling
[thirdparty/openssl.git] / doc / man3 / OSSL_ERR_STATE_save.pod
1 =pod
2
3 =head1 NAME
4
5 OSSL_ERR_STATE_new, OSSL_ERR_STATE_save, OSSL_ERR_STATE_save_to_mark,
6 OSSL_ERR_STATE_restore, OSSL_ERR_STATE_free - saving and restoring error state
7
8 =head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 ERR_STATE *OSSL_ERR_STATE_new(void);
13 void OSSL_ERR_STATE_save(ERR_STATE *es);
14 void OSSL_ERR_STATE_save_to_mark(ERR_STATE *es);
15 void OSSL_ERR_STATE_restore(const ERR_STATE *es);
16 void OSSL_ERR_STATE_free(ERR_STATE *es);
17
18 =head1 DESCRIPTION
19
20 These functions save and restore the error state from the thread
21 local error state to a preallocated error state structure.
22
23 OSSL_ERR_STATE_new() allocates an empty error state structure to
24 be used when saving and restoring thread error state.
25
26 OSSL_ERR_STATE_save() saves the thread error state to I<es>. It
27 subsequently clears the thread error state. Any previously saved
28 state in I<es> is cleared prior to saving the new state.
29
30 OSSL_ERR_STATE_save_to_mark() is similar to OSSL_ERR_STATE_save() but only saves
31 ERR entries up to the most recent mark on the ERR stack. These entries are moved
32 to I<es> and removed from the thread error state. However, the most recent
33 marked ERR and any ERR state before it remains part of the thread error state
34 and is not moved to the ERR_STATE. The mark is not cleared and must be cleared
35 explicitly after a call to this function using L<ERR_pop_to_mark(3)> or
36 L<ERR_clear_last_mark(3)>. (Since a call to OSSL_ERR_STATE_save_to_mark() leaves
37 the marked ERR as the top error, either of these functions will have the same
38 effect.) If there is no marked ERR in the thread local error state, all ERR
39 entries are copied and the effect is the same as for a call to
40 OSSL_ERR_STATE_save().
41
42 OSSL_ERR_STATE_restore() adds all the error entries from the
43 saved state I<es> to the thread error state. Existing entries in
44 the thread error state are not affected if there is enough space
45 for all the added entries. Any allocated data in the saved error
46 entries is duplicated on adding to the thread state.
47
48 OSSL_ERR_STATE_free() frees the saved error state I<es>.
49
50 =head1 RETURN VALUES
51
52 OSSL_ERR_STATE_new() returns a pointer to the allocated ERR_STATE
53 structure or NULL on error.
54
55 OSSL_ERR_STATE_save(), OSSL_ERR_STATE_save_to_mark(), OSSL_ERR_STATE_restore(),
56 OSSL_ERR_STATE_free() do not return any values.
57
58 =head1 NOTES
59
60 OSSL_ERR_STATE_save() and OSSL_ERR_STATE_save_to_mark() cannot fail as it takes
61 over any allocated data from the thread error state.
62
63 OSSL_ERR_STATE_restore() is a best effort function. The only failure
64 that can happen during its operation is when memory allocation fails.
65 Because it manipulates the thread error state it avoids raising memory
66 errors on such failure. At worst the restored error entries will be
67 missing the auxiliary error data.
68
69 =head1 SEE ALSO
70
71 L<ERR_raise(3)>, L<ERR_get_error(3)>, L<ERR_clear_error(3)>
72
73 =head1 COPYRIGHT
74
75 Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
76
77 Licensed under the Apache License 2.0 (the "License"). You may not use
78 this file except in compliance with the License. You can obtain a copy
79 in the file LICENSE in the source distribution or at
80 L<https://www.openssl.org/source/license.html>.
81
82 =cut