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

Add TypeRefCreator trait #2065

Merged
merged 33 commits into from
Apr 23, 2024
Merged

Add TypeRefCreator trait #2065

merged 33 commits into from
Apr 23, 2024

Conversation

tokatoka
Copy link
Member

No description provided.

@tokatoka
Copy link
Member Author

like this? @addisoncrump

@tokatoka
Copy link
Member Author

i didn't implement it for all the struct but just implemented for what is needed now

@domenukk
Copy link
Member

I would do a get(&ref) and have the ref take the name as well.
Also, this again isn't a Has, it should just be impl TypeRef I think

@tokatoka tokatoka changed the title HasTypeRef Add TypeRefCreator trait Apr 17, 2024
@addisoncrump
Copy link
Collaborator

Can I modify this @tokatoka? There's a nicer way to do this that requires fewer modifications

@tokatoka
Copy link
Member Author

yes

@addisoncrump
Copy link
Collaborator

Now it should just automagically work for all types that get entered into tuples and searched by match_name.

@tokatoka
Copy link
Member Author

great 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

deleted

Copy link
Collaborator

Choose a reason for hiding this comment

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

😂 Just messing with you. We should probably gitignore these.

Copy link
Member Author

Choose a reason for hiding this comment

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

but how do we check if it's executable

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I mean these exact file names. You just did cargo make or something, right?

@domenukk
Copy link
Member

domenukk commented Apr 17, 2024

How about calling the guy Referencable? It gives the struct the trait that it can be referenced

@domenukk
Copy link
Member

Also, as mentioned before, I think the ref should directly contain the name, So a real Reference instead of a TypeRef

@tokatoka
Copy link
Member Author

@addisoncrump
can you do the CoW stuff?
I don't know what your desired change is

@addisoncrump
Copy link
Collaborator

Sure thing.

@addisoncrump
Copy link
Collaborator

Note that the Named trait now requires alloc. This is to allow for avoiding a clone whenever using Named, but maybe this is not a reasonable change.

@tokatoka
Copy link
Member Author

this is ready?

orig_hash: u64,
phantom: PhantomData<(M, S)>,
}

impl<M, S> MapEqualityFeedback<M, S> {
Copy link
Member Author

Choose a reason for hiding this comment

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

this guy got deleted for mistake?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope, not accidental -- this one should not be publicly exposed.

@addisoncrump
Copy link
Collaborator

@tokatoka It's not ready, no, I'm working through CI fixes.

@@ -524,6 +526,47 @@ where
}
}

/// Structs that has `TypeRef`
/// You should use this when you want to avoid specifying types using `match_name_type_mut`
pub trait TypeRefCreator {
Copy link
Member

Choose a reason for hiding this comment

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

Referenceable?

@tokatoka
Copy link
Member Author

can you finish this @addisoncrump
or i shoud just fix them?

@tokatoka
Copy link
Member Author

then alloc shouldn't be a feature anymore?
because what can we do without a name now??

@tokatoka
Copy link
Member Author

@domenukk

I think the ref should directly contain the name, So a real Reference instead of a TypeRef

This makes it hard to use.

For example if we do like this

#[derive(Debug, Clone, Copy)]
#[cfg(feature = "alloc")]
pub struct TypeRef<'a, T: ?Sized> {
    name: &'a Cow<'static, str>,
    phantom: PhantomData<T>,
}

Then this code from forkserver_libafl_cc won't compile

    let observer_ref = edges_observer.type_ref();

    let mut tokens = Tokens::new();
    let mut executor = ForkserverExecutor::builder()
        .program(opt.executable)
        .debug_child(debug_child)
        .shmem_provider(&mut shmem_provider)
        .autotokens(&mut tokens)
        .parse_afl_cmdline(args)
        .coverage_map_size(MAP_SIZE)
        .timeout(Duration::from_millis(opt.timeout))
        .kill_signal(opt.signal)
        .build(tuple_list!(time_observer, edges_observer))
        .unwrap();

    if let Some(dynamic_map_size) = executor.coverage_map_size() {
        executor
            .observers_mut()
            .match_by_ref_mut(observer_ref)
            .unwrap()
            .as_mut()
            .truncate(dynamic_map_size);
    }

because edges_observer is moved to the executor then we can't use observer_ref later in match_by_ref_mut()

@addisoncrump
Copy link
Collaborator

addisoncrump commented Apr 23, 2024

@tokatoka in that case, you can clone the Cow and only if necessary will it create a memory reference. It can be safely held without reference to the original observer.

#[derive(Debug, Clone)]
#[cfg(feature = "alloc")]
pub struct TypeRef<T: ?Sized> {
    name: Cow<'static, str>,
    phantom: PhantomData<T>,
}

@addisoncrump
Copy link
Collaborator

And yes, please finish this without me, I am currently rushing a paper submission 😵‍💫

@tokatoka tokatoka merged commit 1766598 into main Apr 23, 2024
102 checks passed
@tokatoka tokatoka deleted the poc branch April 23, 2024 17:03
#[cfg(feature = "alloc")]
pub trait Referenceable: Named {
/// Return the `ReReference `
fn type_ref(&self) -> ReReference<Self> {
Copy link
Member

Choose a reason for hiding this comment

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

ReReference? :D

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