fix build

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
2015-11-09 09:08:44 +00:00
parent d407b82968
commit 414957d985
55 changed files with 35 additions and 77 deletions

View File

@@ -0,0 +1,60 @@
/*********************************************************
* Copyright (C) 1999-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* backdoor.h --
*
* First layer of the internal communication channel between guest
* applications and vmware
*/
#ifndef _BACKDOOR_H_
#define _BACKDOOR_H_
#include "vm_basic_types.h"
#include "vm_assert.h"
#include "backdoor_types.h"
void
Backdoor(Backdoor_proto *bp); // IN/OUT
void
Backdoor_InOut(Backdoor_proto *bp); // IN/OUT
void
Backdoor_HbOut(Backdoor_proto_hb *bp); // IN/OUT
void
Backdoor_HbIn(Backdoor_proto_hb *bp); // IN/OUT
#endif /* _BACKDOOR_H_ */

View File

@@ -0,0 +1,40 @@
/*********************************************************
* Copyright (C) 2005-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* backdoorInt.h --
*
* Internal function prototypes for the real backdoor work.
*/
void BackdoorHbIn(Backdoor_proto_hb *bp);
void BackdoorHbOut(Backdoor_proto_hb *bp);

View File

@@ -0,0 +1,261 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* backdoor_def.h --
*
* This contains backdoor defines that can be included from
* an assembly language file.
*/
#ifndef _BACKDOOR_DEF_H_
#define _BACKDOOR_DEF_H_
/*
* If you want to add a new low-level backdoor call for a guest userland
* application, please consider using the GuestRpc mechanism instead. --hpreg
*/
#define BDOOR_MAGIC 0x564D5868
/* Low-bandwidth backdoor port. --hpreg */
#define BDOOR_PORT 0x5658
#define BDOOR_CMD_GETMHZ 1
/*
* BDOOR_CMD_APMFUNCTION is used by:
*
* o The FrobOS code, which instead should either program the virtual chipset
* (like the new BIOS code does, matthias offered to implement that), or not
* use any VM-specific code (which requires that we correctly implement
* "power off on CLI HLT" for SMP VMs, boris offered to implement that)
*
* o The old BIOS code, which will soon be jettisoned
*
* --hpreg
*/
#define BDOOR_CMD_APMFUNCTION 2 /* CPL0 only. */
#define BDOOR_CMD_GETDISKGEO 3
#define BDOOR_CMD_GETPTRLOCATION 4
#define BDOOR_CMD_SETPTRLOCATION 5
#define BDOOR_CMD_GETSELLENGTH 6
#define BDOOR_CMD_GETNEXTPIECE 7
#define BDOOR_CMD_SETSELLENGTH 8
#define BDOOR_CMD_SETNEXTPIECE 9
#define BDOOR_CMD_GETVERSION 10
#define BDOOR_CMD_GETDEVICELISTELEMENT 11
#define BDOOR_CMD_TOGGLEDEVICE 12
#define BDOOR_CMD_GETGUIOPTIONS 13
#define BDOOR_CMD_SETGUIOPTIONS 14
#define BDOOR_CMD_GETSCREENSIZE 15
#define BDOOR_CMD_MONITOR_CONTROL 16 /* Disabled by default. */
#define BDOOR_CMD_GETHWVERSION 17
#define BDOOR_CMD_OSNOTFOUND 18 /* CPL0 only. */
#define BDOOR_CMD_GETUUID 19
#define BDOOR_CMD_GETMEMSIZE 20
#define BDOOR_CMD_HOSTCOPY 21 /* Devel only. */
//#define BDOOR_CMD_SERVICE_VM 22 /* Not in use. Never shipped. */
#define BDOOR_CMD_GETTIME 23 /* Deprecated -> GETTIMEFULL. */
#define BDOOR_CMD_STOPCATCHUP 24
#define BDOOR_CMD_PUTCHR 25 /* Disabled by default. */
#define BDOOR_CMD_ENABLE_MSG 26 /* Devel only. */
#define BDOOR_CMD_GOTO_TCL 27 /* Devel only. */
#define BDOOR_CMD_INITPCIOPROM 28 /* CPL 0 only. */
//#define BDOOR_CMD_INT13 29 /* Not in use. */
#define BDOOR_CMD_MESSAGE 30
#define BDOOR_CMD_SIDT 31
#define BDOOR_CMD_SGDT 32
#define BDOOR_CMD_SLDT_STR 33
#define BDOOR_CMD_ISACPIDISABLED 34
//#define BDOOR_CMD_TOE 35 /* Not in use. */
#define BDOOR_CMD_ISMOUSEABSOLUTE 36
#define BDOOR_CMD_PATCH_SMBIOS_STRUCTS 37 /* CPL 0 only. */
#define BDOOR_CMD_MAPMEM 38 /* Devel only */
#define BDOOR_CMD_ABSPOINTER_DATA 39
#define BDOOR_CMD_ABSPOINTER_STATUS 40
#define BDOOR_CMD_ABSPOINTER_COMMAND 41
//#define BDOOR_CMD_TIMER_SPONGE 42 /* Not in use. */
#define BDOOR_CMD_PATCH_ACPI_TABLES 43 /* CPL 0 only. */
//#define BDOOR_CMD_DEVEL_FAKEHARDWARE 44 /* Not in use. */
#define BDOOR_CMD_GETHZ 45
#define BDOOR_CMD_GETTIMEFULL 46
#define BDOOR_CMD_STATELOGGER 47 /* Disabled by default. */
#define BDOOR_CMD_CHECKFORCEBIOSSETUP 48 /* CPL 0 only. */
#define BDOOR_CMD_LAZYTIMEREMULATION 49 /* CPL 0 only. */
#define BDOOR_CMD_BIOSBBS 50 /* CPL 0 only. */
//#define BDOOR_CMD_VASSERT 51 /* Not in use. */
#define BDOOR_CMD_ISGOSDARWIN 52
#define BDOOR_CMD_DEBUGEVENT 53
#define BDOOR_CMD_OSNOTMACOSXSERVER 54 /* CPL 0 only. */
#define BDOOR_CMD_GETTIMEFULL_WITH_LAG 55
#define BDOOR_CMD_ACPI_HOTPLUG_DEVICE 56 /* Devel only. */
#define BDOOR_CMD_ACPI_HOTPLUG_MEMORY 57 /* Devel only. */
#define BDOOR_CMD_ACPI_HOTPLUG_CBRET 58 /* Devel only. */
//#define BDOOR_CMD_GET_HOST_VIDEO_MODES 59 /* Not in use. */
#define BDOOR_CMD_ACPI_HOTPLUG_CPU 60 /* Devel only. */
//#define BDOOR_CMD_USB_HOTPLUG_MOUSE 61 /* Not in use. Never shipped. */
#define BDOOR_CMD_XPMODE 62 /* CPL 0 only. */
#define BDOOR_CMD_NESTING_CONTROL 63
#define BDOOR_CMD_FIRMWARE_INIT 64 /* CPL 0 only. */
#define BDOOR_CMD_FIRMWARE_ACPI_SERVICES 65 /* CPL 0 only. */
# define BDOOR_CMD_FAS_GET_TABLE_SIZE 0
# define BDOOR_CMD_FAS_GET_TABLE_DATA 1
# define BDOOR_CMD_FAS_GET_PLATFORM_NAME 2
# define BDOOR_CMD_FAS_GET_PCIE_OSC_MASK 3
# define BDOOR_CMD_FAS_GET_APIC_ROUTING 4
# define BDOOR_CMD_FAS_GET_TABLE_SKIP 5
# define BDOOR_CMD_FAS_GET_SLEEP_ENABLES 6
# define BDOOR_CMD_FAS_GET_HARD_RESET_ENABLE 7
#define BDOOR_CMD_SENDPSHAREHINTS 66
#define BDOOR_CMD_ENABLE_USB_MOUSE 67
#define BDOOR_CMD_GET_VCPU_INFO 68
# define BDOOR_CMD_VCPU_SLC64 0
# define BDOOR_CMD_VCPU_SYNC_VTSCS 1
# define BDOOR_CMD_VCPU_HV_REPLAY_OK 2
# define BDOOR_CMD_VCPU_LEGACY_X2APIC_OK 3
# define BDOOR_CMD_VCPU_RESERVED 31
#define BDOOR_CMD_EFI_SERIALCON_CONFIG 69 /* CPL 0 only. */
#define BDOOR_CMD_BUG328986 70 /* CPL 0 only. */
#define BDOOR_CMD_FIRMWARE_ERROR 71 /* CPL 0 only. */
# define BDOOR_CMD_FE_INSUFFICIENT_MEM 0
# define BDOOR_CMD_FE_EXCEPTION 1
#define BDOOR_CMD_VMK_INFO 72
#define BDOOR_CMD_EFI_BOOT_CONFIG 73 /* CPL 0 only. */
# define BDOOR_CMD_EBC_LEGACYBOOT_ENABLED 0
# define BDOOR_CMD_EBC_GET_ORDER 1
# define BDOOR_CMD_EBC_SHELL_ACTIVE 2
# define BDOOR_CMD_EBC_GET_NETWORK_BOOT_PROTOCOL 3
#define BDOOR_CMD_GET_HW_MODEL 74 /* CPL 0 only. */
#define BDOOR_CMD_GET_SVGA_CAPABILITIES 75 /* CPL 0 only. */
#define BDOOR_CMD_GET_FORCE_X2APIC 76 /* CPL 0 only */
#define BDOOR_CMD_SET_PCI_HOLE 77 /* CPL 0 only */
#define BDOOR_CMD_GET_PCI_HOLE 78 /* CPL 0 only */
#define BDOOR_CMD_GET_PCI_BAR 79 /* CPL 0 only */
#define BDOOR_CMD_SHOULD_GENERATE_SYSTEMID 80 /* CPL 0 only */
#define BDOOR_CMD_READ_DEBUG_FILE 81 /* Devel only. */
#define BDOOR_CMD_MAX 82
/*
* IMPORTANT NOTE: When modifying the behavior of an existing backdoor command,
* you must adhere to the semantics expected by the oldest Tools who use that
* command. Specifically, do not alter the way in which the command modifies
* the registers. Otherwise backwards compatibility will suffer.
*/
/* Processing mode for guest pshare hints (SENDPSHAREHINTS cmd) */
#define BDOOR_PSHARE_HINTS_ASYNC 0
#define BDOOR_PSHARE_HINTS_SYNC 1
#define BDOOR_PSHARE_HINTS_TYPE(ecx) (((ecx) >> 16) & 0x1)
/* Version of backdoor pshare hints protocol */
#define BDOOR_PSHARE_HINTS_VERSION 1
#define BDOOR_PSHARE_HINTS_VER(ecx) (((ecx) >> 17) & 0x7f)
/* Task applied to backdoor pshare hints */
#define BDOOR_PSHARE_HINTS_CMD_SHARE 0
#define BDOOR_PSHARE_HINTS_CMD_DROP 1
#define BDOOR_PSHARE_HINTS_CMD_MAX 2
#define BDOOR_PSHARE_HINTS_CMD(ecx) (((ecx) >> 24) & 0xff)
/* Nesting control operations */
#define NESTING_CONTROL_RESTRICT_BACKDOOR 0
#define NESTING_CONTROL_OPEN_BACKDOOR 1
#define NESTING_CONTROL_QUERY 2
#define NESTING_CONTROL_MAX 2
/* EFI Boot Order options, nibble-sized. */
#define EFI_BOOT_ORDER_TYPE_EFI 0x0
#define EFI_BOOT_ORDER_TYPE_LEGACY 0x1
#define EFI_BOOT_ORDER_TYPE_NONE 0xf
#define BDOOR_NETWORK_BOOT_PROTOCOL_NONE 0x0
#define BDOOR_NETWORK_BOOT_PROTOCOL_IPV4 0x1
#define BDOOR_NETWORK_BOOT_PROTOCOL_IPV6 0x2
/* High-bandwidth backdoor port. --hpreg */
#define BDOORHB_PORT 0x5659
#define BDOORHB_CMD_MESSAGE 0
#define BDOORHB_CMD_VASSERT 1
#define BDOORHB_CMD_MAX 2
/*
* There is another backdoor which allows access to certain TSC-related
* values using otherwise illegal PMC indices when the pseudo_perfctr
* control flag is set.
*/
#define BDOOR_PMC_HW_TSC 0x10000
#define BDOOR_PMC_REAL_NS 0x10001
#define BDOOR_PMC_APPARENT_NS 0x10002
#define BDOOR_PMC_PSEUDO_TSC 0x10003
#define IS_BDOOR_PMC(index) (((index) | 3) == 0x10003)
#define BDOOR_CMD(ecx) ((ecx) & 0xffff)
/* Sub commands for BDOOR_CMD_VMK_INFO */
#define BDOOR_CMD_VMK_INFO_ENTRY 1
#ifdef VMM
/*
*----------------------------------------------------------------------
*
* Backdoor_CmdRequiresFullyValidVCPU --
*
* A few backdoor commands require the full VCPU to be valid
* (including GDTR, IDTR, TR and LDTR). The rest get read/write
* access to GPRs and read access to Segment registers (selectors).
*
* Result:
* True iff VECX contains a command that require the full VCPU to
* be valid.
*
*----------------------------------------------------------------------
*/
static INLINE Bool
Backdoor_CmdRequiresFullyValidVCPU(unsigned cmd)
{
return cmd == BDOOR_CMD_SIDT ||
cmd == BDOOR_CMD_SGDT ||
cmd == BDOOR_CMD_SLDT_STR;
}
#endif
#endif

View File

@@ -0,0 +1,132 @@
/*********************************************************
* Copyright (C) 1999-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* backdoor_types.h --
*
* Type definitions for backdoor interaction code.
*/
#ifndef _BACKDOOR_TYPES_H_
#define _BACKDOOR_TYPES_H_
#ifndef VM_I386
#error The backdoor protocol is only supported on x86 architectures.
#endif
/*
* These #defines are intended for defining register structs as part of
* existing named unions. If the union should encapsulate the register
* (and nothing else), use DECLARE_REG_NAMED_STRUCT defined below.
*/
#define DECLARE_REG32_STRUCT \
struct { \
uint16 low; \
uint16 high; \
} halfs; \
uint32 word
#define DECLARE_REG64_STRUCT \
DECLARE_REG32_STRUCT; \
struct { \
uint32 low; \
uint32 high; \
} words; \
uint64 quad
#ifndef VM_X86_64
#define DECLARE_REG_STRUCT DECLARE_REG32_STRUCT
#else
#define DECLARE_REG_STRUCT DECLARE_REG64_STRUCT
#endif
#define DECLARE_REG_NAMED_STRUCT(_r) \
union { DECLARE_REG_STRUCT; } _r
/*
* Some of the registers are expressed by semantic name, because if they were
* expressed as register structs declared above, we could only address them
* by fixed size (half-word, word, quad, etc.) instead of by varying size
* (size_t, uintptr_t).
*
* To be cleaner, these registers are expressed ONLY by semantic name,
* rather than by a union of the semantic name and a register struct.
*/
typedef union {
struct {
DECLARE_REG_NAMED_STRUCT(ax);
size_t size; /* Register bx. */
DECLARE_REG_NAMED_STRUCT(cx);
DECLARE_REG_NAMED_STRUCT(dx);
DECLARE_REG_NAMED_STRUCT(si);
DECLARE_REG_NAMED_STRUCT(di);
} in;
struct {
DECLARE_REG_NAMED_STRUCT(ax);
DECLARE_REG_NAMED_STRUCT(bx);
DECLARE_REG_NAMED_STRUCT(cx);
DECLARE_REG_NAMED_STRUCT(dx);
DECLARE_REG_NAMED_STRUCT(si);
DECLARE_REG_NAMED_STRUCT(di);
} out;
} Backdoor_proto;
typedef union {
struct {
DECLARE_REG_NAMED_STRUCT(ax);
DECLARE_REG_NAMED_STRUCT(bx);
size_t size; /* Register cx. */
DECLARE_REG_NAMED_STRUCT(dx);
uintptr_t srcAddr; /* Register si. */
uintptr_t dstAddr; /* Register di. */
DECLARE_REG_NAMED_STRUCT(bp);
} in;
struct {
DECLARE_REG_NAMED_STRUCT(ax);
DECLARE_REG_NAMED_STRUCT(bx);
DECLARE_REG_NAMED_STRUCT(cx);
DECLARE_REG_NAMED_STRUCT(dx);
DECLARE_REG_NAMED_STRUCT(si);
DECLARE_REG_NAMED_STRUCT(di);
DECLARE_REG_NAMED_STRUCT(bp);
} out;
} Backdoor_proto_hb;
MY_ASSERTS(BACKDOOR_STRUCT_SIZES,
ASSERT_ON_COMPILE(sizeof(Backdoor_proto) == 6 * sizeof(uintptr_t));
ASSERT_ON_COMPILE(sizeof(Backdoor_proto_hb) == 7 * sizeof(uintptr_t));
)
#undef DECLARE_REG_STRUCT
#endif /* _BACKDOOR_TYPES_H_ */

View File

@@ -0,0 +1,69 @@
/*********************************************************
* Copyright (C) 2009-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* community_source.h --
*
* Macros for excluding source code from community.
*/
#ifndef _COMMUNITY_SOURCE_H_
#define _COMMUNITY_SOURCE_H_
/*
* Convenience macro for COMMUNITY_SOURCE
*/
#undef EXCLUDE_COMMUNITY_SOURCE
#ifdef COMMUNITY_SOURCE
#define EXCLUDE_COMMUNITY_SOURCE(x)
#else
#define EXCLUDE_COMMUNITY_SOURCE(x) x
#endif
#undef COMMUNITY_SOURCE_AMD_SECRET
#if !defined(COMMUNITY_SOURCE) || defined(AMD_SOURCE)
/*
* It's ok to include AMD_SECRET source code for non-Community Source,
* or for drops directed at AMD.
*/
#define COMMUNITY_SOURCE_AMD_SECRET
#endif
#undef COMMUNITY_SOURCE_INTEL_SECRET
#if !defined(COMMUNITY_SOURCE) || defined(INTEL_SOURCE)
/*
* It's ok to include INTEL_SECRET source code for non-Community Source,
* or for drops directed at Intel.
*/
#define COMMUNITY_SOURCE_INTEL_SECRET
#endif
#endif

View File

@@ -0,0 +1,88 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
#ifndef _CPUID_INFO_H
#define _CPUID_INFO_H
#include "vm_basic_asm.h"
#include "x86cpuid_asm.h"
typedef struct CPUID0 {
int numEntries;
char name[16]; // 4 extra bytes to null terminate
} CPUID0;
typedef struct CPUID1 {
uint32 version;
uint32 ebx;
uint32 ecxFeatures;
uint32 edxFeatures;
} CPUID1;
typedef struct CPUID80 {
uint32 numEntries;
uint32 ebx;
uint32 ecx;
uint32 edx;
} CPUID80;
typedef struct CPUID81 {
uint32 eax;
uint32 ebx;
uint32 ecxFeatures;
uint32 edxFeatures;
} CPUID81;
typedef struct CPUIDSummary {
CPUID0 id0;
CPUID1 id1;
CPUIDRegs ida;
CPUID80 id80;
CPUID81 id81;
CPUIDRegs id88, id8a;
} CPUIDSummary;
/*
*----------------------------------------------------------------------
*
* CPUIDSummary_RegsFromCpuid0 --
*
* Fills in the given CPUIDRegs struct with the values from the CPUID0 struct.
*
* Results:
* Returns the CPUIDRegs pointer passed in.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static INLINE CPUIDRegs*
CPUIDSummary_RegsFromCpuid0(CPUID0* id0In,
CPUIDRegs* id0Out)
{
id0Out->eax = id0In->numEntries;
id0Out->ebx = *(uint32 *) (id0In->name + 0);
id0Out->edx = *(uint32 *) (id0In->name + 4);
id0Out->ecx = *(uint32 *) (id0In->name + 8);
return id0Out;
}
#endif

34
vendor/github.com/sigma/vmw-guestinfo/include/debug.h generated vendored Normal file
View File

@@ -0,0 +1,34 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* debug.h --
*
* Platform specific debug routines
*
*/
#ifndef __DEBUG_H__
# define __DEBUG_H__
# include "vm_basic_types.h"
void Debug(char const *fmt, ...) PRINTF_DECL(1, 2);
#endif /* __DEBUG_H__ */

236
vendor/github.com/sigma/vmw-guestinfo/include/dynbuf.h generated vendored Normal file
View File

