├── .gitignore ├── INSTALL ├── LICENSE ├── Makefile ├── README.md ├── pack_and_install.sh ├── vmmon-only ├── COPYING ├── Makefile ├── Makefile.kernel ├── Makefile.normal ├── README ├── autoconf │ └── geninclude.c ├── bootstrap │ ├── bootstrap.c │ ├── monLoader.c │ ├── monLoaderVmmon.c │ └── vmmblob.c ├── common │ ├── apic.c │ ├── apic.h │ ├── comport.c │ ├── comport.h │ ├── cpuid.c │ ├── cpuid.h │ ├── crosspage.c │ ├── crosspage.h │ ├── hostKernel.h │ ├── hostif.h │ ├── hostifGlobalLock.h │ ├── hostifMem.h │ ├── memtrack.c │ ├── memtrack.h │ ├── moduleloop.c │ ├── phystrack.c │ ├── phystrack.h │ ├── sharedAreaVmmon.c │ ├── statVarsVmmon.c │ ├── task.c │ ├── task.h │ ├── vmx86.c │ └── vmx86.h ├── include │ ├── address_defs.h │ ├── addrlayout.h │ ├── addrlayout_table.h │ ├── bootstrap_vmm.h │ ├── community_source.h │ ├── compat_autoconf.h │ ├── compat_kernel.h │ ├── compat_module.h │ ├── compat_page.h │ ├── compat_pgtable.h │ ├── compat_sched.h │ ├── compat_spinlock.h │ ├── compat_version.h │ ├── contextinfo.h │ ├── cpu_defs.h │ ├── cpu_types.h │ ├── crossgdt.h │ ├── driver-config.h │ ├── includeCheck.h │ ├── intelVT.h │ ├── iocontrols.h │ ├── memDefaults.h │ ├── modulecall.h │ ├── monAddrLayout.h │ ├── monLoader.h │ ├── monLoaderLog.h │ ├── mon_assert.h │ ├── mon_constants.h │ ├── msrCache.h │ ├── overheadmem_types.h │ ├── pageLock_defs.h │ ├── perfctr.h │ ├── perfctr_arch.h │ ├── pgtbl.h │ ├── ptsc.h │ ├── rateconv.h │ ├── segs.h │ ├── sharedAreaType.h │ ├── sharedAreaVmmon.h │ ├── statVarsVmmon.h │ ├── uccost.h │ ├── uccostTable.h │ ├── usercalldefs.h │ ├── vcpuid.h │ ├── vcpuset.h │ ├── vcpuset_types.h │ ├── versioned_atomic.h │ ├── virtual_vt.h │ ├── vm_asm.h │ ├── vm_asm_x86.h │ ├── vm_assert.h │ ├── vm_atomic.h │ ├── vm_atomic_acqrel.h │ ├── vm_atomic_relaxed.h │ ├── vm_basic_asm.h │ ├── vm_basic_asm_x86.h │ ├── vm_basic_asm_x86_64.h │ ├── vm_basic_asm_x86_common.h │ ├── vm_basic_defs.h │ ├── vm_basic_math.h │ ├── vm_basic_types.h │ ├── vm_idt.h │ ├── vm_pagetable.h │ ├── vm_time.h │ ├── vmmblob.h │ ├── x86 │ │ └── cpu_types_arch.h │ ├── x86_basic_defs.h │ ├── x86apic.h │ ├── x86cet.h │ ├── x86cpuid.h │ ├── x86cpuid_asm.h │ ├── x86desc.h │ ├── x86msr.h │ ├── x86paging_64.h │ ├── x86paging_common.h │ ├── x86segdescrs.h │ ├── x86sel.h │ ├── x86svm.h │ ├── x86vendor.h │ ├── x86vt-exit-reasons.h │ ├── x86vt-vmcs-fields.h │ ├── x86vt.h │ └── x86vtinstr.h └── linux │ ├── driver.c │ ├── driver.h │ ├── driverLog.c │ ├── driverLog.h │ ├── hostif.c │ ├── hostif_priv.h │ └── vmhost.h └── vmnet-only ├── COPYING ├── Makefile ├── Makefile.kernel ├── Makefile.normal ├── bridge.c ├── community_source.h ├── compat_autoconf.h ├── compat_module.h ├── compat_netdevice.h ├── compat_skbuff.h ├── compat_sock.h ├── compat_version.h ├── driver-config.h ├── driver.c ├── geninclude.c ├── hub.c ├── includeCheck.h ├── net.h ├── netif.c ├── netif_trans_update.c ├── procfs.c ├── smac.c ├── smac.h ├── smac_compat.c ├── smac_compat.h ├── userif.c ├── vm_assert.h ├── vm_atomic.h ├── vm_basic_asm.h ├── vm_basic_asm_x86.h ├── vm_basic_asm_x86_64.h ├── vm_basic_asm_x86_common.h ├── vm_basic_defs.h ├── vm_basic_types.h ├── vm_device_version.h ├── vm_oui.h ├── vmnetInt.h ├── vnet.h ├── vnetEvent.c ├── vnetEvent.h ├── vnetFilter.h ├── vnetInt.h ├── vnetKernel.h └── vnetUserListener.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.mod 3 | *.ko 4 | .*.cmd 5 | *.mod.c 6 | *.tar 7 | .tmp_versions 8 | .cache.mk 9 | Module.symvers 10 | modules.order 11 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | MODULES = vmmon vmnet 2 | SUBDIRS = $(MODULES:%=%-only) 3 | TARBALLS = $(MODULES:%=%.tar) 4 | MODFILES = $(foreach mod,$(MODULES),$(mod)-only/$(mod).ko) 5 | VM_UNAME = $(shell uname -r) 6 | MODDIR = /lib/modules/$(VM_UNAME)/misc 7 | 8 | MODINFO = /sbin/modinfo 9 | DEPMOD = /sbin/depmod 10 | 11 | %.tar: FORCE gitcleancheck 12 | git archive -o $@ --format=tar HEAD $(@:.tar=-only) 13 | 14 | .PHONY: FORCE subdirs $(SUBDIRS) clean tarballs 15 | 16 | subdirs: retiredcheck $(SUBDIRS) 17 | 18 | FORCE: 19 | 20 | $(SUBDIRS): 21 | $(MAKE) -C $@ $(MAKECMDGOALS) 22 | 23 | gitcheck: 24 | @git status >/dev/null 2>&1 \ 25 | || ( echo "This only works in a git repository."; exit 1 ) 26 | 27 | gitcleancheck: gitcheck 28 | @git diff --exit-code HEAD >/dev/null 2>&1 \ 29 | || echo "Warning: tarballs will reflect current HEAD (no uncommited changes)" 30 | 31 | retiredcheck: 32 | @test -f RETIRED && cat RETIRED || true 33 | 34 | install: retiredcheck $(MODFILES) 35 | @for f in $(MODFILES); do \ 36 | mver=$$($(MODINFO) -F vermagic $$f);\ 37 | mver=$${mver%% *};\ 38 | test "$${mver}" = "$(VM_UNAME)" \ 39 | || ( echo "Version mismatch: module $$f $${mver}, kernel $(VM_UNAME)" ; exit 1 );\ 40 | done 41 | install -D -t $(DESTDIR)$(MODDIR) $(MODFILES) 42 | strip --strip-debug $(MODULES:%=$(DESTDIR)$(MODDIR)/%.ko) 43 | if test -z "$(DESTDIR)"; then $(DEPMOD) -a $(VM_UNAME); fi 44 | 45 | clean: $(SUBDIRS) 46 | rm -f *.o 47 | 48 | tarballs: $(TARBALLS) 49 | 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VMWare host modules fork 2 | 3 | My fork of the [VMWare host modules](https://github.com/mkubecek/vmware-host-modules) repository, with some changes: 4 | 5 | - updated to the lastest Workstation Pro version (17.6.0) 6 | - applied @nan0desus' patches (allow compiling on 6.9+ kernels, and fix an out-of-bounds bug) 7 | - applied a patch to fix spurious network disconnections (from fluentreports.com) 8 | - added a small script to pack and install the patched modules 9 | 10 | The master branch contains the latest Workstation version with the patches. For each patched version, there is a branch named `workstation-$vmware_version-sav`. 11 | -------------------------------------------------------------------------------- /pack_and_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o pipefail 4 | set -o errexit 5 | set -o nounset 6 | set -o errtrace 7 | shopt -s inherit_errexit 8 | 9 | make tarballs 10 | sudo chown root: ./*.tar 11 | 12 | if [[ ! -f /usr/lib/vmware/modules/source/vmmon.tar.bak ]]; then 13 | sudo cp -av /usr/lib/vmware/modules/source/vmmon.tar{,.bak} 14 | fi 15 | if [[ ! -f /usr/lib/vmware/modules/source/vmnet.tar.bak ]]; then 16 | sudo cp -av /usr/lib/vmware/modules/source/vmnet.tar{,.bak} 17 | fi 18 | 19 | sudo mv -vf ./*.tar /usr/lib/vmware/modules/source/ 20 | 21 | sudo vmware-modconfig --console --install-all 22 | -------------------------------------------------------------------------------- /vmmon-only/Makefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | ########################################################## 3 | # Copyright (C) 1998-2020 VMware, Inc. All rights reserved. 4 | # 5 | # This program is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU General Public License as published by the 7 | # Free Software Foundation version 2 and no later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, but 10 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | # for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | ########################################################## 19 | 20 | #### 21 | #### VMware kernel module Makefile to be distributed externally 22 | #### 23 | 24 | #### 25 | #### SRCROOT _must_ be a relative path. 26 | #### 27 | SRCROOT = . 28 | 29 | # 30 | # open-vm-tools doesn't replicate shared source files for different modules; 31 | # instead, files are kept in shared locations. So define a few useful macros 32 | # to be able to handle both cases cleanly. 33 | # 34 | INCLUDE := 35 | ifdef OVT_SOURCE_DIR 36 | AUTOCONF_DIR := $(OVT_SOURCE_DIR)/modules/linux/shared/autoconf 37 | VMLIB_PATH = $(OVT_SOURCE_DIR)/lib/$(1) 38 | INCLUDE += -I$(OVT_SOURCE_DIR)/modules/linux/shared 39 | INCLUDE += -I$(OVT_SOURCE_DIR)/lib/include 40 | else 41 | AUTOCONF_DIR := $(SRCROOT)/shared/autoconf 42 | INCLUDE += -I$(SRCROOT)/shared 43 | endif 44 | 45 | 46 | VM_UNAME = $(shell uname -r) 47 | 48 | # Header directory for the running kernel 49 | ifdef LINUXINCLUDE 50 | HEADER_DIR = $(LINUXINCLUDE) 51 | else 52 | HEADER_DIR = /lib/modules/$(VM_UNAME)/build/include 53 | endif 54 | 55 | BUILD_DIR = $(HEADER_DIR)/.. 56 | 57 | DRIVER := vmmon 58 | PRODUCT := @@PRODUCT@@ 59 | 60 | # Grep program 61 | GREP = /bin/grep 62 | 63 | vm_check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ 64 | > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi) 65 | vm_check_file = $(shell if test -f $(1); then echo "yes"; else echo "no"; fi) 66 | 67 | ifndef VM_KBUILD 68 | VM_KBUILD := no 69 | ifeq ($(call vm_check_file,$(BUILD_DIR)/Makefile), yes) 70 | VM_KBUILD := yes 71 | endif 72 | export VM_KBUILD 73 | endif 74 | 75 | ifndef VM_KBUILD_SHOWN 76 | ifeq ($(VM_KBUILD), no) 77 | VM_DUMMY := $(shell echo >&2 "Using standalone build system.") 78 | else 79 | VM_DUMMY := $(shell echo >&2 "Using kernel build system.") 80 | endif 81 | VM_KBUILD_SHOWN := yes 82 | export VM_KBUILD_SHOWN 83 | endif 84 | 85 | ifneq ($(VM_KBUILD), no) 86 | 87 | # If there is no version defined, we are in toplevel pass, not yet in kernel makefiles... 88 | ifeq ($(VERSION),) 89 | 90 | DRIVER_KO := $(DRIVER).ko 91 | 92 | .PHONY: $(DRIVER_KO) 93 | 94 | auto-build: $(DRIVER_KO) 95 | cp -f $< $(SRCROOT)/../$(DRIVER).o 96 | 97 | # $(DRIVER_KO) is a phony target, so compare file times explicitly 98 | $(DRIVER): $(DRIVER_KO) 99 | if [ $< -nt $@ ] || [ ! -e $@ ] ; then cp -f $< $@; fi 100 | 101 | # Use SUBDIRS on 2.x, 3.x, 4.x. Use M on newer kernels. 102 | ifeq ($(filter-out 2 3 4,$(firstword $(subst ., ,$(VM_UNAME)))),) 103 | DIRVAR := SUBDIRS 104 | else 105 | DIRVAR := M 106 | endif 107 | 108 | # 109 | # Define a setup target that gets built before the actual driver. 110 | # This target may not be used at all, but if it is then it will be defined 111 | # in Makefile.kernel 112 | # 113 | prebuild:: ; 114 | postbuild:: ; 115 | 116 | $(DRIVER_KO): prebuild 117 | $(MAKE) -C $(BUILD_DIR) $(DIRVAR)=$$PWD SRCROOT=$$PWD/$(SRCROOT) \ 118 | MODULEBUILDDIR=$(MODULEBUILDDIR) modules 119 | $(MAKE) -C $$PWD SRCROOT=$$PWD/$(SRCROOT) \ 120 | MODULEBUILDDIR=$(MODULEBUILDDIR) postbuild 121 | endif 122 | 123 | vm_check_build = $(shell if $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ 124 | $(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) $(LINUXINCLUDE) \ 125 | $(EXTRA_CFLAGS) -Iinclude2/asm/mach-default \ 126 | -DKBUILD_BASENAME=\"$(DRIVER)\" \ 127 | -Werror -S -o /dev/null -xc $(1) \ 128 | > /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi) 129 | 130 | CC_WARNINGS := -Wall -Wstrict-prototypes 131 | CC_OPTS := $(GLOBAL_DEFS) $(CC_WARNINGS) -DVMW_USING_KBUILD 132 | ifdef VMX86_DEVEL 133 | CC_OPTS += -DVMX86_DEVEL 134 | endif 135 | ifdef VMX86_DEBUG 136 | CC_OPTS += -DVMX86_DEBUG 137 | endif 138 | 139 | # Add Spectre options when available 140 | 141 | include $(SRCROOT)/Makefile.kernel 142 | 143 | else 144 | 145 | include $(SRCROOT)/Makefile.normal 146 | 147 | endif 148 | 149 | #.SILENT: 150 | -------------------------------------------------------------------------------- /vmmon-only/Makefile.kernel: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | ########################################################## 3 | # Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 4 | # The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 5 | # 6 | # This program is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU General Public License as published by the 8 | # Free Software Foundation version 2 and no later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, but 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | # for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | # 19 | ########################################################## 20 | 21 | CC_OPTS += -DVMMON -DVMCORE 22 | 23 | INCLUDE := -I$(SRCROOT)/include -I$(SRCROOT)/include/x86 -I$(SRCROOT)/common -I$(SRCROOT)/linux 24 | EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE) 25 | 26 | obj-m += $(DRIVER).o 27 | 28 | $(DRIVER)-y := $(subst $(SRCROOT)/, , $(patsubst %.c, %.o, \ 29 | $(wildcard $(SRCROOT)/linux/*.c $(SRCROOT)/common/*.c \ 30 | $(SRCROOT)/bootstrap/*.c))) 31 | 32 | clean: 33 | rm -rf $(wildcard $(DRIVER).mod.c $(DRIVER).ko .tmp_versions .cache.mk \ 34 | Module.symvers Modules.symvers Module.markers modules.order \ 35 | $(foreach dir,linux/ common/ bootstrap/ \ 36 | ./,$(addprefix $(dir),.*.cmd .*.o.flags *.o))) 37 | -------------------------------------------------------------------------------- /vmmon-only/Makefile.normal: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | ########################################################## 3 | # Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 4 | # The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 5 | # 6 | # This program is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU General Public License as published by the 8 | # Free Software Foundation version 2 and no later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, but 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | # for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | # 19 | ########################################################## 20 | 21 | vm_check_build = $(shell if $(CC) $(CC_OPTS) $(INCLUDE) -Werror -S -o /dev/null -xc $(1) \ 22 | > /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi) 23 | 24 | #### 25 | #### DESTDIR is where the module, object files, and dependencies are built 26 | #### 27 | DESTDIR := driver-$(VM_UNAME) 28 | 29 | #### 30 | #### DRIVERNAME should be untouched unless you have a good reason to change 31 | #### it. The form below is how the scripts expect it. 32 | #### 33 | DRIVERNAME := $(DRIVER)-xxx-$(VM_UNAME) 34 | 35 | ifneq (,$(filter x86_64%, $(shell $(CC) -dumpmachine))) 36 | MACHINE := x86_64 37 | else 38 | MACHINE := x386 39 | endif 40 | 41 | ifdef QUIET 42 | ECHO := @true 43 | else 44 | ECHO := @echo 45 | endif 46 | 47 | #### 48 | #### You must compile with at least -O level of optimization 49 | #### or the module won't load. 50 | #### If desparate, I think that bringing in might 51 | #### suffice. 52 | #### 53 | CC_WARNINGS := -Wall -Wstrict-prototypes 54 | # Don't use -pipe or egcs-2.91.66 (shipped with RedHat) will die 55 | CC_KFLAGS := -D__KERNEL__ -fno-strength-reduce -fno-omit-frame-pointer \ 56 | -fno-common -DKBUILD_MODNAME=$(DRIVER) 57 | CC_KFLAGS += $(call vm_check_gcc,-falign-loops=2 -falign-jumps=2 -falign-functions=2, \ 58 | -malign-loops=2 -malign-jumps=2 -malign-functions=2) 59 | CC_KFLAGS += $(call vm_check_gcc,-fno-strict-aliasing,) 60 | ifeq ($(MACHINE),x86_64) 61 | CC_KFLAGS += -mno-red-zone -mcmodel=kernel 62 | else 63 | # Gcc 3.0 deprecates -m486 --hpreg 64 | CC_KFLAGS += -DCPU=586 $(call check_gcc,-march=i586,-m486) 65 | endif 66 | 67 | CC_OPTS := -O2 -DMODULE -DVMMON -DVMCORE $(GLOBAL_DEFS) $(CC_KFLAGS) $(CC_WARNINGS) 68 | 69 | INCLUDE := -I$(SRCROOT)/include -I$(SRCROOT)/common -I$(SRCROOT)/linux \ 70 | -I$(HEADER_DIR) 71 | 72 | INCLUDE += $(shell $(CC) $(INCLUDE) -E $(SRCROOT)/autoconf/geninclude.c \ 73 | | sed -n -e 's!^APATH!-I$(HEADER_DIR)/asm!p') 74 | 75 | C_TARGETS_LINUX := driver.o hostif.o driverLog.o 76 | C_TARGETS_COMMON := vmx86.o memtrack.o phystrack.o cpuid.o task.o crosspage.o moduleloop.o 77 | C_TARGETS_BOOTSTRAP := bootstrap.o 78 | C_TARGETS_LINUX_D := ${C_TARGETS_LINUX:.o=.d} 79 | C_TARGETS_COMMON_D := ${C_TARGETS_COMMON:.o=.d} 80 | C_TARGETS_BOOTSTRAP_D := ${C_TARGETS_BOOTSTRAP:.o=.d} 81 | C_TARGETS := $(C_TARGETS_LINUX) $(C_TARGETS_COMMON) $(C_TARGETS_BOOTSTRAP) 82 | 83 | #### 84 | #### Make Targets are beneath here. 85 | #### 86 | 87 | driver: setup deps 88 | $(MAKE) -C $(DESTDIR) -f ../Makefile SRCROOT=../$(SRCROOT) $(DRIVER).o \ 89 | INCLUDE_DEPS=1 90 | 91 | setup: 92 | @if [ -d $(DESTDIR) ] ; then true ; else mkdir $(DESTDIR); chmod 755 $(DESTDIR) ; fi 93 | 94 | $(DRIVER) $(DRIVER).o: $(DRIVERNAME) 95 | cp -f $< $@ 96 | 97 | $(DRIVERNAME): $(C_TARGETS) 98 | $(ECHO) "Building $(DRIVERNAME)" 99 | ld -r -o $(DRIVERNAME) $(C_TARGETS) 100 | 101 | auto-build: 102 | $(MAKE) driver QUIET=1 103 | cp -f $(DESTDIR)/$(DRIVERNAME) $(SRCROOT)/../$(DRIVER).o 104 | 105 | $(C_TARGETS_LINUX): %.o: $(SRCROOT)/linux/%.c 106 | $(ECHO) "Compiling linux/$( $@ 123 | 124 | $(C_TARGETS_LINUX_D): %.d: $(SRCROOT)/linux/%.c 125 | $(ECHO) "Dependencies for $( $@ 127 | 128 | $(C_TARGETS_BOOTSTRAP_D): %.d: $(SRCROOT)/bootstrap/%.c 129 | $(ECHO) "Dependencies for $( $@ 131 | 132 | deps: setup 133 | $(MAKE) -C $(DESTDIR) -f ../Makefile SRCROOT=../$(SRCROOT) driver_deps 134 | 135 | driver_deps: ${C_TARGETS:.o=.d} 136 | 137 | ifdef INCLUDE_DEPS 138 | include ${C_TARGETS:.o=.d} 139 | endif 140 | 141 | .SILENT: 142 | -------------------------------------------------------------------------------- /vmmon-only/README: -------------------------------------------------------------------------------- 1 | This files in this directory and its subdirectories are the kernel module 2 | portion of the VMware Virtual Machine Monitor. In order to build, make 3 | certain the Makefile is correct, especially in whether or not your system 4 | is multi-processor and then just type 5 | 6 | make 7 | 8 | from this directory. A copy of the module will be left in 9 | 10 | driver-/vmmon.o 11 | 12 | (e.g. driver-up-2.0.32/vmmon.o). 13 | 14 | If you have any problems or questions, send mail to support@vmware.com 15 | -------------------------------------------------------------------------------- /vmmon-only/autoconf/geninclude.c: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2003 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #include "compat_version.h" 20 | #include "compat_autoconf.h" 21 | 22 | #ifdef CONFIG_X86_VOYAGER 23 | APATH/mach-voyager 24 | #endif 25 | #ifdef CONFIG_X86_VISWS 26 | APATH/mach-visws 27 | #endif 28 | #ifdef CONFIG_X86_NUMAQ 29 | APATH/mach-numaq 30 | #endif 31 | #ifdef CONFIG_X86_BIGSMP 32 | APATH/mach-bigsmp 33 | #endif 34 | #ifdef CONFIG_X86_SUMMIT 35 | APATH/mach-summit 36 | #endif 37 | #ifdef CONFIG_X86_GENERICARCH 38 | APATH/mach-generic 39 | #endif 40 | APATH/mach-default 41 | 42 | -------------------------------------------------------------------------------- /vmmon-only/bootstrap/bootstrap.c: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2015,2023 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * bootstrap.c -- 21 | * 22 | * Implements the early VMM bootstraping code that is executed 23 | * by the host (vmmon/VMKernel) to create the VMM context. 24 | */ 25 | 26 | #if !defined VMKERNEL || defined VMK_HAS_VMM 27 | #include "vm_basic_types.h" 28 | #include "vm_basic_defs.h" 29 | #include "bootstrap_vmm.h" 30 | 31 | /* 32 | *--------------------------------------------------------------------- 33 | * 34 | * BSVMM_Validate -- 35 | * 36 | * Validates the VMM bootstrap blob. For now, we do it by checking 37 | * the magic number. Returns the bootstrap parameter table if 38 | * successful, NULL otherwise. 39 | * 40 | *--------------------------------------------------------------------- 41 | */ 42 | BSVMM_HostParams * 43 | BSVMM_Validate(void *buf, uint32 nbytes) 44 | { 45 | BSVMM_HostParams *bsParams = buf; 46 | 47 | if (nbytes < sizeof *bsParams) { 48 | return NULL; 49 | } 50 | if (bsParams->magic != BOOTSTRAP_MAGIC) { 51 | return NULL; 52 | } 53 | return bsParams; 54 | } 55 | #endif 56 | -------------------------------------------------------------------------------- /vmmon-only/common/apic.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2011-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * apic.h -- 22 | * 23 | * Some host APIC helper functions 24 | */ 25 | 26 | #ifndef APIC_H 27 | #define APIC_H 28 | 29 | #define INCLUDE_ALLOW_VMMON 30 | #define INCLUDE_ALLOW_VMCORE 31 | #include "includeCheck.h" 32 | 33 | #include "vm_basic_types.h" 34 | 35 | typedef struct { 36 | Bool isX2; 37 | volatile uint32 (*base)[4]; 38 | } APICDescriptor; 39 | 40 | MA APIC_GetMA(void); 41 | uint32 APIC_Read(const APICDescriptor *desc, int regNum); 42 | void APIC_Write(const APICDescriptor *desc, int regNum, uint32 val); 43 | void APIC_WriteICR(const APICDescriptor *desc, uint32 id, uint32 icrLo); 44 | uint64 APIC_ReadICR(const APICDescriptor *desc); 45 | uint32 APIC_ReadID(const APICDescriptor *desc); 46 | uint32 APIC_MaxLVT(const APICDescriptor *desc); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /vmmon-only/common/comport.c: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2006-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * comport.c -- 22 | * 23 | * Simple COM1 port routines for debugging code that can't do any real 24 | * host IO, such as the worldswitch and related. 25 | * 26 | * They all wait for the last character to complete transmission so if the 27 | * system crashes immediately on return, the last character will be seen 28 | * by the remote end. 29 | * 30 | * These routines do not have any external dependencies so can be called 31 | * by any code that has privilege to access IO ports. 32 | * 33 | * Under Windows, they can be made to forward output to DbgPrint for 34 | * printing via the debugger. Just have USE_DBGPRINT set to 1. If you 35 | * let USE_DBGPRINT be 0 with Windows, make sure the comport hardware is 36 | * powered-up by leaving Hyperterm running with the comport open, else 37 | * Windows will power the chip down. 38 | */ 39 | 40 | #include "comport.h" 41 | #include "vm_basic_asm.h" // for INB, OUTB 42 | 43 | #if 000 // defined(_MSC_VER) 44 | #define USE_DBGPRINT 1 45 | #else 46 | #define USE_DBGPRINT 0 47 | #endif 48 | 49 | #if USE_DBGPRINT 50 | void DbgPrint(char const *format, ...); 51 | #else 52 | #define IOBASE 0x3F8 // COM1 base IO port number 53 | #define BAUD 115200 // baud rate 54 | #define THR 0 // transmitter holding register 55 | #define LSR 5 // line status register 56 | #define LSR_TE 0x20 // - transmit fifo completely empty 57 | #define LSR_TI 0x40 // - transmitter idle 58 | #endif 59 | 60 | 61 | void 62 | CP_Init(void) 63 | { 64 | #if !USE_DBGPRINT 65 | OUTB(IOBASE+3, 0x83); // LCR=select DLL/DLH, wordlen=8 bits 66 | OUTB(IOBASE+0, (115200/BAUD)&255); // DLL=lo order baud rate 67 | OUTB(IOBASE+1, (115200/BAUD)/256); // DLH=hi order baud rate 68 | OUTB(IOBASE+3, 0x03); // LCR=select RBR/THR/IER 69 | OUTB(IOBASE+4, 0x07); // MCR=dtr, rts, port-enable 70 | OUTB(IOBASE+2, 0x07); // FCR=reset rcv fifo, reset xmt fifo 71 | OUTB(IOBASE+1, 0); // IER=disable all interrupts 72 | #endif 73 | } 74 | 75 | 76 | void 77 | CP_PutChr(uint8 ch) // IN 78 | { 79 | #if USE_DBGPRINT 80 | DbgPrint("%c", ch); 81 | #else 82 | if (ch == '\n') CP_PutChr('\r'); 83 | while ((INB(IOBASE+LSR) & LSR_TE) == 0) { } 84 | OUTB(IOBASE+THR, ch); 85 | while ((INB(IOBASE+LSR) & LSR_TI) == 0) { } 86 | #endif 87 | } 88 | 89 | 90 | void 91 | CP_PutDec(uint32 value) // IN 92 | { 93 | #if USE_DBGPRINT 94 | DbgPrint("%u", value); 95 | #else 96 | char s[12]; 97 | int i; 98 | 99 | i = 0; 100 | do { 101 | s[i++] = (value % 10) + '0'; 102 | value /= 10; 103 | } while (value > 0); 104 | while (--i >= 0) CP_PutChr(s[i]); 105 | #endif 106 | } 107 | 108 | 109 | void 110 | CP_PutHexPtr(void *value) // IN 111 | { 112 | if (sizeof value == 8) { 113 | CP_PutHex64((uint64)(VA)value); 114 | } 115 | if (sizeof value == 4) { 116 | CP_PutHex32((uint32)(VA)value); 117 | } 118 | } 119 | 120 | 121 | void 122 | CP_PutHex64(uint64 value) // IN 123 | { 124 | CP_PutHex32((uint32)(value >> 32)); 125 | CP_PutHex32((uint32)value); 126 | } 127 | 128 | 129 | void 130 | CP_PutHex32(uint32 value) // IN 131 | { 132 | #if USE_DBGPRINT 133 | DbgPrint("%8.8X", value); 134 | #else 135 | CP_PutHex16((uint16)(value >> 16)); 136 | CP_PutHex16((uint16)value); 137 | #endif 138 | } 139 | 140 | 141 | void 142 | CP_PutHex16(uint16 value) // IN 143 | { 144 | #if USE_DBGPRINT 145 | DbgPrint("%4.4X", value); 146 | #else 147 | CP_PutHex8((uint8)(value >> 8)); 148 | CP_PutHex8((uint8)value); 149 | #endif 150 | } 151 | 152 | 153 | void 154 | CP_PutHex8(uint8 value) // IN 155 | { 156 | #if USE_DBGPRINT 157 | DbgPrint("%2.2X", value); 158 | #else 159 | CP_PutChr("0123456789ABCDEF"[(value>>4)&15]); 160 | CP_PutChr("0123456789ABCDEF"[value&15]); 161 | #endif 162 | } 163 | 164 | 165 | void 166 | CP_PutSp(void) 167 | { 168 | CP_PutChr(' '); 169 | } 170 | 171 | 172 | void 173 | CP_PutCrLf(void) 174 | { 175 | CP_PutChr('\n'); 176 | } 177 | 178 | 179 | void 180 | CP_PutStr(char const *s) // IN 181 | { 182 | #if USE_DBGPRINT 183 | DbgPrint("%s", s); 184 | #else 185 | char c; 186 | 187 | while ((c = *(s ++)) != 0) { 188 | CP_PutChr(c); 189 | } 190 | #endif 191 | } 192 | -------------------------------------------------------------------------------- /vmmon-only/common/comport.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2006 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef _COMPORT_H 20 | #define _COMPORT_H 21 | 22 | #define INCLUDE_ALLOW_VMCORE 23 | #define INCLUDE_ALLOW_VMMON 24 | #define INCLUDE_ALLOW_VMX 25 | #include "includeCheck.h" 26 | 27 | #include "vm_basic_types.h" // for uint8, et al 28 | 29 | void CP_Init(void); 30 | void CP_PutChr(uint8 ch); 31 | void CP_PutDec(uint32 value); 32 | void CP_PutHexPtr(void *value); 33 | void CP_PutHex64(uint64 value); 34 | void CP_PutHex32(uint32 value); 35 | void CP_PutHex16(uint16 value); 36 | void CP_PutHex8(uint8 value); 37 | void CP_PutSp(void); 38 | void CP_PutCrLf(void); 39 | void CP_PutStr(char const *s); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /vmmon-only/common/cpuid.c: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | #ifdef __linux__ 21 | /* Must come before any kernel header file --hpreg */ 22 | # include "driver-config.h" 23 | 24 | # include 25 | #endif 26 | 27 | #include "vm_assert.h" 28 | #include "hostif.h" 29 | #include "cpuid.h" 30 | #include "x86cpuid_asm.h" 31 | #include "x86svm.h" 32 | #include "x86vt.h" 33 | 34 | uint32 cpuidFeatures; 35 | CpuidVendor cpuidVendor = CPUID_NUM_VENDORS; 36 | uint32 cpuidVersion; 37 | Bool hostSupportsVT; 38 | Bool hostSupportsSVM; 39 | Bool hostHasSpecCtrl; 40 | Bool hostSupportsXSave; 41 | 42 | 43 | /* 44 | *----------------------------------------------------------------------------- 45 | * 46 | * CPUIDExtendedSupported -- 47 | * 48 | * Determine whether processor supports extended CPUID (0x8000xxxx) 49 | * and how many of them. 50 | * 51 | * Results: 52 | * 0 if extended CPUID is not supported 53 | * otherwise maximum extended CPUID supported (bit 31 set) 54 | * 55 | * Side effects: 56 | * None. 57 | * 58 | *----------------------------------------------------------------------------- 59 | */ 60 | 61 | static uint32 62 | CPUIDExtendedSupported(void) 63 | { 64 | uint32 eax; 65 | 66 | eax = __GET_EAX_FROM_CPUID(0x80000000); 67 | if ((eax & 0x80000000) != 0x80000000) { 68 | return 0; 69 | } 70 | 71 | return eax; 72 | } 73 | 74 | 75 | void 76 | CPUID_Init(void) 77 | { 78 | CPUIDRegs regs, regs72, regs88; 79 | uint32 *ptr; 80 | char name[16]; 81 | 82 | __GET_CPUID(1, ®s); 83 | cpuidVersion = regs.eax; 84 | cpuidFeatures = regs.edx; 85 | hostSupportsXSave = CPUID_ISSET(1, ECX, XSAVE, regs.ecx); 86 | 87 | __GET_CPUID(0, ®s); 88 | ptr = (uint32 *)name; 89 | ptr[0] = regs.ebx; 90 | ptr[1] = regs.edx; 91 | ptr[2] = regs.ecx; 92 | ptr[3] = 0; 93 | 94 | if (strcmp(name, CPUID_INTEL_VENDOR_STRING_FIXED) == 0) { 95 | cpuidVendor = CPUID_VENDOR_INTEL; 96 | } else if (strcmp(name, CPUID_AMD_VENDOR_STRING_FIXED) == 0) { 97 | cpuidVendor = CPUID_VENDOR_AMD; 98 | } else if (strcmp(name, CPUID_CYRIX_VENDOR_STRING_FIXED) == 0) { 99 | cpuidVendor = CPUID_VENDOR_CYRIX; 100 | } else if (strcmp(name, CPUID_HYGON_VENDOR_STRING_FIXED) == 0) { 101 | cpuidVendor = CPUID_VENDOR_HYGON; 102 | } else { 103 | Warning("VMMON CPUID: Unrecognized CPU\n"); 104 | cpuidVendor = CPUID_VENDOR_UNKNOWN; 105 | } 106 | 107 | __GET_CPUID2(7, 0, ®s); 108 | __GET_CPUID2(7, 2, ®s72); 109 | __GET_CPUID2(0x80000008, 0, ®s88); 110 | hostHasSpecCtrl = CPUID_ISSET(7, EDX, IBRSIBPB, regs.edx) || 111 | CPUID_ISSET(7, EDX, STIBP, regs.edx) || 112 | CPUID_ISSET(7, EDX, SSBD, regs.edx) || 113 | CPUID_ISSET(7, EDX, PSFD, regs72.edx) || 114 | CPUID_ISSET(0x80000008, EBX, LEAF88_SSBD_SPEC_CTRL, 115 | regs88.ebx) || 116 | CPUID_ISSET(0x80000008, EBX, LEAF88_PSFD, regs88.ebx); 117 | 118 | hostSupportsVT = VT_CapableCPU(); 119 | hostSupportsSVM = SVM_CapableCPU(); 120 | } 121 | 122 | 123 | /* 124 | *----------------------------------------------------------------------------- 125 | * 126 | * CPUID_AddressSizeSupported -- 127 | * 128 | * Determine whether processor supports the address size cpuid 129 | * extended leaf. 130 | * 131 | * Results: 132 | * True iff the processor supports CPUID 0x80000008. 133 | * 134 | * Side effects: 135 | * It determines value only on first call, caching it for future. 136 | * 137 | *----------------------------------------------------------------------------- 138 | */ 139 | 140 | Bool 141 | CPUID_AddressSizeSupported(void) 142 | { 143 | /* 144 | * It is OK to use local static variables here as 'result' does not depend 145 | * on any work done in CPUID_Init(). It purely depends on the CPU. 146 | */ 147 | static Bool initialized = FALSE; 148 | static Bool result; 149 | 150 | if (UNLIKELY(!initialized)) { 151 | result = CPUIDExtendedSupported() >= 0x80000008; 152 | initialized = TRUE; 153 | } 154 | 155 | return result; 156 | } 157 | -------------------------------------------------------------------------------- /vmmon-only/common/cpuid.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * cpuid.h -- 22 | * 23 | * wrap CPUID instruction 24 | */ 25 | 26 | #ifndef CPUID_H 27 | #define CPUID_H 28 | 29 | #define INCLUDE_ALLOW_VMMON 30 | #define INCLUDE_ALLOW_VMCORE 31 | #include "includeCheck.h" 32 | 33 | #include "x86cpuid.h" 34 | 35 | extern uint32 cpuidFeatures; 36 | extern uint32 cpuidVersion; 37 | extern CpuidVendor cpuidVendor; 38 | extern Bool hostSupportsVT; 39 | extern Bool hostSupportsSVM; 40 | extern Bool hostHasSpecCtrl; 41 | extern Bool hostSupportsXSave; 42 | 43 | void CPUID_Init(void); 44 | Bool CPUID_AddressSizeSupported(void); 45 | 46 | static INLINE uint32 47 | CPUID_GetFeatures(void) 48 | { 49 | return cpuidFeatures; 50 | } 51 | 52 | static INLINE CpuidVendor 53 | CPUID_GetVendor(void) 54 | { 55 | ASSERT(cpuidVendor != CPUID_NUM_VENDORS); 56 | return cpuidVendor; 57 | } 58 | 59 | static INLINE uint32 60 | CPUID_GetVersion(void) 61 | { 62 | return cpuidVersion; 63 | } 64 | 65 | static INLINE Bool 66 | CPUID_HostSupportsVT(void) 67 | { 68 | return hostSupportsVT; 69 | } 70 | 71 | static INLINE Bool 72 | CPUID_HostSupportsSVM(void) 73 | { 74 | return hostSupportsSVM; 75 | } 76 | 77 | static INLINE Bool 78 | CPUID_HostSupportsHV(void) 79 | { 80 | return hostSupportsVT || hostSupportsSVM; 81 | } 82 | 83 | static INLINE Bool 84 | CPUID_HostSupportsSpecCtrl(void) 85 | { 86 | return hostHasSpecCtrl; 87 | } 88 | 89 | static INLINE Bool 90 | CPUID_HostSupportsXSave(void) 91 | { 92 | return hostSupportsXSave; 93 | } 94 | 95 | static INLINE Bool 96 | CPUID_SSE2Supported(void) 97 | { 98 | return CPUID_ISSET(1, EDX, SSE2, CPUID_GetFeatures()); 99 | } 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /vmmon-only/common/crosspage.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2020-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | #ifndef _CROSSPAGE_H_ 21 | #define _CROSSPAGE_H_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | struct VMCrossPageData; 28 | 29 | extern void HostToVmm(struct VMCrossPageData *crosspageWIN, void *unused1, 30 | void *unused2, struct VMCrossPageData *crosspageSYSV); 31 | extern void CrossPageInitSwitchIDTs(struct VMCrossPageData *cpData); 32 | 33 | extern void CrossPage_CodePage(void); 34 | extern void CrossPage_CodeEnd(void); 35 | extern const VMCrossPageData cpDataTemplate; 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /vmmon-only/common/hostKernel.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * hostKernel.h -- 22 | * 23 | * Definition of HOST_KERNEL_* --hpreg 24 | */ 25 | 26 | 27 | #ifndef __HOST_KERNEL_H__ 28 | # define __HOST_KERNEL_H__ 29 | 30 | 31 | # ifdef __linux__ 32 | /* 33 | * In some cases, this files needs to include Linux kernel header file 34 | * asm/page.h. 35 | * 36 | * However, asm/page.h defines PAGE_SHIFT, PAGE_SIZE, PAGE_MASK, PAGE_OFFSET 37 | * and VMware header file vm_basic_types.h defines PAGE_SHIFT, PAGE_SIZE, 38 | * PAGE_MASK, PAGE_OFFSET. PAGE_MASK and PAGE_OFFSET are defined differently 39 | * (XXX we should really prefix the VMware version with VM_ to prevent any 40 | * further confusion), but fortunately the driver does not use them. 41 | * 42 | * So in this file, we must solve the definition conflict for files that 43 | * include both this file and vm_basic_types.h. 2 cases can occur: 44 | * 45 | * 1) this file is included before vm_basic_types.h is included. This is fine, 46 | * because vm_basic_types.h only defines PAGE_* if they don't exist yet. 47 | * 48 | * 2) vm_basic_types.h is included before this file is included. 49 | * We must undefine 50 | * PAGE_* in between. But this only works if asm/page.h is not included 51 | * before this file is included. 52 | * 53 | * In summary: if you make sure you do not include asm/page.h before you 54 | * include this file, then we guarantee that: 55 | * . This file and vm_basic_types.h can be included in any order 56 | * . asm/page.h will be included 57 | * . The PAGE_* definitions will come from asm/page.h 58 | * 59 | * --hpreg 60 | */ 61 | 62 | /* Must come before any kernel header file --hpreg */ 63 | # include "driver-config.h" 64 | 65 | # undef PAGE_SHIFT 66 | # undef PAGE_SIZE 67 | # undef PAGE_MASK 68 | # undef PAGE_OFFSET 69 | 70 | /* For __PAGE_OFFSET --hpreg */ 71 | # include 72 | 73 | # define HOST_KERNEL_VA_2_LA(_x) (_x) 74 | # define HOST_KERNEL_LA_2_VA(_x) (_x) 75 | # else 76 | /* For VA and LA --hpreg */ 77 | # include "vm_basic_types.h" 78 | 79 | # define HOST_KERNEL_VA_2_LA(_addr) ((LA)(_addr)) 80 | # define HOST_KERNEL_LA_2_VA(_addr) ((VA)(_addr)) 81 | # endif 82 | 83 | 84 | #endif /* __HOST_KERNEL_H__ */ 85 | -------------------------------------------------------------------------------- /vmmon-only/common/hostifGlobalLock.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * hostifGlobalLock.h - Platform dependent interface. This module 22 | * defines functions for manipulating/checking 23 | * the Global lock used by some drivers. 24 | */ 25 | 26 | 27 | #ifndef _HOSTIFGLOBALLOCK_H_ 28 | #define _HOSTIFGLOBALLOCK_H_ 29 | 30 | #define INCLUDE_ALLOW_VMMON 31 | #define INCLUDE_ALLOW_VMCORE 32 | #include "includeCheck.h" 33 | 34 | 35 | #ifdef __APPLE__ 36 | Bool HostIFGlobalLock_Start(void); 37 | void HostIFGlobalLock_Stop(void); 38 | #endif 39 | void HostIF_GlobalLock(int callerID); 40 | void HostIF_GlobalUnlock(int callerID); 41 | #ifdef VMX86_DEBUG 42 | Bool HostIF_GlobalLockIsHeld(void); 43 | #endif 44 | 45 | 46 | #endif // ifdef _HOSTIFGLOBALLOCK_H_ 47 | -------------------------------------------------------------------------------- /vmmon-only/common/hostifMem.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * hostifMem.h - Platform dependent interface. This module defines 22 | * functions for allocating and releasing memory 23 | * from the kernel. 24 | */ 25 | 26 | 27 | #ifndef _HOSTIFMEM_H_ 28 | #define _HOSTIFMEM_H_ 29 | 30 | #define INCLUDE_ALLOW_VMMON 31 | #define INCLUDE_ALLOW_VMCORE 32 | #include "includeCheck.h" 33 | #include "vm_basic_types.h" 34 | 35 | 36 | void *HostIF_AllocKernelMem(size_t size, Bool nonPageable); 37 | void HostIF_FreeKernelMem(void *ptr); 38 | 39 | #endif // ifdef _HOSTIFMEM_H_ 40 | -------------------------------------------------------------------------------- /vmmon-only/common/memtrack.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * memtrack.h -- 22 | * 23 | * Utility module for tracking pinned memory, which allows later 24 | * lookup by VPN and optionally by MPN. 25 | */ 26 | 27 | 28 | #ifndef _MEMTRACK_H_ 29 | #define _MEMTRACK_H_ 30 | 31 | #include "vmx86.h" 32 | 33 | struct MemTrack; 34 | 35 | typedef struct MemTrackEntry { 36 | VPN64 vpn; 37 | MPN mpn; 38 | struct MemTrackEntry *vpnChain; 39 | struct MemTrackEntry *mpnChain; 40 | } MemTrackEntry; 41 | 42 | typedef void (MemTrackCleanupCb)(void *cData, MemTrackEntry *entry); 43 | 44 | extern struct MemTrack *MemTrack_Init(VMDriver *vm); 45 | extern PageCnt MemTrack_Cleanup(struct MemTrack *mt, MemTrackCleanupCb *cb, 46 | void *cbData); 47 | extern MemTrackEntry *MemTrack_Add(struct MemTrack *mt, VPN64 vpn, MPN mpn); 48 | extern MemTrackEntry *MemTrack_LookupVPN(struct MemTrack *mt, VPN64 vpn); 49 | extern MemTrackEntry *MemTrack_LookupMPN(struct MemTrack *mt, MPN mpn); 50 | 51 | #endif // _MEMTRACK_H_ 52 | -------------------------------------------------------------------------------- /vmmon-only/common/phystrack.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * phystrack.h -- 22 | * 23 | * track down the utilization of the physical pages 24 | */ 25 | 26 | #ifndef PHYSTRACK_H 27 | #define PHYSTRACK_H 28 | 29 | #define INCLUDE_ALLOW_VMMON 30 | #define INCLUDE_ALLOW_VMCORE 31 | #include "includeCheck.h" 32 | 33 | #if !defined (__linux__) 34 | /* XXX: can be more efficient based on server vs. desktop and version of Windows */ 35 | #define PHYSTRACK_MAX_SUPPORTED_GB (2048 + 4) /* 2 TB 64-bit W2k8 + 4 GB PCI */ 36 | #endif 37 | 38 | struct PhysTracker; 39 | struct VMDriver; 40 | 41 | EXTERN struct PhysTracker *PhysTrack_Alloc(struct VMDriver *vm); 42 | EXTERN void PhysTrack_Free(struct PhysTracker *); 43 | 44 | EXTERN void PhysTrack_Add(struct PhysTracker *, MPN); 45 | EXTERN void PhysTrack_Remove(struct PhysTracker *, MPN); 46 | EXTERN Bool PhysTrack_Test(const struct PhysTracker *, MPN); 47 | EXTERN MPN PhysTrack_GetNext(const struct PhysTracker *, MPN); 48 | EXTERN PageCnt PhysTrack_GetNumTrackedPages(const struct PhysTracker *); 49 | 50 | #endif 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /vmmon-only/common/task.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | #ifndef TASK_H 21 | #define TASK_H 22 | 23 | #define INCLUDE_ALLOW_VMMON 24 | #define INCLUDE_ALLOW_VMCORE 25 | #include "includeCheck.h" 26 | #include "bootstrap_vmm.h" 27 | 28 | struct MonLoaderHeader; 29 | 30 | extern Bool Task_CreateCrossGDT(BSVMM_GDTInit *gdt); 31 | extern Bool Task_InitCrosspage(VMDriver *vm, LPN monStartLPN, LPN monEndLPN, 32 | PerVcpuPages *perVcpuPages); 33 | extern Bool Task_Switch(VMDriver *vm, Vcpuid vcpuid); 34 | extern Bool Task_Initialize(void); 35 | extern void Task_Terminate(void); 36 | extern MPN Task_GetHVRootPageForPCPU(uint32 pCPU); 37 | extern Descriptor *Task_GetTmpGDT(uint32 pCPU); 38 | extern void Task_SwitchPTPPageCleanup(VMDriver *vm); 39 | 40 | #endif 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /vmmon-only/include/address_defs.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2014-2021 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * address_defs.h -- 21 | * 22 | * Macros for virtual/physical/machine address/page conversions, page types. 23 | */ 24 | 25 | #ifndef _ADDRESS_DEFS_H_ 26 | #define _ADDRESS_DEFS_H_ 27 | 28 | #define INCLUDE_ALLOW_USERLEVEL 29 | #define INCLUDE_ALLOW_MODULE 30 | #define INCLUDE_ALLOW_VMK_MODULE 31 | #define INCLUDE_ALLOW_VMKERNEL 32 | #define INCLUDE_ALLOW_DISTRIBUTE 33 | #define INCLUDE_ALLOW_VMCORE 34 | #define INCLUDE_ALLOW_VMMON 35 | #include "includeCheck.h" 36 | 37 | #include "vm_basic_defs.h" // For PAGE_SHIFT 38 | 39 | #if defined __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | 44 | /* 45 | * Virtual, physical, machine address and page conversion macros 46 | */ 47 | 48 | #define VA_2_VPN(_va) ((_va) >> PAGE_SHIFT) 49 | #define PTR_2_VPN(_ptr) VA_2_VPN((VA)(_ptr)) 50 | #define VPN_2_VA(_vpn) ((_vpn) << PAGE_SHIFT) 51 | #define VPN_2_PTR(_vpn) ((void *)VPN_2_VA(_vpn)) 52 | 53 | /* 54 | * Notice that we don't cast PA_2_PPN's argument to an unsigned type, because 55 | * we would lose compile-time checks for pointer operands and byte-sized 56 | * operands. If you use a signed quantity for _pa, ones may be shifted into the 57 | * high bits of your ppn. 58 | */ 59 | 60 | #define PA_2_PPN(_pa) ((_pa) >> PAGE_SHIFT) 61 | #define PPN_2_PA(_ppn) ((PA)(_ppn) << PAGE_SHIFT) 62 | 63 | #define PA_2_PPN_4KB(_pa) ((_pa) >> PAGE_SHIFT_4KB) 64 | #define PPN_2_PA_4KB(_ppn) ((PA)(_ppn) << PAGE_SHIFT_4KB) 65 | 66 | #define PA_2_PPN_16KB(_pa) ((_pa) >> PAGE_SHIFT_16KB) 67 | #define PPN_2_PA_16KB(_ppn) ((PA)(_ppn) << PAGE_SHIFT_16KB) 68 | 69 | static INLINE MA MPN_2_MA(MPN mpn) { return (MA)mpn << PAGE_SHIFT; } 70 | static INLINE MPN MA_2_MPN(MA ma) { return (MPN)(ma >> PAGE_SHIFT); } 71 | 72 | static INLINE IOA IOPN_2_IOA(IOPN iopn) { return (IOA)(iopn << PAGE_SHIFT); } 73 | static INLINE IOPN IOA_2_IOPN(IOA ioa) { return (IOPN)(ioa >> PAGE_SHIFT); } 74 | 75 | /* 76 | *---------------------------------------------------------------------- 77 | * 78 | * IsGoodMPN -- 79 | * 80 | * Is the given MPN valid? 81 | * 82 | * Results: 83 | * Return TRUE if "mpn" looks plausible. We could make this stricter on 84 | * a per-architecture basis. 85 | * 86 | * Side effects: 87 | * None. 88 | * 89 | *---------------------------------------------------------------------- 90 | */ 91 | 92 | static INLINE Bool 93 | IsGoodMPN(MPN mpn) 94 | { 95 | return mpn <= MAX_MPN; 96 | } 97 | 98 | static INLINE Bool 99 | IsGoodMPNOrMemref(MPN mpn) 100 | { 101 | return IsGoodMPN(mpn) || mpn == MEMREF_MPN; 102 | } 103 | 104 | 105 | #if defined __cplusplus 106 | } // extern "C" 107 | #endif 108 | 109 | #endif // _ADDRESS_DEFS_H_ 110 | -------------------------------------------------------------------------------- /vmmon-only/include/bootstrap_vmm.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2015,2017,2023 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * bootstrap_vmm.h -- 21 | * 22 | * Public VMM bootstrap declarations. 23 | */ 24 | 25 | #ifndef _BOOTSTRAP_VMM_H 26 | #define _BOOTSTRAP_VMM_H 27 | 28 | #define INCLUDE_ALLOW_VMCORE 29 | #define INCLUDE_ALLOW_VMMON 30 | #define INCLUDE_ALLOW_VMKERNEL 31 | #define INCLUDE_ALLOW_USERLEVEL 32 | 33 | #include "includeCheck.h" 34 | #include "vm_basic_types.h" 35 | #include "monAddrLayout.h" 36 | 37 | #define BOOTSTRAP_MAGIC 42 38 | #define BOOTSTRAP_MAX_GDT_DESCS 2 39 | 40 | typedef struct BSVMM_GDTInitEntry { 41 | uint16 index; 42 | LA32 base; 43 | VA32 limit; 44 | uint32 type; 45 | uint32 S; 46 | uint32 DPL; 47 | uint32 present; 48 | uint32 longmode; 49 | uint32 DB; 50 | uint32 gran; 51 | } BSVMM_GDTInitEntry; 52 | 53 | typedef struct BSVMM_GDTInit { 54 | BSVMM_GDTInitEntry entries[BOOTSTRAP_MAX_GDT_DESCS]; 55 | } BSVMM_GDTInit; 56 | 57 | typedef struct BSVMM_HostParams { 58 | uint32 magic; 59 | VMM64_AddrLayout addrLayout; 60 | BSVMM_GDTInit gdtInit; 61 | } BSVMM_HostParams; 62 | 63 | BSVMM_HostParams *BSVMM_Validate(void *buf, uint32 nbytes); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /vmmon-only/include/community_source.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2009-2016 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * community_source.h -- 21 | * 22 | * Macros for excluding source code from community. 23 | */ 24 | 25 | #ifndef _COMMUNITY_SOURCE_H_ 26 | #define _COMMUNITY_SOURCE_H_ 27 | 28 | #define INCLUDE_ALLOW_USERLEVEL 29 | 30 | #define INCLUDE_ALLOW_MODULE 31 | #define INCLUDE_ALLOW_VMMON 32 | #define INCLUDE_ALLOW_VMKERNEL 33 | #define INCLUDE_ALLOW_VMKDRIVERS 34 | #define INCLUDE_ALLOW_VMK_MODULE 35 | #define INCLUDE_ALLOW_DISTRIBUTE 36 | #define INCLUDE_ALLOW_VMCORE 37 | #include "includeCheck.h" 38 | 39 | /* 40 | * Convenience macro for COMMUNITY_SOURCE 41 | */ 42 | #undef EXCLUDE_COMMUNITY_SOURCE 43 | #ifdef COMMUNITY_SOURCE 44 | #define EXCLUDE_COMMUNITY_SOURCE(x) 45 | #else 46 | #define EXCLUDE_COMMUNITY_SOURCE(x) x 47 | #endif 48 | 49 | #undef COMMUNITY_SOURCE_AMD_SECRET 50 | #if !defined(COMMUNITY_SOURCE) || defined(AMD_SOURCE) 51 | /* 52 | * It's ok to include AMD_SECRET source code for non-Community Source, 53 | * or for drops directed at AMD. 54 | */ 55 | #define COMMUNITY_SOURCE_AMD_SECRET 56 | #endif 57 | 58 | #undef COMMUNITY_SOURCE_INTEL_SECRET 59 | #if !defined(COMMUNITY_SOURCE) || defined(INTEL_SOURCE) 60 | /* 61 | * It's ok to include INTEL_SECRET source code for non-Community Source, 62 | * or for drops directed at Intel. 63 | */ 64 | #define COMMUNITY_SOURCE_INTEL_SECRET 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /vmmon-only/include/compat_autoconf.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2009 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef __COMPAT_AUTOCONF_H__ 20 | # define __COMPAT_AUTOCONF_H__ 21 | 22 | #define INCLUDE_ALLOW_VMMON 23 | #define INCLUDE_ALLOW_MODULE 24 | #define INCLUDE_ALLOW_VMCORE 25 | #define INCLUDE_ALLOW_DISTRIBUTE 26 | #define INCLUDE_ALLOW_VMKDRIVERS 27 | #include "includeCheck.h" 28 | 29 | 30 | #ifndef LINUX_VERSION_CODE 31 | # error "Include compat_version.h before compat_autoconf.h" 32 | #endif 33 | 34 | /* autoconf.h moved from linux/autoconf.h to generated/autoconf.h in 2.6.33-rc1. */ 35 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) 36 | # include 37 | #else 38 | # include 39 | #endif 40 | 41 | #if defined(CONFIG_SUSE_VERSION) && defined(CONFIG_SUSE_PATCHLEVEL) 42 | # if CONFIG_SUSE_VERSION == 15 && CONFIG_SUSE_PATCHLEVEL >= 5 43 | # define SLE15_SP5_BACKPORTS 1 44 | # endif 45 | #endif 46 | 47 | #endif /* __COMPAT_AUTOCONF_H__ */ 48 | -------------------------------------------------------------------------------- /vmmon-only/include/compat_kernel.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2004 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef __COMPAT_KERNEL_H__ 20 | # define __COMPAT_KERNEL_H__ 21 | 22 | #include 23 | #include 24 | 25 | /* 26 | * container_of was introduced in 2.5.28 but it's easier to check like this. 27 | */ 28 | #ifndef container_of 29 | #define container_of(ptr, type, member) ({ \ 30 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 31 | (type *)( (char *)__mptr - offsetof(type,member) );}) 32 | #endif 33 | 34 | /* 35 | * vsnprintf became available in 2.4.10. For older kernels, just fall back on 36 | * vsprintf. 37 | */ 38 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 10) 39 | #define vsnprintf(str, size, fmt, args) vsprintf(str, fmt, args) 40 | #endif 41 | 42 | #endif /* __COMPAT_KERNEL_H__ */ 43 | -------------------------------------------------------------------------------- /vmmon-only/include/compat_module.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2007 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * compat_module.h -- 21 | */ 22 | 23 | #ifndef __COMPAT_MODULE_H__ 24 | # define __COMPAT_MODULE_H__ 25 | 26 | 27 | #include 28 | 29 | 30 | /* 31 | * Modules wishing to use the GPL license are required to include a 32 | * MODULE_LICENSE definition in their module source as of 2.4.10. 33 | */ 34 | #ifndef MODULE_LICENSE 35 | #define MODULE_LICENSE(license) 36 | #endif 37 | 38 | /* 39 | * To make use of our own home-brewed MODULE_INFO, we need macros to 40 | * concatenate two expressions to "__mod_", and and to convert an 41 | * expression into a string. I'm sure we've got these in our codebase, 42 | * but I'd rather not introduce such a dependency in a compat header. 43 | */ 44 | #ifndef __module_cat 45 | #define __module_cat_1(a, b) __mod_ ## a ## b 46 | #define __module_cat(a, b) __module_cat_1(a, b) 47 | #endif 48 | 49 | #ifndef __stringify 50 | #define __stringify_1(x) #x 51 | #define __stringify(x) __stringify_1(x) 52 | #endif 53 | 54 | /* 55 | * MODULE_INFO was born in 2.5.69. 56 | */ 57 | #ifndef MODULE_INFO 58 | #define MODULE_INFO(tag, info) \ 59 | static const char __module_cat(tag, __LINE__)[] \ 60 | __attribute__((section(".modinfo"), unused)) = __stringify(tag) "=" info 61 | #endif 62 | 63 | /* 64 | * MODULE_VERSION was born in 2.6.4. The earlier form appends a long "\0xxx" 65 | * string to the module's version, but that was removed in 2.6.10, so we'll 66 | * ignore it in our wrapper. 67 | */ 68 | #ifndef MODULE_VERSION 69 | #define MODULE_VERSION(_version) MODULE_INFO(version, _version) 70 | #endif 71 | 72 | /* 73 | * Linux kernel < 2.6.31 takes 'int' for 'bool' module parameters. 74 | * Linux kernel >= 3.3.0 takes 'bool' for 'bool' module parameters. 75 | * Kernels between the two take either. So flip switch at 3.0.0. 76 | */ 77 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) 78 | typedef bool compat_mod_param_bool; 79 | #else 80 | typedef int compat_mod_param_bool; 81 | #endif 82 | 83 | #endif /* __COMPAT_MODULE_H__ */ 84 | -------------------------------------------------------------------------------- /vmmon-only/include/compat_page.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2002 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef __COMPAT_PAGE_H__ 20 | # define __COMPAT_PAGE_H__ 21 | 22 | 23 | #include 24 | #include 25 | 26 | 27 | /* The pfn_to_page() API appeared in 2.5.14 and changed to function during 2.6.x */ 28 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) && !defined(pfn_to_page) 29 | # define pfn_to_page(_pfn) (mem_map + (_pfn)) 30 | # define page_to_pfn(_page) ((_page) - mem_map) 31 | #endif 32 | 33 | 34 | /* The virt_to_page() API appeared in 2.4.0 --hpreg */ 35 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0) && !defined(virt_to_page) 36 | # define virt_to_page(_kvAddr) pfn_to_page(MAP_NR(_kvAddr)) 37 | #endif 38 | 39 | 40 | /* 41 | * The get_order() API appeared at some point in 2.3.x, and was then backported 42 | * in 2.2.17-21mdk and in the stock 2.2.18. Because we can only detect its 43 | * definition through makefile tricks, we provide our own for now --hpreg 44 | */ 45 | static inline int 46 | compat_get_order(unsigned long size) // IN 47 | { 48 | int order; 49 | 50 | size = (size - 1) >> (PAGE_SHIFT - 1); 51 | order = -1; 52 | do { 53 | size >>= 1; 54 | order++; 55 | } while (size); 56 | 57 | return order; 58 | } 59 | 60 | /* 61 | * BUG() was added to in 2.2.18, and was moved to 62 | * in 2.5.58. 63 | * 64 | * XXX: Technically, this belongs in some sort of "compat_asm_page.h" file, but 65 | * since our compatibility wrappers don't distinguish between and 66 | * , putting it here is reasonable. 67 | */ 68 | #ifndef BUG 69 | #define BUG() do { \ 70 | printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \ 71 | __asm__ __volatile__(".byte 0x0f,0x0b"); \ 72 | } while (0) 73 | #endif 74 | 75 | #endif /* __COMPAT_PAGE_H__ */ 76 | -------------------------------------------------------------------------------- /vmmon-only/include/compat_pgtable.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2002-2017 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef __COMPAT_PGTABLE_H__ 20 | # define __COMPAT_PGTABLE_H__ 21 | 22 | 23 | #if defined(CONFIG_PARAVIRT) && defined(CONFIG_HIGHPTE) 24 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 21) 25 | # include 26 | # undef paravirt_map_pt_hook 27 | # define paravirt_map_pt_hook(type, va, pfn) do {} while (0) 28 | # endif 29 | #endif 30 | #include 31 | 32 | 33 | /* 34 | * p4d level appeared in 4.12. 35 | */ 36 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) 37 | # define compat_p4d_offset(pgd, address) p4d_offset(pgd, address) 38 | # define compat_p4d_present(p4d) p4d_present(p4d) 39 | # define compat_p4d_large(p4d) p4d_large(p4d) 40 | # define compat_p4d_pfn(p4d) p4d_pfn(p4d) 41 | # define COMPAT_P4D_MASK P4D_MASK 42 | typedef p4d_t compat_p4d_t; 43 | #else 44 | # define compat_p4d_offset(pgd, address) (pgd) 45 | # define compat_p4d_present(p4d) (1) 46 | # define compat_p4d_large(p4d) (0) 47 | # define compat_p4d_pfn(p4d) INVALID_MPN /* Not used */ 48 | # define COMPAT_P4D_MASK 0 /* Not used */ 49 | typedef pgd_t compat_p4d_t; 50 | #endif 51 | /* pud_pfn did not exist before 3.8. */ 52 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) 53 | # define pud_pfn(pud) INVALID_MPN 54 | #endif 55 | 56 | 57 | /* 58 | * Define VM_PAGE_KERNEL_EXEC for vmapping executable pages. 59 | * 60 | * On ia32 PAGE_KERNEL_EXEC was introduced in 2.6.8.1. Unfortunately it accesses 61 | * __PAGE_KERNEL_EXEC which is not exported for modules. So we use 62 | * __PAGE_KERNEL and just cut _PAGE_NX bit from it. 63 | * 64 | * For ia32 kernels before 2.6.8.1 we use PAGE_KERNEL directly, these kernels 65 | * do not have noexec support. 66 | * 67 | * On x86-64 situation is a bit better: they always supported noexec, but 68 | * before 2.6.8.1 flag was named PAGE_KERNEL_EXECUTABLE, and it was renamed 69 | * to PAGE_KERNEL_EXEC when ia32 got noexec too (see above). 70 | */ 71 | #ifdef CONFIG_X86 72 | #ifdef _PAGE_NX 73 | #define VM_PAGE_KERNEL_EXEC __pgprot(__PAGE_KERNEL & ~_PAGE_NX) 74 | #else 75 | #define VM_PAGE_KERNEL_EXEC PAGE_KERNEL 76 | #endif 77 | #else 78 | #define VM_PAGE_KERNEL_EXEC PAGE_KERNEL_EXEC 79 | #endif 80 | 81 | 82 | #endif /* __COMPAT_PGTABLE_H__ */ 83 | -------------------------------------------------------------------------------- /vmmon-only/include/compat_spinlock.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2005 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef __COMPAT_SPINLOCK_H__ 20 | # define __COMPAT_SPINLOCK_H__ 21 | 22 | #include 23 | 24 | /* 25 | * Preempt support was added during 2.5.x development cycle, and later 26 | * it was backported to 2.4.x. In 2.4.x backport these definitions 27 | * live in linux/spinlock.h, that's why we put them here (in 2.6.x they 28 | * are defined in linux/preempt.h which is included by linux/spinlock.h). 29 | */ 30 | #ifdef CONFIG_PREEMPT 31 | #define compat_preempt_disable() preempt_disable() 32 | #define compat_preempt_enable() preempt_enable() 33 | #else 34 | #define compat_preempt_disable() do { } while (0) 35 | #define compat_preempt_enable() do { } while (0) 36 | #endif 37 | 38 | /* Some older kernels - 2.6.10 and earlier - lack DEFINE_SPINLOCK */ 39 | #ifndef DEFINE_SPINLOCK 40 | #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED 41 | #endif 42 | 43 | /* Same goes for DEFINE_RWLOCK */ 44 | #ifndef DEFINE_RWLOCK 45 | #define DEFINE_RWLOCK(x) rwlock_t x = RW_LOCK_UNLOCKED 46 | #endif 47 | 48 | #endif /* __COMPAT_SPINLOCK_H__ */ 49 | -------------------------------------------------------------------------------- /vmmon-only/include/compat_version.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | #ifndef __COMPAT_VERSION_H__ 21 | # define __COMPAT_VERSION_H__ 22 | 23 | #define INCLUDE_ALLOW_VMMON 24 | #define INCLUDE_ALLOW_MODULE 25 | #define INCLUDE_ALLOW_VMCORE 26 | #define INCLUDE_ALLOW_DISTRIBUTE 27 | #define INCLUDE_ALLOW_VMKDRIVERS 28 | #include "includeCheck.h" 29 | 30 | 31 | #ifndef __linux__ 32 | # error "linux-version.h" 33 | #endif 34 | 35 | 36 | #include 37 | 38 | #ifndef KERNEL_VERSION 39 | # error KERNEL_VERSION macro is not defined, environment is busted 40 | #endif 41 | 42 | 43 | /* 44 | * Distinguish relevant classes of Linux kernels. 45 | * 46 | * The convention is that version X defines all 47 | * the KERNEL_Y symbols where Y <= X. 48 | * 49 | * XXX Do not add more definitions here. This way of doing things does not 50 | * scale, and we are going to phase it out soon --hpreg 51 | */ 52 | 53 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 1, 0) 54 | # define KERNEL_2_1 55 | #endif 56 | 57 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 2, 0) 58 | # define KERNEL_2_2 59 | #endif 60 | 61 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 1) 62 | # define KERNEL_2_3_1 63 | #endif 64 | 65 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 15) 66 | /* new networking */ 67 | # define KERNEL_2_3_15 68 | #endif 69 | 70 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 25) 71 | /* new procfs */ 72 | # define KERNEL_2_3_25 73 | #endif 74 | 75 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 29) 76 | /* even newer procfs */ 77 | # define KERNEL_2_3_29 78 | #endif 79 | 80 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 43) 81 | /* softnet changes */ 82 | # define KERNEL_2_3_43 83 | #endif 84 | 85 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 47) 86 | /* more softnet changes */ 87 | # define KERNEL_2_3_47 88 | #endif 89 | 90 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 99) 91 | /* name in netdevice struct is array and not pointer */ 92 | # define KERNEL_2_3_99 93 | #endif 94 | 95 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) 96 | /* New 'owner' member at the beginning of struct file_operations */ 97 | # define KERNEL_2_4_0 98 | #endif 99 | 100 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 8) 101 | /* New netif_rx_ni() --hpreg */ 102 | # define KERNEL_2_4_8 103 | #endif 104 | 105 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 2) 106 | /* New kdev_t, major()/minor() API --hpreg */ 107 | # define KERNEL_2_5_2 108 | #endif 109 | 110 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 5) 111 | /* New sk_alloc(), pte_offset_map()/pte_unmap() --hpreg */ 112 | # define KERNEL_2_5_5 113 | #endif 114 | 115 | /* Linux kernel 3.0 can be called 2.6.40, and 3.1 can be 2.6.41... 116 | * Use COMPAT_LINUX_VERSION_CHECK_LT iff you need to compare running kernel to 117 | * versions 3.0 and above. 118 | * 119 | */ 120 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) 121 | /* Straight forward comparison if kernel version is 3.0.0 and beyond */ 122 | # define COMPAT_LINUX_VERSION_CHECK_LT(a, b, c) (LINUX_VERSION_CODE < KERNEL_VERSION (a, b, c)) 123 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 40) 124 | /* Use b of the check to calculate corresponding c of kernel 125 | * version to compare */ 126 | # define COMPAT_LINUX_VERSION_CHECK_LT(a, b, c) (LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, (b + 40))) 127 | #else 128 | /* This is anyways lesser than any 3.x versions */ 129 | # define COMPAT_LINUX_VERSION_CHECK_LT(a, b, c) 1 130 | #endif 131 | 132 | #if defined(RHEL_RELEASE_CODE) && defined(RHEL_RELEASE_VERSION) 133 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(8, 4) 134 | # define RHEL84_BACKPORTS 1 135 | # endif 136 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(8, 5) 137 | # define RHEL85_BACKPORTS 1 138 | # endif 139 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 1) 140 | # define RHEL91_BACKPORTS 1 141 | # endif 142 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 2) 143 | # define RHEL92_BACKPORTS 1 144 | # endif 145 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 4) 146 | # define RHEL94_BACKPORTS 1 147 | # endif 148 | #endif 149 | 150 | #endif /* __COMPAT_VERSION_H__ */ 151 | -------------------------------------------------------------------------------- /vmmon-only/include/contextinfo.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2005-2014,2017 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | 20 | /* 21 | * contextinfo.h 22 | * 23 | * Context structures shared across all products 24 | */ 25 | 26 | #ifndef _CONTEXTINFO_H 27 | #define _CONTEXTINFO_H 28 | 29 | #define INCLUDE_ALLOW_USERLEVEL 30 | #define INCLUDE_ALLOW_VMCORE 31 | #define INCLUDE_ALLOW_VMKERNEL 32 | #define INCLUDE_ALLOW_VMMON 33 | #define INCLUDE_ALLOW_VMX 34 | #include "includeCheck.h" 35 | 36 | #include "x86desc.h" 37 | 38 | #pragma pack(push, 1) 39 | typedef struct Context64 { 40 | uint64 cr3; 41 | uint64 rax; 42 | uint64 rcx; 43 | uint64 rdx; 44 | uint64 rbx; 45 | uint64 rsi; 46 | uint64 rdi; 47 | uint64 rbp; 48 | uint64 rsp; 49 | uint64 r8; 50 | uint64 r9; 51 | uint64 r10; 52 | uint64 r11; 53 | uint64 r12; 54 | uint64 r13; 55 | uint64 r14; 56 | uint64 r15; 57 | uint32 cs; 58 | uint32 ds; 59 | uint32 ss; 60 | uint32 es; 61 | uint32 fs; 62 | uint32 gs; 63 | uint64 rip; 64 | uint64 eflags; 65 | uint16 ldt; 66 | uint16 _pad[3]; 67 | } Context64; 68 | #pragma pack(pop) 69 | 70 | #pragma pack(push, 1) 71 | typedef struct ContextInfo64 { 72 | DTRWords64 gdtr; 73 | DTRWords64 idtr; 74 | Context64 context; 75 | uint16 tr; 76 | uint16 _pad0; 77 | } ContextInfo64; 78 | #pragma pack(pop) 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /vmmon-only/include/cpu_defs.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2009 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * cpu_defs.h -- 21 | * 22 | * CPU-related definitions shared between vmkernel and user-space. 23 | */ 24 | 25 | #ifndef CPU_DEFS_H 26 | #define CPU_DEFS_H 27 | 28 | #define INCLUDE_ALLOW_VMKERNEL 29 | #define INCLUDE_ALLOW_DISTRIBUTE 30 | #define INCLUDE_ALLOW_VMKDRIVERS 31 | #define INCLUDE_ALLOW_VMK_MODULE 32 | #define INCLUDE_ALLOW_MODULE 33 | #define INCLUDE_ALLOW_USERLEVEL 34 | #define INCLUDE_ALLOW_VMCORE 35 | #define INCLUDE_ALLOW_VMMON 36 | 37 | #define INCLUDE_ALLOW_VMX 38 | #include "includeCheck.h" 39 | 40 | #include "vm_basic_types.h" 41 | 42 | typedef uint32 PCPU; 43 | #define INVALID_PCPU ((PCPU) -1) 44 | 45 | #define MAX_PCPUS 1024 46 | #define MAX_PCPUS_BITS 10 // MAX_PCPUS <= (1 << MAX_PCPUS_BITS) 47 | #define MAX_PCPUS_MASK ((1 << MAX_PCPUS_BITS) - 1) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /vmmon-only/include/cpu_types.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2020 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * cpu_types.h -- 21 | * 22 | * Type definitions for the target architecture. 23 | */ 24 | 25 | #if !defined(_CPU_TYPES_H_) 26 | #define _CPU_TYPES_H_ 27 | 28 | #include "vm_basic_types.h" 29 | #include "vm_basic_defs.h" 30 | 31 | typedef uint8 Instruction; 32 | 33 | /* 34 | * Page 35 | */ 36 | typedef char PageArray[PAGE_SIZE]; 37 | 38 | 39 | #include "cpu_types_arch.h" 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /vmmon-only/include/crossgdt.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2006-2017, 2020 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * crossgdt.h -- 21 | * 22 | * This GDT is used for switching between monitor and host context. 23 | * It contains the host and monitor basic segment descriptors. 24 | * There is only one in the whole host system, shared by all VMs. 25 | * It is allocated when the first VCPU is started and freed when the 26 | * driver is unloaded. 27 | * 28 | * The crossGDT size is exactly one page. 29 | * 30 | * The hosted world switch code is based on the assumption that by 31 | * placing VMM descriptors at the end of the page, they will not 32 | * overlap with host kernel descriptors in use when "crossing over". 33 | * 34 | * All necessary host segments must be from first page of GDT. 35 | * In Nov 2006, host GDT limits easily met this constraint: 36 | * 37 | * Linux 64 bit: 80 (yes 80, not 7F) 38 | * MacOS 64 bit: 8F 39 | * Windows 64 bit: 6F 40 | */ 41 | 42 | #ifndef _CROSSGDT_H_ 43 | #define _CROSSGDT_H_ 44 | 45 | #define INCLUDE_ALLOW_USERLEVEL 46 | 47 | #define INCLUDE_ALLOW_VMMON 48 | #define INCLUDE_ALLOW_VMCORE 49 | #include "includeCheck.h" 50 | 51 | #include "vm_basic_defs.h" // PAGE_SIZE 52 | #include "x86/cpu_types_arch.h" // Descriptor 53 | 54 | 55 | typedef struct CrossGDT { 56 | Descriptor gdtes[PAGE_SIZE / sizeof(Descriptor)]; 57 | } CrossGDT; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /vmmon-only/include/driver-config.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 1998 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * Sets the proper defines from the Linux header files 21 | * 22 | * This file must be included before the inclusion of any kernel header file, 23 | * with the exception of linux/autoconf.h and linux/version.h --hpreg 24 | */ 25 | 26 | #ifndef __VMX_CONFIG_H__ 27 | #define __VMX_CONFIG_H__ 28 | 29 | #define INCLUDE_ALLOW_VMCORE 30 | #define INCLUDE_ALLOW_VMMON 31 | #define INCLUDE_ALLOW_MODULE 32 | #define INCLUDE_ALLOW_DISTRIBUTE 33 | #define INCLUDE_ALLOW_VMKDRIVERS 34 | #include "includeCheck.h" 35 | 36 | #include "compat_version.h" 37 | #include "compat_autoconf.h" 38 | 39 | /* 40 | * We rely on Kernel Module support. Check here. 41 | */ 42 | #ifndef CONFIG_MODULES 43 | # error "No Module support in this kernel. Please configure with CONFIG_MODULES" 44 | #endif 45 | 46 | /* 47 | * 2.2 kernels still use __SMP__ (derived from CONFIG_SMP 48 | * in the main Makefile), so we do it here. 49 | */ 50 | 51 | #ifdef CONFIG_SMP 52 | # define __SMP__ 1 53 | #endif 54 | 55 | #if defined(CONFIG_MODVERSIONS) && defined(KERNEL_2_1) 56 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60) 57 | /* 58 | * MODVERSIONS might be already defined when using kernel's Makefiles. 59 | */ 60 | # ifndef MODVERSIONS 61 | # define MODVERSIONS 62 | # endif 63 | # include 64 | # endif 65 | #endif 66 | 67 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) 68 | /* 69 | * Force the uintptr_t definition to come from linux/types.h instead of vm_basic_types.h. 70 | */ 71 | # include 72 | # define _STDINT_H 1 73 | #endif 74 | 75 | #ifndef __KERNEL__ 76 | # define __KERNEL__ 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /vmmon-only/include/includeCheck.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2008,2018-2019 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | -------------------------------------------------------------------------------- /vmmon-only/include/memDefaults.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 1998-2016 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | 20 | #ifndef _MEMDEFAULTS_H_ 21 | #define _MEMDEFAULTS_H_ 22 | 23 | #define INCLUDE_ALLOW_USERLEVEL 24 | #define INCLUDE_ALLOW_VMMON 25 | #define INCLUDE_ALLOW_VMCORE 26 | #define INCLUDE_ALLOW_MODULE 27 | #include "includeCheck.h" 28 | 29 | #include "vm_basic_math.h" 30 | #include "vm_basic_defs.h" 31 | 32 | #if defined(__cplusplus) 33 | extern "C" { 34 | #endif 35 | 36 | #define MEMDEFAULTS_MIN_HOST_PAGES MBYTES_2_PAGES(128) 37 | 38 | 39 | /* 40 | *----------------------------------------------------------------------------- 41 | * 42 | * MemDefaults_CalcMaxLockedPages -- 43 | * 44 | * Calculate the rough estimate of the maximum amount of memory 45 | * that can be locked (total for the kernel, all VMs, and other apps), 46 | * based on the size of host memory as supplied in pages. 47 | * 48 | * Results: 49 | * The estimated maximum memory that can be locked in pages. 50 | * 51 | * Side effects: 52 | * None 53 | * 54 | *----------------------------------------------------------------------------- 55 | */ 56 | 57 | static INLINE unsigned 58 | MemDefaults_CalcMaxLockedPages(unsigned hostPages) // IN: 59 | { 60 | unsigned reservedPages; 61 | 62 | #if defined(__APPLE__) 63 | /* 64 | * Reserve (25% of the host memory + 512 MB) or 4 GB, whichever is lower. 65 | * 4 GB hosts perform poorly with less than 1.5 GB reserved, and large 66 | * memory hosts (>= 16 GB) may want to use more than 75% for VMs. 67 | */ 68 | reservedPages = MIN((hostPages / 4) + MBYTES_2_PAGES(512), 69 | GBYTES_2_PAGES(4)); 70 | #elif defined(_WIN32) 71 | { 72 | unsigned int hostGig = PAGES_2_GBYTES(hostPages); 73 | 74 | if (hostGig <= 4) { 75 | reservedPages = hostPages / 4; 76 | } else if (hostGig >= 16) { 77 | reservedPages = hostPages / 8; 78 | } else { 79 | /* 80 | * Increment by 1/32 for each 4GB of host mem between 4 and 16. 81 | * See PR779556. 82 | */ 83 | reservedPages = hostPages / 32 * (8 - hostGig / 4); 84 | } 85 | } 86 | #else // Linux 87 | reservedPages = hostPages / 8; 88 | #endif 89 | 90 | reservedPages = MAX(reservedPages, MEMDEFAULTS_MIN_HOST_PAGES); 91 | 92 | return hostPages > reservedPages ? hostPages - reservedPages : 0; 93 | } 94 | 95 | 96 | /* 97 | *----------------------------------------------------------------------------- 98 | * 99 | * MemDefaults_CalcMaxLockedMBs -- 100 | * 101 | * Calculate the rough estimate of the maximum amount of memory 102 | * that can be locked based on the size of host memory as supplied 103 | * in MBytes. 104 | * 105 | * Results: 106 | * The estimated maximum memory that can be locked in MBytes. 107 | * 108 | * Side effects: 109 | * None 110 | * 111 | *----------------------------------------------------------------------------- 112 | */ 113 | 114 | static INLINE uint32 115 | MemDefaults_CalcMaxLockedMBs(uint32 hostMem) // IN: 116 | { 117 | return PAGES_2_MBYTES( 118 | MemDefaults_CalcMaxLockedPages(MBYTES_2_PAGES(hostMem))); 119 | } 120 | 121 | 122 | /* 123 | *----------------------------------------------------------------------------- 124 | * 125 | * MemDefaults_CalcMinReservedMBs -- 126 | * 127 | * Provide a lower bound on the user as to the minimum amount 128 | * of memory to lock based on the size of host memory. This 129 | * threshold might be crossed as a result of the user limiting 130 | * the amount of memory consumed by all VMs. 131 | * 132 | * Results: 133 | * The minimum locked memory requirement in MBytes. 134 | * 135 | * Side effects: 136 | * None 137 | * 138 | *----------------------------------------------------------------------------- 139 | */ 140 | 141 | static INLINE uint32 142 | MemDefaults_CalcMinReservedMBs(uint32 hostMem) // IN: 143 | { 144 | if (hostMem < 512) { 145 | return 32; 146 | } else if (hostMem < 1024) { 147 | return 64; 148 | } else { 149 | return 128; 150 | } 151 | } 152 | 153 | 154 | void MemDefaults_GetReservedMemory(uint32 *host, uint32 *min, 155 | uint32 *max, uint32 *recommended); 156 | 157 | #if defined(__cplusplus) 158 | } // extern "C" 159 | #endif 160 | 161 | #endif 162 | -------------------------------------------------------------------------------- /vmmon-only/include/monAddrLayout.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2005-2019 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * monAddrLayout.h -- 21 | * 22 | * Address layout of the monitor. 23 | */ 24 | 25 | #ifndef _MON_ADDR_LAYOUT_H 26 | #define _MON_ADDR_LAYOUT_H 27 | 28 | #include "vm_pagetable.h" 29 | 30 | #define INCLUDE_ALLOW_VMCORE 31 | #define INCLUDE_ALLOW_VMMON 32 | #define INCLUDE_ALLOW_VMKERNEL 33 | #define INCLUDE_ALLOW_USERLEVEL 34 | #include "includeCheck.h" 35 | 36 | #pragma pack(push, 1) 37 | typedef struct VMM64_AddrLayout { 38 | /* 39 | *All address are VPNs and all lengths are numPages 40 | */ 41 | uint64 monBase; // MONITOR_BASE_VPN 42 | uint64 monL5Start; // MON_PAGE_TABLE_L5_START 43 | uint32 monL5Len; // MON_PAGE_TABLE_L5_LEN 44 | uint64 monL4Start; // MON_PAGE_TABLE_L4_START 45 | uint32 monL4Len; // MON_PAGE_TABLE_L4_LEN 46 | uint64 monL3Start; // MON_PAGE_TABLE_L3_START 47 | uint32 monL3Len; // MON_PAGE_TABLE_L3_LEN 48 | uint64 monL2Start; // MON_PAGE_TABLE_L2_START 49 | uint32 monL2Len; // MON_PAGE_TABLE_L2_LEN 50 | uint64 monL1Start; // MON_PAGE_TABLE_L1_START 51 | uint32 monL1Len; // MON_PAGE_TABLE_L1_LEN 52 | #ifndef VMX86_SERVER 53 | uint64 monCpStart; // CROSS_PAGE_START 54 | #endif 55 | } VMM64_AddrLayout; 56 | #pragma pack(pop) 57 | 58 | #define VMM_MONAS_4LP_FIRST_L4OFF 1 59 | #define VMM_MONAS_4LP_LAST_L4OFF 130 60 | 61 | #define VMM_MONAS_5LP_FIRST_L5OFF 1 62 | #define VMM_MONAS_5LP_LAST_L5OFF 34 63 | 64 | static inline PT_Level 65 | MonAS_GetPagingLevel(void) 66 | { 67 | return PT_LEVEL_4; 68 | } 69 | 70 | static inline Bool 71 | MonAS_Uses5LevelPaging(void) 72 | { 73 | return MonAS_GetPagingLevel() == PT_LEVEL_5; 74 | } 75 | #endif 76 | -------------------------------------------------------------------------------- /vmmon-only/include/monLoaderLog.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2016-2019 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * monLoaderLog.h -- 21 | * 22 | * Logging definitions for MonLoader. 23 | */ 24 | 25 | #ifndef _MONLOADER_LOG_H_ 26 | #define _MONLOADER_LOG_H_ 27 | 28 | #if defined VMKERNEL 29 | 30 | #define LOGLEVEL_MODULE MonLoader 31 | #include "log.h" 32 | 33 | #elif defined VMMON 34 | 35 | #include "vm_assert.h" 36 | #define ML_LOGLEVEL_VMMON 0 /* MonLoader/vmmon loglevel. */ 37 | 38 | #undef LOG 39 | #define LOG(_min, _fmt, ...) \ 40 | do { \ 41 | if (vmx86_log && ML_LOGLEVEL_VMMON >= (_min)) { \ 42 | Log(_fmt "\n", ## __VA_ARGS__); \ 43 | } \ 44 | } while (0) 45 | 46 | #else /* !defined VMKERNEL && !defined VMMON */ 47 | #error MonLoader cannot be built as part of this environment 48 | #endif 49 | 50 | #endif /* _MONLOADER_LOG_H_ */ 51 | -------------------------------------------------------------------------------- /vmmon-only/include/mon_constants.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 1998-2018, 2022 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* Do not include inline functions, typedefs or other such 20 | * nonsense here. This file is for _constants_. 21 | */ 22 | 23 | #ifndef _MON_CONSTANTS_H_ 24 | #define _MON_CONSTANTS_H_ 25 | 26 | #define INCLUDE_ALLOW_USERLEVEL 27 | 28 | #define INCLUDE_ALLOW_VMKERNEL 29 | #define INCLUDE_ALLOW_VMCORE 30 | #define INCLUDE_ALLOW_VMMON 31 | #include "includeCheck.h" 32 | 33 | 34 | #define MON_PANIC_NONE 0 35 | #define MON_PANIC_MSG_COPYING 1 36 | #define MON_PANIC_MSG_COPIED 2 37 | #define MON_PANIC_COREDUMPING 3 38 | #define MON_PANIC_VCPU 4 39 | 40 | #define MON_PANIC_MSG_SIZE 256 41 | 42 | /* Ensure enough space for obj build with GCOV_VMM=1. */ 43 | #if defined(VMX86_SERVER) 44 | #define VMMBLOB_SIZE_MAX (25 * 1024 * 1024) 45 | #else 46 | #define VMMBLOB_SIZE_MAX (25 * 1024 * 1024) 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /vmmon-only/include/msrCache.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2008-2020 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef _MSRCACHE_H_ 20 | #define _MSRCACHE_H_ 21 | 22 | /* 23 | * msrCache.h - 24 | * 25 | * Module to handle MSR data from multiple CPUs. 26 | * 27 | */ 28 | 29 | #define INCLUDE_ALLOW_MODULE 30 | #define INCLUDE_ALLOW_USERLEVEL 31 | #define INCLUDE_ALLOW_VMCORE 32 | #define INCLUDE_ALLOW_VMKERNEL 33 | #define INCLUDE_ALLOW_VMMON 34 | #include "includeCheck.h" 35 | 36 | #include "vm_basic_types.h" 37 | #include "vm_basic_defs.h" 38 | #include "x86msr.h" 39 | 40 | #if defined(__cplusplus) 41 | extern "C" { 42 | #endif 43 | 44 | #define FORALL_MSRS(_msr, _cache) \ 45 | do { \ 46 | unsigned _ix; \ 47 | unsigned _count = MSRCache_NumMSRs(_cache); \ 48 | const uint32 *_list = MSRCache_MSRList(_cache); \ 49 | for (_ix = 0; _ix < _count; _ix++) { \ 50 | uint32 _msr = _list[_ix]; 51 | 52 | #define MSRS_DONE \ 53 | } \ 54 | } while(0) 55 | 56 | typedef struct MSRCache MSRCache; 57 | typedef Bool (*MSRQueryFunction)(MSRQuery *query); 58 | 59 | unsigned MSRCache_NumCPUs(const MSRCache *cache); 60 | unsigned MSRCache_NumMSRs(const MSRCache *cache); 61 | const uint32 *MSRCache_MSRList(const MSRCache *cache); 62 | MSRCache *MSRCache_Alloc(unsigned nCPUs, unsigned nMSRs, const uint32 *msrNum); 63 | void MSRCache_Free(MSRCache *cache); 64 | uint64 MSRCache_Get(const MSRCache *cache, uint32 msrNum, unsigned cpu); 65 | void MSRCache_Set(MSRCache *cache, uint32 msrNum, unsigned cpu, uint64 val); 66 | void MSRCache_Populate(MSRCache *cache, unsigned numCPUs, 67 | MSRQueryFunction queryFn); 68 | MSRCache *MSRCache_Clone(const MSRCache *cache); 69 | 70 | #if defined(__cplusplus) 71 | } // extern "C" 72 | #endif 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /vmmon-only/include/pageLock_defs.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2015 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | 20 | /* 21 | * pageLock_defs.h 22 | * 23 | * Page lock status codes, used by vmmon. 24 | */ 25 | 26 | #ifndef _PAGELOCK_DEFS_H_ 27 | #define _PAGELOCK_DEFS_H_ 28 | 29 | #define INCLUDE_ALLOW_USERLEVEL 30 | #define INCLUDE_ALLOW_VMMON 31 | #define INCLUDE_ALLOW_VMCORE 32 | #define INCLUDE_ALLOW_MODULE 33 | #include "includeCheck.h" 34 | 35 | /* 36 | * Return codes from page locking, unlocking, and MPN lookup. 37 | * They share an error code space because they call one another 38 | * internally. 39 | * 40 | * PAGE_LOCK_FAILED The host refused to lock a page. 41 | * PAGE_LOCK_LIMIT_EXCEEDED We have reached the limit of locked 42 | * pages for all VMs 43 | * PAGE_LOCK_TOUCH_FAILED Failed to touch page after lock. 44 | * PAGE_LOCK_IN_TRANSITION The page is locked but marked by Windows 45 | * as nonpresent in CPU PTE and in transition 46 | * in Windows PFN. 47 | * 48 | * PAGE_LOCK_SYS_ERROR System call error. 49 | * PAGE_LOCK_ALREADY_LOCKED Page already locked. 50 | * PAGE_LOCK_MEMTRACKER_ERROR MemTracker fails. 51 | * PAGE_LOCK_PHYSTRACKER_ERROR PhysTracker fails. 52 | * PAGE_LOCK_MDL_ERROR Mdl error on Windows. 53 | * 54 | * PAGE_UNLOCK_NO_ERROR Unlock successful (must be 0). 55 | * PAGE_UNLOCK_NOT_TRACKED Not in memtracker. 56 | * PAGE_UNLOCK_NO_MPN Tracked but no MPN. 57 | * PAGE_UNLOCK_NOT_LOCKED Not locked. 58 | * PAGE_UNLOCK_TOUCH_FAILED Failed to touch page. 59 | * PAGE_UNLOCK_MISMATCHED_TYPE Tracked but was locked by different API 60 | * 61 | * PAGE_LOOKUP_INVALID_ADDR Consistency checking. 62 | * PAGE_LOOKUP_BAD_HIGH_ADDR Consistency checking. 63 | * PAGE_LOOKUP_ZERO_ADDR Consistency checking. 64 | * PAGE_LOOKUP_SMALL_ADDR Consistency checking. 65 | * 66 | * All error values must be negative values less than -4096 to avoid 67 | * conflicts with errno values on Linux. 68 | * 69 | * -- edward 70 | */ 71 | 72 | #define PAGE_LOCK_SUCCESS 0 73 | #define PAGE_LOCK_FAILED (-10001) 74 | #define PAGE_LOCK_LIMIT_EXCEEDED (-10002) 75 | #define PAGE_LOCK_TOUCH_FAILED (-10003) 76 | #define PAGE_LOCK_IN_TRANSITION (-10004) 77 | 78 | #define PAGE_LOCK_SYS_ERROR (-10010) 79 | #define PAGE_LOCK_ALREADY_LOCKED (-10011) 80 | #define PAGE_LOCK_MEMTRACKER_ERROR (-10012) 81 | #define PAGE_LOCK_PHYSTRACKER_ERROR (-10013) 82 | #define PAGE_LOCK_MDL_ERROR (-10014) 83 | 84 | #define PAGE_UNLOCK_SUCCESS 0 85 | #define PAGE_UNLOCK_NOT_TRACKED (-10100) 86 | #define PAGE_UNLOCK_NO_MPN (-10101) 87 | #define PAGE_UNLOCK_NOT_LOCKED (-10102) 88 | #define PAGE_UNLOCK_TOUCH_FAILED (-10103) 89 | #define PAGE_UNLOCK_MISMATCHED_TYPE (-10104) 90 | 91 | #define PAGE_LOOKUP_SUCCESS 0 92 | #define PAGE_LOOKUP_INVALID_ADDR (-10200) 93 | #define PAGE_LOOKUP_BAD_HIGH_ADDR (-10201) 94 | #define PAGE_LOOKUP_ZERO_ADDR (-10202) 95 | #define PAGE_LOOKUP_SMALL_ADDR (-10203) 96 | #define PAGE_LOOKUP_SYS_ERROR (-10204) 97 | #define PAGE_LOOKUP_NOT_TRACKED (-10) // added to another code 98 | #define PAGE_LOOKUP_NO_MPN (-20) // added to another code 99 | #define PAGE_LOOKUP_NOT_LOCKED (-30) // added to another code 100 | #define PAGE_LOOKUP_NO_VM (-40) // added to another code 101 | 102 | #define PAGE_LOCK_SOFT_FAILURE(status) (status <= PAGE_LOCK_FAILED && \ 103 | status > PAGE_LOCK_SYS_ERROR) 104 | 105 | #endif // ifndef _PAGELOCK_DEFS_H_ 106 | -------------------------------------------------------------------------------- /vmmon-only/include/perfctr.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * perfctr.h -- 22 | * 23 | */ 24 | 25 | #ifndef _PERFCTR_H_ 26 | #define _PERFCTR_H_ 27 | 28 | #define INCLUDE_ALLOW_USERLEVEL 29 | 30 | #define INCLUDE_ALLOW_VMKERNEL 31 | #define INCLUDE_ALLOW_MODULE 32 | #define INCLUDE_ALLOW_VMCORE 33 | #define INCLUDE_ALLOW_VMMON 34 | 35 | #include "includeCheck.h" 36 | #include "vm_basic_types.h" 37 | #include "perfctr_arch.h" 38 | 39 | #define PERF_EVENT_NAME_LEN 64 40 | 41 | /* 42 | * CrossProf: structures for unified profiling of vmm, vmx, and 43 | * vmkernel. Per-vcpu. 44 | */ 45 | 46 | #define CALLSTACK_CROSSPROF_PAGES 1 47 | 48 | typedef struct { 49 | /* 50 | * This structure is per-vcpu. The raw data is a packed vector 51 | * of MonitorCallStackSample, a variable-length structure. 52 | */ 53 | 54 | /* raw data - packed vec of MonitorCallStackSample, variable length */ 55 | uint8 crossProfSampleBuffer[PAGES_2_BYTES(CALLSTACK_CROSSPROF_PAGES)]; 56 | 57 | uint32 crossProfSampleBytes; 58 | uint32 crossProfNumDroppedSamples; /* For when buffer fills up */ 59 | Bool enabled; /* Can be false in stats build if monitor.callstack=FALSE */ 60 | uint8 _pad[3]; 61 | } CrossProfShared; 62 | 63 | /* 64 | * PerfCtr_Config -- 65 | * Describes configuration for a single hardware performance counter 66 | * 67 | * Since this is only used to record general performance counters, we 68 | * made the assumption in nmiProfiler.c that the type is GENERAL and 69 | * index is counter number of type GENERAL. 70 | * 71 | * **** x86 **** 72 | * On AMD K8 and GH: 73 | * index: Which perf ctr, 0 to 3. RDPMC argument 74 | * addr: MSR of raw perf ctr (0xc0010004 + index). 75 | * escrAddr: MSR # of the Perf Event Selector (0xc0010000 + index). 76 | * escrVal: Value placed in PerfEvtSel MSR; what to measure. 77 | * 78 | * On AMD with PerfCtrExtCore support: 79 | * index: Which perf ctr, 0 to 5. RDPMC argument 80 | * addr: MSR of raw perf ctr (0xc0010201 + 2 * index). 81 | * aliased PMCs 0 - 3 (0xc0010004 + index). 82 | * escrAddr: MSR # of the Perf Event Selector (0xc0010200 + 2 * index). 83 | * aliased PMCs 0 - 3 (0xc0010000 + index). 84 | * escrVal: Value placed in PerfEvtSel MSR; what to measure. 85 | * 86 | * On Intel Core architecture: 87 | * 88 | * 89 | * **** ARM **** 90 | * escrVal: Value placed in PMEVTYPER_EL0 to configure event counter 91 | * index: Index of the event counter. 92 | */ 93 | typedef struct PerfCtr_Config { 94 | uint64 escrVal; 95 | uint32 index; 96 | uint32 periodMean; 97 | 98 | /* 99 | * Random number (whose absolute value is capped at 100 | * periodJitterMask) is used to randomize sampling interval. 101 | */ 102 | uint32 periodJitterMask; 103 | uint32 seed; // seed is used to compute next random number 104 | uint16 config; 105 | Bool valid; 106 | PERFCTR_CONFIG_ARCH_FIELDS 107 | } PerfCtr_Config; 108 | 109 | 110 | #endif // ifndef _PERFCTR_H_ 111 | -------------------------------------------------------------------------------- /vmmon-only/include/pgtbl.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2002-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | #ifndef __PGTBL_H__ 21 | # define __PGTBL_H__ 22 | 23 | 24 | #include 25 | 26 | #include "compat_pgtable.h" 27 | #include "compat_spinlock.h" 28 | #include "compat_page.h" 29 | #include "compat_version.h" 30 | 31 | 32 | /* 33 | *----------------------------------------------------------------------------- 34 | * 35 | * PgtblVa2MPNLocked -- 36 | * 37 | * Walks through the hardware page tables to try to find the pte 38 | * associated to a virtual address. Then maps PTE to MPN. 39 | * 40 | * Results: 41 | * INVALID_MPN on failure 42 | * mpn on success 43 | * 44 | * Side effects: 45 | * None 46 | * 47 | *----------------------------------------------------------------------------- 48 | */ 49 | 50 | #if COMPAT_LINUX_VERSION_CHECK_LT(6, 5, 0) // only used by PgtblVa2MPN() below 51 | static INLINE MPN 52 | PgtblVa2MPNLocked(struct mm_struct *mm, // IN: Mm structure of a process 53 | VA addr) // IN: Address in the virtual address 54 | // space of that process 55 | { 56 | compat_p4d_t *p4d; 57 | MPN mpn; 58 | pgd_t *pgd = pgd_offset(mm, addr); 59 | 60 | if (pgd_present(*pgd) == 0) { 61 | return INVALID_MPN; 62 | } 63 | if (pgd_large(*pgd)) { 64 | /* Linux kernel does not support PGD huge pages. */ 65 | /* return pgd_pfn(*pgd) + ((addr & PGD_MASK) >> PAGE_SHIFT); */ 66 | return INVALID_MPN; 67 | } 68 | 69 | p4d = compat_p4d_offset(pgd, addr); 70 | if (compat_p4d_present(*p4d) == 0) { 71 | return INVALID_MPN; 72 | } 73 | if (compat_p4d_large(*p4d)) { 74 | mpn = compat_p4d_pfn(*p4d) + ((addr & ~COMPAT_P4D_MASK) >> PAGE_SHIFT); 75 | } else { 76 | pud_t *pud = pud_offset(p4d, addr); 77 | 78 | if (pud_present(*pud) == 0) { 79 | return INVALID_MPN; 80 | } 81 | if (pud_large(*pud)) { 82 | mpn = pud_pfn(*pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); 83 | } else { 84 | pmd_t *pmd = pmd_offset(pud, addr); 85 | 86 | if (pmd_present(*pmd) == 0) { 87 | return INVALID_MPN; 88 | } 89 | if (pmd_large(*pmd)) { 90 | mpn = pmd_pfn(*pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); 91 | } else { 92 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6,5,0) || defined(RHEL94_BACKPORTS) 93 | pte_t *pte = pte_offset_kernel(pmd, addr); 94 | #else 95 | pte_t *pte = pte_offset_map(pmd, addr); 96 | #endif 97 | 98 | if (pte_present(*pte) == 0) { 99 | pte_unmap(pte); 100 | return INVALID_MPN; 101 | } 102 | mpn = pte_pfn(*pte); 103 | pte_unmap(pte); 104 | } 105 | } 106 | } 107 | if (mpn >= INVALID_MPN) { 108 | mpn = INVALID_MPN; 109 | } 110 | return mpn; 111 | } 112 | #endif 113 | 114 | 115 | /* 116 | *----------------------------------------------------------------------------- 117 | * 118 | * PgtblVa2MPN -- 119 | * 120 | * Walks through the hardware page tables of the current process to try to 121 | * find the page structure associated to a virtual address. 122 | * 123 | * Results: 124 | * Same as PgtblVa2MPNLocked() 125 | * 126 | * Side effects: 127 | * None 128 | * 129 | *----------------------------------------------------------------------------- 130 | */ 131 | 132 | #if COMPAT_LINUX_VERSION_CHECK_LT(6, 5, 0) 133 | 134 | static INLINE MPN 135 | PgtblVa2MPN(VA addr) // IN 136 | { 137 | struct mm_struct *mm; 138 | MPN mpn; 139 | 140 | /* current->mm is NULL for kernel threads, so use active_mm. */ 141 | mm = current->active_mm; 142 | spin_lock(&mm->page_table_lock); 143 | mpn = PgtblVa2MPNLocked(mm, addr); 144 | spin_unlock(&mm->page_table_lock); 145 | return mpn; 146 | } 147 | 148 | #else /* COMPAT_LINUX_VERSION_CHECK_LT(6, 5, 0) */ 149 | 150 | static INLINE MPN 151 | PgtblVa2MPN(VA addr) // IN 152 | { 153 | struct page *page; 154 | int npages; 155 | MPN mpn; 156 | 157 | npages = get_user_pages_unlocked(addr, 1, &page, FOLL_HWPOISON); 158 | if (npages != 1) 159 | return INVALID_MPN; 160 | mpn = page_to_pfn(page); 161 | put_page(page); 162 | 163 | return mpn; 164 | } 165 | 166 | #endif /* COMPAT_LINUX_VERSION_CHECK_LT(6, 5, 0) */ 167 | 168 | #endif /* __PGTBL_H__ */ 169 | -------------------------------------------------------------------------------- /vmmon-only/include/rateconv.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2003-2016, 2018-2023 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * 21 | * rateconv.h -- 22 | * 23 | * Parameters and functions for linear rate conversion of 64 bit 24 | * counters: 25 | * 26 | * y = ((x * mult) >> shift) + add. 27 | * 28 | */ 29 | 30 | #ifndef _VM_RATECONV_H_ 31 | #define _VM_RATECONV_H_ 32 | 33 | #define INCLUDE_ALLOW_USERLEVEL 34 | #define INCLUDE_ALLOW_MODULE 35 | #define INCLUDE_ALLOW_VMKERNEL 36 | #define INCLUDE_ALLOW_VMK_MODULE 37 | #define INCLUDE_ALLOW_DISTRIBUTE 38 | #define INCLUDE_ALLOW_VMCORE 39 | #define INCLUDE_ALLOW_VMMON 40 | #include "includeCheck.h" 41 | 42 | #include "vm_basic_types.h" 43 | #include "vm_basic_asm.h" 44 | #include "vm_assert.h" 45 | #include "vm_atomic.h" 46 | #include "versioned_atomic.h" 47 | 48 | #if defined(VM_ARM_ANY) && defined(_MSC_VER) 49 | #include "mul64.h" 50 | #endif 51 | 52 | #if defined __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | 57 | /* RateConv_Params is part of vmx<->vmmon interface (INIT_PSEUDO_TSC ioctl) */ 58 | typedef struct RateConv_Params { 59 | uint32 mult; /* mult == 1 implies shift == 0. */ 60 | uint32 shift; 61 | int64 add; 62 | } RateConv_Params; 63 | 64 | typedef struct RateConv_ParamsVolatile { 65 | RateConv_Params p; 66 | VersionedAtomic vers; 67 | } RateConv_ParamsVolatile; 68 | 69 | typedef struct RateConv_Ratio { 70 | uint32 mult; 71 | uint32 shift; 72 | } RateConv_Ratio; 73 | 74 | #define RATE_CONV_IDENTITY { 1, 0, 0 } /* Out = in. */ 75 | 76 | Bool RateConv_ComputeParams(uint64 inHz, uint64 inBase, 77 | uint64 outHz, uint64 outBase, 78 | RateConv_Params *conv); 79 | void RateConv_LogParams(const char *prefix, 80 | uint64 inHz, uint64 inBase, 81 | uint64 outHz, uint64 outBase, 82 | const RateConv_Params *conv); 83 | Bool RateConv_ComputeRatio(uint64 inHz, uint64 outHz, 84 | RateConv_Ratio *ratio); 85 | void RateConv_LogRatio(const char *prefix, 86 | uint64 inHz, uint64 outHz, 87 | const RateConv_Ratio *ratio); 88 | 89 | 90 | /* 91 | *---------------------------------------------------------------------- 92 | * 93 | * RateConv_Unsigned -- 94 | * 95 | * Apply rate conversion to an unsigned argument: 96 | * y = ((x * mult) >> shift) + add. 97 | * 98 | *---------------------------------------------------------------------- 99 | */ 100 | 101 | static INLINE uint64 102 | RateConv_Unsigned(const RateConv_Params *conv, uint64 x) 103 | { 104 | return Mul64x3264(x, conv->mult, conv->shift) + (uint64)conv->add; 105 | } 106 | 107 | 108 | /* 109 | *---------------------------------------------------------------------- 110 | * 111 | * RateConv_Signed -- 112 | * 113 | * Apply rate conversion to a signed argument: 114 | * y = ((x * mult) >> shift) + add. 115 | * 116 | *---------------------------------------------------------------------- 117 | */ 118 | 119 | static INLINE int64 120 | RateConv_Signed(const RateConv_Params *conv, int64 x) 121 | { 122 | return Muls64x32s64(x, conv->mult, conv->shift) + conv->add; 123 | } 124 | 125 | 126 | #if defined __cplusplus 127 | } // extern "C" 128 | #endif 129 | 130 | #endif // _VM_RATECONV_H_ 131 | -------------------------------------------------------------------------------- /vmmon-only/include/sharedAreaType.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2018 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * sharedAreaType.h -- 21 | * 22 | * This file contains shared area type definitions. 23 | */ 24 | 25 | #ifndef _SHAREDAREATYPE_H_ 26 | #define _SHAREDAREATYPE_H_ 27 | 28 | #define INCLUDE_ALLOW_VMCORE 29 | #define INCLUDE_ALLOW_VMKERNEL 30 | #define INCLUDE_ALLOW_VMX 31 | #define INCLUDE_ALLOW_VMMON 32 | #define INCLUDE_ALLOW_USERLEVEL 33 | #define INCLUDE_ALLOW_MODULE 34 | 35 | #include "includeCheck.h" 36 | 37 | typedef enum { 38 | SHARED_AREA_PER_VM_VMX = 0, 39 | SHARED_AREA_INTER_VCPU_VMX, 40 | SHARED_AREA_PER_VCPU_VMX, 41 | SHARED_AREA_PER_VM, 42 | SHARED_AREA_INTER_VCPU, 43 | SHARED_AREA_PER_VCPU, 44 | NUM_SHARED_AREAS 45 | } SharedAreaType; 46 | 47 | #endif // _SHAREDAREATYPE_H_ 48 | -------------------------------------------------------------------------------- /vmmon-only/include/sharedAreaVmmon.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2018-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * sharedAreaVmmon.h -- 22 | * 23 | * VMMon shared area management. 24 | */ 25 | 26 | #ifndef SHARED_AREA_VMMON_H 27 | #define SHARED_AREA_VMMON_H 28 | 29 | #define INCLUDE_ALLOW_VMCORE 30 | #define INCLUDE_ALLOW_VMMON 31 | #include "includeCheck.h" 32 | 33 | #include "iocontrols.h" 34 | 35 | struct VMDriver; 36 | 37 | /* A collection of pages backing a shared area region. */ 38 | typedef struct SharedAreaVmmonRegion { 39 | PageCnt pagesPerVcpu; 40 | MPN *pages; 41 | } SharedAreaVmmonRegion; 42 | 43 | /* The VMMon Driver shared area. */ 44 | typedef struct SharedAreaVmmon { 45 | SharedAreaVmmonRegion regions[NUM_SHARED_AREAS]; 46 | } SharedAreaVmmon; 47 | 48 | /* Request for a backing MPN for a shared area region at a given VCPU/offset. */ 49 | typedef struct SharedAreaVmmonRequest { 50 | SharedAreaType type; 51 | Vcpuid vcpu; 52 | PageCnt offset; 53 | } SharedAreaVmmonRequest; 54 | 55 | SharedAreaVmmon *SharedAreaVmmon_Init(struct VMDriver *vm); 56 | void SharedAreaVmmon_Cleanup(SharedAreaVmmon *area); 57 | Bool SharedAreaVmmon_RegisterRegion(struct VMDriver *driver, 58 | VMSharedAreaRegistrationBlock *block); 59 | Bool SharedAreaVmmon_ValidateRegionArgs(struct VMDriver *driver, 60 | VMSharedAreaRegistrationBlock *block); 61 | MPN SharedAreaVmmon_GetRegionMPN(struct VMDriver *vm, 62 | SharedAreaVmmonRequest *request); 63 | #endif /* SHARED_AREA_VMMON_H */ 64 | -------------------------------------------------------------------------------- /vmmon-only/include/statVarsVmmon.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2018-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * statVarsVmmon.h -- 22 | * 23 | * VMMon stat vars management. 24 | */ 25 | 26 | #ifndef STAT_VARS_VMMON_H 27 | #define STAT_VARS_VMMON_H 28 | 29 | #define INCLUDE_ALLOW_VMCORE 30 | #define INCLUDE_ALLOW_VMMON 31 | #include "includeCheck.h" 32 | 33 | #include "iocontrols.h" 34 | 35 | struct VMDriver; 36 | 37 | /* The VMMon Driver stat vars area. */ 38 | typedef struct StatVarsVmmon { 39 | PageCnt pagesPerVcpu; 40 | MPN *pages; 41 | } StatVarsVmmon; 42 | 43 | StatVarsVmmon *StatVarsVmmon_Init(struct VMDriver *vm); 44 | void StatVarsVmmon_Cleanup(StatVarsVmmon *statVars); 45 | Bool StatVarsVmmon_RegisterVCPU(struct VMDriver *driver, 46 | VMStatVarsRegistrationBlock *block); 47 | MPN StatVarsVmmon_GetRegionMPN(struct VMDriver *vm, Vcpuid vcpuid, 48 | PageCnt offset); 49 | #endif /* STAT_VARS_VMMON_H */ 50 | -------------------------------------------------------------------------------- /vmmon-only/include/uccost.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2020 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * uccost.h 21 | * 22 | * Definitons for VMX86_UCCOST builds. 23 | */ 24 | 25 | #ifndef _UCCOST_H 26 | #define _UCCOST_H 27 | 28 | #define INCLUDE_ALLOW_VMCORE 29 | #define INCLUDE_ALLOW_VMMON 30 | #include "includeCheck.h" 31 | 32 | #include "vm_basic_defs.h" 33 | 34 | /* 35 | * Define VMX86_UCCOST in the makefiles (Local.mk, 36 | * typically) if you want a special build whose only purpose 37 | * is to measure the overhead of a user call and its 38 | * breakdown. 39 | * 40 | * WINDOWS NOTE: I don't know how to pass VMX86_UCCOST to 41 | * the driver build on Windows. It must be defined by hand. 42 | * 43 | * ESX Note: we don't have a crosspage in which to store these 44 | * timestamps. Such a feature would perhaps be nice (if we 45 | * ever tire of the argument that esx does so few usercalls 46 | * that speed doesn't matter). 47 | */ 48 | 49 | #if defined(VMX86_UCCOST) && !defined(VMX86_SERVER) 50 | #define UCTIMESTAMP(ptr, stamp) \ 51 | do { (ptr)[UCCOST_ ## stamp] = RDTSC(); } while (0) 52 | #else 53 | #define UCTIMESTAMP(cp, stamp) 54 | #endif 55 | 56 | #ifdef VMX86_SERVER 57 | typedef struct UCCostResults { 58 | uint32 vmksti; 59 | uint32 vmkcli; 60 | uint32 ucnop; 61 | } UCCostResults; 62 | #else 63 | 64 | typedef struct UCCostResults { 65 | uint32 htom; 66 | uint32 mtoh; 67 | uint32 ucnop; 68 | } UCCostResults; 69 | 70 | typedef enum UCCostStamp { 71 | #define UC(x, y) UCCOST_ ## x, 72 | #include "uccostTable.h" 73 | UCCOST_MAX 74 | } UCCostStamp; 75 | #endif // VMX86_SERVER 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /vmmon-only/include/uccostTable.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 1998-2014,2020 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #define INCLUDE_ALLOW_VMCORE 20 | #define INCLUDE_ALLOW_VMMON 21 | #include "includeCheck.h" 22 | 23 | UC(CALL_START, FALSE) 24 | UC(BEGIN_BACK_TO_HOST, FALSE) 25 | UC(SWITCHED_TO_MODULE, TRUE) 26 | UC(VMX_HANDLER_START, FALSE) 27 | UC(SWITCHING_TO_MONITOR, TRUE) 28 | UC(DONE_BACK_TO_HOST, FALSE) 29 | UC(CALL_END, FALSE) 30 | 31 | #undef UC 32 | -------------------------------------------------------------------------------- /vmmon-only/include/usercalldefs.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2008,2019-2020 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef USERCALLDEFS_H 20 | #define USERCALLDEFS_H 21 | 22 | #ifdef __linux__ 23 | #include 24 | #define USERCALL_RESTART (-ERESTARTNOINTR) 25 | #else 26 | #include 27 | #define USERCALL_RESTART (USERCALL_NOP) 28 | #endif 29 | /* 30 | * -1 to -4096 are reserved for syscall errors on Linux. -1 is reserved for 31 | * failing DeviceIoControl on Windows. 32 | */ 33 | #define USERCALL_VMX86ALLOCERR (-8192) 34 | #define USERCALL_SWITCHERR (-8193) 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /vmmon-only/include/vcpuid.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2014,2016-2021,2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * 22 | * vcpuid.h -- 23 | * 24 | * Monitor's VCPU ID. 25 | */ 26 | 27 | #ifndef _VCPUID_H_ 28 | #define _VCPUID_H_ 29 | 30 | #define INCLUDE_ALLOW_USERLEVEL 31 | 32 | #define INCLUDE_ALLOW_MODULE 33 | #define INCLUDE_ALLOW_VMMON 34 | #define INCLUDE_ALLOW_VMKERNEL 35 | #define INCLUDE_ALLOW_VMK_MODULE 36 | #define INCLUDE_ALLOW_DISTRIBUTE 37 | #define INCLUDE_ALLOW_VMCORE 38 | #include "includeCheck.h" 39 | 40 | #include "vm_basic_types.h" 41 | 42 | #if defined __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | typedef uint32 Vcpuid; // VCPU number 47 | 48 | #define VCPUID_INVALID (~0U) 49 | 50 | #define BOOT_VCPU_ID 0 51 | #define IS_BOOT_VCPUID(vcpuid) ((vcpuid) == BOOT_VCPU_ID) 52 | 53 | #define MAX_VCPUS 2048 54 | #define MAX_CORES_PER_SOCKET 512 55 | #define MAX_VCPU_SOCKETS 128 56 | 57 | /* 58 | * There are several properties of the VM which change at the 128 VCPU 59 | * boundary. EFI firmware, x2APIC, and IOMMU are required among others. 60 | */ 61 | #define MAX_SMALL_VM_VCPUS 128 62 | 63 | /* Supported limit. */ 64 | #define MAX_SUPPORTED_VCPUS 960 65 | 66 | #if defined __cplusplus 67 | } // extern "C" 68 | #endif 69 | 70 | #endif // ifndef _VCPUID_H_ 71 | -------------------------------------------------------------------------------- /vmmon-only/include/vcpuset_types.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2002-2013, 2016-2017, 2021 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * vcpuset_types.h -- 21 | * 22 | * ADT for a set of VCPUs. Implemented as an array of bitmasks. 23 | * 24 | */ 25 | 26 | #ifndef _VCPUSET_TYPES_H_ 27 | #define _VCPUSET_TYPES_H_ 28 | 29 | 30 | #define INCLUDE_ALLOW_VMX 31 | #define INCLUDE_ALLOW_MODULE 32 | #define INCLUDE_ALLOW_VMMON 33 | #define INCLUDE_ALLOW_VMKERNEL 34 | #define INCLUDE_ALLOW_USERLEVEL 35 | #define INCLUDE_ALLOW_VMCORE 36 | #include "includeCheck.h" 37 | 38 | #include "vcpuid.h" 39 | #include "vm_assert.h" 40 | 41 | #define VCS_SUBSET_WIDTH 64 42 | #define VCS_SUBSET_SHIFT 6 43 | #define VCS_SUBSET_MASK ((CONST64U(1) << VCS_SUBSET_SHIFT) - 1) 44 | #define VCS_SUBSET_COUNT 32 45 | 46 | 47 | #define VCS_VCPUID_SUBSET_IDX(v) ((v) >> VCS_SUBSET_SHIFT) 48 | #define VCS_VCPUID_SUBSET_BIT(v) (CONST64U(1) << ((v) & VCS_SUBSET_MASK)) 49 | 50 | typedef struct VCPUSet { 51 | uint64 subset[VCS_SUBSET_COUNT]; 52 | } VCPUSet; 53 | 54 | MY_ASSERTS(VCPUSET_ASSERTS, 55 | ASSERT_ON_COMPILE(VCS_SUBSET_WIDTH * VCS_SUBSET_COUNT >= MAX_VCPUS); 56 | /* 57 | * There is code that depends on sizeof(VCPUSet) being a power of 58 | * 2 in at least vcpuHotPlug.c and possible other places. 59 | */ 60 | ASSERT_ON_COMPILE((sizeof(VCPUSet) & (sizeof(VCPUSet) - 1)) == 0); 61 | ) 62 | #endif 63 | -------------------------------------------------------------------------------- /vmmon-only/include/vm_asm.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 1998-2014,2019,2024 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * vm_asm.h 21 | * 22 | * asm macros 23 | */ 24 | 25 | #ifndef _VM_ASM_H_ 26 | #define _VM_ASM_H_ 27 | 28 | 29 | #define INCLUDE_ALLOW_MODULE 30 | #define INCLUDE_ALLOW_VMK_MODULE 31 | #define INCLUDE_ALLOW_VMKERNEL 32 | #define INCLUDE_ALLOW_DISTRIBUTE 33 | #define INCLUDE_ALLOW_VMCORE 34 | #define INCLUDE_ALLOW_VMMON 35 | #define INCLUDE_ALLOW_USERLEVEL 36 | #include "includeCheck.h" 37 | 38 | #ifdef VM_ARM_64 39 | #include "vm_asm_arm64.h" 40 | #else 41 | 42 | #include "vm_basic_asm.h" 43 | #include "x86msr.h" 44 | #include "vm_asm_x86.h" 45 | 46 | 47 | static inline void 48 | SET_FS64(uint64 fs64) 49 | { 50 | X86MSR_SetMSR(MSR_FSBASE, fs64); 51 | } 52 | 53 | 54 | static inline void 55 | SET_GS64(uint64 gs64) 56 | { 57 | X86MSR_SetMSR(MSR_GSBASE, gs64); 58 | } 59 | 60 | static inline void 61 | SET_KernelGS64(uint64 kgs64) 62 | { 63 | X86MSR_SetMSR(MSR_KERNELGSBASE, kgs64); 64 | } 65 | 66 | 67 | static inline uint64 68 | GET_FS64(void) 69 | { 70 | return X86MSR_GetMSR(MSR_FSBASE); 71 | } 72 | 73 | 74 | static inline uint64 75 | GET_GS64(void) 76 | { 77 | return X86MSR_GetMSR(MSR_GSBASE); 78 | } 79 | 80 | 81 | static inline uint64 82 | GET_KernelGS64(void) 83 | { 84 | return X86MSR_GetMSR(MSR_KERNELGSBASE); 85 | } 86 | 87 | #endif // VM_ARM_64 88 | #endif 89 | -------------------------------------------------------------------------------- /vmmon-only/include/vm_idt.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2012-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * vm_idt.h -- 22 | * 23 | * Definitions for IDT use in VMware Products which run VMs on x86_64. 24 | */ 25 | 26 | #ifndef _VM_IDT_H_ 27 | #define _VM_IDT_H_ 28 | 29 | #define INCLUDE_ALLOW_USERLEVEL 30 | #define INCLUDE_ALLOW_MODULE 31 | #define INCLUDE_ALLOW_VMMON 32 | #define INCLUDE_ALLOW_VMK_MODULE 33 | #define INCLUDE_ALLOW_VMKERNEL 34 | #define INCLUDE_ALLOW_VMCORE 35 | #include "includeCheck.h" 36 | 37 | #if defined __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* 42 | * User worlds are the only worlds that expect to receive 43 | * interrupts on a stack specified in the %rsp entries of 44 | * the TSS. 45 | */ 46 | #define TSS_RSP0 0 47 | #define TSS_RSP1 1 48 | #define TSS_RSP2 2 49 | 50 | /* 51 | * IDTR limit is set to the maximum because after a vmexit Intel's VT restores 52 | * the IDTR but sets the limit to the maximum value. Please see details 27.5.2 53 | * Loading Host Segment and Descriptor-Table Registers from the Intel manual. 54 | */ 55 | #define IDT_LIMIT 0xFFFF 56 | 57 | #define IDT_NUM_GATES 0x100 58 | /* 59 | * The monitor and the vmkernel use gate stub handlers of a constant size in 60 | * their respective gate stubs called by IDT entries. The only exception is 61 | * the #PF gate (#14) which is twice as long in the monitor IDT, to copy CR2. 62 | */ 63 | #define IDT_VMM_STUB_SIZE 16 64 | #define IDT_VMK_STUB_SIZE 32 65 | #define IDT_VMK_STUB_SIZE_BITS 5 66 | 67 | #define IST_NONE 0 68 | /* IST entries for the monitor. */ 69 | #define IST_VMM_DF 1 70 | #define IST_VMM_NMI 2 71 | #define IST_VMM_MCE 3 72 | #define MAX_VMM_IST 3 73 | /* IST entries for the vmkernel. */ 74 | #define IST_VMK_MCE 5 75 | #define IST_VMK_DF 6 76 | #define IST_VMK_NMI 7 77 | 78 | 79 | static inline int 80 | IDT_MonitorISTForVector(int v) 81 | { 82 | /* 83 | * For non-SVM execution, the monitor uses the IST for #DF, #NMI, and #MC. 84 | */ 85 | if (v == EXC_DF) { 86 | return IST_VMM_DF; 87 | } else if (v == EXC_NMI) { 88 | return IST_VMM_NMI; 89 | } else if (v == EXC_MC) { 90 | return IST_VMM_MCE; 91 | } 92 | return IST_NONE; 93 | } 94 | 95 | #if defined __cplusplus 96 | } // extern "C" 97 | #endif 98 | 99 | #endif /* _VM_IDT_H_ */ 100 | -------------------------------------------------------------------------------- /vmmon-only/include/vm_time.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 1998 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | 20 | /* 21 | * vm_time.h -- 22 | * 23 | * Time management functions. 24 | * Part of driver-only distribution 25 | * 26 | * see comment in poll.c 27 | */ 28 | 29 | 30 | #ifndef VM_TIME_H 31 | #define VM_TIME_H 32 | 33 | #define INCLUDE_ALLOW_USERLEVEL 34 | #define INCLUDE_ALLOW_VMCORE 35 | #include "includeCheck.h" 36 | 37 | 38 | struct VmTimeVirtualRealClock; 39 | typedef struct VmTimeVirtualRealClock VmTimeVirtualRealClock; 40 | 41 | #ifdef USERLEVEL 42 | 43 | VmTimeType VmTime_ReadVirtualTime(void); 44 | VmTimeVirtualRealClock *VmTime_NewVirtualRealClock(void); 45 | void VmTime_StartVirtualRealClock(VmTimeVirtualRealClock *, double); 46 | void VmTime_ResetVirtualRealClock(VmTimeVirtualRealClock *); 47 | VmTimeType VmTime_ReadVirtualRealTime(VmTimeVirtualRealClock *); 48 | VmTimeType VmTime_RemainingVirtualRealTime(VmTimeVirtualRealClock *, 49 | VmTimeType realTime); 50 | void VmTime_UpdateVirtualRealTime(VmTimeVirtualRealClock *clock, 51 | VmTimeType realTime, 52 | VmTimeType virtualTime); 53 | #endif 54 | #endif /* VM_TIME_H */ 55 | 56 | -------------------------------------------------------------------------------- /vmmon-only/include/vmmblob.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2017-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * vmmblob.h -- 22 | * 23 | * VMM blob management. 24 | */ 25 | 26 | #ifndef VMMBLOB_H 27 | #define VMMBLOB_H 28 | 29 | #define INCLUDE_ALLOW_VMCORE 30 | #define INCLUDE_ALLOW_VMMON 31 | #include "includeCheck.h" 32 | 33 | struct VMDriver; 34 | struct MonLoaderHeader; 35 | 36 | typedef struct VmmBlobInfo { 37 | uint8 *blobPtr; 38 | uint32 numBytes; 39 | MPN *mpns; 40 | struct MonLoaderHeader *header; 41 | } VmmBlobInfo; 42 | 43 | void VmmBlob_Cleanup(VmmBlobInfo *bi); 44 | Bool VmmBlob_Load(VA64 bsBlobAddr, uint32 numBytes, uint32 headerOffset, 45 | VmmBlobInfo **blobInfo); 46 | MPN VmmBlob_GetMpn(struct VMDriver *vm, uint64 blobOffset); 47 | MPN VmmBlob_GetHeaderMpn(struct VMDriver *vm); 48 | uint8 *VmmBlob_GetPtr(VMDriver *vm); 49 | uint64 VmmBlob_GetSize(VMDriver *vm); 50 | 51 | #endif /* VMMBLOB_H */ 52 | -------------------------------------------------------------------------------- /vmmon-only/include/x86cet.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2020-2021 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef _X86CET_H_ 20 | #define _X86CET_H_ 21 | 22 | /* 23 | * x86cet.h -- 24 | * 25 | * Contains definitions for the x86 Control-flow Enforcement Technology 26 | * (CET) features: Shadow Stacks and Indirect Branch Tracking. 27 | */ 28 | 29 | #include "x86paging_64.h" 30 | 31 | /* Error codes for #CP causes. */ 32 | #define CP_NEAR_RET 1 33 | #define CP_FAR_RET_IRET 2 34 | #define CP_ENDBRANCH 3 35 | #define CP_RSTORSSP 4 36 | #define CP_SETSSBSY 5 37 | #define CP_ENCL (1 << 15) 38 | 39 | /* Bits for token checks when switching %ssp. */ 40 | #define SSP_SUPERVISOR_TOKEN_BUSY (1 << 0) 41 | #define SSP_RSTOR_TOKEN_LM (1 << 0) 42 | #define SSP_PREV_TOKEN (1 << 1) 43 | 44 | /* The Shadow Stack pointer is always 4-byte aligned. */ 45 | #define SSP_ALIGN_MASK 0x3 46 | #define INVALID_SSP SSP_ALIGN_MASK 47 | 48 | /* 49 | * Shadow Frame -- 50 | * Pushed onto the new shadow stack upon exceptions, interrupts, and 51 | * far calls except User->Supervisor. 52 | * Popped off the old shadow stack upon lret or iret, except 53 | * Supervisor->User. 54 | */ 55 | typedef struct { 56 | uint64 ssp; 57 | uint64 lip; 58 | Selector cs, __cs_unused[3]; 59 | } ShadowFrame64; 60 | 61 | typedef ALIGNED(8) struct { 62 | uint32 ssp, __ssp_unused; 63 | uint32 lip, __lip_unused; 64 | Selector cs, __cs_unused[3]; 65 | } ShadowFrame32; 66 | 67 | 68 | /* 69 | * CET_IBTComputeLegacyByte -- 70 | * Calculates the bit position in the legacy bitmap for the given LA. 71 | * LA [63 ... 48][47 .... 15][14 13 12][11 ... 0] 72 | * unused byteNum bitNum 73 | */ 74 | static inline void 75 | CET_IBTComputeLegacyByte(LA la, uint64 *byteNum, uint8 *byteMask) 76 | { 77 | const unsigned bitsPerByte = 8; 78 | uint64 bitNum = LA_2_LPN((LA64)la & MASK64(VA64_IMPL_BITS)); 79 | *byteNum = bitNum / bitsPerByte; 80 | *byteMask = (uint8)(1 << (bitNum % bitsPerByte)); 81 | } 82 | 83 | #endif /* ifndef _X86CET_H_ */ 84 | -------------------------------------------------------------------------------- /vmmon-only/include/x86cpuid_asm.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2003-2020 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * x86cpuid_asm.h 21 | * 22 | * CPUID-related assembly functions. 23 | */ 24 | 25 | #ifndef _X86CPUID_ASM_H_ 26 | #define _X86CPUID_ASM_H_ 27 | 28 | #define INCLUDE_ALLOW_USERLEVEL 29 | 30 | #define INCLUDE_ALLOW_MODULE 31 | #define INCLUDE_ALLOW_VMMON 32 | #define INCLUDE_ALLOW_VMK_MODULE 33 | #define INCLUDE_ALLOW_VMKERNEL 34 | #define INCLUDE_ALLOW_DISTRIBUTE 35 | #define INCLUDE_ALLOW_VMCORE 36 | #include "includeCheck.h" 37 | 38 | #include "vm_basic_asm.h" 39 | #include "x86cpuid.h" 40 | 41 | 42 | #ifdef __GNUC__ // { 43 | 44 | /* 45 | * Checked against the Intel manual and GCC --hpreg 46 | * 47 | * Need __volatile__ and "memory" since CPUID has a synchronizing effect. 48 | * The CPUID may also change at runtime (APIC flag, etc). 49 | * 50 | */ 51 | 52 | #if defined VM_X86_64 || !defined __PIC__ 53 | #define VM_CPUID_BLOCK "cpuid" 54 | #define VM_EBX_OUT(reg) "=b"(reg) 55 | #else 56 | /* %ebx is reserved on i386 PIC. */ 57 | #define VM_CPUID_BLOCK "movl %%ebx, %1\n\t" \ 58 | "cpuid\n\t" \ 59 | "xchgl %%ebx, %1\n\t" 60 | #define VM_EBX_OUT(reg) "=&rm"(reg) 61 | #endif 62 | 63 | static INLINE void 64 | __GET_CPUID(uint32 eax, // IN 65 | CPUIDRegs *regs) // OUT 66 | { 67 | __asm__ __volatile__( 68 | VM_CPUID_BLOCK 69 | : "=a" (regs->eax), 70 | VM_EBX_OUT(regs->ebx), 71 | "=c" (regs->ecx), 72 | "=d" (regs->edx) 73 | : "a" (eax) 74 | : "memory" 75 | ); 76 | } 77 | 78 | static INLINE void 79 | __GET_CPUID2(uint32 eax, // IN 80 | uint32 ecx, // IN 81 | CPUIDRegs *regs) // OUT 82 | { 83 | __asm__ __volatile__( 84 | VM_CPUID_BLOCK 85 | : "=a" (regs->eax), 86 | VM_EBX_OUT(regs->ebx), 87 | "=c" (regs->ecx), 88 | "=d" (regs->edx) 89 | : "a" (eax), "c" (ecx) 90 | : "memory" 91 | ); 92 | } 93 | 94 | static INLINE uint32 95 | __GET_EAX_FROM_CPUID(uint32 eax) // IN 96 | { 97 | uint32 ebx; 98 | 99 | __asm__ __volatile__( 100 | VM_CPUID_BLOCK 101 | : "=a" (eax), 102 | VM_EBX_OUT(ebx) 103 | : "a" (eax) 104 | : "memory", "%ecx", "%edx" 105 | ); 106 | 107 | return eax; 108 | } 109 | 110 | static INLINE uint32 111 | __GET_EBX_FROM_CPUID(uint32 eax) // IN 112 | { 113 | uint32 ebx; 114 | 115 | __asm__ __volatile__( 116 | VM_CPUID_BLOCK 117 | : "=a" (eax), VM_EBX_OUT(ebx) 118 | : "a" (eax) 119 | : "memory", "%ecx", "%edx" 120 | ); 121 | 122 | return ebx; 123 | } 124 | 125 | static INLINE uint32 126 | __GET_ECX_FROM_CPUID(uint32 eax) // IN 127 | { 128 | uint32 ecx; 129 | uint32 ebx; 130 | 131 | __asm__ __volatile__( 132 | VM_CPUID_BLOCK 133 | : "=a" (eax), 134 | VM_EBX_OUT(ebx), 135 | "=c" (ecx) 136 | : "a" (eax) 137 | : "memory", "%edx" 138 | ); 139 | 140 | return ecx; 141 | } 142 | 143 | static INLINE uint32 144 | __GET_EDX_FROM_CPUID(uint32 eax) // IN 145 | { 146 | uint32 edx; 147 | uint32 ebx; 148 | 149 | __asm__ __volatile__( 150 | VM_CPUID_BLOCK 151 | : "=a" (eax), 152 | VM_EBX_OUT(ebx), 153 | "=d" (edx) 154 | : "a" (eax) 155 | : "memory", "%ecx" 156 | ); 157 | 158 | return edx; 159 | } 160 | 161 | 162 | #undef VM_CPUID_BLOCK 163 | #undef VM_EBX_OUT 164 | 165 | #elif defined(_MSC_VER) // } { 166 | 167 | static INLINE void 168 | __GET_CPUID(uint32 input, CPUIDRegs *regs) 169 | { 170 | __cpuid((int *)regs, input); 171 | } 172 | 173 | static INLINE void 174 | __GET_CPUID2(uint32 inputEax, uint32 inputEcx, CPUIDRegs *regs) 175 | { 176 | __cpuidex((int *)regs, inputEax, inputEcx); 177 | } 178 | 179 | static INLINE uint32 180 | __GET_EAX_FROM_CPUID(uint32 input) 181 | { 182 | CPUIDRegs regs; 183 | __cpuid((int *)®s, input); 184 | return regs.eax; 185 | } 186 | 187 | static INLINE uint32 188 | __GET_EBX_FROM_CPUID(uint32 input) 189 | { 190 | CPUIDRegs regs; 191 | __cpuid((int *)®s, input); 192 | return regs.ebx; 193 | } 194 | 195 | static INLINE uint32 196 | __GET_ECX_FROM_CPUID(uint32 input) 197 | { 198 | CPUIDRegs regs; 199 | __cpuid((int *)®s, input); 200 | return regs.ecx; 201 | } 202 | 203 | static INLINE uint32 204 | __GET_EDX_FROM_CPUID(uint32 input) 205 | { 206 | CPUIDRegs regs; 207 | __cpuid((int *)®s, input); 208 | return regs.edx; 209 | } 210 | 211 | #else // } 212 | #error 213 | #endif 214 | 215 | #define CPUID_FOR_SIDE_EFFECTS() ((void)__GET_EAX_FROM_CPUID(0)) 216 | 217 | #endif 218 | -------------------------------------------------------------------------------- /vmmon-only/include/x86segdescrs.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2006-2020 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * x86segdescrs.h -- 21 | * 22 | * Type definitions for the x86 segment descriptors. 23 | */ 24 | 25 | #ifndef _X86SEGDESCRS_H_ 26 | #define _X86SEGDESCRS_H_ 27 | 28 | #define INCLUDE_ALLOW_USERLEVEL 29 | 30 | #define INCLUDE_ALLOW_MODULE 31 | #define INCLUDE_ALLOW_VMK_MODULE 32 | #define INCLUDE_ALLOW_VMKERNEL 33 | #define INCLUDE_ALLOW_DISTRIBUTE 34 | #define INCLUDE_ALLOW_VMCORE 35 | #define INCLUDE_ALLOW_VMMON 36 | #include "includeCheck.h" 37 | 38 | #include "vm_basic_types.h" 39 | #include "vm_basic_defs.h" 40 | 41 | /* 42 | * Segment Descriptors. 43 | */ 44 | 45 | typedef struct Descriptor { 46 | unsigned limit_lo : 16; 47 | unsigned base_lo : 16; 48 | unsigned base_mid : 8; 49 | unsigned type : 4; 50 | unsigned S : 1; 51 | unsigned DPL : 2; 52 | unsigned present : 1; 53 | unsigned limit_hi : 4; 54 | unsigned AVL : 1; 55 | unsigned longmode : 1; 56 | unsigned DB : 1; 57 | unsigned gran : 1; 58 | unsigned base_hi : 8; 59 | } Descriptor; 60 | 61 | /* 62 | * 16-byte system descriptors for 64-bit mode. 63 | */ 64 | 65 | #pragma pack(push, 1) 66 | typedef struct Descriptor64 { 67 | uint64 limit_lo : 16; // Limit bits 15-0. 68 | uint64 base_lo : 24; // Base bits 23-0. 69 | uint64 type : 4; 70 | uint64 S : 1; 71 | uint64 DPL : 2; 72 | uint64 present : 1; 73 | uint64 limit_hi : 4; // Limit bits 19-16. 74 | uint64 AVL : 1; 75 | uint64 reserved0 : 2; 76 | uint64 gran : 1; 77 | uint64 base_mid : 8; // Base bits 31-24. 78 | uint64 base_hi : 32; // Base bits 63-32. 79 | uint64 reserved1 : 8; 80 | uint64 ext_attrs : 5; 81 | uint64 reserved2 : 19; 82 | } Descriptor64; 83 | #pragma pack(pop) 84 | 85 | typedef union { 86 | Descriptor desc; 87 | uint32 word[2]; 88 | uint64 qword; 89 | } DescriptorUnion; 90 | 91 | typedef union { 92 | Descriptor64 desc; 93 | Descriptor part[2]; 94 | uint32 word[4]; 95 | uint64 qword[2]; 96 | } Descriptor64Union; 97 | 98 | 99 | #endif // ifndef _X86SEGDESCRS_H_ 100 | -------------------------------------------------------------------------------- /vmmon-only/include/x86sel.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2006-2014,2020 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * x86sel.h -- 21 | * 22 | * Definitions and macros for dealing with x86 segment selectors. 23 | */ 24 | 25 | #ifndef _X86SEL_H_ 26 | #define _X86SEL_H_ 27 | 28 | #define INCLUDE_ALLOW_USERLEVEL 29 | 30 | #define INCLUDE_ALLOW_MODULE 31 | #define INCLUDE_ALLOW_VMMON 32 | #define INCLUDE_ALLOW_VMK_MODULE 33 | #define INCLUDE_ALLOW_VMKERNEL 34 | #define INCLUDE_ALLOW_DISTRIBUTE 35 | #define INCLUDE_ALLOW_VMCORE 36 | #include "includeCheck.h" 37 | 38 | #if defined __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "vm_assert.h" 43 | 44 | #define SELECTOR_GDT 0 45 | #define SELECTOR_LDT 1 46 | #define SELECTOR_RPL_SHIFT 0 47 | #define SELECTOR_RPL_MASK 0x03u 48 | #define SELECTOR_TI_SHIFT 2 49 | #define SELECTOR_TI_MASK 0x4 50 | #define SELECTOR_INDEX_SHIFT 3 51 | #define SELECTOR_INDEX_MASK 0xfff8 52 | 53 | #define SELECTOR_RPL(_sel) (((Selector)(_sel)) & SELECTOR_RPL_MASK) 54 | #define SELECTOR_TABLE(_sel) ((((Selector)(_sel)) & SELECTOR_TI_MASK) >> SELECTOR_TI_SHIFT) 55 | #define SELECTOR_INDEX(_sel) (((Selector)(_sel)) >> SELECTOR_INDEX_SHIFT) 56 | #define SELECTOR_CLEAR_RPL(_sel) ((Selector)(((Selector)(_sel)) & ~SELECTOR_RPL_MASK)) 57 | #define NULL_SELECTOR(_sel) (!SELECTOR_CLEAR_RPL(_sel)) 58 | 59 | #define MAKE_SELECTOR_UNCHECKED(_index, _ti, _RPL) \ 60 | ((Selector)(((_index) << SELECTOR_INDEX_SHIFT) | \ 61 | ((_ti ) << SELECTOR_TI_SHIFT) | \ 62 | ((_RPL ) << SELECTOR_RPL_SHIFT))) 63 | 64 | static INLINE Selector 65 | MAKE_SELECTOR(unsigned index, unsigned ti, unsigned rpl) 66 | { 67 | ASSERT(index <= (SELECTOR_INDEX_MASK >> SELECTOR_INDEX_SHIFT) && 68 | ti <= (SELECTOR_TI_MASK >> SELECTOR_TI_SHIFT) && 69 | rpl <= (SELECTOR_RPL_MASK >> SELECTOR_RPL_SHIFT)); 70 | return MAKE_SELECTOR_UNCHECKED(index, ti, rpl); 71 | } 72 | 73 | 74 | #if defined __cplusplus 75 | } // extern "C" 76 | #endif 77 | 78 | #endif /* !defined _X86SEL_H_ */ 79 | -------------------------------------------------------------------------------- /vmmon-only/include/x86vendor.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 1998-2018 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef _X86VENDOR_H_ 20 | #define _X86VENDOR_H_ 21 | 22 | /* 23 | * CPU vendors 24 | */ 25 | 26 | typedef enum { 27 | CPUID_VENDOR_UNKNOWN, 28 | CPUID_VENDOR_COMMON, 29 | CPUID_VENDOR_INTEL, 30 | CPUID_VENDOR_AMD, 31 | CPUID_VENDOR_CYRIX, 32 | CPUID_VENDOR_VIA, 33 | CPUID_VENDOR_HYGON, 34 | CPUID_NUM_VENDORS 35 | } CpuidVendor; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /vmmon-only/include/x86vt-exit-reasons.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2016-2018,2021-2023 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * x86vt-exit-reasons.h -- 21 | * 22 | * VT exit reasons. 23 | * 24 | */ 25 | 26 | #include "community_source.h" 27 | 28 | /* 29 | * Definitions for fields in the exit reason. Bits 28 and 29 are only applicable 30 | * for exits that end in SMM. Bit 16 is MBZ while other bits are reserved for 31 | * future use. 32 | */ 33 | #define VT_EXITREASON_BASIC_REASON_MASK 0xFFFF 34 | #define VT_EXITREASON_FRACT_SHSTK (1U << 25) 35 | #define VT_EXITREASON_BUSLOCK_ASSERTED (1U << 26) 36 | #define VT_EXITREASON_INSIDE_ENCLAVE (1U << 27) 37 | #define VT_EXITREASON_PENDING_MTF (1U << 28) 38 | #define VT_EXITREASON_EXIT_ROOT_OPERATION (1U << 29) 39 | #define VT_EXITREASON_VMENTRYFAIL (1U << 31) 40 | 41 | VT_EXIT(EXC_OR_NMI, 0) 42 | VT_EXIT(EXTINT, 1) 43 | VT_EXIT(TRIPLEFAULT, 2) 44 | VT_EXIT(INIT, 3) 45 | VT_EXIT(SIPI, 4) 46 | VT_EXIT(IOSMI, 5) 47 | VT_EXIT(OTHERSMI, 6) 48 | VT_EXIT(VINTR_WINDOW, 7) 49 | VT_EXIT(VNMI_WINDOW, 8) 50 | VT_EXIT(TS, 9) 51 | VT_EXIT(CPUID, 10) 52 | VT_EXIT(GETSEC, 11) 53 | VT_EXIT(HLT, 12) 54 | VT_EXIT(INVD, 13) 55 | VT_EXIT(INVLPG, 14) 56 | VT_EXIT(RDPMC, 15) 57 | VT_EXIT(RDTSC, 16) 58 | VT_EXIT(RSM, 17) 59 | VT_EXIT(VMCALL, 18) 60 | VT_EXIT(VMCLEAR, 19) 61 | VT_EXIT(VMLAUNCH, 20) 62 | VT_EXIT(VMPTRLD, 21) 63 | VT_EXIT(VMPTRST, 22) 64 | VT_EXIT(VMREAD, 23) 65 | VT_EXIT(VMRESUME, 24) 66 | VT_EXIT(VMWRITE, 25) 67 | VT_EXIT(VMXOFF, 26) 68 | VT_EXIT(VMXON, 27) 69 | VT_EXIT(CR, 28) 70 | VT_EXIT(DR, 29) 71 | VT_EXIT(IO, 30) 72 | VT_EXIT(RDMSR, 31) 73 | VT_EXIT(WRMSR, 32) 74 | VT_EXIT(VMENTRYFAIL_GUEST, (33 | VT_EXITREASON_VMENTRYFAIL)) 75 | VT_EXIT(VMENTRYFAIL_MSR, (34 | VT_EXITREASON_VMENTRYFAIL)) 76 | VT_EXIT(VMEXIT35, 35) 77 | VT_EXIT(MWAIT, 36) 78 | VT_EXIT(MTF, 37) 79 | VT_EXIT(VMEXIT38, 38) 80 | VT_EXIT(MONITOR, 39) 81 | VT_EXIT(PAUSE, 40) 82 | VT_EXIT(VMENTRYFAIL_MC, (41 | VT_EXITREASON_VMENTRYFAIL)) 83 | VT_EXIT(VMEXIT42, 42) 84 | VT_EXIT(TPR, 43) 85 | VT_EXIT(APIC, 44) 86 | VT_EXIT(EOI, 45) 87 | VT_EXIT(GDTR_IDTR, 46) 88 | VT_EXIT(LDTR_TR, 47) 89 | VT_EXIT(EPT_VIOLATION, 48) 90 | VT_EXIT(EPT_MISCONFIG, 49) 91 | VT_EXIT(INVEPT, 50) 92 | VT_EXIT(RDTSCP, 51) 93 | VT_EXIT(TIMER, 52) 94 | VT_EXIT(INVVPID, 53) 95 | VT_EXIT(WBINVD, 54) 96 | VT_EXIT(XSETBV, 55) 97 | VT_EXIT(APIC_WRITE, 56) 98 | VT_EXIT(RDRAND, 57) 99 | VT_EXIT(INVPCID, 58) 100 | VT_EXIT(VMFUNC, 59) 101 | VT_EXIT(ENCLS, 60) 102 | VT_EXIT(RDSEED, 61) 103 | VT_EXIT(PML_LOGFULL, 62) 104 | VT_EXIT(XSAVES, 63) 105 | VT_EXIT(XRSTORS, 64) 106 | VT_EXIT(VMEXIT65, 65) 107 | VT_EXIT(SPP_EVENT, 66) 108 | VT_EXIT(UMWAIT, 67) 109 | VT_EXIT(TPAUSE, 68) 110 | VT_EXIT(LOADIWKEY, 69) 111 | VT_EXIT(ENCLV, 70) 112 | VT_EXIT(SGX_CONFLICT, 71) 113 | VT_EXIT(ENQCMD_PASID_FAIL, 72) 114 | VT_EXIT(ENQCMDS_PASID_FAIL, 73) 115 | VT_EXIT(BUS_LOCK, 74) 116 | VT_EXIT(NOTIFY_WINDOW, 75) 117 | VT_EXIT(SEAMCALL, 76) 118 | VT_EXIT(TDCALL, 77) 119 | /* Bump this up if you add an exit reason. */ 120 | #define VT_NUM_EXIT_REASONS 78 121 | -------------------------------------------------------------------------------- /vmmon-only/linux/driver.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | #ifndef __DRIVER_H__ 21 | #define __DRIVER_H__ 22 | 23 | #define INCLUDE_ALLOW_VMMON 24 | #define INCLUDE_ALLOW_VMCORE 25 | #include "includeCheck.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "vmx86.h" 34 | 35 | 36 | /* Per-instance driver state */ 37 | struct VMDriver; 38 | 39 | typedef struct Device { 40 | struct Device *next; 41 | struct VMDriver *vm; 42 | /* 43 | * This RW semaphore protects accesses to the VMDriver to 44 | * avoid racing between various ioctls, and the creation 45 | * and removal of the VM in question. The lock is read-acquired 46 | * by ioctls that reference the VMDriver, and write-acquired by 47 | * ioctls or device callbacks that allocate or destroy the 48 | * VMDriver. 49 | */ 50 | struct rw_semaphore vmDriverRWSema; 51 | } Device; 52 | 53 | 54 | /* 55 | * Static driver state. 56 | */ 57 | 58 | #define LINUXLOG_BUFFER_SIZE 1024 59 | 60 | typedef struct VMXLinuxState { 61 | char buf[LINUXLOG_BUFFER_SIZE]; 62 | Device *head; 63 | 64 | struct task_struct *fastClockThread; 65 | unsigned fastClockRate; 66 | } VMXLinuxState; 67 | 68 | extern VMXLinuxState linuxState; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /vmmon-only/linux/driverLog.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2007-2014 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | 20 | /* 21 | * driverLog.h -- 22 | * 23 | * Logging functions for Linux kernel modules. 24 | */ 25 | 26 | #ifndef __DRIVERLOG_H__ 27 | #define __DRIVERLOG_H__ 28 | 29 | /* 30 | * The definitions of Warning(), Log(), and Panic() come from vm_assert.h for 31 | * consistency. 32 | */ 33 | #include "vm_assert.h" 34 | 35 | void DriverLog_Init(const char *prefix); 36 | 37 | #endif /* __DRIVERLOG_H__ */ 38 | -------------------------------------------------------------------------------- /vmmon-only/linux/hostif_priv.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2009-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | /* 21 | * hostif_priv.h -- 22 | * 23 | * Defines several Linux-only additions to the HostIF API. 24 | */ 25 | 26 | #ifndef _HOSTIF_PRIV_H_ 27 | #define _HOSTIF_PRIV_H_ 28 | 29 | /* Uptime-related functions. */ 30 | EXTERN void HostIF_InitUptime(void); 31 | EXTERN void HostIF_CleanupUptime(void); 32 | 33 | /* Miscellaneous functions. */ 34 | EXTERN void HostIF_InitGlobalLock(void); 35 | EXTERN Bool HostIF_GetAllCpuInfo(CPUIDQuery *query); 36 | 37 | #endif // ifdef _HOSTIF_PRIV_H_ 38 | -------------------------------------------------------------------------------- /vmmon-only/linux/vmhost.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 2002-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | #ifndef __VMHOST_H__ 21 | #define __VMHOST_H__ 22 | 23 | #define INCLUDE_ALLOW_VMMON 24 | #define INCLUDE_ALLOW_VMCORE 25 | #include "includeCheck.h" 26 | 27 | #include 28 | 29 | 30 | #ifdef VMX86_DEBUG 31 | /* 32 | * A MutexHolder object. In debug builds, we record information about the 33 | * holder of a Mutex. --hpreg 34 | */ 35 | typedef struct MutexHolder { 36 | /* Linux task ID. --hpreg */ 37 | int pid; 38 | 39 | /* Location in the code. --hpreg */ 40 | int callerID; 41 | } MutexHolder; 42 | #endif 43 | 44 | 45 | /* 46 | * A Mutex object. In debug builds, 47 | * o we track contention, 48 | * o we check when the Mutex should be held, 49 | * o we check the pairing and nesting of lock/unlock operations. 50 | * --hpreg 51 | */ 52 | typedef struct Mutex { 53 | /* A binary semaphore. --hpreg */ 54 | struct semaphore sem; 55 | #ifdef VMX86_DEBUG 56 | 57 | /* 58 | * _static_ string describing the Mutex. Set once for all when the Mutex is 59 | * initialized. --hpreg 60 | */ 61 | char const *name; 62 | 63 | /* Information about the previous holder. Protected by 'sem'. --hpreg */ 64 | MutexHolder prev; 65 | 66 | /* Information about the current holder. Protected by 'sem'. --hpreg */ 67 | MutexHolder cur; 68 | #endif 69 | } Mutex; 70 | 71 | 72 | /* 73 | * Per-vm host-specific state. 74 | */ 75 | 76 | typedef struct VMHost { 77 | /* 78 | * Used for shared modifications to VM's VMDriver data, mostly page locking. 79 | * It has higher rank than the global mutex. 80 | */ 81 | Mutex vmMutex; 82 | 83 | struct task_struct **vcpuSemaTask; /* ptr to numVCPUs-sized array */ 84 | 85 | /* 86 | * Pages that were allocated/mapped by VMX and locked by the driver and 87 | * don't have a particular VA. 88 | */ 89 | struct PhysTracker *lockedPages; 90 | /* 91 | * Locked pages that were allocated by the driver and don't have 92 | * a particular VA. They are used as monitor anonymous pages or 93 | * as pages for "AWE" guest memory. 94 | */ 95 | struct PhysTracker *AWEPages; 96 | /* 97 | * Pointer to a userlevel 64-bit area containing the value 1. 98 | * This is used for HostIF_SemaphoreSignal. 99 | */ 100 | void *__user vmmonData; 101 | } VMHost; 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /vmnet-only/Makefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | ########################################################## 3 | # Copyright (C) 1998-2020 VMware, Inc. All rights reserved. 4 | # 5 | # This program is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU General Public License as published by the 7 | # Free Software Foundation version 2 and no later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, but 10 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | # for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | ########################################################## 19 | 20 | #### 21 | #### VMware kernel module Makefile to be distributed externally 22 | #### 23 | 24 | #### 25 | #### SRCROOT _must_ be a relative path. 26 | #### 27 | SRCROOT = . 28 | 29 | # 30 | # open-vm-tools doesn't replicate shared source files for different modules; 31 | # instead, files are kept in shared locations. So define a few useful macros 32 | # to be able to handle both cases cleanly. 33 | # 34 | INCLUDE := 35 | ifdef OVT_SOURCE_DIR 36 | AUTOCONF_DIR := $(OVT_SOURCE_DIR)/modules/linux/shared/autoconf 37 | VMLIB_PATH = $(OVT_SOURCE_DIR)/lib/$(1) 38 | INCLUDE += -I$(OVT_SOURCE_DIR)/modules/linux/shared 39 | INCLUDE += -I$(OVT_SOURCE_DIR)/lib/include 40 | else 41 | AUTOCONF_DIR := $(SRCROOT)/shared/autoconf 42 | INCLUDE += -I$(SRCROOT)/shared 43 | endif 44 | 45 | 46 | VM_UNAME = $(shell uname -r) 47 | 48 | # Header directory for the running kernel 49 | ifdef LINUXINCLUDE 50 | HEADER_DIR = $(LINUXINCLUDE) 51 | else 52 | HEADER_DIR = /lib/modules/$(VM_UNAME)/build/include 53 | endif 54 | 55 | BUILD_DIR = $(HEADER_DIR)/.. 56 | 57 | DRIVER := vmnet 58 | PRODUCT := @@PRODUCT@@ 59 | 60 | # Grep program 61 | GREP = /bin/grep 62 | 63 | vm_check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ 64 | > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi) 65 | vm_check_file = $(shell if test -f $(1); then echo "yes"; else echo "no"; fi) 66 | 67 | ifndef VM_KBUILD 68 | VM_KBUILD := no 69 | ifeq ($(call vm_check_file,$(BUILD_DIR)/Makefile), yes) 70 | VM_KBUILD := yes 71 | endif 72 | export VM_KBUILD 73 | endif 74 | 75 | ifndef VM_KBUILD_SHOWN 76 | ifeq ($(VM_KBUILD), no) 77 | VM_DUMMY := $(shell echo >&2 "Using standalone build system.") 78 | else 79 | VM_DUMMY := $(shell echo >&2 "Using kernel build system.") 80 | endif 81 | VM_KBUILD_SHOWN := yes 82 | export VM_KBUILD_SHOWN 83 | endif 84 | 85 | ifneq ($(VM_KBUILD), no) 86 | 87 | # If there is no version defined, we are in toplevel pass, not yet in kernel makefiles... 88 | ifeq ($(VERSION),) 89 | 90 | DRIVER_KO := $(DRIVER).ko 91 | 92 | .PHONY: $(DRIVER_KO) 93 | 94 | auto-build: $(DRIVER_KO) 95 | cp -f $< $(SRCROOT)/../$(DRIVER).o 96 | 97 | # $(DRIVER_KO) is a phony target, so compare file times explicitly 98 | $(DRIVER): $(DRIVER_KO) 99 | if [ $< -nt $@ ] || [ ! -e $@ ] ; then cp -f $< $@; fi 100 | 101 | # Use SUBDIRS on 2.x, 3.x, 4.x. Use M on newer kernels. 102 | ifeq ($(filter-out 2 3 4,$(firstword $(subst ., ,$(VM_UNAME)))),) 103 | DIRVAR := SUBDIRS 104 | else 105 | DIRVAR := M 106 | endif 107 | 108 | # 109 | # Define a setup target that gets built before the actual driver. 110 | # This target may not be used at all, but if it is then it will be defined 111 | # in Makefile.kernel 112 | # 113 | prebuild:: ; 114 | postbuild:: ; 115 | 116 | $(DRIVER_KO): prebuild 117 | $(MAKE) -C $(BUILD_DIR) $(DIRVAR)=$$PWD SRCROOT=$$PWD/$(SRCROOT) \ 118 | MODULEBUILDDIR=$(MODULEBUILDDIR) modules 119 | $(MAKE) -C $$PWD SRCROOT=$$PWD/$(SRCROOT) \ 120 | MODULEBUILDDIR=$(MODULEBUILDDIR) postbuild 121 | endif 122 | 123 | vm_check_build = $(shell if $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ 124 | $(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) $(LINUXINCLUDE) \ 125 | $(EXTRA_CFLAGS) -Iinclude2/asm/mach-default \ 126 | -DKBUILD_BASENAME=\"$(DRIVER)\" \ 127 | -Werror -S -o /dev/null -xc $(1) \ 128 | > /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi) 129 | 130 | CC_WARNINGS := -Wall -Wstrict-prototypes 131 | CC_OPTS := $(GLOBAL_DEFS) $(CC_WARNINGS) -DVMW_USING_KBUILD 132 | ifdef VMX86_DEVEL 133 | CC_OPTS += -DVMX86_DEVEL 134 | endif 135 | ifdef VMX86_DEBUG 136 | CC_OPTS += -DVMX86_DEBUG 137 | endif 138 | 139 | # Add Spectre options when available 140 | 141 | include $(SRCROOT)/Makefile.kernel 142 | 143 | else 144 | 145 | include $(SRCROOT)/Makefile.normal 146 | 147 | endif 148 | 149 | #.SILENT: 150 | -------------------------------------------------------------------------------- /vmnet-only/Makefile.kernel: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | ########################################################## 3 | # Copyright (C) 1998 VMware, Inc. All rights reserved. 4 | # 5 | # This program is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU General Public License as published by the 7 | # Free Software Foundation version 2 and no later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, but 10 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | # for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | ########################################################## 19 | 20 | INCLUDE := -I$(SRCROOT) 21 | 22 | EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE) 23 | EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/netif_trans_update.c,-DVMW_NETIF_TRANS_UPDATE, ) 24 | 25 | obj-m += $(DRIVER).o 26 | 27 | $(DRIVER)-y := driver.o hub.o userif.o netif.o bridge.o procfs.o smac_compat.o \ 28 | smac.o vnetEvent.o vnetUserListener.o 29 | 30 | #### 31 | #### Make Targets are beneath here. 32 | #### 33 | 34 | clean: 35 | rm -rf $(DRIVER).o $(DRIVER).mod.o $(DRIVER).mod.c $(DRIVER).ko .cache.mk \ 36 | .tmp_versions Module.symvers Modules.symvers Module.markers \ 37 | modules.order $($(DRIVER)-y) .*.cmd .*.o.flags 38 | -------------------------------------------------------------------------------- /vmnet-only/Makefile.normal: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | ########################################################## 3 | # Copyright (C) 1998 VMware, Inc. All rights reserved. 4 | # 5 | # This program is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU General Public License as published by the 7 | # Free Software Foundation version 2 and no later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, but 10 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | # for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | ########################################################## 19 | 20 | vm_check_build = $(shell if $(CC) $(CC_OPTS) $(INCLUDE) -Werror -S -o /dev/null -xc $(1) \ 21 | > /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi) 22 | 23 | DRIVERNAME := $(DRIVER)-xxx-$(VM_UNAME) 24 | 25 | ifneq (,$(filter x86_64%, $(shell $(CC) -dumpmachine))) 26 | MACHINE := x86_64 27 | else 28 | MACHINE := x386 29 | endif 30 | 31 | CC_WARNINGS := -Wall -Wstrict-prototypes 32 | # Don't use -pipe or egcs-2.91.66 (shipped with RedHat) will die 33 | CC_OPTS := -D__KERNEL__ -DMODULE -fomit-frame-pointer -fno-strength-reduce \ 34 | -fno-common -DKBUILD_MODNAME=$(DRIVER) 35 | # Gcc 3.0 deprecates -m486 --hpreg 36 | CC_OPTS += $(call vm_check_gcc,-falign-loops=2 -falign-jumps=2 -falign-functions=2, \ 37 | -malign-loops=2 -malign-jumps=2 -malign-functions=2) 38 | CC_OPTS += $(call vm_check_gcc,-fno-strict-aliasing,) 39 | ifeq ($(MACHINE),x86_64) 40 | CC_OPTS += -mno-red-zone -mcmodel=kernel 41 | else 42 | CC_OPTS += -DCPU=586 $(call check_gcc,-march=i586,-m486) 43 | endif 44 | 45 | INCLUDE := -I. -I$(HEADER_DIR) 46 | INCLUDE += $(shell $(CC) $(INCLUDE) -E geninclude.c \ 47 | | sed -n -e 's!^APATH!-I$(HEADER_DIR)/asm!p') 48 | 49 | CFLAGS := -O $(CC_WARNINGS) $(CC_OPTS) $(INCLUDE) $(GLOBAL_DEFS) 50 | 51 | OBJS := driver.o hub.o userif.o netif.o bridge.o procfs.o smac_compat.o \ 52 | smac.o vnetEvent.o vnetUserListener.o 53 | 54 | LIBS := 55 | 56 | default: all 57 | 58 | all: $(DRIVER).o 59 | 60 | $(DRIVERNAME): $(OBJS) 61 | $(LD) -r -o $@ $^ 62 | 63 | $(DRIVER) $(DRIVER).o ../$(DRIVER).o: $(DRIVERNAME) 64 | cp -f $< $@ 65 | 66 | auto-build: ../$(DRIVER).o 67 | 68 | clean: 69 | rm -f $(DRIVERNAME) $(DRIVER) $(DRIVER).o ../$(DRIVER).o $(OBJS) 70 | 71 | .PHONY: default all auto-build clean 72 | 73 | .SILENT: 74 | -------------------------------------------------------------------------------- /vmnet-only/community_source.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2009-2016 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * community_source.h -- 21 | * 22 | * Macros for excluding source code from community. 23 | */ 24 | 25 | #ifndef _COMMUNITY_SOURCE_H_ 26 | #define _COMMUNITY_SOURCE_H_ 27 | 28 | #define INCLUDE_ALLOW_USERLEVEL 29 | 30 | #define INCLUDE_ALLOW_MODULE 31 | #define INCLUDE_ALLOW_VMMON 32 | #define INCLUDE_ALLOW_VMKERNEL 33 | #define INCLUDE_ALLOW_VMKDRIVERS 34 | #define INCLUDE_ALLOW_VMK_MODULE 35 | #define INCLUDE_ALLOW_DISTRIBUTE 36 | #define INCLUDE_ALLOW_VMCORE 37 | #include "includeCheck.h" 38 | 39 | /* 40 | * Convenience macro for COMMUNITY_SOURCE 41 | */ 42 | #undef EXCLUDE_COMMUNITY_SOURCE 43 | #ifdef COMMUNITY_SOURCE 44 | #define EXCLUDE_COMMUNITY_SOURCE(x) 45 | #else 46 | #define EXCLUDE_COMMUNITY_SOURCE(x) x 47 | #endif 48 | 49 | #undef COMMUNITY_SOURCE_AMD_SECRET 50 | #if !defined(COMMUNITY_SOURCE) || defined(AMD_SOURCE) 51 | /* 52 | * It's ok to include AMD_SECRET source code for non-Community Source, 53 | * or for drops directed at AMD. 54 | */ 55 | #define COMMUNITY_SOURCE_AMD_SECRET 56 | #endif 57 | 58 | #undef COMMUNITY_SOURCE_INTEL_SECRET 59 | #if !defined(COMMUNITY_SOURCE) || defined(INTEL_SOURCE) 60 | /* 61 | * It's ok to include INTEL_SECRET source code for non-Community Source, 62 | * or for drops directed at Intel. 63 | */ 64 | #define COMMUNITY_SOURCE_INTEL_SECRET 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /vmnet-only/compat_autoconf.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2009 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef __COMPAT_AUTOCONF_H__ 20 | # define __COMPAT_AUTOCONF_H__ 21 | 22 | #define INCLUDE_ALLOW_VMMON 23 | #define INCLUDE_ALLOW_MODULE 24 | #define INCLUDE_ALLOW_VMCORE 25 | #define INCLUDE_ALLOW_DISTRIBUTE 26 | #define INCLUDE_ALLOW_VMKDRIVERS 27 | #include "includeCheck.h" 28 | 29 | 30 | #ifndef LINUX_VERSION_CODE 31 | # error "Include compat_version.h before compat_autoconf.h" 32 | #endif 33 | 34 | /* autoconf.h moved from linux/autoconf.h to generated/autoconf.h in 2.6.33-rc1. */ 35 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) 36 | # include 37 | #else 38 | # include 39 | #endif 40 | 41 | #if defined(CONFIG_SUSE_VERSION) && defined(CONFIG_SUSE_PATCHLEVEL) 42 | # if CONFIG_SUSE_VERSION == 15 && CONFIG_SUSE_PATCHLEVEL >= 5 43 | # define SLE15_SP5_BACKPORTS 1 44 | # endif 45 | #endif 46 | 47 | #endif /* __COMPAT_AUTOCONF_H__ */ 48 | -------------------------------------------------------------------------------- /vmnet-only/compat_module.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2007 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * compat_module.h -- 21 | */ 22 | 23 | #ifndef __COMPAT_MODULE_H__ 24 | # define __COMPAT_MODULE_H__ 25 | 26 | 27 | #include 28 | 29 | 30 | /* 31 | * Modules wishing to use the GPL license are required to include a 32 | * MODULE_LICENSE definition in their module source as of 2.4.10. 33 | */ 34 | #ifndef MODULE_LICENSE 35 | #define MODULE_LICENSE(license) 36 | #endif 37 | 38 | /* 39 | * To make use of our own home-brewed MODULE_INFO, we need macros to 40 | * concatenate two expressions to "__mod_", and and to convert an 41 | * expression into a string. I'm sure we've got these in our codebase, 42 | * but I'd rather not introduce such a dependency in a compat header. 43 | */ 44 | #ifndef __module_cat 45 | #define __module_cat_1(a, b) __mod_ ## a ## b 46 | #define __module_cat(a, b) __module_cat_1(a, b) 47 | #endif 48 | 49 | #ifndef __stringify 50 | #define __stringify_1(x) #x 51 | #define __stringify(x) __stringify_1(x) 52 | #endif 53 | 54 | /* 55 | * MODULE_INFO was born in 2.5.69. 56 | */ 57 | #ifndef MODULE_INFO 58 | #define MODULE_INFO(tag, info) \ 59 | static const char __module_cat(tag, __LINE__)[] \ 60 | __attribute__((section(".modinfo"), unused)) = __stringify(tag) "=" info 61 | #endif 62 | 63 | /* 64 | * MODULE_VERSION was born in 2.6.4. The earlier form appends a long "\0xxx" 65 | * string to the module's version, but that was removed in 2.6.10, so we'll 66 | * ignore it in our wrapper. 67 | */ 68 | #ifndef MODULE_VERSION 69 | #define MODULE_VERSION(_version) MODULE_INFO(version, _version) 70 | #endif 71 | 72 | /* 73 | * Linux kernel < 2.6.31 takes 'int' for 'bool' module parameters. 74 | * Linux kernel >= 3.3.0 takes 'bool' for 'bool' module parameters. 75 | * Kernels between the two take either. So flip switch at 3.0.0. 76 | */ 77 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) 78 | typedef bool compat_mod_param_bool; 79 | #else 80 | typedef int compat_mod_param_bool; 81 | #endif 82 | 83 | #endif /* __COMPAT_MODULE_H__ */ 84 | -------------------------------------------------------------------------------- /vmnet-only/compat_sock.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2003 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef __COMPAT_SOCK_H__ 20 | # define __COMPAT_SOCK_H__ 21 | 22 | #include /* for NULL */ 23 | #include 24 | 25 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) 26 | static inline wait_queue_head_t *sk_sleep(struct sock *sk) 27 | { 28 | return sk->sk_sleep; 29 | } 30 | #endif 31 | 32 | 33 | /* 34 | * Prior to 2.6.24, there was no sock network namespace member. In 2.6.26, it 35 | * was hidden behind accessor functions so that its behavior could vary 36 | * depending on the value of CONFIG_NET_NS. 37 | */ 38 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) 39 | # define compat_sock_net(sk) sock_net(sk) 40 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) 41 | # define compat_sock_net(sk) sk->sk_net 42 | #endif 43 | 44 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16) 45 | 46 | #ifndef CONFIG_FILTER 47 | # define sk_filter(sk, skb, needlock) 0 48 | #endif 49 | 50 | /* Taken from 2.6.16's sock.h and modified for macro. */ 51 | # define compat_sk_receive_skb(sk, skb, nested) \ 52 | ({ \ 53 | int rc = NET_RX_SUCCESS; \ 54 | \ 55 | if (sk_filter(sk, skb, 0)) { \ 56 | kfree_skb(skb); \ 57 | } else { \ 58 | skb->dev = NULL; \ 59 | bh_lock_sock(sk); \ 60 | if (!sock_owned_by_user(sk)) { \ 61 | rc = (sk)->sk_backlog_rcv(sk, skb); \ 62 | } else { \ 63 | sk_add_backlog(sk, skb); \ 64 | } \ 65 | bh_unlock_sock(sk); \ 66 | } \ 67 | \ 68 | sock_put(sk); \ 69 | rc; \ 70 | }) 71 | #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) 72 | # define compat_sk_receive_skb(sk, skb, nested) sk_receive_skb(sk, skb) 73 | #else 74 | # define compat_sk_receive_skb(sk, skb, nested) sk_receive_skb(sk, skb, nested) 75 | #endif 76 | 77 | #endif /* __COMPAT_SOCK_H__ */ 78 | -------------------------------------------------------------------------------- /vmnet-only/compat_version.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (c) 1998-2024 Broadcom. All Rights Reserved. 3 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 and no later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | *********************************************************/ 19 | 20 | #ifndef __COMPAT_VERSION_H__ 21 | # define __COMPAT_VERSION_H__ 22 | 23 | #define INCLUDE_ALLOW_VMMON 24 | #define INCLUDE_ALLOW_MODULE 25 | #define INCLUDE_ALLOW_VMCORE 26 | #define INCLUDE_ALLOW_DISTRIBUTE 27 | #define INCLUDE_ALLOW_VMKDRIVERS 28 | #include "includeCheck.h" 29 | 30 | 31 | #ifndef __linux__ 32 | # error "linux-version.h" 33 | #endif 34 | 35 | 36 | #include 37 | 38 | #ifndef KERNEL_VERSION 39 | # error KERNEL_VERSION macro is not defined, environment is busted 40 | #endif 41 | 42 | 43 | /* 44 | * Distinguish relevant classes of Linux kernels. 45 | * 46 | * The convention is that version X defines all 47 | * the KERNEL_Y symbols where Y <= X. 48 | * 49 | * XXX Do not add more definitions here. This way of doing things does not 50 | * scale, and we are going to phase it out soon --hpreg 51 | */ 52 | 53 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 1, 0) 54 | # define KERNEL_2_1 55 | #endif 56 | 57 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 2, 0) 58 | # define KERNEL_2_2 59 | #endif 60 | 61 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 1) 62 | # define KERNEL_2_3_1 63 | #endif 64 | 65 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 15) 66 | /* new networking */ 67 | # define KERNEL_2_3_15 68 | #endif 69 | 70 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 25) 71 | /* new procfs */ 72 | # define KERNEL_2_3_25 73 | #endif 74 | 75 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 29) 76 | /* even newer procfs */ 77 | # define KERNEL_2_3_29 78 | #endif 79 | 80 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 43) 81 | /* softnet changes */ 82 | # define KERNEL_2_3_43 83 | #endif 84 | 85 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 47) 86 | /* more softnet changes */ 87 | # define KERNEL_2_3_47 88 | #endif 89 | 90 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 99) 91 | /* name in netdevice struct is array and not pointer */ 92 | # define KERNEL_2_3_99 93 | #endif 94 | 95 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) 96 | /* New 'owner' member at the beginning of struct file_operations */ 97 | # define KERNEL_2_4_0 98 | #endif 99 | 100 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 8) 101 | /* New netif_rx_ni() --hpreg */ 102 | # define KERNEL_2_4_8 103 | #endif 104 | 105 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 2) 106 | /* New kdev_t, major()/minor() API --hpreg */ 107 | # define KERNEL_2_5_2 108 | #endif 109 | 110 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 5) 111 | /* New sk_alloc(), pte_offset_map()/pte_unmap() --hpreg */ 112 | # define KERNEL_2_5_5 113 | #endif 114 | 115 | /* Linux kernel 3.0 can be called 2.6.40, and 3.1 can be 2.6.41... 116 | * Use COMPAT_LINUX_VERSION_CHECK_LT iff you need to compare running kernel to 117 | * versions 3.0 and above. 118 | * 119 | */ 120 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) 121 | /* Straight forward comparison if kernel version is 3.0.0 and beyond */ 122 | # define COMPAT_LINUX_VERSION_CHECK_LT(a, b, c) (LINUX_VERSION_CODE < KERNEL_VERSION (a, b, c)) 123 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 40) 124 | /* Use b of the check to calculate corresponding c of kernel 125 | * version to compare */ 126 | # define COMPAT_LINUX_VERSION_CHECK_LT(a, b, c) (LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, (b + 40))) 127 | #else 128 | /* This is anyways lesser than any 3.x versions */ 129 | # define COMPAT_LINUX_VERSION_CHECK_LT(a, b, c) 1 130 | #endif 131 | 132 | #if defined(RHEL_RELEASE_CODE) && defined(RHEL_RELEASE_VERSION) 133 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(8, 4) 134 | # define RHEL84_BACKPORTS 1 135 | # endif 136 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(8, 5) 137 | # define RHEL85_BACKPORTS 1 138 | # endif 139 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 1) 140 | # define RHEL91_BACKPORTS 1 141 | # endif 142 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 2) 143 | # define RHEL92_BACKPORTS 1 144 | # endif 145 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 4) 146 | # define RHEL94_BACKPORTS 1 147 | # endif 148 | #endif 149 | 150 | #endif /* __COMPAT_VERSION_H__ */ 151 | -------------------------------------------------------------------------------- /vmnet-only/driver-config.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 1998 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * Sets the proper defines from the Linux header files 21 | * 22 | * This file must be included before the inclusion of any kernel header file, 23 | * with the exception of linux/autoconf.h and linux/version.h --hpreg 24 | */ 25 | 26 | #ifndef __VMX_CONFIG_H__ 27 | #define __VMX_CONFIG_H__ 28 | 29 | #define INCLUDE_ALLOW_VMCORE 30 | #define INCLUDE_ALLOW_VMMON 31 | #define INCLUDE_ALLOW_MODULE 32 | #define INCLUDE_ALLOW_DISTRIBUTE 33 | #define INCLUDE_ALLOW_VMKDRIVERS 34 | #include "includeCheck.h" 35 | 36 | #include "compat_version.h" 37 | #include "compat_autoconf.h" 38 | 39 | /* 40 | * We rely on Kernel Module support. Check here. 41 | */ 42 | #ifndef CONFIG_MODULES 43 | # error "No Module support in this kernel. Please configure with CONFIG_MODULES" 44 | #endif 45 | 46 | /* 47 | * 2.2 kernels still use __SMP__ (derived from CONFIG_SMP 48 | * in the main Makefile), so we do it here. 49 | */ 50 | 51 | #ifdef CONFIG_SMP 52 | # define __SMP__ 1 53 | #endif 54 | 55 | #if defined(CONFIG_MODVERSIONS) && defined(KERNEL_2_1) 56 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60) 57 | /* 58 | * MODVERSIONS might be already defined when using kernel's Makefiles. 59 | */ 60 | # ifndef MODVERSIONS 61 | # define MODVERSIONS 62 | # endif 63 | # include 64 | # endif 65 | #endif 66 | 67 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) 68 | /* 69 | * Force the uintptr_t definition to come from linux/types.h instead of vm_basic_types.h. 70 | */ 71 | # include 72 | # define _STDINT_H 1 73 | #endif 74 | 75 | #ifndef __KERNEL__ 76 | # define __KERNEL__ 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /vmnet-only/geninclude.c: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2003 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #include "compat_version.h" 20 | #include "compat_autoconf.h" 21 | 22 | #ifdef CONFIG_X86_VOYAGER 23 | APATH/mach-voyager 24 | #endif 25 | #ifdef CONFIG_X86_VISWS 26 | APATH/mach-visws 27 | #endif 28 | #ifdef CONFIG_X86_NUMAQ 29 | APATH/mach-numaq 30 | #endif 31 | #ifdef CONFIG_X86_BIGSMP 32 | APATH/mach-bigsmp 33 | #endif 34 | #ifdef CONFIG_X86_SUMMIT 35 | APATH/mach-summit 36 | #endif 37 | #ifdef CONFIG_X86_GENERICARCH 38 | APATH/mach-generic 39 | #endif 40 | APATH/mach-default 41 | 42 | -------------------------------------------------------------------------------- /vmnet-only/includeCheck.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2008 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | -------------------------------------------------------------------------------- /vmnet-only/netif_trans_update.c: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2017 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | 20 | /* 21 | * Detect whether there is netif_trans_update, which got introduced from 4.7.0 22 | * Older kernels may have this function backported by vendors. 23 | */ 24 | 25 | #include "compat_version.h" 26 | #include "compat_autoconf.h" 27 | 28 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) 29 | # error This compile test intentionally fails. 30 | #elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0) 31 | #include 32 | 33 | void test_netif_trans_update(struct net_device *dev) 34 | { 35 | netif_trans_update(dev); 36 | } 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /vmnet-only/smac.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2002-2010,2022 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * smac.h -- 21 | * 22 | * This file declares functionality that allows the 23 | * bridge to be used across links that do 24 | * not support promiscuous mode, nor provide the 25 | * ability to transmit ethernet frames whose MAC source 26 | * address does not match the hardware's MAC address. 27 | */ 28 | 29 | #ifndef _SMAC_H_ 30 | #define _SMAC_H_ 31 | 32 | #ifdef _WIN32 33 | #include "vnetInt.h" 34 | #else /* _WIN32 */ 35 | 36 | #include "vm_basic_types.h" 37 | 38 | /* linux header files include too much garbage, so just define if needed */ 39 | #ifndef ETH_ALEN 40 | #define ETH_ALEN 6 41 | #endif /* ETH_ALEN */ 42 | 43 | #ifndef ETH_HLEN 44 | #define ETH_HLEN 14 45 | #endif /* ETH_HLEN */ 46 | 47 | #endif /* _WIN32 */ 48 | 49 | #if defined __linux__ && !defined __x86_64__ 50 | #define SMACINT __attribute__((cdecl, regparm(3))) 51 | #else 52 | #define SMACINT 53 | #endif 54 | 55 | typedef enum { 56 | PacketStatusTooShort = 0x4546, // insuficient data to process packet 57 | PacketStatusDropPacket, // bridge should drop packet 58 | PacketStatusForwardPacket // bridge should accept/process/forward packet 59 | } PacketStatus; 60 | 61 | typedef struct IPv6Addr { 62 | uint64 addrHi; /* High order 64 bits of the address. */ 63 | uint64 addrLo; /* Low order 64 bits of the address. */ 64 | } IPv6Addr; 65 | 66 | struct SMACState; 67 | 68 | #if defined(_WIN32) && NDIS_SUPPORT_NDIS6 69 | Bool BridgeIPv6MatchAddrMAC(const IPv6Addr *addr, const uint8 *mac); 70 | Bool BridgeIPv4MatchAddrMAC(const ULONG ipAddr, const uint8 *mac); 71 | #endif 72 | void SMACINT 73 | SMAC_InitState(struct SMACState **ptr); // IN: state to alloc/init 74 | void SMACINT 75 | SMAC_SetMac(struct SMACState *state, const uint8 *mac); // IN: state, and host MAC 76 | void SMACINT 77 | SMAC_CleanupState(struct SMACState **ptr); // IN: state to cleanup/dealloc 78 | 79 | /* 80 | * Structure is used to separate out differences 81 | * between packets on different OSes. 82 | */ 83 | 84 | #ifdef _WIN32 85 | /* defines Windows versions of SMACPacket and SMACPackets */ 86 | #include "smac_win.h" 87 | #else /* _WIN32 */ 88 | /* non-WIN32 versions of these structs */ 89 | typedef struct SMACPacket { 90 | #ifdef __linux__ 91 | struct sk_buff *skb; // packet 92 | void *startOfData; // handles non-uniform start of data in sk_buff 93 | unsigned int len; // compensates for ethernet header for inbound packets 94 | #else 95 | mbuf_t m; // packet 96 | #endif 97 | } SMACPacket; 98 | 99 | typedef struct SMACPackets { 100 | SMACPacket orig; // IN: packet 101 | SMACPacket clone; // OUT: packet 102 | } SMACPackets; 103 | #endif /* _WIN32 */ 104 | 105 | PacketStatus SMACINT 106 | SMAC_CheckPacketFromHost(struct SMACState *state, // IN: pointer to smac state 107 | SMACPackets *packets); // IN/OUT: packet(s) to process 108 | 109 | PacketStatus SMACINT 110 | SMAC_CheckPacketToHost(struct SMACState *state, // IN: pointer to smac state 111 | SMACPackets *packets); // IN/OUT: packet(s) to process 112 | 113 | void SMACINT 114 | SMAC_SetForwardUnknownPackets(struct SMACState *state, // IN: pointer to smac state 115 | Bool forwardUnknown); // IN: T/F to forward 116 | 117 | #endif // _SMAC_H_ 118 | 119 | 120 | -------------------------------------------------------------------------------- /vmnet-only/smac_compat.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2005 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * smac_compat.h -- 21 | * 22 | * This file defines an abstraction layer to handling 23 | * differences among the Linux kernel and avoiding 24 | * symbol match issues. 25 | */ 26 | 27 | #ifndef _SMAC_COMPAT_H_ 28 | #define _SMAC_COMPAT_H_ 29 | 30 | #include "vm_basic_types.h" 31 | 32 | #if defined(__x86_64__) 33 | #define SMACINT 34 | #else 35 | #define SMACINT __attribute__((cdecl, regparm(3))) 36 | #endif 37 | 38 | void SMACINT SMACL_Memcpy(void *d, const void *s, size_t l); 39 | int SMACINT SMACL_Memcmp(const void *p1, const void *p2, size_t l); 40 | void SMACINT SMACL_Memset(void *p1, int val, size_t l); 41 | void* SMACINT SMACL_Alloc(size_t s); 42 | void SMACINT SMACL_Free(void *p); 43 | 44 | unsigned long SMACINT SMACL_GetUptime(void); 45 | 46 | void SMACINT SMACL_InitSpinlock(void **s); 47 | void SMACINT SMACL_AcquireSpinlock(void **s, unsigned long *flags); 48 | void SMACINT SMACL_ReleaseSpinlock(void **s, unsigned long *flags); 49 | 50 | 51 | struct sk_buff* SMACINT SMACL_DupPacket(struct sk_buff *skb); 52 | void* SMACINT SMACL_PacketData(struct sk_buff *skb); 53 | int SMACINT SMACL_IsSkbHostBound(struct sk_buff *skb); 54 | #ifdef DBG 55 | void SMACINT SMACL_Print(const char *m, ...); 56 | void SMACINT SMACL_PrintSkb(struct sk_buff *skb, char *type); 57 | #endif /* DBG */ 58 | 59 | #endif /* _SMAC_COMPAT_H */ 60 | 61 | -------------------------------------------------------------------------------- /vmnet-only/vmnetInt.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 1998, 2017 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | #ifndef __VMNETINT_H__ 20 | #define __VMNETINT_H__ 21 | 22 | 23 | #define INCLUDE_ALLOW_MODULE 24 | #include "includeCheck.h" 25 | #include "driver-config.h" 26 | // header for RCU 27 | #include 28 | 29 | #ifdef skb_shinfo 30 | # define SKB_IS_CLONE_OF(clone, skb) ( \ 31 | skb_shinfo(clone) == skb_shinfo(skb) \ 32 | ) 33 | #else 34 | # define SKB_IS_CLONE_OF(clone, skb) ( \ 35 | skb_datarefp(clone) == skb_datarefp(skb) \ 36 | ) 37 | #endif 38 | #define DEV_QUEUE_XMIT(skb, dev, pri) ( \ 39 | (skb)->dev = (dev), \ 40 | (skb)->priority = (pri), \ 41 | compat_skb_reset_mac_header(skb), \ 42 | compat_skb_set_network_header(skb, sizeof (struct ethhdr)), \ 43 | dev_queue_xmit(skb) \ 44 | ) 45 | // old code 46 | // #define dev_lock_list() read_lock(&dev_base_lock) 47 | // #define dev_unlock_list() read_unlock(&dev_base_lock) 48 | #define dev_lock_list() rcu_read_lock() 49 | #define dev_unlock_list() rcu_read_unlock() 50 | 51 | 52 | extern struct proto vmnet_proto; 53 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) || defined(sk_net_refcnt) 54 | # define compat_sk_alloc(_bri, _pri) sk_alloc(&init_net, \ 55 | PF_NETLINK, _pri, &vmnet_proto, 1) 56 | #else 57 | # define compat_sk_alloc(_bri, _pri) sk_alloc(&init_net, \ 58 | PF_NETLINK, _pri, &vmnet_proto) 59 | #endif 60 | 61 | 62 | #ifdef NF_IP_LOCAL_IN 63 | #define VMW_NF_INET_LOCAL_IN NF_IP_LOCAL_IN 64 | #define VMW_NF_INET_POST_ROUTING NF_IP_POST_ROUTING 65 | #else 66 | #define VMW_NF_INET_LOCAL_IN NF_INET_LOCAL_IN 67 | #define VMW_NF_INET_POST_ROUTING NF_INET_POST_ROUTING 68 | #endif 69 | 70 | 71 | #endif /* __VMNETINT_H__ */ 72 | -------------------------------------------------------------------------------- /vmnet-only/vnetEvent.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2007 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * vnetEvent.h -- 21 | */ 22 | 23 | #ifndef _VNETEVENT_H_ 24 | #define _VNETEVENT_H_ 25 | 26 | #include "vm_basic_types.h" 27 | #include "vnet.h" 28 | 29 | typedef struct VNetEvent_Mechanism VNetEvent_Mechanism; 30 | 31 | typedef struct VNetEvent_Sender VNetEvent_Sender; 32 | 33 | typedef struct VNetEvent_Listener VNetEvent_Listener; 34 | 35 | typedef void (*VNetEvent_Handler)(void *data, VNet_EventHeader *e); 36 | 37 | int VNetEvent_CreateMechanism(VNetEvent_Mechanism **m); 38 | int VNetEvent_DestroyMechanism(VNetEvent_Mechanism *m); 39 | 40 | int VNetEvent_CreateSender(VNetEvent_Mechanism *m, VNetEvent_Sender **s); 41 | int VNetEvent_DestroySender(VNetEvent_Sender *s); 42 | int VNetEvent_Send(VNetEvent_Sender *s, VNet_EventHeader *e); 43 | int VNetEvent_GetSenderId(const VNetEvent_Sender *s, uint32 *senderId); 44 | 45 | int VNetEvent_CreateListener(VNetEvent_Mechanism *m, VNetEvent_Handler h, 46 | void *data, uint32 classMask, 47 | VNetEvent_Listener **l); 48 | int VNetEvent_DestroyListener(VNetEvent_Listener *l); 49 | 50 | #endif // _VNETEVENT_H_ 51 | -------------------------------------------------------------------------------- /vmnet-only/vnetKernel.h: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | * Copyright (C) 2008 VMware, Inc. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 and no later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 | * for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | *********************************************************/ 18 | 19 | /* 20 | * vnetKernel.h -- 21 | * This file defines platform-independent functions for accessing basic 22 | * kernel functions. This is the Linux implementation. 23 | */ 24 | 25 | #ifndef _VNETKERNEL_H_ 26 | #define _VNETKERNEL_H_ 27 | 28 | #include "driver-config.h" /* must be first */ 29 | #include 30 | #include 31 | #include "vm_basic_types.h" 32 | 33 | #define VNetKernel_EBUSY (-EBUSY) 34 | #define VNetKernel_EINVAL (-EINVAL) 35 | #define VNetKernel_ENOMEM (-ENOMEM) 36 | 37 | typedef struct VNetKernel_SpinLock { 38 | spinlock_t lock; 39 | } VNetKernel_SpinLock; 40 | 41 | static INLINE void * 42 | VNetKernel_MemoryAllocate(size_t size) 43 | { 44 | return kmalloc(size, GFP_ATOMIC); 45 | } 46 | 47 | static INLINE void 48 | VNetKernel_MemoryFree(void *ptr) 49 | { 50 | kfree(ptr); 51 | } 52 | 53 | static INLINE void 54 | VNetKernel_SpinLockInit(VNetKernel_SpinLock *lock) 55 | { 56 | spin_lock_init(&lock->lock); 57 | } 58 | 59 | static INLINE void 60 | VNetKernel_SpinLockFree(VNetKernel_SpinLock *lock) 61 | { 62 | /* nothing to do */ 63 | } 64 | 65 | static INLINE void 66 | VNetKernel_SpinLockAcquire(VNetKernel_SpinLock *lock) 67 | { 68 | spin_lock(&lock->lock); 69 | } 70 | 71 | static INLINE void 72 | VNetKernel_SpinLockRelease(VNetKernel_SpinLock *lock) 73 | { 74 | spin_unlock(&lock->lock); 75 | } 76 | 77 | static INLINE void * 78 | VNetKernel_ThreadCurrent(void) 79 | { 80 | return current; 81 | } 82 | 83 | #endif // _VNETKERNEL_H_ 84 | --------------------------------------------------------------------------------