Skip to content

illumos header translation is wrong 02000000 should be 0x80000 #1026

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

Merged
merged 1 commit into from
Jul 1, 2018

Conversation

papertigers
Copy link
Contributor

@papertigers papertigers commented Jun 30, 2018

I am recently getting into rust and discovered that tokio wasn't working on illumos. I traced it back to mio but ultimately the issue ended up being this value in the libc crate. It looks like the octal value isn't properly translated to the rust crate as hex. Here's a test program I was using on linux and illumos:

extern crate libc;

#[allow(dead_code)]
const ILLUMOS_EPOLL_CLOEXEC: i32 = 0x80000;

fn find_func() -> usize {
    unsafe { libc::dlsym(libc::RTLD_DEFAULT, "epoll_create1\0".as_ptr() as *const _) as usize }
}

fn main() {
    let addr = find_func();

    #[allow(unused_variables)]
    let hex = format!("{:x}", addr);

    // I think the position changes per run on linux due to something like ASLR
    // so we only test on solaris for this use case
    #[cfg(target_os = "solaris")]
    assert_eq!(hex, "ffffbf7fff226fe0"); // confirmed with addrtosymstr

    unsafe {
        let f = std::mem::transmute::<usize, fn(i32) -> i32>(addr);

        #[cfg(target_os = "linux")]
        let epfd = f(libc::EPOLL_CLOEXEC);

        #[cfg(target_os = "solaris")]
        let epfd = f(ILLUMOS_EPOLL_CLOEXEC);

        println!("call to epoll_create1 returned: {}", epfd);
    }
}

Which outputs the following:

# cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/dlsym`
call to epoll_create1 returned: 3

Edit: typo

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Jun 30, 2018

📌 Commit 2341e6f has been approved by alexcrichton

bors added a commit that referenced this pull request Jun 30, 2018
illumos header translation is wrong 02000000 should be 0x80000

I am recently getting into rust and discovered that tokio wasn't working on illumos.  I traced it back to mio but ultimately the issue ended up being this value in the libc crate.  It looks like the octal value isn't properly translated to the rust crate as hex.  Here's a test program I was using on linux and illumos:

```rust
extern crate libc;

#[allow(dead_code)]
const ILLUMOS_EPOLL_CLOEXEC: i32 = 0x80000;

fn find_func() -> usize {
    unsafe { libc::dlsym(libc::RTLD_DEFAULT, "epoll_create1\0".as_ptr() as *const _) as usize }
}

fn main() {
    let addr = find_func();

    #[allow(unused_variables)]
    let hex = format!("{:x}", addr);

    // I think the position changes per run on linux due to something like ASLR
    // so we only test on solaris for this use case
    #[cfg(target_os = "solaris")]
    assert_eq!(hex, "ffffbf7fff226fe0"); // confirmed with addrtosymstr

    unsafe {
        let f = std::mem::transmute::<usize, fn(i32) -> i32>(addr);

        #[cfg(target_os = "linux")]
        let epfd = f(libc::EPOLL_CLOEXEC);

        #[cfg(target_os = "solaris")]
        let epfd = f(ILLUMOS_EPOLL_CLOEXEC);

        println!("call to epoll_create1 returned: {}", epfd);
    }
}
```

Which outputs the following:

```
# cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/dlsym`
call to epoll_create1 returned: 3
```

Edit: typo
@bors
Copy link
Contributor

bors commented Jun 30, 2018

⌛ Testing commit 2341e6f with merge a9666f6...

@bors
Copy link
Contributor

bors commented Jul 1, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing a9666f6 to master...

@bors bors merged commit 2341e6f into rust-lang:master Jul 1, 2018
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.

4 participants