]>
Commit | Line | Data |
---|---|---|
056a1eb7 SF |
1 | /* $Id: logbackdoor.cpp $ */ |
2 | /** @file | |
3 | * VirtualBox Runtime - Guest Backdoor Logging. | |
4 | */ | |
5 | ||
6 | /* | |
6d209b23 | 7 | * Copyright (C) 2006-2017 Oracle Corporation |
056a1eb7 SF |
8 | * |
9 | * This file is part of VirtualBox Open Source Edition (OSE), as | |
10 | * available from http://www.virtualbox.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 (GPL) as published by the Free Software | |
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the | |
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the | |
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. | |
16 | * | |
17 | * The contents of this file may alternatively be used under the terms | |
18 | * of the Common Development and Distribution License Version 1.0 | |
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the | |
20 | * VirtualBox OSE distribution, in which case the provisions of the | |
21 | * CDDL are applicable instead of those of the GPL. | |
22 | * | |
23 | * You may elect to license modified versions of this file under the | |
24 | * terms and conditions of either the GPL or the CDDL or both. | |
25 | */ | |
26 | ||
27 | ||
28 | /********************************************************************************************************************************* | |
29 | * Header Files * | |
30 | *********************************************************************************************************************************/ | |
31 | #include <VBox/log.h> | |
32 | #include "internal/iprt.h" | |
33 | #include <iprt/asm-amd64-x86.h> | |
34 | #include <iprt/string.h> | |
35 | #ifdef IN_GUEST_R3 | |
36 | # include <VBox/VBoxGuestLib.h> | |
37 | #endif | |
38 | ||
39 | ||
40 | /********************************************************************************************************************************* | |
41 | * Internal Functions * | |
42 | *********************************************************************************************************************************/ | |
43 | static DECLCALLBACK(size_t) rtLogBackdoorOutput(void *pv, const char *pachChars, size_t cbChars); | |
44 | ||
45 | ||
46 | RTDECL(size_t) RTLogBackdoorPrintf(const char *pszFormat, ...) | |
47 | { | |
48 | va_list args; | |
49 | size_t cb; | |
50 | ||
51 | va_start(args, pszFormat); | |
52 | cb = RTLogBackdoorPrintfV(pszFormat, args); | |
53 | va_end(args); | |
54 | ||
55 | return cb; | |
56 | } | |
57 | ||
58 | RT_EXPORT_SYMBOL(RTLogBackdoorPrintf); | |
59 | ||
60 | ||
61 | RTDECL(size_t) RTLogBackdoorPrintfV(const char *pszFormat, va_list args) | |
62 | { | |
63 | return RTLogFormatV(rtLogBackdoorOutput, NULL, pszFormat, args); | |
64 | } | |
65 | ||
66 | RT_EXPORT_SYMBOL(RTLogBackdoorPrintfV); | |
67 | ||
68 | ||
69 | /** | |
70 | * Callback for RTLogFormatV which writes to the backdoor. | |
71 | * See PFNRTSTROUTPUT() for details. | |
72 | */ | |
73 | static DECLCALLBACK(size_t) rtLogBackdoorOutput(void *pvArg, const char *pachChars, size_t cbChars) | |
74 | { | |
75 | RT_NOREF_PV(pvArg); | |
76 | RTLogWriteUser(pachChars, cbChars); | |
77 | return cbChars; | |
78 | } | |
79 | ||
80 | ||
81 | RTDECL(void) RTLogWriteUser(const char *pch, size_t cb) | |
82 | { | |
83 | #ifdef IN_GUEST_R3 | |
84 | VbglR3WriteLog(pch, cb); | |
85 | #else /* !IN_GUEST_R3 */ | |
86 | const uint8_t *pau8 = (const uint8_t *)pch; | |
87 | if (cb > 1) | |
88 | ASMOutStrU8(RTLOG_DEBUG_PORT, pau8, cb); | |
89 | else if (cb) | |
90 | ASMOutU8(RTLOG_DEBUG_PORT, *pau8); | |
91 | #endif /* !IN_GUEST_R3 */ | |
92 | } | |
93 | ||
94 | RT_EXPORT_SYMBOL(RTLogWriteUser); | |
95 |