Skip to content

Commit ecd1876

Browse files
committed
Squashed 'src/ipc/libmultiprocess/' content from commit 1b8d4a6f
git-subtree-dir: src/ipc/libmultiprocess git-subtree-split: 1b8d4a6f1e54b92708bd2ad627ec6d440a1daf3d
0 parents  commit ecd1876

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+6514
-0
lines changed

.clang-tidy

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Checks: '
2+
-*,
3+
bugprone-argument-comment,
4+
bugprone-move-forwarding-reference,
5+
bugprone-string-constructor,
6+
bugprone-use-after-move,
7+
bugprone-lambda-function-name,
8+
bugprone-unhandled-self-assignment,
9+
misc-unused-using-decls,
10+
misc-no-recursion,
11+
modernize-deprecated-headers,
12+
modernize-use-default-member-init,
13+
modernize-use-emplace,
14+
modernize-use-equals-default,
15+
modernize-use-noexcept,
16+
modernize-use-nullptr,
17+
modernize-use-starts-ends-with,
18+
performance-*,
19+
-performance-avoid-endl,
20+
-performance-enum-size,
21+
-performance-inefficient-string-concatenation,
22+
-performance-no-int-to-ptr,
23+
-performance-noexcept-move-constructor,
24+
-performance-unnecessary-value-param,
25+
readability-const-return-type,
26+
readability-redundant-declaration,
27+
readability-redundant-string-init,
28+
clang-analyzer-core.*,
29+
-clang-analyzer-core.UndefinedBinaryOperatorResult,
30+
clang-analyzer-optin.core.*,
31+
'
32+
HeaderFilterRegex: '.'
33+
WarningsAsErrors: '*'
34+
CheckOptions:
35+
- key: modernize-deprecated-headers.CheckHeaderFile
36+
value: false
37+
- key: performance-move-const-arg.CheckTriviallyCopyableMove
38+
value: false
39+
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
40+
value: false

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build-openbsd:
9+
runs-on: ubuntu-latest
10+
name: build • openbsd
11+
defaults:
12+
run:
13+
shell: openbsd {0}
14+
steps:
15+
- uses: actions/checkout@v5
16+
17+
- name: Start OpenBSD VM
18+
uses: vmactions/openbsd-vm@v1
19+
with:
20+
prepare: |
21+
pkg_add -v cmake ninja git python bash
22+
run: |
23+
git clone --depth=1 https://codeberg.org/OpenBSD/ports.git /usr/ports
24+
sync: 'rsync'
25+
copyback: false
26+
27+
- name: Install capnproto
28+
run: |
29+
cd /usr/ports/devel/capnproto/
30+
make install
31+
32+
- name: Run CI script
33+
run: |
34+
cd ${{ github.workspace }}
35+
CI_CONFIG="ci/configs/openbsd.bash" bash ci/scripts/ci.sh
36+
37+
build:
38+
runs-on: ubuntu-latest
39+
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
config: [default, llvm, gnu32, sanitize, olddeps]
44+
45+
name: build • ${{ matrix.config }}
46+
47+
steps:
48+
- uses: actions/checkout@v5
49+
50+
- name: Install Nix
51+
uses: cachix/install-nix-action@v31 # 2025-05-27, from https://github.com/cachix/install-nix-action/tags
52+
with:
53+
nix_path: nixpkgs=channel:nixos-25.05 # latest release
54+
55+
- name: Run CI script
56+
env:
57+
CI_CONFIG: ci/configs/${{ matrix.config }}.bash
58+
run: ci/scripts/run.sh

