|
From: | Alyosha Shevandin |
Subject: | Re: Crash in memory_region_init_ram call chain, when --bios command line parameter is presented. |
Date: | Sun, 19 Feb 2023 10:45:44 +0000 |
Thank you again. Your answer gave me some clues about what is wrong in my code. Actually almost everything was wrong. I misunderstand of how QOM and its macros work. I had defined MySocState so that it included MachineState (it had a field obj_parent of type of MachineState). I had assumed that caller of the init procedure will allocate MySocState object and pass the pointer to the initialization procedure. Which was not the case. MachineState object is allocated with parent_object→class→type→name set to “TYPE_MY_SOC””machine” (since there is a definition DEFINE_MACHINE(TYPE_MY_SOC, my_machine_init) ). So actually, the problem was in the line MySocState* state = OBJECT_CHECK(MySocState, machine, TYPE_MY_SOC); It converted the pointer to the MachineState object to the unrelated MySocState*, the result was the misaligned invalid object. Therefore the specific operations that relate its’ fields cause segfault. I can not understand why it didn’t assert at OBJECT_CHECK Now I had provided a separate initialization code for MySocState and construct this object in the machine initialization procedure.
Regards, Aleksey מאת: Peter Maydell <peter.maydell@linaro.org>
נשלח: יום שלישי 14 פברואר 2023 16:17 אל: Alyosha Shevandin <shevandin_al@hotmail.com> עותק: qemu-discuss@nongnu.org <qemu-discuss@nongnu.org> נושא: Re: Crash in memory_region_init_ram call chain, when --bios command line parameter is presented. On Tue, 14 Feb 2023 at 11:54, Alyosha Shevandin
<shevandin_al@hotmail.com> wrote: > > Thank you for your answer. I belive that 'owner' parameter is initialized: 1) without --bios parameter the code does not crash; 2) I check the the owner parameter before; > Here is the fragment of my code: > > static void my_soc_init(MachineState *machine) > { > > MySocState* state = OBJECT_CHECK(MySocState, machine, TYPE_MY_SOC); This looks very confused. Generally in QEMU the 'board' (inherits from MachineState) is a different object from the SoC (inherits from DeviceState). This code seems to think they are the same thing. > if (!state) { > error_report("failed to convert from the parent MachineState to derived MySocState"); > exit(1); > } > > /* > * Setup the memories. > */ > memory_region_init_ram(&state->ram, > OBJECT(state), > "mysoc.ram", > mysoc_memmap[MYSOCK_DEV_RAM].size, > &error_abort); The 'owner' argument to memory_region_init_ram() must be either NULL or something that inherits from DeviceState. We use the former for memory regions created by boards, and the latter for memory regions created by SoC models. The (cast) MachineState object you are passing is neither, so you end up with an assertion when the code tries to do something to it that only works with a DeviceState. (I'm not sure why this didn't assert in memory_region_init_ram() when it does the DEVICE() cast on the owner pointer.) thanks -- PMM |
[Prev in Thread] | Current Thread | [Next in Thread] |