Skip to content

FFI for KLLVM#4

Merged
ehildenb merged 11 commits into
masterfrom
guy/kframework_ffi
May 29, 2025
Merged

FFI for KLLVM#4
ehildenb merged 11 commits into
masterfrom
guy/kframework_ffi

Conversation

@gtrepta
Copy link
Copy Markdown
Contributor

@gtrepta gtrepta commented Apr 16, 2025

Creates the kframework_ffi crate with an interface into kllvm's data structures and execution.

Notable files:
kframework_ffi/src/kllvm.rs: Has a docstring explaining how to use the FFI
examples/fuzzer/README.md: Explains how to run an example fuzzer for an Imp program

@gtrepta gtrepta requested review from ehildenb and tothtamas28 April 17, 2025 00:01
@ehildenb
Copy link
Copy Markdown
Member

Can we add a github action that just at least builds the project and calls the fuzzer on a few inputs? just to get the test harness in place and make sure that it's working.

Copy link
Copy Markdown
Collaborator

@tothtamas28 tothtamas28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! ✨

Comment thread kframework_ffi/Cargo.toml
Comment thread examples/fuzzer/build.rs
Comment thread kframework_ffi/src/kllvm/ffi.rs
Comment on lines +32 to +41
pub fn init() {
unsafe {
ffi::kllvm_init();
}
}
pub fn free_all_memory() {
unsafe {
ffi::kllvm_free_all_memory();
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a way to safely wrap these based on Rust's ownership / borrowing model. So maybe a struct that calls kllvm_init on instantiation, kllvm_free_all_memory on drop, and owns all the KLLVM objects so that they are only valid in-between.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure about this. What if the struct is instantiated twice? One goes out of scope, calling kllvm::free_all_memory while the other one persists? How will using the owned Pattern's and Block's work, what does that interface look like?

There are enough design hurdles here that would take time and effort to go through and there's no guarantee that on the other side we would have something any more airtight than a possible missed call to kllvm::init (the call to kllvm::free_all_memory matters less imo, because modern OSes these days clean everything up when the process dies anyway).

Looking at this snippet I realized that there are no docstrings giving context for these functions, I'll write something up.

@gtrepta gtrepta force-pushed the guy/kframework_ffi branch from 72d6e86 to 7940449 Compare May 5, 2025 21:53
@gtrepta
Copy link
Copy Markdown
Contributor Author

gtrepta commented May 5, 2025

Can we add a github action that just at least builds the project and calls the fuzzer on a few inputs? just to get the test harness in place and make sure that it's working.

Done.

@ehildenb ehildenb merged commit 35f72d3 into master May 29, 2025
2 checks passed
@ehildenb ehildenb deleted the guy/kframework_ffi branch May 29, 2025 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants