-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Refactor of Qemu configuration #2707
base: main
Are you sure you want to change the base?
Conversation
|
||
#[test] | ||
#[cfg(feature = "usermode")] | ||
fn usermode() { | ||
let program = "/bin/pwd"; | ||
let qemu = Qemu::builder().program("/bin/pwd").build().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doens't the old API look better here? Can't we just keep Qemu::builder() and .build()
then calls Qemu::init_whatever
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, but the thing is that we need to separate the configuration step from the init step, and the builder generated by typed-builder
is not made for this, it's a pain to move around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it's more important to have a good API than to have nice code "on the inside".
This is already what you're using (right?) idanarye/rust-typed-builder#80
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the user's point of view, i think separating configuration from actual initialization is not so bad as well.
it makes more clear what the configuration part is and where qemu is actually getting initialized.
hiding something like qemu initialization in a From
implementation doesn't sound good imho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's really bad for users. We have builders everywhere in the codebase and they all work the same. There's no reason this shoudl work differently. You can still pass around an un-built builder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not migrate all uses of Qemu to Emulator directly? I (as a user) don't get the split between those two
I mean that's probably beyond the scope of this PR...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domenukk the idea of Qemu
is to have a 0-sized object giving a slightly higher-level interface to QEMU (basically making it more convenient to call to QEMU functions and providing a more rusty api), that can only be obtained when QEMU is correctly initialized.
i use this trick a lot to give a Qemu
as parameter for 0 cost.
also (i may be wrong), i think it's nice to let the possibility to use QEMU without all the things in Emulator
and still provide a usable API.
in practice, i think you're right and most people will not want to use Qemu
alone at all. the separation mostly exists to make it simpler to separate things and make it more clear what is specific to QEMU and what is higher-level stuff we introduce. A possible thing we can try is to move Qemu
and QemuHooks
to libafl_qemu_sys
? at least it would remove the confusion between Emulator
and Qemu
for users.
@Marcondiro i thought about this, but i think it will be quite heavy to do in practice because rust-typed-builder
adds up many generics internally that would be difficult to annotate explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not make a builder for emulator instead, and remove qemu from the user-facing APIs then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you're not married to typed_builder if it dropping it makes the API cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QemuConfig
is quite big, not using something like typed_builder
would be a lot of work and make it less maintainable. idk of any other typed builder like this one.
EmulatorBuilder
already exists btw, it's used to set things like the modules, snapshot engine, etc...
QemuConfig
is just a programmatic way to set the cli of QEMU. if we continue to use the derive macro for getting qemu cli from QemuConfig, we need all the fields of the builder to be an option of the QEMU cli, hence the current split.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
* back to one QEMU init function * other small things
* qemu is now a parameter to EmulatorModule callbacks and most function hooks. * EmulatorModules is initialized before QEMU is initialized.
some things we should do at some point:
|
* continue to propagate qemu argument as hook first parameter * use pre_syscall* and post_syscall* everywhere * fix some clippy stuff
…d use the module interface instead. * adapt qemu_launcher example to fully work with emulator, since qemu must now be initialized by emulator.
this pr has an important breaking change: qemu cannot be initialized independently from emulator. if emulator is needed, qemu must be initialized by emulator (before it was possible to initialize qemu and give it to emulator). |
@rmalmain can you merge main? thanks |
Can you write into MIGRATION.md about what you changed in this PR right before you merge this? |
i'm still editing stuff, i'll write when the pr is over |
new proposal for the emulator builder:
opinion @domenukk @Marcondiro ? |
Hey, probably a stupid question, wasn't it enough to add an empty (Also, should we make |
i'm not sure to understand. do you mean QemuBuilder in the original implementation should have returned a
if |
yeah exactly, in the |
hum i don't think we want to do that. it gives access to all the |
Ok got it thanks! If the I think as a user of Sorry if I'm missing something :D |
No description provided.