1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! IEEE 802.3 CRC-32 (the "zip / png / ethernet" variant).
//!
//! NOT cryptographic. v4.37 uses it as a fast checksum on persistent
//! storage envelopes (catalog snapshot, WAL records, backup bundles)
//! so bit-flips surface as explicit "CRC mismatch" errors instead of
//! deserializing into silent corruption.
//!
//! Implementation: standard polynomial `0xEDB88320`, byte-at-a-time
//! table lookup. The 256-entry table is built at first call into an
//! array of `AtomicU32`; thread-safe and zero-allocation after that.
use ;
const POLY: u32 = 0xEDB8_8320;
/// Precomputed table (filled lazily by `ensure_table`). `AtomicU32`
/// is `Sync` and gives us interior mutability without an
/// `UnsafeCell` dance. The `[ZERO; 256]` initialization
/// deliberately gets 256 distinct atomics — the
/// declare-interior-mutable-const lint warns about the const-as-
/// expression footgun (where two readers would share the same
/// underlying value), which doesn't apply here.
static TABLE: = ;
static STATE: AtomicU8 = new;
const UNINIT: u8 = 0;
const INIT: u8 = 1;
const READY: u8 = 2;
/// CRC-32 of `data`. Standard IEEE polynomial; the "zip / png /
/// ethernet" check value.