diff options
-rw-r--r-- | include/iprt/cpp/mem.h | 271 | ||||
-rw-r--r-- | src/VBox/Additions/common/VBoxService/VBoxService.cpp | 2 | ||||
-rw-r--r-- | src/VBox/Additions/x11/VBoxClient/display.cpp | 4 | ||||
-rw-r--r-- | src/VBox/Additions/x11/VBoxClient/draganddrop.cpp | 8 | ||||
-rw-r--r-- | src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp | 75 | ||||
-rw-r--r-- | src/VBox/RDP/client-1.8.3/rdesktop.c | 2 | ||||
-rw-r--r-- | src/VBox/Runtime/testcase/Makefile.kmk | 4 | ||||
-rw-r--r-- | src/VBox/Runtime/testcase/tstMemAutoPtr.cpp | 292 | ||||
-rw-r--r-- | src/VBox/Runtime/testcase/tstRTDvm.cpp | 4 | ||||
-rw-r--r-- | src/VBox/ValidationKit/utils/cpu/cidet.h | 2 | ||||
-rw-r--r-- | src/VBox/ValidationKit/utils/network/NetPerf.cpp | 2 |
11 files changed, 44 insertions, 622 deletions
diff --git a/include/iprt/cpp/mem.h b/include/iprt/cpp/mem.h deleted file mode 100644 index 1e70ecf1d58..00000000000 --- a/include/iprt/cpp/mem.h +++ /dev/null @@ -1,271 +0,0 @@ -/** @file - * IPRT - C++ Memory Resource Management. - */ - -/* - * Copyright (C) 2006-2015 Oracle Corporation - * - * This file is part of VirtualBox Open Source Edition (OSE), as - * available from http://www.virtualbox.org. This file is free software; - * you can redistribute it and/or modify it under the terms of the GNU - * General Public License (GPL) as published by the Free Software - * Foundation, in version 2 as it comes in the "COPYING" file of the - * VirtualBox OSE distribution. VirtualBox OSE is distributed in the - * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. - * - * The contents of this file may alternatively be used under the terms - * of the Common Development and Distribution License Version 1.0 - * (CDDL) only, as it comes in the "COPYING.CDDL" file of the - * VirtualBox OSE distribution, in which case the provisions of the - * CDDL are applicable instead of those of the GPL. - * - * You may elect to license modified versions of this file under the - * terms and conditions of either the GPL or the CDDL or both. - */ - -#ifndef ___iprt_cpp_mem_h -#define ___iprt_cpp_mem_h - -#include <iprt/cpp/autores.h> -#include <iprt/assert.h> -#include <iprt/mem.h> -#include <iprt/string.h> /* for memset */ - -/** @defgroup grp_rt_cpp_autores_mem C++ Memory Resource Management - * @ingroup grp_rt_cpp_autores - * @{ - */ - -/** - * Template function wrapping RTMemFree to get the correct a_fnDestruct - * signature for RTCAutoRes. - * - * We can't use a more complex template here, because the g++ on RHEL 3 - * chokes on it with an internal compiler error. - * - * @tparam T The data type that's being managed. - * @param aMem Pointer to the memory that should be free. - */ -template <class T> -inline void RTCMemAutoDestructor(T *aMem) RT_NO_THROW -{ - RTMemFree(aMem); -} - - -/** - * RTCMemAutoPtr allocator which uses RTMemTmpAlloc(). - * - * @returns Allocated memory on success, NULL on failure. - * @param pvOld What to reallocate, shall always be NULL. - * @param cbNew The amount of memory to allocate (in bytes). - */ -inline void *RTCMemTmpAutoAllocator(void *pvOld, size_t cbNew) RT_NO_THROW -{ - AssertReturn(!pvOld, NULL); - return RTMemTmpAlloc(cbNew); -} - - -/** - * Template function wrapping RTMemTmpFree to get the correct a_fnDestruct - * signature for RTCAutoRes. - * - * We can't use a more complex template here, because the g++ on RHEL 3 - * chokes on it with an internal compiler error. - * - * @tparam T The data type that's being managed. - * @param aMem Pointer to the memory that should be free. - */ -template <class T> -inline void RTCMemTmpAutoDestructor(T *aMem) RT_NO_THROW -{ - RTMemTmpFree(aMem); -} - - -/** - * Template function wrapping RTMemEfFree to get the correct a_fnDestruct - * signature for RTCAutoRes. - * - * We can't use a more complex template here, because the g++ on RHEL 3 - * chokes on it with an internal compiler error. - * - * @tparam T The data type that's being managed. - * @param aMem Pointer to the memory that should be free. - */ -template <class T> -inline void RTCMemEfAutoFree(T *aMem) RT_NO_THROW -{ - RTMemEfFreeNP(aMem); -} - - -/** - * Template function wrapping NULL to get the correct NilRes signature - * for RTCAutoRes. - * - * @tparam T The data type that's being managed. - * @returns NULL with the right type. - */ -template <class T> -inline T *RTCMemAutoNil(void) RT_NO_THROW -{ - return (T *)(NULL); -} - - -/** - * An auto pointer-type template class for managing memory allocating - * via C APIs like RTMem (the default). - * - * The main purpose of this class is to automatically free memory that - * isn't explicitly used (release()'ed) when the object goes out of scope. - * - * As an additional service it can also make the allocations and - * reallocations for you if you like, but it can also take of memory - * you hand it. - * - * @tparam T The data type to manage allocations for. - * @tparam a_fnDestruct The function to be used to free the resource. - * This will default to RTMemFree. - * @tparam a_fnAllocator The function to be used to allocate or reallocate - * the managed memory. - * This is standard realloc() like stuff, so it's - * possible to support simple allocation without - * actually having to support reallocating memory if - * that's a problem. This will default to - * RTMemRealloc. - */ -template <class T, - void a_fnDestruct(T *) = RTCMemAutoDestructor<T>, -# if defined(RTMEM_WRAP_TO_EF_APIS) && !defined(RTMEM_NO_WRAP_TO_EF_APIS) - void *a_fnAllocator(void *, size_t, const char *) = RTMemEfReallocNP -# else - void *a_fnAllocator(void *, size_t, const char *) = RTMemReallocTag -# endif - > -class RTCMemAutoPtr - : public RTCAutoRes<T *, a_fnDestruct, RTCMemAutoNil<T> > -{ -public: - /** - * Constructor. - * - * @param aPtr Memory pointer to manage. Defaults to NULL. - */ - RTCMemAutoPtr(T *aPtr = NULL) - : RTCAutoRes<T *, a_fnDestruct, RTCMemAutoNil<T> >(aPtr) - { - } - - /** - * Constructor that allocates memory. - * - * @param a_cElements The number of elements (of the data type) to allocate. - * @param a_fZeroed Whether the memory should be memset with zeros after - * the allocation. Defaults to false. - */ - RTCMemAutoPtr(size_t a_cElements, bool a_fZeroed = false) - : RTCAutoRes<T *, a_fnDestruct, RTCMemAutoNil<T> >((T *)a_fnAllocator(NULL, a_cElements * sizeof(T), RTMEM_TAG)) - { - if (a_fZeroed && RT_LIKELY(this->get() != NULL)) - memset(this->get(), '\0', a_cElements * sizeof(T)); - } - - /** - * Free current memory and start managing aPtr. - * - * @param aPtr Memory pointer to manage. - */ - RTCMemAutoPtr &operator=(T *aPtr) - { - this->RTCAutoRes<T *, a_fnDestruct, RTCMemAutoNil<T> >::operator=(aPtr); - return *this; - } - - /** - * Dereference with * operator. - */ - T &operator*() - { - return *this->get(); - } - - /** - * Dereference with -> operator. - */ - T *operator->() - { - return this->get(); - } - - /** - * Accessed with the subscript operator ([]). - * - * @returns Reference to the element. - * @param a_i The element to access. - */ - T &operator[](size_t a_i) - { - return this->get()[a_i]; - } - - /** - * Allocates memory and start manage it. - * - * Any previously managed memory will be freed before making - * the new allocation. - * - * @returns Success indicator. - * @retval true if the new allocation succeeds. - * @retval false on failure, no memory is associated with the object. - * - * @param a_cElements The number of elements (of the data type) to allocate. - * This defaults to 1. - * @param a_fZeroed Whether the memory should be memset with zeros after - * the allocation. Defaults to false. - */ - bool alloc(size_t a_cElements = 1, bool a_fZeroed = false) - { - this->reset(NULL); - T *pNewMem = (T *)a_fnAllocator(NULL, a_cElements * sizeof(T), RTMEM_TAG); - if (a_fZeroed && RT_LIKELY(pNewMem != NULL)) - memset(pNewMem, '\0', a_cElements * sizeof(T)); - this->reset(pNewMem); - return pNewMem != NULL; - } - - /** - * Reallocate or allocates the memory resource. - * - * Free the old value if allocation fails. - * - * The content of any additional memory that was allocated is - * undefined when using the default allocator. - * - * @returns Success indicator. - * @retval true if the new allocation succeeds. - * @retval false on failure, no memory is associated with the object. - * - * @param a_cElements The new number of elements (of the data type) to - * allocate. The size of the allocation is the number of - * elements times the size of the data type - this is - * currently what's passed down to the a_fnAllocator. - * This defaults to 1. - */ - bool realloc(size_t a_cElements = 1) - { - T *aNewValue = (T *)a_fnAllocator(this->get(), a_cElements * sizeof(T), RTMEM_TAG); - if (RT_LIKELY(aNewValue != NULL)) - this->release(); - /* We want this both if aNewValue is non-NULL and if it is NULL. */ - this->reset(aNewValue); - return aNewValue != NULL; - } -}; - -/** @} */ - -#endif - diff --git a/src/VBox/Additions/common/VBoxService/VBoxService.cpp b/src/VBox/Additions/common/VBoxService/VBoxService.cpp index e6e2af4e5ef..c4efaba8f59 100644 --- a/src/VBox/Additions/common/VBoxService/VBoxService.cpp +++ b/src/VBox/Additions/common/VBoxService/VBoxService.cpp @@ -179,7 +179,7 @@ DECLCALLBACK(void) VBoxServiceDefaultTerm(void) * @param enmPhase * @param pfnLog */ -static void VBoxServiceLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog) +static DECLCALLBACK(void) VBoxServiceLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog) { /* Some introductory information. */ static RTTIMESPEC s_TimeSpec; diff --git a/src/VBox/Additions/x11/VBoxClient/display.cpp b/src/VBox/Additions/x11/VBoxClient/display.cpp index 91d7a234837..d9e0a93309a 100644 --- a/src/VBox/Additions/x11/VBoxClient/display.cpp +++ b/src/VBox/Additions/x11/VBoxClient/display.cpp @@ -85,7 +85,7 @@ struct DISPLAYSTATE }; /** Thread to monitor and react to X server VT switches and exits. */ -static int pfnMonitorThread(RTTHREAD self, void *pvUser) +static DECLCALLBACK(int) vboxClientMonitorThread(RTTHREAD self, void *pvUser) { struct DISPLAYSTATE *pState = (struct DISPLAYSTATE *)pvUser; Display *pDisplay; @@ -121,7 +121,7 @@ static int startMonitorThread(struct DISPLAYSTATE *pState) { int rc; - rc = RTThreadCreate(NULL, pfnMonitorThread, (void *)pState, 0, RTTHREADTYPE_INFREQUENT_POLLER, 0, "VT_MONITOR"); + rc = RTThreadCreate(NULL, vboxClientMonitorThread, (void *)pState, 0, RTTHREADTYPE_INFREQUENT_POLLER, 0, "VT_MONITOR"); if (rc != VINF_SUCCESS) VBClFatalError(("Failed to start the VT monitor thread, rc=%Rrc\n", rc)); return VINF_SUCCESS; diff --git a/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp b/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp index 7bca6c6cf37..520b35e956a 100644 --- a/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp +++ b/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp @@ -598,8 +598,8 @@ public: private: int dragAndDropInit(void); - static int hgcmEventThread(RTTHREAD hThread, void *pvUser); - static int x11EventThread(RTTHREAD hThread, void *pvUser); + static DECLCALLBACK(int) hgcmEventThread(RTTHREAD hThread, void *pvUser); + static DECLCALLBACK(int) x11EventThread(RTTHREAD hThread, void *pvUser); /* Private member vars */ Display *m_pDisplay; @@ -3169,7 +3169,7 @@ int DragAndDropService::dragAndDropInit(void) * @param pvUser Pointer to DragAndDropService instance to use. */ /* static */ -int DragAndDropService::hgcmEventThread(RTTHREAD hThread, void *pvUser) +DECLCALLBACK(int) DragAndDropService::hgcmEventThread(RTTHREAD hThread, void *pvUser) { AssertPtrReturn(pvUser, VERR_INVALID_PARAMETER); DragAndDropService *pThis = static_cast<DragAndDropService*>(pvUser); @@ -3239,7 +3239,7 @@ int DragAndDropService::hgcmEventThread(RTTHREAD hThread, void *pvUser) * @param pvUser Pointer to DragAndDropService instance to use. */ /* static */ -int DragAndDropService::x11EventThread(RTTHREAD hThread, void *pvUser) +DECLCALLBACK(int) DragAndDropService::x11EventThread(RTTHREAD hThread, void *pvUser) { AssertPtrReturn(pvUser, VERR_INVALID_PARAMETER); DragAndDropService *pThis = static_cast<DragAndDropService*>(pvUser); diff --git a/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp b/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp index 876a8a50ab0..799d225ca24 100644 --- a/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp +++ b/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp @@ -18,8 +18,6 @@ /* Must be included before winutils.h (lwip/def.h), otherwise Windows build breaks. */ #define LOG_GROUP LOG_GROUP_NAT_SERVICE -#include <iprt/cpp/mem.h> - #include "winutils.h" #include <VBox/com/assert.h> @@ -182,11 +180,11 @@ class VBoxNetLwipNAT: public VBoxNetBaseService, public NATNetworkEventAdapter * on startup, and then on sync them on events. */ bool fDontLoadRulesOnStartup; - static void onLwipTcpIpInit(void *arg); - static void onLwipTcpIpFini(void *arg); + static DECLCALLBACK(void) onLwipTcpIpInit(void *arg); + static DECLCALLBACK(void) onLwipTcpIpFini(void *arg); static err_t netifInit(netif *pNetif); static err_t netifLinkoutput(netif *pNetif, pbuf *pBuf); - static int intNetThreadRecv(RTTHREAD, void *); + /* static int intNetThreadRecv(RTTHREAD, void *); - unused */ VECNATSERVICEPF m_vecPortForwardRule4; VECNATSERVICEPF m_vecPortForwardRule6; @@ -293,8 +291,7 @@ HRESULT VBoxNetLwipNAT::HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent) break; default: - LogRel(("Event: %s %s port-forwarding rule \"%s\":" - " invalid protocol %d\n", + LogRel(("Event: %s %s port-forwarding rule \"%s\": invalid protocol %d\n", fCreateFW ? "Add" : "Remove", fIPv6FW ? "IPv6" : "IPv4", com::Utf8Str(name).c_str(), @@ -302,8 +299,7 @@ HRESULT VBoxNetLwipNAT::HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent) goto port_forward_done; } - LogRel(("Event: %s %s port-forwarding rule \"%s\":" - " %s %s%s%s:%d -> %s%s%s:%d\n", + LogRel(("Event: %s %s port-forwarding rule \"%s\": %s %s%s%s:%d -> %s%s%s:%d\n", fCreateFW ? "Add" : "Remove", fIPv6FW ? "IPv6" : "IPv4", com::Utf8Str(name).c_str(), @@ -352,25 +348,22 @@ HRESULT VBoxNetLwipNAT::HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent) for (it = rules.begin(); it != rules.end(); ++it) { /* compare */ - NATSEVICEPORTFORWARDRULE& natFw = *it; + NATSEVICEPORTFORWARDRULE &natFw = *it; if ( natFw.Pfr.iPfrProto == r.Pfr.iPfrProto && natFw.Pfr.u16PfrHostPort == r.Pfr.u16PfrHostPort - && (strncmp(natFw.Pfr.szPfrHostAddr, r.Pfr.szPfrHostAddr, INET6_ADDRSTRLEN) == 0) + && strncmp(natFw.Pfr.szPfrHostAddr, r.Pfr.szPfrHostAddr, INET6_ADDRSTRLEN) == 0 && natFw.Pfr.u16PfrGuestPort == r.Pfr.u16PfrGuestPort - && (strncmp(natFw.Pfr.szPfrGuestAddr, r.Pfr.szPfrGuestAddr, INET6_ADDRSTRLEN) == 0)) + && strncmp(natFw.Pfr.szPfrGuestAddr, r.Pfr.szPfrGuestAddr, INET6_ADDRSTRLEN) == 0) { - RTCMemAutoPtr<fwspec> pFwCopy; - if (RT_UNLIKELY(!pFwCopy.alloc())) - break; - - memcpy(pFwCopy.get(), &natFw.FWSpec, sizeof(natFw.FWSpec)); - - int status = portfwd_rule_del(pFwCopy.get()); - if (status != 0) - break; - - pFwCopy.release(); /* owned by lwip thread now */ - rules.erase(it); + fwspec *pFwCopy = (fwspec *)RTMemDup(&natFw.FWSpec, sizeof(natFw.FWSpec)); + if (pFwCopy) + { + int status = portfwd_rule_del(pFwCopy); + if (status == 0) + rules.erase(it); /* (pFwCopy is owned by lwip thread now.) */ + else + RTMemFree(pFwCopy); + } break; } } /* loop over vector elements */ @@ -426,7 +419,7 @@ HRESULT VBoxNetLwipNAT::HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent) } -void VBoxNetLwipNAT::onLwipTcpIpInit(void* arg) +/*static*/ DECLCALLBACK(void) VBoxNetLwipNAT::onLwipTcpIpInit(void *arg) { AssertPtrReturnVoid(arg); VBoxNetLwipNAT *pNat = static_cast<VBoxNetLwipNAT *>(arg); @@ -519,7 +512,7 @@ void VBoxNetLwipNAT::onLwipTcpIpInit(void* arg) } -void VBoxNetLwipNAT::onLwipTcpIpFini(void* arg) +/*static*/ DECLCALLBACK(void) VBoxNetLwipNAT::onLwipTcpIpFini(void* arg) { AssertPtrReturnVoid(arg); VBoxNetLwipNAT *pThis = (VBoxNetLwipNAT *)arg; @@ -534,7 +527,7 @@ void VBoxNetLwipNAT::onLwipTcpIpFini(void* arg) /* * Callback for netif_add() to initialize the interface. */ -err_t VBoxNetLwipNAT::netifInit(netif *pNetif) +/*static*/ err_t VBoxNetLwipNAT::netifInit(netif *pNetif) { err_t rcLwip = ERR_OK; @@ -596,7 +589,7 @@ err_t VBoxNetLwipNAT::netifInit(netif *pNetif) } -err_t VBoxNetLwipNAT::netifLinkoutput(netif *pNetif, pbuf *pPBuf) +/*static*/ err_t VBoxNetLwipNAT::netifLinkoutput(netif *pNetif, pbuf *pPBuf) { AssertPtrReturn(pNetif, ERR_ARG); AssertPtrReturn(pPBuf, ERR_ARG); @@ -701,7 +694,7 @@ VBoxNetLwipNAT::~VBoxNetLwipNAT() } -int VBoxNetLwipNAT::natServicePfRegister(NATSEVICEPORTFORWARDRULE& natPf) +/*static*/ int VBoxNetLwipNAT::natServicePfRegister(NATSEVICEPORTFORWARDRULE& natPf) { int lrc; @@ -738,27 +731,23 @@ int VBoxNetLwipNAT::natServicePfRegister(NATSEVICEPORTFORWARDRULE& natPf) if (lrc != 0) return VERR_IGNORED; - RTCMemAutoPtr<fwspec> pFwCopy; - if (RT_UNLIKELY(!pFwCopy.alloc())) + fwspec *pFwCopy = (fwspec *)RTMemDup(&natPf.FWSpec, sizeof(natPf.FWSpec)); + if (pFwCopy) { + lrc = portfwd_rule_add(pFwCopy); + if (lrc == 0) + return VINF_SUCCESS; /* (pFwCopy is owned by lwip thread now.) */ + RTMemFree(pFwCopy); + } + else LogRel(("Unable to allocate memory for %s rule \"%s\"\n", natPf.Pfr.fPfrIPv6 ? "IPv6" : "IPv4", natPf.Pfr.szPfrName)); - return VERR_IGNORED; - } - - memcpy(pFwCopy.get(), &natPf.FWSpec, sizeof(natPf.FWSpec)); - - lrc = portfwd_rule_add(pFwCopy.get()); - if (lrc != 0) - return VERR_IGNORED; - - pFwCopy.release(); /* owned by lwip thread now */ - return VINF_SUCCESS; + return VERR_IGNORED; } -int VBoxNetLwipNAT::natServiceProcessRegisteredPf(VECNATSERVICEPF& vecRules) +/*static*/ int VBoxNetLwipNAT::natServiceProcessRegisteredPf(VECNATSERVICEPF& vecRules) { ITERATORNATSERVICEPF it; for (it = vecRules.begin(); it != vecRules.end(); ++it) diff --git a/src/VBox/RDP/client-1.8.3/rdesktop.c b/src/VBox/RDP/client-1.8.3/rdesktop.c index 27300f51669..205713bb982 100644 --- a/src/VBox/RDP/client-1.8.3/rdesktop.c +++ b/src/VBox/RDP/client-1.8.3/rdesktop.c @@ -556,7 +556,7 @@ parse_server_and_port(char *server) #ifdef VBOX /* This disables iprt logging */ -DECLEXPORT(PRTLOGGER) RTLogDefaultInit(void) +DECLEXPORT(PRTLOGGER) RTCALL RTLogDefaultInit(void) { return NULL; } diff --git a/src/VBox/Runtime/testcase/Makefile.kmk b/src/VBox/Runtime/testcase/Makefile.kmk index e1cd19852db..12cb27deaae 100644 --- a/src/VBox/Runtime/testcase/Makefile.kmk +++ b/src/VBox/Runtime/testcase/Makefile.kmk @@ -84,7 +84,6 @@ PROGRAMS += \ tstRTList \ tstRTLockValidator \ tstLog \ - tstMemAutoPtr \ tstRTMemEf \ tstRTMemCache \ tstRTMemPool \ @@ -444,9 +443,6 @@ tstRTLockValidator_SOURCES = tstRTLockValidator.cpp tstLog_TEMPLATE = VBOXR3TSTEXE tstLog_SOURCES = tstLog.cpp -tstMemAutoPtr_TEMPLATE = VBOXR3TSTEXE -tstMemAutoPtr_SOURCES = tstMemAutoPtr.cpp - tstRTMemEf_TEMPLATE = VBOXR3TSTEXE tstRTMemEf_SOURCES = tstRTMemEf.cpp diff --git a/src/VBox/Runtime/testcase/tstMemAutoPtr.cpp b/src/VBox/Runtime/testcase/tstMemAutoPtr.cpp deleted file mode 100644 index 87913de57fb..00000000000 --- a/src/VBox/Runtime/testcase/tstMemAutoPtr.cpp +++ /dev/null @@ -1,292 +0,0 @@ -/* $Id$ */ -/** @file - * IPRT - Testcase the RTCMemAutoPtr template. - */ - -/* - * Copyright (C) 2008-2015 Oracle Corporation - * - * This file is part of VirtualBox Open Source Edition (OSE), as - * available from http://www.virtualbox.org. This file is free software; - * you can redistribute it and/or modify it under the terms of the GNU - * General Public License (GPL) as published by the Free Software - * Foundation, in version 2 as it comes in the "COPYING" file of the - * VirtualBox OSE distribution. VirtualBox OSE is distributed in the - * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. - * - * The contents of this file may alternatively be used under the terms - * of the Common Development and Distribution License Version 1.0 - * (CDDL) only, as it comes in the "COPYING.CDDL" file of the - * VirtualBox OSE distribution, in which case the provisions of the - * CDDL are applicable instead of those of the GPL. - * - * You may elect to license modified versions of this file under the - * terms and conditions of either the GPL or the CDDL or both. - */ - - -/********************************************************************************************************************************* -* Header Files * -*********************************************************************************************************************************/ -#include <iprt/cpp/mem.h> -#include <iprt/stream.h> -#include <iprt/initterm.h> -#include <iprt/string.h> -#include <iprt/rand.h> - - -/********************************************************************************************************************************* -* Structures and Typedefs * -*********************************************************************************************************************************/ -typedef struct TSTMEMAUTOPTRSTRUCT -{ - uint32_t a; - uint32_t b; - uint32_t c; -} TSTMEMAUTOPTRSTRUCT; - - -/********************************************************************************************************************************* -* Global Variables * -*********************************************************************************************************************************/ -#ifndef TST_MEM_AUTO_PTR_ONLY_DISAS -static unsigned g_cErrors = 0; -static unsigned g_cFrees; -#endif - - -/* - * Feel free to inspect with gdb / objdump / whatever / g++ -fverbose-asm in - * a release build and compare with tstMemAutoPtrDisas1PureC. - */ -extern "C" int tstMemAutoPtrDisas1(void **ppv) -{ - RTCMemAutoPtr<TSTMEMAUTOPTRSTRUCT> Handle(1); - if (!Handle) - { - Handle->a = RTRandU32(); - if (Handle->a < UINT32_MAX / 2) - { - *ppv = Handle.release(); - return VINF_SUCCESS; - } - } - return VERR_TRY_AGAIN; -} - -/* - * For comparing to tstMemAutoPtrDisas1. - */ -extern "C" int tstMemAutoPtrDisas1PureC(void **ppv) -{ - TSTMEMAUTOPTRSTRUCT *pHandle = (TSTMEMAUTOPTRSTRUCT *)RTMemRealloc(NULL, sizeof(*pHandle)); - if (pHandle) - { - pHandle->a = RTRandU32(); - if (pHandle->a < UINT32_MAX / 2) - { - *ppv = pHandle; - return VINF_SUCCESS; - } - RTMemFree(pHandle); - } - return VERR_TRY_AGAIN; -} - - -#ifndef TST_MEM_AUTO_PTR_ONLY_DISAS - -template <class T> -void tstMemAutoPtrDestructorCounter(T *aMem) -{ - if (aMem == NULL) - { - RTPrintf("tstMemAutoPtr(): Destructor called with NULL handle!\n"); - g_cErrors++; - } - else if (!VALID_PTR(aMem)) - { - RTPrintf("tstMemAutoPtr(): Destructor called with a bad handle %p\n", aMem); - g_cErrors++; - } - RTMemEfFreeNP(aMem); - g_cFrees++; -} - - -void *tstMemAutoPtrAllocatorNoZero(void *pvOld, size_t cbNew, const char *pszTag) -{ - void *pvNew = RTMemReallocTag(pvOld, cbNew, pszTag); - if (pvNew) - memset(pvNew, 0xfe, cbNew); - return pvNew; -} - - -int main() -{ - RTR3InitExeNoArguments(0); - RTPrintf("tstMemAutoPtr: TESTING...\n"); - -#define CHECK_EXPR(expr) \ - do { bool const f = !!(expr); if (!f) { RTPrintf("tstMemAutoPtr(%d): %s!\n", __LINE__, #expr); g_cErrors++; } } while (0) - - /* - * Some simple stuff. - */ - { - RTCMemAutoPtr<char> NilObj; - CHECK_EXPR(!NilObj); - CHECK_EXPR(NilObj.get() == NULL); - CHECK_EXPR(NilObj.release() == NULL); - NilObj.reset(); - } - - { - RTCMemAutoPtr<char> Alloc(10); - CHECK_EXPR(Alloc.get() != NULL); - char *pch = Alloc.release(); - CHECK_EXPR(pch != NULL); - CHECK_EXPR(Alloc.get() == NULL); - - RTCMemAutoPtr<char> Manage(pch); - CHECK_EXPR(Manage.get() == pch); - CHECK_EXPR(&Manage[0] == pch); - CHECK_EXPR(&Manage[1] == &pch[1]); - CHECK_EXPR(&Manage[9] == &pch[9]); - } - - /* - * Use the electric fence memory API to check alternative template - * arguments and also check some subscript / reference limit thing. - */ - { - RTCMemAutoPtr<char, RTCMemEfAutoFree<char>, RTMemEfReallocNP> Electric(10); - CHECK_EXPR(Electric.get() != NULL); - Electric[0] = '0'; - CHECK_EXPR(Electric[0] == '0'); - CHECK_EXPR(*Electric == '0'); - //CHECK_EXPR(Electric == '0'); - Electric[9] = '1'; - CHECK_EXPR(Electric[9] == '1'); - /* Electric[10] = '2'; - this will crash (of course) */ - } - - /* - * Check that memory is actually free when it should be and isn't when it shouldn't. - * Use the electric heap to get some extra checks. - */ - g_cFrees = 0; - { - RTCMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> FreeIt(128); - FreeIt[127] = '0'; - } - CHECK_EXPR(g_cFrees == 1); - - g_cFrees = 0; - { - RTCMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> FreeIt2(128); - FreeIt2[127] = '1'; - FreeIt2.reset(); - FreeIt2.alloc(128); - FreeIt2[127] = '2'; - FreeIt2.reset(FreeIt2.get()); /* this one is weird, but it's how things works... */ - } - CHECK_EXPR(g_cFrees == 2); - - g_cFrees = 0; - { - RTCMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> DontFreeIt(256); - DontFreeIt[255] = '0'; - RTMemEfFreeNP(DontFreeIt.release()); - } - CHECK_EXPR(g_cFrees == 0); - - g_cFrees = 0; - { - RTCMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> FreeIt3(128); - FreeIt3[127] = '0'; - CHECK_EXPR(FreeIt3.realloc(128)); - FreeIt3[127] = '0'; - CHECK_EXPR(FreeIt3.realloc(256)); - FreeIt3[255] = '0'; - CHECK_EXPR(FreeIt3.realloc(64)); - FreeIt3[63] = '0'; - CHECK_EXPR(FreeIt3.realloc(32)); - FreeIt3[31] = '0'; - } - CHECK_EXPR(g_cFrees == 1); - - g_cFrees = 0; - { - RTCMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> FreeIt4; - CHECK_EXPR(FreeIt4.alloc(123)); - CHECK_EXPR(FreeIt4.realloc(543)); - FreeIt4 = (char *)NULL; - CHECK_EXPR(FreeIt4.get() == NULL); - } - CHECK_EXPR(g_cFrees == 1); - - /* - * Check the ->, [] and * (unary) operators with some useful struct. - */ - { - RTCMemAutoPtr<TSTMEMAUTOPTRSTRUCT> Struct1(1); - Struct1->a = 0x11223344; - Struct1->b = 0x55667788; - Struct1->c = 0x99aabbcc; - CHECK_EXPR(Struct1->a == 0x11223344); - CHECK_EXPR(Struct1->b == 0x55667788); - CHECK_EXPR(Struct1->c == 0x99aabbcc); - - Struct1[0].a = 0x11223344; - Struct1[0].b = 0x55667788; - Struct1[0].c = 0x99aabbcc; - CHECK_EXPR(Struct1[0].a == 0x11223344); - CHECK_EXPR(Struct1[0].b == 0x55667788); - CHECK_EXPR(Struct1[0].c == 0x99aabbcc); - - (*Struct1).a = 0x11223344; - (*Struct1).b = 0x55667788; - (*Struct1).c = 0x99aabbcc; - CHECK_EXPR((*Struct1).a == 0x11223344); - CHECK_EXPR((*Struct1).b == 0x55667788); - CHECK_EXPR((*Struct1).c == 0x99aabbcc); - - /* since at it... */ - Struct1.get()->a = 0x11223344; - Struct1.get()->b = 0x55667788; - Struct1.get()->c = 0x99aabbcc; - CHECK_EXPR(Struct1.get()->a == 0x11223344); - CHECK_EXPR(Struct1.get()->b == 0x55667788); - CHECK_EXPR(Struct1.get()->c == 0x99aabbcc); - } - - /* - * Check the zeroing of memory. - */ - { - RTCMemAutoPtr<uint64_t, RTCMemAutoDestructor<uint64_t>, tstMemAutoPtrAllocatorNoZero> Zeroed1(1, true); - CHECK_EXPR(*Zeroed1 == 0); - } - - { - RTCMemAutoPtr<uint64_t, RTCMemAutoDestructor<uint64_t>, tstMemAutoPtrAllocatorNoZero> Zeroed2; - Zeroed2.alloc(5, true); - CHECK_EXPR(Zeroed2[0] == 0); - CHECK_EXPR(Zeroed2[1] == 0); - CHECK_EXPR(Zeroed2[2] == 0); - CHECK_EXPR(Zeroed2[3] == 0); - CHECK_EXPR(Zeroed2[4] == 0); - } - - /* - * Summary. - */ - if (!g_cErrors) - RTPrintf("tstMemAutoPtr: SUCCESS\n"); - else - RTPrintf("tstMemAutoPtr: FAILED - %d errors\n", g_cErrors); - return !!g_cErrors; -} -#endif /* TST_MEM_AUTO_PTR_ONLY_DISAS */ diff --git a/src/VBox/Runtime/testcase/tstRTDvm.cpp b/src/VBox/Runtime/testcase/tstRTDvm.cpp index 2327e043ef4..4c3da442dea 100644 --- a/src/VBox/Runtime/testcase/tstRTDvm.cpp +++ b/src/VBox/Runtime/testcase/tstRTDvm.cpp @@ -58,7 +58,7 @@ typedef struct TSTRTDVMDISK -static int dvmDiskRead(void *pvUser, uint64_t off, void *pvBuf, size_t cbRead) +static DECLCALLBACK(int) dvmDiskRead(void *pvUser, uint64_t off, void *pvBuf, size_t cbRead) { PTSTRTDVMDISK pDisk = (PTSTRTDVMDISK)pvUser; @@ -67,7 +67,7 @@ static int dvmDiskRead(void *pvUser, uint64_t off, void *pvBuf, size_t cbRead) return RTDvmVolumeRead(pDisk->hVol, off, pvBuf, cbRead); } -static int dvmDiskWrite(void *pvUser, uint64_t off, const void *pvBuf, size_t cbWrite) +static DECLCALLBACK(int) dvmDiskWrite(void *pvUser, uint64_t off, const void *pvBuf, size_t cbWrite) { PTSTRTDVMDISK pDisk = (PTSTRTDVMDISK)pvUser; diff --git a/src/VBox/ValidationKit/utils/cpu/cidet.h b/src/VBox/ValidationKit/utils/cpu/cidet.h index 18a965db160..8d5c63a0fd5 100644 --- a/src/VBox/ValidationKit/utils/cpu/cidet.h +++ b/src/VBox/ValidationKit/utils/cpu/cidet.h @@ -118,7 +118,7 @@ * @param fInvalid When set, get the next invalid operands that will * cause exceptions/faults. */ -typedef int FNCIDETSETUPINOUT(struct CIDETCORE *pThis, bool fInvalid); +typedef DECLCALLBACK(int) FNCIDETSETUPINOUT(struct CIDETCORE *pThis, bool fInvalid); /** Pointer to a FNCIDETSETUPINOUT function. */ typedef FNCIDETSETUPINOUT *PFNCIDETSETUPINOUT; diff --git a/src/VBox/ValidationKit/utils/network/NetPerf.cpp b/src/VBox/ValidationKit/utils/network/NetPerf.cpp index 6d839dffb81..ead20e837b2 100644 --- a/src/VBox/ValidationKit/utils/network/NetPerf.cpp +++ b/src/VBox/ValidationKit/utils/network/NetPerf.cpp @@ -319,7 +319,7 @@ static void Usage(PRTSTREAM pStrm) * @param pvUser Pointer to the stop variable. * @param iTick The tick, ignored. */ -static void netperfStopTimerCallback(RTTIMERLR hTimer, void *pvUser, uint64_t iTick) +static DECLCALLBACK(void) netperfStopTimerCallback(RTTIMERLR hTimer, void *pvUser, uint64_t iTick) { bool volatile *pfStop = (bool volatile *)pvUser; /* RTPrintf("Time's Up!\n");*/ |