template <uint32_t magic>
class Canary
Defined at line 51 of file ../../zircon/system/ulib/fbl/include/fbl/canary.h
An embeddable structure guard. To use this, choose a 4-byte guard value.
If the value is ASCII, you can use fbl::magic() to convert it to a 32-bit
integer. Note that the string *must* be exactly 4-bytes, excluding the
trailing nul-byte. This is checked by a static_assert in Canary.
For this example, we'll use the guard string "guar". Add a member of type
fbl::Canary
<fbl
::magic("guar")> to the class you'd like to guard. It will
automatically initialize itself with the guard value during construction and
check it during destruction. You can check the value during the lifetime of
your object by calling the Assert() method.
If the value is not ASCII, you can directly use an integer literal to
instantiate the class. The value must be storable in a uint32_t. For this
example, we'll use 0x12345678. Add a member of type fbl::Canary
<
0x12345678>
to the class you'd like to guard. As above, it will be automatically checked
on destruction and can be manually asserted against.
Public Methods
void Canary<magic> ()
Defined at line 55 of file ../../zircon/system/ulib/fbl/include/fbl/canary.h
void ~Canary<magic> ()
Defined at line 57 of file ../../zircon/system/ulib/fbl/include/fbl/canary.h
void Assert ()
ZX_ASSERT that the value of |magic_| is as expected.
Defined at line 63 of file ../../zircon/system/ulib/fbl/include/fbl/canary.h
bool Valid ()
Some places have special handling of bad magic values. For theses
cases, simply return whether the |magic_| is correct, and let
them respond appropriately if not.
Defined at line 72 of file ../../zircon/system/ulib/fbl/include/fbl/canary.h