diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-03-26 19:21:20 +0000 |
---|---|---|
committer | <> | 2014-05-08 15:03:54 +0000 |
commit | fb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch) | |
tree | c2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Runtime/generic | |
parent | 58ed4748338f9466599adfc8a9171280ed99e23f (diff) | |
download | VirtualBox-master.tar.gz |
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Runtime/generic')
76 files changed, 1305 insertions, 113 deletions
diff --git a/src/VBox/Runtime/generic/RTAssertShouldPanic-generic.cpp b/src/VBox/Runtime/generic/RTAssertShouldPanic-generic.cpp index 52ea2eef..7c359ff2 100644 --- a/src/VBox/Runtime/generic/RTAssertShouldPanic-generic.cpp +++ b/src/VBox/Runtime/generic/RTAssertShouldPanic-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTDirExists-generic.cpp b/src/VBox/Runtime/generic/RTDirExists-generic.cpp index 0b5f04a9..186160d3 100644 --- a/src/VBox/Runtime/generic/RTDirExists-generic.cpp +++ b/src/VBox/Runtime/generic/RTDirExists-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTDirQueryInfo-generic.cpp b/src/VBox/Runtime/generic/RTDirQueryInfo-generic.cpp index a01a8d80..8e92bf14 100644 --- a/src/VBox/Runtime/generic/RTDirQueryInfo-generic.cpp +++ b/src/VBox/Runtime/generic/RTDirQueryInfo-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTDirSetTimes-generic.cpp b/src/VBox/Runtime/generic/RTDirSetTimes-generic.cpp index b5b781e2..1616c4f4 100644 --- a/src/VBox/Runtime/generic/RTDirSetTimes-generic.cpp +++ b/src/VBox/Runtime/generic/RTDirSetTimes-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTFileCopy-generic.cpp b/src/VBox/Runtime/generic/RTFileCopy-generic.cpp index ea55290c..a87ecb49 100644 --- a/src/VBox/Runtime/generic/RTFileCopy-generic.cpp +++ b/src/VBox/Runtime/generic/RTFileCopy-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTFileExists-generic.cpp b/src/VBox/Runtime/generic/RTFileExists-generic.cpp index f8198816..e238361d 100644 --- a/src/VBox/Runtime/generic/RTFileExists-generic.cpp +++ b/src/VBox/Runtime/generic/RTFileExists-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTFileMove-generic.cpp b/src/VBox/Runtime/generic/RTFileMove-generic.cpp index 21556ec7..3b4e9897 100644 --- a/src/VBox/Runtime/generic/RTFileMove-generic.cpp +++ b/src/VBox/Runtime/generic/RTFileMove-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTFileQuerySize-generic.cpp b/src/VBox/Runtime/generic/RTFileQuerySize-generic.cpp index a561eea6..8ff41f46 100644 --- a/src/VBox/Runtime/generic/RTFileQuerySize-generic.cpp +++ b/src/VBox/Runtime/generic/RTFileQuerySize-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTFileReadAll-generic.cpp b/src/VBox/Runtime/generic/RTFileReadAll-generic.cpp index 71c0af12..1eb3f367 100644 --- a/src/VBox/Runtime/generic/RTFileReadAll-generic.cpp +++ b/src/VBox/Runtime/generic/RTFileReadAll-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTFileReadAllByHandle-generic.cpp b/src/VBox/Runtime/generic/RTFileReadAllByHandle-generic.cpp index 2d94160f..05a32e66 100644 --- a/src/VBox/Runtime/generic/RTFileReadAllByHandle-generic.cpp +++ b/src/VBox/Runtime/generic/RTFileReadAllByHandle-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTFileReadAllByHandleEx-generic.cpp b/src/VBox/Runtime/generic/RTFileReadAllByHandleEx-generic.cpp index 0c41126c..5d5f01f1 100644 --- a/src/VBox/Runtime/generic/RTFileReadAllByHandleEx-generic.cpp +++ b/src/VBox/Runtime/generic/RTFileReadAllByHandleEx-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTFileReadAllEx-generic.cpp b/src/VBox/Runtime/generic/RTFileReadAllEx-generic.cpp index 2046d731..98f92a81 100644 --- a/src/VBox/Runtime/generic/RTFileReadAllEx-generic.cpp +++ b/src/VBox/Runtime/generic/RTFileReadAllEx-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTFileReadAllFree-generic.cpp b/src/VBox/Runtime/generic/RTFileReadAllFree-generic.cpp index 1f1dd292..2bdcc5c7 100644 --- a/src/VBox/Runtime/generic/RTFileReadAllFree-generic.cpp +++ b/src/VBox/Runtime/generic/RTFileReadAllFree-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTLogDefaultInit-generic.cpp b/src/VBox/Runtime/generic/RTLogDefaultInit-generic.cpp index 5a1e122c..7a44173b 100644 --- a/src/VBox/Runtime/generic/RTLogDefaultInit-generic.cpp +++ b/src/VBox/Runtime/generic/RTLogDefaultInit-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTLogWriteDebugger-generic.cpp b/src/VBox/Runtime/generic/RTLogWriteDebugger-generic.cpp index 116900b5..a295fd05 100644 --- a/src/VBox/Runtime/generic/RTLogWriteDebugger-generic.cpp +++ b/src/VBox/Runtime/generic/RTLogWriteDebugger-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTLogWriteStdErr-generic.cpp b/src/VBox/Runtime/generic/RTLogWriteStdErr-generic.cpp index fc7af981..0f72f31b 100644 --- a/src/VBox/Runtime/generic/RTLogWriteStdErr-generic.cpp +++ b/src/VBox/Runtime/generic/RTLogWriteStdErr-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTLogWriteStdErr-stub-generic.cpp b/src/VBox/Runtime/generic/RTLogWriteStdErr-stub-generic.cpp index 4a42187a..946df0ea 100644 --- a/src/VBox/Runtime/generic/RTLogWriteStdErr-stub-generic.cpp +++ b/src/VBox/Runtime/generic/RTLogWriteStdErr-stub-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTLogWriteStdOut-generic.cpp b/src/VBox/Runtime/generic/RTLogWriteStdOut-generic.cpp index a358c08d..cb5377fc 100644 --- a/src/VBox/Runtime/generic/RTLogWriteStdOut-generic.cpp +++ b/src/VBox/Runtime/generic/RTLogWriteStdOut-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTLogWriteStdOut-stub-generic.cpp b/src/VBox/Runtime/generic/RTLogWriteStdOut-stub-generic.cpp index 99b6b2bb..a154edeb 100644 --- a/src/VBox/Runtime/generic/RTLogWriteStdOut-stub-generic.cpp +++ b/src/VBox/Runtime/generic/RTLogWriteStdOut-stub-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTLogWriteUser-generic.cpp b/src/VBox/Runtime/generic/RTLogWriteUser-generic.cpp index 2fe4d0df..a9cdab7f 100644 --- a/src/VBox/Runtime/generic/RTLogWriteUser-generic.cpp +++ b/src/VBox/Runtime/generic/RTLogWriteUser-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpCpuId-generic.cpp b/src/VBox/Runtime/generic/RTMpCpuId-generic.cpp index 591d8318..59a7e33a 100644 --- a/src/VBox/Runtime/generic/RTMpCpuId-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpCpuId-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpCpuIdFromSetIndex-generic.cpp b/src/VBox/Runtime/generic/RTMpCpuIdFromSetIndex-generic.cpp index 2fec3382..91842c08 100644 --- a/src/VBox/Runtime/generic/RTMpCpuIdFromSetIndex-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpCpuIdFromSetIndex-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpCpuIdToSetIndex-generic.cpp b/src/VBox/Runtime/generic/RTMpCpuIdToSetIndex-generic.cpp index 894f8f4f..6cda69fb 100644 --- a/src/VBox/Runtime/generic/RTMpCpuIdToSetIndex-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpCpuIdToSetIndex-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpGetArraySize-generic.cpp b/src/VBox/Runtime/generic/RTMpGetArraySize-generic.cpp index c65eeb2e..08504976 100644 --- a/src/VBox/Runtime/generic/RTMpGetArraySize-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpGetArraySize-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2010-2011 Oracle Corporation + * Copyright (C) 2010-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpGetCoreCount-generic.cpp b/src/VBox/Runtime/generic/RTMpGetCoreCount-generic.cpp new file mode 100644 index 00000000..9155bc4b --- /dev/null +++ b/src/VBox/Runtime/generic/RTMpGetCoreCount-generic.cpp @@ -0,0 +1,40 @@ +/* $Id: RTMpGetCoreCount-generic.cpp $ */ +/** @file + * IPRT - Multiprocessor, Generic RTMpGetCoreCount. + */ + +/* + * Copyright (C) 2013 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/mp.h> +#include "internal/iprt.h" + + +RTDECL(RTCPUID) RTMpGetCoreCount(void) +{ + return RTMpGetCount(); +} +RT_EXPORT_SYMBOL(RTMpGetCoreCount); + diff --git a/src/VBox/Runtime/generic/RTMpGetCount-generic.cpp b/src/VBox/Runtime/generic/RTMpGetCount-generic.cpp index f8625e18..af5cb9fc 100644 --- a/src/VBox/Runtime/generic/RTMpGetCount-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpGetCount-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpGetCurFrequency-generic.cpp b/src/VBox/Runtime/generic/RTMpGetCurFrequency-generic.cpp index 04c9a68d..f4509e0e 100644 --- a/src/VBox/Runtime/generic/RTMpGetCurFrequency-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpGetCurFrequency-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpGetDescription-generic-stub.cpp b/src/VBox/Runtime/generic/RTMpGetDescription-generic-stub.cpp index a3c17668..e0c8cb7b 100644 --- a/src/VBox/Runtime/generic/RTMpGetDescription-generic-stub.cpp +++ b/src/VBox/Runtime/generic/RTMpGetDescription-generic-stub.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpGetDescription-generic.cpp b/src/VBox/Runtime/generic/RTMpGetDescription-generic.cpp index dccd4058..fbf11f2a 100644 --- a/src/VBox/Runtime/generic/RTMpGetDescription-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpGetDescription-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -99,10 +99,11 @@ RTDECL(int) RTMpGetDescription(RTCPUID idCpu, char *pszBuf, size_t cbBuf) /* * Copy it out into the buffer supplied by the caller. */ - size_t cch = strlen(szString); - if (cch >= cbBuf) + char *pszSrc = RTStrStrip(szString); + size_t cchSrc = strlen(pszSrc); + if (cchSrc >= cbBuf) return VERR_BUFFER_OVERFLOW; - memcpy(pszBuf, szString, cch + 1); + memcpy(pszBuf, pszSrc, cchSrc + 1); return VINF_SUCCESS; } RT_EXPORT_SYMBOL(RTMpGetDescription); diff --git a/src/VBox/Runtime/generic/RTMpGetMaxCpuId-generic.cpp b/src/VBox/Runtime/generic/RTMpGetMaxCpuId-generic.cpp index e7963301..8c385471 100644 --- a/src/VBox/Runtime/generic/RTMpGetMaxCpuId-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpGetMaxCpuId-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpGetMaxFrequency-generic.cpp b/src/VBox/Runtime/generic/RTMpGetMaxFrequency-generic.cpp index 4f468d88..197928f3 100644 --- a/src/VBox/Runtime/generic/RTMpGetMaxFrequency-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpGetMaxFrequency-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpGetOnlineCoreCount-generic.cpp b/src/VBox/Runtime/generic/RTMpGetOnlineCoreCount-generic.cpp new file mode 100644 index 00000000..19f78141 --- /dev/null +++ b/src/VBox/Runtime/generic/RTMpGetOnlineCoreCount-generic.cpp @@ -0,0 +1,40 @@ +/* $Id: RTMpGetOnlineCoreCount-generic.cpp $ */ +/** @file + * IPRT - Multiprocessor, Generic RTMpGetCoreCount. + */ + +/* + * Copyright (C) 2013 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/mp.h> +#include "internal/iprt.h" + + +RTDECL(RTCPUID) RTMpGetOnlineCoreCount(void) +{ + return RTMpGetOnlineCount(); +} +RT_EXPORT_SYMBOL(RTMpGetOnlineCoreCount); + diff --git a/src/VBox/Runtime/generic/RTMpGetOnlineCount-generic.cpp b/src/VBox/Runtime/generic/RTMpGetOnlineCount-generic.cpp index e11543e0..40be3d00 100644 --- a/src/VBox/Runtime/generic/RTMpGetOnlineCount-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpGetOnlineCount-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpGetOnlineSet-generic.cpp b/src/VBox/Runtime/generic/RTMpGetOnlineSet-generic.cpp index 753ee62d..b3a4fee4 100644 --- a/src/VBox/Runtime/generic/RTMpGetOnlineSet-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpGetOnlineSet-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpGetSet-generic.cpp b/src/VBox/Runtime/generic/RTMpGetSet-generic.cpp index 01b72496..debd0524 100644 --- a/src/VBox/Runtime/generic/RTMpGetSet-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpGetSet-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpIsCpuOnline-generic.cpp b/src/VBox/Runtime/generic/RTMpIsCpuOnline-generic.cpp index b53c13ae..987b60a6 100644 --- a/src/VBox/Runtime/generic/RTMpIsCpuOnline-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpIsCpuOnline-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTMpIsCpuPossible-generic.cpp b/src/VBox/Runtime/generic/RTMpIsCpuPossible-generic.cpp index 7c57ae83..67256312 100644 --- a/src/VBox/Runtime/generic/RTMpIsCpuPossible-generic.cpp +++ b/src/VBox/Runtime/generic/RTMpIsCpuPossible-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTPathIsSame-generic.cpp b/src/VBox/Runtime/generic/RTPathIsSame-generic.cpp new file mode 100644 index 00000000..2ed42a5f --- /dev/null +++ b/src/VBox/Runtime/generic/RTPathIsSame-generic.cpp @@ -0,0 +1,93 @@ +/* $Id: RTPathIsSame-generic.cpp $ */ +/** @file + * IPRT - Assertions, generic RTPathIsSame. + */ + +/* + * Copyright (C) 2013 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/path.h> +#include "internal/iprt.h" + +#include <iprt/string.h> + + +RTDECL(int) RTPathIsSame(const char *pszPath1, const char *pszPath2) +{ + /* + * Simple checks based on the path values. + */ + if (pszPath1 == pszPath2) + return true; + if (!pszPath1) + return false; + if (!pszPath2) + return false; + if (!strcmp(pszPath1, pszPath2)) + return true; + + /* + * If the files exist, try use the attributes. + */ + RTFSOBJINFO ObjInfo1, ObjInfo2; + int rc = RTPathQueryInfoEx(pszPath1, &ObjInfo1, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK); + if (RT_SUCCESS(rc)) + rc = RTPathQueryInfoEx(pszPath2, &ObjInfo2, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK); + if (RT_SUCCESS(rc)) + { + if ((ObjInfo1.Attr.fMode & RTFS_TYPE_MASK) != (ObjInfo2.Attr.fMode & RTFS_TYPE_MASK)) + return false; + if (ObjInfo1.Attr.u.Unix.INodeIdDevice != ObjInfo2.Attr.u.Unix.INodeIdDevice) + return false; + if (ObjInfo1.Attr.u.Unix.INodeId != ObjInfo2.Attr.u.Unix.INodeId) + return false; + if (ObjInfo1.Attr.u.Unix.GenerationId != ObjInfo2.Attr.u.Unix.GenerationId) + return false; + if ( ObjInfo1.Attr.u.Unix.INodeIdDevice != 0 + && ObjInfo1.Attr.u.Unix.INodeId != 0) + return true; + } + + /* + * Fallback, compare absolute/real paths. Return failure on paths that are + * too long. + */ + char szPath1[RTPATH_MAX]; + rc = RTPathAbs(pszPath1, szPath1, sizeof(szPath1)); + AssertRCReturn(rc, VERR_FILENAME_TOO_LONG); + + char szPath2[RTPATH_MAX]; + rc = RTPathAbs(pszPath2, szPath2, sizeof(szPath2)); AssertRC(rc); + AssertRCReturn(rc, VERR_FILENAME_TOO_LONG); + + if (RTPathCompare(szPath1, szPath2) == 0) + return true; + + /** @todo Relsolve any symbolic links in the paths. Too lazy for that right + * now. */ + return false; +} +RT_EXPORT_SYMBOL(RTPathIsSame); + diff --git a/src/VBox/Runtime/generic/RTProcDaemonize-generic.cpp b/src/VBox/Runtime/generic/RTProcDaemonize-generic.cpp index 3ee4d28b..744dce9b 100644 --- a/src/VBox/Runtime/generic/RTProcDaemonize-generic.cpp +++ b/src/VBox/Runtime/generic/RTProcDaemonize-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2010 Oracle Corporation + * Copyright (C) 2010-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -80,7 +80,8 @@ RTR3DECL(int) RTProcDaemonize(const char * const *papszArgs, const char *pszDaem { hStdOutAndErr.enmType = RTHANDLETYPE_FILE; - rc = RTProcCreateEx(szExecPath, papszNewArgs, RTENV_DEFAULT, RTPROC_FLAGS_DETACHED, + rc = RTProcCreateEx(szExecPath, papszNewArgs, RTENV_DEFAULT, + RTPROC_FLAGS_DETACHED | RTPROC_FLAGS_SAME_CONTRACT, &hStdIn, &hStdOutAndErr, &hStdOutAndErr, NULL /*pszAsUser*/, NULL /*pszPassword*/, NULL /*phProcess*/); diff --git a/src/VBox/Runtime/generic/RTProcIsRunningByName-generic.cpp b/src/VBox/Runtime/generic/RTProcIsRunningByName-generic.cpp index 1682369a..56eb5191 100644 --- a/src/VBox/Runtime/generic/RTProcIsRunningByName-generic.cpp +++ b/src/VBox/Runtime/generic/RTProcIsRunningByName-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTProcessQueryUsernameA-generic.cpp b/src/VBox/Runtime/generic/RTProcessQueryUsernameA-generic.cpp index 9fcba42c..cd7790b6 100644 --- a/src/VBox/Runtime/generic/RTProcessQueryUsernameA-generic.cpp +++ b/src/VBox/Runtime/generic/RTProcessQueryUsernameA-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTRandAdvCreateSystemFaster-generic.cpp b/src/VBox/Runtime/generic/RTRandAdvCreateSystemFaster-generic.cpp index 0b05fa5e..1aaab2d2 100644 --- a/src/VBox/Runtime/generic/RTRandAdvCreateSystemFaster-generic.cpp +++ b/src/VBox/Runtime/generic/RTRandAdvCreateSystemFaster-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTRandAdvCreateSystemTruer-generic.cpp b/src/VBox/Runtime/generic/RTRandAdvCreateSystemTruer-generic.cpp index 375757a7..402ccb80 100644 --- a/src/VBox/Runtime/generic/RTRandAdvCreateSystemTruer-generic.cpp +++ b/src/VBox/Runtime/generic/RTRandAdvCreateSystemTruer-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTSemEventMultiWait-2-ex-generic.cpp b/src/VBox/Runtime/generic/RTSemEventMultiWait-2-ex-generic.cpp index 437be6be..af7933ec 100644 --- a/src/VBox/Runtime/generic/RTSemEventMultiWait-2-ex-generic.cpp +++ b/src/VBox/Runtime/generic/RTSemEventMultiWait-2-ex-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2010 Oracle Corporation + * Copyright (C) 2010-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTSemEventMultiWait-generic.cpp b/src/VBox/Runtime/generic/RTSemEventMultiWait-generic.cpp index 16a9580b..46ee3c6b 100644 --- a/src/VBox/Runtime/generic/RTSemEventMultiWait-generic.cpp +++ b/src/VBox/Runtime/generic/RTSemEventMultiWait-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2009 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp b/src/VBox/Runtime/generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp index c3eb88db..19175a78 100644 --- a/src/VBox/Runtime/generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp +++ b/src/VBox/Runtime/generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2010 Oracle Corporation + * Copyright (C) 2010-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTSemEventWait-2-ex-generic.cpp b/src/VBox/Runtime/generic/RTSemEventWait-2-ex-generic.cpp index b2e78807..650d25e5 100644 --- a/src/VBox/Runtime/generic/RTSemEventWait-2-ex-generic.cpp +++ b/src/VBox/Runtime/generic/RTSemEventWait-2-ex-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2010 Oracle Corporation + * Copyright (C) 2010-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTSemEventWait-generic.cpp b/src/VBox/Runtime/generic/RTSemEventWait-generic.cpp index ade77808..b24fe9dc 100644 --- a/src/VBox/Runtime/generic/RTSemEventWait-generic.cpp +++ b/src/VBox/Runtime/generic/RTSemEventWait-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2009 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTSemEventWaitNoResume-2-ex-generic.cpp b/src/VBox/Runtime/generic/RTSemEventWaitNoResume-2-ex-generic.cpp index 3dbe66cd..2c8181ef 100644 --- a/src/VBox/Runtime/generic/RTSemEventWaitNoResume-2-ex-generic.cpp +++ b/src/VBox/Runtime/generic/RTSemEventWaitNoResume-2-ex-generic.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2010 Oracle Corporation + * Copyright (C) 2010-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTSemMutexRequest-generic.cpp b/src/VBox/Runtime/generic/RTSemMutexRequest-generic.cpp index 32c3f876..0ef65f43 100644 --- a/src/VBox/Runtime/generic/RTSemMutexRequest-generic.cpp +++ b/src/VBox/Runtime/generic/RTSemMutexRequest-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2009 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTSemMutexRequestDebug-generic.cpp b/src/VBox/Runtime/generic/RTSemMutexRequestDebug-generic.cpp index 4ba15039..a26b4af1 100644 --- a/src/VBox/Runtime/generic/RTSemMutexRequestDebug-generic.cpp +++ b/src/VBox/Runtime/generic/RTSemMutexRequestDebug-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2009 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTSystemQueryOSInfo-generic.cpp b/src/VBox/Runtime/generic/RTSystemQueryOSInfo-generic.cpp index ec52c77d..7ba8e781 100644 --- a/src/VBox/Runtime/generic/RTSystemQueryOSInfo-generic.cpp +++ b/src/VBox/Runtime/generic/RTSystemQueryOSInfo-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTTimeLocalDeltaNano-generic.cpp b/src/VBox/Runtime/generic/RTTimeLocalDeltaNano-generic.cpp index 92826f0e..c24b5f38 100644 --- a/src/VBox/Runtime/generic/RTTimeLocalDeltaNano-generic.cpp +++ b/src/VBox/Runtime/generic/RTTimeLocalDeltaNano-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTTimeLocalExplode-generic.cpp b/src/VBox/Runtime/generic/RTTimeLocalExplode-generic.cpp index ae760602..b7b4e567 100644 --- a/src/VBox/Runtime/generic/RTTimeLocalExplode-generic.cpp +++ b/src/VBox/Runtime/generic/RTTimeLocalExplode-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTTimeLocalNow-generic.cpp b/src/VBox/Runtime/generic/RTTimeLocalNow-generic.cpp index f3d268eb..f26124e7 100644 --- a/src/VBox/Runtime/generic/RTTimeLocalNow-generic.cpp +++ b/src/VBox/Runtime/generic/RTTimeLocalNow-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTTimerLRCreate-generic.cpp b/src/VBox/Runtime/generic/RTTimerLRCreate-generic.cpp index 6af2c79a..415fcd05 100644 --- a/src/VBox/Runtime/generic/RTTimerLRCreate-generic.cpp +++ b/src/VBox/Runtime/generic/RTTimerLRCreate-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2008 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/RTUuidCreate-generic.cpp b/src/VBox/Runtime/generic/RTUuidCreate-generic.cpp index e88ab1ff..439bf7bc 100644 --- a/src/VBox/Runtime/generic/RTUuidCreate-generic.cpp +++ b/src/VBox/Runtime/generic/RTUuidCreate-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/cdrom-generic.cpp b/src/VBox/Runtime/generic/cdrom-generic.cpp index 13e8e96f..65332a58 100644 --- a/src/VBox/Runtime/generic/cdrom-generic.cpp +++ b/src/VBox/Runtime/generic/cdrom-generic.cpp @@ -28,7 +28,6 @@ /******************************************************************************* * Header Files * *******************************************************************************/ -#define RTCRITSECT_WITHOUT_REMAPPING #include <iprt/cdrom.h> #include "internal/iprt.h" diff --git a/src/VBox/Runtime/generic/createtemp-generic.cpp b/src/VBox/Runtime/generic/createtemp-generic.cpp index 984dc1bf..addbb5db 100644 --- a/src/VBox/Runtime/generic/createtemp-generic.cpp +++ b/src/VBox/Runtime/generic/createtemp-generic.cpp @@ -149,7 +149,7 @@ RTDECL(int) RTDirCreateTempSecure(char *pszTemplate) /* bool fSafe; */ /* Temporarily convert pszTemplate to a path. */ - RTPathParse(pszTemplate, &cchDir, NULL, NULL); + RTPathParseSimple(pszTemplate, &cchDir, NULL, NULL); chOld = pszTemplate[cchDir]; pszTemplate[cchDir] = '\0'; /** @todo Implement this. */ @@ -218,7 +218,7 @@ RTDECL(int) RTFileCreateTempSecure(char *pszTemplate) /* bool fSafe; */ /* Temporarily convert pszTemplate to a path. */ - RTPathParse(pszTemplate, &cchDir, NULL, NULL); + RTPathParseSimple(pszTemplate, &cchDir, NULL, NULL); chOld = pszTemplate[cchDir]; pszTemplate[cchDir] = '\0'; /** @todo Implement this. */ diff --git a/src/VBox/Runtime/generic/critsect-generic.cpp b/src/VBox/Runtime/generic/critsect-generic.cpp index ed276451..4258fcff 100644 --- a/src/VBox/Runtime/generic/critsect-generic.cpp +++ b/src/VBox/Runtime/generic/critsect-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2011 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/critsectrw-generic.cpp b/src/VBox/Runtime/generic/critsectrw-generic.cpp new file mode 100644 index 00000000..41099ec9 --- /dev/null +++ b/src/VBox/Runtime/generic/critsectrw-generic.cpp @@ -0,0 +1,917 @@ +/* $Id: critsectrw-generic.cpp $ */ +/** @file + * IPRT - Read/Write Critical Section, Generic. + */ + +/* + * Copyright (C) 2009-2013 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 * +*******************************************************************************/ +#define RTCRITSECTRW_WITHOUT_REMAPPING +#define RTASSERT_QUIET +#include <iprt/critsect.h> +#include "internal/iprt.h" + +#include <iprt/asm.h> +#include <iprt/assert.h> +#include <iprt/err.h> +#include <iprt/lockvalidator.h> +#include <iprt/mem.h> +#include <iprt/semaphore.h> +#include <iprt/thread.h> + +#include "internal/magics.h" +#include "internal/strict.h" + + + +RTDECL(int) RTCritSectRwInit(PRTCRITSECTRW pThis) +{ + return RTCritSectRwInitEx(pThis, 0, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTCritSectRw"); +} +RT_EXPORT_SYMBOL(RTCritSectRwInit); + + +RTDECL(int) RTCritSectRwInitEx(PRTCRITSECTRW pThis, uint32_t fFlags, + RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...) +{ + int rc; + AssertReturn(!(fFlags & ~( RTCRITSECT_FLAGS_NO_NESTING | RTCRITSECT_FLAGS_NO_LOCK_VAL | RTCRITSECT_FLAGS_BOOTSTRAP_HACK + | RTCRITSECT_FLAGS_NOP )), + VERR_INVALID_PARAMETER); + + /* + * Initialize the structure, allocate the lock validator stuff and sems. + */ + pThis->u32Magic = RTCRITSECTRW_MAGIC_DEAD; + pThis->fNeedReset = false; + pThis->u64State = 0; + pThis->hNativeWriter = NIL_RTNATIVETHREAD; + pThis->cWriterReads = 0; + pThis->cWriteRecursions = 0; + pThis->hEvtWrite = NIL_RTSEMEVENT; + pThis->hEvtRead = NIL_RTSEMEVENTMULTI; + pThis->pValidatorWrite = NULL; + pThis->pValidatorRead = NULL; +#if HC_ARCH_BITS == 32 + pThis->HCPtrPadding = NIL_RTHCPTR; +#endif + +#ifdef RTCRITSECTRW_STRICT + bool const fLVEnabled = !(fFlags & RTCRITSECT_FLAGS_NO_LOCK_VAL); + if (!pszNameFmt) + { + static uint32_t volatile s_iAnon = 0; + uint32_t i = ASMAtomicIncU32(&s_iAnon) - 1; + rc = RTLockValidatorRecExclCreate(&pThis->pValidatorWrite, hClass, uSubClass, pThis, + fLVEnabled, "RTCritSectRw-%u", i); + if (RT_SUCCESS(rc)) + rc = RTLockValidatorRecSharedCreate(&pThis->pValidatorRead, hClass, uSubClass, pThis, + false /*fSignaller*/, fLVEnabled, "RTCritSectRw-%u", i); + } + else + { + va_list va; + va_start(va, pszNameFmt); + rc = RTLockValidatorRecExclCreateV(&pThis->pValidatorWrite, hClass, uSubClass, pThis, + fLVEnabled, pszNameFmt, va); + va_end(va); + if (RT_SUCCESS(rc)) + { + va_start(va, pszNameFmt); + RTLockValidatorRecSharedCreateV(&pThis->pValidatorRead, hClass, uSubClass, pThis, + false /*fSignaller*/, fLVEnabled, pszNameFmt, va); + va_end(va); + } + } + if (RT_SUCCESS(rc)) + rc = RTLockValidatorRecMakeSiblings(&pThis->pValidatorWrite->Core, &pThis->pValidatorRead->Core); + + if (RT_SUCCESS(rc)) +#endif + { + rc = RTSemEventMultiCreate(&pThis->hEvtRead); + if (RT_SUCCESS(rc)) + { + rc = RTSemEventCreate(&pThis->hEvtWrite); + if (RT_SUCCESS(rc)) + { + pThis->u32Magic = RTCRITSECTRW_MAGIC; + return VINF_SUCCESS; + } + RTSemEventMultiDestroy(pThis->hEvtRead); + } + } + +#ifdef RTCRITSECTRW_STRICT + RTLockValidatorRecSharedDestroy(&pThis->pValidatorRead); + RTLockValidatorRecExclDestroy(&pThis->pValidatorWrite); +#endif + return rc; +} +RT_EXPORT_SYMBOL(RTCritSectRwInitEx); + + +RTDECL(uint32_t) RTCritSectRwSetSubClass(PRTCRITSECTRW pThis, uint32_t uSubClass) +{ + AssertPtrReturn(pThis, RTLOCKVAL_SUB_CLASS_INVALID); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID); +#ifdef RTCRITSECTRW_STRICT + AssertReturn(!(pThis->fFlags & RTCRITSECT_FLAGS_NOP), RTLOCKVAL_SUB_CLASS_INVALID); + + RTLockValidatorRecSharedSetSubClass(pThis->pValidatorRead, uSubClass); + return RTLockValidatorRecExclSetSubClass(pThis->pValidatorWrite, uSubClass); +#else + NOREF(uSubClass); + return RTLOCKVAL_SUB_CLASS_INVALID; +#endif +} +RT_EXPORT_SYMBOL(RTCritSectRwSetSubClass); + + +static int rtCritSectRwEnterShared(PRTCRITSECTRW pThis, PCRTLOCKVALSRCPOS pSrcPos, bool fTryOnly) +{ + /* + * Validate input. + */ + AssertPtr(pThis); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, VERR_SEM_DESTROYED); + +#ifdef RTCRITSECTRW_STRICT + RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt(); + if (!fTryOnly) + { + int rc9; + RTNATIVETHREAD hNativeWriter; + ASMAtomicUoReadHandle(&pThis->hNativeWriter, &hNativeWriter); + if (hNativeWriter != NIL_RTTHREAD && hNativeWriter == RTThreadNativeSelf()) + rc9 = RTLockValidatorRecExclCheckOrder(pThis->pValidatorWrite, hThreadSelf, pSrcPos, RT_INDEFINITE_WAIT); + else + rc9 = RTLockValidatorRecSharedCheckOrder(pThis->pValidatorRead, hThreadSelf, pSrcPos, RT_INDEFINITE_WAIT); + if (RT_FAILURE(rc9)) + return rc9; + } +#endif + + /* + * Get cracking... + */ + uint64_t u64State = ASMAtomicReadU64(&pThis->u64State); + uint64_t u64OldState = u64State; + + for (;;) + { + if ((u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT)) + { + /* It flows in the right direction, try follow it before it changes. */ + uint64_t c = (u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT; + c++; + Assert(c < RTCSRW_CNT_MASK / 2); + u64State &= ~RTCSRW_CNT_RD_MASK; + u64State |= c << RTCSRW_CNT_RD_SHIFT; + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + { +#ifdef RTCRITSECTRW_STRICT + RTLockValidatorRecSharedAddOwner(pThis->pValidatorRead, hThreadSelf, pSrcPos); +#endif + break; + } + } + else if ((u64State & (RTCSRW_CNT_RD_MASK | RTCSRW_CNT_WR_MASK)) == 0) + { + /* Wrong direction, but we're alone here and can simply try switch the direction. */ + u64State &= ~(RTCSRW_CNT_RD_MASK | RTCSRW_CNT_WR_MASK | RTCSRW_DIR_MASK); + u64State |= (UINT64_C(1) << RTCSRW_CNT_RD_SHIFT) | (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT); + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + { + Assert(!pThis->fNeedReset); +#ifdef RTCRITSECTRW_STRICT + RTLockValidatorRecSharedAddOwner(pThis->pValidatorRead, hThreadSelf, pSrcPos); +#endif + break; + } + } + else + { + /* Is the writer perhaps doing a read recursion? */ + RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); + RTNATIVETHREAD hNativeWriter; + ASMAtomicUoReadHandle(&pThis->hNativeWriter, &hNativeWriter); + if (hNativeSelf == hNativeWriter) + { +#ifdef RTCRITSECTRW_STRICT + int rc9 = RTLockValidatorRecExclRecursionMixed(pThis->pValidatorWrite, &pThis->pValidatorRead->Core, pSrcPos); + if (RT_FAILURE(rc9)) + return rc9; +#endif + Assert(pThis->cWriterReads < UINT32_MAX / 2); + ASMAtomicIncU32(&pThis->cWriterReads); + return VINF_SUCCESS; /* don't break! */ + } + + /* If we're only trying, return already. */ + if (fTryOnly) + return VERR_SEM_BUSY; + + /* Add ourselves to the queue and wait for the direction to change. */ + uint64_t c = (u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT; + c++; + Assert(c < RTCSRW_CNT_MASK / 2); + + uint64_t cWait = (u64State & RTCSRW_WAIT_CNT_RD_MASK) >> RTCSRW_WAIT_CNT_RD_SHIFT; + cWait++; + Assert(cWait <= c); + Assert(cWait < RTCSRW_CNT_MASK / 2); + + u64State &= ~(RTCSRW_CNT_RD_MASK | RTCSRW_WAIT_CNT_RD_MASK); + u64State |= (c << RTCSRW_CNT_RD_SHIFT) | (cWait << RTCSRW_WAIT_CNT_RD_SHIFT); + + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + { + for (uint32_t iLoop = 0; ; iLoop++) + { + int rc; +#ifdef RTCRITSECTRW_STRICT + rc = RTLockValidatorRecSharedCheckBlocking(pThis->pValidatorRead, hThreadSelf, pSrcPos, true, + RT_INDEFINITE_WAIT, RTTHREADSTATE_RW_READ, false); + if (RT_SUCCESS(rc)) +#else + RTTHREAD hThreadSelf = RTThreadSelf(); + RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_READ, false); +#endif + { + rc = RTSemEventMultiWait(pThis->hEvtRead, RT_INDEFINITE_WAIT); + RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_RW_READ); + if (pThis->u32Magic != RTCRITSECTRW_MAGIC) + return VERR_SEM_DESTROYED; + } + if (RT_FAILURE(rc)) + { + /* Decrement the counts and return the error. */ + for (;;) + { + u64OldState = u64State = ASMAtomicReadU64(&pThis->u64State); + c = (u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT; Assert(c > 0); + c--; + cWait = (u64State & RTCSRW_WAIT_CNT_RD_MASK) >> RTCSRW_WAIT_CNT_RD_SHIFT; Assert(cWait > 0); + cWait--; + u64State &= ~(RTCSRW_CNT_RD_MASK | RTCSRW_WAIT_CNT_RD_MASK); + u64State |= (c << RTCSRW_CNT_RD_SHIFT) | (cWait << RTCSRW_WAIT_CNT_RD_SHIFT); + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + break; + } + return rc; + } + + Assert(pThis->fNeedReset); + u64State = ASMAtomicReadU64(&pThis->u64State); + if ((u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT)) + break; + AssertMsg(iLoop < 1, ("%u\n", iLoop)); + } + + /* Decrement the wait count and maybe reset the semaphore (if we're last). */ + for (;;) + { + u64OldState = u64State; + + cWait = (u64State & RTCSRW_WAIT_CNT_RD_MASK) >> RTCSRW_WAIT_CNT_RD_SHIFT; + Assert(cWait > 0); + cWait--; + u64State &= ~RTCSRW_WAIT_CNT_RD_MASK; + u64State |= cWait << RTCSRW_WAIT_CNT_RD_SHIFT; + + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + { + if (cWait == 0) + { + if (ASMAtomicXchgBool(&pThis->fNeedReset, false)) + { + int rc = RTSemEventMultiReset(pThis->hEvtRead); + AssertRCReturn(rc, rc); + } + } + break; + } + u64State = ASMAtomicReadU64(&pThis->u64State); + } + +#ifdef RTCRITSECTRW_STRICT + RTLockValidatorRecSharedAddOwner(pThis->pValidatorRead, hThreadSelf, pSrcPos); +#endif + break; + } + } + + if (pThis->u32Magic != RTCRITSECTRW_MAGIC) + return VERR_SEM_DESTROYED; + + ASMNopPause(); + u64State = ASMAtomicReadU64(&pThis->u64State); + u64OldState = u64State; + } + + /* got it! */ + Assert((ASMAtomicReadU64(&pThis->u64State) & RTCSRW_DIR_MASK) == (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT)); + return VINF_SUCCESS; + +} + + +RTDECL(int) RTCritSectRwEnterShared(PRTCRITSECTRW pThis) +{ +#ifndef RTCRITSECTRW_STRICT + return rtCritSectRwEnterShared(pThis, NULL, false /*fTryOnly*/); +#else + RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API(); + return rtCritSectRwEnterShared(pThis, &SrcPos, false /*fTryOnly*/); +#endif +} +RT_EXPORT_SYMBOL(RTCritSectRwEnterShared); + + +RTDECL(int) RTCritSectRwEnterSharedDebug(PRTCRITSECTRW pThis, RTHCUINTPTR uId, RT_SRC_POS_DECL) +{ + RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API(); + return rtCritSectRwEnterShared(pThis, &SrcPos, false /*fTryOnly*/); +} +RT_EXPORT_SYMBOL(RTCritSectRwEnterSharedDebug); + + +RTDECL(int) RTCritSectRwTryEnterShared(PRTCRITSECTRW pThis) +{ +#ifndef RTCRITSECTRW_STRICT + return rtCritSectRwEnterShared(pThis, NULL, true /*fTryOnly*/); +#else + RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API(); + return rtCritSectRwEnterShared(pThis, &SrcPos, true /*fTryOnly*/); +#endif +} +RT_EXPORT_SYMBOL(RTCritSectRwEnterShared); + + +RTDECL(int) RTCritSectRwTryEnterSharedDebug(PRTCRITSECTRW pThis, RTHCUINTPTR uId, RT_SRC_POS_DECL) +{ + RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API(); + return rtCritSectRwEnterShared(pThis, &SrcPos, true /*fTryOnly*/); +} +RT_EXPORT_SYMBOL(RTCritSectRwEnterSharedDebug); + + + +RTDECL(int) RTCritSectRwLeaveShared(PRTCRITSECTRW pThis) +{ + /* + * Validate handle. + */ + AssertPtr(pThis); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, VERR_SEM_DESTROYED); + + /* + * Check the direction and take action accordingly. + */ + uint64_t u64State = ASMAtomicReadU64(&pThis->u64State); + uint64_t u64OldState = u64State; + if ((u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT)) + { +#ifdef RTCRITSECTRW_STRICT + int rc9 = RTLockValidatorRecSharedCheckAndRelease(pThis->pValidatorRead, NIL_RTTHREAD); + if (RT_FAILURE(rc9)) + return rc9; +#endif + for (;;) + { + uint64_t c = (u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT; + AssertReturn(c > 0, VERR_NOT_OWNER); + c--; + + if ( c > 0 + || (u64State & RTCSRW_CNT_WR_MASK) == 0) + { + /* Don't change the direction. */ + u64State &= ~RTCSRW_CNT_RD_MASK; + u64State |= c << RTCSRW_CNT_RD_SHIFT; + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + break; + } + else + { + /* Reverse the direction and signal the reader threads. */ + u64State &= ~(RTCSRW_CNT_RD_MASK | RTCSRW_DIR_MASK); + u64State |= RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT; + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + { + int rc = RTSemEventSignal(pThis->hEvtWrite); + AssertRC(rc); + break; + } + } + + ASMNopPause(); + u64State = ASMAtomicReadU64(&pThis->u64State); + u64OldState = u64State; + } + } + else + { + RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); + RTNATIVETHREAD hNativeWriter; + ASMAtomicUoReadHandle(&pThis->hNativeWriter, &hNativeWriter); + AssertReturn(hNativeSelf == hNativeWriter, VERR_NOT_OWNER); + AssertReturn(pThis->cWriterReads > 0, VERR_NOT_OWNER); +#ifdef RTCRITSECTRW_STRICT + int rc = RTLockValidatorRecExclUnwindMixed(pThis->pValidatorWrite, &pThis->pValidatorRead->Core); + if (RT_FAILURE(rc)) + return rc; +#endif + ASMAtomicDecU32(&pThis->cWriterReads); + } + + return VINF_SUCCESS; +} +RT_EXPORT_SYMBOL(RTCritSectRwLeaveShared); + + +static int rtCritSectRwEnterExcl(PRTCRITSECTRW pThis, PCRTLOCKVALSRCPOS pSrcPos, bool fTryOnly) +{ + /* + * Validate input. + */ + AssertPtr(pThis); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, VERR_SEM_DESTROYED); + +#ifdef RTCRITSECTRW_STRICT + RTTHREAD hThreadSelf = NIL_RTTHREAD; + if (!fTryOnly) + { + hThreadSelf = RTThreadSelfAutoAdopt(); + int rc9 = RTLockValidatorRecExclCheckOrder(pThis->pValidatorWrite, hThreadSelf, pSrcPos, RT_INDEFINITE_WAIT); + if (RT_FAILURE(rc9)) + return rc9; + } +#endif + + /* + * Check if we're already the owner and just recursing. + */ + RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); + RTNATIVETHREAD hNativeWriter; + ASMAtomicUoReadHandle(&pThis->hNativeWriter, &hNativeWriter); + if (hNativeSelf == hNativeWriter) + { + Assert((ASMAtomicReadU64(&pThis->u64State) & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT)); +#ifdef RTCRITSECTRW_STRICT + int rc9 = RTLockValidatorRecExclRecursion(pThis->pValidatorWrite, pSrcPos); + if (RT_FAILURE(rc9)) + return rc9; +#endif + Assert(pThis->cWriteRecursions < UINT32_MAX / 2); + ASMAtomicIncU32(&pThis->cWriteRecursions); + return VINF_SUCCESS; + } + + /* + * Get cracking. + */ + uint64_t u64State = ASMAtomicReadU64(&pThis->u64State); + uint64_t u64OldState = u64State; + + for (;;) + { + if ( (u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT) + || (u64State & (RTCSRW_CNT_RD_MASK | RTCSRW_CNT_WR_MASK)) != 0) + { + /* It flows in the right direction, try follow it before it changes. */ + uint64_t c = (u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT; + c++; + Assert(c < RTCSRW_CNT_MASK / 2); + u64State &= ~RTCSRW_CNT_WR_MASK; + u64State |= c << RTCSRW_CNT_WR_SHIFT; + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + break; + } + else if ((u64State & (RTCSRW_CNT_RD_MASK | RTCSRW_CNT_WR_MASK)) == 0) + { + /* Wrong direction, but we're alone here and can simply try switch the direction. */ + u64State &= ~(RTCSRW_CNT_RD_MASK | RTCSRW_CNT_WR_MASK | RTCSRW_DIR_MASK); + u64State |= (UINT64_C(1) << RTCSRW_CNT_WR_SHIFT) | (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT); + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + break; + } + else if (fTryOnly) + /* Wrong direction and we're not supposed to wait, just return. */ + return VERR_SEM_BUSY; + else + { + /* Add ourselves to the write count and break out to do the wait. */ + uint64_t c = (u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT; + c++; + Assert(c < RTCSRW_CNT_MASK / 2); + u64State &= ~RTCSRW_CNT_WR_MASK; + u64State |= c << RTCSRW_CNT_WR_SHIFT; + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + break; + } + + if (pThis->u32Magic != RTCRITSECTRW_MAGIC) + return VERR_SEM_DESTROYED; + + ASMNopPause(); + u64State = ASMAtomicReadU64(&pThis->u64State); + u64OldState = u64State; + } + + /* + * If we're in write mode now try grab the ownership. Play fair if there + * are threads already waiting. + */ + bool fDone = (u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT) + && ( ((u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT) == 1 + || fTryOnly); + if (fDone) + ASMAtomicCmpXchgHandle(&pThis->hNativeWriter, hNativeSelf, NIL_RTNATIVETHREAD, fDone); + if (!fDone) + { + /* + * If only trying, undo the above writer incrementation and return. + */ + if (fTryOnly) + { + for (;;) + { + u64OldState = u64State = ASMAtomicReadU64(&pThis->u64State); + uint64_t c = (u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT; Assert(c > 0); + c--; + u64State &= ~RTCSRW_CNT_WR_MASK; + u64State |= c << RTCSRW_CNT_WR_SHIFT; + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + break; + } + return VERR_SEM_BUSY; + } + + /* + * Wait for our turn. + */ + for (uint32_t iLoop = 0; ; iLoop++) + { + int rc; +#ifdef RTCRITSECTRW_STRICT + if (hThreadSelf == NIL_RTTHREAD) + hThreadSelf = RTThreadSelfAutoAdopt(); + rc = RTLockValidatorRecExclCheckBlocking(pThis->pValidatorWrite, hThreadSelf, pSrcPos, true, + RT_INDEFINITE_WAIT, RTTHREADSTATE_RW_WRITE, false); + if (RT_SUCCESS(rc)) +#else + RTTHREAD hThreadSelf = RTThreadSelf(); + RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_WRITE, false); +#endif + { + rc = RTSemEventWait(pThis->hEvtWrite, RT_INDEFINITE_WAIT); + RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_RW_WRITE); + if (pThis->u32Magic != RTCRITSECTRW_MAGIC) + return VERR_SEM_DESTROYED; + } + if (RT_FAILURE(rc)) + { + /* Decrement the counts and return the error. */ + for (;;) + { + u64OldState = u64State = ASMAtomicReadU64(&pThis->u64State); + uint64_t c = (u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT; Assert(c > 0); + c--; + u64State &= ~RTCSRW_CNT_WR_MASK; + u64State |= c << RTCSRW_CNT_WR_SHIFT; + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + break; + } + return rc; + } + + u64State = ASMAtomicReadU64(&pThis->u64State); + if ((u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT)) + { + ASMAtomicCmpXchgHandle(&pThis->hNativeWriter, hNativeSelf, NIL_RTNATIVETHREAD, fDone); + if (fDone) + break; + } + AssertMsg(iLoop < 1000, ("%u\n", iLoop)); /* may loop a few times here... */ + } + } + + /* + * Got it! + */ + Assert((ASMAtomicReadU64(&pThis->u64State) & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT)); + ASMAtomicWriteU32(&pThis->cWriteRecursions, 1); + Assert(pThis->cWriterReads == 0); +#ifdef RTCRITSECTRW_STRICT + RTLockValidatorRecExclSetOwner(pThis->pValidatorWrite, hThreadSelf, pSrcPos, true); +#endif + + return VINF_SUCCESS; +} + + +RTDECL(int) RTCritSectRwEnterExcl(PRTCRITSECTRW pThis) +{ +#ifndef RTCRITSECTRW_STRICT + return rtCritSectRwEnterExcl(pThis, NULL, false /*fTryAgain*/); +#else + RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API(); + return rtCritSectRwEnterExcl(pThis, &SrcPos, false /*fTryAgain*/); +#endif +} +RT_EXPORT_SYMBOL(RTCritSectRwEnterExcl); + + +RTDECL(int) RTCritSectRwEnterExclDebug(PRTCRITSECTRW pThis, RTHCUINTPTR uId, RT_SRC_POS_DECL) +{ + RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API(); + return rtCritSectRwEnterExcl(pThis, &SrcPos, false /*fTryAgain*/); +} +RT_EXPORT_SYMBOL(RTCritSectRwEnterExclDebug); + + +RTDECL(int) RTCritSectRwTryEnterExcl(PRTCRITSECTRW pThis) +{ +#ifndef RTCRITSECTRW_STRICT + return rtCritSectRwEnterExcl(pThis, NULL, true /*fTryAgain*/); +#else + RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API(); + return rtCritSectRwEnterExcl(pThis, &SrcPos, true /*fTryAgain*/); +#endif +} +RT_EXPORT_SYMBOL(RTCritSectRwTryEnterExcl); + + +RTDECL(int) RTCritSectRwTryEnterExclDebug(PRTCRITSECTRW pThis, RTHCUINTPTR uId, RT_SRC_POS_DECL) +{ + RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API(); + return rtCritSectRwEnterExcl(pThis, &SrcPos, true /*fTryAgain*/); +} +RT_EXPORT_SYMBOL(RTCritSectRwTryEnterExclDebug); + + +RTDECL(int) RTCritSectRwLeaveExcl(PRTCRITSECTRW pThis) +{ + /* + * Validate handle. + */ + AssertPtr(pThis); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, VERR_SEM_DESTROYED); + + RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); + RTNATIVETHREAD hNativeWriter; + ASMAtomicUoReadHandle(&pThis->hNativeWriter, &hNativeWriter); + AssertReturn(hNativeSelf == hNativeWriter, VERR_NOT_OWNER); + + /* + * Unwind a recursion. + */ + if (pThis->cWriteRecursions == 1) + { + AssertReturn(pThis->cWriterReads == 0, VERR_WRONG_ORDER); /* (must release all read recursions before the final write.) */ +#ifdef RTCRITSECTRW_STRICT + int rc9 = RTLockValidatorRecExclReleaseOwner(pThis->pValidatorWrite, true); + if (RT_FAILURE(rc9)) + return rc9; +#endif + /* + * Update the state. + */ + ASMAtomicWriteU32(&pThis->cWriteRecursions, 0); + ASMAtomicWriteHandle(&pThis->hNativeWriter, NIL_RTNATIVETHREAD); + + for (;;) + { + uint64_t u64State = ASMAtomicReadU64(&pThis->u64State); + uint64_t u64OldState = u64State; + + uint64_t c = (u64State & RTCSRW_CNT_WR_MASK) >> RTCSRW_CNT_WR_SHIFT; + Assert(c > 0); + c--; + + if ( c > 0 + || (u64State & RTCSRW_CNT_RD_MASK) == 0) + { + /* Don't change the direction, wait up the next writer if any. */ + u64State &= ~RTCSRW_CNT_WR_MASK; + u64State |= c << RTCSRW_CNT_WR_SHIFT; + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + { + if (c > 0) + { + int rc = RTSemEventSignal(pThis->hEvtWrite); + AssertRC(rc); + } + break; + } + } + else + { + /* Reverse the direction and signal the reader threads. */ + u64State &= ~(RTCSRW_CNT_WR_MASK | RTCSRW_DIR_MASK); + u64State |= RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT; + if (ASMAtomicCmpXchgU64(&pThis->u64State, u64State, u64OldState)) + { + Assert(!pThis->fNeedReset); + ASMAtomicWriteBool(&pThis->fNeedReset, true); + int rc = RTSemEventMultiSignal(pThis->hEvtRead); + AssertRC(rc); + break; + } + } + + ASMNopPause(); + if (pThis->u32Magic != RTCRITSECTRW_MAGIC) + return VERR_SEM_DESTROYED; + } + } + else + { + Assert(pThis->cWriteRecursions != 0); +#ifdef RTCRITSECTRW_STRICT + int rc9 = RTLockValidatorRecExclUnwind(pThis->pValidatorWrite); + if (RT_FAILURE(rc9)) + return rc9; +#endif + ASMAtomicDecU32(&pThis->cWriteRecursions); + } + + return VINF_SUCCESS; +} +RT_EXPORT_SYMBOL(RTCritSectRwLeaveExcl); + + +RTDECL(bool) RTCritSectRwIsWriteOwner(PRTCRITSECTRW pThis) +{ + /* + * Validate handle. + */ + AssertPtr(pThis); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, false); + + /* + * Check ownership. + */ + RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); + RTNATIVETHREAD hNativeWriter; + ASMAtomicUoReadHandle(&pThis->hNativeWriter, &hNativeWriter); + return hNativeWriter == hNativeSelf; +} +RT_EXPORT_SYMBOL(RTCritSectRwIsWriteOwner); + + +RTDECL(bool) RTCritSectRwIsReadOwner(PRTCRITSECTRW pThis, bool fWannaHear) +{ + /* + * Validate handle. + */ + AssertPtr(pThis); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, false); + + /* + * Inspect the state. + */ + uint64_t u64State = ASMAtomicReadU64(&pThis->u64State); + if ((u64State & RTCSRW_DIR_MASK) == (RTCSRW_DIR_WRITE << RTCSRW_DIR_SHIFT)) + { + /* + * It's in write mode, so we can only be a reader if we're also the + * current writer. + */ + RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); + RTNATIVETHREAD hWriter; + ASMAtomicUoReadHandle(&pThis->hNativeWriter, &hWriter); + return hWriter == hNativeSelf; + } + + /* + * Read mode. If there are no current readers, then we cannot be a reader. + */ + if (!(u64State & RTCSRW_CNT_RD_MASK)) + return false; + +#ifdef RTCRITSECTRW_STRICT + /* + * Ask the lock validator. + */ + return RTLockValidatorRecSharedIsOwner(pThis->pValidatorRead, NIL_RTTHREAD); +#else + /* + * Ok, we don't know, just tell the caller what he want to hear. + */ + return fWannaHear; +#endif +} +RT_EXPORT_SYMBOL(RTCritSectRwIsReadOwner); + + +RTDECL(uint32_t) RTCritSectRwGetWriteRecursion(PRTCRITSECTRW pThis) +{ + /* + * Validate handle. + */ + AssertPtr(pThis); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, 0); + + /* + * Return the requested data. + */ + return pThis->cWriteRecursions; +} +RT_EXPORT_SYMBOL(RTCritSectRwGetWriteRecursion); + + +RTDECL(uint32_t) RTCritSectRwGetWriterReadRecursion(PRTCRITSECTRW pThis) +{ + /* + * Validate handle. + */ + AssertPtr(pThis); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, 0); + + /* + * Return the requested data. + */ + return pThis->cWriterReads; +} +RT_EXPORT_SYMBOL(RTCritSectRwGetWriterReadRecursion); + + +RTDECL(uint32_t) RTCritSectRwGetReadCount(PRTCRITSECTRW pThis) +{ + /* + * Validate input. + */ + AssertPtr(pThis); + AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, 0); + + /* + * Return the requested data. + */ + uint64_t u64State = ASMAtomicReadU64(&pThis->u64State); + if ((u64State & RTCSRW_DIR_MASK) != (RTCSRW_DIR_READ << RTCSRW_DIR_SHIFT)) + return 0; + return (u64State & RTCSRW_CNT_RD_MASK) >> RTCSRW_CNT_RD_SHIFT; +} +RT_EXPORT_SYMBOL(RTCritSectRwGetReadCount); + + +RTDECL(int) RTCritSectRwDelete(PRTCRITSECTRW pThis) +{ + /* + * Assert free waiters and so on. + */ + AssertPtr(pThis); + Assert(pThis->u32Magic == RTCRITSECTRW_MAGIC); + //Assert(pThis->cNestings == 0); + //Assert(pThis->cLockers == -1); + Assert(pThis->hNativeWriter == NIL_RTNATIVETHREAD); + + /* + * Invalidate the structure and free the semaphores. + */ + if (!ASMAtomicCmpXchgU32(&pThis->u32Magic, RTCRITSECTRW_MAGIC_DEAD, RTCRITSECTRW_MAGIC)) + return VERR_INVALID_PARAMETER; + + pThis->fFlags = 0; + pThis->u64State = 0; + + RTSEMEVENT hEvtWrite = pThis->hEvtWrite; + pThis->hEvtWrite = NIL_RTSEMEVENT; + RTSEMEVENTMULTI hEvtRead = pThis->hEvtRead; + pThis->hEvtRead = NIL_RTSEMEVENTMULTI; + + int rc1 = RTSemEventDestroy(hEvtWrite); AssertRC(rc1); + int rc2 = RTSemEventMultiDestroy(hEvtRead); AssertRC(rc2); + + RTLockValidatorRecSharedDestroy(&pThis->pValidatorRead); + RTLockValidatorRecExclDestroy(&pThis->pValidatorWrite); + + return RT_SUCCESS(rc1) ? rc2 : rc1; +} +RT_EXPORT_SYMBOL(RTCritSectRwDelete); + diff --git a/src/VBox/Runtime/generic/env-generic.cpp b/src/VBox/Runtime/generic/env-generic.cpp index c4de0471..0d9a13b9 100644 --- a/src/VBox/Runtime/generic/env-generic.cpp +++ b/src/VBox/Runtime/generic/env-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -56,11 +56,27 @@ RT_C_DECLS_END /******************************************************************************* * Defined Constants And Macros * *******************************************************************************/ +/** The allocation granularity of the RTENVINTERNAL::papszEnv memory. */ +#define RTENV_GROW_SIZE 16 + /** Macro that unlocks the specified environment block. */ #define RTENV_LOCK(pEnvInt) do { } while (0) /** Macro that unlocks the specified environment block. */ #define RTENV_UNLOCK(pEnvInt) do { } while (0) +/** @def RTENV_HAVE_WENVIRON + * Indicates that we have a _wenviron variable with UTF-16 strings that we + * better use instead of the current-cp strings in environ. */ +#if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING) +# define RTENV_HAVE_WENVIRON 1 +#endif + +/** @def RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API + * Indicates the RTEnv*Utf8 APIs are implemented. */ +#if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING) +# define RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API 1 +#endif + /******************************************************************************* * Structures and Typedefs * @@ -84,10 +100,10 @@ typedef struct RTENVINTERNAL /** Array of environment variables in the process CP. * This get (re-)constructed when RTEnvGetExecEnvP method is called. */ char **papszEnvOtherCP; -} RTENVINTERNAL, *PRTENVINTERNAL; -/** The allocation granularity of the RTENVINTERNAL::papszEnv memory. */ -#define RTENV_GROW_SIZE 16 + /** The compare function we're using. */ + DECLCALLBACKMEMBER(int, pfnCompare)(const char *psz1, const char *psz2, size_t cchMax); +} RTENVINTERNAL, *PRTENVINTERNAL; /** @@ -101,9 +117,6 @@ static const char * const *rtEnvDefault(void) { #ifdef RT_OS_DARWIN return *(_NSGetEnviron()); -#elif defined(RT_OS_L4) - /* So far, our L4 libraries do not include environment support. */ - return NULL; #else return environ; #endif @@ -114,10 +127,12 @@ static const char * const *rtEnvDefault(void) * Internal worker that creates an environment handle with a specified capacity. * * @returns IPRT status code. - * @param ppIntEnv Where to store the result. - * @param cAllocated The initial array size. + * @param ppIntEnv Where to store the result. + * @param cAllocated The initial array size. + * @param fCaseSensitive Whether the environment block is case sensitive or + * not. */ -static int rtEnvCreate(PRTENVINTERNAL *ppIntEnv, size_t cAllocated) +static int rtEnvCreate(PRTENVINTERNAL *ppIntEnv, size_t cAllocated, bool fCaseSensitive) { /* * Allocate environment handle. @@ -129,6 +144,7 @@ static int rtEnvCreate(PRTENVINTERNAL *ppIntEnv, size_t cAllocated) * Pre-allocate the variable array. */ pIntEnv->u32Magic = RTENV_MAGIC; + pIntEnv->pfnCompare = fCaseSensitive ? RTStrNCmp : RTStrNICmp; pIntEnv->papszEnvOtherCP = NULL; pIntEnv->cVars = 0; pIntEnv->cAllocated = RT_ALIGN_Z(RT_MAX(cAllocated, RTENV_GROW_SIZE), RTENV_GROW_SIZE); @@ -149,7 +165,7 @@ static int rtEnvCreate(PRTENVINTERNAL *ppIntEnv, size_t cAllocated) RTDECL(int) RTEnvCreate(PRTENV pEnv) { AssertPtrReturn(pEnv, VERR_INVALID_POINTER); - return rtEnvCreate(pEnv, RTENV_GROW_SIZE); + return rtEnvCreate(pEnv, RTENV_GROW_SIZE, false /*fCaseSensitive*/); } RT_EXPORT_SYMBOL(RTEnvCreate); @@ -203,18 +219,41 @@ RTDECL(int) RTEnvClone(PRTENV pEnv, RTENV EnvToClone) /* * Validate input and figure out how many variable to clone and where to get them. */ + bool fCaseSensitive = true; size_t cVars; const char * const *papszEnv; +#ifdef RTENV_HAVE_WENVIRON + PCRTUTF16 const * papwszEnv; +#endif PRTENVINTERNAL pIntEnvToClone; AssertPtrReturn(pEnv, VERR_INVALID_POINTER); if (EnvToClone == RTENV_DEFAULT) { + cVars = 0; pIntEnvToClone = NULL; +#ifdef RTENV_HAVE_WENVIRON + papszEnv = NULL; + papwszEnv = (PCRTUTF16 * const )_wenviron; + if (!papwszEnv) + { + _wgetenv(L"Path"); /* Force the CRT to initalize it. */ + papwszEnv = (PCRTUTF16 * const)_wenviron; + } + if (papwszEnv) + while (papwszEnv[cVars]) + cVars++; +#else papszEnv = rtEnvDefault(); - cVars = 0; if (papszEnv) while (papszEnv[cVars]) cVars++; +#endif + +#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) + /* DOS systems was case insensitive. A prime example is the 'Path' + variable on windows which turns into the 'PATH' variable. */ + fCaseSensitive = false; +#endif } else { @@ -231,7 +270,7 @@ RTDECL(int) RTEnvClone(PRTENV pEnv, RTENV EnvToClone) * Create the duplicate. */ PRTENVINTERNAL pIntEnv; - int rc = rtEnvCreate(&pIntEnv, cVars + 1 /* NULL */); + int rc = rtEnvCreate(&pIntEnv, cVars + 1 /* NULL */, fCaseSensitive); if (RT_SUCCESS(rc)) { pIntEnv->cVars = cVars; @@ -242,7 +281,11 @@ RTDECL(int) RTEnvClone(PRTENV pEnv, RTENV EnvToClone) size_t iDst = 0; for (size_t iSrc = 0; iSrc < cVars; iSrc++) { +#ifdef RTENV_HAVE_WENVIRON + int rc2 = RTUtf16ToUtf8(papwszEnv[iSrc], &pIntEnv->papszEnv[iDst]); +#else int rc2 = RTStrCurrentCPToUtf8(&pIntEnv->papszEnv[iDst], papszEnv[iSrc]); +#endif if (RT_SUCCESS(rc2)) iDst++; else if (rc2 == VERR_NO_TRANSLATION) @@ -321,6 +364,9 @@ RTDECL(int) RTEnvSetEx(RTENV Env, const char *pszVar, const char *pszValue) int rc; if (Env == RTENV_DEFAULT) { +#ifdef RT_OS_WINDOWS + rc = RTEnvSetUtf8(pszVar, pszValue); +#else /* * Since RTEnvPut isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary @@ -339,6 +385,7 @@ RTDECL(int) RTEnvSetEx(RTENV Env, const char *pszVar, const char *pszValue) } RTStrFree(pszVarOtherCP); } +#endif } else { @@ -366,7 +413,7 @@ RTDECL(int) RTEnvSetEx(RTENV Env, const char *pszVar, const char *pszValue) rc = VINF_SUCCESS; size_t iVar; for (iVar = 0; iVar < pIntEnv->cVars; iVar++) - if ( !strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar) + if ( !pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar) && pIntEnv->papszEnv[iVar][cchVar] == '=') break; if (iVar < pIntEnv->cVars) @@ -426,6 +473,9 @@ RTDECL(int) RTEnvUnsetEx(RTENV Env, const char *pszVar) int rc; if (Env == RTENV_DEFAULT) { +#ifdef RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API + rc = RTEnvUnsetUtf8(pszVar); +#else /* * Since RTEnvUnset isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary @@ -438,6 +488,7 @@ RTDECL(int) RTEnvUnsetEx(RTENV Env, const char *pszVar) rc = RTEnvUnset(pszVarOtherCP); RTStrFree(pszVarOtherCP); } +#endif } else { @@ -454,7 +505,7 @@ RTDECL(int) RTEnvUnsetEx(RTENV Env, const char *pszVar) const size_t cchVar = strlen(pszVar); size_t iVar; for (iVar = 0; iVar < pIntEnv->cVars; iVar++) - if ( !strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar) + if ( !pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar) && pIntEnv->papszEnv[iVar][cchVar] == '=') { RTMemFree(pIntEnv->papszEnv[iVar]); @@ -486,6 +537,9 @@ RTDECL(int) RTEnvGetEx(RTENV Env, const char *pszVar, char *pszValue, size_t cbV int rc; if (Env == RTENV_DEFAULT) { +#ifdef RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API + rc = RTEnvGetUtf8(pszVar, pszValue, cbValue, pcchActual); +#else /* * Since RTEnvGet isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary @@ -520,6 +574,7 @@ RTDECL(int) RTEnvGetEx(RTENV Env, const char *pszVar, char *pszValue, size_t cbV else rc = VERR_ENV_VAR_NOT_FOUND; } +#endif } else { @@ -536,7 +591,7 @@ RTDECL(int) RTEnvGetEx(RTENV Env, const char *pszVar, char *pszValue, size_t cbV const size_t cchVar = strlen(pszVar); size_t iVar; for (iVar = 0; iVar < pIntEnv->cVars; iVar++) - if ( !strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar) + if ( !pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar) && pIntEnv->papszEnv[iVar][cchVar] == '=') { rc = VINF_SUCCESS; @@ -557,7 +612,6 @@ RTDECL(int) RTEnvGetEx(RTENV Env, const char *pszVar, char *pszValue, size_t cbV RTENV_UNLOCK(pIntEnv); } return rc; - } RT_EXPORT_SYMBOL(RTEnvGetEx); @@ -566,9 +620,12 @@ RTDECL(bool) RTEnvExistEx(RTENV Env, const char *pszVar) { AssertPtrReturn(pszVar, false); - bool fExist = false; + bool fExists = false; if (Env == RTENV_DEFAULT) { +#ifdef RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API + fExists = RTEnvExistsUtf8(pszVar); +#else /* * Since RTEnvExist isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary @@ -578,9 +635,10 @@ RTDECL(bool) RTEnvExistEx(RTENV Env, const char *pszVar) int rc = RTStrUtf8ToCurrentCP(&pszVarOtherCP, pszVar); if (RT_SUCCESS(rc)) { - fExist = RTEnvExist(pszVarOtherCP); + fExists = RTEnvExist(pszVarOtherCP); RTStrFree(pszVarOtherCP); } +#endif } else { @@ -595,16 +653,16 @@ RTDECL(bool) RTEnvExistEx(RTENV Env, const char *pszVar) */ const size_t cchVar = strlen(pszVar); for (size_t iVar = 0; iVar < pIntEnv->cVars; iVar++) - if ( !strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar) + if ( !pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar) && pIntEnv->papszEnv[iVar][cchVar] == '=') { - fExist = true; + fExists = true; break; } RTENV_UNLOCK(pIntEnv); } - return fExist; + return fExists; } RT_EXPORT_SYMBOL(RTEnvExistEx); @@ -614,6 +672,7 @@ RTDECL(char const * const *) RTEnvGetExecEnvP(RTENV Env) const char * const *papszRet; if (Env == RTENV_DEFAULT) { + /** @todo fix this API it's fundamentally wrong! */ papszRet = rtEnvDefault(); if (!papszRet) { diff --git a/src/VBox/Runtime/generic/fs-stubs-generic.cpp b/src/VBox/Runtime/generic/fs-stubs-generic.cpp index 4d4403ad..9f07d41a 100644 --- a/src/VBox/Runtime/generic/fs-stubs-generic.cpp +++ b/src/VBox/Runtime/generic/fs-stubs-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/mempool-generic.cpp b/src/VBox/Runtime/generic/mempool-generic.cpp index 3ec82610..d9bdf357 100644 --- a/src/VBox/Runtime/generic/mempool-generic.cpp +++ b/src/VBox/Runtime/generic/mempool-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/mppresent-generic.cpp b/src/VBox/Runtime/generic/mppresent-generic.cpp index 2d345f77..2915a656 100644 --- a/src/VBox/Runtime/generic/mppresent-generic.cpp +++ b/src/VBox/Runtime/generic/mppresent-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -46,6 +46,13 @@ RTDECL(RTCPUID) RTMpGetPresentCount(void) RT_EXPORT_SYMBOL(RTMpGetPresentCount); +RTDECL(RTCPUID) RTMpGetPresentCoreCount(void) +{ + return RTMpGetCoreCount(); +} +RT_EXPORT_SYMBOL(RTMpGetPresentCoreCount); + + RTDECL(bool) RTMpIsCpuPresent(RTCPUID idCpu) { return RTMpIsCpuPossible(idCpu); diff --git a/src/VBox/Runtime/generic/sched-generic.cpp b/src/VBox/Runtime/generic/sched-generic.cpp index f272b4d7..fb5cd97c 100644 --- a/src/VBox/Runtime/generic/sched-generic.cpp +++ b/src/VBox/Runtime/generic/sched-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/semfastmutex-generic.cpp b/src/VBox/Runtime/generic/semfastmutex-generic.cpp index 69de1410..299162f2 100644 --- a/src/VBox/Runtime/generic/semfastmutex-generic.cpp +++ b/src/VBox/Runtime/generic/semfastmutex-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/semrw-generic.cpp b/src/VBox/Runtime/generic/semrw-generic.cpp index 929c14e3..9078619e 100644 --- a/src/VBox/Runtime/generic/semrw-generic.cpp +++ b/src/VBox/Runtime/generic/semrw-generic.cpp @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2006-2009 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/semrw-lockless-generic.cpp b/src/VBox/Runtime/generic/semrw-lockless-generic.cpp index 3da9d6fe..27a37c06 100644 --- a/src/VBox/Runtime/generic/semrw-lockless-generic.cpp +++ b/src/VBox/Runtime/generic/semrw-lockless-generic.cpp @@ -1,10 +1,10 @@ /* $Id: semrw-lockless-generic.cpp $ */ /** @file - * IPRT Testcase - RTSemXRoads, generic implementation. + * IPRT - Read-Write Semaphore, Generic, lockless variant. */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -51,8 +51,10 @@ typedef struct RTSEMRWINTERNAL { /** Magic value (RTSEMRW_MAGIC). */ uint32_t volatile u32Magic; - uint32_t u32Padding; /**< alignment padding.*/ - /* The state variable. + /** Indicates whether hEvtRead needs resetting. */ + bool volatile fNeedReset; + + /** The state variable. * All accesses are atomic and it bits are defined like this: * Bits 0..14 - cReads. * Bit 15 - Unused. @@ -68,7 +70,8 @@ typedef struct RTSEMRWINTERNAL RTNATIVETHREAD volatile hNativeWriter; /** The number of reads made by the current writer. */ uint32_t volatile cWriterReads; - /** The number of reads made by the current writer. */ + /** The number of recursions made by the current writer. (The initial grabbing + * of the lock counts as the first one.) */ uint32_t volatile cWriteRecursions; /** What the writer threads are blocking on. */ @@ -76,8 +79,6 @@ typedef struct RTSEMRWINTERNAL /** What the read threads are blocking on when waiting for the writer to * finish. */ RTSEMEVENTMULTI hEvtRead; - /** Indicates whether hEvtRead needs resetting. */ - bool volatile fNeedReset; #ifdef RTSEMRW_STRICT /** The validator record for the writer. */ @@ -494,7 +495,7 @@ RTDECL(int) RTSemRWReleaseRead(RTSEMRW hRWSem) c--; if ( c > 0 - || (u64State & RTSEMRW_CNT_RD_MASK) == 0) + || (u64State & RTSEMRW_CNT_WD_MASK) == 0) { /* Don't change the direction. */ u64State &= ~RTSEMRW_CNT_RD_MASK; @@ -888,7 +889,7 @@ RTDECL(bool) RTSemRWIsReadOwner(RTSEMRW hRWSem, bool fWannaHear) */ RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); RTNATIVETHREAD hWriter; - ASMAtomicUoReadHandle(&pThis->hWriter, &hWriter); + ASMAtomicUoReadHandle(&pThis->hNativeWriter, &hWriter); return hWriter == hNativeSelf; } diff --git a/src/VBox/Runtime/generic/semxroads-generic.cpp b/src/VBox/Runtime/generic/semxroads-generic.cpp index 55f9670a..6e3ea2eb 100644 --- a/src/VBox/Runtime/generic/semxroads-generic.cpp +++ b/src/VBox/Runtime/generic/semxroads-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/strcache-stubs-generic.cpp b/src/VBox/Runtime/generic/strcache-stubs-generic.cpp index 0b358a46..71bf5c12 100644 --- a/src/VBox/Runtime/generic/strcache-stubs-generic.cpp +++ b/src/VBox/Runtime/generic/strcache-stubs-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -77,6 +77,27 @@ RTDECL(const char *) RTStrCacheEnter(RTSTRCACHE hStrCache, const char *psz) RT_EXPORT_SYMBOL(RTStrCacheEnter); +RTDECL(const char *) RTStrCacheEnterLowerN(RTSTRCACHE hStrCache, const char *pchString, size_t cchString) +{ + AssertPtr(pchString); + AssertReturn(cchString < _1G, NULL); + Assert(!RTStrEnd(pchString, cchString)); + + char *pszRet = (char *)RTMemPoolDupEx((RTMEMPOOL)hStrCache, pchString, cchString, 1); + if (pszRet) + RTStrToLower(pszRet); + return pszRet; +} +RT_EXPORT_SYMBOL(RTStrCacheEnterLowerN); + + +RTDECL(const char *) RTStrCacheEnterLower(RTSTRCACHE hStrCache, const char *psz) +{ + return RTStrCacheEnterLowerN(hStrCache, psz, strlen(psz)); +} +RT_EXPORT_SYMBOL(RTStrCacheEnterLower); + + RTDECL(uint32_t) RTStrCacheRetain(const char *psz) { AssertPtr(psz); @@ -102,3 +123,19 @@ RTDECL(size_t) RTStrCacheLength(const char *psz) } RT_EXPORT_SYMBOL(RTStrCacheLength); + +RTDECL(bool) RTStrCacheIsRealImpl(void) +{ + return false; +} +RT_EXPORT_SYMBOL(RTStrCacheIsRealImpl); + + +RTDECL(uint32_t) RTStrCacheGetStats(RTSTRCACHE hStrCache, size_t *pcbStrings, size_t *pcbChunks, size_t *pcbBigEntries, + uint32_t *pcHashCollisions, uint32_t *pcHashCollisions2, uint32_t *pcHashInserts, + uint32_t *pcRehashes) +{ + return UINT32_MAX; +} +RT_EXPORT_SYMBOL(RTStrCacheGetStats); + diff --git a/src/VBox/Runtime/generic/timer-generic.cpp b/src/VBox/Runtime/generic/timer-generic.cpp index ab409c02..8e4c3270 100644 --- a/src/VBox/Runtime/generic/timer-generic.cpp +++ b/src/VBox/Runtime/generic/timer-generic.cpp @@ -116,7 +116,7 @@ RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, uint32_ int rc = RTSemEventCreate(&pTimer->Event); if (RT_SUCCESS(rc)) { - rc = RTThreadCreate(&pTimer->Thread, rtTimerThread, pTimer, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "TIMER"); + rc = RTThreadCreate(&pTimer->Thread, rtTimerThread, pTimer, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "Timer"); if (RT_SUCCESS(rc)) { *ppTimer = pTimer; @@ -256,18 +256,15 @@ static DECLCALLBACK(int) rtTimerThread(RTTHREAD hThreadSelf, void *pvUser) if (u64NanoTS >= pTimer->u64NextTS) { pTimer->iTick++; - pTimer->pfnTimer(pTimer, pTimer->pvUser, pTimer->iTick); - - /* status changed? */ - if (pTimer->fSuspended || pTimer->fDestroyed) - continue; /* one shot? */ if (!pTimer->u64NanoInterval) - { ASMAtomicXchgU8(&pTimer->fSuspended, true); + pTimer->pfnTimer(pTimer, pTimer->pvUser, pTimer->iTick); + + /* status changed? */ + if (pTimer->fSuspended || pTimer->fDestroyed) continue; - } /* calc the next time we should fire. */ pTimer->u64NextTS = pTimer->u64StartTS + pTimer->iTick * pTimer->u64NanoInterval; diff --git a/src/VBox/Runtime/generic/timerlr-generic.cpp b/src/VBox/Runtime/generic/timerlr-generic.cpp index fa46ac78..9f320a88 100644 --- a/src/VBox/Runtime/generic/timerlr-generic.cpp +++ b/src/VBox/Runtime/generic/timerlr-generic.cpp @@ -122,7 +122,7 @@ RTDECL(int) RTTimerLRCreateEx(RTTIMERLR *phTimerLR, uint64_t u64NanoInterval, ui int rc = RTSemEventCreate(&pThis->hEvent); if (RT_SUCCESS(rc)) { - rc = RTThreadCreate(&pThis->hThread, rtTimerLRThread, pThis, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "TIMER"); + rc = RTThreadCreate(&pThis->hThread, rtTimerLRThread, pThis, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "TimerLR"); if (RT_SUCCESS(rc)) { *phTimerLR = pThis; diff --git a/src/VBox/Runtime/generic/tls-generic.cpp b/src/VBox/Runtime/generic/tls-generic.cpp index 7729c77a..cbcbe4b6 100644 --- a/src/VBox/Runtime/generic/tls-generic.cpp +++ b/src/VBox/Runtime/generic/tls-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/utf16locale-generic.cpp b/src/VBox/Runtime/generic/utf16locale-generic.cpp index b75ec9d1..7f9f4439 100644 --- a/src/VBox/Runtime/generic/utf16locale-generic.cpp +++ b/src/VBox/Runtime/generic/utf16locale-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/generic/uuid-generic.cpp b/src/VBox/Runtime/generic/uuid-generic.cpp index 0b4b17dd..c6df68fd 100644 --- a/src/VBox/Runtime/generic/uuid-generic.cpp +++ b/src/VBox/Runtime/generic/uuid-generic.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; |