VirtualBox

Changeset 55326 in vbox


Ignore:
Timestamp:
Apr 17, 2015 12:19:00 PM (10 years ago)
Author:
vboxsync
Message:

VBox/hgcmsvc.h: Added optional arguments for setPointer() and setString() to make deep copies.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/hgcmsvc.h

    r44528 r55326  
    44
    55/*
    6  * Copyright (C) 2006-2011 Oracle Corporation
     6 * Copyright (C) 2006-2015 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2828
    2929#include <iprt/assert.h>
     30#include <iprt/mem.h>
    3031#include <iprt/string.h>
    3132#include <VBox/cdefs.h>
     
    8889
    8990#define VBOX_HGCM_SVC_PARM_INVALID (0U)
    90 #define VBOX_HGCM_SVC_PARM_32BIT (1U)
    91 #define VBOX_HGCM_SVC_PARM_64BIT (2U)
    92 #define VBOX_HGCM_SVC_PARM_PTR   (3U)
     91#define VBOX_HGCM_SVC_PARM_32BIT   (1U)
     92#define VBOX_HGCM_SVC_PARM_64BIT   (2U)
     93#define VBOX_HGCM_SVC_PARM_PTR     (3U)
    9394
    9495typedef struct VBOXHGCMSVCPARM
     
    109110#ifdef __cplusplus
    110111    /** Extract a uint32_t value from an HGCM parameter structure */
    111     int getUInt32 (uint32_t *u32)
     112    int getUInt32(uint32_t *u32)
    112113    {
    113114        AssertPtrReturn(u32, VERR_INVALID_POINTER);
     
    121122
    122123    /** Extract a uint64_t value from an HGCM parameter structure */
    123     int getUInt64 (uint64_t *u64)
     124    int getUInt64(uint64_t *u64)
    124125    {
    125126        AssertPtrReturn(u64, VERR_INVALID_POINTER);
     
    133134
    134135    /** Extract a pointer value from an HGCM parameter structure */
    135     int getPointer (void **ppv, uint32_t *pcb)
     136    int getPointer(void **ppv, uint32_t *pcb)
    136137    {
    137138        AssertPtrReturn(ppv, VERR_INVALID_POINTER);
     
    148149
    149150    /** Extract a constant pointer value from an HGCM parameter structure */
    150     int getPointer (const void **ppcv, uint32_t *pcb)
     151    int getPointer(const void **ppcv, uint32_t *pcb)
    151152    {
    152153        AssertPtrReturn(ppcv, VERR_INVALID_POINTER);
     
    160161    /** Extract a pointer value to a non-empty buffer from an HGCM parameter
    161162     * structure */
    162     int getBuffer (void **ppv, uint32_t *pcb)
     163    int getBuffer(void **ppv, uint32_t *pcb)
    163164    {
    164165        AssertPtrReturn(ppv, VERR_INVALID_POINTER);
     
    181182    /** Extract a pointer value to a non-empty constant buffer from an HGCM
    182183     * parameter structure */
    183     int getBuffer (const void **ppcv, uint32_t *pcb)
     184    int getBuffer(const void **ppcv, uint32_t *pcb)
    184185    {
    185186        AssertPtrReturn(ppcv, VERR_INVALID_POINTER);
     
    192193
    193194    /** Extract a string value from an HGCM parameter structure */
    194     int getString (char **ppch, uint32_t *pcb)
     195    int getString(char **ppch, uint32_t *pcb)
    195196    {
    196197        uint32_t cb = 0;
     
    211212
    212213    /** Extract a constant string value from an HGCM parameter structure */
    213     int getString (const char **ppch, uint32_t *pcb)
     214    int getString(const char **ppch, uint32_t *pcb)
    214215    {
    215216        char *pch = NULL;
     
    234235
    235236    /** Set a pointer value to an HGCM parameter structure */
    236     void setPointer(void *pv, uint32_t cb)
     237    int setPointer(void *pv, uint32_t cb, bool fDeepCopy = false)
    237238    {
    238239        type = VBOX_HGCM_SVC_PARM_PTR;
    239         u.pointer.addr = pv;
     240        void *addr = fDeepCopy ? RTMemDup(pv, cb) : pv;
     241        if (fDeepCopy && !addr)
     242            return VERR_NO_MEMORY;
     243        u.pointer.addr = addr;
    240244        u.pointer.size = cb;
    241245    }
    242246
    243247    /** Set a const string value to an HGCM parameter structure */
    244     void setString(const char *psz)
     248    int setString(const char *psz, bool fDeepCopy = false)
    245249    {
    246250        type = VBOX_HGCM_SVC_PARM_PTR;
    247         u.pointer.addr = (void *)psz;
    248         u.pointer.size = (uint32_t)strlen(psz) + 1;
     251        void *pszaddr = fDeepCopy ? (void *)RTStrDup(psz) : (void *)psz;
     252        if (fDeepCopy && !pszaddr)
     253            return VERR_NO_MEMORY;
     254        u.pointer.addr = pszaddr;
     255        u.pointer.size = (uint32_t)strlen((char *)pszaddr) + 1;
    249256    }
    250257
     
    313320
    314321    VBOXHGCMSVCPARM() : type(VBOX_HGCM_SVC_PARM_INVALID) {}
    315 #endif
     322#endif /* __cplusplus */
    316323} VBOXHGCMSVCPARM;
    317324
Note: See TracChangeset for help on using the changeset viewer.

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