OSSL_ERR_STATE_SAVE(3ossl)
π OSSL_ERR_STATE_SAVE π
okay so bestie, this is a page from the OpenSSL manual, section 3ossl, and it's literally all about saving and restoring error state β like hitting "save game" on your thread's error stack before it gets wiped. no cap, it's giving tiny time capsule energy π
β¨ SYNOPSIS β¨
#include <openssl/err.h>
ERR_STATE *OSSL_ERR_STATE_new(void);
void OSSL_ERR_STATE_save(ERR_STATE *es);
void OSSL_ERR_STATE_save_to_mark(ERR_STATE *es);
void OSSL_ERR_STATE_restore(const ERR_STATE *es);
void OSSL_ERR_STATE_free(ERR_STATE *es);
π¦ DESCRIPTION π¦
so the whole vibe of these five functions is: they shuttle your error state between the thread local error state and a preallocated error state structure. moving house, but for errors π
OSSL_ERR_STATE_new()β allocates a fresh, empty error state structure, which is the thing you'll pass in when you want to save and restore thread error state. brand new, no notes, empty vessel energy β¨OSSL_ERR_STATE_save()β saves the thread error state intoes. and then? it clears the thread error state, like, immediately. also, any state that was previously saved inesgets cleared first, before the new state moves in. out with the old, in with the new π§ΉOSSL_ERR_STATE_save_to_mark()β this one is likeOSSL_ERR_STATE_save()'s slightly more selective cousin. it only savesERRentries up to the most recent mark on theERRstack. those entries get moved toesand removed from the thread error state. BUT β and this is the important part, bestie β the most recent markedERR, plus anyERRstate before it, stays right where it is as part of the thread error state, and does not get moved to theERR_STATE. the mark is not cleared either; you have to clear it yourself after calling this, usingERR_pop_to_mark(3)orERR_clear_last_mark(3). (because a call toOSSL_ERR_STATE_save_to_mark()leaves the markedERRas the top error, either of those two functions will have the same effect.) and if there's no markedERRin the thread local error state at all? then allERRentries get copied, and it behaves exactly like a call toOSSL_ERR_STATE_save(). no mark, no problem πOSSL_ERR_STATE_restore()β adds all the error entries from the saved stateesback into the thread error state. existing entries in the thread error state are not affected, as long as there's enough space for all the new ones. and any allocated data in the saved error entries gets duplicated when it's added to the thread state β no sharing, no aliasing, we duplicate in this house π«ΆOSSL_ERR_STATE_free()β frees the saved error statees. and if the argument isNULL? nothing happens. iconic, honestly, it just minds its business π
πΈ RETURN VALUES πΈ
OSSL_ERR_STATE_new()returns a pointer to the allocatedERR_STATEstructure, orNULLon error. π«OSSL_ERR_STATE_save(),OSSL_ERR_STATE_save_to_mark(),OSSL_ERR_STATE_restore(), andOSSL_ERR_STATE_free()do not return any values. they simply do. main character energy, no receipts π
π NOTES π
OSSL_ERR_STATE_save() and OSSL_ERR_STATE_save_to_mark() cannot fail, because they take over any allocated data from the thread error state. slay, honestly π₯
OSSL_ERR_STATE_restore() is a best effort function β read that again, bestie. the only failure that can happen during its operation is when memory allocation fails. and because it manipulates the thread error state, it avoids raising memory errors on such a failure. at worst, the restored error entries will be missing the auxiliary error data. so like, it tried its best and we respect it π
lowkey important: that missing-auxiliary-data thing is the at worst case, and it only happens on allocation failure. don't panic, just know it π
π SEE ALSO π
π HISTORY π
all of these functions were added in OpenSSL 3.2. so they're relatively new, they're fresh, they're the moment β¨
π COPYRIGHT π
Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie π«Ά this one's from OpenSSL 3.5.6, dated 2026-04-07, page OSSL_ERR_STATE_SAVE(3ossl) β go save some error state, you absolute icon ππ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms