VirtualBox is not calling my virtual device constructor

Discussions related to using the OSE version of VirtualBox.

VirtualBox is not calling my virtual device constructor

Postby RicV » 25. Aug 2015, 19:06

I am working on a virtual device model for Virtual Box (using 5.0.0 on an Ubuntu 14.04 host). After scouring the UG, this forum, and numerous google hits, I am able to build the model and use VBoxManage setextradata to load it into VirtualBox. I see in VBox.log that my .so file is indeed loaded:

00:00:00.575087 [/PDM/Devices/FauxDevice/] (level 3)
00:00:00.575090 Path <string> = "/usr/vboxtest/FauxDevice.so" (cb=38)


I confirmed that my VBoxDevicesRegister() function is called and executes correctly. The version numbers match, and pCallbacks->pfnRegister() returns VINF_SUCCESS. However, VBox is not calling my device constructor, which is of course provided in the PDMDEVREG struct that I am passing to pCallbacks->pfnRegister(), nor is it calling the destructor BTW. I have compared the details in my PDMDEVREG struct to various other devices included in OSE and also a third party project which appears to be based on the OSE Sample device. I don't see anything missing or different that seems like a plausible reason.

Is there some final step that I am missing, to have VBox call my constructor? I am going to try to log the process to see if I can find any clues, but meanwhile any tips would be greatly appreciated. Thanks in advance.
RicV
 
Posts: 96
Joined: 25. Aug 2015, 17:58
Location: Lake Tahoe, California
Primary OS: Ubuntu other
VBox Version: OSE self-compiled
Guest OSses: Linux *.*, Win*

Re: VirtualBox is not calling my virtual device constructor

Postby noteirak » 26. Aug 2015, 15:56

Moved to the "VirtualBox OSE" forum.
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: VirtualBox is not calling my virtual device constructor

Postby RicV » 2. Sep 2015, 00:04

Ping? Any ideas why my virtual device entry point is able to register my virtual device, apparently successfully, yet VBox does not call my constructor?
RicV
 
Posts: 96
Joined: 25. Aug 2015, 17:58
Location: Lake Tahoe, California
Primary OS: Ubuntu other
VBox Version: OSE self-compiled
Guest OSses: Linux *.*, Win*

Re: VirtualBox is not calling my virtual device constructor

Postby frank » 3. Sep 2015, 16:38

I don't think you will get much help without showing a but more of your code.
frank
Oracle Corporation
 
Posts: 3362
Joined: 7. Jun 2007, 09:11
Location: Dresden, Germany
Primary OS: Debian Sid
VBox Version: PUEL
Guest OSses: Linux, Windows

Re: VirtualBox is not calling my virtual device constructor

Postby RicV » 4. Sep 2015, 02:35

Sure, I can attach my code, such as it is. I've only just started, and so far am just looking at the VBoxDevicesRegister entry point, constructor and destructor. Then I will implement the actual functionality later. I was just assuming it was my procedure that was lacking, more than a code bug.

RicV_FauxDev.cpp
Faux Device source code
(18.18 KiB) Downloaded 31 times


However, now that I've moved from VBox installation to a locally built VBox OSE (in order to debug the problem), the problem has changed.

When using the VBox installation, the VM would start successfully, I would see my VBoxDevicesRegister get called and successfully register my device, but the constructor was never called.

When using my locally built VBox OSE, the VM will not start when my Faux Device is attached with VBoxManage setextradata. I don't understand what's different between installed VBox and VBox OSE in this regard, but it seems from the log that the next step is to track down potential causes of VERR_PDM_NO_REGISTRATION_EXPORT.

