Skip to content

Commit 5b87a07

Browse files
pm215bonzini
authored andcommitted
hw/char/pl011: Pad PL011State struct to same size as Rust impl
We have some users of the PL011 struct which embed it directly into their own state structs. This means that the Rust version of the device must have a state struct that is the same size or smaller than the C struct. In commit 9b64209 ("rust: pl011: switch to safe chardev operation") the Rust PL011 state struct changed from having a bindings::CharBackend to a chardev::CharBackend, which made it grow larger than the C version. This results in an assertion at startup when QEMU was built with Rust enabled: $ qemu-system-arm -M raspi2b -display none ERROR:../../qom/object.c:562:object_initialize_with_type: assertion failed: (size >= type->instance_size) The long-term better approach to this problem would be to move our C device code patterns away from "embed a struct" and (back) to "have a pointer to the device", so we can make the C PL011State struct a private implementation detail rather than exposed to its users. For the short term, add a padding field at the end of the C struct so it's big enough that the Rust state struct can fit. Fixes: 9b64209 ("rust: pl011: switch to safe chardev operation") Reviewed-by: Zhao Liu <[email protected]> Signed-off-by: Peter Maydell <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 9d116f4 commit 5b87a07

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

include/hw/char/pl011.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ struct PL011State {
5252
Clock *clk;
5353
bool migrate_clk;
5454
const unsigned char *id;
55+
/*
56+
* Since some users embed this struct directly, we must
57+
* ensure that the C struct is at least as big as the Rust one.
58+
*/
59+
uint8_t padding_for_rust[16];
5560
};
5661

5762
DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr);

0 commit comments

Comments
 (0)