@@ -29,11 +29,6 @@ ORC_RT_JIT_DISPATCH_TAG(__orc_rt_macho_get_initializers_tag)
29
29
ORC_RT_JIT_DISPATCH_TAG(__orc_rt_macho_get_deinitializers_tag)
30
30
ORC_RT_JIT_DISPATCH_TAG(__orc_rt_macho_symbol_lookup_tag)
31
31
32
- // eh-frame registration functions.
33
- // We expect these to be available for all processes.
34
- extern "C" void __register_frame(const void *);
35
- extern " C" void __deregister_frame (const void *);
36
-
37
32
// Objective-C types.
38
33
struct objc_class;
39
34
struct objc_image_info ;
@@ -66,28 +61,6 @@ extern "C" void swift_registerProtocolConformances(
66
61
67
62
namespace {
68
63
69
- template <typename HandleFDEFn>
70
- void walkEHFrameSection (span<const char > EHFrameSection,
71
- HandleFDEFn HandleFDE) {
72
- const char *CurCFIRecord = EHFrameSection.data ();
73
- uint64_t Size = *reinterpret_cast <const uint32_t *>(CurCFIRecord);
74
-
75
- while (CurCFIRecord != EHFrameSection.end () && Size != 0 ) {
76
- const char *OffsetField = CurCFIRecord + (Size == 0xffffffff ? 12 : 4 );
77
- if (Size == 0xffffffff )
78
- Size = *reinterpret_cast <const uint64_t *>(CurCFIRecord + 4 ) + 12 ;
79
- else
80
- Size += 4 ;
81
- uint32_t Offset = *reinterpret_cast <const uint32_t *>(OffsetField);
82
-
83
- if (Offset != 0 )
84
- HandleFDE (CurCFIRecord);
85
-
86
- CurCFIRecord += Size;
87
- Size = *reinterpret_cast <const uint32_t *>(CurCFIRecord);
88
- }
89
- }
90
-
91
64
Error validatePointerSectionExtent (const char *SectionName,
92
65
const ExecutorAddrRange &SE) {
93
66
if (SE.size ().getValue () % sizeof (uintptr_t )) {
@@ -250,8 +223,8 @@ class MachOPlatformRuntimeState {
250
223
MachOPlatformRuntimeState (MachOPlatformRuntimeState &&) = delete ;
251
224
MachOPlatformRuntimeState &operator =(MachOPlatformRuntimeState &&) = delete ;
252
225
253
- Error registerObjectSections (MachOPerObjectSectionsToRegister POSR );
254
- Error deregisterObjectSections (MachOPerObjectSectionsToRegister POSR );
226
+ Error registerThreadDataSection (span< const char > ThreadDataSec );
227
+ Error deregisterThreadDataSection (span< const char > ThreadDataSec );
255
228
256
229
const char *dlerror ();
257
230
void *dlopen (string_view Name, int Mode);
@@ -270,8 +243,6 @@ class MachOPlatformRuntimeState {
270
243
PerJITDylibState *getJITDylibStateByName (string_view Path);
271
244
PerJITDylibState &getOrCreateJITDylibState (MachOJITDylibInitializers &MOJDIs);
272
245
273
- Error registerThreadDataSection (span<const char > ThreadDataSec);
274
-
275
246
Expected<ExecutorAddr> lookupSymbolInJITDylib (void *DSOHandle,
276
247
string_view Symbol);
277
248
@@ -320,27 +291,28 @@ void MachOPlatformRuntimeState::destroy() {
320
291
delete MOPS;
321
292
}
322
293
323
- Error MachOPlatformRuntimeState::registerObjectSections (
324
- MachOPerObjectSectionsToRegister POSR) {
325
- if (POSR.EHFrameSection .Start )
326
- walkEHFrameSection (POSR.EHFrameSection .toSpan <const char >(),
327
- __register_frame);
328
-
329
- if (POSR.ThreadDataSection .Start ) {
330
- if (auto Err = registerThreadDataSection (
331
- POSR.ThreadDataSection .toSpan <const char >()))
332
- return Err;
294
+ Error MachOPlatformRuntimeState::registerThreadDataSection (
295
+ span<const char > ThreadDataSection) {
296
+ std::lock_guard<std::mutex> Lock (ThreadDataSectionsMutex);
297
+ auto I = ThreadDataSections.upper_bound (ThreadDataSection.data ());
298
+ if (I != ThreadDataSections.begin ()) {
299
+ auto J = std::prev (I);
300
+ if (J->first + J->second > ThreadDataSection.data ())
301
+ return make_error<StringError>(" Overlapping __thread_data sections" );
333
302
}
334
-
303
+ ThreadDataSections.insert (
304
+ I, std::make_pair (ThreadDataSection.data (), ThreadDataSection.size ()));
335
305
return Error::success ();
336
306
}
337
307
338
- Error MachOPlatformRuntimeState::deregisterObjectSections (
339
- MachOPerObjectSectionsToRegister POSR) {
340
- if (POSR.EHFrameSection .Start )
341
- walkEHFrameSection (POSR.EHFrameSection .toSpan <const char >(),
342
- __deregister_frame);
343
-
308
+ Error MachOPlatformRuntimeState::deregisterThreadDataSection (
309
+ span<const char > ThreadDataSection) {
310
+ std::lock_guard<std::mutex> Lock (ThreadDataSectionsMutex);
311
+ auto I = ThreadDataSections.find (ThreadDataSection.end ());
312
+ if (I == ThreadDataSections.end ())
313
+ return make_error<StringError>(" Attempt to deregister unknown thread data "
314
+ " section" );
315
+ ThreadDataSections.erase (I);
344
316
return Error::success ();
345
317
}
346
318
@@ -462,20 +434,6 @@ MachOPlatformRuntimeState::getOrCreateJITDylibState(
462
434
return JDS;
463
435
}
464
436
465
- Error MachOPlatformRuntimeState::registerThreadDataSection (
466
- span<const char > ThreadDataSection) {
467
- std::lock_guard<std::mutex> Lock (ThreadDataSectionsMutex);
468
- auto I = ThreadDataSections.upper_bound (ThreadDataSection.data ());
469
- if (I != ThreadDataSections.begin ()) {
470
- auto J = std::prev (I);
471
- if (J->first + J->second > ThreadDataSection.data ())
472
- return make_error<StringError>(" Overlapping __thread_data sections" );
473
- }
474
- ThreadDataSections.insert (
475
- I, std::make_pair (ThreadDataSection.data (), ThreadDataSection.size ()));
476
- return Error::success ();
477
- }
478
-
479
437
Expected<ExecutorAddr>
480
438
MachOPlatformRuntimeState::lookupSymbolInJITDylib (void *DSOHandle,
481
439
string_view Sym) {
@@ -587,6 +545,13 @@ void destroyMachOTLVMgr(void *MachOTLVMgr) {
587
545
delete static_cast <MachOPlatformRuntimeTLVManager *>(MachOTLVMgr);
588
546
}
589
547
548
+ Error runWrapperFunctionCalls (std::vector<WrapperFunctionCall> WFCs) {
549
+ for (auto &WFC : WFCs)
550
+ if (auto Err = WFC.runWithSPSRet ())
551
+ return Err;
552
+ return Error::success ();
553
+ }
554
+
590
555
} // end anonymous namespace
591
556
592
557
// ------------------------------------------------------------------------------
@@ -605,30 +570,41 @@ __orc_rt_macho_platform_shutdown(char *ArgData, size_t ArgSize) {
605
570
return WrapperFunctionResult ().release ();
606
571
}
607
572
608
- // / Wrapper function for registering metadata on a per-object basis.
609
573
ORC_RT_INTERFACE __orc_rt_CWrapperFunctionResult
610
- __orc_rt_macho_register_object_sections (char *ArgData, size_t ArgSize) {
611
- return WrapperFunction<SPSError (SPSMachOPerObjectSectionsToRegister)>::handle (
612
- ArgData, ArgSize,
613
- [](MachOPerObjectSectionsToRegister &POSR) {
614
- return MachOPlatformRuntimeState::get ().registerObjectSections (
615
- std::move (POSR));
574
+ __orc_rt_macho_register_thread_data_section (char *ArgData, size_t ArgSize) {
575
+ // NOTE: Does not use SPS to deserialize arg buffer, instead the arg buffer
576
+ // is taken to be the range of the thread data section.
577
+ return WrapperFunction<SPSError ()>::handle (
578
+ nullptr , 0 ,
579
+ [&]() {
580
+ return MachOPlatformRuntimeState::get ()
581
+ .registerThreadDataSection (
582
+ span<const char >(ArgData, ArgSize));
616
583
})
617
584
.release ();
618
585
}
619
586
620
- // / Wrapper for releasing per-object metadat.
621
587
ORC_RT_INTERFACE __orc_rt_CWrapperFunctionResult
622
- __orc_rt_macho_deregister_object_sections (char *ArgData, size_t ArgSize) {
623
- return WrapperFunction<SPSError (SPSMachOPerObjectSectionsToRegister)>::handle (
624
- ArgData, ArgSize,
625
- [](MachOPerObjectSectionsToRegister &POSR) {
626
- return MachOPlatformRuntimeState::get ().deregisterObjectSections (
627
- std::move (POSR));
588
+ __orc_rt_macho_deregister_thread_data_section (char *ArgData, size_t ArgSize) {
589
+ // NOTE: Does not use SPS to deserialize arg buffer, instead the arg buffer
590
+ // is taken to be the range of the thread data section.
591
+ return WrapperFunction<SPSError ()>::handle (
592
+ nullptr , 0 ,
593
+ [&]() {
594
+ return MachOPlatformRuntimeState::get ()
595
+ .deregisterThreadDataSection (
596
+ span<const char >(ArgData, ArgSize));
628
597
})
629
598
.release ();
630
599
}
631
600
601
+ ORC_RT_INTERFACE __orc_rt_CWrapperFunctionResult
602
+ __orc_rt_macho_run_wrapper_function_calls (char *ArgData, size_t ArgSize) {
603
+ return WrapperFunction<SPSError (SPSSequence<SPSWrapperFunctionCall>)>::handle (
604
+ ArgData, ArgSize, runWrapperFunctionCalls)
605
+ .release ();
606
+ }
607
+
632
608
// ------------------------------------------------------------------------------
633
609
// TLV support
634
610
// ------------------------------------------------------------------------------
0 commit comments