Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: net/udp/udp_socket_posix.cc

Issue 2104533002: Ensure native library isn't actually loaded, and no IO on net thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bug link Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/udp/udp_socket_posix.h" 5 #include "net/udp/udp_socket_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <net/if.h> 9 #include <net/if.h>
10 #include <netdb.h> 10 #include <netdb.h>
11 #include <netinet/in.h> 11 #include <netinet/in.h>
12 #include <sys/ioctl.h> 12 #include <sys/ioctl.h>
13 #include <sys/socket.h> 13 #include <sys/socket.h>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/debug/alias.h" 16 #include "base/debug/alias.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/metrics/sparse_histogram.h" 20 #include "base/metrics/sparse_histogram.h"
21 #include "base/posix/eintr_wrapper.h" 21 #include "base/posix/eintr_wrapper.h"
22 #include "base/rand_util.h" 22 #include "base/rand_util.h"
23 #include "base/threading/thread_restrictions.h"
23 #include "base/trace_event/trace_event.h" 24 #include "base/trace_event/trace_event.h"
24 #include "net/base/io_buffer.h" 25 #include "net/base/io_buffer.h"
25 #include "net/base/ip_address.h" 26 #include "net/base/ip_address.h"
26 #include "net/base/ip_endpoint.h" 27 #include "net/base/ip_endpoint.h"
27 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
28 #include "net/base/network_activity_monitor.h" 29 #include "net/base/network_activity_monitor.h"
29 #include "net/base/sockaddr_storage.h" 30 #include "net/base/sockaddr_storage.h"
30 #include "net/log/net_log.h" 31 #include "net/log/net_log.h"
31 #include "net/socket/socket_descriptor.h" 32 #include "net/socket/socket_descriptor.h"
32 #include "net/udp/udp_net_log_parameters.h" 33 #include "net/udp/udp_net_log_parameters.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // NOTE(pauljensen): This does rely on Android implementation details, but 345 // NOTE(pauljensen): This does rely on Android implementation details, but
345 // these details are unlikely to change. 346 // these details are unlikely to change.
346 typedef int (*SetNetworkForSocket)(unsigned netId, int socketFd); 347 typedef int (*SetNetworkForSocket)(unsigned netId, int socketFd);
347 static SetNetworkForSocket setNetworkForSocket; 348 static SetNetworkForSocket setNetworkForSocket;
348 // This is racy, but all racers should come out with the same answer so it 349 // This is racy, but all racers should come out with the same answer so it
349 // shouldn't matter. 350 // shouldn't matter.
350 if (setNetworkForSocket == nullptr) { 351 if (setNetworkForSocket == nullptr) {
351 // Android's netd client library should always be loaded in our address 352 // Android's netd client library should always be loaded in our address
352 // space as it shims libc functions like connect(). 353 // space as it shims libc functions like connect().
353 base::FilePath file(base::FilePath::FromUTF16Unsafe( 354 base::FilePath file(base::FilePath::FromUTF16Unsafe(
354 base::GetNativeLibraryName(base::ASCIIToUTF16("netd_client")))); 355 base::GetNativeLibraryName(base::ASCIIToUTF16("netd_client"))));
xunjieli 2016/06/27 18:54:16 If we already have netd_client loaded in Chromium'
pauljensen 2016/06/27 19:07:10 setNetworkForSocket is nullptr when the executable
356 // Disable IO assertion in LoadNativeLibrary as the library will already
357 // be loaded by the socket() call (which goes through libnetd_client) that
358 // created |socket_|, so no IO will actually be performed. crbug.com/623555
359 base::ThreadRestrictions::ScopedAllowIO allow_io;
355 base::NativeLibrary lib = base::LoadNativeLibrary(file, nullptr); 360 base::NativeLibrary lib = base::LoadNativeLibrary(file, nullptr);
356 setNetworkForSocket = reinterpret_cast<SetNetworkForSocket>( 361 setNetworkForSocket = reinterpret_cast<SetNetworkForSocket>(
357 base::GetFunctionPointerFromNativeLibrary(lib, "setNetworkForSocket")); 362 base::GetFunctionPointerFromNativeLibrary(lib, "setNetworkForSocket"));
358 } 363 }
359 if (setNetworkForSocket == nullptr) 364 if (setNetworkForSocket == nullptr)
360 return ERR_NOT_IMPLEMENTED; 365 return ERR_NOT_IMPLEMENTED;
361 int rv = setNetworkForSocket(network, socket_); 366 int rv = setNetworkForSocket(network, socket_);
362 // If |network| has since disconnected, |rv| will be ENONET. Surface this as 367 // If |network| has since disconnected, |rv| will be ENONET. Surface this as
363 // ERR_NETWORK_CHANGED, rather than MapSystemError(ENONET) which gives back 368 // ERR_NETWORK_CHANGED, rather than MapSystemError(ENONET) which gives back
364 // the less descriptive ERR_FAILED. 369 // the less descriptive ERR_FAILED.
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 return MapSystemError(errno); 808 return MapSystemError(errno);
804 809
805 return OK; 810 return OK;
806 } 811 }
807 812
808 void UDPSocketPosix::DetachFromThread() { 813 void UDPSocketPosix::DetachFromThread() {
809 base::NonThreadSafe::DetachFromThread(); 814 base::NonThreadSafe::DetachFromThread();
810 } 815 }
811 816
812 } // namespace net 817 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698