-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Why are there lifetimes on objects? #145
Comments
I took a look and you are right, I can't see why these types have explicit lifetimes. Perhaps @fabianfreyer can comment? |
I guess the idea in some cases may have been to tie the lifetime to a prerequisite object. Like if you look in frida-gum, the |
I think that that's the right way to go. We should replace |
Another approach here, that I think I prefer because it'll simplify the programming model would be to wrap the Frida object as a process-global singleton and track its references with refcounts. Then any derived object that assumes Frida is live should hold onto one of these owned references. That way it'll become impossible to mess up, and easier to program with because the objects will be static. |
I can live with that. But it would have to be done for both |
What do other Frida bindings do with regards to getting a handle to Frida or gum? |
Looking at this more, gobject is already doing atomic refcounting for us. I think rather than rust having its own refcounts, we should use One thing I can't easily figure out is which APIs are thread safe and which aren't. It looks to me like the gum APIs are all thread safe whereas the Frida-core APIs seem to not be thread-safe, does that seem right? |
I'm realizing I don't know enough to know what makes sense. I see now that |
Our releng repo's devkit.py, which generates the devkits, renames all symbols not prefixed with |
Thanks for the hint! Given that, it seems like we should use the gobject refcounts data types an instance of a gobject, and cloning in rust should increment the refcount of the underlying gobject. The two special cases are the "namespaces" Gum and Frida which aren't objects, but rather are magical handles to ensure the relevant runtime has been initialized. For those, we should have rust-level reference counting. Any rust handle to a gobject pointer then should also hold onto the namespace handle to make sure we don't accidentally deinit too early. How does that sound to folks? |
Sounds great to me! |
Yup sounds good to me too. |
I don't understand the lifetimes on things like
Device
,Injector
etc. They aren't borrowing from a stack, they own the relevant heap allocations make to construct them. The lifetimes can be literally whatever. For example:These lifetimes makes the APIs harder to both use and understand. Is there some purpose they serve, or were they just cargo-culted from the start?
The text was updated successfully, but these errors were encountered: