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

Switch back to fn() #19

Merged
merged 4 commits into from Feb 12, 2020
Merged

Switch back to fn() #19

merged 4 commits into from Feb 12, 2020

Conversation

mitsuhiko
Copy link
Owner

@mitsuhiko mitsuhiko commented Feb 12, 2020

Going via FnOnce is not really any better than what we did before. Going to to back to fn() for now. Need to figure out that we're not working with any function pointers that are coming from elsewhere separately.

This now also uses findshlibs to locate in which shared library we're doing all this. The downside obviously is that calls are much more expensive now because we need to enumerate all shared libraries around both sides of the call.

Given what the library is supposed to be used for I believe this is a fair enough restriction.

Fixes #18

@mitsuhiko mitsuhiko merged commit de25465 into master Feb 12, 2020
@mitsuhiko mitsuhiko deleted the feature/back-to-fn branch February 12, 2020 20:08
@danielhenrymantilla
Copy link

Ok, just an idea, which needs to be tested:

What about offering a unsafe + macro-based API for performance?

The macro could force a const eval of the function pointer:

#[macro_export]
macro_rules! bikeshed_name_spawn {(
    $fn_pointer:expr
) => ({
    enum ThisFn {}
    impl $crate::TypeLevelConstFn for ThisFn {
        const FN_POINTER: fn() = $fn_pointer;
    }
    $crate::bikeshed_name_spawn_const_fn::<ThisFn>()
})}

#[doc(hidden)]
pub trait TypeLevelConstFn {
    const FN_POINTER: fn();
}

#[doc(hidden)]
pub fn bikeshed_name_spawn_const_fn::<F : TypeLevelConstFn> ()
{
    // can use F::FN_POINTER
    let _: fn() = F::FN_POINTER;
}

or put another way, having the fn pointer be const-promotable would allow defining our own wrapping function that uses it, which could lead to using name-based function resolution rather than address-based, thus totally bypassing things like ASLR.

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.

Zero Sized Closure assumption is Unsound
2 participants