@@ -0,0 +1,236 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* dynbuf.h --
*
* Dynamic buffers
*/
#ifndef __DYNBUF_H__
# define __DYNBUF_H__
#include <string.h>
#include "vm_basic_types.h"
#include "vm_assert.h"
typedef struct DynBuf {
char *data;
size_t size;
size_t allocated;
} DynBuf;
void
DynBuf_Init(DynBuf *b); // IN
void
DynBuf_Destroy(DynBuf *b); // IN
void *
DynBuf_AllocGet(DynBuf const *b); // IN
void
DynBuf_Attach(DynBuf *b, // IN
size_t size, // IN
void *data); // IN
void *
DynBuf_Detach(DynBuf *b); // IN
Bool
DynBuf_Enlarge(DynBuf *b, // IN
size_t min_size); // IN
Bool
DynBuf_Append(DynBuf *b, // IN
void const *data, // IN
size_t size); // IN
Bool
DynBuf_Trim(DynBuf *b); // IN
Bool
DynBuf_Copy(DynBuf *src, // IN
DynBuf *dest); // OUT
void
DynBuf_SafeInternalAppend(DynBuf *b, // IN
void const *data, // IN
size_t size, // IN
char const *file, // IN
unsigned int lineno); // IN
#define DynBuf_SafeAppend(_buf, _data, _size) \
DynBuf_SafeInternalAppend(_buf, _data, _size, __FILE__, __LINE__)
/*
*-----------------------------------------------------------------------------
*
* DynBuf_Get --
*
* Retrieve a pointer to the data contained in a dynamic buffer --hpreg
*
* Results:
* The pointer to the data
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
#if defined(SWIG)
static void *
#else
static INLINE void *
#endif
DynBuf_Get(DynBuf const *b) // IN
{
ASSERT(b);
return b->data;
}
/*
*-----------------------------------------------------------------------------
*
* DynBuf_GetSize --
*
* Returns the current size of the dynamic buffer --hpreg
*
* Results:
* The current size of the dynamic buffer
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
#if defined(SWIG)
static size_t
#else
static INLINE size_t
#endif
DynBuf_GetSize(DynBuf const *b) // IN
{
ASSERT(b);
return b->size;
}
/*
*-----------------------------------------------------------------------------
*
* DynBuf_SetSize --
*
* Set the current size of a dynamic buffer --hpreg
*
* Results:
* None
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
#if defined(SWIG)
static void
#else
static INLINE void
#endif
DynBuf_SetSize(DynBuf *b, // IN
size_t size) // IN
{
ASSERT(b);
ASSERT(size <= b->allocated);
b->size = size;
}
/*
*-----------------------------------------------------------------------------
*
* DynBuf_GetAllocatedSize --
*
* Returns the current allocated size of the dynamic buffer --hpreg
*
* Results:
* The current allocated size of the dynamic buffer
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
#if defined(SWIG)
static size_t
#else
static INLINE size_t
#endif
DynBuf_GetAllocatedSize(DynBuf const *b) // IN
{
ASSERT(b);
return b->allocated;
}
/*
*----------------------------------------------------------------------------
*
* DynBuf_AppendString --
*
* Append the string to the specified DynBuf object. Basically a
* fancy strcat().
*
* Results:
* TRUE on success
* FALSE on failure (not enough memory)
*
*
* Side effects:
* DynBuf may change its size or allocate additional memory.
*
*----------------------------------------------------------------------------
*/
#if defined(SWIG)
static Bool
#else
static INLINE Bool
#endif
DynBuf_AppendString(DynBuf *buf, // IN
const char *string) // IN
{
/*
* Make sure to copy the NULL.
*/
return DynBuf_Append(buf, string, strlen(string) + 1);
}
#endif /* __DYNBUF_H__ */

View File

@@ -0,0 +1,100 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* guest_msg_def.h --
*
* Second layer of the internal communication channel between guest
* applications and vmware
*
*/
#ifndef _GUEST_MSG_DEF_H_
#define _GUEST_MSG_DEF_H_
/* Basic request types */
typedef enum {
MESSAGE_TYPE_OPEN,
MESSAGE_TYPE_SENDSIZE,
MESSAGE_TYPE_SENDPAYLOAD,
MESSAGE_TYPE_RECVSIZE,
MESSAGE_TYPE_RECVPAYLOAD,
MESSAGE_TYPE_RECVSTATUS,
MESSAGE_TYPE_CLOSE,
} MessageType;
/* Reply statuses */
/* The basic request succeeded */
#define MESSAGE_STATUS_SUCCESS 0x0001
/* vmware has a message available for its party */
#define MESSAGE_STATUS_DORECV 0x0002
/* The channel has been closed */
#define MESSAGE_STATUS_CLOSED 0x0004
/* vmware removed the message before the party fetched it */
#define MESSAGE_STATUS_UNSENT 0x0008
/* A checkpoint occurred */
#define MESSAGE_STATUS_CPT 0x0010
/* An underlying device is powering off */
#define MESSAGE_STATUS_POWEROFF 0x0020
/* vmware has detected a timeout on the channel */
#define MESSAGE_STATUS_TIMEOUT 0x0040
/* vmware supports high-bandwidth for sending and receiving the payload */
#define MESSAGE_STATUS_HB 0x0080
/*
* This mask defines the status bits that the guest is allowed to set;
* we use this to mask out all other bits when receiving the status
* from the guest. Otherwise, the guest can manipulate VMX state by
* setting status bits that are only supposed to be changed by the
* VMX. See bug 45385.
*/
#define MESSAGE_STATUS_GUEST_MASK MESSAGE_STATUS_SUCCESS
/*
* Max number of channels.
* Unfortunately this has to be public because the monitor part
* of the backdoor needs it for its trivial-case optimization. [greg]
*/
#define GUESTMSG_MAX_CHANNEL 8
/* Flags to open a channel. --hpreg */
#define GUESTMSG_FLAG_COOKIE 0x80000000
#define GUESTMSG_FLAG_ALL GUESTMSG_FLAG_COOKIE
/*
* Maximum size of incoming message. This is to prevent denial of host service
* attacks from guest applications.
*/
#define GUESTMSG_MAX_IN_SIZE (64 * 1024)
#endif /* _GUEST_MSG_DEF_H_ */

View File

@@ -0,0 +1,36 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* hostType.h --
*
* Interface to host-specific information functions
*
*/
#ifndef _HOSTTYPE_H_
#define _HOSTTYPE_H_
#include "vm_basic_types.h"
Bool HostType_OSIsVMK(void);
Bool HostType_OSIsPureVMK(void);
Bool HostType_OSIsVMK64(void);
Bool HostType_OSIsSimulator(void);
#endif /* ifndef _HOSTTYPE_H_ */

View File

@@ -0,0 +1,234 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* hostinfo.h --
*
* Interface to host-specific information functions
*
*/
#if !defined(_HOSTINFO_H_)
#define _HOSTINFO_H_
#include "vm_basic_types.h"
#include "vm_basic_defs.h"
#include "x86cpuid.h"
#include "unicodeTypes.h"
typedef enum {
HOSTINFO_PROCESS_QUERY_DEAD, // Procss is dead (does not exist)
HOSTINFO_PROCESS_QUERY_ALIVE, // Process is alive (does exist)
HOSTINFO_PROCESS_QUERY_UNKNOWN // Process existence cannot be determined
} HostinfoProcessQuery;
HostinfoProcessQuery Hostinfo_QueryProcessExistence(int pid);
Unicode Hostinfo_NameGet(void); /* don't free result */
Unicode Hostinfo_HostName(void); /* free result */
void Hostinfo_MachineID(uint32 *hostNameHash,
uint64 *hostHardwareID);
Bool Hostinfo_GetMemoryInfoInPages(unsigned int *minSize,
unsigned int *maxSize,
unsigned int *currentSize);
#ifdef __linux__
Bool Hostinfo_GetSwapInfoInPages(unsigned int *totalSwap,
unsigned int *freeSwap);
#endif
Bool Hostinfo_GetRatedCpuMhz(int32 cpuNumber,
uint32 *mHz);
char *Hostinfo_GetCpuDescription(uint32 cpuNumber);
void Hostinfo_GetTimeOfDay(VmTimeType *time);
VmTimeType Hostinfo_SystemUpTime(void);
VmTimeType Hostinfo_SystemTimerNS(void);
static INLINE VmTimeType
Hostinfo_SystemTimerUS(void)
{
return Hostinfo_SystemTimerNS() / 1000ULL;
}
static INLINE VmTimeType
Hostinfo_SystemTimerMS(void)
{
return Hostinfo_SystemTimerNS() / 1000000ULL;
}
int Hostinfo_OSVersion(unsigned int i);
int Hostinfo_GetSystemBitness(void);
const char *Hostinfo_OSVersionString(void);
char *Hostinfo_GetOSName(void);
char *Hostinfo_GetOSGuestString(void);
Bool Hostinfo_OSIsSMP(void);
#if defined(_WIN32)
Bool Hostinfo_OSIsWinNT(void);
Bool Hostinfo_OSIsWow64(void);
Bool Hostinfo_TSCInvariant(void);
DWORD Hostinfo_OpenProcessBits(void);
DWORD Hostinfo_OpenThreadBits(void);
#else
void Hostinfo_ResetProcessState(const int *keepFds,
size_t numKeepFds);
int Hostinfo_Execute(const char *path,
char * const *args,
Bool wait,
const int *keepFds,
size_t numKeepFds);
typedef enum HostinfoDaemonizeFlags {
HOSTINFO_DAEMONIZE_DEFAULT = 0,
HOSTINFO_DAEMONIZE_NOCHDIR = (1 << 0),
HOSTINFO_DAEMONIZE_NOCLOSE = (1 << 1),
HOSTINFO_DAEMONIZE_EXIT = (1 << 2),
HOSTINFO_DAEMONIZE_LOCKPID = (1 << 3),
} HostinfoDaemonizeFlags;
Bool Hostinfo_Daemonize(const char *path,
char * const *args,
HostinfoDaemonizeFlags flags,
const char *pidPath,
const int *keepFds,
size_t numKeepFds);
#endif
Bool Hostinfo_NestingSupported(void);
Bool Hostinfo_VCPUInfoBackdoor(unsigned bit);
Bool Hostinfo_SLC64Supported(void);
Bool Hostinfo_SynchronizedVTSCs(void);
Bool Hostinfo_NestedHVReplaySupported(void);
Bool Hostinfo_TouchBackDoor(void);
Bool Hostinfo_TouchVirtualPC(void);
Bool Hostinfo_TouchXen(void);
char *Hostinfo_HypervisorCPUIDSig(void);
#define HGMP_PRIVILEGE 0
#define HGMP_NO_PRIVILEGE 1
Unicode Hostinfo_GetModulePath(uint32 priv);
char *Hostinfo_GetLibraryPath(void *addr);
Unicode Hostinfo_GetUser(void);
void Hostinfo_LogMemUsage(void);
/*
* HostInfoCpuIdInfo --
*
* Contains cpuid information for a CPU.
*/
typedef struct {
CpuidVendor vendor;
uint32 version;
uint8 family;
uint8 model;
uint8 stepping;
uint8 type;
uint32 features;
uint32 extfeatures;
} HostinfoCpuIdInfo;
uint32 Hostinfo_NumCPUs(void);
char *Hostinfo_GetCpuidStr(void);
Bool Hostinfo_GetCpuid(HostinfoCpuIdInfo *info);
#if !defined(VMX86_SERVER)
Bool Hostinfo_CPUCounts(uint32 *logical,
uint32 *cores,
uint32 *pkgs);
#endif
#if defined(_WIN32)
typedef enum {
OS_WIN95 = 1,
OS_WIN98 = 2,
OS_WINME = 3,
OS_WINNT = 4,
OS_WIN2K = 5,
OS_WINXP = 6,
OS_WIN2K3 = 7,
OS_VISTA = 8,
OS_WINSEVEN = 9,
OS_WIN8 = 10,
OS_WIN10 = 11,
OS_UNKNOWN = 99999 // last, highest value
} OS_TYPE;
typedef enum {
OS_DETAIL_WIN95 = 1,
OS_DETAIL_WIN98 = 2,
OS_DETAIL_WINME = 3,
OS_DETAIL_WINNT = 4,
OS_DETAIL_WIN2K = 5,
OS_DETAIL_WIN2K_PRO = 6,
OS_DETAIL_WIN2K_SERV = 7,
OS_DETAIL_WIN2K_ADV_SERV = 8,
OS_DETAIL_WINXP = 9,
OS_DETAIL_WINXP_HOME = 10,
OS_DETAIL_WINXP_PRO = 11,
OS_DETAIL_WINXP_X64_PRO = 12,
OS_DETAIL_WIN2K3 = 13,
OS_DETAIL_WIN2K3_WEB = 14,
OS_DETAIL_WIN2K3_ST = 15,
OS_DETAIL_WIN2K3_EN = 16,
OS_DETAIL_WIN2K3_BUS = 17,
OS_DETAIL_VISTA = 18,
OS_DETAIL_WIN2K8 = 19,
OS_DETAIL_WINSEVEN = 20,
OS_DETAIL_WIN2K8R2 = 21,
OS_DETAIL_WIN8 = 22,
OS_DETAIL_WIN8SERVER = 23,
OS_DETAIL_WIN10 = 24,
OS_DETAIL_WIN10SERVER = 25,
OS_DETAIL_UNKNOWN = 99999 // last, highest value
} OS_DETAIL_TYPE;
/* generic names (to protect the future) but Windows specific for now */
OS_TYPE Hostinfo_GetOSType(void);
OS_DETAIL_TYPE Hostinfo_GetOSDetailType(void);
Bool Hostinfo_GetPCFrequency(uint64 *pcHz);
Bool Hostinfo_GetMhzOfProcessor(int32 processorNumber,
uint32 *currentMhz,
uint32 *maxMhz);
uint64 Hostinfo_SystemIdleTime(void);
Bool Hostinfo_GetAllCpuid(CPUIDQuery *query);
static INLINE Bool
Hostinfo_AtLeastVista(void)
{
return (Hostinfo_GetOSType() >= OS_VISTA);
}
#endif
void Hostinfo_LogLoadAverage(void);
Bool Hostinfo_GetLoadAverage(uint32 *l);
#ifdef __APPLE__
size_t Hostinfo_GetKernelZoneElemSize(char const *name);
char *Hostinfo_GetHardwareModel(void);
#endif
#endif /* ifndef _HOSTINFO_H_ */

View File

@@ -0,0 +1,49 @@
/*********************************************************
* Copyright (C) 2009-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* hostinfoInt.h --
*
* lib/misc Hostinfo_* private declarations.
*/
#ifndef _HOSTINFOINT_H_
#define _HOSTINFOINT_H_
#define MAX_OS_NAME_LEN 128
#define MAX_OS_FULLNAME_LEN 512
/*
* Global variables
*/
extern volatile Bool HostinfoOSNameCacheValid;
extern char HostinfoCachedOSName[MAX_OS_NAME_LEN];
extern char HostinfoCachedOSFullName[MAX_OS_FULLNAME_LEN];
/*
* Global functions
*/
extern Bool HostinfoOSData(void);
#endif // ifndef _HOSTINFOINT_H_

View File

@@ -0,0 +1,72 @@
/*********************************************************
* Copyright (C) 1999-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* message.h --
*
* Second layer of the internal communication channel between guest
* applications and vmware
*/
#ifndef __MESSAGE_H__
# define __MESSAGE_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "vm_basic_types.h"
typedef struct Message_Channel Message_Channel;
Message_Channel *
Message_Open(uint32 proto); // IN
Bool
Message_Send(Message_Channel *chan, // IN/OUT
const unsigned char *buf, // IN
size_t bufSize); // IN
Bool
Message_Receive(Message_Channel *chan, // IN/OUT
unsigned char **buf, // OUT
size_t *bufSize); // OUT
Bool
Message_Close(Message_Channel *chan); // IN/OUT
#ifdef __cplusplus
}
#endif
#endif /* __MESSAGE_H__ */

143
vendor/github.com/sigma/vmw-guestinfo/include/mul64.h generated vendored Normal file
View File

@@ -0,0 +1,143 @@
/*********************************************************
* Copyright (C) 2003-2014 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* mul64.h
*
* Integer by fixed point multiplication, with rounding.
*
* These routines are implemented in assembly language for most
* supported platforms. This file has plain C fallback versions.
*/
#ifndef _MUL64_H_
#define _MUL64_H_
#define INCLUDE_ALLOW_USERLEVEL
#define INCLUDE_ALLOW_MODULE
#define INCLUDE_ALLOW_VMMON
#define INCLUDE_ALLOW_VMK_MODULE
#define INCLUDE_ALLOW_VMKERNEL
#define INCLUDE_ALLOW_DISTRIBUTE
#define INCLUDE_ALLOW_VMCORE
#include "includeCheck.h"
#include "vm_basic_asm.h"
#ifdef MUL64_NO_ASM
/*
*-----------------------------------------------------------------------------
*
* Mul64x3264 --
*
* Unsigned integer by fixed point multiplication, with rounding:
* result = floor(multiplicand * multiplier * 2**(-shift) + 0.5)
*
* Unsigned 64-bit integer multiplicand.
* Unsigned 32-bit fixed point multiplier, represented as
* (multiplier, shift), where shift < 64.
*
* Result:
* Unsigned 64-bit integer product.
*
*-----------------------------------------------------------------------------
*/
static INLINE uint64
Mul64x3264(uint64 multiplicand, uint32 multiplier, uint32 shift)
{
uint64 lo, hi, lo2, hi2;
unsigned carry;
// ASSERT(shift >= 0 && shift < 64);
lo = (multiplicand & 0xffffffff) * multiplier;
hi = (multiplicand >> 32) * multiplier;
lo2 = lo + (hi << 32);
carry = lo2 < lo;
hi2 = (hi >> 32) + carry;
if (shift == 0) {
return lo2;
} else {
return (lo2 >> shift) + (hi2 << (64 - shift)) +
((lo2 >> (shift - 1)) & 1);
}
}
/*
*-----------------------------------------------------------------------------
*
* Muls64x32s64 --
*
* Signed integer by fixed point multiplication, with rounding:
* result = floor(multiplicand * multiplier * 2**(-shift) + 0.5)
*
* Signed 64-bit integer multiplicand.
* Unsigned 32-bit fixed point multiplier, represented as
* (multiplier, shift), where shift < 64.
*
* Result:
* Signed 64-bit integer product.
*
*-----------------------------------------------------------------------------
*/
static INLINE int64
Muls64x32s64(int64 multiplicand, uint32 multiplier, uint32 shift)
{
uint64 lo, hi, lo2, hi2;
unsigned carry;
// ASSERT(shift >= 0 && shift < 64);
hi = ((uint64)multiplicand >> 32) * multiplier;
if (multiplicand < 0) {
hi -= (uint64)multiplier << 32;
}
lo = ((uint64)multiplicand & 0xffffffff) * multiplier;
lo2 = lo + (hi << 32);
carry = lo2 < lo;
hi2 = (((int64)hi >> 32) + carry);
if (shift == 0) {
return lo2;
} else {
return (lo2 >> shift) + (hi2 << (64 - shift)) +
((lo2 >> (shift - 1)) & 1);
}
}
#endif
#endif // _MUL64_NOASM_H_

View File

@@ -0,0 +1,187 @@
/*********************************************************
* Copyright (C) 2004-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* safetime.h --
*
* This header file defines wrappers so that we use the
* 64-bit versions of the C time calls. This file is
* temporary until we switch to a newer version of
* Visual Studio that uses the 64-bit verisions by default.
*
* In Windows, the user is allowed to set the time past the
* 32-bit overflow date (in 2038), which can cause crashes
* and security problems. In Linux, the time can't be set
* to overflow, so we do nothing.
*
* NB: We do not know if one can set the time past 2038 in
* 64-bit versions of Linux, and, if so, what happens when
* one does. This requires further investigation sometime
* in the future.
*
* The stat types and functions must be defined manually,
* since they contain time_ts, and we can't use the macro
* trick, since the struct stat and the function stat have
* the same 32 bit name (but different 64 bit names).
*
*/
#ifndef _SAFETIME_H_
#define _SAFETIME_H_
#ifdef _WIN32
#undef FMTTIME
#define FMTTIME FMT64"d"
#if (_MSC_VER < 1400)
#if (defined(_STAT_DEFINED) || defined(_INC_TIME) || defined(_INC_TYPES))
#error Use safetime.h instead of time.h, stat.h, and types.h
#endif
#define _STAT_DEFINED
#include <time.h>
#include <sys/utime.h>
#include <sys/timeb.h>
#define time_t __time64_t
#define time(a) _time64(a)
#define localtime(a) _localtime64((a))
#define _ctime(a) _ctime64((a))
#define ctime(a) _ctime64((a))
#define _ftime(a) _ftime64((a))
#define ftime(a) _ftime64((a))
#define _timeb __timeb64
#define _gmtime(a) _gmtime64((a))
#define gmtime(a) _gmtime64((a))
#define _mktime(a) _mktime64((a))
#define mktime(a) _mktime64((a))
#define _utime(a,b) _utime64((a),(b))
#define utime(a,b) _utime64((a),(b))
#define _utimbuf __utimbuf64
#define utimbuf __utimbuf64
#define _wctime(a) _wctime64((a),(b))
#define wctime(a) _wctime64((a),(b))
#define _futime(a,b) _futime64((a),(b))
#define futime(a,b) _futime64((a),(b))
#define _wutime(a,b) _wutime64((a),(b))
#define wutime(a,b) _wutime64((a),(b))
#include <sys/types.h>
#ifdef _MSC_VER
#pragma pack(push,8)
#endif
struct _stat {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
__int64 st_size;
__time64_t st_atime;
__time64_t st_mtime;
__time64_t st_ctime;
};
struct stat {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
__int64 st_size;
__time64_t st_atime;
__time64_t st_mtime;
__time64_t st_ctime;
};
struct __stat64 {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
__int64 st_size;
__time64_t st_atime;
__time64_t st_mtime;
__time64_t st_ctime;
};
#ifdef _MSC_VER
#pragma pack(pop)
#endif
#include <sys/stat.h>
#define stat(a,b) _stat64((a),(struct __stat64*)(b))
#define _stat(a,b) _stat64((a),(struct __stat64*)(b))
#define fstat(a,b) _fstat64((a),(struct __stat64*)(b))
#define _fstat(a,b) _fstat64((a),(struct __stat64*)(b))
#define wstat(a,b) _wstat64((a),(struct __stat64*)(b))
#define _wstat(a,b) _wstat64((a),(struct __stat64*)(b))
#else /* (_MSC_VER < 1400) */
/*
* Starting with VC80, we can pick between 32-bit and 64-bit time_t
* by defining or not defining _USE_32BIT_TIME_T. Don't define it.
*/
#include <time.h>
#include <sys/utime.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
/* Make sure that the headers didn't revert to 32-bit. */
#ifdef _USE_32BIT_TIME_T
#error Refusing to use 32-bit time_t in safetime.h
#endif
#endif /* (_MSC_VER < 1400) */
#else
#include <sys/types.h>
#include <time.h>
#include <sys/stat.h>
#include <utime.h>
#endif
#endif

