OSSL_ERR_STATE_SAVE(3ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’– 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 into es. and then? it clears the thread error state, like, immediately. also, any state that was previously saved in es gets 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 like OSSL_ERR_STATE_save()'s slightly more selective cousin. it only saves ERR entries up to the most recent mark on the ERR stack. those entries get moved to es and removed from the thread error state. BUT β€” and this is the important part, bestie β€” the most recent marked ERR, plus any ERR state before it, stays right where it is as part of the thread error state, and does not get moved to the ERR_STATE. the mark is not cleared either; you have to clear it yourself after calling this, using ERR_pop_to_mark(3) or ERR_clear_last_mark(3). (because a call to OSSL_ERR_STATE_save_to_mark() leaves the marked ERR as the top error, either of those two functions will have the same effect.) and if there's no marked ERR in the thread local error state at all? then all ERR entries get copied, and it behaves exactly like a call to OSSL_ERR_STATE_save(). no mark, no problem 😌
  • OSSL_ERR_STATE_restore() β€” adds all the error entries from the saved state es back 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 state es. and if the argument is NULL? nothing happens. iconic, honestly, it just minds its business πŸ’€

🌸 RETURN VALUES 🌸

  • OSSL_ERR_STATE_new() returns a pointer to the allocated ERR_STATE structure, or NULL on error. 🫠
  • OSSL_ERR_STATE_save(), OSSL_ERR_STATE_save_to_mark(), OSSL_ERR_STATE_restore(), and OSSL_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 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