Fix recommitted pages not being zeroed when madvise is not available.

This commit is contained in:
klzgrad 2023-09-17 20:18:24 +08:00
parent 978ff90c36
commit 0fc7bef6da
4 changed files with 16 additions and 10 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' extra: 'arm_cpu="cortex-a53" build_static=true no_madvise_syscall=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' 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'
- 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' extra: 'arm_version=0 arm_cpu="cortex-a9" arm_float_abi="soft" arm_use_neon=false build_static=true no_madvise_syscall=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' extra: 'mips_arch_variant="r2" mips_float_abi="soft" build_static=true no_madvise_syscall=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,6 +260,8 @@ 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,6 +410,9 @@ 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.
// //
@ -417,12 +420,7 @@ 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.
int ret = madvise(ptr, length, MADV_DONTNEED); PA_PCHECK(0 == 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,6 +14,8 @@ 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
@ -39,6 +41,10 @@ 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"