View File

@@ -0,0 +1,485 @@
/*********************************************************
* Copyright (C) 2007-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* unicodeTypes.h --
*
* Types used throughout the Unicode library.
*/
#ifndef _UNICODE_TYPES_H_
#define _UNICODE_TYPES_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "vm_basic_types.h"
#include "vm_assert.h"
#if defined(SUPPORT_UNICODE_OPAQUE)
/*
* To assist with finding code that hasn't been internationalized, we
* support building with an opaque Unicode type. This catches users
* passing a char * of unknown encoding to Unicode functions, and
* assigning a Unicode to a char *.
*/
typedef struct UnicodeImpl UnicodeImpl;
typedef UnicodeImpl * Unicode;
typedef const UnicodeImpl * ConstUnicode;
#else
/*
* As a transitionary development tactic to prevent code churn while the
* Unicode libraries are being developed, we'll start with a simple
* implementation of Unicode as UTF-8 char *.
*/
typedef char * Unicode;
typedef const char * ConstUnicode;
#endif
typedef ssize_t UnicodeIndex;
/*
* Special UnicodeIndex value returned when a string is not found.
*/
enum {
UNICODE_INDEX_NOT_FOUND = -1
};
/*
* Encodings passed to convert encoded byte strings to and from
* Unicode.
*
* Keep this enum synchronized with ICU_ENCODING_LIST in unicodeICU.cc!
*/
typedef enum {
STRING_ENCODING_FIRST,
/*
* Byte string encodings that support all characters in Unicode.
*
* If you don't know what to use for bytes in a new system, use
* STRING_ENCODING_UTF8.
*/
STRING_ENCODING_UTF8 = STRING_ENCODING_FIRST,
STRING_ENCODING_UTF16_LE, // Little-endian UTF-16.
STRING_ENCODING_UTF16_BE, // Big-endian UTF-16.
STRING_ENCODING_UTF16_XE, // UTF-16 with BOM.
STRING_ENCODING_UTF32_LE, // Little-endian UTF-32.
STRING_ENCODING_UTF32_BE, // Big-endian UTF-32.
STRING_ENCODING_UTF32_XE, // UTF-32 with BOM.
/*
* Legacy byte string encodings that only support a subset of Unicode.
*/
/*
* Latin encodings
*/
STRING_ENCODING_US_ASCII,
STRING_ENCODING_ISO_8859_1,
STRING_ENCODING_ISO_8859_2,
STRING_ENCODING_ISO_8859_3,
STRING_ENCODING_ISO_8859_4,
STRING_ENCODING_ISO_8859_5,
STRING_ENCODING_ISO_8859_6,
STRING_ENCODING_ISO_8859_7,
STRING_ENCODING_ISO_8859_8,
STRING_ENCODING_ISO_8859_9,
STRING_ENCODING_ISO_8859_10,
// ISO-8859-11 is unused.
// Oddly, there is no ISO-8859-12.
STRING_ENCODING_ISO_8859_13,
STRING_ENCODING_ISO_8859_14,
STRING_ENCODING_ISO_8859_15,
/*
* Chinese encodings
*/
STRING_ENCODING_GB_18030,
STRING_ENCODING_BIG_5,
STRING_ENCODING_BIG_5_HK,
STRING_ENCODING_GBK,
STRING_ENCODING_GB_2312,
STRING_ENCODING_ISO_2022_CN,
/*
* Japanese encodings
*/
STRING_ENCODING_SHIFT_JIS,
STRING_ENCODING_EUC_JP,
STRING_ENCODING_ISO_2022_JP,
STRING_ENCODING_ISO_2022_JP_1,
STRING_ENCODING_ISO_2022_JP_2,
/*
* Korean encodings
*/
STRING_ENCODING_ISO_2022_KR,
/*
* Windows encodings
*/
STRING_ENCODING_WINDOWS_1250,
STRING_ENCODING_WINDOWS_1251,
STRING_ENCODING_WINDOWS_1252,
STRING_ENCODING_WINDOWS_1253,
STRING_ENCODING_WINDOWS_1254,
STRING_ENCODING_WINDOWS_1255,
STRING_ENCODING_WINDOWS_1256,
STRING_ENCODING_WINDOWS_1257,
STRING_ENCODING_WINDOWS_1258,
STRING_ENCODING_ISO_6937_2_ADD,
STRING_ENCODING_JIS_X0201,
STRING_ENCODING_JIS_ENCODING,
STRING_ENCODING_EXTENDED_UNIX_CODE_FIXED_WIDTH_FOR_JAPANESE,
STRING_ENCODING_BS_4730,
STRING_ENCODING_SEN_850200_C,
STRING_ENCODING_IT,
STRING_ENCODING_ES,
STRING_ENCODING_DIN_66003,
STRING_ENCODING_NS_4551_1,
STRING_ENCODING_NF_Z_62_010,
STRING_ENCODING_ISO_10646_UTF_1,
STRING_ENCODING_ISO_646_BASIC_1983,
STRING_ENCODING_INVARIANT,
STRING_ENCODING_ISO_646_IRV_1983,
STRING_ENCODING_NATS_SEFI,
STRING_ENCODING_NATS_SEFI_ADD,
STRING_ENCODING_NATS_DANO,
STRING_ENCODING_NATS_DANO_ADD,
STRING_ENCODING_SEN_850200_B,
STRING_ENCODING_KS_C_5601_1987,
STRING_ENCODING_JIS_C6220_1969_JP,
STRING_ENCODING_JIS_C6220_1969_RO,
STRING_ENCODING_PT,
STRING_ENCODING_GREEK7_OLD,
STRING_ENCODING_LATIN_GREEK,
STRING_ENCODING_NF_Z_62_010__1973_,
STRING_ENCODING_LATIN_GREEK_1,
STRING_ENCODING_ISO_5427,
STRING_ENCODING_JIS_C6226_1978,
STRING_ENCODING_BS_VIEWDATA,
STRING_ENCODING_INIS,
STRING_ENCODING_INIS_8,
STRING_ENCODING_INIS_CYRILLIC,
STRING_ENCODING_ISO_5427_1981,
STRING_ENCODING_ISO_5428_1980,
STRING_ENCODING_GB_1988_80,
STRING_ENCODING_GB_2312_80,
STRING_ENCODING_NS_4551_2,
STRING_ENCODING_VIDEOTEX_SUPPL,
STRING_ENCODING_PT2,
STRING_ENCODING_ES2,
STRING_ENCODING_MSZ_7795_3,
STRING_ENCODING_JIS_C6226_1983,
STRING_ENCODING_GREEK7,
STRING_ENCODING_ASMO_449,
STRING_ENCODING_ISO_IR_90,
STRING_ENCODING_JIS_C6229_1984_A,
STRING_ENCODING_JIS_C6229_1984_B,
STRING_ENCODING_JIS_C6229_1984_B_ADD,
STRING_ENCODING_JIS_C6229_1984_HAND,
STRING_ENCODING_JIS_C6229_1984_HAND_ADD,
STRING_ENCODING_JIS_C6229_1984_KANA,
STRING_ENCODING_ISO_2033_1983,
STRING_ENCODING_ANSI_X3_110_1983,
STRING_ENCODING_T_61_7BIT,
STRING_ENCODING_T_61_8BIT,
STRING_ENCODING_ECMA_CYRILLIC,
STRING_ENCODING_CSA_Z243_4_1985_1,
STRING_ENCODING_CSA_Z243_4_1985_2,
STRING_ENCODING_CSA_Z243_4_1985_GR,
STRING_ENCODING_ISO_8859_6_E,
STRING_ENCODING_ISO_8859_6_I,
STRING_ENCODING_T_101_G2,
STRING_ENCODING_ISO_8859_8_E,
STRING_ENCODING_ISO_8859_8_I,
STRING_ENCODING_CSN_369103,
STRING_ENCODING_JUS_I_B1_002,
STRING_ENCODING_IEC_P27_1,
STRING_ENCODING_JUS_I_B1_003_SERB,
STRING_ENCODING_JUS_I_B1_003_MAC,
STRING_ENCODING_GREEK_CCITT,
STRING_ENCODING_NC_NC00_10_81,
STRING_ENCODING_ISO_6937_2_25,
STRING_ENCODING_GOST_19768_74,
STRING_ENCODING_ISO_8859_SUPP,
STRING_ENCODING_ISO_10367_BOX,
STRING_ENCODING_LATIN_LAP,
STRING_ENCODING_JIS_X0212_1990,
STRING_ENCODING_DS_2089,
STRING_ENCODING_US_DK,
STRING_ENCODING_DK_US,
STRING_ENCODING_KSC5636,
STRING_ENCODING_UNICODE_1_1_UTF_7,
STRING_ENCODING_ISO_2022_CN_EXT,
STRING_ENCODING_ISO_8859_16,
STRING_ENCODING_OSD_EBCDIC_DF04_15,
STRING_ENCODING_OSD_EBCDIC_DF03_IRV,
STRING_ENCODING_OSD_EBCDIC_DF04_1,
STRING_ENCODING_ISO_11548_1,
STRING_ENCODING_KZ_1048,
STRING_ENCODING_ISO_10646_UCS_2,
STRING_ENCODING_ISO_10646_UCS_4,
STRING_ENCODING_ISO_10646_UCS_BASIC,
STRING_ENCODING_ISO_10646_UNICODE_LATIN1,
STRING_ENCODING_ISO_10646_J_1,
STRING_ENCODING_ISO_UNICODE_IBM_1261,
STRING_ENCODING_ISO_UNICODE_IBM_1268,
STRING_ENCODING_ISO_UNICODE_IBM_1276,
STRING_ENCODING_ISO_UNICODE_IBM_1264,
STRING_ENCODING_ISO_UNICODE_IBM_1265,
STRING_ENCODING_UNICODE_1_1,
STRING_ENCODING_SCSU,
STRING_ENCODING_UTF_7,
STRING_ENCODING_CESU_8,
STRING_ENCODING_BOCU_1,
STRING_ENCODING_ISO_8859_1_WINDOWS_3_0_LATIN_1,
STRING_ENCODING_ISO_8859_1_WINDOWS_3_1_LATIN_1,
STRING_ENCODING_ISO_8859_2_WINDOWS_LATIN_2,
STRING_ENCODING_ISO_8859_9_WINDOWS_LATIN_5,
STRING_ENCODING_HP_ROMAN8,
STRING_ENCODING_ADOBE_STANDARD_ENCODING,
STRING_ENCODING_VENTURA_US,
STRING_ENCODING_VENTURA_INTERNATIONAL,
STRING_ENCODING_DEC_MCS,
STRING_ENCODING_IBM_850,
STRING_ENCODING_PC8_DANISH_NORWEGIAN,
STRING_ENCODING_IBM_862,
STRING_ENCODING_PC8_TURKISH,
STRING_ENCODING_IBM_SYMBOLS,
STRING_ENCODING_IBM_THAI,
STRING_ENCODING_HP_LEGAL,
STRING_ENCODING_HP_PI_FONT,
STRING_ENCODING_HP_MATH8,
STRING_ENCODING_ADOBE_SYMBOL_ENCODING,
STRING_ENCODING_HP_DESKTOP,
STRING_ENCODING_VENTURA_MATH,
STRING_ENCODING_MICROSOFT_PUBLISHING,
STRING_ENCODING_WINDOWS_31J,
STRING_ENCODING_MACINTOSH,
STRING_ENCODING_IBM_037,
STRING_ENCODING_IBM_038,
STRING_ENCODING_IBM_273,
STRING_ENCODING_IBM_274,
STRING_ENCODING_IBM_275,
STRING_ENCODING_IBM_277,
STRING_ENCODING_IBM_278,
STRING_ENCODING_IBM_280,
STRING_ENCODING_IBM_281,
STRING_ENCODING_IBM_284,
STRING_ENCODING_IBM_285,
STRING_ENCODING_IBM_290,
STRING_ENCODING_IBM_297,
STRING_ENCODING_IBM_420,
STRING_ENCODING_IBM_423,
STRING_ENCODING_IBM_424,
STRING_ENCODING_IBM_437,
STRING_ENCODING_IBM_500,
STRING_ENCODING_IBM_851,
STRING_ENCODING_IBM_852,
STRING_ENCODING_IBM_855,
STRING_ENCODING_IBM_857,
STRING_ENCODING_IBM_860,
STRING_ENCODING_IBM_861,
STRING_ENCODING_IBM_863,
STRING_ENCODING_IBM_864,
STRING_ENCODING_IBM_865,
STRING_ENCODING_IBM_868,
STRING_ENCODING_IBM_869,
STRING_ENCODING_IBM_870,
STRING_ENCODING_IBM_871,
STRING_ENCODING_IBM_880,
STRING_ENCODING_IBM_891,
STRING_ENCODING_IBM_903,
STRING_ENCODING_IBM_904,
STRING_ENCODING_IBM_905,
STRING_ENCODING_IBM_918,
STRING_ENCODING_IBM_1026,
STRING_ENCODING_EBCDIC_AT_DE,
STRING_ENCODING_EBCDIC_AT_DE_A,
STRING_ENCODING_EBCDIC_CA_FR,
STRING_ENCODING_EBCDIC_DK_NO,
STRING_ENCODING_EBCDIC_DK_NO_A,
STRING_ENCODING_EBCDIC_FI_SE,
STRING_ENCODING_EBCDIC_FI_SE_A,
STRING_ENCODING_EBCDIC_FR,
STRING_ENCODING_EBCDIC_IT,
STRING_ENCODING_EBCDIC_PT,
STRING_ENCODING_EBCDIC_ES,
STRING_ENCODING_EBCDIC_ES_A,
STRING_ENCODING_EBCDIC_ES_S,
STRING_ENCODING_EBCDIC_UK,
STRING_ENCODING_EBCDIC_US,
STRING_ENCODING_UNKNOWN_8BIT,
STRING_ENCODING_MNEMONIC,
STRING_ENCODING_MNEM,
STRING_ENCODING_VISCII,
STRING_ENCODING_VIQR,
STRING_ENCODING_KOI8_R,
STRING_ENCODING_HZ_GB_2312,
STRING_ENCODING_IBM_866,
STRING_ENCODING_IBM_775,
STRING_ENCODING_KOI8_U,
STRING_ENCODING_IBM_00858,
STRING_ENCODING_IBM_00924,
STRING_ENCODING_IBM_01140,
STRING_ENCODING_IBM_01141,
STRING_ENCODING_IBM_01142,
STRING_ENCODING_IBM_01143,
STRING_ENCODING_IBM_01144,
STRING_ENCODING_IBM_01145,
STRING_ENCODING_IBM_01146,
STRING_ENCODING_IBM_01147,
STRING_ENCODING_IBM_01148,
STRING_ENCODING_IBM_01149,
STRING_ENCODING_IBM_1047,
STRING_ENCODING_PTCP154,
STRING_ENCODING_AMIGA_1251,
STRING_ENCODING_KOI7_SWITCHED,
STRING_ENCODING_BRF,
STRING_ENCODING_TSCII,
STRING_ENCODING_TIS_620,
STRING_ENCODING_WINDOWS_709,
STRING_ENCODING_WINDOWS_710,
STRING_ENCODING_WINDOWS_720,
STRING_ENCODING_WINDOWS_737,
STRING_ENCODING_WINDOWS_875,
STRING_ENCODING_WINDOWS_1361,
STRING_ENCODING_WINDOWS_10000,
STRING_ENCODING_WINDOWS_10001,
STRING_ENCODING_WINDOWS_10002,
STRING_ENCODING_WINDOWS_10003,
STRING_ENCODING_WINDOWS_10004,
STRING_ENCODING_WINDOWS_10005,
STRING_ENCODING_WINDOWS_10006,
STRING_ENCODING_WINDOWS_10007,
STRING_ENCODING_WINDOWS_10008,
STRING_ENCODING_WINDOWS_10010,
STRING_ENCODING_WINDOWS_10017,
STRING_ENCODING_WINDOWS_10021,
STRING_ENCODING_WINDOWS_10029,
STRING_ENCODING_WINDOWS_10079,
STRING_ENCODING_WINDOWS_10081,
STRING_ENCODING_WINDOWS_10082,
STRING_ENCODING_WINDOWS_20000,
STRING_ENCODING_WINDOWS_20001,
STRING_ENCODING_WINDOWS_20002,
STRING_ENCODING_WINDOWS_20003,
STRING_ENCODING_WINDOWS_20004,
STRING_ENCODING_WINDOWS_20005,
STRING_ENCODING_WINDOWS_20105,
STRING_ENCODING_WINDOWS_20106,
STRING_ENCODING_WINDOWS_20107,
STRING_ENCODING_WINDOWS_20108,
STRING_ENCODING_WINDOWS_20269,
STRING_ENCODING_WINDOWS_20833,
STRING_ENCODING_WINDOWS_20949,
STRING_ENCODING_WINDOWS_21025,
STRING_ENCODING_WINDOWS_21027,
STRING_ENCODING_WINDOWS_29001,
STRING_ENCODING_WINDOWS_38598,
STRING_ENCODING_WINDOWS_50221,
STRING_ENCODING_WINDOWS_50222,
STRING_ENCODING_WINDOWS_50229,
STRING_ENCODING_WINDOWS_50930,
STRING_ENCODING_WINDOWS_50931,
STRING_ENCODING_WINDOWS_50933,
STRING_ENCODING_WINDOWS_50935,
STRING_ENCODING_WINDOWS_50936,
STRING_ENCODING_WINDOWS_50937,
STRING_ENCODING_WINDOWS_50939,
STRING_ENCODING_WINDOWS_51936,
STRING_ENCODING_WINDOWS_51950,
STRING_ENCODING_WINDOWS_57002,
STRING_ENCODING_WINDOWS_57003,
STRING_ENCODING_WINDOWS_57004,
STRING_ENCODING_WINDOWS_57005,
STRING_ENCODING_WINDOWS_57006,
STRING_ENCODING_WINDOWS_57007,
STRING_ENCODING_WINDOWS_57008,
STRING_ENCODING_WINDOWS_57009,
STRING_ENCODING_WINDOWS_57010,
STRING_ENCODING_WINDOWS_57011,
STRING_ENCODING_IBM_813,
STRING_ENCODING_IBM_943_P130_1999,
STRING_ENCODING_IBM_33722,
STRING_ENCODING_WINDOWS_949,
STRING_ENCODING_IBM_1363,
STRING_ENCODING_IBM_1386,
STRING_ENCODING_IBM_1373,
STRING_ENCODING_IBM_5471,
STRING_ENCODING_IBM_874,
// Add more encodings here.
// Sentinel value after the last explicitly specified encoding.
STRING_ENCODING_MAX_SPECIFIED,
/*
* The environment-specified "default" encoding for this process.
*/
STRING_ENCODING_DEFAULT = -1,
STRING_ENCODING_UNKNOWN = -2,
/*
* UTF-16 and UTF-32 in native byte order.
*/
STRING_ENCODING_UTF16 = STRING_ENCODING_UTF16_LE,
STRING_ENCODING_UTF32 = STRING_ENCODING_UTF32_LE,
} StringEncoding;
const char *Unicode_EncodingEnumToName(StringEncoding encoding);
StringEncoding Unicode_EncodingNameToEnum(const char *encodingName);
Bool Unicode_IsEncodingValid(StringEncoding encoding);
void Unicode_Init(int argc, char ***argv, char ***envp);
void Unicode_InitEx(int argc, char ***argv, char ***envp,
const char *icuDataDir);
#if defined (_WIN32)
void Unicode_InitW(int argc, utf16_t **wargv, utf16_t **wenvp,
char ***argv, char ***envp);
#endif
StringEncoding Unicode_GetCurrentEncoding(void);
StringEncoding Unicode_ResolveEncoding(StringEncoding encoding);
#ifdef __cplusplus
}
#endif
#endif // _UNICODE_TYPES_H_

694
vendor/github.com/sigma/vmw-guestinfo/include/util.h generated vendored Normal file
View File

