From a42a5995cff3e503a4b23cc9abf24415b8693e88 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Fri, 23 May 2014 09:26:57 +0200 Subject: [PATCH] vbox: enable guest additions Fixes #1157 --- repos/ports/include/vmm/printf.h | 2 +- .../import/import-virtualbox_libc_support.mk | 1 - repos/ports/lib/mk/virtualbox-common.inc | 3 +- repos/ports/lib/mk/virtualbox-devices.mk | 3 +- repos/ports/lib/mk/virtualbox-runtime.mk | 19 ++- .../ports/lib/mk/virtualbox_libc_support.inc | 85 ------------ .../lib/mk/x86_32/virtualbox_libc_support.mk | 7 - .../lib/mk/x86_64/virtualbox_libc_support.mk | 7 - repos/ports/ports/virtualbox.port | 4 +- repos/ports/run/virtualbox.run | 20 ++- repos/ports/run/virtualbox_auto.inc | 26 ++-- repos/ports/run/virtualbox_auto_disk.run | 2 +- repos/ports/src/virtualbox/dummies.cc | 36 ++--- repos/ports/src/virtualbox/dynlib.cc | 76 +++++++++++ .../src/virtualbox/fake_pci_vendor.patch | 12 +- repos/ports/src/virtualbox/hgcm_sync.patch | 34 +++++ repos/ports/src/virtualbox/iconv.patch | 17 +++ .../ports/src/virtualbox/include/SDLConsole.h | 2 +- repos/ports/src/virtualbox/ioport.cc | 26 +++- repos/ports/src/virtualbox/libc.cc | 40 ++++++ repos/ports/src/virtualbox/main.cc | 125 ++++++++++-------- repos/ports/src/virtualbox/nova/sup.cc | 10 +- repos/ports/src/virtualbox/nova/vcpu.h | 88 ++++++------ repos/ports/src/virtualbox/nova/vcpu_svm.h | 12 +- repos/ports/src/virtualbox/nova/vcpu_vmx.h | 13 +- repos/ports/src/virtualbox/pgm.cc | 84 ++++++++---- repos/ports/src/virtualbox/rt.cc | 27 +--- repos/ports/src/virtualbox/rtc.patch | 9 ++ repos/ports/src/virtualbox/sharedfolder.patch | 12 ++ repos/ports/src/virtualbox/sup.cc | 108 +++++++++------ repos/ports/src/virtualbox/sup.h | 3 + repos/ports/src/virtualbox/target.mk | 17 ++- repos/ports/src/virtualbox/thread.cc | 42 +++++- .../src/virtualbox/time-log-deadlock.patch | 11 ++ repos/ports/src/virtualbox/vboxbfe.patch | 34 ----- repos/ports/src/virtualbox/vmm_memory.h | 22 --- repos/ports/src/virtualbox/vmmdev.patch | 17 ++- 37 files changed, 632 insertions(+), 424 deletions(-) delete mode 100644 repos/ports/lib/import/import-virtualbox_libc_support.mk delete mode 100644 repos/ports/lib/mk/virtualbox_libc_support.inc delete mode 100644 repos/ports/lib/mk/x86_32/virtualbox_libc_support.mk delete mode 100644 repos/ports/lib/mk/x86_64/virtualbox_libc_support.mk create mode 100644 repos/ports/src/virtualbox/dynlib.cc create mode 100644 repos/ports/src/virtualbox/hgcm_sync.patch create mode 100644 repos/ports/src/virtualbox/iconv.patch create mode 100644 repos/ports/src/virtualbox/rtc.patch create mode 100644 repos/ports/src/virtualbox/sharedfolder.patch create mode 100644 repos/ports/src/virtualbox/time-log-deadlock.patch diff --git a/repos/ports/include/vmm/printf.h b/repos/ports/include/vmm/printf.h index 5f3443290..f7ec54e9b 100644 --- a/repos/ports/include/vmm/printf.h +++ b/repos/ports/include/vmm/printf.h @@ -30,7 +30,7 @@ namespace Vmm { /** * Print message while preserving the UTCB content */ -void Vmm::printf(const char *format, ...) +inline void Vmm::printf(const char *format, ...) { va_list list; va_start(list, format); diff --git a/repos/ports/lib/import/import-virtualbox_libc_support.mk b/repos/ports/lib/import/import-virtualbox_libc_support.mk deleted file mode 100644 index 6981d3ed5..000000000 --- a/repos/ports/lib/import/import-virtualbox_libc_support.mk +++ /dev/null @@ -1 +0,0 @@ -include $(call select_from_repositories,lib/import/import-libc.mk) diff --git a/repos/ports/lib/mk/virtualbox-common.inc b/repos/ports/lib/mk/virtualbox-common.inc index 65ecfb377..60f46b6b1 100644 --- a/repos/ports/lib/mk/virtualbox-common.inc +++ b/repos/ports/lib/mk/virtualbox-common.inc @@ -28,6 +28,7 @@ VBOX_CC_OPT += -DIN_SUP_R3 -DIN_VMM_R3 VBOX_CC_OPT += -DRT_OS_FREEBSD VBOX_CC_OPT += -DVBOX_WITH_REM +VBOX_CC_OPT += -DVBOX_WITH_HGCM -DVBOX_WITH_HGSMI VBOX_CC_OPT += -DVBOXBFE_WITHOUT_COM VBOX_CC_OPT += -DVBOX_WITHOUT_TESTING_FEATURES @@ -52,7 +53,7 @@ CC_WARN += -Wno-trigraphs CC_OPT += $(VBOX_CC_OPT) -LIBS += virtualbox_libc_support +LIBS += libc libm INC_DIR += $(REP_DIR)/src/virtualbox/include INC_DIR += $(VIRTUALBOX_DIR)/include diff --git a/repos/ports/lib/mk/virtualbox-devices.mk b/repos/ports/lib/mk/virtualbox-devices.mk index 44182648a..616bfe9e8 100644 --- a/repos/ports/lib/mk/virtualbox-devices.mk +++ b/repos/ports/lib/mk/virtualbox-devices.mk @@ -25,6 +25,7 @@ SRC_CC += Devices/Storage/fdc.c SRC_CC += Devices/Storage/DrvRawImage.cpp SRC_CC += Devices/Network/DevPCNet.cpp SRC_CC += Devices/VMMDev/VMMDev.cpp +SRC_CC += Devices/VMMDev/VMMDevHGCM.cpp SRC_CC += GuestHost/HGSMI/HGSMICommon.cpp SRC_CC += Devices/Serial/DevSerial.cpp SRC_CC += Devices/PC/DevIoApic.cpp @@ -42,7 +43,7 @@ CC_WARN += -Wno-unused-but-set-variable # VGASTATE::lock member would violate the assertion # '!((uintptr_t)pvSample & 7)' in 'stamR3RegisterU'. # -CC_OPT += -DVBOX_WITH_HGSMI -DVBOX_WITH_WDDM -DVBOX_WITH_VDMA +CC_OPT += -DVBOX_WITH_WDDM -DVBOX_WITH_VDMA Devices/Graphics/DevVGA.o: vbetables.h diff --git a/repos/ports/lib/mk/virtualbox-runtime.mk b/repos/ports/lib/mk/virtualbox-runtime.mk index 9b250869a..239d852bf 100644 --- a/repos/ports/lib/mk/virtualbox-runtime.mk +++ b/repos/ports/lib/mk/virtualbox-runtime.mk @@ -4,6 +4,7 @@ INC_DIR += $(VBOX_DIR)/Runtime/include INC_DIR += $(VIRTUALBOX_DIR)/src/libs/liblzf-3.4 INC_DIR += $(VIRTUALBOX_DIR)/src/libs/zlib-1.2.6 +INC_DIR += $(call select_from_ports,libiconv)/include/iconv GENERIC_SRC_CC = $(notdir $(wildcard $(VBOX_DIR)/Runtime/generic/*.cpp)) @@ -20,7 +21,8 @@ FILTERED_OUT_SRC_CC = RTLogDefaultInit-generic.cpp \ RTSemEventWaitNoResume-2-ex-generic.cpp \ RTFileExists-generic.cpp \ RTSemMutexRequest-generic.cpp \ - RTSemMutexRequestDebug-generic.cpp + RTSemMutexRequestDebug-generic.cpp \ + RTDirExists-generic.cpp CC_WARN += -Wno-unused-variable @@ -31,6 +33,7 @@ SRC_CC += Runtime/common/log/logrel.cpp \ SRC_CC += Runtime/common/err/RTErrConvertFromErrno.cpp SRC_CC += Runtime/common/alloc/memcache.cpp +SRC_CC += Runtime/common/alloc/heapoffset.cpp SRC_CC += Runtime/common/checksum/md5.cpp SRC_CC += Runtime/common/log/log.cpp SRC_CC += Runtime/common/log/log.cpp @@ -48,14 +51,18 @@ SRC_CC += Runtime/common/misc/RTAssertMsg2AddWeakV.cpp SRC_CC += Runtime/common/misc/RTAssertMsg2Weak.cpp SRC_CC += Runtime/common/misc/RTAssertMsg2WeakV.cpp SRC_CC += Runtime/common/path/RTPathAbsDup.cpp +SRC_CC += Runtime/common/path/RTPathAbsEx.cpp SRC_CC += Runtime/common/path/RTPathCalcRelative.cpp SRC_CC += Runtime/common/path/RTPathExt.cpp SRC_CC += Runtime/common/path/RTPathFilename.cpp +SRC_CC += Runtime/common/path/RTPathHasPath.cpp SRC_CC += Runtime/common/path/RTPathJoinA.cpp SRC_CC += Runtime/common/path/RTPathParse.cpp +SRC_CC += Runtime/common/path/RTPathRealDup.cpp SRC_CC += Runtime/common/path/RTPathStripExt.cpp SRC_CC += Runtime/common/path/RTPathStripFilename.cpp SRC_CC += Runtime/common/path/RTPathStripTrailingSlash.cpp +SRC_CC += Runtime/common/path/rtPathVolumeSpecLen.cpp SRC_CC += Runtime/common/rand/rand.cpp SRC_CC += Runtime/common/rand/randadv.cpp SRC_CC += Runtime/common/rand/randparkmiller.cpp @@ -82,16 +89,25 @@ SRC_CC += Runtime/common/string/utf-8.cpp SRC_CC += Runtime/common/table/avlpv.cpp SRC_CC += Runtime/common/table/avlroioport.cpp SRC_CC += Runtime/common/table/avlrogcphys.cpp +SRC_CC += Runtime/common/table/avlul.cpp SRC_CC += Runtime/common/time/time.cpp SRC_CC += Runtime/common/time/timeprog.cpp SRC_CC += Runtime/common/time/timesup.cpp SRC_CC += Runtime/common/time/timesupref.cpp SRC_CC += Runtime/r3/alloc.cpp +SRC_CC += Runtime/r3/dir.cpp SRC_CC += Runtime/r3/fileio.cpp +SRC_CC += Runtime/r3/fs.cpp SRC_CC += Runtime/r3/path.cpp SRC_CC += Runtime/r3/generic/semspinmutex-r3-generic.cpp +SRC_CC += Runtime/r3/posix/dir-posix.cpp SRC_CC += Runtime/r3/posix/env-posix.cpp SRC_CC += Runtime/r3/posix/fileio-posix.cpp +SRC_CC += Runtime/r3/posix/fileio2-posix.cpp +SRC_CC += Runtime/r3/posix/fs2-posix.cpp +SRC_CC += Runtime/r3/posix/fs3-posix.cpp +SRC_CC += Runtime/r3/posix/path-posix.cpp +SRC_CC += Runtime/r3/posix/path2-posix.cpp SRC_CC += Runtime/r3/posix/pipe-posix.cpp SRC_CC += Runtime/r3/posix/poll-posix.cpp SRC_CC += Runtime/r3/posix/RTTimeNow-posix.cpp @@ -102,6 +118,7 @@ SRC_CC += Runtime/r3/posix/thread2-posix.cpp SRC_CC += Runtime/r3/posix/thread-posix.cpp SRC_CC += Runtime/r3/posix/time-posix.cpp SRC_CC += Runtime/r3/posix/tls-posix.cpp +SRC_CC += Runtime/r3/posix/utf8-posix.cpp SRC_CC += Runtime/r3/process.cpp SRC_CC += Runtime/r3/stream.cpp SRC_CC += Runtime/VBox/log-vbox.cpp diff --git a/repos/ports/lib/mk/virtualbox_libc_support.inc b/repos/ports/lib/mk/virtualbox_libc_support.inc deleted file mode 100644 index 24d7068a4..000000000 --- a/repos/ports/lib/mk/virtualbox_libc_support.inc +++ /dev/null @@ -1,85 +0,0 @@ -# FreeBSD libc code -SRC_C += gen/ldexp.c -SRC_C += gen/usleep.c -SRC_C += stdio/ferror.c -SRC_C += stdio/fflush.c -SRC_C += stdio/fileno.c -SRC_C += stdio/findfp.c -SRC_C += stdio/stdio.c -SRC_C += string/memchr.c -SRC_C += string/strncmp.c -SRC_C += string/strdup.c - -# Genode libc code -SRC_CC += libc/clock_gettime.cc -SRC_CC += libc/nanosleep.cc -SRC_CC += libc/file_operations.cc -SRC_CC += libc/plugin_registry.cc -SRC_CC += libc/fd_alloc.cc -SRC_CC += libc/libc_mem_alloc.cc -SRC_CC += libc/gettimeofday.cc -SRC_CC += libc/plugin.cc -SRC_CC += libc/select.cc - -# Genode terminal plugin -SRC_CC += libc_terminal/plugin.cc - -# Genode vfs plugin -SRC_CC += libc/vfs_plugin.cc -SRC_CC += libc/pread_pwrite.cc - -# Genode lock pipe plugin (needed by VirtualBox "HostSerial" driver) -SRC_CC += libc_lock_pipe/plugin.cc - -# Genode pthread code -SRC_CC += pthread/semaphore.cc -SRC_CC += pthread/thread.cc -LIBS += timed_semaphore - -# setjmp/longjmp needed by recompiler -LIBS += libc-setjmp - -INC_DIR += $(LIBC_REP_DIR)/src/lib/libc - -vpath %.cc $(LIBC_REP_DIR)/src/lib - -# FreeBSD libc FPU math -FPU_SRC_C = $(wildcard $(LIBC_DIR)/lib/msun/src/*.c) \ - $(wildcard $(LIBC_DIR)/lib/msun/ld80/*.c) \ - $(wildcard $(LIBC_DIR)/lib/msun/bsdsrc/*.c) -SRC_C += $(filter-out e_rem_pio2.c e_rem_pio2f.c s_exp2l.c, $(notdir $(FPU_SRC_C))) - -vpath %.c $(LIBC_DIR)/lib/msun/src -vpath %.c $(LIBC_DIR)/lib/msun/ld80 -vpath %.c $(LIBC_DIR)/lib/msun/bsdsrc - -# Disable warnings for selected files, i.e., to suppress -# 'is static but used in inline function which is not static' -# messages -CC_OPT_s_tanf = -w -CC_OPT_s_tan = -w -CC_OPT_s_sin = -w -CC_OPT_s_cos = -w -CC_OPT_s_cosf = -w -CC_OPT_s_sinf = -w -CC_OPT_k_cosf = -w -CC_OPT_k_sinf = -w -CC_OPT_k_tanf = -w - -# Work-around to get over doubly defined symbols produced by several sources -# that include 'e_rem_pio2.c' and 'e_rem_pio2f.c'. To avoid symbol clashes, -# we rename each occurrence by adding the basename of the compilation unit -# as suffix. (copied from libm.mk) -CC_OPT_s_sin += -D__ieee754_rem_pio2=__ieee754_rem_pio2_s_sin -CC_OPT_s_cos += -D__ieee754_rem_pio2=__ieee754_rem_pio2_s_cos -CC_OPT_s_tan += -D__ieee754_rem_pio2=__ieee754_rem_pio2_s_tan -CC_OPT_s_sinf += -D__ieee754_rem_pio2f=__ieee754_rem_pio2f_s_sinf -CC_OPT_s_sinf += -D__kernel_cosdf=__kernel_cosdf_sinf -CC_OPT_s_cosf += -D__ieee754_rem_pio2f=__ieee754_rem_pio2f_s_cosf -CC_OPT_s_cosf += -D__kernel_sindf=__kernel_sindf_cosf -CC_OPT_s_tanf += -D__ieee754_rem_pio2f=__ieee754_rem_pio2f_s_tanf - -CC_OPT += -D__inline=inline -INC_DIR += $(addprefix $(LIBC_DIR)/lib/msun/,src ld80 bsdsrc) - -# vi: set ft=make : diff --git a/repos/ports/lib/mk/x86_32/virtualbox_libc_support.mk b/repos/ports/lib/mk/x86_32/virtualbox_libc_support.mk deleted file mode 100644 index 9eefd509d..000000000 --- a/repos/ports/lib/mk/x86_32/virtualbox_libc_support.mk +++ /dev/null @@ -1,7 +0,0 @@ -include $(REP_DIR)/lib/mk/seoul_libc_support.mk - -SRC_C += fenv.c - -vpath fenv.c $(LIBC_DIR)/lib/msun/i387 - -include $(REP_DIR)/lib/mk/virtualbox_libc_support.inc diff --git a/repos/ports/lib/mk/x86_64/virtualbox_libc_support.mk b/repos/ports/lib/mk/x86_64/virtualbox_libc_support.mk deleted file mode 100644 index 977957703..000000000 --- a/repos/ports/lib/mk/x86_64/virtualbox_libc_support.mk +++ /dev/null @@ -1,7 +0,0 @@ -include $(REP_DIR)/lib/mk/seoul_libc_support.mk - -SRC_C += fenv.c - -vpath fenv.c $(LIBC_DIR)/lib/msun/amd64 - -include $(REP_DIR)/lib/mk/virtualbox_libc_support.inc diff --git a/repos/ports/ports/virtualbox.port b/repos/ports/ports/virtualbox.port index feabc5cb8..992b94550 100644 --- a/repos/ports/ports/virtualbox.port +++ b/repos/ports/ports/virtualbox.port @@ -17,6 +17,7 @@ VIRTUALBOX_CONTENT = src/VBox/VMM \ src/VBox/Frontends/VBoxBFE \ src/VBox/Storage \ src/VBox/Disassembler \ + src/VBox/HostServices/SharedFolders \ src/recompiler \ src/VBox/Main/include/MouseImpl.h \ src/VBox/Main/include/ConsoleEvents.h \ @@ -31,7 +32,8 @@ VIRTUALBOX_CONTENT = src/VBox/VMM \ ostypes.h VMMDev.h VMMDev2.h \ vusb.h dbg.h version.h \ VBoxVideo.h Hardware bioslogo.h \ - scsi.h HGSMI) \ + scsi.h shflsvc.h VBoxGuest2.h \ + HGSMI) \ include/VBox/msi.h \ include/VBox/DevPCNet.h \ include/VBox/asmdefs.mac \ diff --git a/repos/ports/run/virtualbox.run b/repos/ports/run/virtualbox.run index dc6c91cb0..b345fadb4 100644 --- a/repos/ports/run/virtualbox.run +++ b/repos/ports/run/virtualbox.run @@ -7,6 +7,7 @@ set build_components { lappend_if [have_spec acpi] build_components drivers/acpi lappend_if [have_spec pci] build_components drivers/pci +lappend_if [have_spec x86] build_components drivers/rtc build $build_components @@ -28,7 +29,7 @@ set config { - + @@ -53,13 +54,13 @@ append_if [expr ![have_spec acpi] && [have_spec pci]] config { - } + } append_if [have_spec ps2] config { - } + } append_if [have_spec framebuffer] config { @@ -76,6 +77,14 @@ append_if [have_spec sdl] config { } +append_if [have_spec x86] config { + + + + + + } + append config { @@ -103,6 +112,11 @@ lappend_if [have_spec pci] boot_modules pci_drv lappend_if [have_spec framebuffer] boot_modules fb_drv lappend_if [have_spec linux] boot_modules fb_sdl lappend_if [have_spec nova] boot_modules pci_device_pd +lappend_if [have_spec x86] boot_modules rtc_drv + +append boot_modules { ld.lib.so libc.lib.so libm.lib.so pthread.lib.so + libc_lock_pipe.lib.so libc_terminal.lib.so + libiconv.lib.so } build_boot_image $boot_modules diff --git a/repos/ports/run/virtualbox_auto.inc b/repos/ports/run/virtualbox_auto.inc index e982af196..14a77fe14 100644 --- a/repos/ports/run/virtualbox_auto.inc +++ b/repos/ports/run/virtualbox_auto.inc @@ -17,6 +17,7 @@ set build_components { lappend_if [have_spec acpi] build_components drivers/acpi lappend_if [have_spec pci] build_components drivers/pci +lappend_if [have_spec x86] build_components drivers/rtc build $build_components @@ -38,7 +39,7 @@ set config { - + @@ -70,8 +71,7 @@ set config { - -} + } append_if [have_spec acpi] config { @@ -91,13 +91,13 @@ append_if [expr ![have_spec acpi] && [have_spec pci]] config { - } + } append_if [have_spec ps2] config { - } + } append_if [have_spec framebuffer] config { @@ -106,6 +106,14 @@ append_if [have_spec framebuffer] config { } +append_if [have_spec x86] config { + + + + + + } + append config $config_of_app append config { @@ -117,7 +125,9 @@ install_config $config set boot_modules { core init timer part_blk ahci - ld.lib.so libc.lib.so + ld.lib.so libc.lib.so libm.lib.so pthread.lib.so + libc_lock_pipe.lib.so libc_terminal.lib.so + libiconv.lib.so rump.lib.so rump_fs.lib.so rump_fs virtualbox vbox-auto-test-helper } @@ -158,8 +168,6 @@ lappend_if [have_spec acpi] boot_modules acpi_drv lappend_if [have_spec pci] boot_modules pci_drv lappend_if [have_spec framebuffer] boot_modules fb_drv lappend_if [have_spec nova] boot_modules pci_device_pd +lappend_if [have_spec x86] boot_modules rtc_drv build_boot_image $boot_modules - -append qemu_args " -m 1512 " -append qemu_args " -cpu phenom " diff --git a/repos/ports/run/virtualbox_auto_disk.run b/repos/ports/run/virtualbox_auto_disk.run index 22ff7a131..a09eec574 100644 --- a/repos/ports/run/virtualbox_auto_disk.run +++ b/repos/ports/run/virtualbox_auto_disk.run @@ -63,7 +63,7 @@ source ${genode_dir}/repos/ports/run/virtualbox_auto.inc run_genode_until "ignore resize request to 720x400" 20 -run_genode_until "ignore resize request to 640x480" 15 $spawn_id +run_genode_until "ignore resize request to 640x480" 25 $spawn_id run_genode_until "ignore resize request to 800x600" 35 $spawn_id run_genode_until "ignore resize request to 800x600" 90 $spawn_id run_genode_until "ignore resize request to 720x400" 10 $spawn_id diff --git a/repos/ports/src/virtualbox/dummies.cc b/repos/ports/src/virtualbox/dummies.cc index aa0261b53..c08bec294 100644 --- a/repos/ports/src/virtualbox/dummies.cc +++ b/repos/ports/src/virtualbox/dummies.cc @@ -51,7 +51,7 @@ CHECKED_DUMMY( 0, vmmR3SwitcherInit) /* world switcher */ CHECKED_DUMMY(-1, atexit) CHECKED_DUMMY(-1, getpid) CHECKED_DUMMY(-1, pdmR3FileR3) -CHECKED_DUMMY(-1, setlocale) +CHECKED_DUMMY(0, setlocale) CHECKED_DUMMY(-1, sigaddset) CHECKED_DUMMY(-1, sigemptyset) CHECKED_DUMMY(-1, siginterrupt) @@ -127,7 +127,6 @@ CHECKED_DUMMY( 0, PGMR3InitFinalize) DUMMY(-1, PGMR3SharedModuleCheckAll) DUMMY(-1, PGMR3SharedModuleUnregister) DUMMY(-1, PGMR3SharedModuleRegister) -DUMMY(-1, PGMR3MappingsSize) DUMMY(-1, PGMR3MappingsUnfix) DUMMY(-1, PGMR3PhysChangeMemBalloon) DUMMY(-1, PGMR3MappingsFix) @@ -161,19 +160,14 @@ DUMMY(-1, PGMGetShadowMode) DUMMY(-1, PGMGetHostMode) CHECKED_DUMMY(0, poll) /* needed by 'DrvHostSerial.cpp' */ -DUMMY(-1, printf) DUMMY(-1, pthread_key_delete) -DUMMY(-1, reallocf) DUMMY(-1, RTCrc32); DUMMY(-1, RTCrc32Start) DUMMY(-1, RTCrc32Finish) DUMMY(-1, RTCrc32Process) DUMMY(-1, RTMemExecFree) DUMMY(-1, RTMemPageFree) -DUMMY(-1, RTPathHasPath) DUMMY(-1, RTPathAppend) -DUMMY(-1, rtPathPosixRename) -CHECKED_DUMMY(0, rtProcInitExePath) DUMMY(-1, RTSemEventWaitEx) CHECKED_DUMMY( 0, SELMR3InitFinalize) @@ -206,14 +200,13 @@ DUMMY(-1, VMMR3GetHostToGuestSwitcher) DUMMY(-1, pthread_kill) DUMMY(-1, sscanf) DUMMY(-1, RTHeapSimpleRelocate) -DUMMY(-1, RTHeapOffsetInit) +DUMMY(-1, RTHeapSimpleAlloc) DUMMY(-1, RTHeapSimpleInit) -DUMMY(-1, RTHeapOffsetFree) DUMMY(-1, RTHeapSimpleFree) DUMMY(-1, RTAvloU32Get) DUMMY(-1, RTAvloU32Remove) DUMMY(-1, RTAvloU32GetBestFit) -CHECKED_DUMMY(0, RTAvloU32RemoveBestFit) +DUMMY( 0, RTAvloU32RemoveBestFit) DUMMY(-1, RTAvlU32Destroy) DUMMY(-1, RTAvlU32GetBestFit) DUMMY(-1, RTAvloU32DoWithAll) @@ -240,15 +233,8 @@ DUMMY(-1, IOMInterpretINS) DUMMY(-1, DISInstrToStrWithReader) -DUMMY(0, RTPathQueryInfoEx) - DUMMY(-1, RTFileQueryFsSizes) -time_t mktime(tm *) { - PERR("mktime not implemented, return 0"); - return 0; -} - DUMMY(-1, pthread_mutex_timedlock) CHECKED_DUMMY( 0, PGMHandlerVirtualDeregister) /* XXX */ @@ -257,8 +243,6 @@ CHECKED_DUMMY( 0, PGMR3HandlerVirtualRegister) /* XXX */ /* * Dummies added for storage */ -DUMMY(-1, closedir) -DUMMY(-1, readdir_r) DUMMY(-1, RTAvlrFileOffsetDestroy) DUMMY(-1, RTAvlrFileOffsetGet) DUMMY(-1, RTAvlrFileOffsetGetBestFit) @@ -271,13 +255,8 @@ DUMMY(-1, RTAvlrU64Insert) DUMMY(-1, RTAvlrU64RangeGet) DUMMY(-1, RTAvlrU64RangeRemove) DUMMY(-1, RTAvlrU64Remove) -DUMMY(-1, RTDirOpenFiltered) -DUMMY(-1, RTDirReadEx) -DUMMY(-1, RTDirClose) DUMMY(-1, RTLdrClose) -DUMMY(-1, RTLdrGetSymbol) DUMMY(-1, RTMemDupExTag) -DUMMY(-1, RTPathQueryInfo) DUMMY(-1, rtPathRootSpecLen) DUMMY(-1, RTPathStartsWithRoot) DUMMY(-1, RTSocketToNative) @@ -296,7 +275,14 @@ DUMMY(-1, RTTcpSgWrite) DUMMY(-1, RTTcpSgWriteNB) DUMMY(-1, RTTcpWrite) DUMMY(-1, RTTcpWriteNB) -DUMMY(-1, strncat) +DUMMY(-1, RTTimeLocalExplode) + +DUMMY(-1, RTSymlinkCreate) +DUMMY(-1, RTSymlinkRead) +DUMMY(-1, RTSymlinkDelete) + +CHECKED_DUMMY(0, futimes) +CHECKED_DUMMY(0, lutimes) int __isthreaded; diff --git a/repos/ports/src/virtualbox/dynlib.cc b/repos/ports/src/virtualbox/dynlib.cc new file mode 100644 index 000000000..2aff8f9dd --- /dev/null +++ b/repos/ports/src/virtualbox/dynlib.cc @@ -0,0 +1,76 @@ +/* + * \brief Support to link libraries statically supposed to be dynamic + * \author Alexander Boettcher + * \date 2014-05-13 + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +/* Genode includes */ +#include +#include + +/* VirtualBox includes */ +#include +#include +#include + +extern "C" { + +DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad (VBOXHGCMSVCFNTABLE *ptable); + + +static struct shared { + const char * name; + const char * symbol; + void * func; +} shared[] = { "/VBoxSharedFolders", VBOX_HGCM_SVCLOAD_NAME, (void *)VBoxHGCMSvcLoad }; + + +int RTLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod) +{ + for (unsigned i = 0; i < sizeof(shared) / sizeof(shared[0]); i++) { + if (Genode::strcmp(shared[i].name, pszFilename)) + continue; + + *phLdrMod = reinterpret_cast(&shared[i]); + return VINF_SUCCESS; + } + + PERR("shared library '%s' not supported", pszFilename); + return VERR_NOT_SUPPORTED; +} + + +int RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue) +{ + + struct shared * library = reinterpret_cast(hLdrMod); + + if (!(shared <= library && + library < shared + sizeof(shared) / sizeof(shared[0]))) { + + PERR("shared library handle %p unknown - symbol looked for '%s'", + hLdrMod, pszSymbol); + + return VERR_NOT_SUPPORTED; + } + + if (Genode::strcmp(pszSymbol, library->symbol)) { + PERR("shared library '%s' does not provide symbol '%s'", + library->name, pszSymbol); + + return VERR_NOT_SUPPORTED; + } + + *ppvValue = library->func; + + return VINF_SUCCESS; +} + +} diff --git a/repos/ports/src/virtualbox/fake_pci_vendor.patch b/repos/ports/src/virtualbox/fake_pci_vendor.patch index 0fa3c3a62..6a69b45f7 100644 --- a/repos/ports/src/virtualbox/fake_pci_vendor.patch +++ b/repos/ports/src/virtualbox/fake_pci_vendor.patch @@ -1,4 +1,4 @@ -+++ src/app/virtualbox/src/VBox/Devices/Graphics/DevVGA.cpp ++++ src/app/virtualbox/src/VBox/Devices/Graphics/DevVGA.cpp 2013-12-09 10:33:02.168894689 +0100 @@ -5885,7 +5889,7 @@ vgaR3Reset(pDevIns); @@ -8,13 +8,3 @@ PCIDevSetDeviceId( &pThis->Dev, 0xbeef); PCIDevSetClassSub( &pThis->Dev, 0x00); /* VGA controller */ PCIDevSetClassBase( &pThis->Dev, 0x03); -+++ src/app/virtualbox/src/VBox/Devices/VMMDev/VMMDev.cpp -@@ -3429,7 +3431,7 @@ - pThis->pDevIns = pDevIns; - - /* PCI vendor, just a free bogus value */ -- PCIDevSetVendorId(&pThis->dev, 0x80ee); -+ PCIDevSetVendorId(&pThis->dev, 0x80ef); - /* device ID */ - PCIDevSetDeviceId(&pThis->dev, 0xcafe); - /* class sub code (other type of system peripheral) */ diff --git a/repos/ports/src/virtualbox/hgcm_sync.patch b/repos/ports/src/virtualbox/hgcm_sync.patch new file mode 100644 index 000000000..49725aa51 --- /dev/null +++ b/repos/ports/src/virtualbox/hgcm_sync.patch @@ -0,0 +1,34 @@ ++++ src/app/virtualbox/src/VBox/Devices/VMMDev/VMMDevHGCM.cpp +@@ -39,6 +39,12 @@ + # define VBOXDD_HGCMCALL_COMPLETED_DONE(a,b,c,d) do { } while (0) + #endif + ++#include ++ ++ ++static Genode::Lock w4c(Genode::Lock::LOCKED); ++ ++ + typedef enum _VBOXHGCMCMDTYPE + { + VBOXHGCMCMDTYPE_LOADSTATE = 0, +@@ -1147,6 +1153,9 @@ int vmmdevHGCMCall (VMMDevState *pVMMDevState, VMMDevHGCMCall *pHGCMCall, uint32 + RTMemFree (pCmd); + } + ++ /* wait for completion */ ++ w4c.lock(); ++ + return rc; + } + +@@ -2382,6 +2391,9 @@ DECLCALLBACK(void) hgcmCompleted (PPDMIHGCMPORT pInterface, int32_t result, PVBO + int rc = VMR3ReqCallVoidNoWait(PDMDevHlpGetVM(pVMMDevState->pDevIns), VMCPUID_ANY, + (PFNRT)hgcmCompletedWorker, 3, pInterface, result, pCmd); + AssertRC(rc); ++ ++ /* signal completion */ ++ w4c.unlock(); + } + + /* @thread EMT */ diff --git a/repos/ports/src/virtualbox/iconv.patch b/repos/ports/src/virtualbox/iconv.patch new file mode 100644 index 000000000..9f37dec85 --- /dev/null +++ b/repos/ports/src/virtualbox/iconv.patch @@ -0,0 +1,17 @@ ++++ src/app/virtualbox/src/VBox/Runtime/r3/posix/utf8-posix.cpp +@@ -319,11 +319,11 @@ + size_t cbOutLeft = cbOutput2; + const void *pvInputLeft = pvInput; + void *pvOutputLeft = pvOutput; +-#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || (defined(RT_OS_DARWIN) && defined(_DARWIN_FEATURE_UNIX_CONFORMANCE)) /* there are different opinions about the constness of the input buffer. */ ++//#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || (defined(RT_OS_DARWIN) && defined(_DARWIN_FEATURE_UNIX_CONFORMANCE)) /* there are different opinions about the constness of the input buffer. */ + if (iconv(icHandle, (char **)&pvInputLeft, &cbInLeft, (char **)&pvOutputLeft, &cbOutLeft) != (size_t)-1) +-#else +- if (iconv(icHandle, (const char **)&pvInputLeft, &cbInLeft, (char **)&pvOutputLeft, &cbOutLeft) != (size_t)-1) +-#endif ++//#else ++// if (iconv(icHandle, (const char **)&pvInputLeft, &cbInLeft, (char **)&pvOutputLeft, &cbOutLeft) != (size_t)-1) ++//#endif + { + if (!cbInLeft) + { diff --git a/repos/ports/src/virtualbox/include/SDLConsole.h b/repos/ports/src/virtualbox/include/SDLConsole.h index 213d6b7fd..57cd5e5db 100644 --- a/repos/ports/src/virtualbox/include/SDLConsole.h +++ b/repos/ports/src/virtualbox/include/SDLConsole.h @@ -241,6 +241,6 @@ class SDLConsole : public Console { void eventQuit() { PERR("%s:%s called", __FILE__, __FUNCTION__); } void resetKeys(void) { PERR("%s:%s called", __FILE__, __FUNCTION__); } - VMMDev *getVMMDev() { /*PERR("%s:%s called", __FILE__, __FUNCTION__);*/ return 0; } + VMMDev *getVMMDev() { return gVMMDev; } Display *getDisplay() { return gDisplay; } }; diff --git a/repos/ports/src/virtualbox/ioport.cc b/repos/ports/src/virtualbox/ioport.cc index ebe0b7210..34657f81c 100644 --- a/repos/ports/src/virtualbox/ioport.cc +++ b/repos/ports/src/virtualbox/ioport.cc @@ -133,6 +133,14 @@ class Guest_ioports return 0; } + bool _white_listed(RTIOPORT port) + { + /* LPT1 */ if (port >= 0x0378 && port <= 0x037f) return true; + /* ECP */ if (port >= 0x0778 && port <= 0x077a) return true; + /* IDE1 */ if (port >= 0x0170 && port <= 0x017f) return true; + return false; + } + public: int add_range(PPDMDEVINS pDevIns, @@ -181,17 +189,19 @@ class Guest_ioports return deleted ? VINF_SUCCESS : VERR_GENERAL_FAILURE; } - VBOXSTRICTRC write(RTIOPORT Port, uint32_t u32Value, size_t cbValue) + VBOXSTRICTRC write(RTIOPORT port, uint32_t u32Value, size_t cbValue) { - Range *r = _lookup(Port, cbValue); + Range *r = _lookup(port, cbValue); if (r) - return r->write(Port, u32Value, cbValue); + return r->write(port, u32Value, cbValue); + + if (_white_listed(port)) + return VINF_SUCCESS; char c = u32Value & 0xff; - PWRN("attempted to write to non-existing port 0x%lx+%u %c (%02x)", Port, cbValue, - c >= 32 && c <= 176 ? c : '.', c); + PWRN("attempted to write to non-existing port 0x%lx+%u %c (%02x)", + port, cbValue, c >= 32 && c <= 176 ? c : '.', c); return VINF_SUCCESS; -// return VERR_GENERAL_FAILURE; /* recompiler does not like this */ } VBOXSTRICTRC read(RTIOPORT port, uint32_t *pu32Value, unsigned cbValue) @@ -203,7 +213,9 @@ class Guest_ioports return err; } - PWRN("attempted to read from non-existing port 0x%x+%u %p", port, cbValue, r); + if (!_white_listed(port)) + PWRN("attempted to read from non-existing port 0x%x+%u %p", + port, cbValue, r); switch (cbValue) { diff --git a/repos/ports/src/virtualbox/libc.cc b/repos/ports/src/virtualbox/libc.cc index 94609348e..41f286b7f 100644 --- a/repos/ports/src/virtualbox/libc.cc +++ b/repos/ports/src/virtualbox/libc.cc @@ -14,10 +14,14 @@ /* Genode includes */ #include #include +#include /* libc includes */ #include #include +#include +#include +#include /* libc memory allocator */ #include @@ -103,6 +107,9 @@ extern "C" char *getenv(const char *name) "+pdm" // "+dev_pic.e.l.f" // "+dev_apic.e.l.f" +// "+dev_vmm.e.l.f" +// "+main.e.l.f" +// "+hgcm.e.l.f" ; if (Genode::strcmp(name, "VBOX_LOG_FLAGS") == 0 || @@ -125,3 +132,36 @@ extern "C" int sigaction(int signum, const struct sigaction *act, return 0; } + + +/** + * Used by RTTimeNow + */ +extern "C" int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + if (!tv) + return -1; + + try { + static Rtc::Connection rtc; + /* we need only seconds, current_time in microseconds */ + tv->tv_sec = rtc.get_current_time() / 1000000ULL; + tv->tv_usec = rtc.get_current_time() % 1000000ULL * 1000; + return 0; + } catch (...) { + return -1; + } +} + + +/** + * Used by Shared Folders + */ +extern "C" long pathconf(char const *path, int name) +{ + if (name = _PC_NAME_MAX) return 255; + + PERR("pathconf does not support config option %d", name); + errno = EINVAL; + return -1; +} diff --git a/repos/ports/src/virtualbox/main.cc b/repos/ports/src/virtualbox/main.cc index 5e154cca4..c107752d9 100644 --- a/repos/ports/src/virtualbox/main.cc +++ b/repos/ports/src/virtualbox/main.cc @@ -28,6 +28,9 @@ void *operator new (Genode::size_t size) { return Genode::env()->heap()->alloc(size); } +void *operator new [] (Genode::size_t size) { + return Genode::env()->heap()->alloc(size); } + void operator delete(void * p) { if (Genode::env()->heap()->need_size_for_free()) { PERR("leaking memory - delete operator is missing size information"); @@ -39,60 +42,40 @@ void operator delete(void * p) { namespace { template - struct Args + class Args { - int argc = 0; - char *argv[MAX_ARGS] = { }; + private: - struct Too_many_arguments { }; + int _argc = 0; + char *_argv[MAX_ARGS] = { }; - void add(char const *arg) - { - /* argv[MAX_ARGS - 1] must be unused and set to 0 */ - if (argc >= MAX_ARGS - 1) - throw Too_many_arguments(); + public: - /* XXX yes const-casting hurts but main() needs char** */ - argv[argc++] = const_cast(arg); - } + class Too_many_arguments { }; + + void add(char const *arg) + { + /* argv[MAX_ARGS - 1] must be unused and set to 0 */ + if (_argc >= MAX_ARGS - 1) + throw Too_many_arguments(); + + /* XXX yes const-casting hurts but main() needs char**, if in + * doubt we should strdup() here, right? */ + _argv[_argc++] = const_cast(arg); + } + + char *** argvp() { + static char ** argv = _argv; + return &argv; + } + + int argc() { return _argc; } }; } /* unnamed namespace */ extern "C" { -/* string conversion function currently does not convert ... */ -int RTStrCurrentCPToUtf8Tag(char **ppszString, char *pszString, - const char *pszTag) -{ - /* dangerous */ - *ppszString = pszString; - return 0; -} - -/* don't use 'Runtime/r3/posix/utf8-posix.cpp' because it depends on libiconv */ -int RTStrUtf8ToCurrentCPTag(char **ppszString, char *pszString, - const char *pszTag) -{ - /* dangerous */ - *ppszString = pszString; - return 0; -} - - -char * RTPathRealDup(const char *pszPath) -{ - /* dangerous */ - return (char *)pszPath; -} - - -bool RTPathExists(const char *pszPath) -{ - return true; -} - - /* make output of Virtualbox visible */ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { @@ -150,6 +133,7 @@ extern "C" DECLEXPORT(int) TrustedMain (int argc, char **argv, char **envp); int main() { static char c_mem[16]; + static char c_vram[16]; static char c_type[4]; static char c_file[128]; static bool bOverlay = false; @@ -159,13 +143,17 @@ int main() /* request max available memory */ size_t vm_size = Genode::env()->ram_session()->avail(); - enum { VMM_MEMORY = 64 * 1024 * 1024 /* let a bit memory for the VMM */ }; - if (vm_size < VMM_MEMORY) { + enum { + VMM_MEMORY = 88 * 1024 * 1024, /* let a bit memory for the VMM */ + VRAM_MEMORY = 8 * 1024 * 1024, /* video memory */ + }; + + if (vm_size < VMM_MEMORY + VRAM_MEMORY) { PERR("not enough memory available - need %u, available only %zu " - "- exit", VMM_MEMORY, vm_size); + "- exit", VMM_MEMORY + VRAM_MEMORY, vm_size); return 1; } - vm_size -= VMM_MEMORY; + vm_size -= VMM_MEMORY + VRAM_MEMORY; try { using namespace Genode; @@ -187,12 +175,14 @@ int main() } args.add("virtualbox"); - args.add("-m"); Genode::snprintf(c_mem, sizeof(c_mem), "%u", vm_size / 1024 / 1024); - args.add(c_mem); - args.add("-boot"); + args.add("-m"); args.add(c_mem); + Genode::snprintf(c_vram, sizeof(c_vram), "%u", VRAM_MEMORY / 1024 / 1024); + args.add("-vram"); args.add(c_vram); + + args.add("-boot"); if (!Genode::strcmp(c_type, "iso")) { args.add("d"); args.add("-cdrom"); @@ -211,16 +201,37 @@ int main() if (bOverlay) args.add("-overlay"); - PINF("start %s image '%s' with %zu MB Guest memory=%zu", - c_type, c_file, vm_size / 1024 / 1024, - Genode::env()->ram_session()->avail()); + /* shared folder setup */ + unsigned shares = 0; + try { + using namespace Genode; + for (Xml_node node = config()->xml_node().sub_node("share"); + true; node = node.next("share")) { - if (RT_FAILURE(RTR3InitExe(args.argc, (char ***)&args.argv, 0))) { + Xml_node::Attribute share_dir_host = node.attribute("host"); + Xml_node::Attribute share_dir_guest = node.attribute("guest"); + + char * dir_host = new char[share_dir_host.value_size()]; + char * dir_guest = new char[share_dir_guest.value_size()]; + + share_dir_host.value(dir_host, share_dir_host.value_size()); + share_dir_guest.value(dir_guest, share_dir_guest.value_size()); + + args.add("-share"); args.add(dir_host), args.add(dir_guest); + shares ++; + } + } catch(Genode::Xml_node::Nonexistent_sub_node) { } + + PINF("start %s image '%s' with %zu MB guest memory=%zu and %u shared folders", + c_type, c_file, vm_size / 1024 / 1024, + Genode::env()->ram_session()->avail(), shares); + + if (RT_FAILURE(RTR3InitExe(args.argc(), args.argvp(), 0))) { PERR("Intialization of VBox Runtime failed."); return 5; } - return TrustedMain(args.argc, args.argv, NULL); + return TrustedMain(args.argc(), *args.argvp(), NULL); } -} /* EXTERN "C" */ +} /* extern "C" */ diff --git a/repos/ports/src/virtualbox/nova/sup.cc b/repos/ports/src/virtualbox/nova/sup.cc index 3cac721a1..301472469 100644 --- a/repos/ports/src/virtualbox/nova/sup.cc +++ b/repos/ports/src/virtualbox/nova/sup.cc @@ -22,7 +22,6 @@ #include #include -#include /* NOVA includes that come with Genode */ #include @@ -184,7 +183,8 @@ extern "C" void pthread_yield(void) { Nova::ec_ctrl(Nova::EC_YIELD); } extern "C" bool create_emt_vcpu(pthread_t * pthread, size_t stack, const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg) + void *(*start_routine)(void *), void *arg, + Genode::Cpu_session * cpu_session) { Nova::Hip * hip = hip_rom.local_addr(); @@ -192,10 +192,12 @@ bool create_emt_vcpu(pthread_t * pthread, size_t stack, return false; if (hip->has_feature_vmx()) - vcpu_handler = new Vcpu_handler_vmx(stack, attr, start_routine, arg); + vcpu_handler = new Vcpu_handler_vmx(stack, attr, start_routine, arg, + cpu_session); if (hip->has_feature_svm()) - vcpu_handler = new Vcpu_handler_svm(stack, attr, start_routine, arg); + vcpu_handler = new Vcpu_handler_svm(stack, attr, start_routine, arg, + cpu_session); *pthread = vcpu_handler; return true; diff --git a/repos/ports/src/virtualbox/nova/vcpu.h b/repos/ports/src/virtualbox/nova/vcpu.h index 35f8d256b..f5e4c00ff 100644 --- a/repos/ports/src/virtualbox/nova/vcpu.h +++ b/repos/ports/src/virtualbox/nova/vcpu.h @@ -63,9 +63,10 @@ static inline Genode::uint32_t sel_ar_conv_from_nova(Genode::uint16_t v) /* - * Used to map memory for virtual framebuffer to VM + * Used to map mmio memory to VM */ -extern "C" int MMIO2_MAPPED_SYNC(PVM pVM, RTGCPHYS GCPhys, size_t cbWrite); +extern "C" int MMIO2_MAPPED_SYNC(PVM pVM, RTGCPHYS GCPhys, size_t cbWrite, + void **ppv); class Vcpu_handler : public Vmm::Vcpu_dispatcher @@ -87,6 +88,8 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher asm volatile ("fxrstor %0" : : "m" (*data)); } + enum { IRQ_INJ_VALID_MASK = 0x80000000UL }; + protected: struct { @@ -115,13 +118,14 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher Assert(!(utcb->intr_state & 3)); Assert(utcb->flags & X86_EFL_IF); + Assert(!(utcb->inj_info & IRQ_INJ_VALID_MASK)); if (irq_win(utcb)) { /* reset mtd to not transfer anything back by accident */ utcb->mtd = 0; /* inject IRQ */ - if (inj_event(utcb, _current_vcpu)) - Nova::reply(_stack_reply); + inj_event(utcb, _current_vcpu, utcb->flags & X86_EFL_IF); + Nova::reply(_stack_reply); } /* go back to re-compiler */ @@ -130,9 +134,25 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher __attribute__((noreturn)) void _default_handler() { + Nova::Utcb * utcb = reinterpret_cast(Thread_base::utcb()); + + Assert(!(utcb->inj_info & IRQ_INJ_VALID_MASK)); + longjmp(_env, 1); } + __attribute__((noreturn)) void _recall_handler() + { + /* take care - Mtd::EFL | Mtd::STA are solely written to utcb */ + Nova::Utcb * utcb = reinterpret_cast(Thread_base::utcb()); + + Assert(!(utcb->intr_state & 3)); + + utcb->mtd = 0; + inj_event(utcb, _current_vcpu, utcb->flags & X86_EFL_IF); + + Nova::reply(_stack_reply); + } template __attribute__((noreturn)) inline @@ -142,37 +162,32 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher using namespace Nova; using namespace Genode; - addr_t stack_top; - Assert(utcb->actv_state == 0); Assert(!(utcb->intr_state & 3)); - Assert(!(utcb->inj_info & 0x80000000)); + Assert(!(utcb->inj_info & IRQ_INJ_VALID_MASK)); if (unmap) { PERR("unmap not implemented\n"); - Nova::reply(reinterpret_cast(&stack_top)); + Nova::reply(_stack_reply); } - + + enum { MAP_SIZE = 0x1000UL }; + Flexpage_iterator fli; - void *pv = guest_memory()->lookup_ram(reason, 0x1000UL, fli); + void *pv = guest_memory()->lookup_ram(reason, MAP_SIZE, fli); if (!pv) { - pv = vmm_memory()->lookup(reason, 0x1000UL); - if (pv) { /* XXX */ - fli = Genode::Flexpage_iterator((addr_t)pv, 0x1000UL, - reason, 0x1000UL, reason); - int res = MMIO2_MAPPED_SYNC(_current_vm, reason, 0x1); -/* - Genode::addr_t fb_phys = 0xf0000000UL; - Genode::addr_t fb_size = 0x00400000UL; - pv = vmm_memory()->lookup(fb_phys, fb_size); - - fli = Genode::Flexpage_iterator((addr_t)pv, fb_size, - fb_phys, fb_size, fb_phys); - int res = MMIO2_MAPPED_SYNC(_current_vm, fb_phys, fb_size); -*/ - } + /** + * Check whether this is some mmio memory provided by VMM + * we can map, e.g. VMMDev memory or framebuffer currently. + */ + int res = MMIO2_MAPPED_SYNC(_current_vm, reason, MAP_SIZE, &pv); + if (pv && (res == VINF_SUCCESS)) + fli = Genode::Flexpage_iterator((addr_t)pv, MAP_SIZE, + reason, MAP_SIZE, reason); + else + pv = 0; } /* emulator has to take over if fault region is not ram */ @@ -209,7 +224,7 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher res = utcb->append_item(crd, flexpage.hotspot, USER_PD, GUEST_PGT); } while (res); - Nova::reply(reinterpret_cast(&stack_top)); + Nova::reply(_stack_reply); } /** @@ -395,10 +410,8 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher } - inline bool inj_event(Nova::Utcb * utcb, PVMCPU pVCpu) + inline bool inj_event(Nova::Utcb * utcb, PVMCPU pVCpu, bool if_flag) { - PCPUMCTX const pCtx = CPUMQueryGuestCtxPtr(pVCpu); - if (!TRPMHasTrap(pVCpu)) { if (VMCPU_FF_TESTANDCLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI)) { @@ -408,7 +421,7 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher if (VMCPU_FF_ISPENDING(pVCpu, (VMCPU_FF_INTERRUPT_APIC|VMCPU_FF_INTERRUPT_PIC))) { - if (!(pCtx->rflags.u & X86_EFL_IF)) { + if (!if_flag) { unsigned vector = 0; utcb->inj_info = 0x1000 | vector; @@ -424,12 +437,12 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher rc = TRPMAssertTrap(pVCpu, irq, TRPM_HARDWARE_INT); Assert(RT_SUCCESS(rc)); } else - PWRN("pending interrupt blocked due to INHIBIT flag"); + Vmm::printf("pending interrupt blocked due to INHIBIT flag\n"); } } /* can an interrupt be dispatched ? */ - if (!TRPMHasTrap(pVCpu) || !(pCtx->rflags.u & X86_EFL_IF) || + if (!TRPMHasTrap(pVCpu) || !if_flag || VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INHIBIT_INTERRUPTS)) return false; @@ -452,8 +465,7 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher /* If a new event is pending, then dispatch it now. */ int rc = TRPMQueryTrapAll(pVCpu, &u8Vector, &enmType, &u32ErrorCode, 0); AssertRC(rc); - Assert(pCtx->eflags.Bits.u1IF == 1 || enmType == TRPM_TRAP); - Assert(enmType != TRPM_SOFTWARE_INT); + Assert(enmType == TRPM_HARDWARE_INT); /* Clear the pending trap. */ rc = TRPMResetTrap(pVCpu); @@ -463,8 +475,6 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher Event.n.u1Valid = 1; Event.n.u32ErrorCode = u32ErrorCode; - Assert(enmType == TRPM_HARDWARE_INT); - Event.n.u3Type = SVM_EVENT_EXTERNAL_IRQ; utcb->inj_info = Event.au64[0]; @@ -529,10 +539,12 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher Vcpu_handler(size_t stack_size, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg) + void *(*start_routine) (void *), void *arg, + Genode::Cpu_session * cpu_session) : Vmm::Vcpu_dispatcher(stack_size, _cap_connection, attr ? *attr : 0, start_routine, arg), + _vcpu(cpu_session), _ec_sel(Genode::cap_map()->insert()) { } @@ -653,7 +665,7 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher using namespace Nova; /* check whether to inject interrupts */ - inj_event(utcb, pVCpu); + inj_event(utcb, pVCpu, pCtx->rflags.u & X86_EFL_IF); /* Transfer vCPU state from vBox to Nova format */ if (!vbox_to_utcb(utcb, pVM, pVCpu) || diff --git a/repos/ports/src/virtualbox/nova/vcpu_svm.h b/repos/ports/src/virtualbox/nova/vcpu_svm.h index 77a45b6ae..8bd2ca91f 100644 --- a/repos/ports/src/virtualbox/nova/vcpu_svm.h +++ b/repos/ports/src/virtualbox/nova/vcpu_svm.h @@ -76,18 +76,24 @@ class Vcpu_handler_svm : public Vcpu_handler Nova::reply(nullptr); } + __attribute__((noreturn)) void _svm_recall() + { + Vcpu_handler::_recall_handler(); + } + public: Vcpu_handler_svm(size_t stack_size, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg) - : Vcpu_handler(stack_size, attr, start_routine, arg) + void *(*start_routine) (void *), void *arg, + Genode::Cpu_session * cpu_session) + : Vcpu_handler(stack_size, attr, start_routine, arg, cpu_session) { using namespace Nova; typedef Vcpu_handler_svm This; register_handler(vcpu().exc_base(), Mtd(Mtd::ALL | Mtd::FPU)); + &This::_svm_recall>(vcpu().exc_base(), Mtd(Mtd::EFL | Mtd::STA)); register_handler (vcpu().exc_base(), Mtd(Mtd::ALL | Mtd::FPU)); register_handler (exc_base, Mtd::ALL | Mtd::FPU); register_handler (exc_base, Mtd::ALL | Mtd::FPU); + &This::_vmx_recall> (exc_base, Mtd::EFL | Mtd::STA); start(); } diff --git a/repos/ports/src/virtualbox/pgm.cc b/repos/ports/src/virtualbox/pgm.cc index a4be343d9..2702a154d 100644 --- a/repos/ports/src/virtualbox/pgm.cc +++ b/repos/ports/src/virtualbox/pgm.cc @@ -15,6 +15,8 @@ #include #include +#include + /* VirtualBox includes */ #include "PGMInternal.h" /* enable access to pgm.s.* */ #include @@ -73,10 +75,7 @@ int PGMR3PhysRomRegister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhys, int PGMPhysWrite(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite) { void *pv = guest_memory()->lookup(GCPhys, cbWrite); -/* - PLOG("PGMPhysWrite: GCPhys=0x%lx pvBuf=0x%p cbWrite=0x%zx pv=%p", - (long)GCPhys, pvBuf, cbWrite, pv); -*/ + if (pv) { memcpy(pv, pvBuf, cbWrite); return VINF_SUCCESS; @@ -309,19 +308,32 @@ int PGMR3Init(PVM pVM) int PGMR3PhysTlbGCPhys2Ptr(PVM pVM, RTGCPHYS GCPhys, bool fWritable, void **ppv) { - void *pv = guest_memory()->lookup(GCPhys, 1); + size_t const size = 1; + void *pv = guest_memory()->lookup(GCPhys, size); + + if (pv) { + *ppv = pv; + return VINF_SUCCESS; + } + + PFNPGMR3PHYSHANDLER pfnHandlerR3 = 0; + void *pvUserR3 = 0; + + pv = vmm_memory()->lookup(GCPhys, size, &pfnHandlerR3, &pvUserR3); if (!pv) { - PERR("PGMR3PhysTlbGCPhys2Ptr: lookup for GCPhys=0x%lx failed", (long)GCPhys); - guest_memory()->dump(); + PERR("%s: lookup for GCPhys=0x%p failed", __func__, GCPhys); return VERR_PGM_PHYS_TLB_UNASSIGNED; } - *ppv = pv; - -// PLOG("PGMR3PhysTlbGCPhys2Ptr: GCPhys=0x%lx -> pv=%p", (long)GCPhys, pv); - - return VINF_SUCCESS; + /* pv valid - check handlers next */ + if (!pfnHandlerR3 && !pvUserR3) { + *ppv = pv; + return VINF_SUCCESS; + } + + PERR("%s: denied access - handlers set - GCPhys=0x%p", __func__, GCPhys); + return VERR_PGM_PHYS_TLB_CATCH_ALL; } @@ -524,28 +536,42 @@ int PGMHandlerPhysicalReset(PVM, RTGCPHYS GCPhys) } -extern "C" int MMIO2_MAPPED_SYNC(PVM pVM, RTGCPHYS GCPhys, size_t cbWrite) +extern "C" int MMIO2_MAPPED_SYNC(PVM pVM, RTGCPHYS GCPhys, size_t cbWrite, + void **ppv) { + /* DON'T USE normal printf in this function - corrupts unsaved UTCB !!! */ + PFNPGMR3PHYSHANDLER pfnHandlerR3 = 0; void *pvUserR3 = 0; void * pv = vmm_memory()->lookup(GCPhys, cbWrite, &pfnHandlerR3, &pvUserR3); - if (!pv || !pfnHandlerR3 || !pvUserR3) { - PERR("%s: GCPhys=0x%lx cbWrite=0x%zx", __func__, - GCPhys, cbWrite); - return VERR_GENERAL_FAILURE; - } + if (!pv) + return VERR_PGM_PHYS_TLB_UNASSIGNED; - int rc = pfnHandlerR3(pVM, GCPhys, 0, 0, cbWrite, PGMACCESSTYPE_WRITE, - pvUserR3); - - if (rc == VINF_PGM_HANDLER_DO_DEFAULT) { -// PERR("%s: ok %p %lx+%zx", __func__, pfnHandlerR3, GCPhys, cbWrite); + if (!pfnHandlerR3 && !pvUserR3) { + *ppv = pv; + /* you may map it */ return VINF_SUCCESS; } - PERR("unexpected %s return code %d", __FUNCTION__, rc); + if (pfnHandlerR3 && pvUserR3) { + int rc = pfnHandlerR3(pVM, GCPhys, 0, 0, cbWrite, PGMACCESSTYPE_WRITE, + pvUserR3); + + if (rc == VINF_PGM_HANDLER_DO_DEFAULT) { + *ppv = pv; + /* you may map it */ + return VINF_SUCCESS; + } + + Vmm::printf("%s: GCPhys=0x%lx failed - unexpected rc=%d\n", + __func__, GCPhys, rc); + return rc; + } + + Vmm::printf("%s: GCPhys=0x%lx failed - unexpected state \n", + __func__, GCPhys); return VERR_GENERAL_FAILURE; } @@ -581,3 +607,13 @@ void PGMR3Reset(PVM pVM) PERR("clearing ram and rom areas missing !!!!!!!"); } + + +int PGMR3MappingsSize(PVM pVM, uint32_t *pcb) +{ + PINF("%s - not implemented - %p", __func__, __builtin_return_address(0)); + + *pcb = 0; + + return 0; +} diff --git a/repos/ports/src/virtualbox/rt.cc b/repos/ports/src/virtualbox/rt.cc index f038e2113..eca086717 100644 --- a/repos/ports/src/virtualbox/rt.cc +++ b/repos/ports/src/virtualbox/rt.cc @@ -77,31 +77,8 @@ uint32_t RTBldCfgVersionBuild(void) { return VBOX_VERSION_BUILD; } uint32_t RTBldCfgRevision(void) { return ~0; } -/* - * Copied from 'Runtime/r3/posix/timelocal-posix.cpp' - */ - -static int64_t rtTimeLocalUTCOffset(PCRTTIMESPEC pTime, bool fCurrentTime) +extern "C" DECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath) { - PDBG("rtTimeLocalUTCOffset called - not implemented"); + Genode::strncpy(pszPath, "/virtualbox", cchPath); return 0; } - - -RTDECL(PRTTIME) RTTimeLocalExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec) -{ - RTTIMESPEC LocalTime = *pTimeSpec; - RTTimeSpecAddNano(&LocalTime, rtTimeLocalUTCOffset(&LocalTime, true /* current time, skip fallback */)); - pTime = RTTimeExplode(pTime, &LocalTime); - if (pTime) - pTime->fFlags = (pTime->fFlags & ~RTTIME_FLAGS_TYPE_MASK) | RTTIME_FLAGS_TYPE_LOCAL; - return pTime; -} - - -extern "C" RTDECL(int) RTPathAbs(const char *pszPath, char *pszAbsPath, size_t cchAbsPath) -{ - Genode::strncpy(pszAbsPath, pszPath, cchAbsPath); - return 0; -} - diff --git a/repos/ports/src/virtualbox/rtc.patch b/repos/ports/src/virtualbox/rtc.patch new file mode 100644 index 000000000..da960170d --- /dev/null +++ b/repos/ports/src/virtualbox/rtc.patch @@ -0,0 +1,9 @@ ++++ src/app/virtualbox/src/VBox/Frontends/VBoxBFE/VBoxBFE.cpp +@@ -1470,6 +1481,7 @@ + rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); UPDATE_RC(); + rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC(); + rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC(); ++ rc = CFGMR3InsertInteger(pCfg, "UseUTC", 1); /* boolean */ UPDATE_RC(); + + /* + * Serial ports diff --git a/repos/ports/src/virtualbox/sharedfolder.patch b/repos/ports/src/virtualbox/sharedfolder.patch new file mode 100644 index 000000000..f61eff44a --- /dev/null +++ b/repos/ports/src/virtualbox/sharedfolder.patch @@ -0,0 +1,12 @@ ++++ src/app/virtualbox/src/VBox/Frontends/VBoxBFE/VBoxBFE.cpp 2014-05-14 +@@ -1132,7 +1135,9 @@ + parms[1].u.pointer.size = sizeof (SHFLSTRING) + cbString; + + parms[2].type = VBOX_HGCM_SVC_PARM_32BIT; +- parms[2].u.uint32 = !g_fShareReadOnly[i]; ++ parms[2].u.uint32 = g_fShareReadOnly[i] ? 0 : SHFL_ADD_MAPPING_F_WRITABLE; ++ ++ parms[2].u.uint32 |= SHFL_ADD_MAPPING_F_AUTOMOUNT; + + rc2 = gVMMDev->hgcmHostCall ("VBoxSharedFolders", + SHFL_FN_ADD_MAPPING, SHFL_CPARMS_ADD_MAPPING, &parms[0]); diff --git a/repos/ports/src/virtualbox/sup.cc b/repos/ports/src/virtualbox/sup.cc index 7cbbbf66d..5a585511c 100644 --- a/repos/ports/src/virtualbox/sup.cc +++ b/repos/ports/src/virtualbox/sup.cc @@ -14,22 +14,13 @@ /* Genode includes */ #include #include +#include /* Genode/Virtualbox includes */ #include "sup.h" /* VirtualBox includes */ -#include -#include -#include #include -#include -#include -#include - -using Genode::Semaphore; - -#define B(x) "\033[00;44m" x "\033[0m" struct Attached_gip : Genode::Attached_ram_dataspace @@ -41,7 +32,8 @@ struct Attached_gip : Genode::Attached_ram_dataspace enum { - UPDATE_HZ = 250, /* Hz */ + UPDATE_HZ = 100, /* Hz */ + /* Note: UPDATE_MS < 10ms is not supported by alarm timer, take care !*/ UPDATE_MS = 1000 / UPDATE_HZ, UPDATE_NS = UPDATE_MS * 1000 * 1000, }; @@ -50,48 +42,83 @@ enum { PSUPGLOBALINFOPAGE g_pSUPGlobalInfoPage; -static void _update_tick(PRTTIMER pTimer, void *pvUser, uint64_t iTick) -{ - /** - * We're using rdtsc here since timer_session->elapsed_ms produces - * instable results when the timer service is using the Genode PIC - * driver as done for base-nova currently. - */ - static unsigned long long tsc_last = 0; +class Periodic_GIP : public Genode::Alarm { - unsigned now_low, now_high; - asm volatile("rdtsc" : "=a"(now_low), "=d"(now_high) : : "memory"); + bool on_alarm() + { + /** + * We're using rdtsc here since timer_session->elapsed_ms produces + * instable results when the timer service is using the Genode PIC + * driver as done for base-nova currently. + */ + static unsigned long long tsc_last = 0; - unsigned long long tsc_current = now_high; - tsc_current <<= 32; - tsc_current |= now_low; + Genode::uint32_t now_low, now_high; + asm volatile("rdtsc" : "=a"(now_low), "=d"(now_high) : : "memory"); - unsigned long long elapsed_tsc = tsc_current - tsc_last; - unsigned long elapsed_ms = elapsed_tsc * 1000 / genode_cpu_hz(); - unsigned long long elapsed_nanots = 1000ULL * 1000 * elapsed_ms; + Genode::uint64_t tsc_current = now_high; + tsc_current <<= 32; + tsc_current |= now_low; - tsc_last = tsc_current; + Genode::uint64_t elapsed_tsc; + Genode::uint32_t elapsed_ms; + enum { BOGUS_MULTIPLIER = 10 }; + + /* handle wrap around, backwards running tsc and too bogus timeouts */ + if (tsc_current < tsc_last || + tsc_current - tsc_last > BOGUS_MULTIPLIER * UPDATE_MS * genode_cpu_hz() / 1000) { + +/* + if (tsc_current < tsc_last) + PDBG("bogus timeout - set fixed to %lums - calculated ms %llu " + " - time wrapped", UPDATE_MS, + (tsc_current - tsc_last) * 1000 / genode_cpu_hz()); + else + PDBG("bogus timeout - set fixed to %lums - calculated ms %llu " + " > %u * %lums", UPDATE_MS, + (tsc_current - tsc_last) * 1000 / genode_cpu_hz(), + BOGUS_MULTIPLIER, UPDATE_MS); +*/ + elapsed_ms = UPDATE_MS; + elapsed_tsc = UPDATE_MS * genode_cpu_hz() / 1000; + + } else { + elapsed_tsc = tsc_current - tsc_last; + elapsed_ms = elapsed_tsc * 1000 / genode_cpu_hz(); + } + + Genode::uint64_t elapsed_nanots = 1000ULL * 1000 * elapsed_ms; + + tsc_last = tsc_current; - SUPGIPCPU *cpu = &g_pSUPGlobalInfoPage->aCPUs[0]; + SUPGIPCPU *cpu = &g_pSUPGlobalInfoPage->aCPUs[0]; - cpu->u32TransactionId++; + /* + * Transaction id must be incremented before and after update, + * read struct SUPGIPCPU description for more details. + */ + ASMAtomicIncU32(&cpu->u32TransactionId); - cpu->u64NanoTS += elapsed_nanots; - cpu->u64TSC += elapsed_tsc; + cpu->u64NanoTS += elapsed_nanots; + cpu->u64TSC += elapsed_tsc; - cpu->u32TransactionId++; + /* + * Transaction id must be incremented before and after update, + * read struct SUPGIPCPU description for more details. + */ + ASMAtomicIncU32(&cpu->u32TransactionId); + return true; + } +}; - asm volatile ("":::"memory"); -} - int SUPR3Init(PSUPDRVSESSION *ppSession) { - static bool initialized(false); + static bool initialized = false; if (initialized) return VINF_SUCCESS; @@ -132,10 +159,9 @@ int SUPR3Init(PSUPDRVSESSION *ppSession) cpu->iCpuSet = 0; cpu->idApic = 0; - PRTTIMER pTimer; - - RTTimerCreate(&pTimer, UPDATE_MS, _update_tick, 0); - RTTimerStart(pTimer, 0); + /* schedule periodic call of GIP update function */ + static Periodic_GIP alarm; + Genode::Timeout_thread::alarm_timer()->schedule(&alarm, UPDATE_MS); initialized = true; diff --git a/repos/ports/src/virtualbox/sup.h b/repos/ports/src/virtualbox/sup.h index 36b1db750..ce32a11c7 100644 --- a/repos/ports/src/virtualbox/sup.h +++ b/repos/ports/src/virtualbox/sup.h @@ -15,6 +15,7 @@ #define _SUP_H_ /* Genode includes */ +#include #include "util/misc_math.h" #include "util/string.h" @@ -73,4 +74,6 @@ void inline genode_VMMR0_DO_GVMM_CREATE_VM(PSUPVMMR0REQHDR pReqHdr) req.pVMR3 = pVM; } +Genode::Cpu_session * get_vcpu_cpu_session(); + #endif /* _SUP_H_ */ diff --git a/repos/ports/src/virtualbox/target.mk b/repos/ports/src/virtualbox/target.mk index 9154e8013..1300ed080 100644 --- a/repos/ports/src/virtualbox/target.mk +++ b/repos/ports/src/virtualbox/target.mk @@ -5,7 +5,7 @@ include $(REP_DIR)/lib/mk/virtualbox-common.inc TARGET = virtualbox SRC_CC = main.cc cxx_dummies.cc devices.cc drivers.cc dummies.cc libc.cc \ logger.cc mm.cc pdm.cc pgm.cc rt.cc sup.cc iommio.cc ioport.cc \ - hwaccm.cc thread.cc + hwaccm.cc thread.cc dynlib.cc LIBS += base LIBS += config_args @@ -15,18 +15,29 @@ LIBS += virtualbox-bios virtualbox-recompiler virtualbox-runtime \ virtualbox-storage virtualbox-zlib virtualbox-liblzf \ virtualbox-hwaccl virtualbox-dis +LIBS += pthread libc_terminal libc_lock_pipe libiconv + INC_DIR += $(call select_from_repositories,src/lib/libc) INC_DIR += $(call select_from_repositories,src/lib/pthread) INC_DIR += $(VBOX_DIR)/Runtime/include INC_DIR += $(VBOX_DIR)/Frontends/VBoxBFE -SRC_CC += Frontends/VBoxBFE/VBoxBFE.cpp +# basic frontend SRC_CC += Frontends/VBoxBFE/DisplayImpl.cpp -SRC_CC += Frontends/VBoxBFE/VMMDevInterface.cpp +SRC_CC += Frontends/VBoxBFE/HGCM.cpp +SRC_CC += Frontends/VBoxBFE/HGCMObjects.cpp +SRC_CC += Frontends/VBoxBFE/HGCMThread.cpp SRC_CC += Frontends/VBoxBFE/KeyboardImpl.cpp SRC_CC += Frontends/VBoxBFE/MachineDebuggerImpl.cpp SRC_CC += Frontends/VBoxBFE/StatusImpl.cpp +SRC_CC += Frontends/VBoxBFE/VBoxBFE.cpp +SRC_CC += Frontends/VBoxBFE/VMMDevInterface.cpp + +SRC_CC += HostServices/SharedFolders/service.cpp +SRC_CC += HostServices/SharedFolders/mappings.cpp +SRC_CC += HostServices/SharedFolders/vbsf.cpp +SRC_CC += HostServices/SharedFolders/shflhandle.cpp INC_DIR += $(VBOX_DIR)/Main/include INC_DIR += $(VBOX_DIR)/VMM/include diff --git a/repos/ports/src/virtualbox/thread.cc b/repos/ports/src/virtualbox/thread.cc index 2010be741..4dbd25813 100644 --- a/repos/ports/src/virtualbox/thread.cc +++ b/repos/ports/src/virtualbox/thread.cc @@ -15,6 +15,7 @@ #include #include #include +#include /* Genode libc pthread binding */ #include "thread.h" @@ -26,6 +27,32 @@ /* vbox */ #include +static Genode::Cpu_session * get_cpu_session(RTTHREADTYPE type) { + using namespace Genode; + + static Cpu_connection * con[RTTHREADTYPE_END - 1]; + static Lock lock; + + Assert(type && type < RTTHREADTYPE_END); + + Lock::Guard guard(lock); + + if (con[type - 1]) + return con[type - 1]; + + long const prio = (RTTHREADTYPE_END - type) * + (Cpu_session::PRIORITY_LIMIT / RTTHREADTYPE_END); + + char * data = new (env()->heap()) char[32]; + + snprintf(data, 32, "vbox %u", type); + + con[type - 1] = new (env()->heap()) Cpu_connection(data, prio); + + return con[type - 1]; +} + + extern "C" { /** @@ -34,7 +61,8 @@ extern "C" { */ bool create_emt_vcpu(pthread_t * pthread, size_t stack, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg); + void *(*start_routine) (void *), void *arg, + Genode::Cpu_session *); int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) @@ -52,17 +80,23 @@ extern "C" { PWRN("requested stack for thread '%s' of %zu Bytes is too large, " "limit to %zu Bytes", rtthread->szName, rtthread->cbStack, stack_size); - + + /* sanity check - emt and vcpu thread have to have same prio class */ + if (!Genode::strcmp(rtthread->szName, "EMT")) + Assert(rtthread->enmType == RTTHREADTYPE_EMULATION); + if (rtthread->enmType == RTTHREADTYPE_EMULATION) { - if (create_emt_vcpu(thread, stack_size, attr, start_routine, arg)) + if (create_emt_vcpu(thread, stack_size, attr, start_routine, arg, + get_cpu_session(RTTHREADTYPE_EMULATION))) return 0; /* no haredware support, create normal pthread thread */ } pthread_t thread_obj = new (Genode::env()->heap()) pthread(attr ? *attr : 0, start_routine, - arg, stack_size, rtthread->szName, nullptr); + arg, stack_size, rtthread->szName, + get_cpu_session(rtthread->enmType)); if (!thread_obj) return EAGAIN; diff --git a/repos/ports/src/virtualbox/time-log-deadlock.patch b/repos/ports/src/virtualbox/time-log-deadlock.patch new file mode 100644 index 000000000..9a4a14470 --- /dev/null +++ b/repos/ports/src/virtualbox/time-log-deadlock.patch @@ -0,0 +1,11 @@ ++++ src/app/virtualbox/src/VBox/Runtime/common/log/log.cpp +@@ -3063,7 +3066,8 @@ + { + + #if defined(IN_RING3) || defined(IN_RC) +- uint64_t u64 = RTTimeProgramMicroTS(); ++// uint64_t u64 = RTTimeProgramMicroTS(); ++ uint64_t u64 = 0; + psz += RTStrFormatNumber(psz, (uint32_t)(u64 / RT_US_1HOUR), 10, 2, 0, RTSTR_F_ZEROPAD); + *psz++ = ':'; + uint32_t u32 = (uint32_t)(u64 % RT_US_1HOUR); diff --git a/repos/ports/src/virtualbox/vboxbfe.patch b/repos/ports/src/virtualbox/vboxbfe.patch index fab016c5f..53f99b352 100644 --- a/repos/ports/src/virtualbox/vboxbfe.patch +++ b/repos/ports/src/virtualbox/vboxbfe.patch @@ -11,37 +11,3 @@ #include #include #include -+++ src/app/virtualbox/src/VBox/Frontends/VBoxBFE/VBoxBFE.cpp -@@ -1765,19 +1779,19 @@ - /* - * VMM Device - */ -- rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); UPDATE_RC(); -- rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC(); -- rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC(); -- rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC(); -- rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); UPDATE_RC(); -- rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); UPDATE_RC(); -- rc = CFGMR3InsertInteger(pCfg, "RamSize", g_u32MemorySizeMB * _1M); UPDATE_RC(); -- -- /* the VMM device's Main driver */ -- rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC(); -- rc = CFGMR3InsertString(pLunL0, "Driver", "HGCM"); UPDATE_RC(); -- rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC(); -- rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)gVMMDev); UPDATE_RC(); -+// rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); UPDATE_RC(); -+// rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC(); -+// rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC(); -+// rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC(); -+// rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); UPDATE_RC(); -+// rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); UPDATE_RC(); -+// rc = CFGMR3InsertInteger(pCfg, "RamSize", g_u32MemorySizeMB * _1M); UPDATE_RC(); -+// -+// /* the VMM device's Main driver */ -+// rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC(); -+// rc = CFGMR3InsertString(pLunL0, "Driver", "HGCM"); UPDATE_RC(); -+// rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC(); -+// rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)gVMMDev); UPDATE_RC(); - - /* - * AC'97 ICH audio diff --git a/repos/ports/src/virtualbox/vmm_memory.h b/repos/ports/src/virtualbox/vmm_memory.h index fd8ee1ead..9d34cb1fc 100644 --- a/repos/ports/src/virtualbox/vmm_memory.h +++ b/repos/ports/src/virtualbox/vmm_memory.h @@ -168,28 +168,6 @@ class Vmm_memory } bool unmap_from_vm(RTGCPHYS GCPhys); -/* - { - size_t const size = 1; - - Region *r = _lookup_unsynchronized(GCPhys, size); - if (!r) return false; - - using Genode::addr_t; - addr_t const vmm_local = (addr_t)r->local_addr(); - - Assert(vmm_local); - Assert(!((r->size() - 1) & vmm_local)); - - using namespace Nova; - unsigned const order = Genode::log2(r->size() >> PAGE_SIZE_LOG2); - - Rights rwx(true, true, true); - revoke(Mem_crd(vmm_local >> PAGE_SIZE_LOG2, order, rwx), false); - - return true; - } -*/ }; diff --git a/repos/ports/src/virtualbox/vmmdev.patch b/repos/ports/src/virtualbox/vmmdev.patch index 40e6ffe64..acea3db71 100644 --- a/repos/ports/src/virtualbox/vmmdev.patch +++ b/repos/ports/src/virtualbox/vmmdev.patch @@ -1,5 +1,16 @@ +++ src/app/virtualbox/src/VBox/Devices/VMMDev/VMMDev.cpp -@@ -1854,7 +1854,6 @@ +@@ -770,6 +770,10 @@ + ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER); + + pReq->fEnabled = false; ++ ++ if (!pThis || !pThis->pDrv || !pThis->pDrv->pfnIsPageFusionEnabled) ++ return VINF_SUCCESS; ++ + int rc = pThis->pDrv->pfnIsPageFusionEnabled(pThis->pDrv, &pReq->fEnabled); + if (RT_FAILURE(rc)) + pReq->fEnabled = false; +@@ -1854,7 +1858,6 @@ } break; } @@ -7,7 +18,7 @@ case VMMDevReq_HGCMCancel: { -@@ -1899,6 +1898,7 @@ +@@ -1899,6 +1902,7 @@ } break; } @@ -15,7 +26,7 @@ case VMMDevReq_VideoAccelEnable: { -@@ -3341,8 +3341,10 @@ +@@ -3341,8 +3345,10 @@ /* disabled statistics updating */ pThis->u32LastStatIntervalSize = 0;