-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ CTestTestfile.cmake | |
_deps | ||
CMakeUserPresets.json | ||
*zig-* | ||
*.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const std = @import("std"); | ||
|
||
// [[clang::nonblocking]] | ||
fn array() callconv(.C) void { | ||
|
||
// raw_c_allocator: Real-time violation: intercepted call to real-time unsafe function | ||
// `malloc` in real-time context! | ||
// c_allocator: Real-time violation: intercepted call to real-time unsafe function | ||
// `posix_memalign` in real-time context! | ||
// page_allocator (no-libc/syscalls): None | ||
|
||
var arr = std.ArrayList([]const u8).init(std.heap.raw_c_allocator); | ||
defer arr.deinit(); | ||
arr.append("foo") catch unreachable; | ||
arr.append("bar") catch unreachable; | ||
arr.append("baz") catch unreachable; | ||
} | ||
|
||
fn openfile() callconv(.C) void { | ||
const file = std.fs.cwd().openFile("tests/malloc.d", .{}) catch unreachable; | ||
defer file.close(); | ||
} | ||
|
||
comptime { | ||
@export(&array, .{ | ||
.name = "ffi_zigarray", | ||
.linkage = .weak, | ||
}); | ||
@export(&openfile, .{ | ||
.name = "ffi_zig_openfile", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
/// Reference: | ||
/// https://github.com/CppCon/CppCon2024/blob/main/Presentations/LLVMs_Realtime_Safety_Revolution.pdf | ||
|
||
#include <vector> | ||
// #include <vector> | ||
|
||
int process(int) [[clang::nonblocking]] { | ||
std::vector<int> v(16); | ||
return v[16]; | ||
extern "C" { | ||
void ffi_zigarray(); | ||
void ffi_zig_openfile(); | ||
} | ||
|
||
// int process(int) [[clang::nonblocking]] { | ||
// std::vector<int> v(16); | ||
// return v[16]; | ||
// } | ||
|
||
void zig_main() [[clang::nonblocking]] { | ||
ffi_zigarray(); | ||
ffi_zig_openfile(); | ||
} | ||
|
||
int main() { | ||
zig_main(); | ||
return 0; | ||
} | ||
int main() { return process(0); } |