VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibLog.cpp@ 35380

Last change on this file since 35380 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keyword set to Id
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/* $Id: VBoxGuestR3LibLog.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Logging.
4 */
5
6/*
7 * Copyright (C) 2007-2010 Oracle Corporation
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 <iprt/mem.h>
32#include "VBGLR3Internal.h"
33
34
35/**
36 * Write to the backdoor logger from ring 3 guest code.
37 *
38 * @returns IPRT status code.
39 *
40 * @param pch The string to log. Does not need to be terminated.
41 * @param cch The number of chars (bytes) to log.
42 *
43 * @remarks This currently does not accept more than 255 bytes of data at
44 * one time. It should probably be rewritten to use pass a pointer
45 * in the IOCtl.
46 */
47VBGLR3DECL(int) VbglR3WriteLog(const char *pch, size_t cch)
48{
49 /*
50 * Quietly skip NULL strings.
51 * (Happens in the RTLogBackdoorPrintf case.)
52 */
53 if (!cch)
54 return VINF_SUCCESS;
55 if (!VALID_PTR(pch))
56 return VERR_INVALID_POINTER;
57
58#ifdef RT_OS_WINDOWS
59 /*
60 * Duplicate the string as it may be read only (a C string).
61 */
62 void *pvTmp = RTMemDup(pch, cch);
63 if (!pvTmp)
64 return VERR_NO_MEMORY;
65 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cch), pvTmp, cch);
66 RTMemFree(pvTmp);
67 return rc;
68
69#elif 0 /** @todo Several OSes could take this route (solaris and freebsd for instance). */
70 /*
71 * Handle the entire request in one go.
72 */
73 return vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cch), pvTmp, cch);
74
75#else
76 /*
77 * *BSD does not accept more than 4KB per ioctl request, while
78 * Linux can't express sizes above 8KB, so, split it up into 2KB chunks.
79 */
80# define STEP 2048
81 int rc = VINF_SUCCESS;
82 for (size_t off = 0; off < cch && RT_SUCCESS(rc); off += STEP)
83 {
84 size_t cbStep = RT_MIN(cch - off, STEP);
85 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cbStep), (char *)pch + off, cbStep);
86 }
87# undef STEP
88 return rc;
89#endif
90}
91
Note: See TracBrowser for help on using the repository browser.

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