1 | /* $Id: logbackdoor.cpp 19120 2009-04-22 20:34:12Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Runtime - Guest Backdoor Logging.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /*******************************************************************************
|
---|
32 | * Header Files *
|
---|
33 | *******************************************************************************/
|
---|
34 | #include <VBox/log.h>
|
---|
35 | #include <iprt/asm.h>
|
---|
36 | #include <iprt/string.h>
|
---|
37 | #ifdef IN_GUEST_R3
|
---|
38 | # include <VBox/VBoxGuest.h>
|
---|
39 | #endif
|
---|
40 |
|
---|
41 |
|
---|
42 | /*******************************************************************************
|
---|
43 | * Internal Functions *
|
---|
44 | *******************************************************************************/
|
---|
45 | static DECLCALLBACK(size_t) rtLogBackdoorOutput(void *pv, const char *pachChars, size_t cbChars);
|
---|
46 |
|
---|
47 |
|
---|
48 | RTDECL(size_t) RTLogBackdoorPrintf(const char *pszFormat, ...)
|
---|
49 | {
|
---|
50 | va_list args;
|
---|
51 | size_t cb;
|
---|
52 |
|
---|
53 | va_start(args, pszFormat);
|
---|
54 | cb = RTLogBackdoorPrintfV(pszFormat, args);
|
---|
55 | va_end(args);
|
---|
56 |
|
---|
57 | return cb;
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | RTDECL(size_t) RTLogBackdoorPrintfV(const char *pszFormat, va_list args)
|
---|
62 | {
|
---|
63 | return RTLogFormatV(rtLogBackdoorOutput, NULL, pszFormat, args);
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Callback for RTLogFormatV which writes to the backdoor.
|
---|
69 | * See PFNLOGOUTPUT() for details.
|
---|
70 | */
|
---|
71 | static DECLCALLBACK(size_t) rtLogBackdoorOutput(void *pv, const char *pachChars, size_t cbChars)
|
---|
72 | {
|
---|
73 | RTLogWriteUser(pachChars, cbChars);
|
---|
74 | return cbChars;
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | #ifdef IN_GUEST_R3
|
---|
79 |
|
---|
80 | RTDECL(void) RTLogWriteUser(const char *pch, size_t cb)
|
---|
81 | {
|
---|
82 | VbglR3WriteLog(pch, cb);
|
---|
83 | }
|
---|
84 |
|
---|
85 | #else /* !IN_GUEST_R3 */
|
---|
86 |
|
---|
87 | RTDECL(void) RTLogWriteUser(const char *pch, size_t cb)
|
---|
88 | {
|
---|
89 | const uint8_t *pau8 = (const uint8_t *)pch;
|
---|
90 | if (cb > 1)
|
---|
91 | ASMOutStrU8(RTLOG_DEBUG_PORT, pau8, cb);
|
---|
92 | else if (cb)
|
---|
93 | ASMOutU8(RTLOG_DEBUG_PORT, *pau8);
|
---|
94 | }
|
---|
95 |
|
---|
96 | # if defined(RT_OS_LINUX) && defined(IN_MODULE)
|
---|
97 | /*
|
---|
98 | * When we build this in the Linux kernel module, we wish to make the
|
---|
99 | * symbols available to other modules as well.
|
---|
100 | */
|
---|
101 | # include "the-linux-kernel.h"
|
---|
102 | EXPORT_SYMBOL(RTLogBackdoorPrintf);
|
---|
103 | EXPORT_SYMBOL(RTLogBackdoorPrintfV);
|
---|
104 | EXPORT_SYMBOL(RTLogWriteUser);
|
---|
105 | # endif /* RT_OS_LINUX && IN_MODULE */
|
---|
106 | #endif /* !IN_GUEST_R3 */
|
---|
107 |
|
---|