Compare commits

..

No commits in common. "0fc7bef6da7f64f15798433d14b4a299d1dfb750" and "8f11f75564f4ee416dc94c1a383521f41ff1d5e1" have entirely different histories.

8 changed files with 111 additions and 82 deletions

View File

@ -404,7 +404,7 @@ jobs:
- arch: aarch64_cortex-a53-static - arch: aarch64_cortex-a53-static
openwrt: 'target=sunxi subtarget=cortexa53' openwrt: 'target=sunxi subtarget=cortexa53'
target_cpu: arm64 target_cpu: arm64
extra: 'arm_cpu="cortex-a53" build_static=true no_madvise_syscall=true' extra: 'arm_cpu="cortex-a53" build_static=true'
- arch: aarch64_cortex-a72 - arch: aarch64_cortex-a72
openwrt: 'target=mvebu subtarget=cortexa72' openwrt: 'target=mvebu subtarget=cortexa72'
target_cpu: arm64 target_cpu: arm64
@ -443,7 +443,7 @@ jobs:
- arch: arm_cortex-a7_neon-vfpv4-static - arch: arm_cortex-a7_neon-vfpv4-static
openwrt: 'target=sunxi subtarget=cortexa7' openwrt: 'target=sunxi subtarget=cortexa7'
target_cpu: arm target_cpu: arm
extra: 'arm_version=0 arm_cpu="cortex-a7" arm_fpu="neon-vfpv4" arm_float_abi="hard" arm_use_neon=true build_static=true no_madvise_syscall=true' extra: 'arm_version=0 arm_cpu="cortex-a7" arm_fpu="neon-vfpv4" arm_float_abi="hard" arm_use_neon=true build_static=true'
- arch: arm_cortex-a8_vfpv3 - arch: arm_cortex-a8_vfpv3
openwrt: 'target=sunxi subtarget=cortexa8' openwrt: 'target=sunxi subtarget=cortexa8'
target_cpu: arm target_cpu: arm
@ -455,7 +455,7 @@ jobs:
- arch: arm_cortex-a9-static - arch: arm_cortex-a9-static
openwrt: 'target=bcm53xx subtarget=generic' openwrt: 'target=bcm53xx subtarget=generic'
target_cpu: arm target_cpu: arm
extra: 'arm_version=0 arm_cpu="cortex-a9" arm_float_abi="soft" arm_use_neon=false build_static=true no_madvise_syscall=true' extra: 'arm_version=0 arm_cpu="cortex-a9" arm_float_abi="soft" arm_use_neon=false build_static=true'
- arch: arm_cortex-a9_neon - arch: arm_cortex-a9_neon
openwrt: 'target=zynq subtarget=generic' openwrt: 'target=zynq subtarget=generic'
target_cpu: arm target_cpu: arm
@ -479,7 +479,7 @@ jobs:
- arch: mipsel_24kc-static - arch: mipsel_24kc-static
openwrt: 'target=ramips subtarget=rt305x' openwrt: 'target=ramips subtarget=rt305x'
target_cpu: mipsel target_cpu: mipsel
extra: 'mips_arch_variant="r2" mips_float_abi="soft" build_static=true no_madvise_syscall=true' extra: 'mips_arch_variant="r2" mips_float_abi="soft" build_static=true'
- arch: mipsel_mips32 - arch: mipsel_mips32
openwrt: 'target=bcm47xx subtarget=generic' openwrt: 'target=bcm47xx subtarget=generic'
target_cpu: mipsel target_cpu: mipsel

View File

