From 40a3b658d7f06db1be0a6be8db4ff98e1e6c4e12 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 11 Nov 2025 15:01:25 +1100 Subject: [PATCH] [orc-rt] Replace wrapper fn `void *CallCtx` arg with `uint64_t CallId`. This argument serves as an opaque id (outside the ControllerAccess object) for a call to a wrapper function. I expect that most ControllerAccess implementations will want to use this argument as a sequence number (plain integer), for which uint64_t will be a better fit than void*. For ControllerAccess implementations that want to use a pointer, uint64_t should be sufficiently large. --- orc-rt/include/orc-rt-c/WrapperFunction.h | 7 +-- orc-rt/include/orc-rt/SPSWrapperFunction.h | 4 +- orc-rt/include/orc-rt/SimpleNativeMemoryMap.h | 8 ++-- orc-rt/include/orc-rt/WrapperFunction.h | 28 ++++++------ orc-rt/lib/executor/SimpleNativeMemoryMap.cpp | 16 +++---- orc-rt/unittests/DirectCaller.h | 8 ++-- orc-rt/unittests/SPSWrapperFunctionTest.cpp | 43 ++++++++++--------- 7 files changed, 60 insertions(+), 54 deletions(-) diff --git a/orc-rt/include/orc-rt-c/WrapperFunction.h b/orc-rt/include/orc-rt-c/WrapperFunction.h index 280e513c9c0e6..fefdf03ff3f06 100644 --- a/orc-rt/include/orc-rt-c/WrapperFunction.h +++ b/orc-rt/include/orc-rt-c/WrapperFunction.h @@ -54,7 +54,7 @@ typedef struct { * Asynchronous return function for an orc-rt wrapper function. */ typedef void (*orc_rt_WrapperFunctionReturn)( - orc_rt_SessionRef Session, void *CallCtx, + orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionBuffer ResultBytes); /** @@ -62,10 +62,11 @@ typedef void (*orc_rt_WrapperFunctionReturn)( * * ArgBytes contains the serialized arguments for the wrapper function. * Session holds a reference to the session object. - * CallCtx holds a pointer to the context object for this particular call. + * CallId holds a pointer to the context object for this particular call. * Return holds a pointer to the return function. */ -typedef void (*orc_rt_WrapperFunction)(orc_rt_SessionRef Session, void *CallCtx, +typedef void (*orc_rt_WrapperFunction)(orc_rt_SessionRef Session, + uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes); diff --git a/orc-rt/include/orc-rt/SPSWrapperFunction.h b/orc-rt/include/orc-rt/SPSWrapperFunction.h index 46c08a0c688d0..1ae2c130dc0cf 100644 --- a/orc-rt/include/orc-rt/SPSWrapperFunction.h +++ b/orc-rt/include/orc-rt/SPSWrapperFunction.h @@ -124,10 +124,10 @@ template struct SPSWrapperFunction { } template - static void handle(orc_rt_SessionRef Session, void *CallCtx, + static void handle(orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, WrapperFunctionBuffer ArgBytes, Handler &&H) { - WrapperFunction::handle(Session, CallCtx, Return, std::move(ArgBytes), + WrapperFunction::handle(Session, CallId, Return, std::move(ArgBytes), WrapperFunctionSPSSerializer(), std::forward(H)); } diff --git a/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h b/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h index cf0e4ac732ca0..20b080e960dea 100644 --- a/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h +++ b/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h @@ -114,21 +114,21 @@ class SimpleNativeMemoryMap : public ResourceManager { } // namespace orc_rt ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_reserve_sps_wrapper( - orc_rt_SessionRef Session, void *CallCtx, + orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes); ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_releaseMultiple_sps_wrapper( - orc_rt_SessionRef Session, void *CallCtx, + orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes); ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_initialize_sps_wrapper( - orc_rt_SessionRef Session, void *CallCtx, + orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes); ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_deinitializeMultiple_sps_wrapper( - orc_rt_SessionRef Session, void *CallCtx, + orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes); #endif // ORC_RT_SIMPLENATIVEMEMORYMAP_H diff --git a/orc-rt/include/orc-rt/WrapperFunction.h b/orc-rt/include/orc-rt/WrapperFunction.h index 6e8b84e980dc0..494e2a0dc0bb1 100644 --- a/orc-rt/include/orc-rt/WrapperFunction.h +++ b/orc-rt/include/orc-rt/WrapperFunction.h @@ -137,14 +137,14 @@ using WFHandlerTraits = CallableTraitsHelper; template class StructuredYieldBase { public: - StructuredYieldBase(orc_rt_SessionRef Session, void *CallCtx, + StructuredYieldBase(orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, Serializer &&S) - : Session(Session), CallCtx(CallCtx), Return(Return), + : Session(Session), CallId(CallId), Return(Return), S(std::forward(S)) {} protected: orc_rt_SessionRef Session; - void *CallCtx; + uint64_t CallId; orc_rt_WrapperFunctionReturn Return; std::decay_t S; }; @@ -158,9 +158,9 @@ class StructuredYield, Serializer> using StructuredYieldBase::StructuredYieldBase; void operator()(RetT &&R) { if (auto ResultBytes = this->S.result().serialize(std::forward(R))) - this->Return(this->Session, this->CallCtx, ResultBytes->release()); + this->Return(this->Session, this->CallId, ResultBytes->release()); else - this->Return(this->Session, this->CallCtx, + this->Return(this->Session, this->CallId, WrapperFunctionBuffer::createOutOfBandError( "Could not serialize wrapper function result data") .release()); @@ -173,7 +173,7 @@ class StructuredYield, Serializer> public: using StructuredYieldBase::StructuredYieldBase; void operator()() { - this->Return(this->Session, this->CallCtx, + this->Return(this->Session, this->CallId, WrapperFunctionBuffer().release()); } }; @@ -251,12 +251,12 @@ struct WrapperFunction { /// /// /// static void adder_add_async_sps_wrapper( - /// orc_rt_SessionRef Session, void *CallCtx, + /// orc_rt_SessionRef Session, uint64_t CallId, /// orc_rt_WrapperFunctionReturn Return, /// orc_rt_WrapperFunctionBuffer ArgBytes) { /// using SPSSig = SPSString(SPSExecutorAddr, int32_t, bool); /// SPSWrapperFunction::handle( - /// Session, CallCtx, Return, ArgBytes, + /// Session, CallId, Return, ArgBytes, /// WrapperFunction::handleWithAsyncMethod(&MyClass::myMethod)); /// } /// @endcode @@ -313,12 +313,12 @@ struct WrapperFunction { /// /// /// static void adder_add_sync_sps_wrapper( - /// orc_rt_SessionRef Session, void *CallCtx, + /// orc_rt_SessionRef Session, uint64_t CallId, /// orc_rt_WrapperFunctionReturn Return, /// orc_rt_WrapperFunctionBuffer ArgBytes) { /// using SPSSig = SPSString(SPSExecutorAddr, int32_t, bool); /// SPSWrapperFunction::handle( - /// Session, CallCtx, Return, ArgBytes, + /// Session, CallId, Return, ArgBytes, /// WrapperFunction::handleWithSyncMethod(&Adder::addSync)); /// } /// @endcode @@ -368,7 +368,7 @@ struct WrapperFunction { /// This utility deserializes and serializes arguments and return values /// (using the given Serializer), and calls the given handler. template - static void handle(orc_rt_SessionRef Session, void *CallCtx, + static void handle(orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, WrapperFunctionBuffer ArgBytes, Serializer &&S, Handler &&H) { @@ -380,16 +380,16 @@ struct WrapperFunction { typedef typename CallableArgInfo::args_tuple_type RetTupleType; if (ArgBytes.getOutOfBandError()) - return Return(Session, CallCtx, ArgBytes.release()); + return Return(Session, CallId, ArgBytes.release()); if (auto Args = S.arguments().template deserialize(ArgBytes)) std::apply(HandlerTraits::forwardArgsAsRequested(bind_front( std::forward(H), detail::StructuredYield( - Session, CallCtx, Return, std::move(S)))), + Session, CallId, Return, std::move(S)))), *Args); else - Return(Session, CallCtx, + Return(Session, CallId, WrapperFunctionBuffer::createOutOfBandError( "Could not deserialize wrapper function arg data") .release()); diff --git a/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp b/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp index 5d410acbc65d9..c6a005d6a70e6 100644 --- a/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp +++ b/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp @@ -367,45 +367,45 @@ Error SimpleNativeMemoryMap::recordDeallocActions( } ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_reserve_sps_wrapper( - orc_rt_SessionRef Session, void *CallCtx, + orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { using Sig = SPSExpected(SPSExecutorAddr, SPSSize); SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, + Session, CallId, Return, ArgBytes, WrapperFunction::handleWithAsyncMethod(&SimpleNativeMemoryMap::reserve)); } ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_releaseMultiple_sps_wrapper( - orc_rt_SessionRef Session, void *CallCtx, + orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { using Sig = SPSError(SPSExecutorAddr, SPSSequence); - SPSWrapperFunction::handle(Session, CallCtx, Return, ArgBytes, + SPSWrapperFunction::handle(Session, CallId, Return, ArgBytes, WrapperFunction::handleWithAsyncMethod( &SimpleNativeMemoryMap::releaseMultiple)); } ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_initialize_sps_wrapper( - orc_rt_SessionRef Session, void *CallCtx, + orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { using Sig = SPSExpected( SPSExecutorAddr, SPSSimpleNativeMemoryMapInitializeRequest); - SPSWrapperFunction::handle(Session, CallCtx, Return, ArgBytes, + SPSWrapperFunction::handle(Session, CallId, Return, ArgBytes, WrapperFunction::handleWithAsyncMethod( &SimpleNativeMemoryMap::initialize)); } ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_deinitializeMultiple_sps_wrapper( - orc_rt_SessionRef Session, void *CallCtx, + orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { using Sig = SPSError(SPSExecutorAddr, SPSSequence); SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, + Session, CallId, Return, ArgBytes, WrapperFunction::handleWithAsyncMethod( &SimpleNativeMemoryMap::deinitializeMultiple)); } diff --git a/orc-rt/unittests/DirectCaller.h b/orc-rt/unittests/DirectCaller.h index 7c5c9d300d882..fab006717c157 100644 --- a/orc-rt/unittests/DirectCaller.h +++ b/orc-rt/unittests/DirectCaller.h @@ -22,10 +22,11 @@ class DirectCaller { virtual ~DirectResultSender() {} virtual void send(orc_rt_SessionRef Session, orc_rt::WrapperFunctionBuffer ResultBytes) = 0; - static void send(orc_rt_SessionRef Session, void *CallCtx, + static void send(orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionBuffer ResultBytes) { std::unique_ptr( - reinterpret_cast(CallCtx)) + reinterpret_cast( + static_cast(CallId))) ->send(Session, ResultBytes); } }; @@ -59,7 +60,8 @@ class DirectCaller { orc_rt::WrapperFunctionBuffer ArgBytes) { auto DR = makeDirectResultSender(std::forward(HandleResult)); - Fn(Session, reinterpret_cast(DR.release()), + Fn(Session, + static_cast(reinterpret_cast(DR.release())), DirectResultSender::send, ArgBytes.release()); } diff --git a/orc-rt/unittests/SPSWrapperFunctionTest.cpp b/orc-rt/unittests/SPSWrapperFunctionTest.cpp index 81e5755e821f3..3b1592d89d8f1 100644 --- a/orc-rt/unittests/SPSWrapperFunctionTest.cpp +++ b/orc-rt/unittests/SPSWrapperFunctionTest.cpp @@ -22,11 +22,11 @@ using namespace orc_rt; -static void void_noop_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, +static void void_noop_sps_wrapper(orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, + Session, CallId, Return, ArgBytes, [](move_only_function Return) { Return(); }); } @@ -40,11 +40,12 @@ TEST(SPSWrapperFunctionUtilsTest, VoidNoop) { EXPECT_TRUE(Ran); } -static void add_via_lambda_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, +static void add_via_lambda_sps_wrapper(orc_rt_SessionRef Session, + uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, + Session, CallId, Return, ArgBytes, [](move_only_function Return, int32_t X, int32_t Y) { Return(X + Y); }); @@ -64,11 +65,11 @@ static void add_via_function(move_only_function Return, } static void -add_via_function_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, +add_via_function_sps_wrapper(orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, add_via_function); + Session, CallId, Return, ArgBytes, add_via_function); } TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunction) { @@ -80,11 +81,11 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunction) { } static void -add_via_function_pointer_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, +add_via_function_pointer_sps_wrapper(orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, &add_via_function); + Session, CallId, Return, ArgBytes, &add_via_function); } TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunctionPointer) { @@ -96,11 +97,12 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunctionPointer) { } static void -round_trip_string_via_span_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, +round_trip_string_via_span_sps_wrapper(orc_rt_SessionRef Session, + uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, + Session, CallId, Return, ArgBytes, [](move_only_function Return, span S) { Return({S.data(), S.size()}); }); @@ -119,11 +121,11 @@ TEST(SPSWrapperFunctionUtilsTest, RoundTripStringViaSpan) { } static void improbable_feat_sps_wrapper(orc_rt_SessionRef Session, - void *CallCtx, + uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, + Session, CallId, Return, ArgBytes, [](move_only_function Return, bool LuckyHat) { if (LuckyHat) Return(Error::success()); @@ -155,11 +157,11 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentConversionErrorFailureCase) { EXPECT_EQ(ErrMsg, "crushed by boulder"); } -static void halve_number_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, +static void halve_number_sps_wrapper(orc_rt_SessionRef Session, uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction(int32_t)>::handle( - Session, CallCtx, Return, ArgBytes, + Session, CallId, Return, ArgBytes, [](move_only_function)> Return, int N) { if (N % 2 == 0) Return(N >> 1); @@ -208,12 +210,12 @@ class SPSSerializationTraits, OpCounter> { static void handle_with_reference_types_sps_wrapper(orc_rt_SessionRef Session, - void *CallCtx, + uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction, SPSOpCounter<1>, SPSOpCounter<2>, - SPSOpCounter<3>)>::handle(Session, CallCtx, Return, ArgBytes, + SPSOpCounter<3>)>::handle(Session, CallId, Return, ArgBytes, [](move_only_function Return, OpCounter<0>, OpCounter<1> &, const OpCounter<2> &, @@ -281,11 +283,11 @@ class Adder { } // anonymous namespace static void adder_add_async_sps_wrapper(orc_rt_SessionRef Session, - void *CallCtx, + uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, + Session, CallId, Return, ArgBytes, WrapperFunction::handleWithAsyncMethod(&Adder::addAsync)); } @@ -300,11 +302,12 @@ TEST(SPSWrapperFunctionUtilsTest, HandleWtihAsyncMethod) { EXPECT_EQ(Result, 42); } -static void adder_add_sync_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, +static void adder_add_sync_sps_wrapper(orc_rt_SessionRef Session, + uint64_t CallId, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, + Session, CallId, Return, ArgBytes, WrapperFunction::handleWithSyncMethod(&Adder::addSync)); }