@@ -102,9 +102,8 @@ __xray_register_sleds(const XRaySledEntry *SledsBegin,
102
102
return -1 ;
103
103
}
104
104
105
- if (Verbosity ()) {
105
+ if (Verbosity ())
106
106
Report (" Registering %d new functions!\n " , SledMap.Functions );
107
- }
108
107
109
108
{
110
109
SpinMutexLock Guard (&XRayInstrMapMutex);
@@ -145,9 +144,15 @@ void __xray_init() XRAY_NEVER_INSTRUMENT {
145
144
// Pre-allocation takes up approx. 5kB for XRayMaxObjects=64.
146
145
XRayInstrMaps = allocateBuffer<XRaySledMap>(XRayMaxObjects);
147
146
148
- __xray_register_sleds (__start_xray_instr_map, __stop_xray_instr_map,
147
+ int MainBinaryId = __xray_register_sleds (__start_xray_instr_map, __stop_xray_instr_map,
149
148
__start_xray_fn_idx, __stop_xray_fn_idx, false , {});
150
149
150
+ // The executable should always get ID 0.
151
+ if (MainBinaryId != 0 ) {
152
+ Report (" Registering XRay sleds failed.\n " );
153
+ return ;
154
+ }
155
+
151
156
atomic_store (&XRayInitialized, true , memory_order_release);
152
157
153
158
#ifndef XRAY_NO_PREINIT
@@ -187,8 +192,12 @@ SANITIZER_INTERFACE_ATTRIBUTE int32_t __xray_register_dso(
187
192
188
193
SANITIZER_INTERFACE_ATTRIBUTE bool
189
194
__xray_deregister_dso (int32_t ObjId) XRAY_NEVER_INSTRUMENT {
190
- // Make sure XRay has been initialized in the main executable.
191
- __xray_init ();
195
+
196
+ if (!atomic_load (&XRayInitialized, memory_order_acquire)) {
197
+ if (Verbosity ())
198
+ Report (" XRay has not been initialized. Cannot deregister DSO.\n " );
199
+ return false ;
200
+ }
192
201
193
202
if (ObjId <= 0 || ObjId >= __xray_num_objects ()) {
194
203
if (Verbosity ())
@@ -210,8 +219,9 @@ __xray_deregister_dso(int32_t ObjId) XRAY_NEVER_INSTRUMENT {
210
219
if (Verbosity ())
211
220
Report (" Can't deregister object with ID %d: object is not loaded.\n " ,
212
221
ObjId);
222
+ return false ;
213
223
}
214
- // This is all we have to do here .
224
+ // Mark DSO as unloaded. No need to unpatch .
215
225
Entry.Loaded = false ;
216
226
}
217
227
0 commit comments