@ -260,8 +260,6 @@ constexpr PA_COMPONENT_EXPORT(
PARTITION_ALLOC) bool DecommittedMemoryIsAlwaysZeroed() { PARTITION_ALLOC) bool DecommittedMemoryIsAlwaysZeroed() {
#if BUILDFLAG(IS_APPLE) #if BUILDFLAG(IS_APPLE)
return false; return false;
#elif defined(NO_MADVISE_SYSCALL)
return false;
#else #else
return true; return true;
#endif #endif

View File

@ -410,9 +410,6 @@ void DiscardSystemPagesInternal(uintptr_t address, size_t length) {
ret = madvise(ptr, length, MADV_DONTNEED); ret = madvise(ptr, length, MADV_DONTNEED);
} }
PA_PCHECK(ret == 0); PA_PCHECK(ret == 0);
#elif defined(NO_MADVISE_SYSCALL)
static_cast<void>(ptr);
static_cast<void>(length);
#else // BUILDFLAG(IS_APPLE) #else // BUILDFLAG(IS_APPLE)
// We have experimented with other flags, but with suboptimal results. // We have experimented with other flags, but with suboptimal results.
// //
@ -420,7 +417,12 @@ void DiscardSystemPagesInternal(uintptr_t address, size_t length) {
// performance benefits unclear. // performance benefits unclear.
// //
// Therefore, we just do the simple thing: MADV_DONTNEED. // Therefore, we just do the simple thing: MADV_DONTNEED.
PA_PCHECK(0 == madvise(ptr, length, MADV_DONTNEED)); int ret = madvise(ptr, length, MADV_DONTNEED);
if (ret && errno == ENOSYS) {
// Ignores when the kernel is built without CONFIG_ADVISE_SYSCALLS
return;
}
PA_PCHECK(ret == 0);
#endif // BUILDFLAG(IS_APPLE) #endif // BUILDFLAG(IS_APPLE)
} }

View File