@@ -0,0 +1,694 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* util.h --
*
* misc util functions
*/
#ifndef UTIL_H
#define UTIL_H
#include <stdarg.h>
#include <string.h>
#ifndef VMKBOOT
#include <stdlib.h>
#endif
#ifdef _WIN32
#ifdef USERLEVEL
#include <tchar.h> /* Needed for MBCS string functions */
#include <windows.h> /* for definition of HANDLE */
#endif
#else
#include <sys/types.h>
#include "errno.h"
#endif
#include "vm_assert.h"
#include "vm_basic_defs.h"
#include "unicodeTypes.h"
/*
* Define the Util_ThreadID type, and assorted standard bits.
*/
#if defined(_WIN32)
typedef DWORD Util_ThreadID;
#else
#include <unistd.h>
#if defined(__APPLE__) || defined(__FreeBSD__)
#include <pthread.h>
typedef pthread_t Util_ThreadID;
#else // Linux et al
typedef pid_t Util_ThreadID;
#endif
#endif
uint32 CRC_Compute(const uint8 *buf, int len);
uint32 Util_Checksum32(const uint32 *buf, int len);
uint32 Util_Checksum(const uint8 *buf, int len);
uint32 Util_Checksumv(void *iov, int numEntries);
uint32 Util_HashString(const char *str);
Unicode Util_ExpandString(ConstUnicode fileName);
void Util_ExitThread(int);
NORETURN void Util_ExitProcessAbruptly(int);
int Util_HasAdminPriv(void);
#if defined _WIN32 && defined USERLEVEL
int Util_TokenHasAdminPriv(HANDLE token);
int Util_TokenHasInteractPriv(HANDLE token);
#endif
Bool Util_Data2Buffer(char *buf, size_t bufSize, const void *data0,
size_t dataSize);
char *Util_GetCanonicalPath(const char *path);
#ifdef _WIN32
char *Util_CompatGetCanonicalPath(const char *path);
char *Util_GetCanonicalPathForHash(const char *path);
char *Util_CompatGetLowerCaseCanonicalPath(const char* path);
#endif
int Util_BumpNoFds(uint32 *cur, uint32 *wanted);
Bool Util_CanonicalPathsIdentical(const char *path1, const char *path2);
Bool Util_IsAbsolutePath(const char *path);
unsigned Util_GetPrime(unsigned n0);
Util_ThreadID Util_GetCurrentThreadId(void);
char *Util_DeriveFileName(const char *source,
const char *name,
const char *ext);
char *Util_CombineStrings(char **sources, int count);
char **Util_SeparateStrings(char *source, int *count);
typedef struct UtilSingleUseResource UtilSingleUseResource;
UtilSingleUseResource *Util_SingleUseAcquire(const char *name);
void Util_SingleUseRelease(UtilSingleUseResource *res);
#ifndef _WIN32
Bool Util_IPv4AddrValid(const char *addr);
Bool Util_IPv6AddrValid(const char *addr);
Bool Util_IPAddrValid(const char *addr);
#endif
#if defined(__linux__) || defined(__FreeBSD__) || defined(sun)
Bool Util_GetProcessName(pid_t pid, char *bufOut, size_t bufOutSize);
#endif
#if defined __linux__ && !defined VMX86_SERVER
Bool Util_IsPhysicalSSD(const char* device);
#endif
// backtrace functions and utilities
#define UTIL_BACKTRACE_LINE_LEN (511)
typedef void (*Util_OutputFunc)(void *data, const char *fmt, ...);
void Util_Backtrace(int bugNr);
void Util_BacktraceFromPointer(uintptr_t *basePtr);
void Util_BacktraceFromPointerWithFunc(uintptr_t *basePtr,
Util_OutputFunc outFunc,
void *outFuncData);
void Util_BacktraceWithFunc(int bugNr,
Util_OutputFunc outFunc,
void *outFuncData);
void Util_BacktraceToBuffer(uintptr_t *basePtr,
uintptr_t *buffer, int len);
// sleep functions
void Util_Usleep(long usec);
void Util_Sleep(unsigned int sec);
int Util_CompareDotted(const char *s1, const char *s2);
/*
* This enum defines how Util_GetOpt should handle non-option arguments:
*
* UTIL_NONOPT_PERMUTE: Permute argv so that all non-options are at the end.
* UTIL_NONOPT_STOP: Stop when first non-option argument is seen.
* UTIL_NONOPT_ALL: Return each non-option argument as if it were
* an option with character code 1.
*/
typedef enum { UTIL_NONOPT_PERMUTE, UTIL_NONOPT_STOP, UTIL_NONOPT_ALL } Util_NonOptMode;
struct option;
int Util_GetOpt(int argc, char * const *argv, const struct option *opts,
Util_NonOptMode mode);
#if defined(VMX86_STATS)
Bool Util_QueryCStResidency(uint32 *numCpus, uint32 *numCStates,
uint64 **transitns, uint64 **residency,
uint64 **transTime, uint64 **residTime);
#endif
/*
* In util_shared.h
*/
#define UTIL_FASTRAND_SEED_MAX (0x7fffffff)
Bool Util_Throttle(uint32 count);
uint32 Util_FastRand(uint32 seed);
// Not thread safe!
void Util_OverrideHomeDir(const char *path);
/*
*-----------------------------------------------------------------------------
*
* Util_ValidateBytes --
*
* Check that memory is filled with the specified value.
*
* Results:
* NULL No error
* !NULL First address that doesn't have the proper value
*
* Side effects:
* None.
*
*-----------------------------------------------------------------------------
*/
static INLINE void *
Util_ValidateBytes(const void *ptr, // IN: ptr to check
size_t size, // IN: size of ptr
uint8 byteValue) // IN: memory must be filled with this
{
uint8 *p;
uint8 *end;
uint64 bigValue;
ASSERT(ptr);
if (size == 0) {
return NULL;
}
p = (uint8 *) ptr;
end = p + size;
/* Compare bytes until a "nice" boundary is achieved. */
while ((uintptr_t) p % sizeof bigValue) {
if (*p != byteValue) {
return p;
}
p++;
if (p == end) {
return NULL;
}
}
/* Compare using a "nice sized" chunk for a long as possible. */
memset(&bigValue, (int) byteValue, sizeof bigValue);
while (p + sizeof bigValue <= end) {
if (*((uint64 *) p) != bigValue) {
/* That's not right... let the loop below report the exact address. */
break;
}
size -= sizeof bigValue;
p += sizeof bigValue;
}
/* Handle any trailing bytes. */
while (p < end) {
if (*p != byteValue) {
return p;
}
p++;
}
return NULL;
}
/*
*----------------------------------------------------------------------
*
* Util_BufferIsEmpty --
*
* Determine if the specified buffer of 'len' bytes starting at 'base'
* is empty (i.e. full of zeroes).
*
* Results:
* TRUE Yes
* FALSE No
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static INLINE Bool
Util_BufferIsEmpty(void const *base, // IN:
size_t len) // IN:
{
return Util_ValidateBytes(base, len, '\0') == NULL;
}
Bool Util_MakeSureDirExistsAndAccessible(char const *path,
unsigned int mode);
#if _WIN32
# define DIRSEPS "\\"
# define DIRSEPS_W L"\\"
# define DIRSEPC '\\'
# define DIRSEPC_W L'\\'
# define VALID_DIRSEPS "\\/"
# define VALID_DIRSEPS_W L"\\/"
# define CUR_DIRS_W L"."
# define CUR_DIRC_W L'.'
#else
# define DIRSEPS "/"
# define DIRSEPC '/'
# define VALID_DIRSEPS DIRSEPS
#endif
#define CURR_DIRS "."
#define CURR_DIRC '.'
/*
*-----------------------------------------------------------------------
*
* Util_Safe[Malloc, Realloc, Calloc, Strdup] and
* Util_Safe[Malloc, Realloc, Calloc, Strdup]Bug --
*
* These functions work just like the standard C library functions
* (except Util_SafeStrdup[,Bug]() accept NULL, see below),
* but will not fail. Instead they Panic(), printing the file and
* line number of the caller, if the underlying library function
* fails. The Util_SafeFnBug functions print bugNumber in the
* Panic() message.
*
* These functions should only be used when there is no way to
* gracefully recover from the error condition.
*
* The internal versions of these functions expect a bug number
* as the first argument. If that bug number is something other
* than -1, the panic message will include the bug number.
*
* Since Util_SafeStrdup[,Bug]() do not need to return NULL
* on error, they have been extended to accept the null pointer
* (and return it). The competing view is that they should
* panic on NULL. This is a convenience vs. strictness argument.
* Convenience wins. -- edward
*
* Results:
* The freshly allocated memory.
*
* Side effects:
* Panic() if the library function fails.
*
*--------------------------------------------------------------------------
*/
void *UtilSafeMalloc0(size_t size);
void *UtilSafeMalloc1(size_t size,
int bugNumber, const char *file, int lineno);
void *UtilSafeRealloc0(void *ptr, size_t size);
void *UtilSafeRealloc1(void *ptr, size_t size,
int bugNumber, const char *file, int lineno);
void *UtilSafeCalloc0(size_t nmemb, size_t size);
void *UtilSafeCalloc1(size_t nmemb, size_t size,
int bugNumber, const char *file, int lineno);
char *UtilSafeStrdup0(const char *s);
char *UtilSafeStrdup1(const char *s,
int bugNumber, const char *file, int lineno);
char *UtilSafeStrndup0(const char *s, size_t n);
char *UtilSafeStrndup1(const char *s, size_t n,
int bugNumber, const char *file, int lineno);
/*
* Debug builds carry extra arguments into the allocation functions for
* better error reporting. Non-debug builds don't pay this extra overhead.
*/
#ifdef VMX86_DEBUG
#define Util_SafeMalloc(_size) \
UtilSafeMalloc1((_size), -1, __FILE__, __LINE__)
#define Util_SafeMallocBug(_bugNr, _size) \
UtilSafeMalloc1((_size),(_bugNr), __FILE__, __LINE__)
#define Util_SafeRealloc(_ptr, _size) \
UtilSafeRealloc1((_ptr), (_size), -1, __FILE__, __LINE__)
#define Util_SafeReallocBug(_bugNr, _ptr, _size) \
UtilSafeRealloc1((_ptr), (_size), (_bugNr), __FILE__, __LINE__)
#define Util_SafeCalloc(_nmemb, _size) \
UtilSafeCalloc1((_nmemb), (_size), -1, __FILE__, __LINE__)
#define Util_SafeCallocBug(_bugNr, _nmemb, _size) \
UtilSafeCalloc1((_nmemb), (_size), (_bugNr), __FILE__, __LINE__)
#define Util_SafeStrndup(_str, _size) \
UtilSafeStrndup1((_str), (_size), -1, __FILE__, __LINE__)
#define Util_SafeStrndupBug(_bugNr, _str, _size) \
UtilSafeStrndup1((_str), (_size), (_bugNr), __FILE__, __LINE__)
#define Util_SafeStrdup(_str) \
UtilSafeStrdup1((_str), -1, __FILE__, __LINE__)
#define Util_SafeStrdupBug(_bugNr, _str) \
UtilSafeStrdup1((_str), (_bugNr), __FILE__, __LINE__)
#else /* VMX86_DEBUG */
#define Util_SafeMalloc(_size) \
UtilSafeMalloc0((_size))
#define Util_SafeMallocBug(_bugNr, _size) \
UtilSafeMalloc0((_size))
#define Util_SafeRealloc(_ptr, _size) \
UtilSafeRealloc0((_ptr), (_size))
#define Util_SafeReallocBug(_ptr, _size) \
UtilSafeRealloc0((_ptr), (_size))
#define Util_SafeCalloc(_nmemb, _size) \
UtilSafeCalloc0((_nmemb), (_size))
#define Util_SafeCallocBug(_bugNr, _nmemb, _size) \
UtilSafeCalloc0((_nmemb), (_size))
#define Util_SafeStrndup(_str, _size) \
UtilSafeStrndup0((_str), (_size))
#define Util_SafeStrndupBug(_bugNr, _str, _size) \
UtilSafeStrndup0((_str), (_size))
#define Util_SafeStrdup(_str) \
UtilSafeStrdup0((_str))
#define Util_SafeStrdupBug(_bugNr, _str) \
UtilSafeStrdup0((_str))
#endif /* VMX86_DEBUG */
void *Util_Memcpy(void *dest, const void *src, size_t count);
/*
*-----------------------------------------------------------------------------
*
* Util_Zero --
*
* Zeros out bufSize bytes of buf. NULL is legal.
*
* Results:
* None.
*
* Side effects:
* See above.
*
*-----------------------------------------------------------------------------
*/
static INLINE void
Util_Zero(void *buf, // OUT
size_t bufSize) // IN
{
if (buf != NULL) {
#if defined _WIN32 && defined USERLEVEL
/*
* Simple memset calls might be optimized out. See CERT advisory
* MSC06-C.
*/
SecureZeroMemory(buf, bufSize);
#else
memset(buf, 0, bufSize);
#if !defined _WIN32
/*
* Memset calls before free might be optimized out. See PR1248269.
*/
__asm__ __volatile__("" : : "r"(&buf) : "memory");
#endif
#endif
}
}
/*
*-----------------------------------------------------------------------------
*
* Util_ZeroString --
*
* Zeros out a NULL-terminated string. NULL is legal.
*
* Results:
* None.
*
* Side effects:
* See above.
*
*-----------------------------------------------------------------------------
*/
static INLINE void
Util_ZeroString(char *str) // IN/OUT
{
if (str != NULL) {
Util_Zero(str, strlen(str));
}
}
#ifndef VMKBOOT
/*
*-----------------------------------------------------------------------------
*
* Util_ZeroFree --
*
* Zeros out bufSize bytes of buf, and then frees it. NULL is
* legal.
*
* Results:
* None.
*
* Side effects:
* buf is zeroed, and then free() is called on it.
*
*-----------------------------------------------------------------------------
*/
static INLINE void
Util_ZeroFree(void *buf, // OUT
size_t bufSize) // IN
{
if (buf != NULL) {
Util_Zero(buf, bufSize);
free(buf);
}
}
/*
*-----------------------------------------------------------------------------
*
* Util_ZeroFreeString --
*
* Zeros out a NULL-terminated string, and then frees it. NULL is
* legal.
*
* Results:
* None.
*
* Side effects:
* str is zeroed, and then free() is called on it.
*
*-----------------------------------------------------------------------------
*/
static INLINE void
Util_ZeroFreeString(char *str) // IN
{
if (str != NULL) {
Util_ZeroString(str);
free(str);
}
}
#ifdef _WIN32
/*
*-----------------------------------------------------------------------------
*
* Util_ZeroFreeStringW --
*
* Zeros out a NUL-terminated wide-character string, and then frees it.
* NULL is legal.
*
* Results:
* None.
*
* Side effects:
* str is zeroed, and then free() is called on it.
*
*-----------------------------------------------------------------------------
*/
static INLINE void
Util_ZeroFreeStringW(wchar_t *str) // IN
{
if (str != NULL) {
Util_Zero(str, wcslen(str) * sizeof *str);
free(str);
}
}
#endif // _WIN32
/*
*-----------------------------------------------------------------------------
*
* Util_FreeList --
* Util_FreeStringList --
*
* Free a list (actually a vector) of allocated objects.
* The list (vector) itself is also freed.
*
* The list either has a specified length or is
* argv-style NULL terminated (if length is negative).
*
* The list can be NULL, in which case no operation is performed.
*
* Results:
* None
*
* Side effects:
* errno or Windows last error is preserved.
*
*-----------------------------------------------------------------------------
*/
static INLINE void
Util_FreeList(void **list, // IN/OUT: the list to free
ssize_t length) // IN: the length
{
if (list == NULL) {
ASSERT(length <= 0);
return;
}
if (length >= 0) {
ssize_t i;
for (i = 0; i < length; i++) {
free(list[i]);
DEBUG_ONLY(list[i] = NULL);
}
} else {
void **s;
for (s = list; *s != NULL; s++) {
free(*s);
DEBUG_ONLY(*s = NULL);
}
}
free(list);
}
static INLINE void
Util_FreeStringList(char **list, // IN/OUT: the list to free
ssize_t length) // IN: the length
{
Util_FreeList((void **) list, length);
}
#endif
#ifndef _WIN32
/*
*-----------------------------------------------------------------------------
*
* Util_IsFileDescriptorOpen --
*
* Check if given file descriptor is open.
*
* Results:
* TRUE if fd is open.
*
* Side effects:
* Clobbers errno.
*
*-----------------------------------------------------------------------------
*/
static INLINE Bool
Util_IsFileDescriptorOpen(int fd) // IN
{
return (lseek(fd, 0L, SEEK_CUR) == -1) ? errno != EBADF : TRUE;
}
#endif /* !_WIN32 */
/*
*-----------------------------------------------------------------------------
*
* Util_Memcpy32 --
*
* Special purpose version of memcpy that requires nbytes be a
* multiple of 4. This assumption lets us have a very small,
* inlineable implementation.
*
* Results:
* dst
*
* Side effects:
* See above.
*
*-----------------------------------------------------------------------------
*/
static INLINE void *
Util_Memcpy32(void *dst, const void *src, size_t nbytes)
{
ASSERT((nbytes % 4) == 0);
#if defined __GNUC__ && (defined(__i386__) || defined(__x86_64__))
do {
int dummy0, dummy1, dummy2;
__asm__ __volatile__(
"cld \n\t"
"rep ; movsl" "\n\t"
: "=&c" (dummy0), "=&D" (dummy1), "=&S" (dummy2)
: "0" (nbytes / 4), "1" ((long) dst), "2" ((long) src)
: "memory", "cc"
);
return dst;
} while (0);
#else
return memcpy(dst, src, nbytes);
#endif
}
#endif /* UTIL_H */

View File

