VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/VMAll.cpp@ 1

最後變更 在這個檔案從1是 1,由 vboxsync 提交於 55 年 前

import

檔案大小: 5.3 KB
 
1/** @file
2 *
3 * VM - Virtual Machine All Contexts.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_VM
27#include "VMInternal.h"
28#include <VBox/vmm.h>
29#include <VBox/mm.h>
30#include <VBox/vm.h>
31#include <VBox/err.h>
32
33#include <iprt/assert.h>
34#include <iprt/string.h>
35
36
37/**
38 * Sets the error message.
39 *
40 * @returns rc. Meaning you can do:
41 * @code
42 * return VM_SET_ERROR(pVM, VERR_OF_YOUR_CHOICE, "descriptive message");
43 * @codeend
44 * @param pVM VM handle. Must be non-NULL.
45 * @param rc VBox status code.
46 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
47 * @param pszFormat Error message format string.
48 * @param ... Error message arguments.
49 * @thread Any
50 */
51VMDECL(int) VMSetError(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
52{
53 va_list args;
54 va_start(args, pszFormat);
55 int rc2 = VMSetErrorV(pVM, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc == rc2); NOREF(rc2);
56 va_end(args);
57 return rc;
58}
59
60
61/**
62 * Sets the error message.
63 *
64 * @returns rc. Meaning you can do:
65 * @code
66 * return VM_SET_ERROR(pVM, VERR_OF_YOUR_CHOICE, "descriptive message");
67 * @codeend
68 * @param pVM VM handle. Must be non-NULL.
69 * @param rc VBox status code.
70 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
71 * @param pszFormat Error message format string.
72 * @param args Error message arguments.
73 * @thread Any
74 */
75VMDECL(int) VMSetErrorV(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list args)
76{
77#ifdef IN_RING3
78 /*
79 * Switch to EMT.
80 */
81 PVMREQ pReq;
82 VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT, (PFNRT)vmR3SetErrorV, 7, /* ASSUMES 3 source pos args! */
83 pVM, rc, RT_SRC_POS_ARGS, pszFormat, &args);
84 VMR3ReqFree(pReq);
85
86#else
87 /*
88 * We're already on the EMT thread and can safely create a VMERROR chunk.
89 */
90 vmSetErrorCopy(pVM, rc, RT_SRC_POS_ARGS, pszFormat, args);
91
92# ifdef IN_GC
93 VMMGCCallHost(pVM, VMMCALLHOST_VM_SET_ERROR, 0);
94# elif defined(IN_RING0)
95 VMMR0CallHost(pVM, VMMCALLHOST_VM_SET_ERROR, 0);
96# else
97# endif
98#endif
99 return rc;
100}
101
102
103/**
104 * Copies the error to a VMERROR structure.
105 *
106 * This is mainly intended for Ring-0 and GC where the error must be copied to
107 * memory accessible from ring-3. But it's just possible that we might add
108 * APIs for retrieving the VMERROR copy later.
109 *
110 * @param pVM VM handle. Must be non-NULL.
111 * @param rc VBox status code.
112 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
113 * @param pszFormat Error message format string.
114 * @param args Error message arguments.
115 * @thread EMT
116 */
117void vmSetErrorCopy(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list args)
118{
119#if 0 /// @todo implement Ring-0 and GC VMSetError
120 /*
121 * Create the untranslated message copy.
122 */
123 /* free any old message. */
124 MMHyperFree(pVM, MMHyperR32Ctx(pVM, pVM->vm.s.pError));
125 pVM->vm.s.pError = NULL;
126
127 /* calc reasonable start size. */
128 size_t cchFile = pszFile ? strlen(pszFile) : 0;
129 size_t cchFunction = pszFunction ? strlen(pszFunction) : 0;
130 size_t cchFormat = strlen(pszFormat);
131 size_t cb = sizeof(VMERROR)
132 + cchFile + 1
133 + cchFunction + 1
134 + cchFormat + 32;
135
136 /* allocate it */
137 void *pv;
138 int rc2 = MMHyperAlloc(pVM, cb, 0, MM_TAG_VM, &pv);
139 if (VBOX_SUCCESS(rc2))
140 {
141 /* initialize it. */
142 PVMERROR pErr = (PVMERROR)pv;
143 pErr->cbAllocated = cb;
144 pErr->iLine = iLine;
145 pErr->off = sizeof(VMERROR);
146 pErr->offFile = pErr->offFunction = 0;
147
148 if (cchFile)
149 {
150 pErr->offFile = pErr->off;
151 memcpy((uint8_t *)pErr + pErr->off, pszFile, cchFile + 1);
152 pErr->off += cchFile + 1;
153 }
154
155 if (cchFunction)
156 {
157 pErr->offFunction = pErr->off;
158 memcpy((uint8_t *)pErr + pErr->off, pszFunction, cchFunction + 1);
159 pErr->off += cchFunction + 1;
160 }
161
162 pErr->offMessage = pErr->off;
163
164 /* format the message (pErr might be reallocated) */
165 VMSETERRORFMTARGS Args;
166 Args.pVM = pVM;
167 Args.pErr = pErr;
168
169 va_list va2;
170 va_copy(va2, args);
171 RTStrFormatV(vmSetErrorFmtOut, &pErr, NULL, NULL, &pszFormatTmp, args);
172 va_end(va2);
173
174 /* done. */
175 pVM->vm.s.pErrorR3 = MMHyper2HC(pVM, (uintptr_t)pArgs.pErr);
176 }
177#endif
178}
179
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette