Commit 351b5444 authored by Zhongyi Shi's avatar Zhongyi Shi Committed by Commit Bot

Add memorry correction detection code in UdpSocketPosix.

This change will confirm if crbug.com/906005 is caused by memory correction.

Bug: 906005
Change-Id: If9a6181bdf5b3591dec0cd340c66fafe77c2e2f5
Reviewed-on: https://chromium-review.googlesource.com/c/1347274
Commit-Queue: Misha Efimov <mef@chromium.org>
Reviewed-by: default avatarMisha Efimov <mef@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611134}
parent 9deef45c
...@@ -167,6 +167,10 @@ const guardid_t kSocketFdGuard = 0xD712BC0BC9A4EAD4; ...@@ -167,6 +167,10 @@ const guardid_t kSocketFdGuard = 0xD712BC0BC9A4EAD4;
#endif // defined(OS_MACOSX) && !defined(OS_IOS) #endif // defined(OS_MACOSX) && !defined(OS_IOS)
int GetSocketFDHash(int fd) {
return fd ^ 1595649551;
}
} // namespace } // namespace
UDPSocketPosix::UDPSocketPosix(DatagramSocket::BindType bind_type, UDPSocketPosix::UDPSocketPosix(DatagramSocket::BindType bind_type,
...@@ -175,6 +179,7 @@ UDPSocketPosix::UDPSocketPosix(DatagramSocket::BindType bind_type, ...@@ -175,6 +179,7 @@ UDPSocketPosix::UDPSocketPosix(DatagramSocket::BindType bind_type,
: write_async_watcher_(std::make_unique<WriteAsyncWatcher>(this)), : write_async_watcher_(std::make_unique<WriteAsyncWatcher>(this)),
sender_(new UDPSocketPosixSender()), sender_(new UDPSocketPosixSender()),
socket_(kInvalidSocket), socket_(kInvalidSocket),
socket_hash_(0),
addr_family_(0), addr_family_(0),
is_connected_(false), is_connected_(false),
socket_options_(SOCKET_OPTION_MULTICAST_LOOP), socket_options_(SOCKET_OPTION_MULTICAST_LOOP),
...@@ -218,6 +223,7 @@ int UDPSocketPosix::Open(AddressFamily address_family) { ...@@ -218,6 +223,7 @@ int UDPSocketPosix::Open(AddressFamily address_family) {
PCHECK(change_fdguard_np(socket_, NULL, 0, &kSocketFdGuard, PCHECK(change_fdguard_np(socket_, NULL, 0, &kSocketFdGuard,
GUARD_CLOSE | GUARD_DUP, NULL) == 0); GUARD_CLOSE | GUARD_DUP, NULL) == 0);
#endif // defined(OS_MACOSX) && !defined(OS_IOS) #endif // defined(OS_MACOSX) && !defined(OS_IOS)
socket_hash_ = GetSocketFDHash(socket_);
if (!base::SetNonBlocking(socket_)) { if (!base::SetNonBlocking(socket_)) {
const int err = MapSystemError(errno); const int err = MapSystemError(errno);
Close(); Close();
...@@ -304,6 +310,9 @@ void UDPSocketPosix::Close() { ...@@ -304,6 +310,9 @@ void UDPSocketPosix::Close() {
ok = write_socket_watcher_.StopWatchingFileDescriptor(); ok = write_socket_watcher_.StopWatchingFileDescriptor();
DCHECK(ok); DCHECK(ok);
// Verify that |socket_| hasn't been corrupted. Needed to debug
// crbug.com/906005.
CHECK_EQ(socket_hash_, GetSocketFDHash(socket_));
#if defined(OS_MACOSX) && !defined(OS_IOS) #if defined(OS_MACOSX) && !defined(OS_IOS)
PCHECK(IGNORE_EINTR(guarded_close_np(socket_, &kSocketFdGuard)) == 0); PCHECK(IGNORE_EINTR(guarded_close_np(socket_, &kSocketFdGuard)) == 0);
#else #else
......
...@@ -540,6 +540,11 @@ class NET_EXPORT UDPSocketPosix { ...@@ -540,6 +540,11 @@ class NET_EXPORT UDPSocketPosix {
int socket_; int socket_;
// Hash of |socket_| to verify that it is not corrupted when calling close().
// Used to debug https://crbug.com/906005.
// TODO(crbug.com/906005): Remove this once the bug is fixed.
int socket_hash_;
int addr_family_; int addr_family_;
bool is_connected_; bool is_connected_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment