Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse allocation of ks_asm #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

tesuji
Copy link

@tesuji tesuji commented Sep 19, 2024

Basically this:

-    pub fn asm(&self, insns: String, address: u64) -> Result<KeystoneOutput> {
+    pub fn asm(&self, insns: &CStr, address: u64) -> Result<KeystoneOutput> {
// and
 pub struct KeystoneOutput {
-    /// Size of the array storing the encoded instructions.
-    pub size: u32,
     /// Number of instructions that were successfully encoded.
-    pub stat_count: u32,
-    /// Array of encoded instructions.
-    pub bytes: Vec<u8>,
+    pub stat_count: size_t,
+    /// Size of the array storing the encoded instructions.
+    size: size_t,
+    /// A pointer of allocated encoded instructions.
+    ptr: *mut u8,
+}
+impl Drop for KeystoneOutput {
+    fn drop(&mut self) {
+        unsafe {
+            ffi::ks_free(self.ptr);
+        }
+    }
+}

From keystone-engine/keystone#589 but it stalled

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.

1 participant