GCC Middle and Back End API Reference
vtable-verify.h
Go to the documentation of this file.
1/* Copyright (C) 2013-2024 Free Software Foundation, Inc.
2
3This file is part of GCC.
4
5GCC is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free
7Software Foundation; either version 3, or (at your option) any later
8version.
9
10GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11WARRANTY; without even the implied warranty of MERCHANTABILITY or
12FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13for more details.
14
15You should have received a copy of the GNU General Public License
16along with GCC; see the file COPYING3. If not see
17<http://www.gnu.org/licenses/>. */
18
19/* Virtual Table Pointer Security. */
20
21#ifndef VTABLE_VERIFY_H
22#define VTABLE_VERIFY_H
23
24#include "sbitmap.h"
25
26/* The function decl used to create calls to __VLTVtableVerify. It must
27 be global because it needs to be initialized in the C++ front end, but
28 used in the middle end (in the vtable verification pass). */
29
31
32/* Global variable keeping track of how many vtable map variables we
33 have created. */
34extern unsigned num_vtable_map_nodes;
35
36/* Keep track of how many virtual calls we are actually verifying. */
39
40/* Each vtable map variable corresponds to a virtual class. Each
41 vtable map variable has a hash table associated with it, that keeps
42 track of the vtable pointers for which we have generated a call to
43 __VLTRegisterPair (with the current vtable map variable). This is
44 the hash table node that is used for each entry in this hash table
45 of vtable pointers.
46
47 Sometimes there are multiple valid vtable pointer entries that use
48 the same vtable pointer decl with different offsets. Therefore,
49 for each vtable pointer in the hash table, there is also an array
50 of offsets used with that vtable. */
51
53{
54 tree vtable_decl; /* The var decl of the vtable. */
55 vec<unsigned> offsets; /* The offsets array. */
56};
57
58struct registration_hasher : nofree_ptr_hash <struct vtable_registration>
59{
60 static inline hashval_t hash (const vtable_registration *);
61 static inline bool equal (const vtable_registration *,
62 const vtable_registration *);
63};
64
67
68/* This struct is used to represent the class hierarchy information
69 that we need. Each vtable map variable has an associated class
70 hierarchy node (struct vtv_graph_node). Note: In this struct,
71 'children' means immediate descendants in the class hierarchy;
72 'descendant' means any descendant however many levels deep. */
73
75 tree class_type; /* The record_type of the class. */
76 unsigned class_uid; /* A unique, monotonically
77 ascending id for class node.
78 Each vtable map node also has
79 an id. The class uid is the
80 same as the vtable map node id
81 for nodes corresponding to the
82 same class. */
83 unsigned num_processed_children; /* # of children for whom we have
84 computed the class hierarchy
85 transitive closure. */
86 vec<struct vtv_graph_node *> parents; /* Vector of parents in the graph. */
87 vec<struct vtv_graph_node *> children; /* Vector of children in the graph.*/
88 sbitmap descendants; /* Bitmap representing all this node's
89 descendants in the graph. */
90};
91
92/* This is the node used for our hashtable of vtable map variable
93 information. When we create a vtable map variable (var decl) we
94 put it into one of these nodes; create a corresponding
95 vtv_graph_node for our class hierarchy info and store that in this
96 node; generate a unique (monotonically ascending) id for both the
97 vtbl_map_node and the vtv_graph_node; and insert the node into two
98 data structures (to make it easy to find in several different
99 ways): 1). A hash table ("vtbl_map_hash" in vtable-verify.cc).
100 This gives us an easy way to check to see if we already have a node
101 for the vtable map variable or not; and 2). An array (vector) of
102 vtbl_map_nodes, where the array index corresponds to the unique id
103 of the vtbl_map_node, which gives us an easy way to use bitmaps to
104 represent and find the vtable map nodes. */
105
107 tree vtbl_map_decl; /* The var decl for the vtable map
108 variable. */
109 tree class_name; /* The DECL_ASSEMBLER_NAME of the
110 class. */
111 struct vtv_graph_node *class_info; /* Our class hierarchy info for the
112 class. */
113 unsigned uid; /* The unique id for the vtable map
114 variable. */
115 struct vtbl_map_node *next, *prev; /* Pointers for the linked list
116 structure. */
117 register_table_type *registered; /* Hashtable of vtable pointers for which
118 we have generated a _VLTRegisterPair
119 call with this vtable map variable. */
120 bool is_used; /* Boolean indicating if we used this vtable map
121 variable in a call to __VLTVerifyVtablePointer. */
122};
123
124/* Controls debugging for vtable verification. */
125extern bool vtv_debug;
126
127/* The global vector of vtbl_map_nodes. */
129
130/* The global vectors for mangled class names for anonymous classes. */
133
135extern struct vtbl_map_node *vtbl_map_get_node (tree);
137extern void vtbl_map_node_class_insert (struct vtbl_map_node *, unsigned);
139 tree, unsigned);
141 tree, unsigned);
142
143#endif /* VTABLE_VERIFY_H */
Definition hash-table.h:474
Definition hash-table.h:375
#define GTY(x)
Definition coretypes.h:41
union tree_node * tree
Definition coretypes.h:97
Definition hash-traits.h:303
Definition vtable-verify.h:59
static hashval_t hash(const vtable_registration *)
Definition vtable-verify.cc:244
static bool equal(const vtable_registration *, const vtable_registration *)
Definition vtable-verify.cc:251
Definition sbitmap.h:87
Definition vec.h:359
Definition vec.h:450
Definition vtable-verify.h:53
vec< unsigned > offsets
Definition vtable-verify.h:55
tree vtable_decl
Definition vtable-verify.h:54
Definition vtable-verify.h:106
tree class_name
Definition vtable-verify.h:109
struct vtbl_map_node * prev
Definition vtable-verify.h:115
struct vtv_graph_node * class_info
Definition vtable-verify.h:111
tree vtbl_map_decl
Definition vtable-verify.h:107
unsigned uid
Definition vtable-verify.h:113
bool is_used
Definition vtable-verify.h:120
struct vtbl_map_node * next
Definition vtable-verify.h:115
register_table_type * registered
Definition vtable-verify.h:117
Definition vtable-verify.h:74
unsigned class_uid
Definition vtable-verify.h:76
vec< struct vtv_graph_node * > children
Definition vtable-verify.h:87
tree class_type
Definition vtable-verify.h:75
sbitmap descendants
Definition vtable-verify.h:88
unsigned num_processed_children
Definition vtable-verify.h:83
vec< struct vtv_graph_node * > parents
Definition vtable-verify.h:86
unsigned num_vtable_map_nodes
Definition vtable-verify.cc:147
vec< tree, va_gc > * vtbl_mangled_name_ids
Definition vtable-verify.cc:311
vec< struct vtbl_map_node * > vtbl_map_nodes_vec
Definition vtable-verify.cc:305
int total_num_virtual_calls
Definition vtable-verify.cc:148
tree verify_vtbl_ptr_fndecl
Definition vtable-verify.cc:152
bool vtbl_map_node_registration_find(struct vtbl_map_node *, tree, unsigned)
Definition vtable-verify.cc:169
int total_num_verified_vcalls
Definition vtable-verify.cc:149
hash_table< registration_hasher > register_table_type
Definition vtable-verify.h:65
void vtbl_register_mangled_name(tree, tree)
Definition vtable-verify.cc:352
register_table_type::iterator registration_iterator_type
Definition vtable-verify.h:66
void vtbl_map_node_class_insert(struct vtbl_map_node *, unsigned)
struct vtbl_map_node * find_or_create_vtbl_map_node(tree)
Definition vtable-verify.cc:414
vec< tree, va_gc > * vtbl_mangled_name_types
Definition vtable-verify.cc:310
bool vtv_debug
struct vtbl_map_node * vtbl_map_get_node(tree)
Definition vtable-verify.cc:374
bool vtbl_map_node_registration_insert(struct vtbl_map_node *, tree, unsigned)
Definition vtable-verify.cc:197