From eb748b47f3a24488602f9e553933acc01c062812 Mon Sep 17 00:00:00 2001 From: Michal Ziulek Date: Thu, 16 May 2024 15:20:01 +0200 Subject: [PATCH 1/2] integration-with-c: Use bofObjectRunAsyncThread() instead of bofObjectRun(). --- bofs/src/simple-chain/wSimpleChainShared.zig | 1 + bofs/src/simple-chain/wSimpleChainStage1.zig | 2 ++ examples/integration-with-c/main.c | 13 +++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bofs/src/simple-chain/wSimpleChainShared.zig b/bofs/src/simple-chain/wSimpleChainShared.zig index 0e1e5de..f6192fe 100644 --- a/bofs/src/simple-chain/wSimpleChainShared.zig +++ b/bofs/src/simple-chain/wSimpleChainShared.zig @@ -1,3 +1,4 @@ pub const State = struct { number: u32, + handle: *anyopaque, }; diff --git a/bofs/src/simple-chain/wSimpleChainStage1.zig b/bofs/src/simple-chain/wSimpleChainStage1.zig index 120ef98..95df9ce 100644 --- a/bofs/src/simple-chain/wSimpleChainStage1.zig +++ b/bofs/src/simple-chain/wSimpleChainStage1.zig @@ -1,5 +1,6 @@ const std = @import("std"); const beacon = @import("bof_api").beacon; +const w32 = @import("bof_api").win32; const shared = @import("wSimpleChainShared.zig"); pub export fn go(args: ?[*]u8, args_len: i32) callconv(.C) u8 { @@ -12,6 +13,7 @@ pub export fn go(args: ?[*]u8, args_len: i32) callconv(.C) u8 { }; state.number += 1; + state.handle = w32.GetCurrentProcess(); return 0; } diff --git a/examples/integration-with-c/main.c b/examples/integration-with-c/main.c index 0500f40..2b6aec5 100644 --- a/examples/integration-with-c/main.c +++ b/examples/integration-with-c/main.c @@ -36,8 +36,17 @@ int main(int argc, char *argv[]) { printf("Running BOF from command line C application...\n"); BofContext* bof_context = NULL; - if (bofObjectRun(bof_handle, NULL, 0, &bof_context) < 0) return 1; - if (bof_context == NULL) return 1; + if (bofObjectRunAsyncThread( + bof_handle, + NULL, + 0, + NULL, + NULL, + &bof_context) < 0) return 1; + if (bof_context == NULL) + return 1; + + bofContextWait(bof_context); const char* output = bofContextGetOutput(bof_context, NULL); if (output) From 9a28a596cd6372031cbeaa1a9768c2e7b62a0483 Mon Sep 17 00:00:00 2001 From: Michal Ziulek Date: Thu, 16 May 2024 15:22:48 +0200 Subject: [PATCH 2/2] integration-with-c: Use bofObjectRunAsyncThread() instead of bofObjectRun(). --- examples/integration-with-c/main.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/examples/integration-with-c/main.c b/examples/integration-with-c/main.c index 2b6aec5..2e6c351 100644 --- a/examples/integration-with-c/main.c +++ b/examples/integration-with-c/main.c @@ -36,15 +36,8 @@ int main(int argc, char *argv[]) { printf("Running BOF from command line C application...\n"); BofContext* bof_context = NULL; - if (bofObjectRunAsyncThread( - bof_handle, - NULL, - 0, - NULL, - NULL, - &bof_context) < 0) return 1; - if (bof_context == NULL) - return 1; + if (bofObjectRunAsyncThread(bof_handle, NULL, 0, NULL, NULL, &bof_context) < 0) return 1; + if (bof_context == NULL) return 1; bofContextWait(bof_context);