Skip to content

Commit 31f4792

Browse files
committed
Fix handling of error values
1 parent 22fbdef commit 31f4792

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

offload/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,13 @@ void *GenericDeviceTy::getFree_ArgBuf(size_t sz) {
18911891
}
18921892
}
18931893
if (!found_ptr) {
1894-
found_ptr = this->allocate(sz, &found_ptr, TARGET_ALLOC_SHARED);
1894+
auto AllocOrErr = this->allocate(sz, nullptr, TARGET_ALLOC_SHARED);
1895+
if (!AllocOrErr) {
1896+
REPORT("Could not get SHARED mem for Arg Buffer: %s\n",
1897+
toString(AllocOrErr.takeError()).data());
1898+
return nullptr;
1899+
}
1900+
found_ptr = *AllocOrErr;
18951901
assert(found_ptr && "Could not get SHARED mem for Arg Buffer\n");
18961902
ArgBufEntryTy *new_entry_ptr = new ArgBufEntryTy;
18971903
new_entry_ptr->Size = sz;
@@ -1915,7 +1921,7 @@ void GenericDeviceTy::moveBusyToFree_ArgBuf(void *ptr) {
19151921
}
19161922
void GenericDeviceTy::clear_ArgBufs() {
19171923
for (auto entry : ArgBufEntries) {
1918-
this->free(entry->Addr, TARGET_ALLOC_SHARED);
1924+
consumeError(this->free(entry->Addr, TARGET_ALLOC_SHARED));
19191925
delete entry;
19201926
}
19211927
ArgBufEntries.clear();

offload/plugins-nextgen/common/src/RPC.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,23 @@ rpc::Status handleOffloadOpcodes(plugin::GenericDeviceTy &Device,
7070
#ifdef OFFLOAD_ENABLE_EMISSARY_APIS
7171
case ALT_LIBC_MALLOC: {
7272
Port.recv_and_send([&](rpc::Buffer *Buffer, uint32_t) {
73-
Buffer->data[0] = reinterpret_cast<uintptr_t>(
74-
Device.allocate(Buffer->data[0], nullptr, TARGET_ALLOC_DEVICE));
73+
auto PtrOrErr =
74+
Device.allocate(Buffer->data[0], nullptr, TARGET_ALLOC_DEVICE);
75+
void *Ptr = nullptr;
76+
if (!PtrOrErr)
77+
consumeError(PtrOrErr.takeError());
78+
else
79+
Ptr = *PtrOrErr;
80+
Buffer->data[0] = reinterpret_cast<uintptr_t>(Ptr);
7581
});
7682
break;
7783
}
7884
case ALT_LIBC_FREE: {
7985
Port.recv([&](rpc::Buffer *Buffer, uint32_t) {
80-
Device.free(reinterpret_cast<void *>(Buffer->data[0]),
81-
TARGET_ALLOC_DEVICE);
86+
if (auto Error = Device.free(reinterpret_cast<void *>(Buffer->data[0]),
87+
TARGET_ALLOC_DEVICE)) {
88+
consumeError(std::move(Error));
89+
}
8290
});
8391
break;
8492
}

0 commit comments

Comments
 (0)