Code: Select all   Expand viewCollapse view
000000562 00:00:00.561693 EMT      GIM: KVM: Resetting MSRs
000000563 00:00:00.562617 VMPwrUp  VMSetError: /home/rvilbig/vbox/VirtualBox-5.0.0/src/VBox/VMM/VMMR3/VM.cpp(366) int VMR3Create(uint32_t, PCVMM2USERMETHODS, PFNVMATERROR, void*, PFNCFGMCONSTRUCTOR, void*, VM**, UVM**); rc=VERR_PDM_NO_REGISTRATION_EXPORT
000000563 00:00:00.562625 VMPwrUp  VMSetError: Couldn't find any export for registration of drivers/devices.
000000563 00:00:00.562801 VMPwrUp  ERROR [COM]: aRC=NS_ERROR_FAILURE (0x80004005) aIID={872da645-4a9b-1727-bee2-5585105b9eed} aComponent={ConsoleWrap} aText={Couldn't find any export for registration of drivers/devices. (VERR_PDM_NO_REGISTRATION_EXPORT)}, preserve=false aResultDetail=0
000000563 00:00:00.562929 VMPwrUp  Console: Machine state changed to 'PoweredOff'
000000625 00:00:00.625021 VMPwrUp  Power up failed (vrc=VERR_PDM_NO_REGISTRATION_EXPORT, rc=NS_ERROR_FAILURE (0X80004005))
000000796 00:00:00.796012 main     GUI: UIMachineViewNormal::resendSizeHint: Restoring guest size-hint for screen 0 to 800x600
000000797 00:00:00.797107 main     ERROR [COM]: aRC=E_ACCESSDENIED (0x80070005) aIID={7303a66d-433b-25a4-f9a8-fcadf87e0c2a} aComponent={DisplayWrap} aText={The console is not powered up}, preserve=false aResultDetail=0
RicV
 
Posts: 96
Joined: 25. Aug 2015, 17:58
Location: Lake Tahoe, California
Primary OS: Ubuntu other
VBox Version: OSE self-compiled
Guest OSses: Linux *.*, Win*

Re: VirtualBox is not calling my virtual device constructor

Postby frank » 4. Sep 2015, 11:14

If you get an error code the first step is to grep the source code to find out where this error is generated. VirtualBox uses a huge number of different error codes for the purpose of making it easier to determine where an error condition is generated. In case of VERR_PDM_NO_REGISTRATION_EXPORT you will quickly find out that the device code you are trying to load does not contain a "magic" function named VBoxDevicesRegister. See VMM/VMMR3/PDMDevice.cpp.
frank
Oracle Corporation
 
Posts: 3362
Joined: 7. Jun 2007, 09:11
Location: Dresden, Germany
Primary OS: Debian Sid
VBox Version: PUEL
Guest OSses: Linux, Windows

Re: VirtualBox is not calling my virtual device constructor

Postby RicV » 4. Sep 2015, 17:41

Thanks, Frank. Indeed I do plan to track down the error code in the source. My last post was just the very end of the work day. BTW, my device does actually include the magic VBoxDevicesRegister function, as shown in the code I attached. And when loaded into the installed VBox that function is actually called, though VBox does not subsequently call my constructor. It's just the VBox OSE build that is erroring out and not calling my magic function.
RicV
 
Posts: 96
Joined: 25. Aug 2015, 17:58
Location: Lake Tahoe, California
Primary OS: Ubuntu other
VBox Version: OSE self-compiled
Guest OSses: Linux *.*, Win*

Re: VirtualBox is not calling my virtual device constructor

Postby RicV » 4. Sep 2015, 21:42

OK, so the problem I posted last night about VBox OSE behaving differently than installed VBox, and generating the VERR_PDM_NO_REGISTRATION_EXPORT error, was a cockpit error on my part. I had a mistake in my Makefile.

Now that's resolved, VBox OSE behaves the same as installed VBox, and I'm back to the original problem report. VBox loads my device .so library, it calls my magic VBoxDevicesRegister() function which successfully registers my device. However VBox never calls the constructor that I provide in the registration struct.
RicV
 
Posts: 96
Joined: 25. Aug 2015, 17:58
Location: Lake Tahoe, California
Primary OS: Ubuntu other
VBox Version: OSE self-compiled
Guest OSses: Linux *.*, Win*

Re: VirtualBox is not calling my virtual device constructor

Postby RicV » 17. Sep 2015, 03:23

I have been pursuing this off and on, and learning about the CFGMR3 tree in the process. I found that pdmR3DevInit() only instantiates devices below //root/Devices, whereas my device is below //root/PDM/Devices. My device wound up there because of the way I added it, with this command, based on other posts in the VBox forum.

Code: Select all   Expand viewCollapse view
VBoxManage setextradata My_VM VBoxInternal/PDM/Devices/<DeviceName>/Path <path/><device>.so


By changing it to the following, I moved my device to //root/Devices and now VBox is at least trying to instantiate my device.

Code: Select all   Expand viewCollapse view
VBoxManage setextradata My_VM VBoxInternal/Devices/<DeviceName>/Path <path/><device>.so


Now that it's at least trying to instantiate my device, the next step seems to be debugging why it's failing. But am I on the right track with moving the device like that?
RicV
 
Posts: 96
Joined: 25. Aug 2015, 17:58
Location: Lake Tahoe, California
Primary OS: Ubuntu other
VBox Version: OSE self-compiled
Guest OSses: Linux *.*, Win*

Re: VirtualBox is not calling my virtual device constructor

Postby RicV » 23. Sep 2015, 03:05

I was finally able to sort this out, after some digging in the VBox PDM device registration and instantiation code. For the sake of anyone else who may be watching or someday stumble onto this thread, here is what I had to do.

1. As mentioned earlier in this thread (and others), you need to add the device and path to the shared library which implements the virtual device with a command such as follows. Note that the devlib.so library must be owned by root.

Code: Select all   Expand viewCollapse view
VBoxManage setextradata "My VM" VBoxInternal/PDM/Devices/<DeviceName>/Path    </path/devlib.so>


2. What I did not know was that to instantiate the device during VM startup, you must also add another entry for each instance of the device, in another part of the CFGMR3 tree. I am not sure the following is the best or even right way to do that, but it seems to work. The DeviceName must match in both places for them to be associated; the 0 is the device instance. 'Anything' really (apparently) can be anything.

Code: Select all   Expand viewCollapse view
VBoxManage setextradata "My VM" VBoxInternal/Devices/<DeviceName>/0/anything  Anything


After loading my device (due to the first entry), and instantiating it (due to the second), VBox is now calling my constructor, thereby solving the original problem raised in this thread.
RicV
 
Posts: 96
Joined: 25. Aug 2015, 17:58
Location: Lake Tahoe, California
Primary OS: Ubuntu other
VBox Version: OSE self-compiled
Guest OSses: Linux *.*, Win*


Return to VirtualBox OSE

Who is online

Users browsing this forum: No registered users and 2 guests