/src/openssl40/crypto/err/err_mark.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2003-2026 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #include <openssl/err.h> |
11 | | #include "err_local.h" |
12 | | |
13 | | int ERR_set_mark(void) |
14 | 393M | { |
15 | 393M | ERR_STATE *es; |
16 | | |
17 | 393M | es = ossl_err_get_state_int(); |
18 | 393M | if (es == NULL) |
19 | 0 | return 0; |
20 | | |
21 | 393M | if (es->bottom == es->top) |
22 | 260M | return 0; |
23 | 133M | es->err_marks[es->top]++; |
24 | 133M | return 1; |
25 | 393M | } |
26 | | |
27 | | int ERR_pop(void) |
28 | 0 | { |
29 | 0 | ERR_STATE *es; |
30 | |
|
31 | 0 | es = ossl_err_get_state_int(); |
32 | 0 | if (es == NULL || es->bottom == es->top) |
33 | 0 | return 0; |
34 | | |
35 | 0 | err_clear(es, es->top, 0); |
36 | 0 | es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1; |
37 | 0 | return 1; |
38 | 0 | } |
39 | | |
40 | | int ERR_pop_to_mark(void) |
41 | 375M | { |
42 | 375M | ERR_STATE *es; |
43 | | |
44 | 375M | es = ossl_err_get_state_int(); |
45 | 375M | if (es == NULL) |
46 | 0 | return 0; |
47 | | |
48 | 691M | while (es->bottom != es->top |
49 | 445M | && es->err_marks[es->top] == 0) { |
50 | 316M | err_clear(es, es->top, 0); |
51 | 316M | es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1; |
52 | 316M | } |
53 | | |
54 | 375M | if (es->bottom == es->top) |
55 | 246M | return 0; |
56 | 128M | es->err_marks[es->top]--; |
57 | 128M | return 1; |
58 | 375M | } |
59 | | |
60 | | int ERR_count_to_mark(void) |
61 | 49.2M | { |
62 | 49.2M | ERR_STATE *es; |
63 | 49.2M | int count = 0, top; |
64 | | |
65 | 49.2M | es = ossl_err_get_state_int(); |
66 | 49.2M | if (es == NULL) |
67 | 0 | return 0; |
68 | | |
69 | 49.2M | top = es->top; |
70 | 49.3M | while (es->bottom != top |
71 | 678k | && es->err_marks[top] == 0) { |
72 | 40.8k | ++count; |
73 | 40.8k | top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1; |
74 | 40.8k | } |
75 | | |
76 | 49.2M | return count; |
77 | 49.2M | } |
78 | | |
79 | | int ERR_clear_last_mark(void) |
80 | 18.3M | { |
81 | 18.3M | ERR_STATE *es; |
82 | 18.3M | int top; |
83 | | |
84 | 18.3M | es = ossl_err_get_state_int(); |
85 | 18.3M | if (es == NULL) |
86 | 0 | return 0; |
87 | | |
88 | 18.3M | top = es->top; |
89 | 25.0M | while (es->bottom != top |
90 | 11.1M | && es->err_marks[top] == 0) { |
91 | 6.64M | top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1; |
92 | 6.64M | } |
93 | | |
94 | 18.3M | if (es->bottom == top) |
95 | 13.8M | return 0; |
96 | 4.51M | es->err_marks[top]--; |
97 | 4.51M | return 1; |
98 | 18.3M | } |