CMakeLists.txt

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
# Copyright (c) The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
cmake_minimum_required(VERSION 3.12)
6+
7+
project("Libmultiprocess" CXX)
8+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
9+
set(CMAKE_CXX_STANDARD 20)
10+
set(CMAKE_CXX_STANDARD_REQUIRED YES)
11+
endif()
12+
13+
include("cmake/compat_find.cmake")
14+
15+
find_package(Threads REQUIRED)
16+
find_package(CapnProto 0.7 REQUIRED)
17+
18+
# Check for list-of-pointers memory access bug from Nov 2022
19+
# https://nvd.nist.gov/vuln/detail/CVE-2022-46149
20+
# https://github.com/advisories/GHSA-qqff-4vw4-f6hx
21+
# https://github.com/capnproto/capnproto/security/advisories/GHSA-qqff-4vw4-f6hx
22+
# https://github.com/capnproto/capnproto/blob/master/security-advisories/2022-11-30-0-pointer-list-bounds.md
23+
# https://capnproto.org/news/2022-11-30-CVE-2022-46149-security-advisory.html
24+
# https://dwrensha.github.io/capnproto-rust/2022/11/30/out_of_bounds_memory_access_bug.html
25+
if(CapnProto_VERSION STREQUAL "0.7.0"
26+
OR CapnProto_VERSION STREQUAL "0.8.0"
27+
OR CapnProto_VERSION STREQUAL "0.9.0"
28+
OR CapnProto_VERSION STREQUAL "0.9.1"
29+
OR CapnProto_VERSION STREQUAL "0.10.0"
30+
OR CapnProto_VERSION STREQUAL "0.10.1"
31+
OR CapnProto_VERSION STREQUAL "0.10.2")
32+
message(FATAL_ERROR
33+
"Cap'n Proto ${CapnProto_VERSION} is affected by CVE-2022-46149.\n"
34+
"Please install an updated package.\n"
35+
"Details: https://github.com/advisories/GHSA-qqff-4vw4-f6hx
36+
")
37+
endif()
38+
39+
set(MPGEN_EXECUTABLE "" CACHE FILEPATH "If specified, should be full path to an external mpgen binary to use rather than the one built internally.")
40+
41+
option(MP_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
42+
if(MP_ENABLE_CLANG_TIDY)
43+
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy)
44+
if(NOT CLANG_TIDY_EXECUTABLE)
45+
message(FATAL_ERROR "MP_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.")
46+
endif()
47+
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")
48+
49+
# Workaround for nix from https://gitlab.kitware.com/cmake/cmake/-/issues/20912#note_793338
50+
# Nix injects header paths via $NIX_CFLAGS_COMPILE; CMake tags these as
51+
# CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES and omits them from the compile
52+
# database, so clang-tidy, which ignores $NIX_CFLAGS_COMPILE, can't find capnp
53+
# headers. Setting them as standard passes them to clang-tidy.
54+
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
55+
endif()
56+
57+
option(MP_ENABLE_IWYU "Run include-what-you-use with the compiler." OFF)
58+
if(MP_ENABLE_IWYU)
59+
find_program(IWYU_EXECUTABLE NAMES include-what-you-use iwyu)
60+
if(NOT IWYU_EXECUTABLE)
61+
message(FATAL_ERROR "MP_ENABLE_IWYU is ON but include-what-you-use was not found.")
62+
endif()
63+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXECUTABLE};-Xiwyu;--error")
64+
if(DEFINED ENV{IWYU_MAPPING_FILE})
65+
list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE "-Xiwyu" "--mapping_file=$ENV{IWYU_MAPPING_FILE}")
66+
endif()
67+
endif()
68+
69+
include("cmake/compat_config.cmake")
70+
include("cmake/pthread_checks.cmake")
71+
include(GNUInstallDirs)
72+
73+
# Set MP_INCLUDE_DIR as a global property so target_capnp_sources function can
74+
# use it, and its callers don't need to specify the include directory manually
75+
# to avoid "error: Import failed: /mp/proxy.capnp" failures from capnproto.
76+
set_property(GLOBAL PROPERTY MP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
77+
78+
# Set a convenience variable for subdirectories.
79+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
80+
set(MP_STANDALONE TRUE)
81+
include(CTest)
82+
else()
83+
set(MP_STANDALONE FALSE)
84+
endif()
85+
86+
# Prevent include directories from parent project from leaking into this one.
87+
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "")
88+
89+
# Generated C++ preprocessor defines
90+
configure_file(include/mp/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/mp/config.h")
91+
92+
# Generated C++ Capn'Proto schema files
93+
capnp_generate_cpp(MP_PROXY_SRCS MP_PROXY_HDRS include/mp/proxy.capnp)
94+
set_source_files_properties("${MP_PROXY_SRCS}" PROPERTIES SKIP_LINTING TRUE) # Ignored before cmake 3.27
95+
96+
# util library
97+
add_library(mputil OBJECT src/mp/util.cpp)
98+
target_include_directories(mputil PRIVATE
99+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
100+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
101+
target_link_libraries(mputil PUBLIC CapnProto::kj)
102+
103+
# libmultiprocess.a runtime library
104+
set(MP_PUBLIC_HEADERS
105+
${MP_PROXY_HDRS}
106+
include/mp/proxy-io.h
107+
include/mp/proxy-types.h
108+
include/mp/proxy.h
109+
include/mp/type-char.h
110+
include/mp/type-chrono.h
111+
include/mp/type-context.h
112+
include/mp/type-data.h
113+
include/mp/type-decay.h
114+
include/mp/type-exception.h
115+
include/mp/type-function.h
116+
include/mp/type-interface.h
117+
include/mp/type-map.h
118+
include/mp/type-message.h
119+
include/mp/type-number.h
120+
include/mp/type-optional.h
121+
include/mp/type-pair.h
122+
include/mp/type-pointer.h
123+
include/mp/type-set.h
124+
include/mp/type-string.h
125+
include/mp/type-struct.h
126+
include/mp/type-threadmap.h
127+
include/mp/type-tuple.h
128+
include/mp/type-vector.h
129+
include/mp/type-void.h
130+
include/mp/util.h)
131+
add_library(multiprocess STATIC
132+
${MP_PROXY_SRCS}
133+
${MP_PUBLIC_HEADERS}
134+
src/mp/proxy.cpp
135+
$<TARGET_OBJECTS:mputil>)
136+
add_library(Libmultiprocess::multiprocess ALIAS multiprocess)
137+
target_include_directories(multiprocess PUBLIC
138+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
139+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
140+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
141+
target_link_libraries(multiprocess PUBLIC CapnProto::capnp)
142+
target_link_libraries(multiprocess PUBLIC CapnProto::capnp-rpc)
143+
target_link_libraries(multiprocess PUBLIC CapnProto::kj)
144+
target_link_libraries(multiprocess PUBLIC CapnProto::kj-async)
145+
set_target_properties(multiprocess PROPERTIES
146+
PUBLIC_HEADER "${MP_PUBLIC_HEADERS}")
147+
install(TARGETS multiprocess EXPORT LibTargets
148+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib
149+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT lib)
150+
151+
# mpgen code generator
152+
add_executable(mpgen src/mp/gen.cpp $<TARGET_OBJECTS:mputil>)
153+
add_executable(Libmultiprocess::mpgen ALIAS mpgen)
154+
target_include_directories(mpgen PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
155+
target_include_directories(mpgen PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
156+
target_link_libraries(mpgen PRIVATE CapnProto::capnp)
157+
target_link_libraries(mpgen PRIVATE CapnProto::capnp-rpc)
158+
target_link_libraries(mpgen PRIVATE CapnProto::capnpc)
159+
target_link_libraries(mpgen PRIVATE CapnProto::kj)
160+
target_link_libraries(mpgen PRIVATE Threads::Threads)
161+
set_target_properties(mpgen PROPERTIES
162+
INSTALL_RPATH_USE_LINK_PATH TRUE)
163+
set_target_properties(mpgen PROPERTIES
164+
PUBLIC_HEADER include/mp/proxy.capnp)
165+
install(TARGETS mpgen EXPORT BinTargets
166+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin
167+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT bin)
168+
169+
# makefile include to invoke mpgen code generator, for downstream Make projects
170+
install(FILES "include/mpgen.mk"
171+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT bin)
172+
173+
# pkg-config module to build against libmultiprocess library, for downstream autoconf projects
174+
configure_file(pkgconfig/libmultiprocess.pc.in "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc" @ONLY)
175+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc"
176+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT lib)
177+
178+
# cmake include to invoke mpgen code generator, for downstream CMake projects
179+
install(
180+
FILES
181+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/TargetCapnpSources.cmake
182+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT bin)
183+
184+
# CMake target import files, for downstream CMake projects
185+
install(EXPORT BinTargets
186+
NAMESPACE Libmultiprocess::
187+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT bin)
188+
install(EXPORT LibTargets
189+
NAMESPACE Libmultiprocess::
190+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT lib)
191+
192+
# CMake find_package config file, for downstream CMake projects
193+
include(CMakePackageConfigHelpers)
194+
configure_package_config_file(
195+
${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
196+
LibmultiprocessConfig.cmake
197+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess
198+
NO_SET_AND_CHECK_MACRO)
199+
install(
200+
FILES
201+
${CMAKE_CURRENT_BINARY_DIR}/LibmultiprocessConfig.cmake
202+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess
203+
COMPONENT common)
204+
205+
# Makefile targets to support "make install-bin" "make install-lib"
206+
add_custom_target(install-bin
207+
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=bin -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
208+
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=common -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
209+
VERBATIM)
210+
add_dependencies(install-bin mpgen)
211+
add_custom_target(install-lib
212+
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=lib -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
213+
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=common -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
214+
VERBATIM)
215+
add_dependencies(install-lib multiprocess)
216+
217+
# Example and test subdirectories
218+
add_subdirectory(example EXCLUDE_FROM_ALL)
219+
add_subdirectory(test EXCLUDE_FROM_ALL)

COPYING

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2009-2019 The Bitcoin Core developers
4+
Copyright (c) 2009-2019 Bitcoin Developers
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# libmultiprocess
2+
3+
`libmultiprocess` is a C++ library and code generator making it easy to call functions and reference objects in different processes.
4+
5+
For more information see the [usage instructions](doc/usage.md), [installation instructions](doc/install.md), or [design documentation](doc/design.md).
6+
7+
If you have any questions, comments, or feedback, please submit an [issue](https://github.com/bitcoin-core/libmultiprocess/issues/new).
8+
Duplicate issues are perfectly fine and all discussion about the project is welcome, since there isn't another discussion forum currently.

ci/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
### CI quick-reference
2+
3+
All CI is just bash and nix.
4+
5+
* **Workflow**:
6+
- `.github/workflows/ci.yml` – lists the jobs (`default`, `llvm`, …).
7+
* **Scripts**:
8+
- `ci/scripts/run.sh` – spins up the Nix shell then calls…
9+
- `ci/scripts/ci.sh` – …to configure, build, and test.
10+
* **Configuration**:
11+
- `ci/configs/*.sh` – defines flags for each job.
12+
- `shell.nix` – defines build environment (compilers, tools, libraries).
13+
* **Build directories**:
14+
- `build-*/` – separate build directories (like `build-default`, `build-llvm`) will be created for each job.
15+
16+
To run jobs locally:
17+
18+
```bash
19+
CI_CONFIG=ci/configs/default.bash ci/scripts/run.sh
20+
CI_CONFIG=ci/configs/llvm.bash ci/scripts/run.sh
21+
CI_CONFIG=ci/configs/gnu32.bash ci/scripts/run.sh
22+
CI_CONFIG=ci/configs/sanitize.bash ci/scripts/run.sh
23+
CI_CONFIG=ci/configs/olddeps.bash ci/scripts/run.sh
24+
```
25+
26+
By default CI jobs will reuse their build directories. `CI_CLEAN=1` can be specified to delete them before running instead.

ci/configs/default.bash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CI_DESC="CI job using default libraries and tools, and running IWYU"
2+
CI_DIR=build-default
3+
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter"
4+
CMAKE_ARGS=(-DMP_ENABLE_IWYU=ON)
5+
BUILD_ARGS=(-k)

ci/configs/gnu32.bash

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CI_DESC="CI job cross-compiling to 32-bit"
2+
CI_DIR=build-gnu32
3+
NIX_ARGS=(
4+
--arg minimal true
5+
--arg crossPkgs 'import <nixpkgs> { crossSystem = { config = "i686-unknown-linux-gnu"; }; }'
6+
)
7+
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter"
8+
CMAKE_ARGS=(-G Ninja)
9+
BUILD_ARGS=(-k 0)

0 commit comments

Comments
 (0)