devel/electron34: add port: Build cross-platform desktop apps with JavaScript, HTML, and CSS

Build cross platform desktop apps with JavaScript, HTML, and CSS.

It's easier than you think.

If you can build a website, you can build a desktop app. Electron is a
framework for creating native applications with web technologies like
JavaScript, HTML, and CSS. It takes care of the hard parts so you can
focus on the core of your application.

WWW: https://electronjs.org/
This commit is contained in:
Hiroki Tagato
2025-03-14 18:43:48 +09:00
parent ee8461378e
commit 65178207cf
1483 changed files with 46861 additions and 0 deletions
+1
View File
@@ -658,6 +658,7 @@
SUBDIR += electron31
SUBDIR += electron32
SUBDIR += electron33
SUBDIR += electron34
SUBDIR += elf
SUBDIR += elf-dissector
SUBDIR += elfcat
+454
View File
@@ -0,0 +1,454 @@
PORTNAME= electron
DISTVERSIONPREFIX= v
DISTVERSION= ${ELECTRON_VER}
PULSEMV= 16
PULSEV= ${PULSEMV}.1
CATEGORIES= devel
MASTER_SITES= https://github.com/tagattie/FreeBSD-Electron/releases/download/v34.3.2/:chromium \
https://freedesktop.org/software/pulseaudio/releases/:pulseaudio
PKGNAMESUFFIX= ${ELECTRON_VER_MAJOR}
DISTFILES= chromium-${CHROMIUM_VER}${EXTRACT_SUFX}.0:chromium \
chromium-${CHROMIUM_VER}${EXTRACT_SUFX}.1:chromium \
chromium-${CHROMIUM_VER}${EXTRACT_SUFX}.2:chromium \
pulseaudio-${PULSEV}.tar.gz:pulseaudio \
electron-yarn-cache-${ELECTRON_VER}${EXTRACT_SUFX}:prefetch
DIST_SUBDIR= ${PORTNAME}
EXTRACT_ONLY= chromium-${CHROMIUM_VER}${EXTRACT_SUFX} \
${DISTFILES:C/:[^:]+$//:C/chromium-${CHROMIUM_VER}${EXTRACT_SUFX}\.[0-9]//}
MAINTAINER= tagattie@FreeBSD.org
COMMENT= Build cross-platform desktop apps with JavaScript, HTML, and CSS
WWW= https://electronjs.org/
LICENSE= BSD3CLAUSE LGPL21 MPL11 MIT
LICENSE_COMB= multi
LICENSE_FILE= ${WRKSRC}/electron/LICENSE
ONLY_FOR_ARCHS= aarch64 amd64 i386
FETCH_DEPENDS= yarn${NODEJS_SUFFIX}>0:www/yarn${NODEJS_SUFFIX}
EXTRACT_DEPENDS=yarn${NODEJS_SUFFIX}>0:www/yarn${NODEJS_SUFFIX}
PATCH_DEPENDS= git:devel/git \
jq:textproc/jq
BUILD_DEPENDS= gperf:devel/gperf \
bindgen:devel/rust-bindgen-cli \
yasm:devel/yasm \
${LOCALBASE}/libdata/pkgconfig/dri.pc:graphics/mesa-dri \
rustc:lang/rust \
${LOCALBASE}/include/linux/videodev2.h:multimedia/v4l_compat \
node${NODEJS_VERSION}>0:www/node${NODEJS_VERSION} \
npm${NODEJS_SUFFIX}>0:www/npm${NODEJS_SUFFIX}
LIB_DEPENDS= libatk-bridge-2.0.so:accessibility/at-spi2-core \
libatspi.so:accessibility/at-spi2-core \
libFLAC.so:audio/flac \
libopus.so:audio/opus \
libdbus-1.so:devel/dbus \
libicuuc.so:devel/icu \
libepoll-shim.so:devel/libepoll-shim \
libevent.so:devel/libevent \
libffi.so:devel/libffi \
libnotify.so:devel/libnotify \
libpci.so:devel/libpci \
libnspr4.so:devel/nspr \
libre2.so:devel/re2 \
libdrm.so:graphics/libdrm \
libpng.so:graphics/png \
libwayland-client.so:graphics/wayland \
libwebp.so:graphics/webp \
libdav1d.so:multimedia/dav1d \
libva.so:multimedia/libva \
libopenh264.so:multimedia/openh264 \
libfreetype.so:print/freetype2 \
libharfbuzz.so:print/harfbuzz \
libsecret-1.so:security/libsecret \
libnss3.so:security/nss \
libexpat.so:textproc/expat2 \
libxkbcommon.so:x11/libxkbcommon \
libxshmfence.so:x11/libxshmfence \
libfontconfig.so:x11-fonts/fontconfig
RUN_DEPENDS= xdg-open:devel/xdg-utils
TEST_DEPENDS= git:devel/git \
${PYTHON_PKGNAMEPREFIX}python-dbusmock>0:devel/py-python-dbusmock@${PY_FLAVOR} \
npm${NODEJS_SUFFIX}>0:www/npm${NODEJS_SUFFIX}
USES= bison compiler:c++17-lang cpe gettext-tools gl gmake gnome \
iconv:wchar_t jpeg localbase:ldflags ninja nodejs:20,build \
pkgconfig python:build,test shebangfix tar:xz xorg
CPE_VENDOR= electronjs
USE_GITHUB= yes
GH_TUPLE= nodejs:node:v${NODE_VER}:node \
nodejs:nan:${NAN_VER}:nan \
Squirrel:Squirrel.Mac:${SQUIRREL_MAC_VER}:squirrel_mac \
ReactiveCocoa:ReactiveObjC:${REACTIVEOBJC_VER}:reactiveobjc \
Mantle:Mantle:${MANTLE_VER}:mantle \
EngFlow:reclient-configs:${ENGFLOW_RECLIENT_CONFIGS_VER}:reclient_configs
USE_GL= gbm gl glesv2
USE_GNOME= atk cairo gdkpixbuf2 gtk30 libxml2 libxslt pango
USE_XORG= x11 xcb xcomposite xcursor xdamage xext xfixes xi xrandr \
xrender xscrnsaver xtst
SHEBANG_FILES= chrome/tools/build/linux/chrome-wrapper buildtools/linux64/clang-format
MAKE_ARGS= -C out/${BUILDTYPE}
MAKE_ENV+= C_INCLUDE_PATH=${LOCALBASE}/include \
CPLUS_INCLUDE_PATH=${LOCALBASE}/include
ALL_TARGET= electron electron:node_headers
POST_BUILD_TARGETS= licenses version
POST_BUILD_DIST_TARGETS=electron_dist_zip electron_chromedriver_zip \
electron_mksnapshot_zip
DATADIR= ${PREFIX}/share/${PORTNAME}${PKGNAMESUFFIX}
BINARY_ALIAS= python3=${PYTHON_CMD}
BUNDLE_LIBS= yes
NO_WRKSUBDIR= yes
WRKSRC_SUBDIR= src
GN_ARGS+= clang_use_chrome_plugins=false \
enable_backup_ref_ptr_support=false \
enable_hangout_services_extension=true \
enable_nacl=false \
enable_remoting=false \
fatal_linker_warnings=false \
icu_use_data_file=false \
is_clang=true \
optimize_webui=true \
toolkit_views=true \
treat_warnings_as_errors=false \
use_allocator_shim=false \
use_aura=true \
use_custom_libcxx=true \
use_custom_libunwind=true \
use_lld=true \
use_partition_alloc=true \
use_partition_alloc_as_malloc=false \
use_sysroot=false \
use_system_freetype=false \
use_system_harfbuzz=true \
use_system_libffi=true \
use_system_libjpeg=true \
use_udev=false \
chrome_pgo_phase=0 \
extra_cflags="${CFLAGS}" \
extra_cxxflags="${CXXFLAGS} -I${LOCALBASE}/include/libepoll-shim ${PINCLUDES}" \
extra_ldflags="${LDFLAGS}" \
ffmpeg_branding="${FFMPEG_BRAND}" \
override_electron_version="${ELECTRON_VER}"
# TODO: investigate building with these options:
# use_system_minigbm
GN_BOOTSTRAP_FLAGS= --no-clean --no-rebuild --skip-generate-buildfiles
PLIST_SUB= ELECTRON_VER=${ELECTRON_VER} \
ELECTRON_VER_MAJOR=${ELECTRON_VER_MAJOR}
OPTIONS_DEFINE= CODECS CUPS DEBUG DIST DRIVER KERBEROS LTO PIPEWIRE
OPTIONS_DEFAULT= CODECS CUPS DRIVER KERBEROS PIPEWIRE ALSA PULSEAUDIO SNDIO
OPTIONS_EXCLUDE_aarch64=LTO
OPTIONS_GROUP= AUDIO
OPTIONS_GROUP_AUDIO= ALSA PULSEAUDIO SNDIO
OPTIONS_RADIO= KERBEROS
OPTIONS_RADIO_KERBEROS= HEIMDAL HEIMDAL_BASE MIT
OPTIONS_SUB= yes
CODECS_DESC= Compile and enable patented codecs like H.264
DIST_DESC= Build distribution zip files
DRIVER_DESC= Install chromedriver
HEIMDAL_BASE_DESC= Heimdal Kerberos (base)
HEIMDAL_DESC= Heimdal Kerberos (security/heimdal)
MIT_DESC= MIT Kerberos (security/krb5)
PIPEWIRE_DESC= Screen capture via PipeWire
ALSA_LIB_DEPENDS= libasound.so:audio/alsa-lib
ALSA_RUN_DEPENDS= ${LOCALBASE}/lib/alsa-lib/libasound_module_pcm_oss.so:audio/alsa-plugins \
alsa-lib>=1.1.1_1:audio/alsa-lib
ALSA_VARS= GN_ARGS+=use_alsa=true
ALSA_VARS_OFF= GN_ARGS+=use_alsa=false
CODECS_VARS= GN_ARGS+=proprietary_codecs=true \
FFMPEG_BRAND="Chrome"
CODECS_VARS_OFF= GN_ARGS+=proprietary_codecs=false \
FFMPEG_BRAND="Chromium"
CUPS_LIB_DEPENDS= libcups.so:print/cups
CUPS_VARS= GN_ARGS+=use_cups=true
CUPS_VARS_OFF= GN_ARGS+=use_cups=false
DEBUG_BUILD_DEPENDS= esbuild:devel/esbuild
DEBUG_VARS= BUILDTYPE=Debug \
GN_FILE=testing.gn \
GN_ARGS+=is_debug=true \
GN_ARGS+=is_component_build=false \
GN_ARGS+=symbol_level=1 \
GN_BOOTSTRAP_FLAGS+=--debug \
WANTSPACE="21 GB"
DEBUG_VARS_OFF= BUILDTYPE=Release \
GN_FILE=release.gn \
GN_ARGS+=blink_symbol_level=0 \
GN_ARGS+=is_debug=false \
GN_ARGS+=is_official_build=true \
GN_ARGS+=symbol_level=0 \
WANTSPACE="14 GB"
DIST_IMPLIES= DRIVER
DRIVER_MAKE_ARGS= chromedriver
HEIMDAL_LIB_DEPENDS= libkrb5.so.26:security/heimdal
KERBEROS_VARS= GN_ARGS+=use_kerberos=true
KERBEROS_VARS_OFF= GN_ARGS+=use_kerberos=false
LTO_VARS= GN_ARGS+=use_thin_lto=true \
GN_ARGS+=thin_lto_enable_optimizations=true \
WANTSPACE="14 GB"
LTO_VARS_OFF= GN_ARGS+=use_thin_lto=false
MIT_LIB_DEPENDS= libkrb5.so.3:security/krb5
PIPEWIRE_LIB_DEPENDS= libpipewire-0.3.so:multimedia/pipewire
PIPEWIRE_VARS= GN_ARGS+=rtc_use_pipewire=true \
GN_ARGS+=rtc_link_pipewire=true
PIPEWIRE_VARS_OFF= GN_ARGS+=rtc_use_pipewire=false \
GN_ARGS+=rtc_link_pipewire=false
PULSEAUDIO_VARS= GN_ARGS+=use_pulseaudio=true \
PINCLUDES="-I${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/pulseaudio-${PULSEV}/src -DPA_MAJOR=${PULSEMV}"
PULSEAUDIO_VARS_OFF= GN_ARGS+=use_pulseaudio=false
SNDIO_LIB_DEPENDS= libsndio.so:audio/sndio
SNDIO_VARS= GN_ARGS+=use_sndio=true
SNDIO_VARS_OFF= GN_ARGS+=use_sndio=false
# See ${WRKSRC}/electron/DEPS for CHROMIUM_VER
CHROMIUM_VER= 132.0.6834.210
# See ${WRKSRC}/electron/DEPS for NODE_VER
NODE_VER= 20.18.3
# See ${WRKSRC}/electron/DEPS for NAN_VER
NAN_VER= e14bdcd1f72d62bca1d541b66da43130384ec213
# See ${WRKSRC}/electron/DEPS for SQUIRREL_MAC_VER
SQUIRREL_MAC_VER= 0e5d146ba13101a1302d59ea6e6e0b3cace4ae38
# See ${WRKSRC}/electron/DEPS for REACTIVEOBJC_VER
REACTIVEOBJC_VER= 74ab5baccc6f7202c8ac69a8d1e152c29dc1ea76
# See ${WRKSRC}/electron/DEPS for MANTLE_VER
MANTLE_VER= 78d3966b3c331292ea29ec38661b25df0a245948
# See ${WRKSRC}/electron/DEPS for ENGFLOW_RECLIENT_CONFIGS_VER
ENGFLOW_RECLIENT_CONFIGS_VER= 955335c30a752e9ef7bff375baab5e0819b6c00d
YARN_TIMESTAMP= 61171200
.include "Makefile.version"
.include <bsd.port.pre.mk>
.if ${PORT_OPTIONS:MHEIMDAL_BASE} && !exists(/usr/lib/libkrb5.so)
IGNORE= you have selected HEIMDAL_BASE but do not have Heimdal installed in base
.endif
LLVM_DEFAULT= 19
BUILD_DEPENDS+= clang${LLVM_DEFAULT}:devel/llvm${LLVM_DEFAULT}
BINARY_ALIAS+= cpp=${LOCALBASE}/bin/clang-cpp${LLVM_DEFAULT} \
cc=${LOCALBASE}/bin/clang${LLVM_DEFAULT} \
c++=${LOCALBASE}/bin/clang++${LLVM_DEFAULT} \
ar=${LOCALBASE}/bin/llvm-ar${LLVM_DEFAULT} \
nm=${LOCALBASE}/bin/llvm-nm${LLVM_DEFAULT} \
ld=${LOCALBASE}/bin/ld.lld${LLVM_DEFAULT}
CFLAGS+= -Wno-error=implicit-function-declaration
.if ${ARCH} == "aarch64"
PLIST_SUB+= AARCH64="" \
AMD64="@comment " \
I386="@comment " \
NOT_AARCH64="@comment "
FFMPEG_TARGET= arm64
.elif ${ARCH} == "amd64"
BUILD_DEPENDS+= nasm:devel/nasm
PLIST_SUB+= AARCH64="@comment " \
AMD64="" \
I386="@comment " \
NOT_AARCH64=""
FFMPEG_TARGET= x64
.elif ${ARCH} == "i386"
BUILD_DEPENDS+= nasm:devel/nasm
PLIST_SUB+= AARCH64="@comment " \
AMD64="@comment " \
I386="" \
NOT_AARCH64=""
FFMPEG_TARGET= ia32
.endif
FFMPEG_BDIR= ${WRKSRC}/third_party/ffmpeg/build.${FFMPEG_TARGET}.freebsd/${FFMPEG_BRAND}
FFMPEG_CDIR= ${WRKSRC}/third_party/ffmpeg/chromium/config/${FFMPEG_BRAND}/freebsd/${FFMPEG_TARGET}
# Allow relocations against read-only segments (override lld default)
LDFLAGS_i386= -Wl,-znotext
# TODO: -isystem, would be just as ugly as this approach, but more reliably
# build would fail without C_INCLUDE_PATH/CPLUS_INCLUDE_PATH env var set.
MAKE_ENV+= C_INCLUDE_PATH=${LOCALBASE}/include \
CPLUS_INCLUDE_PATH=${LOCALBASE}/include
# rust
RUSTC_VERSION!= rustc -V 2>/dev/null || true
MAKE_ENV+= RUSTC_BOOTSTRAP=1
GN_ARGS+= enable_rust=true \
rust_sysroot_absolute="${LOCALBASE}" \
rustc_version="${RUSTC_VERSION}"
pre-everything::
@${ECHO_MSG}
@${ECHO_MSG} "To build electron, you should have around 2GB of memory"
@${ECHO_MSG} "and around ${WANTSPACE} of free disk space."
@${ECHO_MSG}
pre-fetch:
@${MKDIR} ${DISTDIR}/${DIST_SUBDIR}
if [ ! -f ${DISTDIR}/${DIST_SUBDIR}/electron-yarn-cache-${ELECTRON_VER}${EXTRACT_SUFX} ]; \
then ${MKDIR} ${WRKDIR}; \
${ECHO_CMD} 'yarn-offline-mirror "./yarn-offline-cache"' >> \
${WRKDIR}/.yarnrc; \
${CP} ${FILESDIR}/package.json ${FILESDIR}/yarn.lock ${WRKDIR}; \
cd ${WRKDIR} && ${SETENV} HOME=${WRKDIR} XDG_CACHE_HOME=${WRKDIR}/.cache \
yarn --frozen-lockfile --ignore-scripts; \
${MTREE_CMD} -cbnSp yarn-offline-cache | ${MTREE_CMD} -C | ${SED} \
-e 's:time=[0-9.]*:time=${YARN_TIMESTAMP}.000000000:' \
-e 's:\([gu]id\)=[0-9]*:\1=0:g' \
-e 's:mode=\([0-9]\)7[0-9][0-9]:mode=\1755:' \
-e 's:mode=\([0-9]\)6[0-9][0-9]:mode=\1644:' \
-e 's:flags=.*:flags=none:' \
-e 's:^\.:./yarn-offline-cache:' > yarn-offline-cache.mtree; \
${TAR} cJf ${DISTDIR}/${DIST_SUBDIR}/electron-yarn-cache-${ELECTRON_VER}${EXTRACT_SUFX} \
@yarn-offline-cache.mtree; \
${RM} -r ${WRKDIR}; \
fi
post-fetch:
@if [ ! -f ${DISTDIR}/${DIST_SUBDIR}/chromium-${CHROMIUM_VER}${EXTRACT_SUFX} ]; then \
${CAT} ${DISTDIR}/${DIST_SUBDIR}/chromium-${CHROMIUM_VER}${EXTRACT_SUFX}.? > \
${DISTDIR}/${DIST_SUBDIR}/chromium-${CHROMIUM_VER}${EXTRACT_SUFX}; \
fi
post-extract:
# Move extracted sources to appropriate locations
${MV} ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/chromium-${CHROMIUM_VER} ${WRKSRC}
${MV} ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/${PORTNAME}-${ELECTRON_VER} ${WRKSRC}/electron
${MV} ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/${GH_PROJECT_nan}-${NAN_VER} \
${WRKSRC}/third_party/nan
${MV} ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/${GH_PROJECT_node}-${NODE_VER} \
${WRKSRC}/third_party/electron_node
${MV} ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/${GH_PROJECT_squirrel_mac}-${SQUIRREL_MAC_VER} \
${WRKSRC}/third_party/squirrel.mac
${MKDIR} ${WRKSRC}/third_party/squirrel.mac/vendor
${MV} ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/${GH_PROJECT_reactiveobjc}-${REACTIVEOBJC_VER} \
${WRKSRC}/third_party/squirrel.mac/vendor/ReactiveObjC
${MV} ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/${GH_PROJECT_mantle}-${MANTLE_VER} \
${WRKSRC}/third_party/squirrel.mac/vendor/Mantle
${MV} ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/${GH_PROJECT_reclient_configs}-${ENGFLOW_RECLIENT_CONFIGS_VER} \
${WRKSRC}/third_party/engflow-reclient-configs
# Install node modules for electron
${MV} ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/yarn-offline-cache ${WRKDIR}
${ECHO_CMD} 'yarn-offline-mirror "../../../yarn-offline-cache"' >> ${WRKSRC}/electron/.yarnrc
${MV} ${WRKSRC}/electron/package.json ${WRKSRC}/electron/package.json.bak
${CP} ${FILESDIR}/package.json ${WRKSRC}/electron
cd ${WRKSRC}/electron && \
${SETENV} HOME=${WRKDIR} XDG_CACHE_HOME=${WRKDIR}/.cache yarn --frozen-lockfile --offline
pre-patch:
${SH} ${FILESDIR}/apply-electron-patches.sh ${WRKSRC}
# ${FIND} ${WRKSRC} -type f -name '*.orig' -print -delete
# ${FIND} ${WRKSRC} -type f -name '*~' -print -delete
pre-configure:
# We used to remove bundled libraries to be sure that chromium uses
# system libraries and not shipped ones.
# cd ${WRKSRC} && ${PYTHON_CMD} \
#./build/linux/unbundle/remove_bundled_libraries.py [list of preserved]
cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ${PYTHON_CMD} \
./build/linux/unbundle/replace_gn_files.py --system-libraries \
dav1d flac fontconfig harfbuzz-ng libdrm libevent libpng \
libusb libwebp libxml libxslt openh264 opus || ${FALSE}
# Chromium uses an unreleased version of FFmpeg, so configure it
cd ${WRKSRC}/media/ffmpeg && \
${PYTHON_CMD} scripts/build_ffmpeg.py freebsd ${FFMPEG_TARGET} \
--config-only --branding=${FFMPEG_BRAND}
cd ${FFMPEG_BDIR} && ${GMAKE} ffversion.h
${MKDIR} ${FFMPEG_CDIR}
.for _e in config.h config.asm config_components.h libavcodec libavformat libavutil
-${CP} -pR ${FFMPEG_BDIR}/${_e} ${FFMPEG_CDIR}
.endfor
touch ${WRKDIR}/${PORTNAME}-${ELECTRON_VER}/pulseaudio-${PULSEV}/src/pulse/version.h
@${REINPLACE_CMD} -e 's|$${LOCALBASE}|${LOCALBASE}|;s|$${MODCLANG_VERSION}|${LLVM_DEFAULT}|' \
${WRKSRC}/build/rust/rust_bindgen.gni \
${WRKSRC}/build/rust/rust_bindgen_generator.gni
do-configure:
# GN generator bootstrapping and generating ninja files
cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} CC=${CC} CXX=${CXX} LD=${CXX} \
READELF=${READELF} AR=${AR} NM=${NM} ${PYTHON_CMD} \
./tools/gn/bootstrap/bootstrap.py ${GN_BOOTSTRAP_FLAGS}
cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ./out/${BUILDTYPE}/gn gen out/${BUILDTYPE} \
--args='import("//electron/build/args/${GN_FILE}") ${GN_ARGS}'
# Setup nodejs dependency
@${MKDIR} ${WRKSRC}/third_party/node/freebsd/node-freebsd/bin
${LN} -sf ${LOCALBASE}/bin/node ${WRKSRC}/third_party/node/freebsd/node-freebsd/bin/node
# Setup buildtools/freebsd
@${MKDIR} ${WRKSRC}/buildtools/freebsd
${LN} -sf ${WRKSRC}/buildtools/linux64/clang-format ${WRKSRC}/buildtools/freebsd
${LN} -sf ${WRKSRC}/out/${BUILDTYPE}/gn ${WRKSRC}/buildtools/freebsd
${LN} -sf /usr/bin/strip ${WRKSRC}/buildtools/freebsd/strip
post-build:
cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} \
${MAKE_CMD} ${MAKE_ARGS} ${POST_BUILD_TARGETS}
post-build-DIST-on:
cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} \
${MAKE_CMD} ${MAKE_ARGS} ${POST_BUILD_DIST_TARGETS}
cd ${WRKSRC}/out/${BUILDTYPE} && \
${CP} chromedriver.zip chromedriver-v${ELECTRON_VER}-freebsd-${ARCH:S/amd64/x64/:S/i386/ia32/}.zip && \
${CP} dist.zip electron-v${ELECTRON_VER}-freebsd-${ARCH:S/amd64/x64/:S/i386/ia32/}.zip && \
${CP} mksnapshot.zip mksnapshot-v${ELECTRON_VER}-freebsd-${ARCH:S/amd64/x64/:S/i386/ia32/}.zip && \
${SHA256} -r *-v${ELECTRON_VER}-freebsd-*.zip | ${SED} -e 's/ / */' > SHASUMS256.txt
do-install:
${MKDIR} ${STAGEDIR}${DATADIR}
.for f in electron mksnapshot v8_context_snapshot_generator
${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/${f} ${STAGEDIR}${DATADIR}
.endfor
.for f in libEGL.so libGLESv2.so libffmpeg.so libvk_swiftshader.so
${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/${f} ${STAGEDIR}${DATADIR}
.endfor
${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libvulkan.so.1 ${STAGEDIR}${DATADIR}/libvulkan.so
.for f in LICENSE LICENSES.chromium.html snapshot_blob.bin v8_context_snapshot.bin version vk_swiftshader_icd.json
${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/${f} ${STAGEDIR}${DATADIR}
.endfor
.for f in chrome_100_percent.pak chrome_200_percent.pak resources.pak
${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/${f} ${STAGEDIR}${DATADIR}
.endfor
${MKDIR} ${STAGEDIR}${DATADIR}/locales
${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/locales/*.pak ${STAGEDIR}${DATADIR}/locales
${MKDIR} ${STAGEDIR}${DATADIR}/resources
.for f in default_app.asar
${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/resources/${f} ${STAGEDIR}${DATADIR}/resources
.endfor
cd ${WRKSRC}/out/${BUILDTYPE}/gen && ${COPYTREE_SHARE} node_headers ${STAGEDIR}${DATADIR}
cd ${WRKSRC}/out/${BUILDTYPE} && ${COPYTREE_SHARE} gen/electron/buildflags ${STAGEDIR}${DATADIR}
cd ${WRKSRC}/out/${BUILDTYPE} && ${COPYTREE_SHARE} gen/v8/embedded.S ${STAGEDIR}${DATADIR}
${RLN} ${STAGEDIR}${DATADIR}/electron ${STAGEDIR}${PREFIX}/bin/electron${PKGNAMESUFFIX}
post-install-DIST-on:
${MKDIR} ${STAGEDIR}${DATADIR}/releases
${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/SHASUMS256.txt ${STAGEDIR}${DATADIR}/releases
${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/*-v${ELECTRON_VER}-freebsd-*.zip ${STAGEDIR}${DATADIR}/releases
post-install-DRIVER-on:
${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/chromedriver.unstripped \
${STAGEDIR}${DATADIR}/chromedriver
do-test:
# Note 1: "npm install" will run before actual tests are executed
# Note 2: Xvfb or something similar is necessary for headless testing
cd ${WRKSRC}/electron && \
${SETENV} ${TEST_ENV} ELECTRON_OUT_DIR=${BUILDTYPE} LOCAL_GIT_DIRECTORY=${LOCALBASE} \
npm run test -- --ci
.include <bsd.port.post.mk>
+2
View File
@@ -0,0 +1,2 @@
ELECTRON_VER= 34.3.2
ELECTRON_VER_MAJOR= ${ELECTRON_VER:C/\..*//}
+25
View File
@@ -0,0 +1,25 @@
TIMESTAMP = 1741694502
SHA256 (electron/chromium-132.0.6834.210.tar.xz.0) = ede58a1501f175aaa6c92e47793b773ed10b31a43d600375cb40727c4ae677d5
SIZE (electron/chromium-132.0.6834.210.tar.xz.0) = 2000000000
SHA256 (electron/chromium-132.0.6834.210.tar.xz.1) = 6d080b3948ef1d63d08b8cc1390662a439e635b881561434787b8b67ea99b08d
SIZE (electron/chromium-132.0.6834.210.tar.xz.1) = 2000000000
SHA256 (electron/chromium-132.0.6834.210.tar.xz.2) = 989e234492cf50454303ec6f490f9e20002aa16cd69915a3c09b6e06f668be82
SIZE (electron/chromium-132.0.6834.210.tar.xz.2) = 484148560
SHA256 (electron/pulseaudio-16.1.tar.gz) = 027266c62f2a84422ac45fa721a649508f0f1628fb1fd9242315ac54ce2d7c92
SIZE (electron/pulseaudio-16.1.tar.gz) = 2763111
SHA256 (electron/electron-yarn-cache-34.3.2.tar.xz) = f0fa33e22a0b00e5440fbc57517f7b303d43ca07c25e43f35e28f97c2ce12c83
SIZE (electron/electron-yarn-cache-34.3.2.tar.xz) = 29062184
SHA256 (electron/electron-electron-v34.3.2_GH0.tar.gz) = 2376ccfadd700973e62f4c7e3ef58d5e1613102aaf058e7812294e9e87c44685
SIZE (electron/electron-electron-v34.3.2_GH0.tar.gz) = 14826088
SHA256 (electron/nodejs-node-v20.18.3_GH0.tar.gz) = a2049a1607fbc5b9ec4336d9d04faeeb9b8efdc9ec853e8ddf7cf419be9dbb3d
SIZE (electron/nodejs-node-v20.18.3_GH0.tar.gz) = 115601859
SHA256 (electron/nodejs-nan-e14bdcd1f72d62bca1d541b66da43130384ec213_GH0.tar.gz) = 02edf8d5b3fef9af94d8a1355da60564a57e7f2c99cb422bce042400607ed2eb
SIZE (electron/nodejs-nan-e14bdcd1f72d62bca1d541b66da43130384ec213_GH0.tar.gz) = 180646
SHA256 (electron/Squirrel-Squirrel.Mac-0e5d146ba13101a1302d59ea6e6e0b3cace4ae38_GH0.tar.gz) = f4ebb40a8d85dbb7ef02aa0571b2f8e22182c6d73b6992484a53c90047779d01
SIZE (electron/Squirrel-Squirrel.Mac-0e5d146ba13101a1302d59ea6e6e0b3cace4ae38_GH0.tar.gz) = 2112918
SHA256 (electron/ReactiveCocoa-ReactiveObjC-74ab5baccc6f7202c8ac69a8d1e152c29dc1ea76_GH0.tar.gz) = 88e65f116c7a06fccedb43970fba63080a57a4e5dc29147d2cdfe1ee58dd0546
SIZE (electron/ReactiveCocoa-ReactiveObjC-74ab5baccc6f7202c8ac69a8d1e152c29dc1ea76_GH0.tar.gz) = 1136238
SHA256 (electron/Mantle-Mantle-78d3966b3c331292ea29ec38661b25df0a245948_GH0.tar.gz) = a365df6d83e0be3cc000b70bd39734d80c28f0d9983ebe44698337a2ca464bb1
SIZE (electron/Mantle-Mantle-78d3966b3c331292ea29ec38661b25df0a245948_GH0.tar.gz) = 62962
SHA256 (electron/EngFlow-reclient-configs-955335c30a752e9ef7bff375baab5e0819b6c00d_GH0.tar.gz) = c148f76220fc41a89ffeaf370c2cc175577be184688b12aa6fec5f8ac6c714c4
SIZE (electron/EngFlow-reclient-configs-955335c30a752e9ef7bff375baab5e0819b6c00d_GH0.tar.gz) = 13014
@@ -0,0 +1,26 @@
#! /bin/sh
PATH=/bin:/usr/bin:/usr/local/bin
GIT_CMD="git"
PATCH_CMD="${GIT_CMD} apply"
#PATCH_FLAGS="--numstat --check" # for debugging
PATCH_FLAGS="--verbose --reject"
WRKSRC=$1
PATCH_CONF=${WRKSRC}/electron/patches/config.json
${GIT_CMD} status "${WRKSRC}" > /dev/null 2>&1 && IS_GIT_REPO=1
PATCHD_REPOD_PAIRS=$(jq -r '.[] | .patch_dir + ":" + .repo' "${PATCH_CONF}")
for prp in ${PATCHD_REPOD_PAIRS}; do
pd=$(echo "${prp}" | awk -F: '{print $1}' | sed -e 's/src/./')
rd=$(echo "${prp}" | awk -F: '{print $2}' | sed -e 's/src/./')
(cd "${WRKSRC}/${rd}" && \
if [ -n "${IS_GIT_REPO}" ]; then
PATCH_FLAGS="${PATCH_FLAGS} --directory=$(${GIT_CMD} rev-parse --show-prefix)"
fi && \
while read -r p; do
${PATCH_CMD} ${PATCH_FLAGS} "${WRKSRC}/${pd}/${p}"
done < "${WRKSRC}/${pd}/.patches")
done
+141
View File
@@ -0,0 +1,141 @@
{
"name": "electron",
"version": "0.0.0-development",
"repository": "https://github.com/electron/electron",
"description": "Build cross platform desktop apps with JavaScript, HTML, and CSS",
"devDependencies": {
"@azure/storage-blob": "^12.25.0",
"@electron/asar": "^3.2.13",
"@electron/docs-parser": "^2.0.0",
"@electron/fiddle-core": "^1.3.4",
"@electron/github-app-auth": "^2.2.1",
"@electron/lint-roller": "^2.4.0",
"@electron/typescript-definitions": "^9.0.0",
"@octokit/rest": "^20.0.2",
"@primer/octicons": "^10.0.0",
"@types/minimist": "^1.2.5",
"@types/node": "^20.9.0",
"@types/semver": "^7.5.8",
"@types/stream-json": "^1.7.7",
"@types/temp": "^0.9.4",
"@types/webpack": "^5.28.5",
"@types/webpack-env": "^1.18.5",
"@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0",
"buffer": "^6.0.3",
"chalk": "^4.1.0",
"check-for-leaks": "^1.2.1",
"dugite": "^2.7.1",
"eslint": "^8.57.1",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-standard": "^5.0.0",
"eslint-plugin-unicorn": "^55.0.0",
"events": "^3.2.0",
"folder-hash": "^2.1.1",
"got": "^11.8.5",
"husky": "^8.0.1",
"lint-staged": "^10.2.11",
"markdownlint-cli2": "^0.13.0",
"minimist": "^1.2.8",
"null-loader": "^4.0.1",
"pre-flight": "^2.0.0",
"process": "^0.11.10",
"remark-cli": "^10.0.0",
"remark-preset-lint-markdown-style-guide": "^4.0.0",
"semver": "^7.6.3",
"shx": "^0.3.4",
"stream-json": "^1.8.0",
"tap-xunit": "^2.4.1",
"temp": "^0.9.4",
"timers-browserify": "1.4.2",
"ts-loader": "^8.0.2",
"ts-node": "6.2.0",
"typescript": "^5.6.2",
"url": "^0.11.4",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"wrapper-webpack-plugin": "^2.2.0"
},
"private": true,
"scripts": {
"asar": "asar",
"generate-version-json": "node script/generate-version-json.js",
"lint": "node ./script/lint.js && npm run lint:docs",
"lint:js": "node ./script/lint.js --js",
"lint:clang-format": "python3 script/run-clang-format.py -r -c shell/ || (echo \"\\nCode not formatted correctly.\" && exit 1)",
"lint:clang-tidy": "ts-node ./script/run-clang-tidy.ts",
"lint:cpp": "node ./script/lint.js --cc",
"lint:objc": "node ./script/lint.js --objc",
"lint:py": "node ./script/lint.js --py",
"lint:gn": "node ./script/lint.js --gn",
"lint:docs": "remark docs -qf && npm run lint:js-in-markdown && npm run create-typescript-definitions && npm run lint:ts-check-js-in-markdown && npm run lint:docs-fiddles && npm run lint:docs-relative-links && npm run lint:markdown && npm run lint:api-history",
"lint:docs-fiddles": "standard \"docs/fiddles/**/*.js\"",
"lint:docs-relative-links": "lint-roller-markdown-links --root docs \"**/*.md\"",
"lint:markdown": "node ./script/lint.js --md",
"lint:ts-check-js-in-markdown": "lint-roller-markdown-ts-check --root docs \"**/*.md\" --ignore \"breaking-changes.md\"",
"lint:js-in-markdown": "lint-roller-markdown-standard --root docs \"**/*.md\"",
"lint:api-history": "lint-roller-markdown-api-history --root \"./docs/api/\" --schema \"./docs/api-history.schema.json\" --breaking-changes-file \"./docs/breaking-changes.md\" --check-placement --check-strings \"*.md\"",
"create-api-json": "node script/create-api-json.mjs",
"create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --api=electron-api.json && node spec/ts-smoke/runner.js",
"gn-typescript-definitions": "npm run create-typescript-definitions && shx cp electron.d.ts",
"pre-flight": "pre-flight",
"gn-check": "node ./script/gn-check.js",
"gn-format": "python3 script/run-gn-format.py",
"precommit": "lint-staged",
"preinstall": "node -e 'process.exit(0)'",
"pretest": "npm run create-typescript-definitions",
"prepack": "check-for-leaks",
"repl": "node ./script/start.js --interactive",
"start": "node ./script/start.js",
"test": "node ./script/spec-runner.js",
"tsc": "tsc",
"webpack": "webpack"
},
"license": "MIT",
"author": "Electron Community",
"keywords": [
"electron"
],
"lint-staged": {
"*.{js,ts}": [
"node script/lint.js --js --fix --only --"
],
"*.{js,ts,d.ts}": [
"ts-node script/gen-filenames.ts"
],
"*.{cc,mm,c,h}": [
"python3 script/run-clang-format.py -r -c --fix"
],
"*.md": [
"npm run lint:docs"
],
"*.{gn,gni}": [
"npm run gn-check",
"npm run gn-format"
],
"*.py": [
"node script/lint.js --py --fix --only --"
],
"docs/api/**/*.md": [
"ts-node script/gen-filenames.ts",
"markdownlint-cli2 --config .autofix.markdownlint-cli2.jsonc --fix",
"git add filenames.auto.gni"
],
"{*.patch,.patches}": [
"node script/lint.js --patches --only --",
"ts-node script/check-patch-diff.ts"
],
"DEPS": [
"node script/gen-hunspell-filenames.js",
"node script/gen-libc++-filenames.js"
]
},
"resolutions": {
"nan": "nodejs/nan#e14bdcd1f72d62bca1d541b66da43130384ec213"
}
}
+89
View File
@@ -0,0 +1,89 @@
--- BUILD.gn.orig 2025-01-27 17:37:37 UTC
+++ BUILD.gn
@@ -68,7 +68,7 @@ declare_args() {
root_extra_deps = []
}
-if (is_official_build) {
+if (is_official_build && !is_bsd) {
# An official (maximally optimized!) component (optimized for build times)
# build doesn't make sense and usually doesn't work.
assert(!is_component_build)
@@ -100,7 +100,6 @@ group("gn_all") {
"//codelabs",
"//components:components_unittests",
"//components/gwp_asan:gwp_asan_unittests",
- "//infra/orchestrator:orchestrator_all",
"//net:net_unittests",
"//sandbox:sandbox_unittests",
"//services:services_unittests",
@@ -446,7 +445,7 @@ group("gn_all") {
}
}
- if (is_linux || is_chromeos || is_android) {
+ if ((is_linux && !is_bsd) || is_chromeos || is_android) {
deps += [
"//third_party/breakpad:breakpad_unittests",
"//third_party/breakpad:core-2-minidump",
@@ -636,6 +635,15 @@ group("gn_all") {
}
}
+ if (is_bsd) {
+ deps -= [
+ "//third_party/breakpad:dump_syms($host_system_allocator_toolchain)",
+ "//third_party/breakpad:microdump_stackwalk($host_system_allocator_toolchain)",
+ "//third_party/breakpad:minidump_dump($host_system_allocator_toolchain)",
+ "//third_party/breakpad:minidump_stackwalk($host_system_allocator_toolchain)",
+ ]
+ }
+
if (is_mac) {
deps += [
"//third_party/breakpad:dump_syms($host_system_allocator_toolchain)",
@@ -684,7 +692,7 @@ group("gn_all") {
}
}
- if (!is_fuchsia) {
+ if (!is_fuchsia && !is_bsd) {
# The official builders use this binary from the default toolchain's
# output directory after building in order to upload the symbols of that
# binary. They build the binary like `ninja symupload` which requires the
@@ -1172,7 +1180,7 @@ if (use_blink && !is_cronet_build) {
]
}
- if (!is_chromeos_ash && !is_ios && !is_fuchsia && !is_android && !is_castos) {
+ if (!is_chromeos_ash && !is_ios && !is_fuchsia && !is_android && !is_castos && !is_bsd) {
script_test("chrome_wpt_tests") {
script = "//third_party/blink/tools/run_wpt_tests.py"
args = _common_web_test_options + [ "--product=chrome" ]
@@ -1265,7 +1273,7 @@ if (use_blink && !is_cronet_build) {
data_deps += [ "//content/web_test:web_test_common_mojom_js_data_deps" ]
}
- if (!is_win && !is_android) {
+ if (!is_win && !is_android && !is_bsd) {
# Using the default toolchain for this tool, as it's run during tests not
# during the build. This places a symlink in the root_build_dir for scrips
# to use.
@@ -1279,7 +1287,7 @@ if (use_blink && !is_cronet_build) {
data_deps += [ "//third_party/breakpad:dump_syms" ]
}
- if (is_linux || is_chromeos) {
+ if ((is_linux && !is_bsd) || is_chromeos) {
# Using the default toolchain for this tool, as it's run during tests not
# during the build. This places a symlink in the root_build_dir for scrips
# to use.
@@ -1743,7 +1751,7 @@ group("chromium_builder_perf") {
data_deps += [ "//chrome/test:performance_browser_tests" ]
}
- if (!is_win) {
+ if (!is_win && !is_bsd) {
data_deps += [ "//third_party/breakpad:minidump_stackwalk($host_system_allocator_toolchain)" ]
}
}
@@ -0,0 +1,11 @@
--- apps/ui/views/app_window_frame_view.cc.orig 2024-08-14 20:54:19 UTC
+++ apps/ui/views/app_window_frame_view.cc
@@ -149,7 +149,7 @@ gfx::Rect AppWindowFrameView::GetWindowBoundsForClient
gfx::Rect window_bounds = client_bounds;
// TODO(crbug.com/40118868): Revisit once build flag switch of lacros-chrome is
// complete.
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_BSD)
// Get the difference between the widget's client area bounds and window
// bounds, and grow |window_bounds| by that amount.
gfx::Insets native_frame_insets =
@@ -0,0 +1,14 @@
--- ash/display/mirror_window_controller.cc.orig 2025-01-27 17:37:37 UTC
+++ ash/display/mirror_window_controller.cc
@@ -295,7 +295,11 @@ void MirrorWindowController::UpdateWindow(
if (!base::Contains(display_info_list, iter->first,
&display::ManagedDisplayInfo::id)) {
CloseAndDeleteHost(iter->second, true);
+#if defined(__llvm__)
+ mirroring_host_info_map_.erase(iter++);
+#else
iter = mirroring_host_info_map_.erase(iter);
+#endif
} else {
++iter;
}
+151
View File
@@ -0,0 +1,151 @@
--- base/BUILD.gn.orig 2025-02-02 01:39:07 UTC
+++ base/BUILD.gn
@@ -1078,11 +1078,27 @@ component("base") {
# Needed for <atomic> if using newer C++ library than sysroot, except if
# building inside the cros_sdk environment - use host_toolchain as a
# more robust check for this.
- if (!use_sysroot && (is_android || is_chromeos || (is_linux && !is_castos)) &&
+ if (!use_sysroot && (is_android || is_chromeos || (is_linux && !is_castos && !is_bsd)) &&
host_toolchain != "//build/toolchain/cros:host") {
libs += [ "atomic" ]
}
+ # *BSD needs libkvm
+ if (is_bsd) {
+ libs += [
+ "kvm",
+ "epoll-shim",
+ ]
+ }
+
+ if (is_freebsd) {
+ libs += [
+ "execinfo",
+ "util",
+ "z",
+ ]
+ }
+
if (use_allocator_shim) {
if (is_apple) {
sources += [ "allocator/early_zone_registration_apple.h" ]
@@ -1102,7 +1118,7 @@ component("base") {
# Allow more direct string conversions on platforms with native utf8
# strings
- if (is_apple || is_chromeos || is_castos || is_cast_android || is_fuchsia) {
+ if (is_apple || is_chromeos || is_castos || is_cast_android || is_fuchsia || is_bsd) {
defines += [ "SYSTEM_NATIVE_UTF8" ]
}
@@ -2096,6 +2112,22 @@ component("base") {
]
}
+ if (is_openbsd) {
+ sources += [
+ "process/process_handle_openbsd.cc",
+ "process/process_iterator_openbsd.cc",
+ "process/process_metrics_openbsd.cc",
+ "system/sys_info_openbsd.cc",
+ ]
+ } else if (is_freebsd) {
+ sources += [
+ "process/process_handle_freebsd.cc",
+ "process/process_iterator_freebsd.cc",
+ "process/process_metrics_freebsd.cc",
+ "system/sys_info_freebsd.cc",
+ ]
+ }
+
# iOS
if (is_ios) {
sources += [
@@ -2240,6 +2272,33 @@ component("base") {
}
}
+ if (is_bsd) {
+ sources -= [
+ "files/file_path_watcher_inotify.cc",
+ "files/scoped_file_linux.cc",
+ "process/set_process_title_linux.cc",
+ "process/set_process_title_linux.h",
+ "system/sys_info_linux.cc",
+ "process/process_iterator_linux.cc",
+ "process/process_linux.cc",
+ "process/process_metrics_linux.cc",
+ "process/process_handle_linux.cc",
+ "profiler/stack_copier_signal.cc",
+ "profiler/stack_copier_signal.h",
+ "profiler/thread_delegate_posix.cc",
+ "profiler/thread_delegate_posix.h",
+ "threading/platform_thread_linux.cc",
+ "stack_canary_linux.cc",
+ "stack_canary_linux.h",
+ ]
+ sources += [
+ "files/file_path_watcher_kqueue.cc",
+ "files/file_path_watcher_kqueue.h",
+ "files/file_path_watcher_bsd.cc",
+ "threading/platform_thread_bsd.cc",
+ ]
+ }
+
if (use_blink) {
sources += [
"files/file_path_watcher.cc",
@@ -2595,7 +2654,7 @@ buildflag_header("protected_memory_buildflags") {
header = "protected_memory_buildflags.h"
header_dir = "base/memory"
- protected_memory_enabled = !is_component_build && is_clang &&
+ protected_memory_enabled = !is_openbsd && !is_component_build && is_clang &&
(is_win || is_linux || is_android || is_mac)
flags = [ "PROTECTED_MEMORY_ENABLED=$protected_memory_enabled" ]
@@ -3080,7 +3139,7 @@ if (is_apple) {
}
}
-if (!is_nacl && (is_linux || is_chromeos)) {
+if (!is_nacl && !is_bsd && (is_linux || is_chromeos)) {
# This test must compile with -fstack-protector-all
source_set("stack_canary_linux_unittests") {
testonly = true
@@ -3757,7 +3816,7 @@ test("base_unittests") {
]
}
- if (is_linux || is_chromeos) {
+ if (!is_bsd && (is_linux || is_chromeos)) {
sources += [
"debug/proc_maps_linux_unittest.cc",
"files/scoped_file_linux_unittest.cc",
@@ -3784,7 +3843,7 @@ test("base_unittests") {
"posix/file_descriptor_shuffle_unittest.cc",
"posix/unix_domain_socket_unittest.cc",
]
- if (!is_nacl && !is_apple) {
+ if (!is_nacl && !is_apple && !is_bsd) {
sources += [
"profiler/stack_base_address_posix_unittest.cc",
"profiler/stack_copier_signal_unittest.cc",
@@ -3795,7 +3854,7 @@ test("base_unittests") {
# Allow more direct string conversions on platforms with native utf8
# strings
- if (is_apple || is_chromeos || is_castos || is_cast_android || is_fuchsia) {
+ if (is_apple || is_chromeos || is_castos || is_cast_android || is_fuchsia || is_bsd) {
defines += [ "SYSTEM_NATIVE_UTF8" ]
}
@@ -3985,7 +4044,7 @@ test("base_unittests") {
deps += [ ":base_profiler_test_support_library" ]
}
- if (is_fuchsia || is_linux || is_chromeos) {
+ if ((is_fuchsia || is_linux || is_chromeos) && !is_bsd) {
sources += [
"debug/elf_reader_unittest.cc",
"debug/test_elf_image_builder.cc",
@@ -0,0 +1,11 @@
--- base/allocator/dispatcher/tls.h.orig 2024-06-18 21:43:17 UTC
+++ base/allocator/dispatcher/tls.h
@@ -77,7 +77,7 @@ struct BASE_EXPORT MMapAllocator {
constexpr static size_t AllocationChunkSize = 16384;
#elif BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_64_BITS)
constexpr static size_t AllocationChunkSize = 16384;
-#elif BUILDFLAG(IS_LINUX) && defined(ARCH_CPU_ARM64)
+#elif (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD)) && defined(ARCH_CPU_ARM64)
constexpr static size_t AllocationChunkSize = 16384;
#else
constexpr static size_t AllocationChunkSize = 4096;
@@ -0,0 +1,20 @@
--- base/allocator/partition_allocator/partition_alloc.gni.orig 2025-01-27 17:37:37 UTC
+++ base/allocator/partition_allocator/partition_alloc.gni
@@ -38,7 +38,7 @@ has_memory_tagging =
use_large_empty_slot_span_ring = true
has_memory_tagging =
- current_cpu == "arm64" && is_clang && !is_asan && (is_linux || is_android)
+ current_cpu == "arm64" && is_clang && !is_asan && !is_bsd && (is_linux || is_android)
declare_args() {
# Causes all the allocations to be routed via allocator_shim.cc. Usually,
@@ -432,7 +432,7 @@ is_pkeys_available =
# dependencies that use partition_allocator are compiled in AOSP against a
# version of glibc that does not include pkeys syscall numbers.
is_pkeys_available =
- (is_linux || is_chromeos) && current_cpu == "x64" && !is_cronet_build
+ !is_bsd && (is_linux || is_chromeos) && current_cpu == "x64" && !is_cronet_build
declare_args() {
enable_pkeys = is_pkeys_available
}
@@ -0,0 +1,11 @@
--- base/allocator/partition_allocator/src/partition_alloc/BUILD.gn.orig 2025-01-27 17:37:37 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/BUILD.gn
@@ -863,7 +863,7 @@ if (is_clang_or_gcc) {
configs -= [ partition_alloc_enable_arc_config ]
}
}
- if (is_chromeos || is_linux) {
+ if ((is_chromeos || is_linux) && !is_bsd) {
shim_headers += [
"shim/allocator_shim_override_cpp_symbols.h",
"shim/allocator_shim_override_glibc_weak_symbols.h",
@@ -0,0 +1,20 @@
--- base/allocator/partition_allocator/src/partition_alloc/address_space_randomization.h.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/address_space_randomization.h
@@ -38,7 +38,7 @@ AslrMask(uintptr_t bits) {
#if PA_BUILDFLAG(PA_ARCH_CPU_64_BITS)
- #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
+ #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) && !PA_BUILDFLAG(IS_BSD)
// We shouldn't allocate system pages at all for sanitizer builds. However,
// we do, and if random hint addresses interfere with address ranges
@@ -125,7 +125,7 @@ AslrMask(uintptr_t bits) {
return AslrAddress(0x20000000ULL);
}
#elif PA_BUILDFLAG(PA_ARCH_CPU_ARM64)
- #if PA_BUILDFLAG(IS_LINUX)
+ #if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_BSD)
// Linux on arm64 can use 39, 42, 48, or 52-bit user space, depending on
// page size and number of levels of translation pages used. We use
@@ -0,0 +1,11 @@
--- base/allocator/partition_allocator/src/partition_alloc/page_allocator.h.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/page_allocator.h
@@ -269,7 +269,7 @@ constexpr PA_COMPONENT_EXPORT(
// recommitted. Do not assume that this will not change over time.
constexpr PA_COMPONENT_EXPORT(
PARTITION_ALLOC) bool DecommittedMemoryIsAlwaysZeroed() {
-#if PA_BUILDFLAG(IS_APPLE)
+#if PA_BUILDFLAG(IS_APPLE) || PA_BUILDFLAG(IS_BSD)
return false;
#else
return true;
@@ -0,0 +1,13 @@
--- base/allocator/partition_allocator/src/partition_alloc/page_allocator_constants.h.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/page_allocator_constants.h
@@ -26,8 +26,8 @@
#define PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR __attribute__((const))
#elif (PA_BUILDFLAG(IS_ANDROID) && PA_BUILDFLAG(PA_ARCH_CPU_64_BITS)) || \
- (PA_BUILDFLAG(IS_LINUX) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64)) || \
- (PA_BUILDFLAG(IS_LINUX) && PA_BUILDFLAG(PA_ARCH_CPU_PPC64))
+ ((PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_BSD)) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64)) || \
+ ((PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_BSD)) && PA_BUILDFLAG(PA_ARCH_CPU_PPC64))
// This should work for all POSIX (if needed), but currently all other
// supported OS/architecture combinations use either hard-coded values
// (such as x86) or have means to determine these values without needing
@@ -0,0 +1,11 @@
--- base/allocator/partition_allocator/src/partition_alloc/page_allocator_internals_posix.cc.orig 2025-01-27 17:37:37 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/page_allocator_internals_posix.cc
@@ -39,7 +39,7 @@ uint32_t SecTaskGetCodeSignStatus(SecTaskRef task) API
#if PA_BUILDFLAG(HAS_MEMORY_TAGGING) || \
(defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1) && \
- __has_include(<sys/ifunc.h>))
+ __has_include(<sys/ifunc.h>) && !PA_BUILDFLAG(IS_BSD))
struct __ifunc_arg_t;
#include "partition_alloc/aarch64_support.h"
@@ -0,0 +1,16 @@
--- base/allocator/partition_allocator/src/partition_alloc/page_allocator_internals_posix.h.orig 2025-01-27 17:37:37 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/page_allocator_internals_posix.h
@@ -302,8 +302,12 @@ void DiscardSystemPagesInternal(uintptr_t address, siz
void DiscardSystemPagesInternal(uintptr_t address, size_t length) {
void* ptr = reinterpret_cast<void*>(address);
-#if PA_BUILDFLAG(IS_APPLE)
+#if PA_BUILDFLAG(IS_APPLE) || PA_BUILDFLAG(IS_BSD)
+#if PA_BUILDFLAG(IS_BSD)
+ int ret = madvise(ptr, length, MADV_FREE);
+#else
int ret = madvise(ptr, length, MADV_FREE_REUSABLE);
+#endif
if (ret) {
// MADV_FREE_REUSABLE sometimes fails, so fall back to MADV_DONTNEED.
ret = madvise(ptr, length, MADV_DONTNEED);
@@ -0,0 +1,11 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/proc_maps_linux.cc.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/proc_maps_linux.cc
@@ -19,7 +19,7 @@
#include "partition_alloc/partition_alloc_check.h"
#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS) || \
- PA_BUILDFLAG(IS_ANDROID)
+ PA_BUILDFLAG(IS_ANDROID) || PA_BUILDFLAG(IS_BSD)
#include <inttypes.h>
#endif
@@ -0,0 +1,34 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/stack_trace_posix.cc.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/stack_trace_posix.cc
@@ -13,11 +13,11 @@
#include "partition_alloc/partition_alloc_base/posix/eintr_wrapper.h"
#include "partition_alloc/partition_alloc_base/strings/safe_sprintf.h"
-#if !PA_BUILDFLAG(IS_ANDROID) && !PA_BUILDFLAG(IS_APPLE)
+#if !PA_BUILDFLAG(IS_ANDROID) && !PA_BUILDFLAG(IS_APPLE) && !PA_BUILDFLAG(IS_BSD)
#include <link.h> // For ElfW() macro.
#endif
-#if PA_BUILDFLAG(IS_APPLE)
+#if PA_BUILDFLAG(IS_APPLE) || PA_BUILDFLAG(IS_BSD)
#include <dlfcn.h>
#endif
@@ -25,7 +25,7 @@ namespace {
namespace {
-#if !PA_BUILDFLAG(IS_APPLE)
+#if !PA_BUILDFLAG(IS_APPLE) && !PA_BUILDFLAG(IS_BSD)
// On Android the 'open' function has two versions:
// int open(const char *pathname, int flags);
@@ -369,7 +369,7 @@ void PrintStackTraceInternal(const void** trace, size_
}
#endif // !PA_BUILDFLAG(IS_APPLE)
-#if PA_BUILDFLAG(IS_APPLE)
+#if PA_BUILDFLAG(IS_APPLE) || PA_BUILDFLAG(IS_BSD)
// Since /proc/self/maps is not available, use dladdr() to obtain module
// names and offsets inside the modules from the given addresses.
void PrintStackTraceInternal(const void* const* trace, size_t size) {
@@ -0,0 +1,13 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_posix.cc.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_posix.cc
@@ -102,6 +102,10 @@ void RandBytes(void* output, size_t output_length) {
if (getentropy(output, output_length) == 0) {
return;
}
+#elif PA_BUILDFLAG(IS_BSD)
+ if (getentropy(output, output_length) == 0) {
+ return;
+ }
#endif
// If getrandom(2) above returned with an error and the /dev/urandom fallback
// took place on Linux/ChromeOS bots, they would fail with a CHECK in
@@ -0,0 +1,11 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread.h.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread.h
@@ -37,6 +37,8 @@ typedef mach_port_t PlatformThreadId;
typedef zx_handle_t PlatformThreadId;
#elif PA_BUILDFLAG(IS_APPLE)
typedef mach_port_t PlatformThreadId;
+#elif PA_BUILDFLAG(IS_BSD)
+typedef uint64_t PlatformThreadId;
#elif PA_BUILDFLAG(IS_POSIX)
typedef pid_t PlatformThreadId;
#endif
@@ -0,0 +1,11 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_internal_posix.h.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_internal_posix.h
@@ -10,7 +10,7 @@ namespace partition_alloc::internal::base::internal {
namespace partition_alloc::internal::base::internal {
-#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)
+#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS) || PA_BUILDFLAG(IS_BSD)
// Current thread id is cached in thread local storage for performance reasons.
// In some rare cases it's important to invalidate that cache explicitly (e.g.
// after going through clone() syscall which does not call pthread_atfork()
@@ -0,0 +1,11 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_posix.cc.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_posix.cc
@@ -18,7 +18,7 @@
#include "partition_alloc/partition_alloc_base/logging.h"
#include "partition_alloc/partition_alloc_base/threading/platform_thread_internal_posix.h"
-#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)
+#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS) || PA_BUILDFLAG(IS_BSD)
#include <sys/syscall.h>
#include <atomic>
#endif
@@ -0,0 +1,20 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_alloc_config.h.orig 2025-01-27 17:37:37 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_alloc_config.h
@@ -170,7 +170,7 @@ constexpr bool kUseLazyCommit = false;
// This may be required on more platforms in the future.
#define PA_CONFIG_HAS_ATFORK_HANDLER() \
(PA_BUILDFLAG(IS_APPLE) || PA_BUILDFLAG(IS_LINUX) || \
- PA_BUILDFLAG(IS_CHROMEOS))
+ PA_BUILDFLAG(IS_CHROMEOS) || PA_BUILDFLAG(IS_BSD))
// Enable shadow metadata.
//
@@ -233,7 +233,7 @@ constexpr bool kUseLazyCommit = false;
// Also enabled on ARM64 macOS and iOS, as the 16kiB pages on this platform lead
// to larger slot spans.
#if PA_BUILDFLAG(IS_LINUX) || \
- (PA_BUILDFLAG(IS_APPLE) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64))
+ (PA_BUILDFLAG(IS_APPLE) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64)) || PA_BUILDFLAG(IS_BSD)
#define PA_CONFIG_PREFER_SMALLER_SLOT_SPANS() 1
#else
#define PA_CONFIG_PREFER_SMALLER_SLOT_SPANS() 0
@@ -0,0 +1,20 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_alloc_constants.h.orig 2024-10-16 21:30:44 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_alloc_constants.h
@@ -329,7 +329,7 @@ PA_DEFINE_OPERATORS_FOR_FLAGS(PoolHandleMask);
// 8GB for each of the glued pools).
#if PA_BUILDFLAG(HAS_64_BIT_POINTERS)
#if PA_BUILDFLAG(IS_ANDROID) || PA_BUILDFLAG(IS_IOS) || \
- PA_BUILDFLAG(ENABLE_POINTER_COMPRESSION)
+ PA_BUILDFLAG(ENABLE_POINTER_COMPRESSION) || PA_BUILDFLAG(IS_BSD)
constexpr size_t kPoolMaxSize = 8 * kGiB;
#else
constexpr size_t kPoolMaxSize = 16 * kGiB;
@@ -446,7 +446,7 @@ PA_ALWAYS_INLINE constexpr size_t MaxDirectMapped() {
// TODO(casey.smalley@arm.com): under 64k pages we can end up in a situation
// where a normal slot span will be large enough to contain multiple items,
// but the address will go over the final partition page after being aligned.
-#if PA_BUILDFLAG(IS_LINUX) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64)
+#if (PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_BSD)) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64)
constexpr size_t kMaxSupportedAlignment = kSuperPageSize / 4;
#else
constexpr size_t kMaxSupportedAlignment = kSuperPageSize / 2;
@@ -0,0 +1,16 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_alloc_forward.h.orig 2023-11-29 21:39:39 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_alloc_forward.h
@@ -28,9 +28,13 @@ namespace internal {
// the second one 16. We could technically return something different for
// malloc() and operator new(), but this would complicate things, and most of
// our allocations are presumably coming from operator new() anyway.
+#if defined(__i386__) && defined(OS_FREEBSD)
+constexpr size_t kAlignment = 8;
+#else
constexpr size_t kAlignment =
std::max(alignof(max_align_t),
static_cast<size_t>(__STDCPP_DEFAULT_NEW_ALIGNMENT__));
+#endif
static_assert(kAlignment <= 16,
"PartitionAlloc doesn't support a fundamental alignment larger "
"than 16 bytes.");
@@ -0,0 +1,29 @@
--- base/allocator/partition_allocator/src/partition_alloc/partition_root.cc.orig 2025-01-27 17:37:37 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/partition_root.cc
@@ -44,7 +44,7 @@
#include "wow64apiset.h"
#endif
-#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)
+#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS) || PA_BUILDFLAG(IS_BSD)
#include <pthread.h>
#if PA_CONFIG(ENABLE_SHADOW_METADATA)
#include <sys/mman.h>
@@ -293,7 +293,7 @@ void PartitionAllocMallocInitOnce() {
return;
}
-#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)
+#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS) || PA_BUILDFLAG(IS_BSD)
// When fork() is called, only the current thread continues to execute in the
// child process. If the lock is held, but *not* by this thread when fork() is
// called, we have a deadlock.
@@ -1113,7 +1113,7 @@ void PartitionRoot::Init(PartitionOptions opts) {
// apple OSes.
PA_CHECK((internal::SystemPageSize() == (size_t{1} << 12)) ||
(internal::SystemPageSize() == (size_t{1} << 14)));
-#elif PA_BUILDFLAG(IS_LINUX) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64)
+#elif (PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_BSD)) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64)
// Check runtime pagesize. Though the code is currently the same, it is
// not merged with the IS_APPLE case above as a 1 << 16 case is only
// supported on Linux on AArch64.
@@ -0,0 +1,53 @@
--- base/allocator/partition_allocator/src/partition_alloc/spinning_mutex.cc.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/spinning_mutex.cc
@@ -17,7 +17,16 @@
#endif
#if PA_CONFIG(HAS_LINUX_KERNEL)
+#if defined(OS_OPENBSD)
+#include <sys/time.h>
+#include <sys/futex.h>
+#elif defined(OS_FREEBSD)
+#include <sys/types.h>
+#include <sys/thr.h>
+#include <sys/umtx.h>
+#else
#include <linux/futex.h>
+#endif
#include <sys/syscall.h>
#include <unistd.h>
@@ -106,8 +115,16 @@ void SpinningMutex::FutexWait() {
// |kLockedContended| anymore. Note that even without spurious wakeups, the
// value of |state_| is not guaranteed when this returns, as another thread
// may get the lock before we get to run.
+#if defined(OS_FREEBSD)
+ int err = _umtx_op(&state_, UMTX_OP_WAIT_UINT_PRIVATE,
+ kLockedContended, nullptr, nullptr);
+#elif defined(OS_OPENBSD)
+ int err = futex(reinterpret_cast<volatile unsigned int *>(&state_), FUTEX_WAIT | FUTEX_PRIVATE_FLAG,
+ kLockedContended, nullptr, nullptr);
+#else
int err = syscall(SYS_futex, &state_, FUTEX_WAIT | FUTEX_PRIVATE_FLAG,
kLockedContended, nullptr, nullptr, 0);
+#endif
if (err) {
// These are programming error, check them.
@@ -119,8 +136,16 @@ void SpinningMutex::FutexWake() {
void SpinningMutex::FutexWake() {
int saved_errno = errno;
+#if defined(OS_FREEBSD)
+ long retval = _umtx_op(&state_, UMTX_OP_WAKE_PRIVATE,
+ 1 /* wake up a single waiter */, nullptr, nullptr);
+#elif defined(OS_OPENBSD)
+ long retval = futex(reinterpret_cast<volatile unsigned int *>(&state_), FUTEX_WAKE | FUTEX_PRIVATE_FLAG,
+ 1 /* wake up a single waiter */, nullptr, nullptr);
+#else
long retval = syscall(SYS_futex, &state_, FUTEX_WAKE | FUTEX_PRIVATE_FLAG,
1 /* wake up a single waiter */, nullptr, nullptr, 0);
+#endif
PA_CHECK(retval != -1);
errno = saved_errno;
}
@@ -0,0 +1,50 @@
--- base/allocator/partition_allocator/src/partition_alloc/stack/stack.cc.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/stack/stack.cc
@@ -18,6 +18,10 @@
#include <pthread.h>
#endif
+#if PA_BUILDFLAG(IS_BSD)
+#include <pthread_np.h>
+#endif
+
#if PA_BUILDFLAG(PA_LIBC_GLIBC)
extern "C" void* __libc_stack_end;
#endif
@@ -48,6 +52,36 @@ void* GetStackTop() {
void* GetStackTop() {
return pthread_get_stackaddr_np(pthread_self());
+}
+
+#elif PA_BUILDFLAG(IS_OPENBSD)
+
+void* GetStackTop() {
+ stack_t ss;
+ if (pthread_stackseg_np(pthread_self(), &ss) != 0)
+ return nullptr;
+ return reinterpret_cast<uint8_t*>(ss.ss_sp);
+}
+
+#elif PA_BUILDFLAG(IS_FREEBSD)
+
+void* GetStackTop() {
+ pthread_attr_t attr;
+ int error = pthread_attr_init(&attr);
+ if (error) {
+ return nullptr;
+ }
+ error = pthread_attr_get_np(pthread_self(), &attr);
+ if (!error) {
+ void* base;
+ size_t size;
+ error = pthread_attr_getstack(&attr, &base, &size);
+ PA_CHECK(!error);
+ pthread_attr_destroy(&attr);
+ return reinterpret_cast<uint8_t*>(base) + size;
+ }
+ pthread_attr_destroy(&attr);
+ return nullptr;
}
#elif PA_BUILDFLAG(IS_POSIX) || PA_BUILDFLAG(IS_FUCHSIA)
@@ -0,0 +1,11 @@
--- base/allocator/partition_allocator/src/partition_alloc/thread_isolation/pkey.cc.orig 2024-08-14 20:54:22 UTC
+++ base/allocator/partition_allocator/src/partition_alloc/thread_isolation/pkey.cc
@@ -16,7 +16,7 @@
#include "partition_alloc/partition_alloc_check.h"
#include "partition_alloc/thread_isolation/thread_isolation.h"
-#if !PA_BUILDFLAG(IS_LINUX) && !PA_BUILDFLAG(IS_CHROMEOS)
+#if !PA_BUILDFLAG(IS_LINUX) && !PA_BUILDFLAG(IS_CHROMEOS) && !PA_BUILDFLAG(IS_BSD)
#error "This pkey code is currently only supported on Linux and ChromeOS"
#endif
@@ -0,0 +1,14 @@
--- base/atomicops.h.orig 2023-03-30 00:33:38 UTC
+++ base/atomicops.h
@@ -71,7 +71,11 @@ typedef intptr_t Atomic64;
// Use AtomicWord for a machine-sized pointer. It will use the Atomic32 or
// Atomic64 routines below, depending on your architecture.
+#if !defined(OS_OPENBSD) && defined(__i386__)
+typedef Atomic32 AtomicWord;
+#else
typedef intptr_t AtomicWord;
+#endif
// Atomically execute:
// result = *ptr;
@@ -0,0 +1,108 @@
--- base/base_paths_posix.cc.orig 2024-10-16 21:30:44 UTC
+++ base/base_paths_posix.cc
@@ -15,6 +15,7 @@
#include <ostream>
#include <string>
+#include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@@ -26,9 +27,13 @@
#include "base/process/process_metrics.h"
#include "build/build_config.h"
-#if BUILDFLAG(IS_FREEBSD)
+#if BUILDFLAG(IS_BSD)
#include <sys/param.h>
#include <sys/sysctl.h>
+#if BUILDFLAG(IS_OPENBSD)
+#include <kvm.h>
+#define MAXTOKENS 2
+#endif
#elif BUILDFLAG(IS_SOLARIS) || BUILDFLAG(IS_AIX)
#include <stdlib.h>
#endif
@@ -47,8 +52,7 @@ bool PathProviderPosix(int key, FilePath* result) {
*result = bin_dir;
return true;
#elif BUILDFLAG(IS_FREEBSD)
- int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
- std::optional<std::string> bin_dir = StringSysctl(name, std::size(name));
+ std::optional<std::string> bin_dir = StringSysctl({ CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 });
if (!bin_dir.has_value() || bin_dir.value().length() <= 1) {
NOTREACHED() << "Unable to resolve path.";
}
@@ -62,13 +66,65 @@ bool PathProviderPosix(int key, FilePath* result) {
*result = FilePath(bin_dir);
return true;
#elif BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_AIX)
- // There is currently no way to get the executable path on OpenBSD
- char* cpath;
- if ((cpath = getenv("CHROME_EXE_PATH")) != NULL)
- *result = FilePath(cpath);
- else
- *result = FilePath("/usr/local/chrome/chrome");
- return true;
+ char *cpath;
+#if !BUILDFLAG(IS_AIX)
+ struct kinfo_file *files;
+ kvm_t *kd = NULL;
+ char errbuf[_POSIX2_LINE_MAX];
+ static char retval[PATH_MAX];
+ int cnt;
+ struct stat sb;
+ pid_t cpid = getpid();
+ bool ret = false;
+
+ const base::CommandLine* command_line =
+ base::CommandLine::ForCurrentProcess();
+
+ VLOG(1) << "PathProviderPosix argv: " << command_line->argv()[0];
+
+ if (realpath(command_line->argv()[0].c_str(), retval) == NULL)
+ goto out;
+
+ if (stat(command_line->argv()[0].c_str(), &sb) < 0)
+ goto out;
+
+ if (!command_line->HasSwitch("no-sandbox")) {
+ ret = true;
+ *result = FilePath(retval);
+ VLOG(1) << "PathProviderPosix (sandbox) result: " << retval;
+ goto out;
+ }
+
+ if ((kd = kvm_openfiles(NULL, NULL, NULL, (int)KVM_NO_FILES, errbuf)) == NULL)
+ goto out;
+
+ if ((files = kvm_getfiles(kd, KERN_FILE_BYPID, cpid,
+ sizeof(struct kinfo_file), &cnt)) == NULL)
+ goto out;
+
+ for (int i = 0; i < cnt; i++) {
+ if (files[i].fd_fd == KERN_FILE_TEXT &&
+ files[i].va_fsid == static_cast<uint32_t>(sb.st_dev) &&
+ files[i].va_fileid == sb.st_ino) {
+ ret = true;
+ *result = FilePath(retval);
+ VLOG(1) << "PathProviderPosix result: " << retval;
+ }
+ }
+out:
+ if (kd)
+ kvm_close(kd);
+ if (!ret) {
+#endif
+ if ((cpath = getenv("CHROME_EXE_PATH")) != NULL)
+ *result = FilePath(cpath);
+ else
+ *result = FilePath("/usr/local/chrome/chrome");
+ return true;
+#if !BUILDFLAG(IS_AIX)
+ }
+ return ret;
+#endif
#endif
}
case DIR_SRC_TEST_DATA_ROOT: {
@@ -0,0 +1,10 @@
--- base/compiler_specific.h.orig 2025-01-27 17:37:37 UTC
+++ base/compiler_specific.h
@@ -683,6 +683,7 @@ inline constexpr bool AnalyzerAssumeTrue(bool arg) {
#if __has_cpp_attribute(clang::preserve_most) && \
(defined(ARCH_CPU_ARM64) || defined(ARCH_CPU_X86_64)) && \
!defined(COMPONENT_BUILD) && \
+ !BUILDFLAG(IS_OPENBSD) && \
!(BUILDFLAG(IS_WIN) && defined(ARCH_CPU_ARM64))
#define PRESERVE_MOST [[clang::preserve_most]]
#else
@@ -0,0 +1,69 @@
--- base/debug/debugger_posix.cc.orig 2024-06-18 21:43:17 UTC
+++ base/debug/debugger_posix.cc
@@ -41,6 +41,10 @@
#include <sys/sysctl.h>
#endif
+#if BUILDFLAG(IS_OPENBSD)
+#include <sys/proc.h>
+#endif
+
#if BUILDFLAG(IS_FREEBSD)
#include <sys/user.h>
#endif
@@ -100,32 +104,51 @@ bool BeingDebugged() {
// Caution: struct kinfo_proc is marked __APPLE_API_UNSTABLE. The source and
// binary interfaces may change.
+#if BUILDFLAG(IS_OPENBSD)
+ struct kinfo_proc *info;
+ size_t info_size;
+#else
struct kinfo_proc info;
size_t info_size = sizeof(info);
+#endif
#if BUILDFLAG(IS_OPENBSD)
if (sysctl(mib, std::size(mib), NULL, &info_size, NULL, 0) < 0)
return -1;
- mib[5] = (info_size / sizeof(struct kinfo_proc));
+ mib[5] = static_cast<int>((info_size / sizeof(struct kinfo_proc)));
+ if ((info = reinterpret_cast<kinfo_proc*>(malloc(info_size))) == NULL) {
+ is_set = true;
+ being_debugged = false;
+ return being_debugged;
+ }
+
+ int sysctl_result = sysctl(mib, std::size(mib), info, &info_size, NULL, 0);
#endif
+#if !BUILDFLAG(IS_OPENBSD)
int sysctl_result = sysctl(mib, std::size(mib), &info, &info_size, NULL, 0);
+#endif
DCHECK_EQ(sysctl_result, 0);
if (sysctl_result != 0) {
is_set = true;
being_debugged = false;
- return being_debugged;
+ goto out;
}
// This process is being debugged if the P_TRACED flag is set.
is_set = true;
#if BUILDFLAG(IS_FREEBSD)
being_debugged = (info.ki_flag & P_TRACED) != 0;
-#elif BUILDFLAG(IS_BSD)
- being_debugged = (info.p_flag & P_TRACED) != 0;
+#elif BUILDFLAG(IS_OPENBSD)
+ being_debugged = (info->p_psflags & PS_TRACED) != 0;
#else
being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0;
+#endif
+
+out:
+#if BUILDFLAG(IS_OPENBSD)
+ free(info);
#endif
return being_debugged;
}
@@ -0,0 +1,13 @@
--- base/debug/elf_reader.cc.orig 2024-06-18 21:43:17 UTC
+++ base/debug/elf_reader.cc
@@ -50,6 +50,10 @@ constexpr char kGnuNoteName[] = "GNU";
constexpr char kGnuNoteName[] = "GNU";
+#ifndef NT_GNU_BUILD_ID
+#define NT_GNU_BUILD_ID 3
+#endif
+
// Returns a pointer to the header of the ELF binary mapped into memory, or a
// null pointer if the header is invalid. Here and below |elf_mapped_base| is a
// pointer to the start of the ELF image.
@@ -0,0 +1,11 @@
--- base/debug/proc_maps_linux.cc.orig 2025-01-27 17:37:37 UTC
+++ base/debug/proc_maps_linux.cc
@@ -20,7 +20,7 @@
#include "base/strings/string_split.h"
#include "build/build_config.h"
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
#include <inttypes.h>
#endif
@@ -0,0 +1,29 @@
--- base/debug/stack_trace.cc.orig 2024-10-16 21:30:44 UTC
+++ base/debug/stack_trace.cc
@@ -258,7 +258,7 @@ bool StackTrace::WillSymbolizeToStreamForTesting() {
// Symbols are not expected to be reliable when gn args specifies
// symbol_level=0.
return false;
-#elif defined(__UCLIBC__) || defined(_AIX)
+#elif defined(__UCLIBC__) || defined(_AIX) || BUILDFLAG(IS_BSD)
// StackTrace::OutputToStream() is not implemented under uclibc, nor AIX.
// See https://crbug.com/706728
return false;
@@ -320,7 +320,7 @@ std::string StackTrace::ToStringWithPrefix(cstring_vie
std::string StackTrace::ToStringWithPrefix(cstring_view prefix_string) const {
std::stringstream stream;
-#if !defined(__UCLIBC__) && !defined(_AIX)
+#if !defined(__UCLIBC__) && !defined(_AIX) && !BUILDFLAG(IS_BSD)
OutputToStreamWithPrefix(&stream, prefix_string);
#endif
return stream.str();
@@ -344,7 +344,7 @@ std::ostream& operator<<(std::ostream& os, const Stack
}
std::ostream& operator<<(std::ostream& os, const StackTrace& s) {
-#if !defined(__UCLIBC__) && !defined(_AIX)
+#if !defined(__UCLIBC__) && !defined(_AIX) && !BUILDFLAG(IS_BSD)
s.OutputToStream(&os);
#else
os << "StackTrace::OutputToStream not implemented.";
@@ -0,0 +1,101 @@
--- base/debug/stack_trace_posix.cc.orig 2025-01-27 17:37:37 UTC
+++ base/debug/stack_trace_posix.cc
@@ -46,7 +46,7 @@
// execinfo.h and backtrace(3) are really only present in glibc and in macOS
// libc.
#if BUILDFLAG(IS_APPLE) || \
- (defined(__GLIBC__) && !defined(__UCLIBC__) && !defined(__AIX))
+ (defined(__GLIBC__) && !defined(__UCLIBC__) && !defined(__AIX) && !BUILDFLAG(IS_BSD))
#define HAVE_BACKTRACE
#include <execinfo.h>
#endif
@@ -64,8 +64,10 @@
#include <AvailabilityMacros.h>
#endif
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
+#if !BUILDFLAG(IS_BSD)
#include <sys/prctl.h>
+#endif
#include "base/debug/proc_maps_linux.h"
#endif
@@ -322,7 +324,7 @@ void PrintToStderr(const char* output) {
std::ignore = HANDLE_EINTR(write(STDERR_FILENO, output, strlen(output)));
}
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
void AlarmSignalHandler(int signal, siginfo_t* info, void* void_context) {
// We have seen rare cases on AMD linux where the default signal handler
// either does not run or a thread (Probably an AMD driver thread) prevents
@@ -339,7 +341,11 @@ void AlarmSignalHandler(int signal, siginfo_t* info, v
"Warning: Default signal handler failed to terminate process.\n");
PrintToStderr("Calling exit_group() directly to prevent timeout.\n");
// See: https://man7.org/linux/man-pages/man2/exit_group.2.html
+#if BUILDFLAG(IS_BSD)
+ _exit(EXIT_FAILURE);
+#else
syscall(SYS_exit_group, EXIT_FAILURE);
+#endif
}
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) ||
// BUILDFLAG(IS_CHROMEOS)
@@ -537,7 +543,7 @@ void StackDumpSignalHandler(int signal, siginfo_t* inf
_exit(EXIT_FAILURE);
}
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// Set an alarm to trigger in case the default handler does not terminate
// the process. See 'AlarmSignalHandler' for more details.
struct sigaction action;
@@ -562,6 +568,7 @@ void StackDumpSignalHandler(int signal, siginfo_t* inf
// signals that do not re-raise autonomously), such as signals delivered via
// kill() and asynchronous hardware faults such as SEGV_MTEAERR, which would
// otherwise be lost when re-raising the signal via raise().
+#if !BUILDFLAG(IS_BSD)
long retval = syscall(SYS_rt_tgsigqueueinfo, getpid(), syscall(SYS_gettid),
info->si_signo, info);
if (retval == 0) {
@@ -576,6 +583,7 @@ void StackDumpSignalHandler(int signal, siginfo_t* inf
if (errno != EPERM) {
_exit(EXIT_FAILURE);
}
+#endif
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) ||
// BUILDFLAG(IS_CHROMEOS)
@@ -772,6 +780,7 @@ class SandboxSymbolizeHelper {
return -1;
}
+#if !BUILDFLAG(IS_BSD)
// This class is copied from
// third_party/crashpad/crashpad/util/linux/scoped_pr_set_dumpable.h.
// It aims at ensuring the process is dumpable before opening /proc/self/mem.
@@ -864,11 +873,15 @@ class SandboxSymbolizeHelper {
r.base = cur_base;
}
}
+#endif
// Parses /proc/self/maps in order to compile a list of all object file names
// for the modules that are loaded in the current process.
// Returns true on success.
bool CacheMemoryRegions() {
+#if BUILDFLAG(IS_BSD)
+ return false;
+#else
// Reads /proc/self/maps.
std::string contents;
if (!ReadProcMaps(&contents)) {
@@ -886,6 +899,7 @@ class SandboxSymbolizeHelper {
is_initialized_ = true;
return true;
+#endif
}
// Opens all object files and caches their file descriptors.
@@ -0,0 +1,39 @@
--- base/files/dir_reader_linux.h.orig 2024-06-18 21:43:17 UTC
+++ base/files/dir_reader_linux.h
@@ -21,10 +21,16 @@
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
+#include "build/build_config.h"
+
// See the comments in dir_reader_posix.h about this.
namespace base {
+#if BUILDFLAG(IS_BSD)
+#include <dirent.h>
+typedef struct dirent linux_dirent;
+#else
struct linux_dirent {
uint64_t d_ino;
int64_t d_off;
@@ -32,6 +38,7 @@ struct linux_dirent {
unsigned char d_type;
char d_name[0];
};
+#endif
class DirReaderLinux {
public:
@@ -66,7 +73,11 @@ class DirReaderLinux {
if (offset_ != size_)
return true;
+#if BUILDFLAG(IS_BSD)
+ const int r = getdents(fd_, reinterpret_cast<char *>(buf_), sizeof(buf_));
+#else
const long r = syscall(__NR_getdents64, fd_, buf_, sizeof(buf_));
+#endif
if (r == 0)
return false;
if (r < 0) {
@@ -0,0 +1,20 @@
--- base/files/dir_reader_posix.h.orig 2022-06-17 14:20:10 UTC
+++ base/files/dir_reader_posix.h
@@ -17,7 +17,7 @@
// seems worse than falling back to enumerating all file descriptors so we will
// probably never implement this on the Mac.
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
#include "base/files/dir_reader_linux.h"
#else
#include "base/files/dir_reader_fallback.h"
@@ -25,7 +25,7 @@
namespace base {
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
typedef DirReaderLinux DirReaderPosix;
#else
typedef DirReaderFallback DirReaderPosix;
@@ -0,0 +1,11 @@
--- base/files/drive_info.h.orig 2025-01-27 17:37:37 UTC
+++ base/files/drive_info.h
@@ -40,7 +40,7 @@ class BASE_EXPORT DriveInfo {
std::optional<bool> has_seek_penalty;
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
- BUILDFLAG(IS_CHROMEOS)
+ BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// Whether the drive is a removable drive.
//
// Note on macOS: that SSDs that are connected over USB that you can eject
@@ -0,0 +1,11 @@
--- base/files/drive_info_posix.cc.orig 2025-01-27 17:37:37 UTC
+++ base/files/drive_info_posix.cc
@@ -28,7 +28,7 @@ std::optional<DriveInfo> GetFileDriveInfo(const FilePa
std::optional<DriveInfo> GetFileDriveInfo(const FilePath& file_path) {
DriveInfo drive_info;
-#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA)
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_BSD)
drive_info.has_seek_penalty = false;
return drive_info;
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
@@ -0,0 +1,11 @@
--- base/files/file_path_watcher.h.orig 2024-02-21 00:20:30 UTC
+++ base/files/file_path_watcher.h
@@ -105,7 +105,7 @@ class BASE_EXPORT FilePathWatcher {
Type type = Type::kNonRecursive;
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
- BUILDFLAG(IS_FUCHSIA)
+ BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_BSD)
// The callback will return the full path to a changed file instead of
// the watched path supplied as |path| when Watch is called.
// So the full path can be different from the watched path when a folder is
@@ -0,0 +1,57 @@
--- base/files/file_path_watcher_bsd.cc.orig 2022-10-24 13:33:33 UTC
+++ base/files/file_path_watcher_bsd.cc
@@ -0,0 +1,54 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <memory>
+
+#include "base/files/file_path_watcher.h"
+#include "base/files/file_path_watcher_kqueue.h"
+#include "base/memory/ptr_util.h"
+#include "build/build_config.h"
+
+namespace base {
+
+namespace {
+
+class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate {
+ public:
+ FilePathWatcherImpl() = default;
+ FilePathWatcherImpl(const FilePathWatcherImpl&) = delete;
+ FilePathWatcherImpl& operator=(const FilePathWatcherImpl&) = delete;
+ ~FilePathWatcherImpl() override = default;
+
+ bool Watch(const FilePath& path,
+ Type type,
+ const FilePathWatcher::Callback& callback) override {
+ DCHECK(!impl_.get());
+ if (type == Type::kRecursive) {
+ if (!FilePathWatcher::RecursiveWatchAvailable())
+ return false;
+ } else {
+ impl_ = std::make_unique<FilePathWatcherKQueue>();
+ }
+ DCHECK(impl_.get());
+ return impl_->Watch(path, type, callback);
+ }
+
+ void Cancel() override {
+ if (impl_.get())
+ impl_->Cancel();
+ set_cancelled();
+ }
+
+ private:
+ std::unique_ptr<PlatformDelegate> impl_;
+};
+
+} // namespace
+
+FilePathWatcher::FilePathWatcher() {
+ DETACH_FROM_SEQUENCE(sequence_checker_);
+ impl_ = std::make_unique<FilePathWatcherImpl>();
+}
+
+} // namespace base
@@ -0,0 +1,10 @@
--- base/files/file_path_watcher_kqueue.h.orig 2022-02-07 13:39:41 UTC
+++ base/files/file_path_watcher_kqueue.h
@@ -5,6 +5,7 @@
#ifndef BASE_FILES_FILE_PATH_WATCHER_KQUEUE_H_
#define BASE_FILES_FILE_PATH_WATCHER_KQUEUE_H_
+#include <sys/time.h>
#include <sys/event.h>
#include <memory>
@@ -0,0 +1,29 @@
--- base/files/file_path_watcher_unittest.cc.orig 2024-08-14 20:54:23 UTC
+++ base/files/file_path_watcher_unittest.cc
@@ -902,7 +902,7 @@ TEST_F(FilePathWatcherTest, WatchDirectory) {
}
delegate.RunUntilEventsMatch(event_expecter);
-#if !BUILDFLAG(IS_APPLE)
+#if !BUILDFLAG(IS_APPLE) && BUILDFLAG(IS_BSD)
ASSERT_TRUE(WriteFile(file1, "content v2"));
// Mac implementation does not detect files modified in a directory.
// TODO(crbug.com/40263777): Expect that no events are fired on Mac.
@@ -1848,7 +1848,7 @@ enum Permission { Read, Write, Execute };
enum Permission { Read, Write, Execute };
-#if BUILDFLAG(IS_APPLE)
+#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_BSD)
bool ChangeFilePermissions(const FilePath& path, Permission perm, bool allow) {
struct stat stat_buf;
@@ -1882,7 +1882,7 @@ bool ChangeFilePermissions(const FilePath& path, Permi
} // namespace
-#if BUILDFLAG(IS_APPLE)
+#if BUILDFLAG(IS_APPLE) && BUILDFLAG(IS_BSD)
// Linux implementation of FilePathWatcher doesn't catch attribute changes.
// http://crbug.com/78043
// Windows implementation of FilePathWatcher catches attribute changes that
@@ -0,0 +1,55 @@
--- base/files/file_util_posix.cc.orig 2025-01-27 17:37:37 UTC
+++ base/files/file_util_posix.cc
@@ -897,36 +897,33 @@ bool CreateDirectoryAndGetError(const FilePath& full_p
bool CreateDirectoryAndGetError(const FilePath& full_path, File::Error* error) {
ScopedBlockingCall scoped_blocking_call(
FROM_HERE, BlockingType::MAY_BLOCK); // For call to mkdir().
+ const FilePath kFileSystemRoot("/");
std::vector<FilePath> subpaths;
// Collect a list of all parent directories.
FilePath last_path = full_path;
- subpaths.push_back(full_path);
- for (FilePath path = full_path.DirName(); path.value() != last_path.value();
- path = path.DirName()) {
+ if (full_path != kFileSystemRoot)
+ subpaths.push_back(full_path);
+ for (FilePath path = full_path.DirName(); (path.value() != last_path.value() &&
+ (path != kFileSystemRoot)); path = path.DirName()) {
subpaths.push_back(path);
last_path = path;
}
// Iterate through the parents and create the missing ones.
for (const FilePath& subpath : base::Reversed(subpaths)) {
- if (DirectoryExists(subpath)) {
- continue;
- }
- if (mkdir(subpath.value().c_str(), 0700) == 0) {
- continue;
- }
- // Mkdir failed, but it might have failed with EEXIST, or some other error
- // due to the directory appearing out of thin air. This can occur if
- // two processes are trying to create the same file system tree at the same
- // time. Check to see if it exists and make sure it is a directory.
- int saved_errno = errno;
- if (!DirectoryExists(subpath)) {
- if (error) {
- *error = File::OSErrorToFileError(saved_errno);
+ if (!PathExists(subpath)) {
+ if ((mkdir(subpath.value().c_str(), 0700) == -1) &&
+ ((full_path != subpath) ? (errno != ENOENT) : (-1))) {
+ int saved_errno = errno;
+ if (error)
+ *error = File::OSErrorToFileError(saved_errno);
+ return false;
}
- errno = saved_errno;
- return false;
+ } else if (!DirectoryExists(subpath)) {
+ if (error)
+ *error = File::OSErrorToFileError(ENOTDIR);
+ return false;
}
}
return true;
@@ -0,0 +1,20 @@
--- base/files/file_util_unittest.cc.orig 2025-01-27 17:37:37 UTC
+++ base/files/file_util_unittest.cc
@@ -3908,7 +3908,7 @@ TEST_F(FileUtilTest, ReadFileToStringWithNamedPipe) {
}
#endif // BUILDFLAG(IS_WIN)
-#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)
+#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_BSD)
TEST_F(FileUtilTest, ReadFileToStringWithProcFileSystem) {
FilePath file_path("/proc/cpuinfo");
std::string data = "temp";
@@ -4645,7 +4645,7 @@ TEST(FileUtilMultiThreadedTest, MultiThreadedTempFiles
NULL);
#else
size_t bytes_written =
- ::write(::fileno(output_file.get()), content.c_str(), content.length());
+ ::write(fileno(output_file.get()), content.c_str(), content.length());
#endif
EXPECT_EQ(content.length(), bytes_written);
::fflush(output_file.get());
@@ -0,0 +1,12 @@
--- base/files/important_file_writer_cleaner.cc.orig 2022-02-28 16:54:41 UTC
+++ base/files/important_file_writer_cleaner.cc
@@ -25,7 +25,8 @@ namespace base {
namespace {
base::Time GetUpperBoundTime() {
-#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS) || BUILDFLAG(IS_FUCHSIA)
+// needed because of .CreationTime() pledge
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_BSD)
// If process creation time is not available then use instance creation
// time as the upper-bound for old files. Modification times may be
// rounded-down to coarse-grained increments, e.g. FAT has 2s granularity,
@@ -0,0 +1,11 @@
--- base/files/scoped_file.cc.orig 2024-08-14 20:54:23 UTC
+++ base/files/scoped_file.cc
@@ -32,7 +32,7 @@ void ScopedFDCloseTraits::Free(int fd) {
int ret = IGNORE_EINTR(close(fd));
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_APPLE) || \
- BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_ANDROID)
+ BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
// NB: Some file descriptors can return errors from close() e.g. network
// filesystems such as NFS and Linux input devices. On Linux, macOS, and
// Fuchsia's POSIX layer, errors from close other than EBADF do not indicate
@@ -0,0 +1,11 @@
--- base/functional/unretained_traits.h.orig 2024-04-15 20:33:42 UTC
+++ base/functional/unretained_traits.h
@@ -93,7 +93,7 @@ struct SupportsUnretainedImpl {
// official builds, and then in non-test code as well.
#if defined(FORCE_UNRETAINED_COMPLETENESS_CHECKS_FOR_TESTS) || \
(!defined(UNIT_TEST) && !defined(OFFICIAL_BUILD) && \
- (BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)))
+ (BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_BSD)))
static_assert(v,
"Argument requires unretained storage, but type is not "
"fully defined. This prevents determining whether "
@@ -0,0 +1,20 @@
--- base/i18n/icu_util.cc.orig 2024-04-15 20:33:42 UTC
+++ base/i18n/icu_util.cc
@@ -52,7 +52,7 @@
#include "third_party/icu/source/common/unicode/unistr.h"
#endif
-#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) || \
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_BSD) || \
BUILDFLAG(IS_CHROMEOS) || (BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CASTOS))
#include "third_party/icu/source/i18n/unicode/timezone.h"
#endif
@@ -328,7 +328,7 @@ void InitializeIcuTimeZone() {
FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdForIcuInitialization();
icu::TimeZone::adoptDefault(
icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(zone_id)));
-#elif BUILDFLAG(IS_CHROMEOS) || (BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CASTOS))
+#elif BUILDFLAG(IS_CHROMEOS) || (BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CASTOS)) || BUILDFLAG(IS_BSD)
// To respond to the time zone change properly, the default time zone
// cache in ICU has to be populated on starting up.
// See TimeZoneMonitorLinux::NotifyClientsFromImpl().
@@ -0,0 +1,17 @@
--- base/linux_util.cc.orig 2025-01-27 17:37:37 UTC
+++ base/linux_util.cc
@@ -154,10 +154,14 @@ bool GetThreadsForProcess(pid_t pid, std::vector<pid_t
}
bool GetThreadsForProcess(pid_t pid, std::vector<pid_t>* tids) {
+#if BUILDFLAG(IS_BSD)
+ return false;
+#else
// 25 > strlen("/proc//task") + strlen(base::NumberToString(INT_MAX)) + 1 = 22
char buf[25];
strings::SafeSPrintf(buf, "/proc/%d/task", pid);
return GetThreadsFromProcessDir(buf, tids);
+#endif
}
bool GetThreadsForCurrentProcess(std::vector<pid_t>* tids) {
@@ -0,0 +1,31 @@
--- base/logging_unittest.cc.orig 2025-01-27 17:37:37 UTC
+++ base/logging_unittest.cc
@@ -41,7 +41,7 @@
#include "base/posix/eintr_wrapper.h"
#endif // BUILDFLAG(IS_POSIX)
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FREEBSD)
#include <ucontext.h>
#endif
@@ -585,14 +585,18 @@ void CheckCrashTestSighandler(int, siginfo_t* info, vo
// need the arch-specific boilerplate below, which is inspired by breakpad.
// At the same time, on OSX, ucontext.h is deprecated but si_addr works fine.
uintptr_t crash_addr = 0;
-#if BUILDFLAG(IS_MAC)
+#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_FREEBSD)
crash_addr = reinterpret_cast<uintptr_t>(info->si_addr);
#else // OS_*
ucontext_t* context = reinterpret_cast<ucontext_t*>(context_ptr);
#if defined(ARCH_CPU_X86)
crash_addr = static_cast<uintptr_t>(context->uc_mcontext.gregs[REG_EIP]);
#elif defined(ARCH_CPU_X86_64)
+#if BUILDFLAG(IS_OPENBSD)
+ crash_addr = static_cast<uintptr_t>(context->sc_rip);
+#else
crash_addr = static_cast<uintptr_t>(context->uc_mcontext.gregs[REG_RIP]);
+#endif
#elif defined(ARCH_CPU_ARMEL)
crash_addr = static_cast<uintptr_t>(context->uc_mcontext.arm_pc);
#elif defined(ARCH_CPU_ARM64)
@@ -0,0 +1,38 @@
--- base/memory/discardable_memory.cc.orig 2024-10-16 21:30:44 UTC
+++ base/memory/discardable_memory.cc
@@ -26,7 +26,7 @@ BASE_FEATURE(kMadvFreeDiscardableMemory,
base::FEATURE_DISABLED_BY_DEFAULT);
#endif // BUILDFLAG(IS_POSIX)
-#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
BASE_FEATURE(kDiscardableMemoryBackingTrial,
"DiscardableMemoryBackingTrial",
base::FEATURE_DISABLED_BY_DEFAULT);
@@ -39,7 +39,7 @@ namespace {
namespace {
-#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
DiscardableMemoryBacking GetBackingForFieldTrial() {
DiscardableMemoryTrialGroup trial_group =
@@ -58,7 +58,7 @@ DiscardableMemoryBacking GetBackingForFieldTrial() {
} // namespace
-#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// Probe capabilities of this device to determine whether we should participate
// in the discardable memory backing trial.
@@ -88,7 +88,7 @@ DiscardableMemoryBacking GetDiscardableMemoryBacking()
DiscardableMemory::~DiscardableMemory() = default;
DiscardableMemoryBacking GetDiscardableMemoryBacking() {
-#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
if (DiscardableMemoryBackingFieldTrialIsEnabled()) {
return GetBackingForFieldTrial();
}
@@ -0,0 +1,11 @@
--- base/memory/discardable_memory_internal.h.orig 2024-10-16 21:30:44 UTC
+++ base/memory/discardable_memory_internal.h
@@ -12,7 +12,7 @@
#include "base/metrics/field_trial_params.h"
#include "build/build_config.h"
-#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
namespace base {
@@ -0,0 +1,21 @@
--- base/memory/madv_free_discardable_memory_posix.cc.orig 2024-10-16 21:30:44 UTC
+++ base/memory/madv_free_discardable_memory_posix.cc
@@ -310,6 +310,10 @@ bool MadvFreeDiscardableMemoryPosix::IsResident() cons
bool MadvFreeDiscardableMemoryPosix::IsResident() const {
DFAKE_SCOPED_RECURSIVE_LOCK(thread_collision_warner_);
+// XXX mincore
+#if BUILDFLAG(IS_BSD)
+ return false;
+#else
#if BUILDFLAG(IS_APPLE)
std::vector<char> vec(allocated_pages_);
#else
@@ -325,6 +329,7 @@ bool MadvFreeDiscardableMemoryPosix::IsResident() cons
return false;
}
return true;
+#endif
}
bool MadvFreeDiscardableMemoryPosix::IsDiscarded() const {
@@ -0,0 +1,29 @@
--- base/memory/platform_shared_memory_region.h.orig 2025-01-27 17:37:37 UTC
+++ base/memory/platform_shared_memory_region.h
@@ -18,7 +18,7 @@
#include "base/unguessable_token.h"
#include "build/build_config.h"
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
namespace content {
class SandboxIPCHandler;
}
@@ -85,7 +85,7 @@ class BASE_EXPORT PlatformSharedMemoryRegion {
kMaxValue = GET_SHMEM_TEMP_DIR_FAILURE
};
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// Structure to limit access to executable region creation.
struct ExecutableRegion {
private:
@@ -217,7 +217,7 @@ class BASE_EXPORT PlatformSharedMemoryRegion {
CheckPlatformHandlePermissionsCorrespondToMode);
static PlatformSharedMemoryRegion Create(Mode mode,
size_t size
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
,
bool executable = false
#endif
@@ -0,0 +1,29 @@
--- base/memory/platform_shared_memory_region_posix.cc.orig 2023-02-01 18:43:07 UTC
+++ base/memory/platform_shared_memory_region_posix.cc
@@ -55,7 +55,7 @@ bool CheckFDAccessMode(int fd, int expected_mode) {
} // namespace
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// static
ScopedFD PlatformSharedMemoryRegion::ExecutableRegion::CreateFD(size_t size) {
PlatformSharedMemoryRegion region =
@@ -168,7 +168,7 @@ bool PlatformSharedMemoryRegion::ConvertToUnsafe() {
// static
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Create(Mode mode,
size_t size
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
,
bool executable
#endif
@@ -197,7 +197,7 @@ PlatformSharedMemoryRegion PlatformSharedMemoryRegion:
// flag.
FilePath directory;
if (!GetShmemTempDir(
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
executable,
#else
false /* executable */,
@@ -0,0 +1,44 @@
--- base/memory/protected_memory.h.orig 2025-01-27 17:37:37 UTC
+++ base/memory/protected_memory.h
@@ -120,12 +120,12 @@ __declspec(selectany) char __stop_protected_memory;
#define DECLARE_PROTECTED_DATA constinit
#define DEFINE_PROTECTED_DATA constinit __declspec(allocate("prot$mem"))
-#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
+#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
// This value is used to align the writers variable. That variable needs to be
// aligned to ensure that the protected memory section starts on a page
// boundary.
#if (PA_BUILDFLAG(IS_ANDROID) && PA_BUILDFLAG(PA_ARCH_CPU_64_BITS)) || \
- (PA_BUILDFLAG(IS_LINUX) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64))
+ ((PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_BSD)) && PA_BUILDFLAG(PA_ARCH_CPU_ARM64))
// arm64 supports 4kb, 16kb, and 64kb pages. Set to the largest of 64kb as that
// will guarantee the section is page aligned regardless of the choice.
inline constexpr int kProtectedMemoryAlignment = 65536;
@@ -340,7 +340,7 @@ class BASE_EXPORT AutoWritableMemoryBase {
// where an attacker could overwrite it with a large value and invoke code
// that constructs and destructs an AutoWritableMemory. After such a call
// protected memory would still be set writable because writers > 0.
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
// On Linux, the protected memory section is not automatically page aligned.
// This means that attempts to reset the protected memory region to readonly
// will set some of the preceding section that is on the same page readonly
@@ -354,7 +354,7 @@ class BASE_EXPORT AutoWritableMemoryBase {
#endif
static inline size_t writers GUARDED_BY(writers_lock()) = 0;
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
// On Linux, there is no guarantee the section following the protected
// memory section is page aligned. This can result in attempts to change
// the access permissions of the end of the protected memory section
@@ -412,7 +412,7 @@ class BASE_EXPORT AutoWritableMemoryInitializer
// the variable to something large before the section was read-only.
WriterData::writers = 0;
CHECK(SetProtectedSectionReadOnly());
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
// Set the protected_memory_section_buffer to true to ensure the buffer
// section is created. If a variable is declared but not used the memory
// section won't be created.
@@ -0,0 +1,20 @@
--- base/memory/protected_memory_posix.cc.orig 2024-10-16 21:30:44 UTC
+++ base/memory/protected_memory_posix.cc
@@ -6,7 +6,7 @@
#include <sys/mman.h>
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
#include <sys/resource.h>
#endif // BUILDFLAG(IS_LINUX)
@@ -34,7 +34,7 @@ namespace internal {
} // namespace
namespace internal {
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
void CheckMemoryReadOnly(const void* ptr) {
const uintptr_t page_start =
bits::AlignDown(reinterpret_cast<uintptr_t>(ptr), GetPageSize());
@@ -0,0 +1,11 @@
--- base/message_loop/message_pump_epoll.cc.orig 2024-10-16 21:30:44 UTC
+++ base/message_loop/message_pump_epoll.cc
@@ -42,7 +42,7 @@ constexpr std::pair<uint32_t, short int> kEpollToPollE
std::atomic_bool g_use_poll = false;
constexpr std::pair<uint32_t, short int> kEpollToPollEvents[] = {
- {EPOLLIN, POLLIN}, {EPOLLOUT, POLLOUT}, {EPOLLRDHUP, POLLRDHUP},
+ {EPOLLIN, POLLIN}, {EPOLLOUT, POLLOUT},
{EPOLLPRI, POLLPRI}, {EPOLLERR, POLLERR}, {EPOLLHUP, POLLHUP}};
void SetEventsForPoll(const uint32_t epoll_events, struct pollfd* poll_entry) {
@@ -0,0 +1,14 @@
--- base/message_loop/message_pump_epoll.h.orig 2024-10-16 21:30:44 UTC
+++ base/message_loop/message_pump_epoll.h
@@ -51,7 +51,11 @@ BASE_FEATURE(kUsePollForMessagePumpEpoll,
// every call, don't do it when we have too many FDs.
BASE_FEATURE(kUsePollForMessagePumpEpoll,
"UsePollForMessagePumpEpoll",
+#if BUILDFLAG(IS_BSD)
+ base::FEATURE_ENABLED_BY_DEFAULT);
+#else
base::FEATURE_DISABLED_BY_DEFAULT);
+#endif
// A MessagePump implementation suitable for I/O message loops on Linux-based
// systems with epoll API support.
@@ -0,0 +1,28 @@
--- base/message_loop/message_pump_glib.cc.orig 2022-08-31 12:19:35 UTC
+++ base/message_loop/message_pump_glib.cc
@@ -8,6 +8,11 @@
#include <glib.h>
#include <math.h>
+#if BUILDFLAG(IS_BSD)
+#include <pthread.h>
+#include <pthread_np.h>
+#endif
+
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
@@ -51,9 +56,13 @@ int GetTimeIntervalMilliseconds(TimeTicks next_task_ti
}
bool RunningOnMainThread() {
+#if BUILDFLAG(IS_BSD)
+ return pthread_main_np();
+#else
auto pid = getpid();
auto tid = PlatformThread::CurrentId();
return pid > 0 && tid > 0 && pid == tid;
+#endif
}
// A brief refresher on GLib:
@@ -0,0 +1,11 @@
--- base/native_library_posix.cc.orig 2024-08-14 20:54:23 UTC
+++ base/native_library_posix.cc
@@ -34,7 +34,7 @@ NativeLibrary LoadNativeLibraryWithOptions(const FileP
// http://crbug.com/17943, http://crbug.com/17557, http://crbug.com/36892,
// and http://crbug.com/40794.
int flags = RTLD_LAZY;
-#if BUILDFLAG(IS_ANDROID) || !defined(RTLD_DEEPBIND)
+#if BUILDFLAG(IS_ANDROID) || !defined(RTLD_DEEPBIND) || BUILDFLAG(IS_BSD)
// Certain platforms don't define RTLD_DEEPBIND. Android dlopen() requires
// further investigation, as it might vary across versions. Crash here to
// warn developers that they're trying to rely on uncertain behavior.
@@ -0,0 +1,11 @@
--- base/native_library_unittest.cc.orig 2024-10-16 21:30:44 UTC
+++ base/native_library_unittest.cc
@@ -135,7 +135,7 @@ TEST(NativeLibraryTest, LoadLibrary) {
// versions with respect to symbol resolution scope.
// TSan and MSan error out on RTLD_DEEPBIND, https://crbug.com/705255
#if !BUILDFLAG(IS_ANDROID) && !defined(THREAD_SANITIZER) && \
- !defined(MEMORY_SANITIZER)
+ !defined(MEMORY_SANITIZER) && !BUILDFLAG(IS_BSD)
// Verifies that the |prefer_own_symbols| option satisfies its guarantee that
// a loaded library will always prefer local symbol resolution before
@@ -0,0 +1,16 @@
--- base/posix/can_lower_nice_to.cc.orig 2022-02-28 16:54:41 UTC
+++ base/posix/can_lower_nice_to.cc
@@ -11,8 +11,12 @@
#include "build/build_config.h"
+#if BUILDFLAG(IS_FREEBSD)
+#include <sys/param.h>
+#endif
+
// Not defined on AIX by default.
-#if BUILDFLAG(IS_AIX)
+#if BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
#if defined(RLIMIT_NICE)
#error Assumption about OS_AIX is incorrect
#endif
@@ -0,0 +1,11 @@
--- base/posix/file_descriptor_shuffle.h.orig 2024-10-16 21:30:44 UTC
+++ base/posix/file_descriptor_shuffle.h
@@ -26,6 +26,8 @@
#include "base/base_export.h"
#include "base/compiler_specific.h"
+#undef close
+
namespace base {
// A Delegate which performs the actions required to perform an injective
@@ -0,0 +1,10 @@
--- base/posix/sysctl.cc.orig 2023-11-29 21:39:40 UTC
+++ base/posix/sysctl.cc
@@ -4,6 +4,7 @@
#include "base/posix/sysctl.h"
+#include <sys/types.h>
#include <sys/sysctl.h>
#include <initializer_list>
@@ -0,0 +1,57 @@
--- base/posix/unix_domain_socket.cc.orig 2024-06-18 21:43:17 UTC
+++ base/posix/unix_domain_socket.cc
@@ -56,7 +56,7 @@ bool UnixDomainSocket::EnableReceiveProcessId(int fd)
// static
bool UnixDomainSocket::EnableReceiveProcessId(int fd) {
-#if !BUILDFLAG(IS_APPLE)
+#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_BSD)
const int enable = 1;
return setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &enable, sizeof(enable)) == 0;
#else
@@ -82,7 +82,7 @@ bool UnixDomainSocket::SendMsg(int fd,
struct cmsghdr* cmsg;
msg.msg_control = control_buffer;
-#if BUILDFLAG(IS_APPLE)
+#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_BSD)
msg.msg_controllen = checked_cast<socklen_t>(control_len);
#else
msg.msg_controllen = control_len;
@@ -90,7 +90,7 @@ bool UnixDomainSocket::SendMsg(int fd,
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
-#if BUILDFLAG(IS_APPLE)
+#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_BSD)
cmsg->cmsg_len = checked_cast<u_int>(CMSG_LEN(sizeof(int) * fds.size()));
#else
cmsg->cmsg_len = CMSG_LEN(sizeof(int) * fds.size());
@@ -154,7 +154,7 @@ ssize_t UnixDomainSocket::RecvMsgWithFlags(int fd,
const size_t kControlBufferSize =
CMSG_SPACE(sizeof(int) * kMaxFileDescriptors)
-#if !BUILDFLAG(IS_APPLE)
+#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_BSD)
// macOS does not support ucred.
// macOS supports xucred, but this structure is insufficient.
+ CMSG_SPACE(sizeof(struct ucred))
@@ -182,7 +182,7 @@ ssize_t UnixDomainSocket::RecvMsgWithFlags(int fd,
wire_fds = reinterpret_cast<int*>(CMSG_DATA(cmsg));
wire_fds_len = payload_len / sizeof(int);
}
-#if !BUILDFLAG(IS_APPLE)
+#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_BSD)
// macOS does not support SCM_CREDENTIALS.
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_CREDENTIALS) {
@@ -216,6 +216,9 @@ ssize_t UnixDomainSocket::RecvMsgWithFlags(int fd,
socklen_t pid_size = sizeof(pid);
if (getsockopt(fd, SOL_LOCAL, LOCAL_PEERPID, &pid, &pid_size) != 0)
pid = -1;
+#elif BUILDFLAG(IS_BSD)
+ NOTIMPLEMENTED();
+ pid = -1;
#else
// |pid| will legitimately be -1 if we read EOF, so only DCHECK if we
// actually received a message. Unfortunately, Linux allows sending zero
@@ -0,0 +1,11 @@
--- base/posix/unix_domain_socket_unittest.cc.orig 2024-06-18 21:43:17 UTC
+++ base/posix/unix_domain_socket_unittest.cc
@@ -15,6 +15,8 @@
#include <sys/types.h>
#include <unistd.h>
+#include <signal.h>
+
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/functional/bind.h"
@@ -0,0 +1,20 @@
--- base/process/internal_linux.h.orig 2024-06-18 21:43:17 UTC
+++ base/process/internal_linux.h
@@ -140,6 +140,9 @@ void ForEachProcessTask(base::ProcessHandle process, L
// arguments to the lambda.
template <typename Lambda>
void ForEachProcessTask(base::ProcessHandle process, Lambda&& lambda) {
+#if BUILDFLAG(IS_BSD)
+ return;
+#else
// Iterate through the different threads tracked in /proc/<pid>/task.
FilePath fd_path = GetProcPidDir(process).Append("task");
@@ -159,6 +162,7 @@ void ForEachProcessTask(base::ProcessHandle process, L
FilePath task_path = fd_path.Append(tid_str);
lambda(tid, task_path);
}
+#endif
}
} // namespace internal
@@ -0,0 +1,11 @@
--- base/process/kill.h.orig 2024-06-18 21:43:17 UTC
+++ base/process/kill.h
@@ -123,7 +123,7 @@ BASE_EXPORT TerminationStatus GetKnownDeadTerminationS
BASE_EXPORT TerminationStatus GetKnownDeadTerminationStatus(
ProcessHandle handle, int* exit_code);
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// Spawns a thread to wait asynchronously for the child |process| to exit
// and then reaps it.
BASE_EXPORT void EnsureProcessGetsReaped(Process process);
@@ -0,0 +1,11 @@
--- base/process/kill_posix.cc.orig 2023-03-30 00:33:38 UTC
+++ base/process/kill_posix.cc
@@ -157,7 +157,7 @@ void EnsureProcessTerminated(Process process) {
0, new BackgroundReaper(std::move(process), Seconds(2)));
}
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
void EnsureProcessGetsReaped(Process process) {
DCHECK(!process.is_current());
@@ -0,0 +1,11 @@
--- base/process/launch.h.orig 2025-01-27 17:37:37 UTC
+++ base/process/launch.h
@@ -241,7 +241,7 @@ struct BASE_EXPORT LaunchOptions {
bool clear_environment = false;
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// If non-zero, start the process using clone(), using flags as provided.
// Unlike in clone, clone_flags may not contain a custom termination signal
// that is sent to the parent when the child dies. The termination signal will
@@ -0,0 +1,12 @@
--- base/process/launch_posix.cc.orig 2024-10-16 21:30:44 UTC
+++ base/process/launch_posix.cc
@@ -67,6 +67,9 @@
#error "macOS should use launch_mac.cc"
#endif
+#if defined(OS_FREEBSD)
+#pragma weak environ
+#endif
extern char** environ;
namespace base {
@@ -0,0 +1,44 @@
--- base/process/memory_linux.cc.orig 2024-08-14 20:54:23 UTC
+++ base/process/memory_linux.cc
@@ -28,6 +28,7 @@ namespace base {
namespace base {
+#if !BUILDFLAG(IS_BSD)
namespace {
void ReleaseReservationOrTerminate() {
@@ -37,12 +38,14 @@ void ReleaseReservationOrTerminate() {
}
} // namespace
+#endif
void EnableTerminationOnHeapCorruption() {
// On Linux, there nothing to do AFAIK.
}
void EnableTerminationOnOutOfMemory() {
+#if !BUILDFLAG(IS_BSD)
// Set the new-out of memory handler.
std::set_new_handler(&ReleaseReservationOrTerminate);
// If we're using glibc's allocator, the above functions will override
@@ -51,8 +54,10 @@ void EnableTerminationOnOutOfMemory() {
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
allocator_shim::SetCallNewHandlerOnMallocFailure(true);
#endif
+#endif
}
+#if !BUILDFLAG(IS_BSD)
// ScopedAllowBlocking() has private constructor and it can only be used in
// friend classes/functions. Declaring a class is easier in this situation to
// avoid adding more dependency to thread_restrictions.h because of the
@@ -110,6 +115,7 @@ bool AdjustOOMScore(ProcessId process, int score) {
bool AdjustOOMScore(ProcessId process, int score) {
return AdjustOOMScoreHelper::AdjustOOMScore(process, score);
}
+#endif
bool UncheckedMalloc(size_t size, void** result) {
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
@@ -0,0 +1,11 @@
--- base/process/process_handle.cc.orig 2022-02-28 16:54:41 UTC
+++ base/process/process_handle.cc
@@ -30,7 +30,7 @@ UniqueProcId GetUniqueIdForProcess() {
: UniqueProcId(GetCurrentProcId());
}
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
void InitUniqueIdForProcessInPidNamespace(ProcessId pid_outside_of_namespace) {
DCHECK(pid_outside_of_namespace != kNullProcessId);
@@ -0,0 +1,11 @@
--- base/process/process_handle.h.orig 2024-02-21 00:20:30 UTC
+++ base/process/process_handle.h
@@ -86,7 +86,7 @@ BASE_EXPORT UniqueProcId GetUniqueIdForProcess();
// processes may be reused.
BASE_EXPORT UniqueProcId GetUniqueIdForProcess();
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// When a process is started in a different PID namespace from the browser
// process, this function must be called with the process's PID in the browser's
// PID namespace in order to initialize its unique ID. Not thread safe.
@@ -0,0 +1,25 @@
--- base/process/process_handle_freebsd.cc.orig 2024-04-15 20:33:42 UTC
+++ base/process/process_handle_freebsd.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/process/process_handle.h"
+#include "base/files/file_util.h"
#include <limits.h>
#include <stddef.h>
@@ -20,10 +21,13 @@ ProcessId GetParentProcessId(ProcessHandle process) {
ProcessId GetParentProcessId(ProcessHandle process) {
struct kinfo_proc info;
- size_t length;
+ size_t length = sizeof(struct kinfo_proc);
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process };
if (sysctl(mib, std::size(mib), &info, &length, NULL, 0) < 0)
+ return -1;
+
+ if (length < sizeof(struct kinfo_proc))
return -1;
return info.ki_ppid;
@@ -0,0 +1,133 @@
--- base/process/process_handle_openbsd.cc.orig 2024-04-15 20:33:42 UTC
+++ base/process/process_handle_openbsd.cc
@@ -3,48 +3,112 @@
// found in the LICENSE file.
#include "base/process/process_handle.h"
+#include "base/files/file_util.h"
#include <stddef.h>
+#include <stdlib.h>
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <unistd.h>
+#include <kvm.h>
+
namespace base {
ProcessId GetParentProcessId(ProcessHandle process) {
- struct kinfo_proc info;
+ struct kinfo_proc *info;
size_t length;
+ pid_t ppid;
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process,
sizeof(struct kinfo_proc), 0 };
if (sysctl(mib, std::size(mib), NULL, &length, NULL, 0) < 0)
return -1;
- mib[5] = (length / sizeof(struct kinfo_proc));
+ info = (struct kinfo_proc *)malloc(length);
- if (sysctl(mib, std::size(mib), &info, &length, NULL, 0) < 0)
- return -1;
+ mib[5] = static_cast<int>((length / sizeof(struct kinfo_proc)));
- return info.p_ppid;
+ if (sysctl(mib, std::size(mib), info, &length, NULL, 0) < 0) {
+ ppid = -1;
+ goto out;
+ }
+
+ ppid = info->p_ppid;
+
+out:
+ free(info);
+ return ppid;
}
FilePath GetProcessExecutablePath(ProcessHandle process) {
- struct kinfo_proc kp;
+ struct kinfo_file *files;
+ kvm_t *kd = NULL;
+ char errbuf[_POSIX2_LINE_MAX];
+ char **retvalargs, *cpath, retval[PATH_MAX];
+ int cnt;
size_t len;
- int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process,
- sizeof(struct kinfo_proc), 0 };
+ char *tokens[2];
+ struct stat sb;
+ FilePath result;
- if (sysctl(mib, std::size(mib), NULL, &len, NULL, 0) == -1)
- return FilePath();
- mib[5] = (len / sizeof(struct kinfo_proc));
- if (sysctl(mib, std::size(mib), &kp, &len, NULL, 0) < 0)
- return FilePath();
- if ((kp.p_flag & P_SYSTEM) != 0)
- return FilePath();
- if (strcmp(kp.p_comm, "chrome") == 0)
- return FilePath(kp.p_comm);
+ int mib[] = { CTL_KERN, KERN_PROC_ARGS, process, KERN_PROC_ARGV };
- return FilePath();
+ if ((cpath = getenv("CHROME_EXE_PATH")) != NULL)
+ result = FilePath(cpath);
+ else
+ result = FilePath("/usr/local/chrome/chrome");
+
+ if (sysctl(mib, std::size(mib), NULL, &len, NULL, 0) != -1) {
+ retvalargs = static_cast<char**>(malloc(len));
+ if (!retvalargs)
+ return result;
+
+ if (sysctl(mib, std::size(mib), retvalargs, &len, NULL, 0) < 0) {
+ free(retvalargs);
+ return result;
+ }
+
+ if ((*tokens = strtok(retvalargs[0], ":")) == NULL) {
+ free(retvalargs);
+ return result;
+ }
+
+ free(retvalargs);
+
+ if (tokens[0] == NULL)
+ return result;
+
+ if (realpath(tokens[0], retval) == NULL)
+ return result;
+
+ if (stat(retval, &sb) < 0)
+ return result;
+
+ if ((kd = kvm_openfiles(NULL, NULL, NULL, (int)KVM_NO_FILES,
+ errbuf)) == NULL)
+ return result;
+
+ if ((files = kvm_getfiles(kd, KERN_FILE_BYPID, process,
+ sizeof(struct kinfo_file), &cnt)) == NULL) {
+ kvm_close(kd);
+ return result;
+ }
+
+ for (int i = 0; i < cnt; i++) {
+ if (files[i].fd_fd == KERN_FILE_TEXT &&
+ files[i].va_fsid == static_cast<uint32_t>(sb.st_dev) &&
+ files[i].va_fileid == sb.st_ino) {
+ kvm_close(kd);
+ result = FilePath(retval);
+ }
+ }
+ }
+
+ return result;
}
} // namespace base
@@ -0,0 +1,51 @@
--- base/process/process_iterator_freebsd.cc.orig 2023-03-30 00:33:38 UTC
+++ base/process/process_iterator_freebsd.cc
@@ -18,7 +18,7 @@ namespace base {
ProcessIterator::ProcessIterator(const ProcessFilter* filter)
: filter_(filter) {
- int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid() };
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, (int) getuid() };
bool done = false;
int try_num = 1;
@@ -37,7 +37,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter*
num_of_kinfo_proc += 16;
kinfo_procs_.resize(num_of_kinfo_proc);
len = num_of_kinfo_proc * sizeof(struct kinfo_proc);
- if (sysctl(mib, std::size(mib), &kinfo_procs_[0], &len, NULL, 0) < 0) {
+ if (sysctl(mib, std::size(mib), kinfo_procs_.data(), &len, NULL, 0) < 0) {
// If we get a mem error, it just means we need a bigger buffer, so
// loop around again. Anything else is a real error and give up.
if (errno != ENOMEM) {
@@ -47,7 +47,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter*
}
} else {
// Got the list, just make sure we're sized exactly right
- size_t num_of_kinfo_proc = len / sizeof(struct kinfo_proc);
+ num_of_kinfo_proc = len / sizeof(struct kinfo_proc);
kinfo_procs_.resize(num_of_kinfo_proc);
done = true;
}
@@ -68,18 +68,13 @@ bool ProcessIterator::CheckForNextProcess() {
for (; index_of_kinfo_proc_ < kinfo_procs_.size(); ++index_of_kinfo_proc_) {
size_t length;
struct kinfo_proc kinfo = kinfo_procs_[index_of_kinfo_proc_];
- int mib[] = { CTL_KERN, KERN_PROC_ARGS, kinfo.ki_pid };
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, kinfo.ki_pid };
if ((kinfo.ki_pid > 0) && (kinfo.ki_stat == SZOMB))
continue;
- length = 0;
- if (sysctl(mib, std::size(mib), NULL, &length, NULL, 0) < 0) {
- LOG(ERROR) << "failed to figure out the buffer size for a command line";
- continue;
- }
-
- data.resize(length);
+ data.resize(ARG_MAX);
+ length = ARG_MAX;
if (sysctl(mib, std::size(mib), &data[0], &length, NULL, 0) < 0) {
LOG(ERROR) << "failed to fetch a commandline";
@@ -0,0 +1,45 @@
--- base/process/process_iterator_openbsd.cc.orig 2023-03-30 00:33:38 UTC
+++ base/process/process_iterator_openbsd.cc
@@ -6,6 +6,9 @@
#include <errno.h>
#include <stddef.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/proc.h>
#include <sys/sysctl.h>
#include "base/logging.h"
@@ -16,12 +19,13 @@ namespace base {
ProcessIterator::ProcessIterator(const ProcessFilter* filter)
: filter_(filter) {
- int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid(),
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, static_cast<int>(getuid()),
sizeof(struct kinfo_proc), 0 };
bool done = false;
int try_num = 1;
const int max_tries = 10;
+ size_t num_of_kinfo_proc;
do {
size_t len = 0;
@@ -30,7 +34,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter*
kinfo_procs_.resize(0);
done = true;
} else {
- size_t num_of_kinfo_proc = len / sizeof(struct kinfo_proc);
+ num_of_kinfo_proc = len / sizeof(struct kinfo_proc);
// Leave some spare room for process table growth (more could show up
// between when we check and now)
num_of_kinfo_proc += 16;
@@ -46,7 +50,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter*
}
} else {
// Got the list, just make sure we're sized exactly right
- size_t num_of_kinfo_proc = len / sizeof(struct kinfo_proc);
+ num_of_kinfo_proc = len / sizeof(struct kinfo_proc);
kinfo_procs_.resize(num_of_kinfo_proc);
done = true;
}
@@ -0,0 +1,49 @@
--- base/process/process_metrics.cc.orig 2024-06-18 21:43:17 UTC
+++ base/process/process_metrics.cc
@@ -17,7 +17,7 @@ namespace {
namespace {
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
- BUILDFLAG(IS_AIX)
+ BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
int CalculateEventsPerSecond(uint64_t event_count,
uint64_t* last_event_count,
base::TimeTicks* last_calculated) {
@@ -54,7 +54,7 @@ SystemMetrics SystemMetrics::Sample() {
SystemMetrics system_metrics;
system_metrics.committed_memory_ = GetSystemCommitCharge();
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
GetSystemMemoryInfo(&system_metrics.memory_info_);
GetVmStatInfo(&system_metrics.vmstat_info_);
GetSystemDiskInfo(&system_metrics.disk_info_);
@@ -73,7 +73,7 @@ Value::Dict SystemMetrics::ToDict() const {
Value::Dict res;
res.Set("committed_memory", static_cast<int>(committed_memory_));
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
Value::Dict meminfo = memory_info_.ToDict();
meminfo.Merge(vmstat_info_.ToDict());
res.Set("meminfo", std::move(meminfo));
@@ -100,7 +100,6 @@ std::unique_ptr<ProcessMetrics> ProcessMetrics::Create
#endif // !BUILDFLAG(IS_MAC)
}
-#if !BUILDFLAG(IS_FREEBSD) || !BUILDFLAG(IS_POSIX)
double ProcessMetrics::GetPlatformIndependentCPUUsage(
TimeDelta cumulative_cpu) {
TimeTicks time = TimeTicks::Now();
@@ -129,10 +128,9 @@ ProcessMetrics::GetPlatformIndependentCPUUsage() {
return GetPlatformIndependentCPUUsage(cpu_usage);
});
}
-#endif
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
- BUILDFLAG(IS_AIX)
+ BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
int ProcessMetrics::CalculateIdleWakeupsPerSecond(
uint64_t absolute_idle_wakeups) {
return CalculateEventsPerSecond(absolute_idle_wakeups,
@@ -0,0 +1,115 @@
--- base/process/process_metrics.h.orig 2024-10-16 21:30:44 UTC
+++ base/process/process_metrics.h
@@ -38,7 +38,7 @@
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
- BUILDFLAG(IS_AIX)
+ BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
#include <string>
#include <utility>
#include <vector>
@@ -48,7 +48,7 @@ namespace base {
namespace base {
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
// Minor and major page fault counts since the process creation.
// Both counts are process-wide, and exclude child processes.
//
@@ -113,7 +113,7 @@ class BASE_EXPORT ProcessMetrics {
// convenience wrapper for CreateProcessMetrics().
static std::unique_ptr<ProcessMetrics> CreateCurrentProcessMetrics();
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
// Resident Set Size is a Linux/Android specific memory concept. Do not
// attempt to extend this to other platforms.
BASE_EXPORT size_t GetResidentSetSize() const;
@@ -147,7 +147,7 @@ class BASE_EXPORT ProcessMetrics {
base::expected<TimeDelta, ProcessCPUUsageError> GetCumulativeCPUUsage();
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
- BUILDFLAG(IS_AIX)
+ BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
// Emits the cumulative CPU usage for all currently active threads since they
// were started into the output parameter (replacing its current contents).
// Threads that have already terminated will not be reported. Thus, the sum of
@@ -192,7 +192,7 @@ class BASE_EXPORT ProcessMetrics {
int GetOpenFdSoftLimit() const;
#endif // BUILDFLAG(IS_POSIX)
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
// Bytes of swap as reported by /proc/[pid]/status.
uint64_t GetVmSwapBytes() const;
@@ -213,7 +213,7 @@ class BASE_EXPORT ProcessMetrics {
#endif // !BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
- BUILDFLAG(IS_AIX)
+ BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
int CalculateIdleWakeupsPerSecond(uint64_t absolute_idle_wakeups);
#endif
#if BUILDFLAG(IS_APPLE)
@@ -235,12 +235,10 @@ class BASE_EXPORT ProcessMetrics {
// Used to store the previous times and CPU usage counts so we can
// compute the CPU usage between calls.
TimeTicks last_cpu_time_;
-#if !BUILDFLAG(IS_FREEBSD) || !BUILDFLAG(IS_POSIX)
TimeDelta last_cumulative_cpu_;
-#endif
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
- BUILDFLAG(IS_AIX)
+ BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
// Same thing for idle wakeups.
TimeTicks last_idle_wakeups_time_;
uint64_t last_absolute_idle_wakeups_;
@@ -281,7 +279,7 @@ BASE_EXPORT void IncreaseFdLimitTo(unsigned int max_de
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_AIX) || \
- BUILDFLAG(IS_FUCHSIA)
+ BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_BSD)
// Data about system-wide memory consumption. Values are in KB. Available on
// Windows, Mac, Linux, Android and Chrome OS.
//
@@ -316,7 +314,7 @@ struct BASE_EXPORT SystemMemoryInfoKB {
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
- BUILDFLAG(IS_AIX)
+ BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
// This provides an estimate of available memory as described here:
// https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
// NOTE: this is ONLY valid in kernels 3.14 and up. Its value will always
@@ -331,7 +329,7 @@ struct BASE_EXPORT SystemMemoryInfoKB {
#endif
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
- BUILDFLAG(IS_AIX) || BUILDFLAG(IS_FUCHSIA)
+ BUILDFLAG(IS_AIX) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_BSD)
int buffers = 0;
int cached = 0;
int active_anon = 0;
@@ -368,7 +366,7 @@ BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoK
// BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
- BUILDFLAG(IS_AIX)
+ BUILDFLAG(IS_AIX) || BUILDFLAG(IS_BSD)
// Parse the data found in /proc/<pid>/stat and return the sum of the
// CPU-related ticks. Returns -1 on parse error.
// Exposed for testing.
@@ -563,7 +561,7 @@ class BASE_EXPORT SystemMetrics {
FRIEND_TEST_ALL_PREFIXES(SystemMetricsTest, SystemMetrics);
size_t committed_memory_;
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_BSD)
SystemMemoryInfoKB memory_info_;
VmStatInfo vmstat_info_;
SystemDiskInfo disk_info_;
@@ -0,0 +1,306 @@
--- base/process/process_metrics_freebsd.cc.orig 2024-10-16 21:30:44 UTC
+++ base/process/process_metrics_freebsd.cc
@@ -3,43 +3,58 @@
// found in the LICENSE file.
#include "base/process/process_metrics.h"
+#include "base/notreached.h"
#include <stddef.h>
+#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#include <unistd.h>
+#include <fcntl.h> /* O_RDONLY */
+#include <kvm.h>
+#include <libutil.h>
+
#include "base/memory/ptr_util.h"
+#include "base/values.h"
namespace base {
+namespace {
+int GetPageShift() {
+ int pagesize = getpagesize();
+ int pageshift = 0;
-ProcessMetrics::ProcessMetrics(ProcessHandle process)
- : process_(process),
- last_cpu_(0) {}
+ while (pagesize > 1) {
+ pageshift++;
+ pagesize >>= 1;
+ }
+ return pageshift;
+}
+}
+
+ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process) {}
+
// static
std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
ProcessHandle process) {
return WrapUnique(new ProcessMetrics(process));
}
-base::expected<double, ProcessCPUUsageError>
-ProcessMetrics::GetPlatformIndependentCPUUsage() {
+base::expected<TimeDelta, ProcessCPUUsageError>
+ProcessMetrics::GetCumulativeCPUUsage() {
struct kinfo_proc info;
- int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, process_};
- size_t length = sizeof(info);
+ size_t length = sizeof(struct kinfo_proc);
+ struct timeval tv;
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_ };
+
if (sysctl(mib, std::size(mib), &info, &length, NULL, 0) < 0)
- return base::unexpected(ProcessCPUUsageError::kSystemError);
+ return base::ok(TimeDelta());
- return base::ok(double{info.ki_pctcpu} / FSCALE * 100.0);
+ return base::ok(Microseconds(info.ki_runtime));
}
-base::expected<TimeDelta, ProcessCPUUsageError>
-ProcessMetrics::GetCumulativeCPUUsage() {
- NOTREACHED();
-}
-
size_t GetSystemCommitCharge() {
int mib[2], pagesize;
unsigned long mem_total, mem_free, mem_inactive;
@@ -61,6 +76,230 @@ size_t GetSystemCommitCharge() {
pagesize = getpagesize();
return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize);
+}
+
+int64_t GetNumberOfThreads(ProcessHandle process) {
+ // Taken from FreeBSD top (usr.bin/top/machine.c)
+
+ kvm_t* kd = kvm_open(NULL, "/dev/null", NULL, O_RDONLY, "kvm_open");
+ if (kd == NULL)
+ return 0;
+
+ struct kinfo_proc* pbase;
+ int nproc;
+ pbase = kvm_getprocs(kd, KERN_PROC_PID, process, &nproc);
+ if (pbase == NULL)
+ return 0;
+
+ if (kvm_close(kd) == -1)
+ return 0;
+
+ return nproc;
+}
+
+bool GetSystemMemoryInfo(SystemMemoryInfoKB *meminfo) {
+ unsigned int mem_total, mem_free, swap_total, swap_used;
+ size_t length;
+ int pagesizeKB;
+
+ pagesizeKB = getpagesize() / 1024;
+
+ length = sizeof(mem_total);
+ if (sysctlbyname("vm.stats.vm.v_page_count", &mem_total,
+ &length, NULL, 0) != 0 || length != sizeof(mem_total))
+ return false;
+
+ length = sizeof(mem_free);
+ if (sysctlbyname("vm.stats.vm.v_free_count", &mem_free, &length, NULL, 0)
+ != 0 || length != sizeof(mem_free))
+ return false;
+
+ length = sizeof(swap_total);
+ if (sysctlbyname("vm.swap_size", &swap_total, &length, NULL, 0)
+ != 0 || length != sizeof(swap_total))
+ return false;
+
+ length = sizeof(swap_used);
+ if (sysctlbyname("vm.swap_anon_use", &swap_used, &length, NULL, 0)
+ != 0 || length != sizeof(swap_used))
+ return false;
+
+ meminfo->total = mem_total * pagesizeKB;
+ meminfo->free = mem_free * pagesizeKB;
+ meminfo->swap_total = swap_total * pagesizeKB;
+ meminfo->swap_free = (swap_total - swap_used) * pagesizeKB;
+
+ return true;
+}
+
+int ProcessMetrics::GetOpenFdCount() const {
+ struct kinfo_file * kif;
+ int cnt;
+
+ if ((kif = kinfo_getfile(process_, &cnt)) == NULL)
+ return -1;
+
+ free(kif);
+
+ return cnt;
+}
+
+int ProcessMetrics::GetOpenFdSoftLimit() const {
+ size_t length;
+ int total_count = 0;
+ int mib[] = { CTL_KERN, KERN_MAXFILESPERPROC };
+
+ length = sizeof(total_count);
+
+ if (sysctl(mib, std::size(mib), &total_count, &length, NULL, 0) < 0) {
+ total_count = -1;
+ }
+
+ return total_count;
+}
+
+size_t ProcessMetrics::GetResidentSetSize() const {
+ kvm_t *kd = kvm_open(nullptr, "/dev/null", nullptr, O_RDONLY, "kvm_open");
+
+ if (kd == nullptr)
+ return 0;
+
+ struct kinfo_proc *pp;
+ int nproc;
+
+ if ((pp = kvm_getprocs(kd, KERN_PROC_PID, process_, &nproc)) == nullptr) {
+ kvm_close(kd);
+ return 0;
+ }
+
+ size_t rss;
+
+ if (nproc > 0) {
+ rss = pp->ki_rssize << GetPageShift();
+ } else {
+ rss = 0;
+ }
+
+ kvm_close(kd);
+ return rss;
+}
+
+uint64_t ProcessMetrics::GetVmSwapBytes() const {
+ kvm_t *kd = kvm_open(nullptr, "/dev/null", nullptr, O_RDONLY, "kvm_open");
+
+ if (kd == nullptr)
+ return 0;
+
+ struct kinfo_proc *pp;
+ int nproc;
+
+ if ((pp = kvm_getprocs(kd, KERN_PROC_PID, process_, &nproc)) == nullptr) {
+ kvm_close(kd);
+ return 0;
+ }
+
+ size_t swrss;
+
+ if (nproc > 0) {
+ swrss = pp->ki_swrss > pp->ki_rssize
+ ? (pp->ki_swrss - pp->ki_rssize) << GetPageShift()
+ : 0;
+ } else {
+ swrss = 0;
+ }
+
+ kvm_close(kd);
+ return swrss;
+}
+
+int ProcessMetrics::GetIdleWakeupsPerSecond() {
+ NOTIMPLEMENTED();
+ return 0;
+}
+
+bool GetSystemDiskInfo(SystemDiskInfo* diskinfo) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool GetVmStatInfo(VmStatInfo* vmstat) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+SystemDiskInfo::SystemDiskInfo() {
+ reads = 0;
+ reads_merged = 0;
+ sectors_read = 0;
+ read_time = 0;
+ writes = 0;
+ writes_merged = 0;
+ sectors_written = 0;
+ write_time = 0;
+ io = 0;
+ io_time = 0;
+ weighted_io_time = 0;
+}
+
+SystemDiskInfo::SystemDiskInfo(const SystemDiskInfo& other) = default;
+
+SystemDiskInfo& SystemDiskInfo::operator=(const SystemDiskInfo&) = default;
+
+Value::Dict SystemDiskInfo::ToDict() const {
+ Value::Dict res;
+
+ // Write out uint64_t variables as doubles.
+ // Note: this may discard some precision, but for JS there's no other option.
+ res.Set("reads", static_cast<double>(reads));
+ res.Set("reads_merged", static_cast<double>(reads_merged));
+ res.Set("sectors_read", static_cast<double>(sectors_read));
+ res.Set("read_time", static_cast<double>(read_time));
+ res.Set("writes", static_cast<double>(writes));
+ res.Set("writes_merged", static_cast<double>(writes_merged));
+ res.Set("sectors_written", static_cast<double>(sectors_written));
+ res.Set("write_time", static_cast<double>(write_time));
+ res.Set("io", static_cast<double>(io));
+ res.Set("io_time", static_cast<double>(io_time));
+ res.Set("weighted_io_time", static_cast<double>(weighted_io_time));
+
+ NOTIMPLEMENTED();
+
+ return res;
+}
+
+Value::Dict SystemMemoryInfoKB::ToDict() const {
+ Value::Dict res;
+ res.Set("total", total);
+ res.Set("free", free);
+ res.Set("available", available);
+ res.Set("buffers", buffers);
+ res.Set("cached", cached);
+ res.Set("active_anon", active_anon);
+ res.Set("inactive_anon", inactive_anon);
+ res.Set("active_file", active_file);
+ res.Set("inactive_file", inactive_file);
+ res.Set("swap_total", swap_total);
+ res.Set("swap_free", swap_free);
+ res.Set("swap_used", swap_total - swap_free);
+ res.Set("dirty", dirty);
+ res.Set("reclaimable", reclaimable);
+
+ NOTIMPLEMENTED();
+
+ return res;
+}
+
+Value::Dict VmStatInfo::ToDict() const {
+ Value::Dict res;
+ // TODO(crbug.com/1334256): Make base::Value able to hold uint64_t and remove
+ // casts below.
+ res.Set("pswpin", static_cast<int>(pswpin));
+ res.Set("pswpout", static_cast<int>(pswpout));
+ res.Set("pgmajfault", static_cast<int>(pgmajfault));
+
+ NOTIMPLEMENTED();
+
+ return res;
}
} // namespace base
@@ -0,0 +1,233 @@
--- base/process/process_metrics_openbsd.cc.orig 2024-10-16 21:30:44 UTC
+++ base/process/process_metrics_openbsd.cc
@@ -6,74 +6,50 @@
#include <stddef.h>
#include <stdint.h>
+#include <fcntl.h>
#include <sys/param.h>
#include <sys/sysctl.h>
+#include <sys/vmmeter.h>
+#include <kvm.h>
+
#include "base/memory/ptr_util.h"
#include "base/types/expected.h"
+#include "base/values.h"
+#include "base/notreached.h"
namespace base {
-namespace {
+ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process) {}
-base::expected<int, ProcessCPUUsageError> GetProcessCPU(pid_t pid) {
+base::expected<TimeDelta, ProcessCPUUsageError>
+ProcessMetrics::GetCumulativeCPUUsage() {
struct kinfo_proc info;
- size_t length;
- int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid,
- sizeof(struct kinfo_proc), 0 };
+ size_t length = sizeof(struct kinfo_proc);
+ struct timeval tv;
- if (sysctl(mib, std::size(mib), NULL, &length, NULL, 0) < 0) {
- return base::unexpected(ProcessCPUUsageError::kSystemError);
- }
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_,
+ sizeof(struct kinfo_proc), 1 };
- mib[5] = (length / sizeof(struct kinfo_proc));
-
if (sysctl(mib, std::size(mib), &info, &length, NULL, 0) < 0) {
return base::unexpected(ProcessCPUUsageError::kSystemError);
}
- return base::ok(info.p_pctcpu);
+ tv.tv_sec = info.p_rtime_sec;
+ tv.tv_usec = info.p_rtime_usec;
+
+ return base::ok(Microseconds(TimeValToMicroseconds(tv)));
}
-} // namespace
-
// static
std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
ProcessHandle process) {
return WrapUnique(new ProcessMetrics(process));
}
-base::expected<double, ProcessCPUUsageError>
-ProcessMetrics::GetPlatformIndependentCPUUsage() {
- TimeTicks time = TimeTicks::Now();
-
- if (last_cpu_time_.is_zero()) {
- // First call, just set the last values.
- last_cpu_time_ = time;
- return base::ok(0.0);
- }
-
- const base::expected<int, ProcessCPUUsageError> cpu = GetProcessCPU(process_);
- if (!cpu.has_value()) {
- return base::unexpected(cpu.error());
- }
-
- last_cpu_time_ = time;
- return base::ok(double{cpu.value()} / FSCALE * 100.0);
-}
-
-base::expected<TimeDelta, ProcessCPUUsageError>
-ProcessMetrics::GetCumulativeCPUUsage() {
- NOTREACHED();
-}
-
-ProcessMetrics::ProcessMetrics(ProcessHandle process)
- : process_(process),
- last_cpu_(0) {}
-
size_t GetSystemCommitCharge() {
int mib[] = { CTL_VM, VM_METER };
- int pagesize;
+ size_t pagesize;
struct vmtotal vmtotal;
unsigned long mem_total, mem_free, mem_inactive;
size_t len = sizeof(vmtotal);
@@ -85,9 +61,136 @@ size_t GetSystemCommitCharge() {
mem_free = vmtotal.t_free;
mem_inactive = vmtotal.t_vm - vmtotal.t_avm;
- pagesize = getpagesize();
+ pagesize = checked_cast<size_t>(getpagesize());
return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize);
+}
+
+int ProcessMetrics::GetOpenFdCount() const {
+#if 0
+ struct kinfo_file *files;
+ kvm_t *kd = NULL;
+ int total_count = 0;
+ char errbuf[_POSIX2_LINE_MAX];
+
+ if ((kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL)
+ goto out;
+
+ if ((files = kvm_getfiles(kd, KERN_FILE_BYPID, process_,
+ sizeof(struct kinfo_file), &total_count)) == NULL) {
+ total_count = 0;
+ goto out;
+ }
+
+ kvm_close(kd);
+
+out:
+ return total_count;
+#endif
+ return getdtablecount();
+}
+
+int ProcessMetrics::GetOpenFdSoftLimit() const {
+ return getdtablesize();
+// return GetMaxFds();
+}
+
+uint64_t ProcessMetrics::GetVmSwapBytes() const {
+ NOTIMPLEMENTED();
+ return 0;
+}
+
+bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
+ NOTIMPLEMENTED_LOG_ONCE();
+ return false;
+}
+
+bool GetSystemDiskInfo(SystemDiskInfo* diskinfo) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool GetVmStatInfo(VmStatInfo* vmstat) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+int ProcessMetrics::GetIdleWakeupsPerSecond() {
+ NOTIMPLEMENTED();
+ return 0;
+}
+
+Value::Dict SystemMemoryInfoKB::ToDict() const {
+ Value::Dict res;
+ res.Set("total", total);
+ res.Set("free", free);
+ res.Set("available", available);
+ res.Set("buffers", buffers);
+ res.Set("cached", cached);
+ res.Set("active_anon", active_anon);
+ res.Set("inactive_anon", inactive_anon);
+ res.Set("active_file", active_file);
+ res.Set("inactive_file", inactive_file);
+ res.Set("swap_total", swap_total);
+ res.Set("swap_free", swap_free);
+ res.Set("swap_used", swap_total - swap_free);
+ res.Set("dirty", dirty);
+ res.Set("reclaimable", reclaimable);
+
+ NOTIMPLEMENTED();
+
+ return res;
+}
+
+Value::Dict VmStatInfo::ToDict() const {
+ Value::Dict res;
+ res.Set("pswpin", static_cast<int>(pswpin));
+ res.Set("pswpout", static_cast<int>(pswpout));
+ res.Set("pgmajfault", static_cast<int>(pgmajfault));
+
+ NOTIMPLEMENTED();
+
+ return res;
+}
+
+SystemDiskInfo::SystemDiskInfo() {
+ reads = 0;
+ reads_merged = 0;
+ sectors_read = 0;
+ read_time = 0;
+ writes = 0;
+ writes_merged = 0;
+ sectors_written = 0;
+ write_time = 0;
+ io = 0;
+ io_time = 0;
+ weighted_io_time = 0;
+}
+
+SystemDiskInfo::SystemDiskInfo(const SystemDiskInfo&) = default;
+
+SystemDiskInfo& SystemDiskInfo::operator=(const SystemDiskInfo&) = default;
+
+Value::Dict SystemDiskInfo::ToDict() const {
+ Value::Dict res;
+
+ // Write out uint64_t variables as doubles.
+ // Note: this may discard some precision, but for JS there's no other option.
+ res.Set("reads", static_cast<double>(reads));
+ res.Set("reads_merged", static_cast<double>(reads_merged));
+ res.Set("sectors_read", static_cast<double>(sectors_read));
+ res.Set("read_time", static_cast<double>(read_time));
+ res.Set("writes", static_cast<double>(writes));
+ res.Set("writes_merged", static_cast<double>(writes_merged));
+ res.Set("sectors_written", static_cast<double>(sectors_written));
+ res.Set("write_time", static_cast<double>(write_time));
+ res.Set("io", static_cast<double>(io));
+ res.Set("io_time", static_cast<double>(io_time));
+ res.Set("weighted_io_time", static_cast<double>(weighted_io_time));
+
+ NOTIMPLEMENTED();
+
+ return res;
}
} // namespace base
@@ -0,0 +1,20 @@
--- base/process/process_metrics_posix.cc.orig 2023-08-10 01:48:31 UTC
+++ base/process/process_metrics_posix.cc
@@ -21,6 +21,8 @@
#if BUILDFLAG(IS_APPLE)
#include <malloc/malloc.h>
+#elif BUILDFLAG(IS_OPENBSD)
+#include <stdlib.h>
#else
#include <malloc.h>
#endif
@@ -134,7 +136,7 @@ size_t ProcessMetrics::GetMallocUsage() {
return stats.size_in_use;
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
return GetMallocUsageMallinfo();
-#elif BUILDFLAG(IS_FUCHSIA)
+#elif BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_BSD)
// TODO(fuchsia): Not currently exposed. https://crbug.com/735087.
return 0;
#endif
@@ -0,0 +1,12 @@
--- base/process/process_metrics_unittest.cc.orig 2024-06-18 21:43:17 UTC
+++ base/process/process_metrics_unittest.cc
@@ -62,7 +62,8 @@
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_WIN) || \
- BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_APPLE)
+ BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_APPLE) || \
+ BUILDFLAG(IS_BSD)
#define ENABLE_CPU_TESTS 1
#else
#define ENABLE_CPU_TESTS 0
@@ -0,0 +1,94 @@
--- base/process/process_posix.cc.orig 2024-06-18 21:43:17 UTC
+++ base/process/process_posix.cc
@@ -23,10 +23,15 @@
#include "base/trace_event/base_tracing.h"
#include "build/build_config.h"
-#if BUILDFLAG(IS_MAC)
+#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_BSD)
#include <sys/event.h>
#endif
+#if BUILDFLAG(IS_BSD)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
#if BUILDFLAG(CLANG_PROFILING)
#include "base/test/clang_profiling.h"
#endif
@@ -99,7 +104,7 @@ bool WaitpidWithTimeout(base::ProcessHandle handle,
}
#endif
-#if BUILDFLAG(IS_MAC)
+#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_BSD)
// Using kqueue on Mac so that we can wait on non-child processes.
// We can't use kqueues on child processes because we need to reap
// our own children using wait.
@@ -376,7 +381,7 @@ bool Process::WaitForExitWithTimeoutImpl(base::Process
const bool exited = (parent_pid < 0);
if (!exited && parent_pid != our_pid) {
-#if BUILDFLAG(IS_MAC)
+#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_BSD)
// On Mac we can wait on non child processes.
return WaitForSingleNonChildProcess(handle, timeout);
#else
@@ -413,7 +418,56 @@ int Process::GetOSPriority() const {
int Process::GetOSPriority() const {
DCHECK(IsValid());
+// avoid pledge(2) violation
+#if BUILDFLAG(IS_BSD)
+ return 0;
+#else
return getpriority(PRIO_PROCESS, static_cast<id_t>(process_));
+#endif
}
+
+Time Process::CreationTime() const {
+// avoid ps pledge in the network process
+#if !BUILDFLAG(IS_BSD)
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid(),
+ sizeof(struct kinfo_proc), 0 };
+ struct kinfo_proc *info = nullptr;
+ size_t info_size;
+#endif
+ Time ct = Time();
+
+#if !BUILDFLAG(IS_BSD)
+ if (sysctl(mib, std::size(mib), NULL, &info_size, NULL, 0) < 0)
+ goto out;
+
+ mib[5] = (info_size / sizeof(struct kinfo_proc));
+ if ((info = reinterpret_cast<kinfo_proc*>(malloc(info_size))) == NULL)
+ goto out;
+
+ if (sysctl(mib, std::size(mib), info, &info_size, NULL, 0) < 0)
+ goto out;
+
+ ct = Time::FromTimeT(info->p_ustart_sec);
+
+out:
+ if (info)
+ free(info);
+#endif
+ return ct;
+}
+
+#if BUILDFLAG(IS_BSD)
+Process::Priority Process::GetPriority() const {
+ return Priority::kUserBlocking;
+}
+
+bool Process::SetPriority(Priority priority) {
+ return false;
+}
+
+bool Process::CanSetPriority() {
+ return false;
+}
+#endif
} // namespace base
@@ -0,0 +1,11 @@
--- base/process/process_unittest.cc.orig 2024-10-16 21:30:44 UTC
+++ base/process/process_unittest.cc
@@ -203,7 +203,7 @@ TEST_F(ProcessTest, CreationTimeOtherProcess) {
// was spawned and a time recorded after it was spawned. However, since the
// base::Time and process creation clocks don't match, tolerate some error.
constexpr base::TimeDelta kTolerance =
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// On Linux, process creation time is relative to boot time which has a
// 1-second resolution. Tolerate 1 second for the imprecise boot time and
// 100 ms for the imprecise clock.
@@ -0,0 +1,11 @@
--- base/profiler/module_cache.cc.orig 2024-04-15 20:33:42 UTC
+++ base/profiler/module_cache.cc
@@ -38,7 +38,7 @@ std::string TransformModuleIDToSymbolServerFormat(std:
// Android and Linux Chrome builds use the "breakpad" format to index their
// build id, so we transform the build id for these platforms. All other
// platforms keep their symbols indexed by the original build ID.
-#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD)
// Linux ELF module IDs are 160bit integers, which we need to mangle
// down to 128bit integers to match the id that Breakpad outputs.
// Example on version '66.0.3359.170' x64:
@@ -0,0 +1,20 @@
--- base/profiler/sampling_profiler_thread_token.cc.orig 2024-04-15 20:33:42 UTC
+++ base/profiler/sampling_profiler_thread_token.cc
@@ -6,7 +6,7 @@
#include "build/build_config.h"
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
#include <pthread.h>
#include "base/profiler/stack_base_address_posix.h"
@@ -18,7 +18,7 @@ SamplingProfilerThreadToken GetSamplingProfilerCurrent
PlatformThreadId id = PlatformThread::CurrentId();
#if BUILDFLAG(IS_ANDROID)
return {id, pthread_self()};
-#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
std::optional<uintptr_t> maybe_stack_base =
GetThreadStackBaseAddress(id, pthread_self());
return {id, maybe_stack_base};
@@ -0,0 +1,20 @@
--- base/profiler/sampling_profiler_thread_token.h.orig 2024-04-15 20:33:42 UTC
+++ base/profiler/sampling_profiler_thread_token.h
@@ -13,7 +13,7 @@
#if BUILDFLAG(IS_ANDROID)
#include <pthread.h>
-#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
#include <stdint.h>
#endif
@@ -27,7 +27,7 @@ struct SamplingProfilerThreadToken {
PlatformThreadId id;
#if BUILDFLAG(IS_ANDROID)
pthread_t pthread_id;
-#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
// Due to the sandbox, we can only retrieve the stack base address for the
// current thread. We must grab it during
// GetSamplingProfilerCurrentThreadToken() and not try to get it later.
@@ -0,0 +1,59 @@
--- base/profiler/stack_base_address_posix.cc.orig 2024-04-15 20:33:42 UTC
+++ base/profiler/stack_base_address_posix.cc
@@ -17,6 +17,10 @@
#include "base/files/scoped_file.h"
#endif
+#if BUILDFLAG(IS_BSD)
+#include <pthread_np.h>
+#endif
+
#if BUILDFLAG(IS_CHROMEOS)
extern "C" void* __libc_stack_end;
#endif
@@ -45,7 +49,21 @@ uintptr_t GetThreadStackBaseAddressImpl(pthread_t pthr
#if !BUILDFLAG(IS_LINUX)
uintptr_t GetThreadStackBaseAddressImpl(pthread_t pthread_id) {
+#if BUILDFLAG(IS_OPENBSD)
+ stack_t ss;
+ void *address;
+ size_t size;
+ if (pthread_stackseg_np(pthread_id, &ss) != 0)
+ return 0;
+ size = ss.ss_size;
+ address = (void*)((size_t) ss.ss_sp - ss.ss_size);
+#else
pthread_attr_t attr;
+#if BUILDFLAG(IS_FREEBSD)
+ int result;
+ pthread_attr_init(&attr);
+ pthread_attr_get_np(pthread_id, &attr);
+#else
// pthread_getattr_np will crash on ChromeOS & Linux if we are in the sandbox
// and pthread_id refers to a different thread, due to the use of
// sched_getaffinity().
@@ -58,12 +76,14 @@ uintptr_t GetThreadStackBaseAddressImpl(pthread_t pthr
<< logging::SystemErrorCodeToString(result);
// See crbug.com/617730 for limitations of this approach on Linux-like
// systems.
+#endif
void* address;
size_t size;
result = pthread_attr_getstack(&attr, &address, &size);
CHECK_EQ(result, 0) << "pthread_attr_getstack returned "
<< logging::SystemErrorCodeToString(result);
pthread_attr_destroy(&attr);
+#endif
const uintptr_t base_address = reinterpret_cast<uintptr_t>(address) + size;
return base_address;
}
@@ -80,7 +100,7 @@ std::optional<uintptr_t> GetThreadStackBaseAddress(Pla
// trying to work around the problem.
return std::nullopt;
#else
- const bool is_main_thread = id == GetCurrentProcId();
+ const bool is_main_thread = id == checked_cast<PlatformThreadId>(GetCurrentProcId());
if (is_main_thread) {
#if BUILDFLAG(IS_ANDROID)
// The implementation of pthread_getattr_np() in Bionic reads proc/self/maps
@@ -0,0 +1,11 @@
--- base/profiler/stack_sampling_profiler_test_util.cc.orig 2024-06-18 21:43:17 UTC
+++ base/profiler/stack_sampling_profiler_test_util.cc
@@ -42,7 +42,7 @@
// Fortunately, it provides _alloca, which functions identically.
#include <malloc.h>
#define alloca _alloca
-#else
+#elif !BUILDFLAG(IS_BSD)
#include <alloca.h>
#endif
@@ -0,0 +1,11 @@
--- base/profiler/stack_sampling_profiler_unittest.cc.orig 2024-08-14 20:54:23 UTC
+++ base/profiler/stack_sampling_profiler_unittest.cc
@@ -45,7 +45,7 @@
#include <intrin.h>
#include <malloc.h>
-#else
+#elif !BUILDFLAG(IS_BSD)
#include <alloca.h>
#endif
@@ -0,0 +1,20 @@
--- base/profiler/thread_delegate_posix.cc.orig 2024-06-18 21:43:17 UTC
+++ base/profiler/thread_delegate_posix.cc
@@ -19,7 +19,7 @@
#include "base/process/process_handle.h"
#include "build/build_config.h"
-#if !(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS))
+#if !(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD))
#include "base/profiler/stack_base_address_posix.h"
#endif
@@ -28,7 +28,7 @@ std::unique_ptr<ThreadDelegatePosix> ThreadDelegatePos
std::unique_ptr<ThreadDelegatePosix> ThreadDelegatePosix::Create(
SamplingProfilerThreadToken thread_token) {
std::optional<uintptr_t> base_address;
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
base_address = thread_token.stack_base_address;
#else
base_address =
@@ -0,0 +1,11 @@
--- base/rand_util.h.orig 2025-01-27 17:37:37 UTC
+++ base/rand_util.h
@@ -141,7 +141,7 @@ void RandomShuffle(Itr first, Itr last) {
std::shuffle(first, last, RandomBitGenerator());
}
-#if BUILDFLAG(IS_POSIX)
+#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_BSD)
BASE_EXPORT int GetUrandomFD();
#endif

Some files were not shown because too many files have changed in this diff Show More