Coder Social home page Coder Social logo

rust-xed / xed-sys Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 7.0 494 KB

Rust FFI bindings for Intel XED

License: Apache License 2.0

Rust 96.77% Shell 0.08% C 3.14%
x86 x86-64 intel rust-lang rust-ffi-bindings rust rust-language rust-ffi intel-xed encoder

xed-sys's Introduction

Build Status docs.rs crates.io

xed-sys

Rust FFI bindings for Intel XED.

/// Similar to `examples/xed-min.c` from official Intel XED repository.
use xed_sys::*;

fn main() {
    unsafe {
        let (mmode, stack_addr_width) = (XED_MACHINE_MODE_LEGACY_32, XED_ADDRESS_WIDTH_32b);

        xed_tables_init();

        let itext: [u8; 15] = [
            0xf, 0x85, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        ];

        for bytes in 0..16 {
            let mut xedd = ::std::mem::MaybeUninit::<xed_decoded_inst_t>::uninit();
            xed_decoded_inst_zero(xedd.as_mut_ptr());
            xed_decoded_inst_set_mode(xedd.as_mut_ptr(), mmode, stack_addr_width);

            let xed_error: xed_error_enum_t = xed_decode(xedd.as_mut_ptr(), itext.as_ptr(), bytes);
            let desc = std::ffi::CStr::from_ptr(xed_error_enum_t2str(xed_error)).to_string_lossy();
            println!("bytes={} error={}", bytes, desc);
        }
    }
}

Building

In order to build this crate, you need:

If you have the bindgen feature enabled then you will also need:

Examples

You can find usage examples in the examples/ directory.

These examples are meant to be executed with cargo. For instance, to run the example named xed_min:

# cd to the crate's root directory
cargo run --example xed_min

xed-sys's People

Contributors

agodnic avatar dependabot-preview[bot] avatar dependabot[bot] avatar flier avatar jxors avatar khuey avatar phantomical avatar tathanhdinh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xed-sys's Issues

Simpler binding

Hello all,

In the current build script, I find that sometimes we need copy the source folders (i.e. xed and mbuild), that may be not necessary.

Could you please take a look at this WIP branch which proposes a simpler build script.

Many thanks for any response.

[Discussion] Move all functions into the crate namespace?

Currently, we have two top-level modules: xed_interface and xed_version.

  • xed_version contains xed_get_version and xed_get_copyright
  • xed_interface contains everything. This includes xed_get_version and xed_get_copyright.

This is... not quite optimal. I propose that we simply export everything in the root module.

For backwards compatibility we need to keep the xed_interface and xed_version modules. However, they can be defined like this:

pub mod xed_interface {
    pub use crate::xed_interface_internal::*;
}
pub mod xed_version {
    pub use crate::{xed_get_version, xed_get_copyright};
}

where xed_interface_internal is wherever we actually import everything. This approach allows for the rustdoc to be nicer as well. Note that this approach ensures that we don't export xed_interface::xed_interface::etc which would be needlessly messy.

I wouldn't mark xed_interface and xed_version as deprecated just yet since that seems too quick to do in a single version bump. We can do that later whenever we feel like creating a 3.0 version.

Thoughts?

Discussion: how to deal with XED's static inline functions

Bindgen is currently unable to deal with functions declared as static inline (see #1344 and #1090).
XED has way too many functions like this.

The current workaround being used in this repository is to manually run c2rust to transpile the whole functions.

Disadvantages of current approach

  1. Updating the XED git submodule to a newer version requires manually running c2rust.
  2. (I'm not sure about this one) The transpiled code may be architecture-dependant in some way, since the function's code is generated for a fixed processor architecture and potentially run on a different architecture.

Possible solutions

  1. Change build.rs so that c2rust is run in conjunction with bindgen.
  2. Implement the feature we need in bindgen.

About crate ownership

The name xed-sys is already taken on crates.io, which is unfortunate.

I wonder if the owner @valarauca is interested in joining us to make a crates.io release with the name xed-sys. This way we would avoid creating unnecessary fragmentation in the Rust ecosystem.

If so, we'd have to:

  • Change this crate's name on Cargo.toml from xed-sys2 to xed-sys.
  • Change this crate's version to a number strictly greater than the current version on crates.io. I think it should be 0.2.0 since we'll introduce a breaking change in one way or another.

Change crate name/version

After merging #13:

  • Change this crate's name on Cargo.toml from xed-sys2 to xed-sys. Update examples/xed-min/Cargo.toml.
  • Change this crate's version to 0.2.0.

New crates.io release

With the changes that have gone in recently it'd probably be good to do a crates.io release :)

While you're at it, it would be good to add either me or rust-xed as an owner on crates.io so that we don't have to go through this again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.