|
13 | 13 |
|
14 | 14 | #define DEBUG_TYPE "jitlink"
|
15 | 15 |
|
| 16 | +using namespace llvm; |
| 17 | + |
| 18 | +namespace { |
| 19 | + |
| 20 | +// FIXME: Remove this copy of CWrapperFunctionResult as soon as JITLink can |
| 21 | +// depend on shared utils from Orc. |
| 22 | + |
| 23 | +// Must be kept in-sync with compiler-rt/lib/orc/c-api.h. |
| 24 | +union CWrapperFunctionResultDataUnion { |
| 25 | + char *ValuePtr; |
| 26 | + char Value[sizeof(ValuePtr)]; |
| 27 | +}; |
| 28 | + |
| 29 | +// Must be kept in-sync with compiler-rt/lib/orc/c-api.h. |
| 30 | +typedef struct { |
| 31 | + CWrapperFunctionResultDataUnion Data; |
| 32 | + size_t Size; |
| 33 | +} CWrapperFunctionResult; |
| 34 | + |
| 35 | +Error toError(CWrapperFunctionResult R) { |
| 36 | + bool HasError = false; |
| 37 | + std::string ErrMsg; |
| 38 | + if (R.Size) { |
| 39 | + bool Large = R.Size > sizeof(CWrapperFunctionResultDataUnion); |
| 40 | + char *Content = Large ? R.Data.ValuePtr : R.Data.Value; |
| 41 | + if (Content[0]) { |
| 42 | + HasError = true; |
| 43 | + ErrMsg.resize(R.Size - 1); |
| 44 | + memcpy(&ErrMsg[0], Content + 1, R.Size - 1); |
| 45 | + } |
| 46 | + if (Large) |
| 47 | + free(R.Data.ValuePtr); |
| 48 | + } else if (R.Data.ValuePtr) { |
| 49 | + HasError = true; |
| 50 | + ErrMsg = R.Data.ValuePtr; |
| 51 | + free(R.Data.ValuePtr); |
| 52 | + } |
| 53 | + |
| 54 | + if (HasError) |
| 55 | + return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode()); |
| 56 | + return Error::success(); |
| 57 | +} |
| 58 | +} // namespace |
| 59 | + |
16 | 60 | namespace llvm {
|
17 | 61 | namespace jitlink {
|
18 | 62 |
|
19 | 63 | JITLinkMemoryManager::~JITLinkMemoryManager() = default;
|
20 | 64 | JITLinkMemoryManager::InFlightAlloc::~InFlightAlloc() = default;
|
21 | 65 |
|
22 | 66 | static Error runAllocAction(JITLinkMemoryManager::AllocActionCall &C) {
|
23 |
| - using DeallocFnTy = char *(*)(const void *, size_t); |
24 |
| - auto *Fn = jitTargetAddressToPointer<DeallocFnTy>(C.FnAddr); |
25 |
| - |
26 |
| - if (char *ErrMsg = Fn(jitTargetAddressToPointer<const void *>(C.CtxAddr), |
27 |
| - static_cast<size_t>(C.CtxSize))) { |
28 |
| - auto E = make_error<StringError>(ErrMsg, inconvertibleErrorCode()); |
29 |
| - free(ErrMsg); |
30 |
| - return E; |
31 |
| - } |
| 67 | + using WrapperFnTy = CWrapperFunctionResult (*)(const void *, size_t); |
| 68 | + auto *Fn = jitTargetAddressToPointer<WrapperFnTy>(C.FnAddr); |
32 | 69 |
|
33 |
| - return Error::success(); |
| 70 | + return toError(Fn(jitTargetAddressToPointer<const void *>(C.CtxAddr), |
| 71 | + static_cast<size_t>(C.CtxSize))); |
34 | 72 | }
|
35 | 73 |
|
36 | 74 | // Align a JITTargetAddress to conform with block alignment requirements.
|
|
0 commit comments