BRL-CAD
magic.h
Go to the documentation of this file.
1/* M A G I C . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2008-2023 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21#ifndef BU_MAGIC_H
22#define BU_MAGIC_H
23
24#include "common.h"
25
26#include "bu/defines.h"
27
28/** @addtogroup bu_magic
29 *
30 * @brief
31 * Global registry of recognized magic numbers.
32 *
33 * Magic numbers provide a means
34 * to perform run-time sanity checks for memory corruption and
35 * uninitialized data.
36 *
37 * The one ugly thing about this implementation is that every BRL-CAD
38 * structure needs to have its magic number registered here and in
39 * the header.
40 *
41 * This file is part of LIBBU even though it provides magic numbers
42 * for structures in other libraries.
43 *
44 * The defines should be considered PRIVATE (even though they are not)
45 * and should NEVER be referenced by value.
46 */
47/** @{ */
48/** @brief Global registry of recognized magic numbers. */
49/** @file bu/magic.h */
50
51__BEGIN_DECLS
52
53/* libbu */
54
55#define BU_AVS_MAGIC 0x41765321 /**< AvS! */
56#define BU_BITV_MAGIC 0x62697476 /**< bitv */
57#define BU_COLOR_MAGIC 0x6275636c /**< bucl */
58#define BU_EXTERNAL_MAGIC 0x768dbbd0 /**< v??? */
59#define BU_HASH_ENTRY_MAGIC 0x48454e54 /**< HENT */
60#define BU_HASH_RECORD_MAGIC 0x68617368 /**< hash */
61#define BU_HASH_TBL_MAGIC 0x48415348 /**< HASH */
62#define BU_HIST_MAGIC 0x48697374 /**< Hist */
63#define BU_HOOK_LIST_MAGIC 0x90d5dead /**< ???? => Nietzsche? */
64#define BU_IMAGE_FILE_MAGIC 0x6269666d /**< bifm */
65#define BU_LIST_HEAD_MAGIC 0x01016580 /**< ??e? */
66#define BU_MAPPED_FILE_MAGIC 0x4d617066 /**< Mapf */
67#define BU_OBSERVER_MAGIC 0x65796573 /**< eyes */
68#define BU_PTBL_MAGIC 0x7074626c /**< ptbl */
69#define BU_RB_LIST_MAGIC 0x72626c73 /**< rbls */
70#define BU_RB_NODE_MAGIC 0x72626e6f /**< rbno */
71#define BU_RB_PKG_MAGIC 0x7262706b /**< rbpk */
72#define BU_RB_TREE_MAGIC 0x72627472 /**< rbtr */
73#define BU_VLB_MAGIC 0x5f564c42 /**< _VLB */
74#define BU_VLS_MAGIC 0x89333bbb /**< ?3;? */
75
76/* libbn */
77
78#define BN_GAUSS_MAGIC 0x1e886880 /**< ??h? => 512256128 */
79#define BN_POLY_MAGIC 0x506f4c79 /**< PoLy */
80#define BN_SPM_MAGIC 0x41278678 /**< A'?x */
81#define BN_TABDATA_MAGIC 0x53736d70 /**< Ssmp */
82#define BN_TABLE_MAGIC 0x53706374 /**< Spct */
83#define BN_TOL_MAGIC 0x98c734bb /**< ??4? */
84#define BN_UNIF_MAGIC 0x00be7460 /**< ??t` => 12481632 */
85#define BN_VERT_TREE_MAGIC 0x56455254 /**< VERT */
86#define BV_VLBLOCK_MAGIC 0x981bd112 /**< ???? */
87#define BV_VLIST_MAGIC 0x98237474 /**< ?\#tt */
88
89/* libbg */
90#define BG_TESS_TOL_MAGIC 0xb9090dab /**< ???? */
91
92/* primitive internals */
93
94#define RT_ARBN_INTERNAL_MAGIC 0x18236461 /**< ?\#da */
95#define RT_ARB_INTERNAL_MAGIC 0x9befd010 /**< ???? */
96#define RT_ARS_INTERNAL_MAGIC 0x77ddbbe3 /**< w??? */
97#define RT_BINUNIF_INTERNAL_MAGIC 0x42696e55 /**< BinU */
98#define RT_BOT_INTERNAL_MAGIC 0x626f7472 /**< botr */
99#define RT_BREP_INTERNAL_MAGIC 0x42524550 /**< BREP */
100#define RT_CLINE_INTERNAL_MAGIC 0x43767378 /**< CLIN */
101#define RT_DATUM_INTERNAL_MAGIC 0x6461746d /**< datm */
102#define RT_DSP_INTERNAL_MAGIC 0x00000de6 /**< ???? */
103#define RT_EBM_INTERNAL_MAGIC 0xf901b231 /**< ???1 */
104#define RT_EHY_INTERNAL_MAGIC 0xaaccee91 /**< ???? */
105#define RT_ELL_INTERNAL_MAGIC 0x93bb23ff /**< ??\#? */
106#define RT_EPA_INTERNAL_MAGIC 0xaaccee90 /**< ???? */
107#define RT_ETO_INTERNAL_MAGIC 0xaaccee92 /**< ???? */
108#define RT_EXTRUDE_INTERNAL_MAGIC 0x65787472 /**< extr */
109#define RT_GRIP_INTERNAL_MAGIC 0x31196205 /**< 1?b? */
110#define RT_HALF_INTERNAL_MAGIC 0xaa87bbdd /**< ???? */
111#define RT_HF_INTERNAL_MAGIC 0x4846494d /**< HFIM */
112#define RT_HYP_INTERNAL_MAGIC 0x68797065 /**< hype */
113#define RT_JOINT_INTERNAL_MAGIC 0x4a6f696e /**< Join */
114#define RT_METABALL_INTERNAL_MAGIC 0x62616c6c /**< ball */
115#define RT_NURB_INTERNAL_MAGIC 0x002b2bdd /**< ?++? */
116#define RT_PART_INTERNAL_MAGIC 0xaaccee87 /**< ???? */
117#define RT_PG_INTERNAL_MAGIC 0x9bfed887 /**< ???? */
118#define RT_PIPE_INTERNAL_MAGIC 0x7dd7bb3e /**< }??> */
119#define RT_REVOLVE_INTERNAL_MAGIC 0x7265766C /**< revl */
120#define RT_RHC_INTERNAL_MAGIC 0xaaccee89 /**< ???? */
121#define RT_RPC_INTERNAL_MAGIC 0xaaccee88 /**< ???? */
122#define RT_SKETCH_INTERNAL_MAGIC 0x736b6574 /**< sket */
123#define RT_SUBMODEL_INTERNAL_MAGIC 0x7375626d /**< subm */
124#define RT_SUPERELL_INTERNAL_MAGIC 0xff93bb23 /**< ???? */
125#define RT_TGC_INTERNAL_MAGIC 0xaabbdd87 /**< ???? */
126#define RT_TOR_INTERNAL_MAGIC 0x9bffed87 /**< ???? */
127#define RT_VOL_INTERNAL_MAGIC 0x987ba1d0 /**< ?{?? */
128#define RT_PNTS_INTERNAL_MAGIC 0x706e7473 /**< pnts */
129#define RT_ANNOT_INTERNAL_MAGIC 0x616e6e6f /**< anno */
130#define RT_HRT_INTERNAL_MAGIC 0x6872743f /**< hrt? */
131#define RT_SCRIPT_INTERNAL_MAGIC 0x73637269 /**< scri */
132
133/* n-manifold geometry */
134
135#define NMG_EDGEUSE2_MAGIC 0x91919191 /**< ???? => used in eu->l2.magic */
136#define NMG_EDGEUSE_MAGIC 0x90909090 /**< ???? */
137#define NMG_EDGE_G_CNURB_MAGIC 0x636e7262 /**< cnrb */
138#define NMG_EDGE_G_LSEG_MAGIC 0x6c696768 /**< ligh */
139#define NMG_EDGE_MAGIC 0x33333333 /**< 3333 */
140#define NMG_FACEUSE_MAGIC 0x56565656 /**< VVVV */
141#define NMG_FACE_G_PLANE_MAGIC 0x726b6e65 /**< rkne */
142#define NMG_FACE_G_SNURB_MAGIC 0x736e7262 /**< snrb */
143#define NMG_FACE_MAGIC 0x45454545 /**< EEEE */
144#define NMG_INTER_STRUCT_MAGIC 0x99912120 /**< ??! */
145#define NMG_KNOT_VECTOR_MAGIC 0x6b6e6f74 /**< knot */
146#define NMG_LOOPUSE_MAGIC 0x78787878 /**< xxxx */
147#define NMG_LOOP_A_MAGIC 0x6420224c /**< d "L */
148#define NMG_LOOP_MAGIC 0x67676767 /**< gggg */
149#define NMG_MODEL_MAGIC 0x12121212 /**< ???? */
150#define NMG_RADIAL_MAGIC 0x52614421 /**< RaD! */
151#define NMG_RAY_DATA_MAGIC 0x01651771 /**< ?e?q */
152#define NMG_REGION_A_MAGIC 0x696e6720 /**< ing */
153#define NMG_REGION_MAGIC 0x23232323 /**< \#\#\#\# */
154#define NMG_RT_HIT_MAGIC 0x48697400 /**< Hit? */
155#define NMG_RT_HIT_SUB_MAGIC 0x48696d00 /**< Him? */
156#define NMG_RT_MISS_MAGIC 0x4d697300 /**< Mis? */
157#define NMG_SHELL_A_MAGIC 0x65207761 /**< e wa */
158#define NMG_SHELL_MAGIC 0x71077345 /**< q?sE => shell oil */
159#define NMG_VERTEXUSE_A_CNURB_MAGIC 0x20416e64 /**< And */
160#define NMG_VERTEXUSE_A_PLANE_MAGIC 0x69676874 /**< ight */
161#define NMG_VERTEXUSE_MAGIC 0x12341234 /**< ?4?4 */
162#define NMG_VERTEX_G_MAGIC 0x72737707 /**< rsw? */
163#define NMG_VERTEX_MAGIC 0x00123123 /**< ??1\# */
164
165/* raytrace */
166
167#define RT_ANP_MAGIC 0x41507270 /**< APrp */
168#define RT_AP_MAGIC 0x4170706c /**< Appl */
169#define RT_COMB_MAGIC 0x436f6d49 /**< ComI */
170#define RT_CONSTRAINT_MAGIC 0x7063696d /**< pcim */
171#define RT_MATERIAL_MAGIC 0x54414d55 /**< TAMU */
172#define RT_CTS_MAGIC 0x98989123 /**< ???\# */
173#define RT_DB_TRAVERSE_MAGIC 0x64627472 /**< dbtr */
174#define RT_DBTS_MAGIC 0x64627473 /**< dbts */
175#define RT_DB_INTERNAL_MAGIC 0x0dbbd867 /**< ???g */
176#define RT_DIR_MAGIC 0x05551212 /**< ?U?? => Directory assistance */
177#define RT_FUNCTAB_MAGIC 0x46754e63 /**< FuNc */
178#define RT_HIT_MAGIC 0x20686974 /**< hit */
179#define RT_HTBL_MAGIC 0x6874626c /**< htbl */
180#define RT_PIECELIST_MAGIC 0x70636c73 /**< pcls */
181#define RT_PIECESTATE_MAGIC 0x70637374 /**< pcst */
182#define RT_RAY_MAGIC 0x78726179 /**< xray */
183#define RT_REGION_MAGIC 0xdffb8001 /**< ???? */
184#define RT_SEG_MAGIC 0x98bcdef1 /**< ???? */
185#define RT_SOLTAB2_MAGIC 0x92bfcde2 /**< ???? => l2.magic */
186#define RT_SOLTAB_MAGIC 0x92bfcde0 /**< ???? => l.magic */
187#define RT_TREE_MAGIC 0x91191191 /**< ???? */
188#define RT_WDB_MAGIC 0x5f576462 /**< _Wdb */
189
190/* ged */
191
192#define GED_CMD_MAGIC 0x65786563 /**< exec */
193
194/* fb */
195
196#define FB_MAGIC 0xfbfb00fb /**< ???? */
197#define FB_WGL_MAGIC 0x574f4642 /**< WOFB */
198#define FB_OGL_MAGIC 0x584f4642 /**< XOFB */
199#define FB_X24_MAGIC 0x58324642 /**< X2FB */
200#define FB_TK_MAGIC 0x544b4642 /**< TKFB */
201#define FB_QT_MAGIC 0x51544642 /**< QTFB */
202#define FB_QTGL_MAGIC 0x51474642 /**< QGFB */
203#define FB_DEBUG_MAGIC 0x44424642 /**< DBFB */
204#define FB_DISK_MAGIC 0x44494642 /**< STFB */
205#define FB_STK_MAGIC 0x53544642 /**< STFB */
206#define FB_MEMORY_MAGIC 0x4d454642 /**< MEFB */
207#define FB_REMOTE_MAGIC 0x524d4642 /**< MEFB */
208#define FB_NULL_MAGIC 0x4e554642 /**< NUFB */
209#define FB_SWFB_MAGIC 0x51474642 /**< SWFB */
210
211/* misc */
212
213#define ANIMATE_MAGIC 0x414e4963 /**< ANIc */
214#define BV_MAGIC 0x62766965 /**< bvie */
215#define CURVE_BEZIER_MAGIC 0x62657a69 /**< bezi */
216#define CURVE_CARC_MAGIC 0x63617263 /**< carc */
217#define CURVE_LSEG_MAGIC 0x6c736567 /**< lseg */
218#define CURVE_NURB_MAGIC 0x6e757262 /**< nurb */
219#define ANN_TSEG_MAGIC 0x74736567 /**< tseg */
220#define DB5_RAW_INTERNAL_MAGIC 0x64357269 /**< d5ri */
221#define DBI_MAGIC 0x57204381 /**< W C? */
222#define DB_FULL_PATH_MAGIC 0x64626670 /**< dbfp */
223#define DM_MAGIC 0x444d4d4d /**< DMMM */
224#define LIGHT_MAGIC 0xdbddbdb7 /**< ???? */
225#define MF_MAGIC 0x55968058 /**< U??X */
226#define PIXEL_EXT_MAGIC 0x50787400 /**< Pxt */
227#define PL_MAGIC 0x0beef00d /**< ???? => mm. bee food. */
228#define PT_HD_MAGIC 0x87687680 /**< ?hv? */
229#define PT_MAGIC 0x87687681 /**< ?hv? */
230#define RESOURCE_MAGIC 0x83651835 /**< ?e?5 */
231#define RTI_MAGIC 0x99101658 /**< ???X */
232#define WDB_METABALLPT_MAGIC 0x6d627074 /**< mbpt */
233#define WDB_PIPESEG_MAGIC 0x9723ffef /**< ?\#?? */
234#define WMEMBER_MAGIC 0x43128912 /**< C??? */
235#define ICV_IMAGE_MAGIC 0x6269666d /**< bifm */
236
237/** @brief Routines involved with handling "magic numbers" used to identify various in-memory data structures. */
238
239/**
240 * Macros to check and validate a structure pointer, given that the
241 * first entry in the structure is a magic number. ((void)(1?0:((_ptr), void(), 0)))
242 */
243#ifdef NO_BOMBING_MACROS
244# define BU_CKMAG(_ptr, _magic, _str) (void)(_ptr)
245#else
246# define BU_CKMAG(_ptr, _magic, _str) do { \
247 /* coverity[BAD_SIZEOF] */ \
248 if (UNLIKELY(( ((uintptr_t)(_ptr) == 0) /* non-zero pointer */ \
249 || ((uintptr_t)(_ptr) & (sizeof((uintptr_t)(_ptr))-1)) /* aligned ptr */ \
250 || (*((const uint32_t *)(_ptr)) != (uint32_t)(_magic)) /* matches value */ \
251 ))) { \
252 bu_badmagic((const uint32_t *)(_ptr), (uint32_t)(_magic), _str, __FILE__, __LINE__); \
253 } \
254 } while (0)
255#endif
256
257
258/**
259 * This function is called when there is something wrong with a
260 * pointer. It's primarily a support routine for BU_CKMAG macro, but
261 * may be used elsewhere. This function never returns.
262 */
263BU_EXPORT NORETURN extern void bu_badmagic(const uint32_t *ptr, uint32_t magic, const char *str, const char *file, int line);
264
265
266/** @brief Routines involved with handling "magic numbers" used to identify various in-memory data structures. */
267
268/**
269 * Given a number which has been found in the magic number field of a
270 * structure (which is typically the first entry), determine what kind
271 * of structure this magic number pertains to. This is called by the
272 * macro BU_CK_MAGIC() to provide a "hint" as to what sort of pointer
273 * error might have been made.
274 */
275BU_EXPORT extern const char *bu_identify_magic(uint32_t magic);
276
277
278/** @} */
279
280__END_DECLS
281
282#endif /* BU_MAGIC_H */
283
284/*
285 * Local Variables:
286 * tab-width: 8
287 * mode: C
288 * indent-tabs-mode: t
289 * c-file-style: "stroustrup"
290 * End:
291 * ex: shiftwidth=4 tabstop=8
292 */
Header file for the BRL-CAD common definitions.
const char * bu_identify_magic(uint32_t magic)
Routines involved with handling "magic numbers" used to identify various in-memory data structures.
NORETURN void bu_badmagic(const uint32_t *ptr, uint32_t magic, const char *str, const char *file, int line)
#define NORETURN
Definition: common.h:427