@@ -0,0 +1,359 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* vm_assert.h --
*
* The basic assertion facility for all VMware code.
*
* For proper use, see bora/doc/assert and
* http://vmweb.vmware.com/~mts/WebSite/guide/programming/asserts.html.
*/
#ifndef _VM_ASSERT_H_
#define _VM_ASSERT_H_
// XXX not necessary except some places include vm_assert.h improperly
#include "vm_basic_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Some bits of vmcore are used in VMKernel code and cannot have
* the VMKERNEL define due to other header dependencies.
*/
#if defined(VMKERNEL) && !defined(VMKPANIC)
#define VMKPANIC 1
#endif
/*
* Internal macros, functions, and strings
*
* The monitor wants to save space at call sites, so it has specialized
* functions for each situation. User level wants to save on implementation
* so it uses generic functions.
*/
#if !defined VMM || defined MONITOR_APP // {
#if defined VMKPANIC
#include "vmk_assert.h"
#else /* !VMKPANIC */
#define _ASSERT_PANIC(name) \
Panic(_##name##Fmt "\n", __FILE__, __LINE__)
#define _ASSERT_PANIC_BUG(bug, name) \
Panic(_##name##Fmt " bugNr=%d\n", __FILE__, __LINE__, bug)
#define _ASSERT_PANIC_NORETURN(name) \
Panic(_##name##Fmt "\n", __FILE__, __LINE__)
#define _ASSERT_PANIC_BUG_NORETURN(bug, name) \
Panic(_##name##Fmt " bugNr=%d\n", __FILE__, __LINE__, bug)
#endif /* VMKPANIC */
#endif // }
// These strings don't have newline so that a bug can be tacked on.
#define _AssertPanicFmt "PANIC %s:%d"
#define _AssertAssertFmt "ASSERT %s:%d"
#define _AssertVerifyFmt "VERIFY %s:%d"
#define _AssertNotImplementedFmt "NOT_IMPLEMENTED %s:%d"
#define _AssertNotReachedFmt "NOT_REACHED %s:%d"
#define _AssertMemAllocFmt "MEM_ALLOC %s:%d"
#define _AssertNotTestedFmt "NOT_TESTED %s:%d"
/*
* Panic and log functions
*/
void Log(const char *fmt, ...) PRINTF_DECL(1, 2);
void Warning(const char *fmt, ...) PRINTF_DECL(1, 2);
#if defined VMKPANIC
void Panic_SaveRegs(void);
#ifdef VMX86_DEBUG
void Panic_NoSave(const char *fmt, ...) PRINTF_DECL(1, 2);
#else
NORETURN void Panic_NoSave(const char *fmt, ...) PRINTF_DECL(1, 2);
#endif
NORETURN void Panic_NoSaveNoReturn(const char *fmt, ...) PRINTF_DECL(1, 2);
#define Panic(fmt...) do { \
Panic_SaveRegs(); \
Panic_NoSave(fmt); \
} while(0)
#define Panic_NoReturn(fmt...) do { \
Panic_SaveRegs(); \
Panic_NoSaveNoReturn(fmt); \
} while(0)
#else
NORETURN void Panic(const char *fmt, ...) PRINTF_DECL(1, 2);
#endif
void LogThrottled(uint32 *count, const char *fmt, ...) PRINTF_DECL(2, 3);
void WarningThrottled(uint32 *count, const char *fmt, ...) PRINTF_DECL(2, 3);
#ifndef ASSERT_IFNOT
/*
* PR 271512: When compiling with gcc, catch assignments inside an ASSERT.
*
* 'UNLIKELY' is defined with __builtin_expect, which does not warn when
* passed an assignment (gcc bug 36050). To get around this, we put 'cond'
* in an 'if' statement and make sure it never gets executed by putting
* that inside of 'if (0)'. We use gcc's statement expression syntax to
* make ASSERT an expression because some code uses it that way.
*
* Since statement expression syntax is a gcc extension and since it's
* not clear if this is a problem with other compilers, the ASSERT
* definition was not changed for them. Using a bare 'cond' with the
* ternary operator may provide a solution.
*/
#ifdef __GNUC__
#define ASSERT_IFNOT(cond, panic) \
({if (UNLIKELY(!(cond))) { panic; if (0) { if (cond) {;}}} (void)0;})
#else
#define ASSERT_IFNOT(cond, panic) \
(UNLIKELY(!(cond)) ? (panic) : (void)0)
#endif
#endif
/*
* Assert, panic, and log macros
*
* Some of these are redefined below undef !VMX86_DEBUG.
* ASSERT() is special cased because of interaction with Windows DDK.
*/
#if defined VMX86_DEBUG
#undef ASSERT
#define ASSERT(cond) ASSERT_IFNOT(cond, _ASSERT_PANIC(AssertAssert))
#define ASSERT_BUG(bug, cond) \
ASSERT_IFNOT(cond, _ASSERT_PANIC_BUG(bug, AssertAssert))
#endif
#undef VERIFY
#define VERIFY(cond) \
ASSERT_IFNOT(cond, _ASSERT_PANIC_NORETURN(AssertVerify))
#define VERIFY_BUG(bug, cond) \
ASSERT_IFNOT(cond, _ASSERT_PANIC_BUG_NORETURN(bug, AssertVerify))
#define PANIC() _ASSERT_PANIC(AssertPanic)
#define PANIC_BUG(bug) _ASSERT_PANIC_BUG(bug, AssertPanic)
#define ASSERT_NOT_IMPLEMENTED(cond) \
ASSERT_IFNOT(cond, NOT_IMPLEMENTED())
#define ASSERT_NOT_IMPLEMENTED_BUG(bug, cond) \
ASSERT_IFNOT(cond, NOT_IMPLEMENTED_BUG(bug))
#if defined VMKPANIC || defined VMM
#define NOT_IMPLEMENTED() _ASSERT_PANIC_NORETURN(AssertNotImplemented)
#else
#define NOT_IMPLEMENTED() _ASSERT_PANIC(AssertNotImplemented)
#endif
#if defined VMM
#define NOT_IMPLEMENTED_BUG(bug) \
_ASSERT_PANIC_BUG_NORETURN(bug, AssertNotImplemented)
#else
#define NOT_IMPLEMENTED_BUG(bug) _ASSERT_PANIC_BUG(bug, AssertNotImplemented)
#endif
#if defined VMKPANIC || defined VMM
#define NOT_REACHED() _ASSERT_PANIC_NORETURN(AssertNotReached)
#else
#define NOT_REACHED() _ASSERT_PANIC(AssertNotReached)
#endif
#define ASSERT_MEM_ALLOC(cond) \
ASSERT_IFNOT(cond, _ASSERT_PANIC(AssertMemAlloc))
#ifdef VMX86_DEVEL
#define ASSERT_DEVEL(cond) ASSERT(cond)
#define NOT_TESTED() Warning(_AssertNotTestedFmt "\n", __FILE__, __LINE__)
#else
#define ASSERT_DEVEL(cond) ((void)0)
#define NOT_TESTED() Log(_AssertNotTestedFmt "\n", __FILE__, __LINE__)
#endif
#define ASSERT_NO_INTERRUPTS() ASSERT(!INTERRUPTS_ENABLED())
#define ASSERT_HAS_INTERRUPTS() ASSERT(INTERRUPTS_ENABLED())
#define ASSERT_NOT_TESTED(cond) (UNLIKELY(!(cond)) ? NOT_TESTED() : (void)0)
#define NOT_TESTED_ONCE() DO_ONCE(NOT_TESTED())
#define NOT_TESTED_1024() \
do { \
static uint16 count = 0; \
if (UNLIKELY(count == 0)) { NOT_TESTED(); } \
count = (count + 1) & 1023; \
} while (0)
#define LOG_ONCE(_s) DO_ONCE(Log _s)
/*
* Redefine macros that are only in debug versions
*/
#if !defined VMX86_DEBUG // {
#undef ASSERT
#define ASSERT(cond) ((void)0)
#define ASSERT_BUG(bug, cond) ((void)0)
/*
* Expand NOT_REACHED() as appropriate for each situation.
*
* Mainly, we want the compiler to infer the same control-flow
* information as it would from Panic(). Otherwise, different
* compilation options will lead to different control-flow-derived
* errors, causing some make targets to fail while others succeed.
*
* VC++ has the __assume() built-in function which we don't trust
* (see bug 43485); gcc has no such construct; we just panic in
* userlevel code. The monitor doesn't want to pay the size penalty
* (measured at 212 bytes for the release vmm for a minimal infinite
* loop; panic would cost even more) so it does without and lives
* with the inconsistency.
*/
#if defined VMKPANIC || defined VMM
#undef NOT_REACHED
#if defined __GNUC__ && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define NOT_REACHED() (__builtin_unreachable())
#else
#define NOT_REACHED() ((void)0)
#endif
#else
// keep debug definition
#endif
#undef LOG_UNEXPECTED
#define LOG_UNEXPECTED(bug) ((void)0)
#undef ASSERT_NOT_TESTED
#define ASSERT_NOT_TESTED(cond) ((void)0)
#undef NOT_TESTED
#define NOT_TESTED() ((void)0)
#undef NOT_TESTED_ONCE
#define NOT_TESTED_ONCE() ((void)0)
#undef NOT_TESTED_1024
#define NOT_TESTED_1024() ((void)0)
#endif // !VMX86_DEBUG }
/*
* Compile-time assertions.
*
* ASSERT_ON_COMPILE does not use the common
* switch (0) { case 0: case (e): ; } trick because some compilers (e.g. MSVC)
* generate code for it.
*
* The implementation uses both enum and typedef because the typedef alone is
* insufficient; gcc allows arrays to be declared with non-constant expressions
* (even in typedefs, where it makes no sense).
*
* NOTE: if GCC ever changes so that it ignores unused types altogether, this
* assert might not fire! We explicitly mark it as unused because GCC 4.8+
* uses -Wunused-local-typedefs as part of -Wall, which means the typedef will
* generate a warning.
*/
#define ASSERT_ON_COMPILE(e) \
do { \
enum { AssertOnCompileMisused = ((e) ? 1 : -1) }; \
UNUSED_TYPE(typedef char AssertOnCompileFailed[AssertOnCompileMisused]); \
} while (0)
/*
* To put an ASSERT_ON_COMPILE() outside a function, wrap it
* in MY_ASSERTS(). The first parameter must be unique in
* each .c file where it appears. For example,
*
* MY_ASSERTS(FS3_INT,
* ASSERT_ON_COMPILE(sizeof(FS3_DiskLock) == 128);
* ASSERT_ON_COMPILE(sizeof(FS3_DiskLockReserved) == DISK_BLOCK_SIZE);
* ASSERT_ON_COMPILE(sizeof(FS3_DiskBlock) == DISK_BLOCK_SIZE);
* ASSERT_ON_COMPILE(sizeof(Hardware_DMIUUID) == 16);
* )
*
* Caution: ASSERT() within MY_ASSERTS() is silently ignored.
* The same goes for anything else not evaluated at compile time.
*/
#define MY_ASSERTS(name, assertions) \
static INLINE void name(void) { \
assertions \
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* ifndef _VM_ASSERT_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,553 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* vm_basic_asm_x86.h
*
* Basic IA32 asm macros
*/
#ifndef _VM_BASIC_ASM_X86_H_
#define _VM_BASIC_ASM_X86_H_
#ifdef VM_X86_64
/*
* The gcc inline asm uses the "A" constraint which differs in 32 & 64
* bit mode. 32 bit means eax and edx, 64 means rax or rdx.
*/
#error "x86-64 not supported"
#endif
/*
* XTEST
* Return TRUE if processor is in transaction region.
*
*/
#if defined(__GNUC__) && (defined(VMM) || defined(VMKERNEL) || defined(FROBOS))
static INLINE Bool
xtest(void)
{
uint8 al;
__asm__ __volatile__(".byte 0x0f, 0x01, 0xd6 # xtest \n"
"setnz %%al\n"
: "=a"(al) : : "cc");
return al;
}
#endif /* __GNUC__ */
/*
* FXSAVE/FXRSTOR
* save/restore SIMD/MMX fpu state
*
* The pointer passed in must be 16-byte aligned.
*
* Intel and AMD processors behave differently w.r.t. fxsave/fxrstor. Intel
* processors unconditionally save the exception pointer state (instruction
* ptr., data ptr., and error instruction opcode). FXSAVE_ES1 and FXRSTOR_ES1
* work correctly for Intel processors.
*
* AMD processors only save the exception pointer state if ES=1. This leads to a
* security hole whereby one process/VM can inspect the state of another process
* VM. The AMD recommended workaround involves clobbering the exception pointer
* state unconditionally, and this is implemented in FXRSTOR_AMD_ES0. Note that
* FXSAVE_ES1 will only save the exception pointer state for AMD processors if
* ES=1.
*
* The workaround (FXRSTOR_AMD_ES0) only costs 1 cycle more than just doing an
* fxrstor, on both AMD Opteron and Intel Core CPUs.
*/
#if defined(__GNUC__)
static INLINE void
FXSAVE_ES1(void *save)
{
__asm__ __volatile__ ("fxsave %0\n" : "=m" (*(uint8 *)save) : : "memory");
}
static INLINE void
FXRSTOR_ES1(const void *load)
{
__asm__ __volatile__ ("fxrstor %0\n"
: : "m" (*(const uint8 *)load) : "memory");
}
static INLINE void
FXRSTOR_AMD_ES0(const void *load)
{
uint64 dummy = 0;
__asm__ __volatile__
("fnstsw %%ax \n" // Grab x87 ES bit
"bt $7,%%ax \n" // Test ES bit
"jnc 1f \n" // Jump if ES=0
"fnclex \n" // ES=1. Clear it so fild doesn't trap
"1: \n"
"ffree %%st(7) \n" // Clear tag bit - avoid poss. stack overflow
"fildl %0 \n" // Dummy Load from "safe address" changes all
// x87 exception pointers.
"fxrstor %1 \n"
:
: "m" (dummy), "m" (*(const uint8 *)load)
: "ax", "memory");
}
#endif /* __GNUC__ */
/*
* XSAVE/XRSTOR
* save/restore GSSE/SIMD/MMX fpu state
*
* The pointer passed in must be 64-byte aligned.
* See above comment for more information.
*/
#if defined(__GNUC__) && (defined(VMM) || defined(VMKERNEL) || defined(FROBOS))
static INLINE void
XSAVE_ES1(void *save, uint64 mask)
{
#if __GNUC__ < 4 || __GNUC__ == 4 && __GNUC_MINOR__ == 1
__asm__ __volatile__ (
".byte 0x0f, 0xae, 0x21 \n"
:
: "c" ((uint8 *)save), "a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#else
__asm__ __volatile__ (
"xsave %0 \n"
: "=m" (*(uint8 *)save)
: "a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#endif
}
static INLINE void
XSAVEOPT_ES1(void *save, uint64 mask)
{
__asm__ __volatile__ (
".byte 0x0f, 0xae, 0x31 \n"
:
: "c" ((uint8 *)save), "a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
}
static INLINE void
XRSTOR_ES1(const void *load, uint64 mask)
{
#if __GNUC__ < 4 || __GNUC__ == 4 && __GNUC_MINOR__ == 1
__asm__ __volatile__ (
".byte 0x0f, 0xae, 0x29 \n"
:
: "c" ((const uint8 *)load),
"a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#else
__asm__ __volatile__ (
"xrstor %0 \n"
:
: "m" (*(const uint8 *)load),
"a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#endif
}
static INLINE void
XRSTOR_AMD_ES0(const void *load, uint64 mask)
{
uint64 dummy = 0;
__asm__ __volatile__
("fnstsw %%ax \n" // Grab x87 ES bit
"bt $7,%%ax \n" // Test ES bit
"jnc 1f \n" // Jump if ES=0
"fnclex \n" // ES=1. Clear it so fild doesn't trap
"1: \n"
"ffree %%st(7) \n" // Clear tag bit - avoid poss. stack overflow
"fildl %0 \n" // Dummy Load from "safe address" changes all
// x87 exception pointers.
"mov %%ebx, %%eax \n"
#if __GNUC__ < 4 || __GNUC__ == 4 && __GNUC_MINOR__ == 1
".byte 0x0f, 0xae, 0x29 \n"
:
: "m" (dummy), "c" ((const uint8 *)load),
"b" ((uint32)mask), "d" ((uint32)(mask >> 32))
#else
"xrstor %1 \n"
:
: "m" (dummy), "m" (*(const uint8 *)load),
"b" ((uint32)mask), "d" ((uint32)(mask >> 32))
#endif
: "eax", "memory");
}
#endif /* __GNUC__ */
/*
*-----------------------------------------------------------------------------
*
* Div643232 --
*
* Unsigned integer division:
* The dividend is 64-bit wide
* The divisor is 32-bit wide
* The quotient is 32-bit wide
*
* Use this function if you are certain that:
* o Either the quotient will fit in 32 bits,
* o Or your code is ready to handle a #DE exception indicating overflow.
* If that is not the case, then use Div643264().
*
* Results:
* Quotient and remainder
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
#if defined(__GNUC__)
static INLINE void
Div643232(uint64 dividend, // IN
uint32 divisor, // IN
uint32 *quotient, // OUT
uint32 *remainder) // OUT
{
__asm__(
"divl %4"
: "=a" (*quotient),
"=d" (*remainder)
: "0" ((uint32)dividend),
"1" ((uint32)(dividend >> 32)),
"rm" (divisor)
: "cc"
);
}
#elif defined _MSC_VER
static INLINE void
Div643232(uint64 dividend, // IN
uint32 divisor, // IN
uint32 *quotient, // OUT
uint32 *remainder) // OUT
{
__asm {
mov eax, DWORD PTR [dividend]
mov edx, DWORD PTR [dividend+4]
div DWORD PTR [divisor]
mov edi, DWORD PTR [quotient]
mov [edi], eax
mov edi, DWORD PTR [remainder]
mov [edi], edx
}
}
#else
#error No compiler defined for Div643232
#endif
#if defined(__GNUC__)
/*
*-----------------------------------------------------------------------------
*
* Div643264 --
*
* Unsigned integer division:
* The dividend is 64-bit wide
* The divisor is 32-bit wide
* The quotient is 64-bit wide
*
* Results:
* Quotient and remainder
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
static INLINE void
Div643264(uint64 dividend, // IN
uint32 divisor, // IN
uint64 *quotient, // OUT
uint32 *remainder) // OUT
{
uint32 hQuotient;
uint32 lQuotient;
__asm__(
"divl %5" "\n\t"
"movl %%eax, %0" "\n\t"
"movl %4, %%eax" "\n\t"
"divl %5"
: "=&rm" (hQuotient),
"=a" (lQuotient),
"=d" (*remainder)
: "1" ((uint32)(dividend >> 32)),
"g" ((uint32)dividend),
"rm" (divisor),
"2" (0)
: "cc"
);
*quotient = (uint64)hQuotient << 32 | lQuotient;
}
#endif
/*
*-----------------------------------------------------------------------------
*
* Mul64x3264 --
*
* Unsigned integer by fixed point multiplication, with rounding:
* result = floor(multiplicand * multiplier * 2**(-shift) + 0.5)
*
* Unsigned 64-bit integer multiplicand.
* Unsigned 32-bit fixed point multiplier, represented as
* (multiplier, shift), where shift < 64.
*
* Result:
* Unsigned 64-bit integer product.
*
*-----------------------------------------------------------------------------
*/
#if defined(__GNUC__) && \
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) && \
!defined(MUL64_NO_ASM)
static INLINE uint64
Mul64x3264(uint64 multiplicand, uint32 multiplier, uint32 shift)
{
uint64 result;
uint32 tmp1, tmp2;
// ASSERT(shift >= 0 && shift < 64);
__asm__("mov %%eax, %2\n\t" // Save lo(multiplicand)
"mov %%edx, %%eax\n\t" // Get hi(multiplicand)
"mull %4\n\t" // p2 = hi(multiplicand) * multiplier
"xchg %%eax, %2\n\t" // Save lo(p2), get lo(multiplicand)
"mov %%edx, %1\n\t" // Save hi(p2)
"mull %4\n\t" // p1 = lo(multiplicand) * multiplier
"addl %2, %%edx\n\t" // hi(p1) += lo(p2)
"adcl $0, %1\n\t" // hi(p2) += carry from previous step
"cmpl $32, %%ecx\n\t" // shift < 32?
"jl 2f\n\t" // Go if so
"shll $1, %%eax\n\t" // Save lo(p1) bit 31 in CF in case shift=32
"mov %%edx, %%eax\n\t" // result = hi(p2):hi(p1) >> (shift & 31)
"mov %1, %%edx\n\t"
"shrdl %%edx, %%eax\n\t"
"mov $0, %2\n\t"
"adcl $0, %2\n\t" // Get highest order bit shifted out, from CF
"shrl %%cl, %%edx\n\t"
"jmp 3f\n"
"2:\n\t"
"xor %2, %2\n\t"
"shrdl %%edx, %%eax\n\t" // result = hi(p2):hi(p1):lo(p1) >> shift
"adcl $0, %2\n\t" // Get highest order bit shifted out, from CF
"shrdl %1, %%edx\n"
"3:\n\t"
"addl %2, %%eax\n\t" // result += highest order bit shifted out
"adcl $0, %%edx"
: "=A" (result), "=&r" (tmp1), "=&r" (tmp2)
: "0" (multiplicand), "rm" (multiplier), "c" (shift)
: "cc");
return result;
}
#elif defined _MSC_VER
#pragma warning(disable: 4035)
static INLINE uint64
Mul64x3264(uint64 multiplicand, uint32 multiplier, uint32 shift)
{
// ASSERT(shift >= 0 && shift < 64);
__asm {
mov eax, DWORD PTR [multiplicand+4] // Get hi(multiplicand)
mul DWORD PTR [multiplier] // p2 = hi(multiplicand) * multiplier
mov ecx, eax // Save lo(p2)
mov ebx, edx // Save hi(p2)
mov eax, DWORD PTR [multiplicand] // Get lo(multiplicand)
mul DWORD PTR [multiplier+0] // p1 = lo(multiplicand) * multiplier
add edx, ecx // hi(p1) += lo(p2)
adc ebx, 0 // hi(p2) += carry from previous step
mov ecx, DWORD PTR [shift] // Get shift
cmp ecx, 32 // shift < 32?
jl SHORT l2 // Go if so
shl eax, 1 // Save lo(p1) bit 31 in CF in case shift=32
mov eax, edx // result = hi(p2):hi(p1) >> (shift & 31)
mov edx, ebx
shrd eax, edx, cl
mov esi, 0
adc esi, 0 // Get highest order bit shifted out, from CF
shr edx, cl
jmp SHORT l3
l2:
xor esi, esi
shrd eax, edx, cl // result = hi(p2):hi(p1):lo(p1) >> shift
adc esi, 0 // Get highest order bit shifted out, from CF
shrd edx, ebx, cl
l3:
add eax, esi // result += highest order bit shifted out
adc edx, 0
}
// return with result in edx:eax
}
#pragma warning(default: 4035)
#else
#define MUL64_NO_ASM 1
#include "mul64.h"
#endif
/*
*-----------------------------------------------------------------------------
*
* Muls64x32s64 --
*
* Signed integer by fixed point multiplication, with rounding:
* result = floor(multiplicand * multiplier * 2**(-shift) + 0.5)
*
* Signed 64-bit integer multiplicand.
* Unsigned 32-bit fixed point multiplier, represented as
* (multiplier, shift), where shift < 64.
*
* Result:
* Signed 64-bit integer product.
*
*-----------------------------------------------------------------------------
*/
#if defined(__GNUC__) && \
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) && \
!defined(MUL64_NO_ASM)
static INLINE int64
Muls64x32s64(int64 multiplicand, uint32 multiplier, uint32 shift)
{
int64 result;
uint32 tmp1, tmp2;
// ASSERT(shift >= 0 && shift < 64);
__asm__("mov %%eax, %2\n\t" // Save lo(multiplicand)
"mov %%edx, %%eax\n\t" // Get hi(multiplicand)
"test %%eax, %%eax\n\t" // Check sign of multiplicand
"jl 0f\n\t" // Go if negative
"mull %4\n\t" // p2 = hi(multiplicand) * multiplier
"jmp 1f\n"
"0:\n\t"
"mull %4\n\t" // p2 = hi(multiplicand) * multiplier
"sub %4, %%edx\n" // hi(p2) += -1 * multiplier
"1:\n\t"
"xchg %%eax, %2\n\t" // Save lo(p2), get lo(multiplicand)
"mov %%edx, %1\n\t" // Save hi(p2)
"mull %4\n\t" // p1 = lo(multiplicand) * multiplier
"addl %2, %%edx\n\t" // hi(p1) += lo(p2)
"adcl $0, %1\n\t" // hi(p2) += carry from previous step
"cmpl $32, %%ecx\n\t" // shift < 32?
"jl 2f\n\t" // Go if so
"shll $1, %%eax\n\t" // Save lo(p1) bit 31 in CF in case shift=32
"mov %%edx, %%eax\n\t" // result = hi(p2):hi(p1) >> (shift & 31)
"mov %1, %%edx\n\t"
"shrdl %%edx, %%eax\n\t"
"mov $0, %2\n\t"
"adcl $0, %2\n\t" // Get highest order bit shifted out from CF
"sarl %%cl, %%edx\n\t"
"jmp 3f\n"
"2:\n\t"
"xor %2, %2\n\t"
"shrdl %%edx, %%eax\n\t" // result = hi(p2):hi(p1):lo(p1) >> shift
"adcl $0, %2\n\t" // Get highest order bit shifted out from CF
"shrdl %1, %%edx\n"
"3:\n\t"
"addl %2, %%eax\n\t" // result += highest order bit shifted out
"adcl $0, %%edx"
: "=A" (result), "=&r" (tmp1), "=&rm" (tmp2)
: "0" (multiplicand), "rm" (multiplier), "c" (shift)
: "cc");
return result;
}
#elif defined(_MSC_VER)
#pragma warning(disable: 4035)
static INLINE int64
Muls64x32s64(int64 multiplicand, uint32 multiplier, uint32 shift)
{
//ASSERT(shift >= 0 && shift < 64);
__asm {
mov eax, DWORD PTR [multiplicand+4] // Get hi(multiplicand)
test eax, eax // Check sign of multiplicand
jl SHORT l0 // Go if negative
mul DWORD PTR [multiplier] // p2 = hi(multiplicand) * multiplier
jmp SHORT l1
l0:
mul DWORD PTR [multiplier] // p2 = hi(multiplicand) * multiplier
sub edx, DWORD PTR [multiplier] // hi(p2) += -1 * multiplier
l1:
mov ecx, eax // Save lo(p2)
mov ebx, edx // Save hi(p2)
mov eax, DWORD PTR [multiplicand] // Get lo(multiplicand)
mul DWORD PTR [multiplier] // p1 = lo(multiplicand) * multiplier
add edx, ecx // hi(p1) += lo(p2)
adc ebx, 0 // hi(p2) += carry from previous step
mov ecx, DWORD PTR [shift] // Get shift
cmp ecx, 32 // shift < 32?
jl SHORT l2 // Go if so
shl eax, 1 // Save lo(p1) bit 31 in CF in case shift=32
mov eax, edx // result = hi(p2):hi(p1) >> (shift & 31)
mov edx, ebx
shrd eax, edx, cl
mov esi, 0
adc esi, 0 // Get highest order bit shifted out, from CF
sar edx, cl
jmp SHORT l3
l2:
xor esi, esi
shrd eax, edx, cl // result = hi(p2):hi(p1):lo(p1) << shift
adc esi, 0 // Get highest order bit shifted out, from CF
shrd edx, ebx, cl
l3:
add eax, esi // result += highest order bit shifted out
adc edx, 0
}
// return with result in edx:eax
}
#pragma warning(default: 4035)
#endif
#endif

View File

@@ -0,0 +1,616 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* vm_basic_asm_x86_64.h
*
* Basic x86_64 asm macros.
*/
#ifndef _VM_BASIC_ASM_X86_64_H_
#define _VM_BASIC_ASM_X86_64_H_
#ifndef VM_X86_64
#error "This file is x86-64 only!"
#endif
#if defined(_MSC_VER) && !defined(BORA_NO_WIN32_INTRINS)
#ifdef __cplusplus
extern "C" {
#endif
uint64 _umul128(uint64 multiplier, uint64 multiplicand,
uint64 *highProduct);
int64 _mul128(int64 multiplier, int64 multiplicand,
int64 *highProduct);
uint64 __shiftright128(uint64 lowPart, uint64 highPart, uint8 shift);
#ifdef __cplusplus
}
#endif
#pragma intrinsic(_umul128, _mul128, __shiftright128)
#endif // _MSC_VER
#if defined(__GNUC__)
/*
* GET_CURRENT_RIP
*
* Returns the current instruction pointer. In the example below:
*
* foo.c
* L123: Foo(GET_CURRENT_RIP())
*
* the return value from GET_CURRENT_RIP will point a debugger to L123.
*/
#define GET_CURRENT_RIP() ({ \
void *__rip; \
asm("lea 0(%%rip), %0;\n\t" \
: "=r" (__rip)); \
__rip; \
})
/*
* GET_CURRENT_LOCATION
*
* Updates the arguments with the values of the %rip, %rbp, and %rsp
* registers at the current code location where the macro is invoked.
*/
#define GET_CURRENT_LOCATION(rip, rbp, rsp) \
asm("lea 0(%%rip), %0\n" \
"mov %%rbp, %1\n" \
"mov %%rsp, %2\n" \
: "=r" (rip), "=r" (rbp), "=r" (rsp))
#endif
/*
* FXSAVE/FXRSTOR
* save/restore SIMD/MMX fpu state
*
* The pointer passed in must be 16-byte aligned.
*
* Intel and AMD processors behave differently w.r.t. fxsave/fxrstor. Intel
* processors unconditionally save the exception pointer state (instruction
* ptr., data ptr., and error instruction opcode). FXSAVE_ES1 and FXRSTOR_ES1
* work correctly for Intel processors.
*
* AMD processors only save the exception pointer state if ES=1. This leads to a
* security hole whereby one process/VM can inspect the state of another process
* VM. The AMD recommended workaround involves clobbering the exception pointer
* state unconditionally, and this is implemented in FXRSTOR_AMD_ES0. Note that
* FXSAVE_ES1 will only save the exception pointer state for AMD processors if
* ES=1.
*
* The workaround (FXRSTOR_AMD_ES0) only costs 1 cycle more than just doing an
* fxrstor, on both AMD Opteron and Intel Core CPUs.
*/
#if defined(__GNUC__)
static INLINE void
FXSAVE_ES1(void *save)
{
__asm__ __volatile__ ("fxsaveq %0 \n" : "=m" (*(uint8 *)save) : : "memory");
}
static INLINE void
FXSAVE_COMPAT_ES1(void *save)
{
__asm__ __volatile__ ("fxsave %0 \n" : "=m" (*(uint8 *)save) : : "memory");
}
static INLINE void
FXRSTOR_ES1(const void *load)
{
__asm__ __volatile__ ("fxrstorq %0 \n"
: : "m" (*(const uint8 *)load) : "memory");
}
static INLINE void
FXRSTOR_COMPAT_ES1(const void *load)
{
__asm__ __volatile__ ("fxrstor %0 \n"
: : "m" (*(const uint8 *)load) : "memory");
}
static INLINE void
FXRSTOR_AMD_ES0(const void *load)
{
uint64 dummy = 0;
__asm__ __volatile__
("fnstsw %%ax \n" // Grab x87 ES bit
"bt $7,%%ax \n" // Test ES bit
"jnc 1f \n" // Jump if ES=0
"fnclex \n" // ES=1. Clear it so fild doesn't trap
"1: \n"
"ffree %%st(7) \n" // Clear tag bit - avoid poss. stack overflow
"fildl %0 \n" // Dummy Load from "safe address" changes all
// x87 exception pointers.
"fxrstorq %1 \n"
:
: "m" (dummy), "m" (*(const uint8 *)load)
: "ax", "memory");
}
#endif /* __GNUC__ */
/*
* XSAVE/XRSTOR
* save/restore GSSE/SIMD/MMX fpu state
*
* The pointer passed in must be 64-byte aligned.
* See above comment for more information.
*/
#if defined(__GNUC__) && (defined(VMM) || defined(VMKERNEL) || defined(FROBOS))
static INLINE void
XSAVE_ES1(void *save, uint64 mask)
{
#if __GNUC__ < 4 || __GNUC__ == 4 && __GNUC_MINOR__ == 1
__asm__ __volatile__ (
".byte 0x48, 0x0f, 0xae, 0x21 \n"
:
: "c" ((uint8 *)save), "a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#else
__asm__ __volatile__ (
"xsaveq %0 \n"
: "=m" (*(uint8 *)save)
: "a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#endif
}
static INLINE void
XSAVE_COMPAT_ES1(void *save, uint64 mask)
{
#if __GNUC__ < 4 || __GNUC__ == 4 && __GNUC_MINOR__ == 1
__asm__ __volatile__ (
".byte 0x0f, 0xae, 0x21 \n"
:
: "c" ((uint8 *)save), "a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#else
__asm__ __volatile__ (
"xsave %0 \n"
: "=m" (*(uint8 *)save)
: "a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#endif
}
static INLINE void
XSAVEOPT_ES1(void *save, uint64 mask)
{
__asm__ __volatile__ (
".byte 0x48, 0x0f, 0xae, 0x31 \n"
:
: "c" ((uint8 *)save), "a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
}
static INLINE void
XRSTOR_ES1(const void *load, uint64 mask)
{
#if __GNUC__ < 4 || __GNUC__ == 4 && __GNUC_MINOR__ == 1
__asm__ __volatile__ (
".byte 0x48, 0x0f, 0xae, 0x29 \n"
:
: "c" ((const uint8 *)load),
"a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#else
__asm__ __volatile__ (
"xrstorq %0 \n"
:
: "m" (*(const uint8 *)load),
"a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#endif
}
static INLINE void
XRSTOR_COMPAT_ES1(const void *load, uint64 mask)
{
#if __GNUC__ < 4 || __GNUC__ == 4 && __GNUC_MINOR__ == 1
__asm__ __volatile__ (
".byte 0x0f, 0xae, 0x29 \n"
:
: "c" ((const uint8 *)load),
"a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#else
__asm__ __volatile__ (
"xrstor %0 \n"
:
: "m" (*(const uint8 *)load),
"a" ((uint32)mask), "d" ((uint32)(mask >> 32))
: "memory");
#endif
}
static INLINE void
XRSTOR_AMD_ES0(const void *load, uint64 mask)
{
uint64 dummy = 0;
__asm__ __volatile__
("fnstsw %%ax \n" // Grab x87 ES bit
"bt $7,%%ax \n" // Test ES bit
"jnc 1f \n" // Jump if ES=0
"fnclex \n" // ES=1. Clear it so fild doesn't trap
"1: \n"
"ffree %%st(7) \n" // Clear tag bit - avoid poss. stack overflow
"fildl %0 \n" // Dummy Load from "safe address" changes all
// x87 exception pointers.
"mov %%ebx, %%eax \n"
#if __GNUC__ < 4 || __GNUC__ == 4 && __GNUC_MINOR__ == 1
".byte 0x48, 0x0f, 0xae, 0x29 \n"
:
: "m" (dummy), "c" ((const uint8 *)load),
"b" ((uint32)mask), "d" ((uint32)(mask >> 32))
#else
"xrstorq %1 \n"
:
: "m" (dummy), "m" (*(const uint8 *)load),
"b" ((uint32)mask), "d" ((uint32)(mask >> 32))
#endif
: "eax", "memory");
}
#endif /* __GNUC__ */
/*
* XTEST
* Return TRUE if processor is in transaction region.
*
*/
#if defined(__GNUC__) && (defined(VMM) || defined(VMKERNEL) || defined(FROBOS))
static INLINE Bool
xtest(void)
{
uint8 al;
__asm__ __volatile__(".byte 0x0f, 0x01, 0xd6 # xtest \n"
"setnz %%al\n"
: "=a"(al) : : "cc");
return al;
}
#endif /* __GNUC__ */
/*
*-----------------------------------------------------------------------------
*
* Mul64x6464 --
*
* Unsigned integer by fixed point multiplication, with rounding:
* result = floor(multiplicand * multiplier * 2**(-shift) + 0.5)
*
* Unsigned 64-bit integer multiplicand.
* Unsigned 64-bit fixed point multiplier, represented as
* (multiplier, shift), where shift < 64.
*
* Result:
* Unsigned 64-bit integer product.
*
*-----------------------------------------------------------------------------
*/
#if defined(__GNUC__) && !defined(MUL64_NO_ASM)
static INLINE uint64
Mul64x6464(uint64 multiplicand,
uint64 multiplier,
uint32 shift)
{
/*
* Implementation:
* Multiply 64x64 bits to yield a full 128-bit product.
* Clear the carry bit (needed for the shift == 0 case).
* Shift result in RDX:RAX right by "shift".
* Add the carry bit. (If shift > 0, this is the highest order bit
* that was discarded by the shift; else it is 0.)
* Return the low-order 64 bits of the above.
*
*/
uint64 result, dummy;
__asm__("mulq %3 \n\t"
"clc \n\t"
"shrdq %b4, %1, %0 \n\t"
"adc $0, %0 \n\t"
: "=a" (result),
"=d" (dummy)
: "0" (multiplier),
"rm" (multiplicand),
"c" (shift)
: "cc");
return result;
}
#elif defined(_MSC_VER) && !defined(MUL64_NO_ASM)
static INLINE uint64
Mul64x6464(uint64 multiplicand,
uint64 multiplier,
uint32 shift)
{
/*
* Unfortunately, MSVC intrinsics don't give us access to the carry
* flag after a 128-bit shift, so the implementation is more
* awkward:
* Multiply 64x64 bits to yield a full 128-bit product.
* Shift result right by "shift".
* If shift != 0, extract and add in highest order bit that was
* discarded by the shift.
* Return the low-order 64 bits of the above.
*/
uint64 tmplo, tmphi;
tmplo = _umul128(multiplicand, multiplier, &tmphi);
if (shift == 0) {
return tmplo;
} else {
return __shiftright128(tmplo, tmphi, (uint8) shift) +
((tmplo >> (shift - 1)) & 1);
}
}
#else
#define MUL64_NO_ASM 1
#include "mul64.h"
#endif
/*
*-----------------------------------------------------------------------------
*
* Muls64x64s64 --
*
* Signed integer by fixed point multiplication, with rounding:
* result = floor(multiplicand * multiplier * 2**(-shift) + 0.5)
*
* Signed 64-bit integer multiplicand.
* Unsigned 64-bit fixed point multiplier, represented as
* (multiplier, shift), where shift < 64.
*
* Result:
* Signed 64-bit integer product.
*
*-----------------------------------------------------------------------------
*/
#if defined(__GNUC__) && !defined(MUL64_NO_ASM)
static inline int64
Muls64x64s64(int64 multiplicand,
int64 multiplier,
uint32 shift)
{
int64 result, dummy;
/* Implementation:
* Multiply 64x64 bits to yield a full 128-bit product.
* Clear the carry bit (needed for the shift == 0 case).
* Shift result in RDX:RAX right by "shift".
* Add the carry bit. (If shift > 0, this is the highest order bit
* that was discarded by the shift; else it is 0.)
* Return the low-order 64 bits of the above.
*
* Note: using the unsigned shrd instruction is correct because
* shift < 64 and we return only the low 64 bits of the shifted
* result.
*/
__asm__("imulq %3 \n\t"
"clc \n\t"
"shrdq %b4, %1, %0 \n\t"
"adc $0, %0 \n\t"
: "=a" (result),
"=d" (dummy)
: "0" (multiplier),
"rm" (multiplicand),
"c" (shift)
: "cc");
return result;
}
#elif defined(_MSC_VER) && !defined(MUL64_NO_ASM)
static INLINE int64
Muls64x64s64(int64 multiplicand,
int64 multiplier,
uint32 shift)
{
/*
* Unfortunately, MSVC intrinsics don't give us access to the carry
* flag after a 128-bit shift, so the implementation is more
* awkward:
* Multiply 64x64 bits to yield a full 128-bit product.
* Shift result right by "shift".
* If shift != 0, extract and add in highest order bit that was
* discarded by the shift.
* Return the low-order 64 bits of the above.
*
* Note: using an unsigned shift is correct because shift < 64 and
* we return only the low 64 bits of the shifted result.
*/
int64 tmplo, tmphi;
tmplo = _mul128(multiplicand, multiplier, &tmphi);
if (shift == 0) {
return tmplo;
} else {
return __shiftright128(tmplo, tmphi, (uint8) shift) +
((tmplo >> (shift - 1)) & 1);
}
}
#endif
#ifndef MUL64_NO_ASM
/*
*-----------------------------------------------------------------------------
*
* Mul64x3264 --
*
* Unsigned integer by fixed point multiplication, with rounding:
* result = floor(multiplicand * multiplier * 2**(-shift) + 0.5)
*
* Unsigned 64-bit integer multiplicand.
* Unsigned 32-bit fixed point multiplier, represented as
* (multiplier, shift), where shift < 64.
*
* Result:
* Unsigned 64-bit integer product.
*
*-----------------------------------------------------------------------------
*/
static INLINE uint64
Mul64x3264(uint64 multiplicand, uint32 multiplier, uint32 shift)
{
return Mul64x6464(multiplicand, multiplier, shift);
}
/*
*-----------------------------------------------------------------------------
*
* Muls64x32s64 --
*
* Signed integer by fixed point multiplication, with rounding:
* result = floor(multiplicand * multiplier * 2**(-shift) + 0.5)
*
* Signed 64-bit integer multiplicand.
* Unsigned 32-bit fixed point multiplier, represented as
* (multiplier, shift), where shift < 64.
*
* Result:
* Signed 64-bit integer product.
*
*-----------------------------------------------------------------------------
*/
static INLINE int64
Muls64x32s64(int64 multiplicand, uint32 multiplier, uint32 shift)
{
return Muls64x64s64(multiplicand, multiplier, shift);
}
#endif
#if defined(__GNUC__)
static INLINE void *
uint64set(void *dst, uint64 val, uint64 count)
{
int dummy0;
int dummy1;
__asm__ __volatile__("\t"
"cld" "\n\t"
"rep ; stosq" "\n"
: "=c" (dummy0), "=D" (dummy1)
: "0" (count), "1" (dst), "a" (val)
: "memory", "cc");
return dst;
}
#endif
/*
*-----------------------------------------------------------------------------
*
* Div643232 --
*
* Unsigned integer division:
* The dividend is 64-bit wide
* The divisor is 32-bit wide
* The quotient is 32-bit wide
*
* Use this function if you are certain that the quotient will fit in 32 bits,
* If that is not the case, a #DE exception was generated in 32-bit version,
* but not in this 64-bit version. So please be careful.
*
* Results:
* Quotient and remainder
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
#if defined(__GNUC__) || defined(_MSC_VER)
static INLINE void
Div643232(uint64 dividend, // IN
uint32 divisor, // IN
uint32 *quotient, // OUT
uint32 *remainder) // OUT
{
*quotient = (uint32)(dividend / divisor);
*remainder = (uint32)(dividend % divisor);
}
#endif
/*
*-----------------------------------------------------------------------------
*
* Div643264 --
*
* Unsigned integer division:
* The dividend is 64-bit wide
* The divisor is 32-bit wide
* The quotient is 64-bit wide
*
* Results:
* Quotient and remainder
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
#if defined(__GNUC__)
static INLINE void
Div643264(uint64 dividend, // IN
uint32 divisor, // IN
uint64 *quotient, // OUT
uint32 *remainder) // OUT
{
*quotient = dividend / divisor;
*remainder = dividend % divisor;
}
#endif
#endif // _VM_BASIC_ASM_X86_64_H_

View File

@@ -0,0 +1,752 @@
/*********************************************************
* Copyright (C) 2003-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* vm_basic_defs.h --
*
* Standard macros for VMware source code.
*/
#ifndef _VM_BASIC_DEFS_H_
#define _VM_BASIC_DEFS_H_
#include "vm_basic_types.h" // For INLINE.
/* Checks for FreeBSD, filtering out VMKERNEL. */
#define __IS_FREEBSD__ (!defined(VMKERNEL) && defined(__FreeBSD__))
#define __IS_FREEBSD_VER__(ver) (__IS_FREEBSD__ && __FreeBSD_version >= (ver))
#if defined _WIN32 && defined USERLEVEL
#include <stddef.h> /*
* We redefine offsetof macro from stddef; make
* sure that it's already defined before we do that.
*/
#include <windows.h> // for Sleep() and LOWORD() etc.
#undef GetFreeSpace // Unpollute preprocessor namespace.
#endif
/*
* Simple macros
*/
#if (defined __APPLE__ || defined __FreeBSD__) && \
(!defined KERNEL && !defined _KERNEL && !defined VMKERNEL && !defined __KERNEL__)
# include <stddef.h>
#else
// XXX the _WIN32 one matches that of VC++, to prevent redefinition warning
// XXX the other one matches that of gcc3.3.3/glibc2.2.4 to prevent redefinition warnings
#ifndef offsetof
#define VMW_DEFINED_OFFSETOF
#ifdef _WIN32
#define offsetof(s,m) (size_t)&(((s *)0)->m)
#else
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#endif
#endif // __APPLE__
/*
* This is necessary until we eliminate the inclusion of <windows.h> above.
* At that time, it should be possible to use "offsetof" everywhere.
*/
#ifndef vmw_offsetof
#define vmw_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#define VMW_CONTAINER_OF(ptr, type, member) \
((type *)((char *)(ptr) - vmw_offsetof(type, member)))
#ifndef ARRAYSIZE
#define ARRAYSIZE(a) (sizeof (a) / sizeof *(a))
#endif
#ifndef MIN
#define MIN(_a, _b) (((_a) < (_b)) ? (_a) : (_b))
#endif
/* The Solaris 9 cross-compiler complains about these not being used */
#ifndef sun
static INLINE int
Min(int a, int b)
{
return a < b ? a : b;
}
#endif
#ifndef MAX
#define MAX(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
#endif
#ifndef sun
static INLINE int
Max(int a, int b)
{
return a > b ? a : b;
}
#endif
#define VMW_CLAMP(x, min, max) \
((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
#define ROUNDUP(x,y) (((x) + (y) - 1) / (y) * (y))
#define ROUNDDOWN(x,y) ((x) / (y) * (y))
#define ROUNDUPBITS(x, bits) (((uintptr_t) (x) + MASK(bits)) & ~MASK(bits))
#define ROUNDDOWNBITS(x, bits) ((uintptr_t) (x) & ~MASK(bits))
#define CEILING(x, y) (((x) + (y) - 1) / (y))
#if defined __APPLE__
#include <machine/param.h>
#undef MASK
#endif
/*
* The MASK macro behaves badly when given negative numbers or numbers larger
* than the highest order bit number (e.g. 32 on a 32-bit machine) as an
* argument. The range 0..31 is safe.
*/
#define MASK(n) ((1 << (n)) - 1) /* make an n-bit mask */
#define MASK64(n) ((CONST64U(1) << (n)) - 1) /* make an n-bit mask */
/*
* MASKRANGE64 makes a bit vector starting at bit lo and ending at bit hi. No
* checking for lo < hi is done.
*/
#define MASKRANGE64(hi, lo) (MASK64((hi) - (lo) + 1) << (lo))
/* SIGNEXT64 sign extends a n-bit value to 64-bits. */
#define SIGNEXT64(val, n) (((int64)(val) << (64 - (n))) >> (64 - (n)))
#define DWORD_ALIGN(x) ((((x) + 3) >> 2) << 2)
#define QWORD_ALIGN(x) ((((x) + 7) >> 3) << 3)
#define IMPLIES(a,b) (!(a) || (b))
/*
* Not everybody (e.g., the monitor) has NULL
*/
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
/*
* Token concatenation
*
* The C preprocessor doesn't prescan arguments when they are
* concatenated or stringified. So we need extra levels of
* indirection to convince the preprocessor to expand its
* arguments.
*/
#define CONC(x, y) x##y
#define XCONC(x, y) CONC(x, y)
#define XXCONC(x, y) XCONC(x, y)
#define MAKESTR(x) #x
#define XSTR(x) MAKESTR(x)
/*
* Wide versions of string constants.
*/
#ifndef WSTR
#define WSTR_(X) L ## X
#define WSTR(X) WSTR_(X)
#endif
/*
* Page operations
*
* It has been suggested that these definitions belong elsewhere
* (like x86types.h). However, I deem them common enough
* (since even regular user-level programs may want to do
* page-based memory manipulation) to be here.
* -- edward
*/
#ifndef PAGE_SHIFT // {
#if defined VM_I386
#define PAGE_SHIFT 12
#elif defined __APPLE__
#define PAGE_SHIFT 12
#elif defined __arm__
#define PAGE_SHIFT 12
#else
#error
#endif
#endif // }
#ifndef PAGE_SIZE
#define PAGE_SIZE (1<<PAGE_SHIFT)
#endif
#ifndef PAGE_MASK
#define PAGE_MASK (PAGE_SIZE - 1)
#endif
#ifndef PAGE_OFFSET
#define PAGE_OFFSET(_addr) ((uintptr_t)(_addr)&(PAGE_SIZE-1))
#endif
#ifndef VM_PAGE_BASE
#define VM_PAGE_BASE(_addr) ((_addr)&~(PAGE_SIZE-1))
#endif
#ifndef VM_PAGES_SPANNED
#define VM_PAGES_SPANNED(_addr, _size) \
((((_addr) & (PAGE_SIZE - 1)) + (_size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT)
#endif
#ifndef BYTES_2_PAGES
#define BYTES_2_PAGES(_nbytes) ((_nbytes) >> PAGE_SHIFT)
#endif
#ifndef PAGES_2_BYTES
#define PAGES_2_BYTES(_npages) (((uint64)(_npages)) << PAGE_SHIFT)
#endif
#ifndef MBYTES_2_PAGES
#define MBYTES_2_PAGES(_nbytes) ((_nbytes) << (20 - PAGE_SHIFT))
#endif
#ifndef PAGES_2_MBYTES
#define PAGES_2_MBYTES(_npages) ((_npages) >> (20 - PAGE_SHIFT))
#endif
#ifndef GBYTES_2_PAGES
#define GBYTES_2_PAGES(_nbytes) ((_nbytes) << (30 - PAGE_SHIFT))
#endif
#ifndef PAGES_2_GBYTES
#define PAGES_2_GBYTES(_npages) ((_npages) >> (30 - PAGE_SHIFT))
#endif
#ifndef BYTES_2_MBYTES
#define BYTES_2_MBYTES(_nbytes) ((_nbytes) >> 20)
#endif
#ifndef MBYTES_2_BYTES
#define MBYTES_2_BYTES(_nbytes) ((uint64)(_nbytes) << 20)
#endif
#ifndef BYTES_2_GBYTES
#define BYTES_2_GBYTES(_nbytes) ((_nbytes) >> 30)
#endif
#ifndef GBYTES_2_BYTES
#define GBYTES_2_BYTES(_nbytes) ((uint64)(_nbytes) << 30)
#endif
#ifndef VM_PAE_LARGE_PAGE_SHIFT
#define VM_PAE_LARGE_PAGE_SHIFT 21
#endif
#ifndef VM_PAE_LARGE_PAGE_SIZE
#define VM_PAE_LARGE_PAGE_SIZE (1 << VM_PAE_LARGE_PAGE_SHIFT)
#endif
#ifndef VM_PAE_LARGE_PAGE_MASK
#define VM_PAE_LARGE_PAGE_MASK (VM_PAE_LARGE_PAGE_SIZE - 1)
#endif
#ifndef VM_PAE_LARGE_2_SMALL_PAGES
#define VM_PAE_LARGE_2_SMALL_PAGES (BYTES_2_PAGES(VM_PAE_LARGE_PAGE_SIZE))
#endif
/*
* Word operations
*/
#ifndef LOWORD
#define LOWORD(_dw) ((_dw) & 0xffff)
#endif
#ifndef HIWORD
#define HIWORD(_dw) (((_dw) >> 16) & 0xffff)
#endif
#ifndef LOBYTE
#define LOBYTE(_w) ((_w) & 0xff)
#endif
#ifndef HIBYTE
#define HIBYTE(_w) (((_w) >> 8) & 0xff)
#endif
#define HIDWORD(_qw) ((uint32)((_qw) >> 32))
#define LODWORD(_qw) ((uint32)(_qw))
#define QWORD(_hi, _lo) ((((uint64)(_hi)) << 32) | ((uint32)(_lo)))
/*
* Deposit a field _src at _pos bits from the right,
* with a length of _len, into the integer _target.
*/
#define DEPOSIT_BITS(_src,_pos,_len,_target) { \
unsigned mask = ((1 << _len) - 1); \
unsigned shiftedmask = ((1 << _len) - 1) << _pos; \
_target = (_target & ~shiftedmask) | ((_src & mask) << _pos); \
}
/*
* Get return address.
*/
#ifdef _MSC_VER
#ifdef __cplusplus
extern "C"
#endif
void *_ReturnAddress(void);
#pragma intrinsic(_ReturnAddress)
#define GetReturnAddress() _ReturnAddress()
#elif __GNUC__
#define GetReturnAddress() __builtin_return_address(0)
#endif
#ifdef __GNUC__
#ifndef sun
/*
* A bug in __builtin_frame_address was discovered in gcc 4.1.1, and
* fixed in 4.2.0; assume it originated in 4.0. PR 147638 and 554369.
*/
#if !(__GNUC__ == 4 && (__GNUC_MINOR__ == 0 || __GNUC_MINOR__ == 1))
#define GetFrameAddr() __builtin_frame_address(0)
#endif
#endif // sun
#endif // __GNUC__
/*
* Data prefetch was added in gcc 3.1.1
* http://www.gnu.org/software/gcc/gcc-3.1/changes.html
*/
#ifdef __GNUC__
# if ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ > 1) || \
(__GNUC__ == 3 && __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ >= 1))
# define PREFETCH_R(var) __builtin_prefetch((var), 0 /* read */, \
3 /* high temporal locality */)
# define PREFETCH_W(var) __builtin_prefetch((var), 1 /* write */, \
3 /* high temporal locality */)
# else
# define PREFETCH_R(var) ((void)(var))
# define PREFETCH_W(var) ((void)(var))
# endif
#endif /* __GNUC__ */
#ifdef USERLEVEL // {
/*
* Note this might be a problem on NT b/c while sched_yield guarantees it
* moves you to the end of your priority list, Sleep(0) offers no such
* guarantee. Bummer. --Jeremy.
*/
#if defined(N_PLAT_NLM)
/* We do not have YIELD() as we do not need it yet... */
#elif defined(_WIN32)
# define YIELD() Sleep(0)
#elif defined(VMKERNEL)
/* We don't have a YIELD macro in the vmkernel */
#else
# include <sched.h> // For sched_yield. Don't ask. --Jeremy.
# define YIELD() sched_yield()
#endif
/*
* Standardize some Posix names on Windows.
*/
#ifdef _WIN32 // {
#define snprintf _snprintf
#define strtok_r strtok_s
#if (_MSC_VER < 1500)
#define vsnprintf _vsnprintf
#endif
typedef int uid_t;
typedef int gid_t;
static INLINE void
sleep(unsigned int sec)
{
Sleep(sec * 1000);
}
static INLINE int
usleep(unsigned long usec)
{
Sleep(CEILING(usec, 1000));
return 0;
}
typedef int pid_t;
#define F_OK 0
#define X_OK 1
#define W_OK 2
#define R_OK 4
#endif // }
/*
* Macro for username comparison.
*/
#ifdef _WIN32 // {
#define USERCMP(x,y) Str_Strcasecmp(x,y)
#else
#define USERCMP(x,y) strcmp(x,y)
#endif // }
#endif // }
#ifndef va_copy
#ifdef _WIN32
/*
* Windows needs va_copy. This works for both 32 and 64-bit Windows
* based on inspection of how varags.h from the Visual C CRTL is
* implemented. (Future versions of the RTL may break this).
*/
#define va_copy(dest, src) ((dest) = (src))
#elif defined(__APPLE__) && defined(KERNEL)
#include "availabilityMacOS.h"
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
// The Mac OS 10.5 kernel SDK defines va_copy in stdarg.h.
#include <stdarg.h>
#else
/*
* The Mac OS 10.4 kernel SDK needs va_copy. Based on inspection of
* stdarg.h from the MacOSX10.4u.sdk kernel framework, this should
* work.
*/
#define va_copy(dest, src) ((dest) = (src))
#endif // MAC_OS_X_VERSION_MIN_REQUIRED
#elif defined(__GNUC__) && (__GNUC__ < 3)
/*
* Old versions of gcc recognize __va_copy, but not va_copy.
*/
#define va_copy(dest, src) __va_copy(dest, src)
#endif // _WIN32
#endif // va_copy
/*
* This one is outside USERLEVEL because it's used by
* files compiled into the Windows hgfs driver or the display
* driver.
*/
#ifdef _WIN32
#define PATH_MAX 256
#ifndef strcasecmp
#define strcasecmp(_s1,_s2) _stricmp((_s1),(_s2))
#endif
#ifndef strncasecmp
#define strncasecmp(_s1,_s2,_n) _strnicmp((_s1),(_s2),(_n))
#endif
#endif
#if defined __linux__ && !defined __KERNEL__ && !defined MODULE && \
!defined VMM && !defined FROBOS && !defined __ANDROID__
#include <features.h>
#if __GLIBC_PREREQ(2, 1) && !defined GLIBC_VERSION_21
#define GLIBC_VERSION_21
#endif
#if __GLIBC_PREREQ(2, 2) && !defined GLIBC_VERSION_22
#define GLIBC_VERSION_22
#endif
#if __GLIBC_PREREQ(2, 3) && !defined GLIBC_VERSION_23
#define GLIBC_VERSION_23
#endif
#if __GLIBC_PREREQ(2, 4) && !defined GLIBC_VERSION_24
#define GLIBC_VERSION_24
#endif
#if __GLIBC_PREREQ(2, 5) && !defined GLIBC_VERSION_25
#define GLIBC_VERSION_25
#endif
#if __GLIBC_PREREQ(2, 12) && !defined GLIBC_VERSION_212
#define GLIBC_VERSION_212
#endif
#endif
/*
* Convenience macros and definitions. Can often be used instead of #ifdef.
*/
#undef DEBUG_ONLY
#ifdef VMX86_DEBUG
#define vmx86_debug 1
#define DEBUG_ONLY(x) x
#else
#define vmx86_debug 0
#define DEBUG_ONLY(x)
#endif
#ifdef VMX86_STATS
#define vmx86_stats 1
#define STATS_ONLY(x) x
#else
#define vmx86_stats 0
#define STATS_ONLY(x)
#endif
#ifdef VMX86_DEVEL
#define vmx86_devel 1
#define DEVEL_ONLY(x) x
#else
#define vmx86_devel 0
#define DEVEL_ONLY(x)
#endif
#ifdef VMX86_LOG
#define vmx86_log 1
#define LOG_ONLY(x) x
#else
#define vmx86_log 0
#define LOG_ONLY(x)
#endif
#ifdef VMX86_BETA
#define vmx86_beta 1
#define BETA_ONLY(x) x
#else
#define vmx86_beta 0
#define BETA_ONLY(x)
#endif
#ifdef VMX86_RELEASE
#define vmx86_release 1
#define RELEASE_ONLY(x) x
#else
#define vmx86_release 0
#define RELEASE_ONLY(x)
#endif
#ifdef VMX86_SERVER
#define vmx86_server 1
#define SERVER_ONLY(x) x
#define HOSTED_ONLY(x)
#else
#define vmx86_server 0
#define SERVER_ONLY(x)
#define HOSTED_ONLY(x) x
#endif
#ifdef VMKERNEL
#define vmkernel 1
#define VMKERNEL_ONLY(x) x
#else
#define vmkernel 0
#define VMKERNEL_ONLY(x)
#endif
#ifdef _WIN32
#define WIN32_ONLY(x) x
#define POSIX_ONLY(x)
#define vmx86_win32 1
#else
#define WIN32_ONLY(x)
#define POSIX_ONLY(x) x
#define vmx86_win32 0
#endif
#ifdef __linux__
#define vmx86_linux 1
#define LINUX_ONLY(x) x
#else
#define vmx86_linux 0
#define LINUX_ONLY(x)
#endif
#ifdef __APPLE__
#define vmx86_apple 1
#define APPLE_ONLY(x) x
#else
#define vmx86_apple 0
#define APPLE_ONLY(x)
#endif
#ifdef VMM
#define VMM_ONLY(x) x
#define USER_ONLY(x)
#else
#define VMM_ONLY(x)
#define USER_ONLY(x) x
#endif
/* VMVISOR ifdef only allowed in the vmkernel */
#ifdef VMKERNEL
#ifdef VMVISOR
#define vmvisor 1
#define VMVISOR_ONLY(x) x
#else
#define vmvisor 0
#define VMVISOR_ONLY(x)
#endif
#endif
#ifdef _WIN32
#define VMW_INVALID_HANDLE INVALID_HANDLE_VALUE
#else
#define VMW_INVALID_HANDLE (-1LL)
#endif
#ifdef _WIN32
#define fsync(fd) _commit(fd)
#define fileno(f) _fileno(f)
#else
#endif
/*
* Debug output macros for Windows drivers (the Eng variant is for
* display/printer drivers only.
*/
#ifdef _WIN32
#ifndef USES_OLD_WINDDK
#if defined(VMX86_LOG)
#ifdef _WIN64
#define WinDrvPrint(arg, ...) DbgPrintEx(DPFLTR_IHVDRIVER_ID, (ULONG)~0, arg, __VA_ARGS__)
#else
#define WinDrvPrint(arg, ...) DbgPrint(arg, __VA_ARGS__)
#endif
#define WinDrvEngPrint(arg, ...) EngDbgPrint(arg, __VA_ARGS__)
#else
#define WinDrvPrint(arg, ...)
#define WinDrvEngPrint(arg, ...)
#endif
#endif
#endif // _WIN32
#ifdef HOSTED_LG_PG
#define hosted_lg_pg 1
#else
#define hosted_lg_pg 0
#endif
/*
* Use to initialize cbSize for this structure to preserve < Vista
* compatibility.
*/
#define NONCLIENTMETRICSINFO_V1_SIZE CCSIZEOF_STRUCT(NONCLIENTMETRICS, \
lfMessageFont)
/* This is not intended to be thread-safe. */
#define DO_ONCE(code) \
do { \
static Bool _doOnceDone = FALSE; \
if (UNLIKELY(!_doOnceDone)) { \
_doOnceDone = TRUE; \
code; \
} \
} while (0)
/*
* Bug 827422 and 838523.
*/
#if defined __GNUC__ && __GNUC__ >= 4
#define VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
#else
#define VISIBILITY_HIDDEN /* nothing */
#endif
/*
* Bitfield extraction.
*/
#define EXTRACT_BITSLICE32(_val , _lsb, _msb) \
(((uint32)(_val) << (31 - (_msb))) >> ((31 - (_msb)) + (_lsb)))
#define EXTRACT_BITFIELD32(_val, _pos, _len) \
EXTRACT_BITSLICE32((_val), (_pos), ((_pos) + (_len) - 1))
#define EXTRACT_BITSLICE64(_val, _lsb, _msb) \
(((uint64)(_val) << (63 - (_msb))) >> ((63 - (_msb)) + (_lsb)))
#define EXTRACT_BITFIELD64(_val, _pos, _len) \
EXTRACT_BITSLICE64((_val), (_pos), ((_pos) + (_len) - 1))
/*
* Typical cache line size. Use this for aligning structures to cache
* lines for performance, but do not rely on it for correctness.
*/
#define CACHELINE_SIZE 64
#define CACHELINE_ALIGNMENT_MASK (CACHELINE_SIZE - 1)
#endif // ifndef _VM_BASIC_DEFS_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,47 @@
/*********************************************************
* Copyright (C) 2006-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* vmcheck.h --
*
* Utility functions for discovering our virtualization status.
*/
#ifndef __VMCHECK_H__
# define __VMCHECK_H__
#ifdef __cplusplus
extern "C" {
#endif
# include "vm_basic_types.h"
Bool
VmCheck_GetVersion(uint32 *version, // OUT
uint32 *type); // OUT
Bool
VmCheck_IsVirtualWorld(void);
#ifdef __cplusplus
}
#endif
#endif /* __VMCHECK_H__ */

View File

@@ -0,0 +1,37 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* vmsignal.h --
*
* Posix signal handling utility functions
*
*/
#ifndef __VMSIGNAL_H__
# define __VMSIGNAL_H__
#include <signal.h>
int Signal_SetGroupHandler(int const *signals, struct sigaction *olds, unsigned int nr, void (*handler)(int signal));
int Signal_ResetGroupHandler(int const *signals, struct sigaction const *olds, unsigned int nr);
#endif /* __VMSIGNAL_H__ */

87
vendor/github.com/sigma/vmw-guestinfo/include/vmware.h generated vendored Normal file
View File

@@ -0,0 +1,87 @@
/*********************************************************
* Copyright (C) 2003-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* vmware.h --
*
* Standard include file for VMware source code.
*/
#ifndef _VMWARE_H_
#define _VMWARE_H_
#include "vm_basic_types.h"
#include "vm_basic_defs.h"
#include "vm_assert.h"
/*
* Global error codes. Currently used internally, but may be exported
* to customers one day, like VM_E_XXX in vmcontrol_constants.h
*/
typedef enum VMwareStatus {
VMWARE_STATUS_SUCCESS, /* success */
VMWARE_STATUS_ERROR, /* generic error */
VMWARE_STATUS_NOMEM, /* generic memory allocation error */
VMWARE_STATUS_INSUFFICIENT_RESOURCES, /* internal or system resource limit exceeded */
VMWARE_STATUS_INVALID_ARGS /* invalid arguments */
} VMwareStatus;
#define VMWARE_SUCCESS(s) ((s) == VMWARE_STATUS_SUCCESS)
#endif // ifndef _VMWARE_H_

View File

@@ -0,0 +1,57 @@
/*********************************************************
* Copyright (C) 2002-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* vmware_pack_begin.h --
*
* Begin of structure packing. See vmware_pack_init.h for details.
*
* Note that we do not use the following construct in this include file,
* because we want to emit the code every time the file is included --hpreg
*
* #ifndef foo
* # define foo
* ...
* #endif
*
*/
#include "vmware_pack_init.h"
#ifdef _MSC_VER
# pragma pack(push, 1)
#elif __GNUC__
#else
# error Compiler packing...
#endif

View File

@@ -0,0 +1,58 @@
/*********************************************************
* Copyright (C) 2002-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* vmware_pack_end.h --
*
* End of structure packing. See vmware_pack_init.h for details.
*
* Note that we do not use the following construct in this include file,
* because we want to emit the code every time the file is included --hpreg
*
* #ifndef foo
* # define foo
* ...
* #endif
*
*/
#include "vmware_pack_init.h"
#ifdef _MSC_VER
# pragma pack(pop)
#elif __GNUC__
__attribute__((__packed__))
#else
# error Compiler packing...
#endif

View File

@@ -0,0 +1,79 @@
/*********************************************************
* Copyright (C) 2002-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
#ifndef __VMWARE_PACK_INIT_H__
# define __VMWARE_PACK_INIT_H__
/*
* vmware_pack_init.h --
*
* Platform-independent code to make the compiler pack (i.e. have them
* occupy the smallest possible space) structure definitions. The following
* constructs are known to work --hpreg
*
* #include "vmware_pack_begin.h"
* struct foo {
* ...
* }
* #include "vmware_pack_end.h"
* ;
*
* typedef
* #include "vmware_pack_begin.h"
* struct foo {
* ...
* }
* #include "vmware_pack_end.h"
* foo;
*/
#ifdef _MSC_VER
/*
* MSVC 6.0 emits warning 4103 when the pack push and pop pragma pairing is
* not balanced within 1 included file. That is annoying because our scheme
* is based on the pairing being balanced between 2 included files.
*
* So we disable this warning, but this is safe because the compiler will also
* emit warning 4161 when there is more pops than pushes within 1 main
* file --hpreg
*/
# pragma warning(disable:4103)
#elif __GNUC__
#else
# error Compiler packing...
#endif
#endif /* __VMWARE_PACK_INIT_H__ */

View File

@@ -0,0 +1,243 @@
/*********************************************************
* Copyright (C) 2006-2013 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* x86_basic_defs.h --
*
* Basic macros describing the x86 architecture.
*/
#ifndef _X86_BASIC_DEFS_H_
#define _X86_BASIC_DEFS_H_
#define SIZE_8BIT 1
#define SIZE_16BIT 2
#define SIZE_24BIT 3
#define SIZE_32BIT 4
#define SIZE_48BIT 6
#define SIZE_64BIT 8
#define SIZE_80BIT 10
#define SIZE_128BIT 16
#define SIZE_256BIT 32
#define X86_MAX_INSTR_LEN 15 /* Max byte length of an x86 instruction. */
#define NUM_IDT_VECTORS 256
/*
* control registers
*/
#define CR0_PE 0x00000001
#define CR0_MP 0x00000002
#define CR0_EM 0x00000004
#define CR0_TS 0x00000008
#define CR0_ET 0x00000010
#define CR0_NE 0x00000020
#define CR0_WP 0x00010000
#define CR0_AM 0x00040000
#define CR0_NW 0x20000000
#define CR0_CD 0x40000000
#define CR0_PG 0x80000000
#define CR0_RESERVED CONST64U(0xffffffff1ffaffc0)
#define CR3_PWT 0x00000008
#define CR3_PCD 0x00000010
#define CR3_PDB_SHIFT 12
#define CR3_PDB_MASK 0xfffff000
#define CR3_IGNORE 0xFFF
#define PAE_CR3_IGNORE 0x1F
#define CR3_PCID_MASK 0xFFF
#define CR3_NO_FLUSH (1ULL << 63)
#define CR4_VME 0x00000001
#define CR4_PVI 0x00000002
#define CR4_TSD 0x00000004
#define CR4_DE 0x00000008
#define CR4_PSE 0x00000010
#define CR4_PAE 0x00000020
#define CR4_MCE 0x00000040
#define CR4_PGE 0x00000080
#define CR4_PCE 0x00000100
#define CR4_OSFXSR 0x00000200 // CPU/OS supports SIMD insts
#define CR4_OSXMMEXCPT 0x00000400 // #XF exception enable PIII only
#define CR4_VMXE 0x00002000
#define CR4_SMXE 0x00004000
#define CR4_FSGSBASE 0x00010000
#define CR4_PCIDE 0x00020000
#define CR4_OSXSAVE 0x00040000
#define CR4_SMEP 0x00100000
#define CR4_SMAP 0x00200000
/* Removing a bit from CR4_RESERVED causes Task_Switch to leave the bit set. */
#define CR4_RESERVED CONST64U(0xffffffffffc89800)
#define CR8_RESERVED CONST64U(0xfffffffffffffff0)
/*
* Debug registers.
*/
#define DR_COUNT 4
#define DR6_B0 0x00000001
#define DR6_B1 0x00000002
#define DR6_B2 0x00000004
#define DR6_B3 0x00000008
#define DR6_B0123 (DR6_B0 | DR6_B1 | DR6_B2 | DR6_B3)
#define DR6_B(_n) (1 << (_n))
#define DR6_BD 0x00002000
#define DR6_BS 0x00004000
#define DR6_BT 0x00008000
#define DR6_RTM 0x00010000
#define DR6_ONES 0xfffe0ff0
#define DR6_DEFAULT (DR6_ONES | DR6_RTM)
#define DR6_RESERVED_MASK 0xfffe1ff0
#define DR7_L_MASK(_n) (1 << ((_n) * 2))
#define DR7_G_MASK(_n) (1 << ((_n) * 2 + 1))
#define DR7_LG_MASK(_n) (3 << ((_n) * 2))
#define DR7_RW_MASK(_n) (3 << (16 + (_n) * 4))
#define DR7_LEN_MASK(_n) (3 << (18 + (_n) * 4))
#define DR7_BP_MASK(_n) (DR7_L_MASK(_n) |\
DR7_G_MASK(_n) |\
DR7_RW_MASK(_n) |\
DR7_LEN_MASK(_n))
#define DR7_L0 DR7_L_MASK(0)
#define DR7_G0 DR7_G_MASK(0)
#define DR7_L1 DR7_L_MASK(1)
#define DR7_G1 DR7_G_MASK(1)
#define DR7_L2 DR7_L_MASK(2)
#define DR7_G2 DR7_G_MASK(2)
#define DR7_L3 DR7_L_MASK(3)
#define DR7_G3 DR7_G_MASK(3)
#define DR7_ENABLED 0x000000ff
#define DR7_LE 0x00000100 // Deprecated in modern hardware
#define DR7_GE 0x00000200 // Deprecated in modern hardware
#define DR7_GD 0x00002000
#define DR7_ONES 0x00000400
#define DR7_RTM 0x00000800
#define DR7_RESERVED CONST64U(0xffffffff0000d400)
#define DR7_DEFUNCT (DR7_LE | DR7_GE)
#define DR7_DEFAULT DR7_ONES
#define DR7_LX_MASK (DR7_L0 | DR7_L1 | DR7_L2 | DR7_L3 | DR7_LE)
#define DR7_GX_MASK (DR7_G0 | DR7_G1 | DR7_G2 | DR7_G3 | DR7_GE)
#define DR7_LGX_MASK (DR7_LX_MASK | DR7_GX_MASK)
#define DR7_RW(_r,_n) (((_r) >> (16+(_n)*4)) & 0x3)
#define DR7_L(_r,_n) (((_r) >> ((_n)*2)) & 1)
#define DR7_G(_r,_n) (((_r) >> (1 + (_n)*2)) & 1)
#define DR7_LEN(_r,_n) (((_r) >> (18+(_n)*4)) & 0x3)
#define DR7_RW_BITS(_n,_rw) ((_rw) << (16 + (_n) * 4))
#define DR7_LEN_BITS(_n,_len) ((_len) << (18 + (_n) * 4))
#define DR7_RW_INST 0x0
#define DR7_RW_WRITES 0x1
#define DR7_RW_IO 0x2
#define DR7_RW_ACCESS 0x3
#define DR7_LENGTH_1 0x0
#define DR7_LENGTH_2 0x1
#define DR7_LENGTH_8 0x2
#define DR7_LENGTH_4 0x3
#define DEBUG_STATUS_B0 (1<<0)
#define DEBUG_STATUS_B1 (1<<1)
#define DEBUG_STATUS_B2 (1<<2)
#define DEBUG_STATUS_B3 (1<<3)
#define DEBUG_STATUS_DB (1<<13)
#define DEBUG_STATUS_BS (1<<14)
#define DEBUG_STATUS_BT (1<<15)
/*
* exception error codes
*/
#define EXC_DE 0
#define EXC_DB 1
#define EXC_NMI 2
#define EXC_BP 3
#define EXC_OF 4
#define EXC_BR 5
#define EXC_UD 6
#define EXC_NM 7
#define EXC_DF 8
#define EXC_TS 10
#define EXC_NP 11
#define EXC_SS 12
#define EXC_GP 13
#define EXC_PF 14
#define EXC_MF 16
#define EXC_AC 17
#define EXC_MC 18
#define EXC_XF 19 /* SIMD exception. */
#define EXC_SX 30 /* Security exception (SVM only). */
/*
* eflag/rflag definitions.
*/
#define EFLAGS_IOPL_SHIFT 12
typedef enum x86_FLAGS {
EFLAGS_NONE = 0,
EFLAGS_CF = (1 << 0), /* User */
EFLAGS_SET = (1 << 1),
EFLAGS_PF = (1 << 2), /* User */
EFLAGS_AF = (1 << 4), /* User */
EFLAGS_ZF = (1 << 6), /* User */
EFLAGS_SF = (1 << 7), /* User */
EFLAGS_TF = (1 << 8), /* Priv */
EFLAGS_IF = (1 << 9), /* Priv */
EFLAGS_DF = (1 << 10), /* User */
EFLAGS_OF = (1 << 11), /* User */
EFLAGS_NT = (1 << 14), /* Priv */
EFLAGS_RF = (1 << 16), /* Priv */
EFLAGS_VM = (1 << 17), /* Priv */
EFLAGS_AC = (1 << 18), /* Priv */
EFLAGS_VIF = (1 << 19), /* Priv */
EFLAGS_VIP = (1 << 20), /* Priv */
EFLAGS_ID = (1 << 21), /* Priv */
EFLAGS_IOPL = 3 << EFLAGS_IOPL_SHIFT,
EFLAGS_ARITH = (EFLAGS_CF | EFLAGS_PF | EFLAGS_AF | EFLAGS_ZF |
EFLAGS_SF | EFLAGS_OF),
EFLAGS_USER = (EFLAGS_CF | EFLAGS_PF | EFLAGS_AF | EFLAGS_ZF |
EFLAGS_SF | EFLAGS_DF | EFLAGS_OF),
EFLAGS_PRIV = (EFLAGS_TF | EFLAGS_IF | EFLAGS_IOPL | EFLAGS_NT |
EFLAGS_RF | EFLAGS_VM | EFLAGS_AC | EFLAGS_VIF |
EFLAGS_VIP | EFLAGS_ID),
EFLAGS_ALL = (EFLAGS_CF | EFLAGS_PF | EFLAGS_AF | EFLAGS_ZF |
EFLAGS_SF | EFLAGS_DF | EFLAGS_OF | EFLAGS_TF |
EFLAGS_IF | EFLAGS_IOPL | EFLAGS_NT | EFLAGS_RF |
EFLAGS_VM | EFLAGS_AC | EFLAGS_VIF | EFLAGS_VIP |
EFLAGS_ID),
EFLAGS_ALL_16 = EFLAGS_ALL & 0xffff,
EFLAGS_REAL_32 = (EFLAGS_ALL & ~(EFLAGS_VIP | EFLAGS_VIF | EFLAGS_VM)),
EFLAGS_V8086_32 = (EFLAGS_ALL & ~(EFLAGS_VIP | EFLAGS_VIF |
EFLAGS_VM | EFLAGS_IOPL)),
EFLAGS_REAL_16 = EFLAGS_REAL_32 & 0xffff,
EFLAGS_V8086_16 = EFLAGS_V8086_32 & 0xffff,
EFLAGS_CLEAR_ON_EXC = (EFLAGS_TF | EFLAGS_VM | EFLAGS_RF | EFLAGS_NT),
EFLAGS__4 = 0x7fffffff /* ensure 4 byte encoding */
} x86_FLAGS;
#endif // ifndef _VM_BASIC_DEFS_H_

1626
vendor/github.com/sigma/vmw-guestinfo/include/x86cpuid.h generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,455 @@
/*********************************************************
* Copyright (C) 2003-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* x86cpuid_asm.h
*
* CPUID-related assembly functions.
*/
#ifndef _X86CPUID_ASM_H_
#define _X86CPUID_ASM_H_
#include "vm_basic_asm.h"
#include "x86cpuid.h"
/*
* x86-64 windows doesn't support inline asm so we have to use these
* intrinsic functions defined in the compiler. Not all of these are well
* documented. There is an array in the compiler dll (c1.dll) which has
* an array of the names of all the intrinsics minus the leading
* underscore. Searching around in the ntddk.h file can also be helpful.
*
* The declarations for the intrinsic functions were taken from the DDK.
* Our declarations must match the ddk's otherwise the 64-bit c++ compiler
* will complain about second linkage of the intrinsic functions.
* We define the intrinsic using the basic types corresponding to the
* Windows typedefs. This avoids having to include windows header files
* to get to the windows types.
*/
#ifdef _MSC_VER
#ifdef __cplusplus
extern "C" {
#endif
#ifdef VM_X86_64
/*
* intrinsic functions only supported by x86-64 windows as of 2k3sp1
*/
void __cpuid(int regs[4], int eax);
#pragma intrinsic(__cpuid)
#endif /* VM_X86_64 */
#ifdef __cplusplus
}
#endif
#endif /* _MSC_VER */
#ifdef __GNUC__ // {
/*
* Checked against the Intel manual and GCC --hpreg
*
* Need __volatile__ and "memory" since CPUID has a synchronizing effect.
* The CPUID may also change at runtime (APIC flag, etc).
*
*/
/*
* %ebx is reserved on i386 PIC. Apple's gcc-5493 (gcc 4.0) compiling
* for x86_64 incorrectly errors out saying %ebx is reserved. This is
* Apple bug 7304232.
*/
#if vm_x86_64 ? (defined __APPLE_CC__ && __APPLE_CC__ == 5493) : defined __PIC__
#if vm_x86_64
/*
* Note that this generates movq %rbx,%rbx; cpuid; xchgq %rbx,%rbx ...
* Unfortunately Apple's assembler does not have .ifnes, and I cannot
* figure out how to do that with .if. If we ever enable this code
* on other 64bit systems, both movq & xchgq should be surrounded by
* .ifnes \"%%rbx\", \"%q1\" & .endif
*/
#define VM_CPUID_BLOCK "movq %%rbx, %q1\n\t" \
"cpuid\n\t" \
"xchgq %%rbx, %q1\n\t"
#define VM_EBX_OUT(reg) "=&r"(reg)
#else
#define VM_CPUID_BLOCK "movl %%ebx, %1\n\t" \
"cpuid\n\t" \
"xchgl %%ebx, %1\n\t"
#define VM_EBX_OUT(reg) "=&rm"(reg)
#endif
#else
#define VM_CPUID_BLOCK "cpuid"
#define VM_EBX_OUT(reg) "=b"(reg)
#endif
static INLINE void
__GET_CPUID(int eax, // IN
CPUIDRegs *regs) // OUT
{
__asm__ __volatile__(
VM_CPUID_BLOCK
: "=a" (regs->eax), VM_EBX_OUT(regs->ebx), "=c" (regs->ecx), "=d" (regs->edx)
: "a" (eax)
: "memory"
);
}
static INLINE void
__GET_CPUID2(int eax, // IN
int ecx, // IN
CPUIDRegs *regs) // OUT
{
__asm__ __volatile__(
VM_CPUID_BLOCK
: "=a" (regs->eax), VM_EBX_OUT(regs->ebx), "=c" (regs->ecx), "=d" (regs->edx)
: "a" (eax), "c" (ecx)
: "memory"
);
}
static INLINE uint32
__GET_EAX_FROM_CPUID(int eax) // IN
{
uint32 ebx;
__asm__ __volatile__(
VM_CPUID_BLOCK
: "=a" (eax), VM_EBX_OUT(ebx)
: "a" (eax)
: "memory", "%ecx", "%edx"
);
return eax;
}
static INLINE uint32
__GET_EBX_FROM_CPUID(int eax) // IN
{
uint32 ebx;
__asm__ __volatile__(
VM_CPUID_BLOCK
: "=a" (eax), VM_EBX_OUT(ebx)
: "a" (eax)
: "memory", "%ecx", "%edx"
);
return ebx;
}
static INLINE uint32
__GET_ECX_FROM_CPUID(int eax) // IN
{
uint32 ecx;
uint32 ebx;
__asm__ __volatile__(
VM_CPUID_BLOCK
: "=a" (eax), VM_EBX_OUT(ebx), "=c" (ecx)
: "a" (eax)
: "memory", "%edx"
);
return ecx;
}
static INLINE uint32
__GET_EDX_FROM_CPUID(int eax) // IN
{
uint32 edx;
uint32 ebx;
__asm__ __volatile__(
VM_CPUID_BLOCK
: "=a" (eax), VM_EBX_OUT(ebx), "=d" (edx)
: "a" (eax)
: "memory", "%ecx"
);
return edx;
}
static INLINE uint32
__GET_EAX_FROM_CPUID4(int ecx) // IN
{
uint32 eax;
uint32 ebx;
__asm__ __volatile__(
VM_CPUID_BLOCK
: "=a" (eax), VM_EBX_OUT(ebx), "=c" (ecx)
: "a" (4), "c" (ecx)
: "memory", "%edx"
);
return eax;
}
#undef VM_CPUID_BLOCK
#undef VM_EBX_OUT
#elif defined(_MSC_VER) // } {
static INLINE void
__GET_CPUID(int input, CPUIDRegs *regs)
{
#ifdef VM_X86_64
__cpuid((int *)regs, input);
#else
__asm push esi
__asm push ebx
__asm push ecx
__asm push edx
__asm mov eax, input
__asm mov esi, regs
__asm _emit 0x0f __asm _emit 0xa2
__asm mov 0x0[esi], eax
__asm mov 0x4[esi], ebx
__asm mov 0x8[esi], ecx
__asm mov 0xC[esi], edx
__asm pop edx
__asm pop ecx
__asm pop ebx
__asm pop esi
#endif
}
#ifdef VM_X86_64
/*
* No inline assembly in Win64. Implemented in bora/lib/misc in
* cpuidMasm64.asm.
*/
extern void
__GET_CPUID2(int inputEax, int inputEcx, CPUIDRegs *regs);
#else // VM_X86_64
static INLINE void
__GET_CPUID2(int inputEax, int inputEcx, CPUIDRegs *regs)
{
__asm push esi
__asm push ebx
__asm push ecx
__asm push edx
__asm mov eax, inputEax
__asm mov ecx, inputEcx
__asm mov esi, regs
__asm _emit 0x0f __asm _emit 0xa2
__asm mov 0x0[esi], eax
__asm mov 0x4[esi], ebx
__asm mov 0x8[esi], ecx
__asm mov 0xC[esi], edx
__asm pop edx
__asm pop ecx
__asm pop ebx
__asm pop esi
}
#endif
static INLINE uint32
__GET_EAX_FROM_CPUID(int input)
{
#ifdef VM_X86_64
CPUIDRegs regs;
__cpuid((int *)&regs, input);
return regs.eax;
#else
uint32 output;
//NOT_TESTED();
__asm push ebx
__asm push ecx
__asm push edx
__asm mov eax, input
__asm _emit 0x0f __asm _emit 0xa2
__asm mov output, eax
__asm pop edx
__asm pop ecx
__asm pop ebx
return output;
#endif
}
static INLINE uint32
__GET_EBX_FROM_CPUID(int input)
{
#ifdef VM_X86_64
CPUIDRegs regs;
__cpuid((int *)&regs, input);
return regs.ebx;
#else
uint32 output;
//NOT_TESTED();
__asm push ebx
__asm push ecx
__asm push edx
__asm mov eax, input
__asm _emit 0x0f __asm _emit 0xa2
__asm mov output, ebx
__asm pop edx
__asm pop ecx
__asm pop ebx
return output;
#endif
}
static INLINE uint32
__GET_ECX_FROM_CPUID(int input)
{
#ifdef VM_X86_64
CPUIDRegs regs;
__cpuid((int *)&regs, input);
return regs.ecx;
#else
uint32 output;
//NOT_TESTED();
__asm push ebx
__asm push ecx
__asm push edx
__asm mov eax, input
__asm _emit 0x0f __asm _emit 0xa2
__asm mov output, ecx
__asm pop edx
__asm pop ecx
__asm pop ebx
return output;
#endif
}
static INLINE uint32
__GET_EDX_FROM_CPUID(int input)
{
#ifdef VM_X86_64
CPUIDRegs regs;
__cpuid((int *)&regs, input);
return regs.edx;
#else
uint32 output;
//NOT_TESTED();
__asm push ebx
__asm push ecx
__asm push edx
__asm mov eax, input
__asm _emit 0x0f __asm _emit 0xa2
__asm mov output, edx
__asm pop edx
__asm pop ecx
__asm pop ebx
return output;
#endif
}
#ifdef VM_X86_64
/*
* No inline assembly in Win64. Implemented in bora/lib/misc in
* cpuidMasm64.asm.
*/
extern uint32
__GET_EAX_FROM_CPUID4(int inputEcx);
#else // VM_X86_64
static INLINE uint32
__GET_EAX_FROM_CPUID4(int inputEcx)
{
uint32 output;
//NOT_TESTED();
__asm push ebx
__asm push ecx
__asm push edx
__asm mov eax, 4
__asm mov ecx, inputEcx
__asm _emit 0x0f __asm _emit 0xa2
__asm mov output, eax
__asm pop edx
__asm pop ecx
__asm pop ebx
return output;
}
#endif // VM_X86_64
#else // }
#error
#endif
#define CPUID_FOR_SIDE_EFFECTS() ((void)__GET_EAX_FROM_CPUID(0))
static INLINE void
__GET_CPUID4(int inputEcx, CPUIDRegs *regs)
{
__GET_CPUID2(4, inputEcx, regs);
}
/* The first parameter is used as an rvalue and then as an lvalue. */
#define GET_CPUID(_ax, _bx, _cx, _dx) { \
CPUIDRegs regs; \
__GET_CPUID(_ax, &regs); \
_ax = regs.eax; \
_bx = regs.ebx; \
_cx = regs.ecx; \
_dx = regs.edx; \
}
#endif

View File

@@ -0,0 +1,51 @@
/*********************************************************
* Copyright (C) 1998-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
#ifndef _X86VENDOR_H_
#define _X86VENDOR_H_
/*
* CPU vendors
*/
typedef enum {
CPUID_VENDOR_UNKNOWN,
CPUID_VENDOR_COMMON,
CPUID_VENDOR_INTEL,
CPUID_VENDOR_AMD,
CPUID_VENDOR_CYRIX,
CPUID_VENDOR_VIA,
CPUID_NUM_VENDORS
} CpuidVendor;
#endif