summaryrefslogtreecommitdiffstats
path: root/base/win
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-07 00:26:51 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-07 00:26:51 +0000
commite486b60cfbe2d4c420b17fa7b21c4c4bb6fbc189 (patch)
treebfb18f6546d922f5325c874f75efb39322fe445c /base/win
parentae049b8befcf76b2199a23c0c464c3aab5ba2fa1 (diff)
downloadchromium_src-e486b60cfbe2d4c420b17fa7b21c4c4bb6fbc189.zip
chromium_src-e486b60cfbe2d4c420b17fa7b21c4c4bb6fbc189.tar.gz
chromium_src-e486b60cfbe2d4c420b17fa7b21c4c4bb6fbc189.tar.bz2
Base: Add another pc to the handle verifier to get to the
actual caller. I was hoping for an inlining that didn't happened. BUG=127931 TEST=none Review URL: https://chromiumcodereview.appspot.com/10537041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140899 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/win')
-rw-r--r--base/win/scoped_handle.cc9
-rw-r--r--base/win/scoped_handle.h33
2 files changed, 29 insertions, 13 deletions
diff --git a/base/win/scoped_handle.cc b/base/win/scoped_handle.cc
index 91f95bf..4a4e995 100644
--- a/base/win/scoped_handle.cc
+++ b/base/win/scoped_handle.cc
@@ -16,7 +16,8 @@ namespace {
struct Info {
const void* owner;
- const void* pc;
+ const void* pc1;
+ const void* pc2;
DWORD thread_id;
};
typedef std::map<HANDLE, Info> HandleMap;
@@ -33,7 +34,7 @@ namespace win {
// Static.
void VerifierTraits::StartTracking(HANDLE handle, const void* owner,
- const void* pc) {
+ const void* pc1, const void* pc2) {
if (OSInfo::GetInstance()->version() > VERSION_XP)
return;
@@ -48,7 +49,7 @@ void VerifierTraits::StartTracking(HANDLE handle, const void* owner,
return;
}
- Info handle_info = { owner, pc, thread_id };
+ Info handle_info = { owner, pc1, pc2, thread_id };
std::pair<HANDLE, Info> item(handle, handle_info);
std::pair<HandleMap::iterator, bool> result = g_handle_map.Get().insert(item);
if (!result.second) {
@@ -60,7 +61,7 @@ void VerifierTraits::StartTracking(HANDLE handle, const void* owner,
// Static.
void VerifierTraits::StopTracking(HANDLE handle, const void* owner,
- const void* pc) {
+ const void* pc1, const void* pc2) {
if (OSInfo::GetInstance()->version() > VERSION_XP)
return;
diff --git a/base/win/scoped_handle.h b/base/win/scoped_handle.h
index 2991dbf..765e691 100644
--- a/base/win/scoped_handle.h
+++ b/base/win/scoped_handle.h
@@ -16,6 +16,14 @@
namespace base {
namespace win {
+// TODO(rvargas): remove this with the rest of the verifier.
+#if defined(COMPILER_MSVC)
+#define BASE_WIN_GET_CALLER _ReturnAddress()
+#elif defined(COMPILER_GCC)
+#define BASE_WIN_GET_CALLER __builtin_extract_return_addr(\\
+ __builtin_return_address(0))
+#endif
+
// Generic wrapper for raw handles that takes care of closing handles
// automatically. The class interface follows the style of
// the ScopedStdioHandle class with a few additions:
@@ -48,7 +56,7 @@ class GenericScopedHandle {
if (Traits::IsHandleValid(handle)) {
handle_ = handle;
- Verifier::StartTracking(handle, this,
+ Verifier::StartTracking(handle, this, BASE_WIN_GET_CALLER,
tracked_objects::GetProgramCounter());
}
}
@@ -66,7 +74,7 @@ class GenericScopedHandle {
DCHECK(!Traits::IsHandleValid(handle_)) << "Handle must be NULL";
// We cannot track this case :(. Just tell the verifier about it.
- Verifier::StartTracking(INVALID_HANDLE_VALUE, this,
+ Verifier::StartTracking(INVALID_HANDLE_VALUE, this, BASE_WIN_GET_CALLER,
tracked_objects::GetProgramCounter());
return &handle_;
}
@@ -75,15 +83,16 @@ class GenericScopedHandle {
Handle Take() {
Handle temp = handle_;
handle_ = Traits::NullHandle();
- Verifier::StopTracking(temp, this, tracked_objects::GetProgramCounter());
+ Verifier::StopTracking(temp, this, BASE_WIN_GET_CALLER,
+ tracked_objects::GetProgramCounter());
return temp;
}
// Explicitly closes the owned handle.
void Close() {
if (Traits::IsHandleValid(handle_)) {
- Verifier::StopTracking(handle_, this,
- tracked_objects::GetProgramCounter());
+ Verifier::StopTracking(handle_, this, BASE_WIN_GET_CALLER,
+ tracked_objects::GetProgramCounter());
if (!Traits::CloseHandle(handle_))
CHECK(false);
@@ -98,6 +107,8 @@ class GenericScopedHandle {
DISALLOW_COPY_AND_ASSIGN(GenericScopedHandle);
};
+#undef BASE_WIN_GET_CALLER
+
// The traits class for Win32 handles that can be closed via CloseHandle() API.
class HandleTraits {
public:
@@ -127,8 +138,10 @@ class DummyVerifierTraits {
public:
typedef HANDLE Handle;
- static void StartTracking(HANDLE handle, const void* owner, const void* pc) {}
- static void StopTracking(HANDLE handle, const void* owner, const void* pc) {}
+ static void StartTracking(HANDLE handle, const void* owner,
+ const void* pc1, const void* pc2) {}
+ static void StopTracking(HANDLE handle, const void* owner,
+ const void* pc1, const void* pc2) {}
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(DummyVerifierTraits);
@@ -139,8 +152,10 @@ class BASE_EXPORT VerifierTraits {
public:
typedef HANDLE Handle;
- static void StartTracking(HANDLE handle, const void* owner, const void* pc);
- static void StopTracking(HANDLE handle, const void* owner, const void* pc);
+ static void StartTracking(HANDLE handle, const void* owner,
+ const void* pc1, const void* pc2);
+ static void StopTracking(HANDLE handle, const void* owner,
+ const void* pc1, const void* pc2);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits);