diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
commit | f215e02bf85f68d3a6106c2a1f4f7f063f819064 (patch) | |
tree | 6bb5b92c046312c4e95ac2620b10ddf482d3fa8b /src/VBox/Runtime/win | |
parent | Initial commit. (diff) | |
download | virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.tar.xz virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.zip |
Adding upstream version 7.0.14-dfsg.upstream/7.0.14-dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/Runtime/win')
23 files changed, 2004 insertions, 0 deletions
diff --git a/src/VBox/Runtime/win/Makefile.kup b/src/VBox/Runtime/win/Makefile.kup new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/VBox/Runtime/win/Makefile.kup diff --git a/src/VBox/Runtime/win/RTErrConvertFromWin32.cpp b/src/VBox/Runtime/win/RTErrConvertFromWin32.cpp new file mode 100644 index 00000000..acc28fc3 --- /dev/null +++ b/src/VBox/Runtime/win/RTErrConvertFromWin32.cpp @@ -0,0 +1,471 @@ +/* $Id: RTErrConvertFromWin32.cpp $ */ +/** @file + * IPRT - Convert win32 error codes to iprt status codes. + */ + +/* + * Copyright (C) 2006-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * 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 GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include <iprt/win/windows.h> + +#include <iprt/err.h> +#include <iprt/log.h> +#include <iprt/assert.h> + + +RTR3DECL(int) RTErrConvertFromWin32(unsigned uNativeCode) +{ + /* very fast check for no error. */ + if (uNativeCode == ERROR_SUCCESS) + return(VINF_SUCCESS); + + /* process error codes. */ + switch (uNativeCode) + { + case ERROR_INVALID_FUNCTION: return VERR_INVALID_FUNCTION; + case ERROR_FILE_NOT_FOUND: return VERR_FILE_NOT_FOUND; + case ERROR_PATH_NOT_FOUND: return VERR_PATH_NOT_FOUND; + case ERROR_TOO_MANY_OPEN_FILES: return VERR_TOO_MANY_OPEN_FILES; + case ERROR_ACCESS_DENIED: return VERR_ACCESS_DENIED; + case ERROR_NOACCESS: return VERR_INVALID_POINTER; /* (STATUS_ACCESS_VIOLATION, STATUS_DATATYPE_MISALIGNMENT, STATUS_DATATYPE_MISALIGNMENT_ERROR) */ + + case ERROR_INVALID_HANDLE: + case ERROR_DIRECT_ACCESS_HANDLE: return VERR_INVALID_HANDLE; + + case ERROR_NO_SYSTEM_RESOURCES: /** @todo better translation */ + case ERROR_NOT_ENOUGH_MEMORY: + case ERROR_OUTOFMEMORY: return VERR_NO_MEMORY; + + case ERROR_INVALID_DRIVE: return VERR_INVALID_DRIVE; + case ERROR_CURRENT_DIRECTORY: return VERR_CANT_DELETE_DIRECTORY; + case ERROR_NOT_SAME_DEVICE: return VERR_NOT_SAME_DEVICE; + case ERROR_NO_MORE_FILES: return VERR_NO_MORE_FILES; + case ERROR_WRITE_PROTECT: return VERR_WRITE_PROTECT; + case ERROR_BAD_UNIT: return VERR_IO_BAD_UNIT; + case ERROR_NOT_READY: return VERR_IO_NOT_READY; + case ERROR_BAD_COMMAND: return VERR_IO_BAD_COMMAND; + case ERROR_CRC: return VERR_IO_CRC; + case ERROR_BAD_LENGTH: return VERR_IO_BAD_LENGTH; + case ERROR_SEEK: return VERR_SEEK; + case ERROR_NOT_DOS_DISK: return VERR_DISK_INVALID_FORMAT; + case ERROR_SECTOR_NOT_FOUND: return VERR_IO_SECTOR_NOT_FOUND; + case ERROR_WRITE_FAULT: return VERR_WRITE_ERROR; + case ERROR_READ_FAULT: return VERR_READ_ERROR; + case ERROR_GEN_FAILURE: return VERR_IO_GEN_FAILURE; + case ERROR_SHARING_VIOLATION: return VERR_SHARING_VIOLATION; + case ERROR_LOCK_VIOLATION: return VERR_FILE_LOCK_VIOLATION; + case ERROR_HANDLE_EOF: return VERR_EOF; + case ERROR_NOT_LOCKED: return VERR_FILE_NOT_LOCKED; + case ERROR_DIR_NOT_EMPTY: return VERR_DIR_NOT_EMPTY; + + case ERROR_HANDLE_DISK_FULL: + case ERROR_DISK_FULL: return VERR_DISK_FULL; + + case ERROR_NOT_SUPPORTED: return VERR_NOT_SUPPORTED; + + case ERROR_INVALID_PARAMETER: + case ERROR_BAD_ARGUMENTS: + case ERROR_INVALID_FLAGS: return VERR_INVALID_PARAMETER; + + case ERROR_REM_NOT_LIST: return VERR_NET_IO_ERROR; + + case ERROR_BAD_NETPATH: + case ERROR_NETNAME_DELETED: return VERR_NET_HOST_NOT_FOUND; + + case ERROR_BAD_NET_NAME: + case ERROR_DEV_NOT_EXIST: return VERR_NET_PATH_NOT_FOUND; + + case ERROR_NETWORK_BUSY: + case ERROR_TOO_MANY_CMDS: + case ERROR_TOO_MANY_NAMES: + case ERROR_TOO_MANY_SESS: + case ERROR_OUT_OF_STRUCTURES: return VERR_NET_OUT_OF_RESOURCES; + + case ERROR_PRINTQ_FULL: + case ERROR_NO_SPOOL_SPACE: + case ERROR_PRINT_CANCELLED: return VERR_NET_PRINT_ERROR; + + case ERROR_DUP_NAME: + case ERROR_ADAP_HDW_ERR: + case ERROR_BAD_NET_RESP: + case ERROR_UNEXP_NET_ERR: + case ERROR_BAD_REM_ADAP: + case ERROR_NETWORK_ACCESS_DENIED: + case ERROR_BAD_DEV_TYPE: + case ERROR_SHARING_PAUSED: + case ERROR_REQ_NOT_ACCEP: + case ERROR_REDIR_PAUSED: + case ERROR_ALREADY_ASSIGNED: + case ERROR_INVALID_PASSWORD: + case ERROR_NET_WRITE_FAULT: return VERR_NET_IO_ERROR; + + case ERROR_FILE_EXISTS: + case ERROR_ALREADY_EXISTS: return VERR_ALREADY_EXISTS; + + case ERROR_CANNOT_MAKE: return VERR_CANT_CREATE; + case ERROR_NO_PROC_SLOTS: return VERR_MAX_PROCS_REACHED; + case ERROR_TOO_MANY_SEMAPHORES: return VERR_TOO_MANY_SEMAPHORES; + case ERROR_EXCL_SEM_ALREADY_OWNED: return VERR_EXCL_SEM_ALREADY_OWNED; + case ERROR_SEM_IS_SET: return VERR_SEM_IS_SET; + case ERROR_TOO_MANY_SEM_REQUESTS: return VERR_TOO_MANY_SEM_REQUESTS; + case ERROR_SEM_OWNER_DIED: return VERR_SEM_OWNER_DIED; + case ERROR_DRIVE_LOCKED: return VERR_DRIVE_LOCKED; + case ERROR_BROKEN_PIPE: return VERR_BROKEN_PIPE; + case ERROR_OPEN_FAILED: return VERR_OPEN_FAILED; + + case ERROR_BUFFER_OVERFLOW: + case ERROR_INSUFFICIENT_BUFFER: return VERR_BUFFER_OVERFLOW; + + case ERROR_NO_MORE_SEARCH_HANDLES: return VERR_NO_MORE_SEARCH_HANDLES; + + case ERROR_SEM_TIMEOUT: + case WAIT_TIMEOUT: + case ERROR_SERVICE_REQUEST_TIMEOUT: + case ERROR_COUNTER_TIMEOUT: + case ERROR_TIMEOUT: return VERR_TIMEOUT; + + case ERROR_INVALID_NAME: + case ERROR_BAD_DEVICE: + case ERROR_BAD_PATHNAME: return VERR_INVALID_NAME; + + case ERROR_NEGATIVE_SEEK: return VERR_NEGATIVE_SEEK; + case ERROR_SEEK_ON_DEVICE: return VERR_SEEK_ON_DEVICE; + + case ERROR_SIGNAL_REFUSED: + case ERROR_NO_SIGNAL_SENT: return VERR_SIGNAL_REFUSED; + + case ERROR_SIGNAL_PENDING: return VERR_SIGNAL_PENDING; + case ERROR_MAX_THRDS_REACHED: return VERR_MAX_THRDS_REACHED; + case ERROR_LOCK_FAILED: return VERR_FILE_LOCK_FAILED; + case ERROR_SEM_NOT_FOUND: return VERR_SEM_NOT_FOUND; + case ERROR_FILENAME_EXCED_RANGE: return VERR_FILENAME_TOO_LONG; + case ERROR_INVALID_SIGNAL_NUMBER: return VERR_SIGNAL_INVALID; + + case ERROR_BAD_PIPE: return VERR_BAD_PIPE; + case ERROR_PIPE_BUSY: return VERR_PIPE_BUSY; + case ERROR_NO_DATA: return VERR_NO_DATA; + case ERROR_PIPE_NOT_CONNECTED: return VERR_PIPE_NOT_CONNECTED; + case ERROR_MORE_DATA: return VERR_MORE_DATA; + case ERROR_NOT_OWNER: return VERR_NOT_OWNER; + case ERROR_TOO_MANY_POSTS: return VERR_TOO_MANY_POSTS; + + case ERROR_PIPE_CONNECTED: + case ERROR_PIPE_LISTENING: return VERR_PIPE_IO_ERROR; + + case ERROR_OPERATION_ABORTED: return VERR_INTERRUPTED; + case ERROR_NO_UNICODE_TRANSLATION: return VERR_NO_TRANSLATION; + + case RPC_S_INVALID_STRING_UUID: return VERR_INVALID_UUID_FORMAT; + + case ERROR_PROC_NOT_FOUND: return VERR_SYMBOL_NOT_FOUND; + case ERROR_MOD_NOT_FOUND: return VERR_MODULE_NOT_FOUND; + + case ERROR_INVALID_EXE_SIGNATURE: return VERR_INVALID_EXE_SIGNATURE; + case ERROR_BAD_EXE_FORMAT: return VERR_BAD_EXE_FORMAT; + case ERROR_FILE_CORRUPT: return VERR_BAD_EXE_FORMAT; + case ERROR_RESOURCE_DATA_NOT_FOUND: return VERR_NO_DATA; /// @todo fix ERROR_RESOURCE_DATA_NOT_FOUND translation + case ERROR_INVALID_ADDRESS: return VERR_INVALID_POINTER; /// @todo fix ERROR_INVALID_ADDRESS translation - dbghelp returns it on some line number queries. + + case ERROR_CANCELLED: return VERR_CANCELLED; + case ERROR_USER_MAPPED_FILE: return VERR_SHARING_VIOLATION; + case ERROR_DIRECTORY: return VERR_NOT_A_DIRECTORY; + + case ERROR_TRUSTED_RELATIONSHIP_FAILURE: + case ERROR_TRUSTED_DOMAIN_FAILURE: + return VERR_AUTHENTICATION_FAILURE; + case ERROR_LOGON_FAILURE: return VERR_AUTHENTICATION_FAILURE; + case ERROR_PRIVILEGE_NOT_HELD: return VERR_PRIVILEGE_NOT_HELD; + + case ERROR_PASSWORD_EXPIRED: + case ERROR_ACCOUNT_RESTRICTION: + case ERROR_PASSWORD_RESTRICTION: + case ERROR_ACCOUNT_DISABLED: return VERR_ACCOUNT_RESTRICTED; + + case ERROR_INVALID_IMAGE_HASH: return VERR_LDR_IMAGE_HASH; + case ERROR_UNRECOGNIZED_VOLUME: return VERR_MEDIA_NOT_RECOGNIZED; + case ERROR_ELEVATION_REQUIRED: return VERR_PROC_ELEVATION_REQUIRED; + + case ERROR_ENVVAR_NOT_FOUND: return VERR_ENV_VAR_NOT_FOUND; + + + case ERROR_SERVICE_ALREADY_RUNNING: return VERR_ALREADY_LOADED; /* Not the best match, but seen it with VBoxSup.sys. */ + + + /* + * Winsocket errors are mostly BSD errno.h wrappers. + * This is copied from RTErrConvertFromErrno() and checked against winsock.h. + * Please, keep things in sync! + */ +#ifdef WSAEPERM + case WSAEPERM: return VERR_ACCESS_DENIED; /* 1 */ +#endif +#ifdef WSAENOENT + case WSAENOENT: return VERR_FILE_NOT_FOUND; +#endif +#ifdef WSAESRCH + case WSAESRCH: return VERR_PROCESS_NOT_FOUND; +#endif + case WSAEINTR: return VERR_INTERRUPTED; +#ifdef WSAEIO + case WSAEIO: return VERR_DEV_IO_ERROR; +#endif +#ifdef WSAE2BIG + case WSAE2BIG: return VERR_TOO_MUCH_DATA; +#endif +#ifdef WSAENOEXEC + case WSAENOEXEC: return VERR_BAD_EXE_FORMAT; +#endif + case WSAEBADF: return VERR_INVALID_HANDLE; +#ifdef WSAECHILD + case WSAECHILD: return VERR_PROCESS_NOT_FOUND; //... /* 10 */ +#endif + case WSAEWOULDBLOCK: return VERR_TRY_AGAIN; /* EAGAIN */ +#ifdef WSAENOMEM + case WSAENOMEM: return VERR_NO_MEMORY; +#endif + case WSAEACCES: return VERR_ACCESS_DENIED; + case WSAEFAULT: return VERR_INVALID_POINTER; + //case WSAENOTBLK: return VERR_; +#ifdef WSAEBUSY + case WSAEBUSY: return VERR_DEV_IO_ERROR; +#endif +#ifdef WSAEEXIST + case WSAEEXIST: return VERR_ALREADY_EXISTS; +#endif + //case WSAEXDEV: +#ifdef WSAENODEV + case WSAENODEV: return VERR_NOT_SUPPORTED; +#endif +#ifdef WSAENOTDIR + case WSAENOTDIR: return VERR_PATH_NOT_FOUND; /* 20 */ +#endif +#ifdef WSAEISDIR + case WSAEISDIR: return VERR_FILE_NOT_FOUND; +#endif + case WSAEINVAL: return VERR_INVALID_PARAMETER; +#ifdef WSAENFILE + case WSAENFILE: return VERR_TOO_MANY_OPEN_FILES; +#endif + case WSAEMFILE: return VERR_TOO_MANY_OPEN_FILES; +#ifdef WSAENOTTY + case WSAENOTTY: return VERR_INVALID_FUNCTION; +#endif +#ifdef WSAETXTBSY + case WSAETXTBSY: return VERR_SHARING_VIOLATION; +#endif + //case WSAEFBIG: +#ifdef WSAENOSPC + case WSAENOSPC: return VERR_DISK_FULL; +#endif +#ifdef WSAESPIPE + case WSAESPIPE: return VERR_SEEK_ON_DEVICE; +#endif +#ifdef WSAEROFS + case WSAEROFS: return VERR_WRITE_PROTECT; /* 30 */ +#endif + //case WSAEMLINK: +#ifdef WSAEPIPE + case WSAEPIPE: return VERR_BROKEN_PIPE; +#endif +#ifdef WSAEDOM + case WSAEDOM: return VERR_INVALID_PARAMETER; +#endif +#ifdef WSAERANGE + case WSAERANGE: return VERR_INVALID_PARAMETER; +#endif +#ifdef WSAEDEADLK + case WSAEDEADLK: return VERR_DEADLOCK; +#endif + case WSAENAMETOOLONG: return VERR_FILENAME_TOO_LONG; +#ifdef WSAENOLCK + case WSAENOLCK: return VERR_FILE_LOCK_FAILED; +#endif +#ifdef WSAENOSYS + case WSAENOSYS: return VERR_NOT_SUPPORTED; +#endif + case WSAENOTEMPTY: return VERR_CANT_DELETE_DIRECTORY; + case WSAELOOP: return VERR_TOO_MANY_SYMLINKS; /* 40 */ + //case WSAENOMSG 42 /* No message of desired type */ + //case WSAEIDRM 43 /* Identifier removed */ + //case WSAECHRNG 44 /* Channel number out of range */ + //case WSAEL2NSYNC 45 /* Level 2 not synchronized */ + //case WSAEL3HLT 46 /* Level 3 halted */ + //case WSAEL3RST 47 /* Level 3 reset */ + //case WSAELNRNG 48 /* Link number out of range */ + //case WSAEUNATCH 49 /* Protocol driver not attached */ + //case WSAENOCSI 50 /* No CSI structure available */ + //case WSAEL2HLT 51 /* Level 2 halted */ + //case WSAEBADE 52 /* Invalid exchange */ + //case WSAEBADR 53 /* Invalid request descriptor */ + //case WSAEXFULL 54 /* Exchange full */ + //case WSAENOANO 55 /* No anode */ + //case WSAEBADRQC 56 /* Invalid request code */ + //case WSAEBADSLT 57 /* Invalid slot */ + //case 58: + //case WSAEBFONT 59 /* Bad font file format */ + //case WSAENOSTR 60 /* Device not a stream */ +#ifdef WSAENODATA + case WSAENODATA: return VERR_NO_DATA; +#endif + //case WSAETIME 62 /* Timer expired */ + //case WSAENOSR 63 /* Out of streams resources */ +#ifdef WSAENONET + case WSAENONET: return VERR_NET_NO_NETWORK; +#endif + //case WSAENOPKG 65 /* Package not installed */ + //case WSAEREMOTE 66 /* Object is remote */ + //case WSAENOLINK 67 /* Link has been severed */ + //case WSAEADV 68 /* Advertise error */ + //case WSAESRMNT 69 /* Srmount error */ + //case WSAECOMM 70 /* Communication error on send */ + //case WSAEPROTO 71 /* Protocol error */ + //case WSAEMULTIHOP 72 /* Multihop attempted */ + //case WSAEDOTDOT 73 /* RFS specific error */ + //case WSAEBADMSG 74 /* Not a data message */ +#ifdef WSAEOVERFLOW + case WSAEOVERFLOW: return VERR_TOO_MUCH_DATA; +#endif +#ifdef WSAENOTUNIQ + case WSAENOTUNIQ: return VERR_NET_NOT_UNIQUE_NAME; +#endif +#ifdef WSAEBADFD + case WSAEBADFD: return VERR_INVALID_HANDLE; +#endif + //case WSAEREMCHG 78 /* Remote address changed */ + //case WSAELIBACC 79 /* Can not access a needed shared library */ + //case WSAELIBBAD 80 /* Accessing a corrupted shared library */ + //case WSAELIBSCN 81 /* .lib section in a.out corrupted */ + //case WSAELIBMAX 82 /* Attempting to link in too many shared libraries */ + //case WSAELIBEXEC 83 /* Cannot exec a shared library directly */ +#ifdef WSAEILSEQ + case WSAEILSEQ: return VERR_NO_TRANSLATION; +#endif +#ifdef WSAERESTART + case WSAERESTART: return VERR_INTERRUPTED; +#endif + //case WSAESTRPIPE 86 /* Streams pipe error */ + //case WSAEUSERS 87 /* Too many users */ + case WSAENOTSOCK: return VERR_NET_NOT_SOCKET; + case WSAEDESTADDRREQ: return VERR_NET_DEST_ADDRESS_REQUIRED; + case WSAEMSGSIZE: return VERR_NET_MSG_SIZE; + case WSAEPROTOTYPE: return VERR_NET_PROTOCOL_TYPE; + case WSAENOPROTOOPT: return VERR_NET_PROTOCOL_NOT_AVAILABLE; + case WSAEPROTONOSUPPORT: return VERR_NET_PROTOCOL_NOT_SUPPORTED; + case WSAESOCKTNOSUPPORT: return VERR_NET_SOCKET_TYPE_NOT_SUPPORTED; + case WSAEOPNOTSUPP: return VERR_NET_OPERATION_NOT_SUPPORTED; + case WSAEPFNOSUPPORT: return VERR_NET_PROTOCOL_FAMILY_NOT_SUPPORTED; + case WSAEAFNOSUPPORT: return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED; + case WSAEADDRINUSE: return VERR_NET_ADDRESS_IN_USE; + case WSAEADDRNOTAVAIL: return VERR_NET_ADDRESS_NOT_AVAILABLE; + case WSAENETDOWN: return VERR_NET_DOWN; + case WSAENETUNREACH: return VERR_NET_UNREACHABLE; + case WSAENETRESET: return VERR_NET_CONNECTION_RESET; + case WSAECONNABORTED: return VERR_NET_CONNECTION_ABORTED; + case WSAECONNRESET: return VERR_NET_CONNECTION_RESET_BY_PEER; + case WSAENOBUFS: return VERR_NET_NO_BUFFER_SPACE; + case WSAEISCONN: return VERR_NET_ALREADY_CONNECTED; + case WSAENOTCONN: return VERR_NET_NOT_CONNECTED; + case WSAESHUTDOWN: return VERR_NET_SHUTDOWN; + case WSAETOOMANYREFS: return VERR_NET_TOO_MANY_REFERENCES; + case WSAETIMEDOUT: return VERR_TIMEOUT; + case WSAECONNREFUSED: return VERR_NET_CONNECTION_REFUSED; + case WSAEHOSTDOWN: return VERR_NET_HOST_DOWN; + case WSAEHOSTUNREACH: return VERR_NET_HOST_UNREACHABLE; + case WSAEALREADY: return VERR_NET_ALREADY_IN_PROGRESS; + case WSAEINPROGRESS: return VERR_NET_IN_PROGRESS; + case WSAEPROVIDERFAILEDINIT: return VERR_NET_INIT_FAILED; + + //case WSAESTALE 116 /* Stale NFS file handle */ + //case WSAEUCLEAN 117 /* Structure needs cleaning */ + //case WSAENOTNAM 118 /* Not a XENIX named type file */ + //case WSAENAVAIL 119 /* No XENIX semaphores available */ + //case WSAEISNAM 120 /* Is a named type file */ + //case WSAEREMOTEIO 121 /* Remote I/O error */ + case WSAEDQUOT: return VERR_DISK_FULL; +#ifdef WSAENOMEDIUM + case WSAENOMEDIUM: return VERR_MEDIA_NOT_PRESENT; +#endif +#ifdef WSAEMEDIUMTYPE + case WSAEMEDIUMTYPE: return VERR_MEDIA_NOT_RECOGNIZED; +#endif + case WSAEPROCLIM: return VERR_MAX_PROCS_REACHED; + + //case WSAEDISCON: (WSABASEERR+101) + //case WSASYSNOTREADY (WSABASEERR+91) + //case WSAVERNOTSUPPORTED (WSABASEERR+92) + //case WSANOTINITIALISED (WSABASEERR+93) + +#ifdef WSAHOST_NOT_FOUND + case WSAHOST_NOT_FOUND: return VERR_NET_HOST_NOT_FOUND; +#endif +#ifdef WSATRY_AGAIN + case WSATRY_AGAIN: return VERR_TRY_AGAIN; +#endif +#ifndef WSANO_RECOVERY + case WSANO_RECOVERY: return VERR_IO_GEN_FAILURE; +#endif +#ifdef WSANO_DATA + case WSANO_DATA: return VERR_NET_ADDRESS_NOT_AVAILABLE; +#endif + + case 1272 /*STATUS_SMB_GUEST_LOGON_BLOCKED*/: return VERR_AUTHENTICATION_FAILURE; + + +#ifndef ERROR_NOT_A_REPARSE_POINT +# define ERROR_NOT_A_REPARSE_POINT 0x1126 +#endif + case ERROR_NOT_A_REPARSE_POINT: return VERR_NOT_SYMLINK; + + case NTE_BAD_ALGID: return VERR_CR_PKIX_UNKNOWN_DIGEST_TYPE; + + case ERROR_SERVICE_DOES_NOT_EXIST: return VERR_NOT_FOUND; + +#ifndef STATUS_ELEVATION_REQUIRED +# define STATUS_ELEVATION_REQUIRED 0xc000042c +#endif + case STATUS_ELEVATION_REQUIRED: return VERR_PRIVILEGE_NOT_HELD; + } + + /* unknown error. */ +#if !defined(IN_SUP_HARDENED_R3) \ + && !defined(IPRT_NO_CRT) /* Please, don't drag log.cpp into the no-CRT images! */ + AssertLogRelMsgFailed(("Unhandled error %u\n", uNativeCode)); +#else + /* hardened main has no LogRel */ + AssertMsgFailed(("Unhandled error %u\n", uNativeCode)); +#endif + return VERR_UNRESOLVED_ERROR; +} + diff --git a/src/VBox/Runtime/win/amd64/ASMAtomicBitClear.asm b/src/VBox/Runtime/win/amd64/ASMAtomicBitClear.asm new file mode 100644 index 00000000..0a7fb2cd --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMAtomicBitClear.asm @@ -0,0 +1,54 @@ +;; @file +; IPRT - ASMAtomicBitClear(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Atomically clears a bit in a bitmap. +; +; @param rcx pvBitmap Pointer to the bitmap. +; @param edx iBit The bit to toggle set. +; @remark No memory barrier, take care on smp. +; +RT_BEGINPROC ASMAtomicBitClear + lock btr [rcx], edx + ret +ENDPROC ASMAtomicBitClear + diff --git a/src/VBox/Runtime/win/amd64/ASMAtomicBitTestAndToggle.asm b/src/VBox/Runtime/win/amd64/ASMAtomicBitTestAndToggle.asm new file mode 100644 index 00000000..128521d9 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMAtomicBitTestAndToggle.asm @@ -0,0 +1,56 @@ +;; @file +; IPRT - ASMAtomicBitTestAndToggle(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Atomically tests and toggles a bit in a bitmap. +; +; @returns al(rax) true if the bit was set. +; @returns al(rax) false if the bit was clear. +; @param rcx pvBitmap Pointer to the bitmap. +; @param edx iBit The bit to test and toggle. +RT_BEGINPROC ASMAtomicBitTestAndToggle + lock btc [rcx], edx + sbb eax, eax + ret +ENDPROC ASMAtomicBitTestAndToggle + diff --git a/src/VBox/Runtime/win/amd64/ASMAtomicBitToggle.asm b/src/VBox/Runtime/win/amd64/ASMAtomicBitToggle.asm new file mode 100644 index 00000000..dc9d2d9a --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMAtomicBitToggle.asm @@ -0,0 +1,53 @@ +;; @file +; IPRT - ASMAtomicBitToggle(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Atomically toggles a bit in a bitmap. +; +; @param rcx pvBitmap Pointer to the bitmap. +; @param edx iBit The bit to test and set. +RT_BEGINPROC ASMAtomicBitToggle + lock btc [rcx], edx + ret +ENDPROC ASMAtomicBitToggle + diff --git a/src/VBox/Runtime/win/amd64/ASMAtomicReadU64.asm b/src/VBox/Runtime/win/amd64/ASMAtomicReadU64.asm new file mode 100644 index 00000000..bb2a1e10 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMAtomicReadU64.asm @@ -0,0 +1,55 @@ +;; @file +; IPRT - ASMAtomicReadU64(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Atomically Reads a unsigned 64-bit value. +; +; @returns rax Current *pu64 value +; @param rcx pu64 Pointer to the 64-bit variable to read. +; The memory pointed to must be writable. +; +RT_BEGINPROC ASMAtomicReadU64 + mov rax, [rcx] + ret +ENDPROC ASMAtomicReadU64 + diff --git a/src/VBox/Runtime/win/amd64/ASMAtomicXchgU8.asm b/src/VBox/Runtime/win/amd64/ASMAtomicXchgU8.asm new file mode 100644 index 00000000..b9fac068 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMAtomicXchgU8.asm @@ -0,0 +1,52 @@ +;; @file +; IPRT - ASMAtomicXchgU8(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; @returns al Current *pu8 value +; @param rcx pu8 Pointer to the 8-bit variable to update. +; @param dl u8 The 8-bit value to assign to *pu8. +RT_BEGINPROC ASMAtomicXchgU8 + xchg [rcx], dl + movzx eax, dl + ret +ENDPROC ASMAtomicXchgU8 + diff --git a/src/VBox/Runtime/win/amd64/ASMGetCS.asm b/src/VBox/Runtime/win/amd64/ASMGetCS.asm new file mode 100644 index 00000000..2373d624 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetCS.asm @@ -0,0 +1,52 @@ +;; @file +; IPRT - ASMGetCS(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the cs register. +; @returns cs. +; +RT_BEGINPROC ASMGetCS + mov eax, cs + ret +ENDPROC ASMGetCS + diff --git a/src/VBox/Runtime/win/amd64/ASMGetDR0.asm b/src/VBox/Runtime/win/amd64/ASMGetDR0.asm new file mode 100644 index 00000000..9194a5c6 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetDR0.asm @@ -0,0 +1,57 @@ +;; @file +; IPRT - ASMGetDR0(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the dr0 register value. +; @returns dr0. +; +RT_BEGINPROC ASMGetDR0 + mov rax, dr0 + ret +ENDPROC ASMGetDR0 + + +RT_BEGINPROC ASMSetDR0 + mov dr0, rcx + ret +ENDPROC ASMSetDR0 diff --git a/src/VBox/Runtime/win/amd64/ASMGetDR1.asm b/src/VBox/Runtime/win/amd64/ASMGetDR1.asm new file mode 100644 index 00000000..2860521a --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetDR1.asm @@ -0,0 +1,56 @@ +;; @file +; IPRT - ASMGetDR1(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the dr1 register value. +; @returns dr1. +; +RT_BEGINPROC ASMGetDR1 + mov rax, dr1 + ret +ENDPROC ASMGetDR1 + + +RT_BEGINPROC ASMSetDR1 + mov dr1, rcx + ret +ENDPROC ASMSetDR1 diff --git a/src/VBox/Runtime/win/amd64/ASMGetDR2.asm b/src/VBox/Runtime/win/amd64/ASMGetDR2.asm new file mode 100644 index 00000000..37a23fa4 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetDR2.asm @@ -0,0 +1,57 @@ +;; @file +; IPRT - ASMGetDR2(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the dr2 register value. +; @returns dr2. +; +RT_BEGINPROC ASMGetDR2 + mov rax, dr2 + ret +ENDPROC ASMGetDR2 + + +RT_BEGINPROC ASMSetDR2 + mov dr2, rcx + ret +ENDPROC ASMSetDR2 diff --git a/src/VBox/Runtime/win/amd64/ASMGetDR3.asm b/src/VBox/Runtime/win/amd64/ASMGetDR3.asm new file mode 100644 index 00000000..ad2b96a1 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetDR3.asm @@ -0,0 +1,57 @@ +;; @file +; IPRT - ASMGetDR3(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the dr3 register value. +; @returns dr3. +; +RT_BEGINPROC ASMGetDR3 + mov rax, dr3 + ret +ENDPROC ASMGetDR3 + + +RT_BEGINPROC ASMSetDR3 + mov dr3, rcx + ret +ENDPROC ASMSetDR3 diff --git a/src/VBox/Runtime/win/amd64/ASMGetDR6.asm b/src/VBox/Runtime/win/amd64/ASMGetDR6.asm new file mode 100644 index 00000000..2b5f3c96 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetDR6.asm @@ -0,0 +1,56 @@ +;; @file +; IPRT - ASMGetDR6(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the dr6 register value. +; @returns dr6. +; +RT_BEGINPROC ASMGetDR6 + mov rax, dr6 + ret +ENDPROC ASMGetDR6 + + +RT_BEGINPROC ASMSetDR6 + mov dr6, rcx + ret +ENDPROC ASMSetDR6 diff --git a/src/VBox/Runtime/win/amd64/ASMGetDR7.asm b/src/VBox/Runtime/win/amd64/ASMGetDR7.asm new file mode 100644 index 00000000..24e26bc9 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetDR7.asm @@ -0,0 +1,55 @@ +;; @file +; IPRT - ASMGetDR7(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the dr7 register value. +; @returns dr7. +; +RT_BEGINPROC ASMGetDR7 + mov rax, dr7 + ret +ENDPROC ASMGetDR7 + +RT_BEGINPROC ASMSetDR7 + mov dr7, rcx + ret +ENDPROC ASMSetDR7 diff --git a/src/VBox/Runtime/win/amd64/ASMGetDS.asm b/src/VBox/Runtime/win/amd64/ASMGetDS.asm new file mode 100644 index 00000000..998cdbc0 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetDS.asm @@ -0,0 +1,51 @@ +;; @file +; IPRT - ASMGetDS(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the ds register. +; @returns ds. +; +RT_BEGINPROC ASMGetDS + mov eax, DS + ret +ENDPROC ASMGetDS + diff --git a/src/VBox/Runtime/win/amd64/ASMGetES.asm b/src/VBox/Runtime/win/amd64/ASMGetES.asm new file mode 100644 index 00000000..47e950fb --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetES.asm @@ -0,0 +1,51 @@ +;; @file +; IPRT - ASMGetES(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the es register. +; @returns es. +; +RT_BEGINPROC ASMGetES + mov eax, es + ret +ENDPROC ASMGetES + diff --git a/src/VBox/Runtime/win/amd64/ASMGetFS.asm b/src/VBox/Runtime/win/amd64/ASMGetFS.asm new file mode 100644 index 00000000..42a8da5e --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetFS.asm @@ -0,0 +1,51 @@ +;; @file +; IPRT - ASMGetFS(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the fs register. +; @returns fs. +; +RT_BEGINPROC ASMGetFS + mov eax, fs + ret +ENDPROC ASMGetFS + diff --git a/src/VBox/Runtime/win/amd64/ASMGetGS.asm b/src/VBox/Runtime/win/amd64/ASMGetGS.asm new file mode 100644 index 00000000..c6afd691 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetGS.asm @@ -0,0 +1,51 @@ +;; @file +; IPRT - ASMGetGS(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the gs register. +; @returns gs. +; +RT_BEGINPROC ASMGetGS + mov eax, gs + ret +ENDPROC ASMGetGS + diff --git a/src/VBox/Runtime/win/amd64/ASMGetSS.asm b/src/VBox/Runtime/win/amd64/ASMGetSS.asm new file mode 100644 index 00000000..5285c36d --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMGetSS.asm @@ -0,0 +1,51 @@ +;; @file +; IPRT - ASMGetSS(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Get the ss register. +; @returns ss. +; +RT_BEGINPROC ASMGetSS + mov eax, ss + ret +ENDPROC ASMGetSS + diff --git a/src/VBox/Runtime/win/amd64/ASMProbeReadByte.asm b/src/VBox/Runtime/win/amd64/ASMProbeReadByte.asm new file mode 100644 index 00000000..2f419e35 --- /dev/null +++ b/src/VBox/Runtime/win/amd64/ASMProbeReadByte.asm @@ -0,0 +1,58 @@ +;; @file +; IPRT - ASMProbeReadByte(). +; + +; +; Copyright (C) 2006-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; 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 GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included +; in the VirtualBox distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; +; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 +; + +;******************************************************************************* +;* Header Files * +;******************************************************************************* +%include "iprt/asmdefs.mac" + +BEGINCODE + +;; +; Probes a byte pointer for read access. +; +; While the function will not fault if the byte is not read accessible, +; the idea is to do this in a safe place like before acquiring locks +; and such like. +; +; Also, this functions guarantees that an eager compiler is not going +; to optimize the probing away. +; +; @param rcx pvByte Pointer to the byte. +RT_BEGINPROC ASMProbeReadByte + mov al, [rcx] + ret +ENDPROC ASMProbeReadByte + diff --git a/src/VBox/Runtime/win/amd64/Makefile.kup b/src/VBox/Runtime/win/amd64/Makefile.kup new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/VBox/Runtime/win/amd64/Makefile.kup diff --git a/src/VBox/Runtime/win/errmsgwin-sorter.cpp b/src/VBox/Runtime/win/errmsgwin-sorter.cpp new file mode 100644 index 00000000..e281038d --- /dev/null +++ b/src/VBox/Runtime/win/errmsgwin-sorter.cpp @@ -0,0 +1,335 @@ +/* $Id: errmsgwin-sorter.cpp $ */ +/** @file + * IPRT - Status code messages, Windows, sorter build program. + */ + +/* + * Copyright (C) 2006-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * 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 GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include <iprt/win/windows.h> + +#include <iprt/errcore.h> +#include <iprt/asm.h> +#include <iprt/string.h> + +#include <stdio.h> +#include <stdlib.h> + + +/* + * Include the string table code. + */ +#define BLDPROG_STRTAB_MAX_STRLEN 1024 +#define BLDPROG_STRTAB_WITH_COMPRESSION +#define BLDPROG_STRTAB_PURE_ASCII +#define BLDPROG_STRTAB_WITH_CAMEL_WORDS +#include <iprt/bldprog-strtab-template.cpp.h> + + +/********************************************************************************************************************************* +* Defined Constants And Macros * +*********************************************************************************************************************************/ +/* This is define casts the result to DWORD, whereas HRESULT and RTWINERRMSG + are using long, causing newer compilers to complain. */ +#undef _NDIS_ERROR_TYPEDEF_ +#define _NDIS_ERROR_TYPEDEF_(lErr) (long)(lErr) + + +/********************************************************************************************************************************* +* Structures and Typedefs * +*********************************************************************************************************************************/ +typedef long VBOXSTATUSTYPE; /* used by errmsgvboxcomdata.h */ + +/** Used for raw-input and sorting. */ +typedef struct RTWINERRMSGINT1 +{ + /** Pointer to the full message string. */ + const char *pszMsgFull; + /** Pointer to the define string. */ + const char *pszDefine; + /** Status code number. */ + long iCode; + /** Set if duplicate. */ + bool fDuplicate; +} RTWINERRMSGINT1; +typedef RTWINERRMSGINT1 *PRTWINERRMSGINT1; + + +/** This is used when building the string table and printing it. */ +typedef struct RTWINERRMSGINT2 +{ + /** The full message string. */ + BLDPROGSTRING MsgFull; + /** The define string. */ + BLDPROGSTRING Define; + /** Pointer to the define string. */ + const char *pszDefine; + /** Status code number. */ + long iCode; +} RTWINERRMSGINT2; +typedef RTWINERRMSGINT2 *PRTWINERRMSGINT2; + + +/********************************************************************************************************************************* +* Global Variables * +*********************************************************************************************************************************/ +static const char *g_pszProgName = "errmsgwin-sorter"; +static RTWINERRMSGINT1 g_aStatusMsgs[] = +{ +#if !defined(IPRT_NO_ERROR_DATA) && !defined(DOXYGEN_RUNNING) +# include "errmsgwindata.h" +# if defined(VBOX) && !defined(IN_GUEST) +# include "errmsgvboxcomdata.h" +# endif + +/* A few hardcoded items not in winerror.h */ +# define HARDCODED_ENTRY(a_Name, aValue) { #a_Name, #a_Name, aValue, false } + HARDCODED_ENTRY(AUDCLNT_E_NOT_INITIALIZED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x01)), + HARDCODED_ENTRY(AUDCLNT_E_ALREADY_INITIALIZED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x02)), + HARDCODED_ENTRY(AUDCLNT_E_WRONG_ENDPOINT_TYPE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x03)), + HARDCODED_ENTRY(AUDCLNT_E_DEVICE_INVALIDATED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x04)), + HARDCODED_ENTRY(AUDCLNT_E_NOT_STOPPED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x05)), + HARDCODED_ENTRY(AUDCLNT_E_BUFFER_TOO_LARGE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x06)), + HARDCODED_ENTRY(AUDCLNT_E_OUT_OF_ORDER , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x07)), + HARDCODED_ENTRY(AUDCLNT_E_UNSUPPORTED_FORMAT , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x08)), + HARDCODED_ENTRY(AUDCLNT_E_INVALID_SIZE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x09)), + HARDCODED_ENTRY(AUDCLNT_E_DEVICE_IN_USE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0a)), + HARDCODED_ENTRY(AUDCLNT_E_BUFFER_OPERATION_PENDING , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0b)), + HARDCODED_ENTRY(AUDCLNT_E_THREAD_NOT_REGISTERED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0c)), + HARDCODED_ENTRY(AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0e)), + HARDCODED_ENTRY(AUDCLNT_E_ENDPOINT_CREATE_FAILED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0f)), + HARDCODED_ENTRY(AUDCLNT_E_SERVICE_NOT_RUNNING , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x10)), + HARDCODED_ENTRY(AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x11)), + HARDCODED_ENTRY(AUDCLNT_E_EXCLUSIVE_MODE_ONLY , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x12)), + HARDCODED_ENTRY(AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x13)), + HARDCODED_ENTRY(AUDCLNT_E_EVENTHANDLE_NOT_SET , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x14)), + HARDCODED_ENTRY(AUDCLNT_E_INCORRECT_BUFFER_SIZE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x15)), + HARDCODED_ENTRY(AUDCLNT_E_BUFFER_SIZE_ERROR , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x16)), + HARDCODED_ENTRY(AUDCLNT_E_CPUUSAGE_EXCEEDED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x17)), + HARDCODED_ENTRY(AUDCLNT_E_BUFFER_ERROR , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x18)), + HARDCODED_ENTRY(AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x19)), + HARDCODED_ENTRY(AUDCLNT_E_INVALID_DEVICE_PERIOD , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x20)), + HARDCODED_ENTRY(AUDCLNT_E_INVALID_STREAM_FLAG , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x21)), + HARDCODED_ENTRY(AUDCLNT_E_ENDPOINT_OFFLOAD_NOT_CAPABLE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x22)), + HARDCODED_ENTRY(AUDCLNT_E_OUT_OF_OFFLOAD_RESOURCES , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x23)), + HARDCODED_ENTRY(AUDCLNT_E_OFFLOAD_MODE_ONLY , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x24)), + HARDCODED_ENTRY(AUDCLNT_E_NONOFFLOAD_MODE_ONLY , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x25)), + HARDCODED_ENTRY(AUDCLNT_E_RESOURCES_INVALIDATED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x26)), + HARDCODED_ENTRY(AUDCLNT_E_RAW_MODE_UNSUPPORTED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x27)), + HARDCODED_ENTRY(AUDCLNT_E_ENGINE_PERIODICITY_LOCKED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x28)), + HARDCODED_ENTRY(AUDCLNT_E_ENGINE_FORMAT_LOCKED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x29)), + HARDCODED_ENTRY(AUDCLNT_E_HEADTRACKING_ENABLED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x30)), + HARDCODED_ENTRY(AUDCLNT_E_HEADTRACKING_UNSUPPORTED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x40)), + HARDCODED_ENTRY(AUDCLNT_S_BUFFER_EMPTY , MAKE_SCODE(SEVERITY_SUCCESS, 2185, 1)), + HARDCODED_ENTRY(AUDCLNT_S_THREAD_ALREADY_REGISTERED , MAKE_SCODE(SEVERITY_SUCCESS, 2185, 2)), + HARDCODED_ENTRY(AUDCLNT_S_POSITION_STALLED , MAKE_SCODE(SEVERITY_SUCCESS, 2185, 3)), +# undef HARDCODED_ENTRY +#endif + { "Success.", "ERROR_SUCCESS", 0, false }, +}; + + +static RTEXITCODE error(const char *pszFormat, ...) +{ + va_list va; + va_start(va, pszFormat); + fprintf(stderr, "%s: error: ", g_pszProgName); + vfprintf(stderr, pszFormat, va); + va_end(va); + return RTEXITCODE_FAILURE; +} + + +/** qsort callback. */ +static int CompareWinErrMsg(const void *pv1, const void *pv2) RT_NOTHROW_DEF +{ + PCRTWINERRMSG p1 = (PCRTWINERRMSG)pv1; + PCRTWINERRMSG p2 = (PCRTWINERRMSG)pv2; + int iDiff; + if (p1->iCode < p2->iCode) + iDiff = -1; + else if (p1->iCode > p2->iCode) + iDiff = 1; + else + iDiff = 0; + return iDiff; +} + + +int main(int argc, char **argv) +{ + /* + * Parse arguments. + */ + enum { kMode_All, kMode_OnlyDefines } enmMode; + if (argc == 3 && strcmp(argv[1], "--all") == 0) + enmMode = kMode_All; + else if (argc == 3 && strcmp(argv[1], "--only-defines") == 0) + enmMode = kMode_OnlyDefines; + else + { + fprintf(stderr, + "syntax error!\n" + "Usage: %s <--all|--only-defines> <outfile>\n", argv[0]); + return RTEXITCODE_SYNTAX; + } + const char * const pszOutFile = argv[2]; + + /* + * Sort the table and mark duplicates. + */ + qsort(g_aStatusMsgs, RT_ELEMENTS(g_aStatusMsgs), sizeof(g_aStatusMsgs[0]), CompareWinErrMsg); + + int rcExit = RTEXITCODE_SUCCESS; + long iPrev = (long)0x80000000; + bool fHaveSuccess = false; + for (size_t i = 0; i < RT_ELEMENTS(g_aStatusMsgs); i++) + { + PRTWINERRMSGINT1 pMsg = &g_aStatusMsgs[i]; + if (pMsg->iCode == iPrev && i != 0) + { + pMsg->fDuplicate = true; + + if (iPrev == 0) + continue; + + PRTWINERRMSGINT1 pPrev = &g_aStatusMsgs[i - 1]; + if (strcmp(pMsg->pszDefine, pPrev->pszDefine) == 0) + continue; + rcExit = error("Duplicate value %#lx (%ld) - %s and %s\n", + (unsigned long)iPrev, iPrev, pMsg->pszDefine, pPrev->pszDefine); + } + else + { + pMsg->fDuplicate = false; + iPrev = pMsg->iCode; + if (iPrev == 0) + fHaveSuccess = true; + } + } + if (!fHaveSuccess) + rcExit = error("No zero / success value in the table!\n"); + + /* + * Create a string table for it all. + */ + BLDPROGSTRTAB StrTab; + if (!BldProgStrTab_Init(&StrTab, RT_ELEMENTS(g_aStatusMsgs) * 3)) + return error("Out of memory!\n"); + + static RTWINERRMSGINT2 s_aStatusMsgs2[RT_ELEMENTS(g_aStatusMsgs)]; + size_t cStatusMsgs = 0; + for (size_t i = 0; i < RT_ELEMENTS(g_aStatusMsgs); i++) + { + if (!g_aStatusMsgs[i].fDuplicate) + { + s_aStatusMsgs2[cStatusMsgs].iCode = g_aStatusMsgs[i].iCode; + s_aStatusMsgs2[cStatusMsgs].pszDefine = g_aStatusMsgs[i].pszDefine; + BldProgStrTab_AddStringDup(&StrTab, &s_aStatusMsgs2[cStatusMsgs].Define, g_aStatusMsgs[i].pszDefine); + if (enmMode != kMode_OnlyDefines) + BldProgStrTab_AddStringDup(&StrTab, &s_aStatusMsgs2[cStatusMsgs].MsgFull, g_aStatusMsgs[i].pszMsgFull); + cStatusMsgs++; + } + } + + if (!BldProgStrTab_CompileIt(&StrTab, true)) + return error("BldProgStrTab_CompileIt failed!\n"); + + /* + * Prepare output file. + */ + FILE *pOut = fopen(pszOutFile, "wt"); + if (pOut) + { + /* + * Print the table. + */ + fprintf(pOut, + "\n" + "typedef struct RTMSGWINENTRYINT\n" + "{\n" + " uint32_t offDefine : 20;\n" + " uint32_t cchDefine : 9;\n" + "%s" + " int32_t iCode;\n" + "} RTMSGWINENTRYINT;\n" + "typedef RTMSGWINENTRYINT *PCRTMSGWINENTRYINT;\n" + "\n" + "static const RTMSGWINENTRYINT g_aWinMsgs[ /*%lu*/ ] =\n" + "{\n" + , + enmMode == kMode_All + ? " uint32_t offMsgFull : 23;\n" + " uint32_t cchMsgFull : 9;\n" : "", + (unsigned long)cStatusMsgs); + + if (enmMode == kMode_All) + for (size_t i = 0; i < cStatusMsgs; i++) + fprintf(pOut, "/*%#010lx:*/ { %#08x, %3u, %#08x, %3u, %ld },\n", + s_aStatusMsgs2[i].iCode, + s_aStatusMsgs2[i].Define.offStrTab, + (unsigned)s_aStatusMsgs2[i].Define.cchString, + s_aStatusMsgs2[i].MsgFull.offStrTab, + (unsigned)s_aStatusMsgs2[i].MsgFull.cchString, + s_aStatusMsgs2[i].iCode); + else if (enmMode == kMode_OnlyDefines) + for (size_t i = 0; i < cStatusMsgs; i++) + fprintf(pOut, "/*%#010lx:*/ { %#08x, %3u, %ld },\n", + s_aStatusMsgs2[i].iCode, + s_aStatusMsgs2[i].Define.offStrTab, + (unsigned)s_aStatusMsgs2[i].Define.cchString, + s_aStatusMsgs2[i].iCode); + else + return error("Unsupported message selection (%d)!\n", enmMode); + fprintf(pOut, + "};\n" + "\n"); + + BldProgStrTab_WriteStringTable(&StrTab, pOut, "static ", "g_", "WinMsgStrTab"); + + /* + * Close the output file and we're done. + */ + fflush(pOut); + if (ferror(pOut)) + rcExit = error("Error writing '%s'!\n", pszOutFile); + if (fclose(pOut) != 0) + rcExit = error("Failed to close '%s' after writing it!\n", pszOutFile); + } + else + rcExit = error("Failed to open '%s' for writing!\n", pszOutFile); + return rcExit; +} + diff --git a/src/VBox/Runtime/win/errmsgwin.cpp b/src/VBox/Runtime/win/errmsgwin.cpp new file mode 100644 index 00000000..1f8ce822 --- /dev/null +++ b/src/VBox/Runtime/win/errmsgwin.cpp @@ -0,0 +1,225 @@ +/* $Id: errmsgwin.cpp $ */ +/** @file + * IPRT - Status code messages, Windows. + */ + +/* + * Copyright (C) 2006-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * 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 GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include <iprt/win/windows.h> + +#include <iprt/errcore.h> +#include <iprt/asm.h> +#include <iprt/string.h> + +#include <iprt/bldprog-strtab.h> + + +/********************************************************************************************************************************* +* Global Variables * +*********************************************************************************************************************************/ +#if defined(IPRT_NO_ERROR_DATA) || defined(IPRT_NO_WIN_ERROR_DATA) +/* Cook data just for VINF_SUCCESS so that code below compiles fine. */ +static const char g_achWinStrTabData[] = { "ERROR_SUCCESS" }; +static const RTBLDPROGSTRTAB g_WinMsgStrTab = { g_achWinStrTabData, sizeof(g_achWinStrTabData) - 1, 0, NULL }; +static const struct +{ + int16_t iCode; + uint8_t offDefine; + uint8_t cchDefine; + uint8_t offMsgFull; + uint8_t cchMsgFull; +} g_aWinMsgs[] = +{ + { 0, 0, 13, 0, 13, }, +}; +#else +# include "errmsgwindata-only-defines.h" +#endif + + +/** + * Looks up the message table entry for @a rc. + * + * @returns index into g_aWinMsgs on success, ~(size_t)0 if not found. + * @param rc The status code to locate the entry for. + */ +static size_t rtErrWinLookup(long rc) +{ + /* + * Perform binary search (duplicate code in rtErrLookup). + */ + size_t iStart = 0; + size_t iEnd = RT_ELEMENTS(g_aWinMsgs); + for (;;) + { + size_t i = iStart + (iEnd - iStart) / 2; + long const iCode = g_aWinMsgs[i].iCode; + if (rc < iCode) + { + if (iStart < i) + iEnd = i; + else + break; + } + else if (rc > iCode) + { + i++; + if (i < iEnd) + iStart = i; + else + break; + } + else + return i; + } + +#ifdef RT_STRICT + for (size_t i = 0; i < RT_ELEMENTS(g_aWinMsgs); i++) + Assert(g_aWinMsgs[i].iCode != rc); +#endif + + return ~(size_t)0; +} + + +RTDECL(bool) RTErrWinIsKnown(long rc) +{ + if (rtErrWinLookup(rc) != ~(size_t)0) + return true; + if (SCODE_FACILITY(rc) == FACILITY_WIN32) + { + if (rtErrWinLookup(HRESULT_CODE(rc)) != ~(size_t)0) + return true; + } + return false; +} + + +RTDECL(ssize_t) RTErrWinQueryDefine(long rc, char *pszBuf, size_t cbBuf, bool fFailIfUnknown) +{ + size_t idx = rtErrWinLookup(rc); + if (idx != ~(size_t)0) + return RTBldProgStrTabQueryString(&g_WinMsgStrTab, + g_aWinMsgs[idx].offDefine, g_aWinMsgs[idx].cchDefine, + pszBuf, cbBuf); + + /* + * If FACILITY_WIN32 kind of status, look up the win32 code. + */ + if ( SCODE_FACILITY(rc) == FACILITY_WIN32 + && (idx = rtErrWinLookup(HRESULT_CODE(rc))) != ~(size_t)0) + { + /* Append the incoming rc, so we know it's not a regular WIN32 status: */ + ssize_t cchRet = RTBldProgStrTabQueryString(&g_WinMsgStrTab, + g_aWinMsgs[idx].offDefine, g_aWinMsgs[idx].cchDefine, + pszBuf, cbBuf); + if (cchRet > 0) + { + pszBuf[cchRet++] = '/'; + return RTStrFormatU32(pszBuf + cchRet, cbBuf - cchRet, rc, 16, 0, 0, RTSTR_F_SPECIAL); + } + return VERR_BUFFER_OVERFLOW; + } + + if (fFailIfUnknown) + return VERR_NOT_FOUND; + return RTStrFormatU32(pszBuf, cbBuf, rc, 16, 0, 0, RTSTR_F_SPECIAL); +} + + +RTDECL(size_t) RTErrWinFormatDefine(long rc, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, char *pszTmp, size_t cbTmp) +{ + RT_NOREF(pszTmp, cbTmp); + size_t idx = rtErrWinLookup(rc); + if (idx != ~(size_t)0) + return RTBldProgStrTabQueryOutput(&g_WinMsgStrTab, + g_aWinMsgs[idx].offDefine, g_aWinMsgs[idx].cchDefine, + pfnOutput, pvArgOutput); + + /* + * If FACILITY_WIN32 kind of status, look up the win32 code. + */ + size_t cchRet = 0; + if ( SCODE_FACILITY(rc) == FACILITY_WIN32 + && (idx = rtErrWinLookup(HRESULT_CODE(rc))) != ~(size_t)0) + { + /* Append the incoming rc, so we know it's not a regular WIN32 status: */ + cchRet = RTBldProgStrTabQueryOutput(&g_WinMsgStrTab, + g_aWinMsgs[idx].offDefine, g_aWinMsgs[idx].cchDefine, + pfnOutput, pvArgOutput); + cchRet += pfnOutput(pvArgOutput, RT_STR_TUPLE("/")); + } + + ssize_t cchValue = RTStrFormatU32(pszTmp, cbTmp, rc, 16, 0, 0, RTSTR_F_SPECIAL); + Assert(cchValue > 0); + cchRet += pfnOutput(pvArgOutput, pszTmp, cchValue); + return cchRet; +} + + +RTDECL(size_t) RTErrWinFormatMsg(long rc, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, char *pszTmp, size_t cbTmp) +{ + return RTErrWinFormatDefine(rc, pfnOutput, pvArgOutput, pszTmp, cbTmp); +} + + +RTDECL(size_t) RTErrWinFormatMsgAll(long rc, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, char *pszTmp, size_t cbTmp) +{ + RT_NOREF(pszTmp, cbTmp); + size_t cchRet; + size_t idx = rtErrWinLookup(rc); + if ( idx != ~(size_t)0 + || ( SCODE_FACILITY(rc) == FACILITY_WIN32 + && (idx = rtErrWinLookup(HRESULT_CODE(rc))) != ~(size_t)0)) + { + cchRet = RTBldProgStrTabQueryOutput(&g_WinMsgStrTab, + g_aWinMsgs[idx].offDefine, g_aWinMsgs[idx].cchDefine, + pfnOutput, pvArgOutput); + cchRet += pfnOutput(pvArgOutput, RT_STR_TUPLE(" (")); + } + else + cchRet = pfnOutput(pvArgOutput, RT_STR_TUPLE("Unknown Status ")); + + ssize_t cchValue = RTStrFormatU32(pszTmp, cbTmp, rc, 16, 0, 0, RTSTR_F_SPECIAL); + Assert(cchValue > 0); + cchRet += pfnOutput(pvArgOutput, pszTmp, cchValue); + + if (idx != ~(size_t)0) + cchRet += pfnOutput(pvArgOutput, RT_STR_TUPLE(")")); + + return cchRet; +} + |