@ -14,8 +14,6 @@ assert(current_os == "openwrt")
declare_args() { declare_args() {
build_static = false build_static = false
no_madvise_syscall = false
} }
# This is included by reference in the //build/config/compiler config that # This is included by reference in the //build/config/compiler config that
@ -41,10 +39,6 @@ config("compiler") {
ldflags += [ "-Wl,--dynamic-linker=/lib/ld-musl-mipsel-sf.so.1" ] ldflags += [ "-Wl,--dynamic-linker=/lib/ld-musl-mipsel-sf.so.1" ]
} }
if (no_madvise_syscall) {
defines += [ "NO_MADVISE_SYSCALL" ]
}
abi = "musl" abi = "musl"
if (current_cpu == "arm") { if (current_cpu == "arm") {
abi = "muslgnueabi" abi = "muslgnueabi"

View File

@ -1818,6 +1818,8 @@ executable("naive") {
"tools/naive/redirect_resolver.cc", "tools/naive/redirect_resolver.cc",
"tools/naive/socks5_server_socket.cc", "tools/naive/socks5_server_socket.cc",
"tools/naive/socks5_server_socket.h", "tools/naive/socks5_server_socket.h",
"tools/naive/partition_alloc_support.cc",
"tools/naive/partition_alloc_support.h",
] ]
deps = [ deps = [

View File

@ -9,18 +9,14 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "base/allocator/allocator_check.h"
#include "base/allocator/partition_alloc_support.h" #include "base/allocator/partition_alloc_support.h"
#include "base/allocator/partition_allocator/shim/allocator_shim.h"
#include "base/at_exit.h" #include "base/at_exit.h"
#include "base/check.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/json/json_file_value_serializer.h" #include "base/json/json_file_value_serializer.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/process/memory.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/escape.h" #include "base/strings/escape.h"
@ -65,6 +61,7 @@
#include "net/tools/naive/naive_protocol.h" #include "net/tools/naive/naive_protocol.h"
#include "net/tools/naive/naive_proxy.h" #include "net/tools/naive/naive_proxy.h"
#include "net/tools/naive/naive_proxy_delegate.h" #include "net/tools/naive/naive_proxy_delegate.h"
#include "net/tools/naive/partition_alloc_support.h"
#include "net/tools/naive/redirect_resolver.h" #include "net/tools/naive/redirect_resolver.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
@ -74,7 +71,6 @@
#include "url/url_util.h" #include "url/url_util.h"
#if BUILDFLAG(IS_APPLE) #if BUILDFLAG(IS_APPLE)
#include "base/allocator/early_zone_registration_mac.h"
#include "base/mac/scoped_nsautorelease_pool.h" #include "base/mac/scoped_nsautorelease_pool.h"
#endif #endif
@ -530,70 +526,12 @@ std::unique_ptr<URLRequestContext> BuildURLRequestContext(
} // namespace net } // namespace net
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// chrome/app/chrome_exe_main_mac.cc: main() naive_partition_alloc_support::ReconfigureEarly();
#if BUILDFLAG(IS_APPLE)
partition_alloc::EarlyMallocZoneRegistration();
#endif
// content/app/content_main.cc: RunContentProcess()
#if BUILDFLAG(IS_MAC)
base::mac::ScopedNSAutoreleasePool pool;
#endif
// content/app/content_main.cc: RunContentProcess()
#if BUILDFLAG(IS_APPLE) && BUILDFLAG(USE_ALLOCATOR_SHIM)
// The static initializer function for initializing PartitionAlloc
// InitializeDefaultMallocZoneWithPartitionAlloc() would be removed by the
// linker if allocator_shim.o is not referenced by the following call,
// resulting in undefined behavior of accessing uninitialized TLS
// data in PurgeCurrentThread() when PA is enabled.
allocator_shim::InitializeAllocatorShim();
#endif
// content/app/content_main.cc: RunContentProcess()
base::EnableTerminationOnOutOfMemory();
auto multiple_listens = std::make_unique<MultipleListenCollector>();
MultipleListenCollector& multiple_listens_ref = *multiple_listens;
base::CommandLine::SetDuplicateSwitchHandler(std::move(multiple_listens));
// content/app/content_main.cc: RunContentProcess()
base::CommandLine::Init(argc, argv);
// content/app/content_main.cc: RunContentProcess()
base::EnableTerminationOnHeapCorruption();
// content/app/content_main.cc: RunContentProcess()
// content/app/content_main_runner_impl.cc: Initialize()
base::AtExitManager exit_manager;
std::string process_type = "";
base::allocator::PartitionAllocSupport::Get()->ReconfigureEarlyish(
process_type);
// content/app/content_main.cc: RunContentProcess()
// content/app/content_main_runner_impl.cc: Initialize()
// If we are on a platform where the default allocator is overridden (e.g.
// with PartitionAlloc on most platforms) smoke-tests that the overriding
// logic is working correctly. If not causes a hard crash, as its unexpected
// absence has security implications.
CHECK(base::allocator::IsAllocatorInitialized());
// content/app/content_main.cc: RunContentProcess()
// content/app/content_main_runner_impl.cc: Run()
base::FeatureList::InitializeInstance(
"PartitionConnectionsByNetworkIsolationKey", std::string());
base::allocator::PartitionAllocSupport::Get()
->ReconfigureAfterFeatureListInit(/*process_type=*/"");
base::SingleThreadTaskExecutor io_task_executor(base::MessagePumpType::IO);
base::ThreadPoolInstance::CreateAndStartWithDefaultParams("naive");
base::allocator::PartitionAllocSupport::Get()->ReconfigureAfterTaskRunnerInit(
process_type);
url::AddStandardScheme("quic", url::AddStandardScheme("quic",
url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION); url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION);
base::FeatureList::InitializeInstance(
"PartitionConnectionsByNetworkIsolationKey", std::string());
net::ClientSocketPoolManager::set_max_sockets_per_pool( net::ClientSocketPoolManager::set_max_sockets_per_pool(
net::HttpNetworkSession::NORMAL_SOCKET_POOL, net::HttpNetworkSession::NORMAL_SOCKET_POOL,
kDefaultMaxSocketsPerPool * kExpectedMaxUsers); kDefaultMaxSocketsPerPool * kExpectedMaxUsers);
@ -604,6 +542,20 @@ int main(int argc, char* argv[]) {
net::HttpNetworkSession::NORMAL_SOCKET_POOL, net::HttpNetworkSession::NORMAL_SOCKET_POOL,
kDefaultMaxSocketsPerGroup * kExpectedMaxUsers); kDefaultMaxSocketsPerGroup * kExpectedMaxUsers);
base::allocator::PartitionAllocSupport::Get()
->ReconfigureAfterFeatureListInit(/*process_type=*/"");
#if BUILDFLAG(IS_APPLE)
base::mac::ScopedNSAutoreleasePool pool;
#endif
base::AtExitManager exit_manager;
auto multiple_listens = std::make_unique<MultipleListenCollector>();
MultipleListenCollector& multiple_listens_ref = *multiple_listens;
base::CommandLine::SetDuplicateSwitchHandler(std::move(multiple_listens));
base::CommandLine::Init(argc, argv);
CommandLine cmdline; CommandLine cmdline;
Params params; Params params;
@ -625,6 +577,12 @@ int main(int argc, char* argv[]) {
} }
CHECK(logging::InitLogging(params.log_settings)); CHECK(logging::InitLogging(params.log_settings));
base::SingleThreadTaskExecutor io_task_executor(base::MessagePumpType::IO);
base::ThreadPoolInstance::CreateAndStartWithDefaultParams("naive");
base::allocator::PartitionAllocSupport::Get()
->ReconfigureAfterTaskRunnerInit(/*process_type=*/"");
if (!params.ssl_key_path.empty()) { if (!params.ssl_key_path.empty()) {
net::SSLClientSocket::SetSSLKeyLogger( net::SSLClientSocket::SetSSLKeyLogger(
std::make_unique<net::SSLKeyLoggerImpl>(params.ssl_key_path)); std::make_unique<net::SSLKeyLoggerImpl>(params.ssl_key_path));

View File

@ -0,0 +1,60 @@
// Copyright 2021 The Chromium Authors
// Copyright 2022 klzgrad <kizdiv@gmail.com>.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/tools/naive/partition_alloc_support.h"
#include "base/allocator/allocator_check.h"
#include "base/allocator/partition_alloc_support.h"
#include "base/allocator/partition_allocator/shim/allocator_shim.h"
#include "base/check.h"
#include "base/process/memory.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_APPLE)
#include "base/allocator/early_zone_registration_mac.h"
#endif
namespace naive_partition_alloc_support {
void ReconfigureEarly() {
// chrome/app/chrome_exe_main_mac.cc: main()
#if BUILDFLAG(IS_APPLE)
partition_alloc::EarlyMallocZoneRegistration();
#endif
// content/app/content_main.cc: RunContentProcess()
#if BUILDFLAG(IS_APPLE) && BUILDFLAG(USE_ALLOCATOR_SHIM)
// The static initializer function for initializing PartitionAlloc
// InitializeDefaultMallocZoneWithPartitionAlloc() would be removed by the
// linker if allocator_shim.o is not referenced by the following call,
// resulting in undefined behavior of accessing uninitialized TLS
// data in PurgeCurrentThread() when PA is enabled.
allocator_shim::InitializeAllocatorShim();
#endif
// content/app/content_main.cc: RunContentProcess()
base::EnableTerminationOnOutOfMemory();
// content/app/content_main.cc: RunContentProcess()
base::EnableTerminationOnHeapCorruption();
// content/app/content_main.cc: RunContentProcess()
// content/app/content_main_runner_impl.cc: Initialize()
// ReconfigureEarlyish():
// These initializations are only relevant for PartitionAlloc-Everywhere
// builds.
base::allocator::PartitionAllocSupport::Get()->ReconfigureEarlyish(
/*process_type=*/"");
// content/app/content_main.cc: RunContentProcess()
// content/app/content_main_runner_impl.cc: Initialize()
// If we are on a platform where the default allocator is overridden (e.g.
// with PartitionAlloc on most platforms) smoke-tests that the overriding
// logic is working correctly. If not causes a hard crash, as its unexpected
// absence has security implications.
CHECK(base::allocator::IsAllocatorInitialized());
}
} // namespace naive_partition_alloc_support

View File

@ -0,0 +1,15 @@
// Copyright 2021 The Chromium Authors
// Copyright 2022 klzgrad <kizdiv@gmail.com>.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_NAIVE_PARTITION_ALLOC_SUPPORT_H_
#define NET_TOOLS_NAIVE_PARTITION_ALLOC_SUPPORT_H_
namespace naive_partition_alloc_support {
void ReconfigureEarly();
} // namespace naive_partition_alloc_support
#endif // NET_TOOLS_NAIVE_PARTITION_ALLOC_SUPPORT_H_