├── codegen ├── README.md ├── .gitignore ├── requirements.txt ├── src │ └── erlang_edf_codegen │ │ ├── __init__.py │ │ ├── context │ │ ├── nif.py │ │ ├── dpi.py │ │ └── config.py │ │ └── __main__.py ├── templates0 │ └── apps │ │ └── erldist_filter │ │ └── c_src │ │ └── nif │ │ ├── erldist_filter_nif_version.c.j2 │ │ ├── config │ │ ├── edf_config.c.j2 │ │ └── edf_config.h.j2 │ │ └── channel │ │ ├── edf_channel_stats.c.j2 │ │ └── edf_channel_stats.h.j2 ├── Dockerfile ├── templates1 │ └── apps │ │ └── erldist_filter │ │ └── c_src │ │ └── nif │ │ ├── erldist_filter_nif_atoms.h.j2 │ │ └── erldist_filter_nif_atoms.c.j2 └── pyproject.toml ├── apps ├── erldist_filter │ ├── priv │ │ └── .keep │ ├── rebar.lock │ ├── .gitignore │ ├── c_src │ │ ├── nif │ │ │ ├── erl_nif_trampoline.h │ │ │ ├── etf │ │ │ │ ├── etf_common.h │ │ │ │ ├── etf_decode.h │ │ │ │ ├── etf_rewrite_as_drop.h │ │ │ │ ├── etf_redirect_spawn_request.h │ │ │ │ ├── etf_encode.h │ │ │ │ ├── etf_redirect_dop.h │ │ │ │ ├── etf_decode_udist.h │ │ │ │ ├── etf_rollback_atom_cache.h │ │ │ │ ├── etf_rewrite_fragment_header.h │ │ │ │ └── etf_decode_dist_header.h │ │ │ ├── erldist_filter_nif_version.h │ │ │ ├── trap │ │ │ │ └── edf_trap_impl.h │ │ │ ├── world │ │ │ │ └── edf_world_impl.h │ │ │ ├── erldist_filter_nif_version.c │ │ │ ├── erts │ │ │ │ ├── edf_erts_dist_impl.h │ │ │ │ └── atom.h │ │ │ ├── config │ │ │ │ ├── edf_config_impl.h │ │ │ │ └── edf_config.c │ │ │ ├── channel │ │ │ │ ├── edf_channel_inspect.h │ │ │ │ ├── edf_channel_recv.h │ │ │ │ ├── edf_channel_impl.h │ │ │ │ └── edf_external_sequence.h │ │ │ ├── blocklist │ │ │ │ └── edf_otp_name_blocklist.h │ │ │ ├── vterm │ │ │ │ └── vterm_impl.h │ │ │ └── logger │ │ │ │ ├── edf_logger_queue_recv.h │ │ │ │ └── edf_logger_impl.h │ │ ├── .clang-format │ │ └── primitive │ │ │ ├── align.h │ │ │ ├── bool.h │ │ │ ├── memset_explicit.h │ │ │ ├── unreachable.h │ │ │ ├── slice.h │ │ │ ├── spinlock.h │ │ │ ├── spinwait.h │ │ │ └── linklist.h │ ├── src │ │ ├── vterm │ │ │ ├── vterm_simplify.erl │ │ │ ├── vterm_the_non_value.erl │ │ │ ├── vterm_pid.erl │ │ │ ├── vterm_reference.erl │ │ │ ├── vterm_atom.erl │ │ │ ├── vterm_atom_cache_ref.erl │ │ │ ├── vterm_nil_ext.erl │ │ │ ├── vterm_integer_ext.erl │ │ │ ├── vterm_small_integer_ext.erl │ │ │ ├── vterm_lazy_term.erl │ │ │ ├── vterm_atom_ext.erl │ │ │ ├── vterm_binary_ext.erl │ │ │ ├── vterm_atom_utf8_ext.erl │ │ │ ├── vterm_small_atom_ext.erl │ │ │ ├── vterm_small_atom_utf8_ext.erl │ │ │ ├── vterm_new_float_ext.erl │ │ │ ├── vterm_float_ext.erl │ │ │ ├── vterm_string_ext.erl │ │ │ ├── vterm_atom_cache_ref_resolved.erl │ │ │ ├── vterm_small_big_ext.erl │ │ │ ├── vterm_large_big_ext.erl │ │ │ ├── vterm_nif_term.erl │ │ │ ├── vterm_small_tuple_ext.erl │ │ │ ├── vterm_v4_port_ext.erl │ │ │ ├── vterm_bit_binary_ext.erl │ │ │ ├── vterm_new_port_ext.erl │ │ │ ├── vterm_large_tuple_ext.erl │ │ │ ├── vterm_port_ext.erl │ │ │ ├── vterm_map_ext.erl │ │ │ └── vterm_reference_ext.erl │ │ ├── erldist_filter.app.src.script │ │ ├── erldist_filter_dist_util_tracer.erl │ │ ├── vdist │ │ │ ├── vdist_header_encode.erl │ │ │ ├── vdist_pass_through_header.erl │ │ │ ├── vdist_fragment_cont.erl │ │ │ ├── vdist_dop_send.erl │ │ │ ├── vdist_dop_link.erl │ │ │ ├── vdist_old_atom_cache_ref_entry.erl │ │ │ ├── vdist_dop_unlink.erl │ │ │ ├── vdist_dop_group_leader.erl │ │ │ ├── vdist_dop_alias_send.erl │ │ │ ├── vdist_dop_send_sender.erl │ │ │ ├── vdist_dop_payload_exit.erl │ │ │ ├── vdist_dop_payload_exit2.erl │ │ │ ├── vdist_dop_send_tt.erl │ │ │ ├── vdist_dop_exit.erl │ │ │ ├── vdist_dop_exit2.erl │ │ │ ├── vdist_dop_unlink_id.erl │ │ │ ├── vdist_dop_unlink_id_ack.erl │ │ │ ├── vdist_dop_reg_send.erl │ │ │ ├── vdist_dop_alias_send_tt.erl │ │ │ ├── vdist_dop_monitor_p.erl │ │ │ ├── vdist_dop_send_sender_tt.erl │ │ │ ├── vdist_dop_demonitor_p.erl │ │ │ ├── vdist_dop_payload_exit_tt.erl │ │ │ ├── vdist_dop_payload_exit2_tt.erl │ │ │ └── vdist_dop_exit_tt.erl │ │ ├── edf.erl │ │ ├── erldist_filter_app.erl │ │ └── erldist_filter.app.src │ ├── include │ │ ├── erldist_filter.hrl │ │ ├── erldist_filter_otp_27_net_address.hrl │ │ ├── erldist_filter_otp_28_net_address.hrl │ │ └── vedf.hrl │ ├── rebar.config │ ├── rebar.config.script │ └── mix.exs └── erldist_filter_test │ ├── .gitignore │ ├── _checkouts │ └── erldist_filter │ ├── rebar.lock │ ├── rebar.config │ └── src │ ├── erldist_filter_test_p2p_manager.erl │ ├── erldist_filter_test.app.src │ ├── erldist_filter_test_app.erl │ └── property_test │ ├── erldist_filter_nif_spbt_prop.erl │ └── erldist_filter_peer_spbt_prop.erl ├── justfile ├── config └── config.exs ├── mix.lock ├── .formatter.exs ├── rebar.lock ├── test └── test_helper.exs ├── rebar.config ├── mix.exs ├── README.md ├── justfiles ├── python.just ├── docker.just └── tools.just ├── LICENSE.md ├── CHANGELOG.md ├── .gitignore └── CONTRIBUTING.md /codegen/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apps/erldist_filter/priv/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apps/erldist_filter/rebar.lock: -------------------------------------------------------------------------------- 1 | []. 2 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/.gitignore: -------------------------------------------------------------------------------- 1 | !_checkouts/ 2 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/_checkouts/erldist_filter: -------------------------------------------------------------------------------- 1 | ../../erldist_filter -------------------------------------------------------------------------------- /apps/erldist_filter/.gitignore: -------------------------------------------------------------------------------- 1 | /CHANGELOG.md 2 | /LICENSE.md 3 | /README.md 4 | /src/erldist_filter_play.erl 5 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/erl_nif_trampoline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/rebar.lock: -------------------------------------------------------------------------------- 1 | {"1.2.0", 2 | [{<<"proper">>,{pkg,<<"proper">>,<<"1.5.0">>},0}]}. 3 | [ 4 | {pkg_hash,[ 5 | {<<"proper">>, <<"4A87CE8B219858E64C9AA015F4F7ED739D0AC3CA6BFD77FA62794617EE784225">>}]}, 6 | {pkg_hash_ext,[ 7 | {<<"proper">>, <<"FBF7CF0625E5441A314514F7D8E1EAFF52090FCD94FF34B5171FF293D3F9969A">>}]} 8 | ]. 9 | -------------------------------------------------------------------------------- /codegen/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | /.pytest_cache/ 8 | /.venv/ 9 | !/src/**/__init__.py 10 | !/src/**/__main__.py 11 | -------------------------------------------------------------------------------- /codegen/requirements.txt: -------------------------------------------------------------------------------- 1 | annotated-types==0.7.0 2 | attrs==25.3.0 3 | click==8.2.1 4 | colorama==0.4.6 5 | jinja2==3.1.6 6 | jsonschema-specifications==2025.4.1 7 | jsonschema==4.25.0 8 | markupsafe==3.0.2 9 | pydantic-core==2.33.2 10 | pydantic==2.11.7 11 | pyyaml==6.0.2 12 | referencing==0.36.2 13 | rpds-py==0.27.0 14 | typing-extensions==4.14.1 15 | typing-inspection==0.4.1 16 | -------------------------------------------------------------------------------- /justfile: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | import? 'justfiles/docker.just' 8 | import? 'justfiles/python.just' 9 | import? 'justfiles/tools.just' 10 | 11 | default: 12 | just --list 13 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | import Config 8 | 9 | # config(:logger, 10 | # level: :debug, 11 | # handle_otp_reports: true, 12 | # handle_sasl_reports: true 13 | # ) 14 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"}, 3 | "proper": {:hex, :proper, "1.5.0", "4a87ce8b219858e64c9aa015f4f7ed739d0ac3ca6bfd77fa62794617ee784225", [:rebar3], [], "hexpm", "fbf7cf0625e5441a314514f7d8e1eaff52090fcd94ff34b5171ff293d3f9969a"}, 4 | } 5 | -------------------------------------------------------------------------------- /codegen/src/erlang_edf_codegen/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | """Generate C and Erlang code from YAML configuration using Jinja2.""" 8 | from .code_generator import CodeGenerator 9 | from .schema import Root 10 | 11 | __all__ = ["CodeGenerator", "Root"] 12 | -------------------------------------------------------------------------------- /.formatter.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | # Used by "mix format" 8 | [ 9 | inputs: [ 10 | "{mix,.formatter}.exs", 11 | "{config,lib,test}/**/*.{ex,exs}", 12 | "apps/erldist_filter/{mix,.formatter}.exs", 13 | "apps/erldist_filter/{config,lib,test}/**/*.{ex,exs}" 14 | ], 15 | line_length: 132 16 | ] 17 | -------------------------------------------------------------------------------- /rebar.lock: -------------------------------------------------------------------------------- 1 | {"1.2.0", 2 | [{<<"eqwalizer_support">>, 3 | {git_subdir,"https://github.com/WhatsApp/eqwalizer.git", 4 | {ref,"54a74ae351f494328fa77515830a87275088426a"}, 5 | "eqwalizer_support"}, 6 | 0}, 7 | {<<"proper">>,{pkg,<<"proper">>,<<"1.5.0">>},0}]}. 8 | [ 9 | {pkg_hash,[ 10 | {<<"proper">>, <<"4A87CE8B219858E64C9AA015F4F7ED739D0AC3CA6BFD77FA62794617EE784225">>}]}, 11 | {pkg_hash_ext,[ 12 | {<<"proper">>, <<"FBF7CF0625E5441A314514F7D8E1EAFF52090FCD94FF34B5171FF293D3F9969A">>}]} 13 | ]. 14 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/.clang-format: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | --- 7 | Language: Cpp 8 | BasedOnStyle: LLVM 9 | AllowShortFunctionsOnASingleLine: None 10 | AlwaysBreakAfterDefinitionReturnType: true 11 | BreakBeforeBraces: Linux 12 | ColumnLimit: 132 13 | IndentWidth: 4 14 | InsertNewlineAtEOF: true 15 | SortIncludes: false 16 | ... 17 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/rebar.config: -------------------------------------------------------------------------------- 1 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 2 | %%% Copyright (c) WhatsApp LLC 3 | %%% 4 | %%% This source code is licensed under the MIT license found in the 5 | %%% LICENSE.md file in the root directory of this source tree. 6 | %%% % @format 7 | {erl_opts, [debug_info]}. 8 | 9 | {deps, [ 10 | erldist_filter, 11 | {proper, "1.5.0"} 12 | ]}. 13 | 14 | {shell, 15 | % {config, "config/sys.config"}, 16 | [{apps, [erldist_filter, erldist_filter_test]}]}. 17 | 18 | {project_plugins, [{rebar3_proper, "0.12.1"}]}. 19 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/primitive/align.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef CORE_ALIGN_H 10 | #define CORE_ALIGN_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | 18 | /* Darwin can be frustrating sometimes */ 19 | 20 | #ifndef alignas 21 | #define alignas(T) _Alignas(T) 22 | #endif 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | # :ok = :logger.set_primary_config(:level, :debug) 8 | # :ok = :lists.foreach(&:logger.remove_handler/1, :logger.get_handler_ids) 9 | # :ok = :logger.add_handler(:debug_output, :logger_std_h, %{ 10 | # config: %{type: :standard_error}, 11 | # formatter: {:logger_formatter, %{legacy_header: false, single_line: true}}, 12 | # level: :debug 13 | # }) 14 | 15 | ExUnit.start(max_cases: 1) 16 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_DECODE_COMMON_H 10 | #define ETF_DECODE_COMMON_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "../erldist_filter_nif.h" 17 | #include "../channel/edf_external.h" 18 | #include "../trap/edf_trap.h" 19 | #include "../vec.h" 20 | 21 | #include "../erts/dist.h" 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/erldist_filter_nif_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ERLDIST_FILTER_NIF_VERSION_H 10 | #define ERLDIST_FILTER_NIF_VERSION_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "erldist_filter_nif.h" 17 | 18 | /* Function Declarations */ 19 | 20 | extern ERL_NIF_TERM erldist_filter_nif_version_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_decode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_DECODE_H 10 | #define ETF_DECODE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_decode_dist_header.h" 17 | #include "etf_decode_term_length.h" 18 | #include "etf_decode_udist.h" 19 | #include "etf_decode_vterm.h" 20 | 21 | /* Macro Definitions */ 22 | 23 | /* Type Definitions */ 24 | 25 | /* Function Declarations */ 26 | 27 | /* Inline Function Definitions */ 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_rewrite_as_drop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_REWRITE_AS_DROP_H 10 | #define ETF_REWRITE_AS_DROP_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Function Declarations */ 23 | 24 | extern int etf_rewrite_as_drop(ErlNifEnv *caller_env, edf_external_t *external, ERL_NIF_TERM *err_termp); 25 | 26 | /* Inline Function Definitions */ 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /codegen/templates0/apps/erldist_filter/c_src/nif/erldist_filter_nif_version.c.j2: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #include "erldist_filter_nif_version.h" 10 | 11 | /* clang-format off */ //- 12 | static const ErlNifUInt64 erldist_filter_nif_version = {{ ctx.version }}ULL; 13 | /* clang-format on */ //- 14 | 15 | ERL_NIF_TERM 16 | erldist_filter_nif_version_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) 17 | { 18 | if (argc != 0) { 19 | return EXCP_BADARG(env, "argc must be 0"); 20 | } 21 | 22 | return enif_make_uint64(env, erldist_filter_nif_version); 23 | } 24 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_redirect_spawn_request.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_REDIRECT_SPAWN_REQUEST_H 10 | #define ETF_REDIRECT_SPAWN_REQUEST_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Function Declarations */ 23 | 24 | extern int etf_redirect_spawn_request(ErlNifEnv *caller_env, edf_external_t *external, ERL_NIF_TERM *err_termp); 25 | 26 | /* Inline Function Definitions */ 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/trap/edf_trap_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_TRAP_IMPL_H 10 | #define EDF_TRAP_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_trap.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_trap_2_continue(ErlNifEnv *caller_env, int argc, const ERL_NIF_TERM argv[]); 27 | 28 | /* Inline Function Definitions */ 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/world/edf_world_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_WORLD_IMPL_H 10 | #define EDF_WORLD_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_world.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_world_stats_get_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | 28 | /* Inline Function Definitions */ 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_encode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_ENCODE_H 10 | #define ETF_ENCODE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_redirect_dop.h" 17 | #include "etf_redirect_spawn_request.h" 18 | #include "etf_rewrite_as_drop.h" 19 | #include "etf_rewrite_fragment_header.h" 20 | #include "etf_rollback_atom_cache.h" 21 | 22 | /* Macro Definitions */ 23 | 24 | /* Type Definitions */ 25 | 26 | /* Function Declarations */ 27 | 28 | /* Inline Function Definitions */ 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/src/erldist_filter_test_p2p_manager.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%%----------------------------------------------------------------------------- 9 | -module(erldist_filter_test_p2p_manager). 10 | -moduledoc """ 11 | """. 12 | -moduledoc #{author => ["Andrew Bennett "]}. 13 | -moduledoc #{created => "2025-08-26", modified => "2025-08-26"}. 14 | -moduledoc #{copyright => "Meta Platforms, Inc. and affiliates."}. 15 | -compile(warn_missing_spec_all). 16 | -oncall("whatsapp_clr"). 17 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/erldist_filter_nif_version.c: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT: this file was generated by 'just codegen' 2 | // @generated SignedSource<> 3 | /* 4 | * Copyright (c) Meta Platforms, Inc. and affiliates. 5 | * Copyright (c) WhatsApp LLC 6 | * 7 | * This source code is licensed under the MIT license found in the 8 | * LICENSE.md file in the root directory of this source tree. 9 | */ 10 | 11 | #include "erldist_filter_nif_version.h" 12 | 13 | static const ErlNifUInt64 erldist_filter_nif_version = 20250905211452ULL; 14 | 15 | ERL_NIF_TERM 16 | erldist_filter_nif_version_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) 17 | { 18 | if (argc != 0) { 19 | return EXCP_BADARG(env, "argc must be 0"); 20 | } 21 | 22 | return enif_make_uint64(env, erldist_filter_nif_version); 23 | } 24 | -------------------------------------------------------------------------------- /codegen/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | # Copyright (c) Meta Platforms, Inc. and affiliates. 4 | # Copyright (c) WhatsApp LLC 5 | # 6 | # This source code is licensed under the MIT license found in the 7 | # LICENSE.md file in the root directory of this source tree. 8 | 9 | # Use an official Python image. 10 | FROM python:3.13-alpine 11 | 12 | # Install apk dependencies. 13 | RUN apk add --no-cache bash clang-extra-tools 14 | RUN apk add --no-cache -X https://dl-cdn.alpinelinux.org/alpine/edge/community just 15 | 16 | # Set the working directory. 17 | RUN mkdir -p /project 18 | WORKDIR /project 19 | COPY ./justfile . 20 | 21 | # Setup Python. 22 | COPY ./justfiles/python.just ./justfiles/python.just 23 | ENV PYTHONDONTWRITEBYTECODE=1 24 | ENV PYTHONUNBUFFERED=1 25 | RUN just setup-python 26 | ENV POETRY_VIRTUALENVS_IN_PROJECT=true 27 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/primitive/bool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef CORE_BOOL_H 10 | #define CORE_BOOL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | // bool, true, and false are now keywords as part of the C23 standard 17 | // See https://en.cppreference.com/w/c/language/bool_constant 18 | #include 19 | 20 | /* Darwin can be frustrating sometimes */ 21 | 22 | // #ifndef bool 23 | // #define bool _Bool 24 | // #endif 25 | #ifndef false 26 | #define false 0 27 | #endif 28 | #ifndef true 29 | #define true 1 30 | #endif 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_redirect_dop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_REDIRECT_DOP_H 10 | #define ETF_REDIRECT_DOP_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Function Declarations */ 23 | 24 | extern int etf_redirect_dop(ErlNifEnv *caller_env, edf_external_t *external, ERL_NIF_TERM *err_termp); 25 | extern int etf_redirect_dop_resolve_node(ErlNifEnv *caller_env, edf_external_t *ext, vec_t *node_vec); 26 | 27 | /* Inline Function Definitions */ 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /rebar.config: -------------------------------------------------------------------------------- 1 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 2 | %%% Copyright (c) WhatsApp LLC 3 | %%% 4 | %%% This source code is licensed under the MIT license found in the 5 | %%% LICENSE.md file in the root directory of this source tree. 6 | %%% % @format 7 | {erl_opts, [debug_info]}. 8 | 9 | {deps, [ 10 | {eqwalizer_support, 11 | {git_subdir, "https://github.com/WhatsApp/eqwalizer.git", {branch, "main"}, "eqwalizer_support"}} 12 | ]}. 13 | 14 | {shell, 15 | % {config, "config/sys.config"}, 16 | [{apps, [erldist_filter, erldist_filter_test]}]}. 17 | 18 | {dialyzer, [ 19 | {plt_apps, all_deps}, 20 | {warnings, [ 21 | unknown 22 | ]} 23 | ]}. 24 | 25 | {xref_checks, [ 26 | undefined_function_calls, 27 | undefined_functions, 28 | locals_not_used, 29 | % exports_not_used, 30 | deprecated_function_calls, 31 | deprecated_functions 32 | ]}. 33 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/erts/edf_erts_dist_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_ERTS_DIST_IMPL_H 10 | #define EDF_ERTS_DIST_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "../erldist_filter_nif.h" 17 | 18 | /* Function Declarations */ 19 | 20 | extern ERL_NIF_TERM erldist_filter_nif_altact_sig_flags_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 21 | extern ERL_NIF_TERM erldist_filter_nif_distribution_flags_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 22 | extern ERL_NIF_TERM erldist_filter_nif_spawn_flags_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /codegen/templates0/apps/erldist_filter/c_src/nif/config/edf_config.c.j2: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #include "edf_config.h" 10 | 11 | /* Global Variables */ 12 | 13 | static edf_config_t edf_config_internal = { 14 | /* clang-format off */ //- 15 | {% for field in ctx.config.fields_list %} 16 | .{{ field.key }} = false, 17 | {% endfor %} 18 | /* clang-format on */ //- 19 | }; 20 | edf_config_t *edf_config_global = &edf_config_internal; 21 | 22 | /* Function Definitions */ 23 | 24 | int 25 | edf_config_load(ErlNifEnv *env) 26 | { 27 | int retval = 0; 28 | (void)env; 29 | return retval; 30 | } 31 | 32 | void 33 | edf_config_unload(ErlNifEnv *env) 34 | { 35 | (void)env; 36 | return; 37 | } 38 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_simplify.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_simplify). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | %% Callbacks 17 | -callback simplify(T :: vterm:t()) -> term(). 18 | 19 | %%%============================================================================= 20 | %%% API functions 21 | %%%============================================================================= 22 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/erldist_filter.app.src.script: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%%----------------------------------------------------------------------------- 9 | 10 | SourceDir = filename:dirname(SCRIPT), 11 | AppDir = rebar_file_utils:absolute_path(filename:join([SourceDir, ".."])), 12 | ProjectDir = rebar_file_utils:absolute_path(filename:join([AppDir, "..", ".."])), 13 | 14 | FileNameList = ["CHANGELOG.md", "LICENSE.md", "README.md"], 15 | 16 | Sources = [filename:join([ProjectDir, FileName]) || FileName <- FileNameList], 17 | Dest = AppDir, 18 | Options = [{dereference, true}], 19 | ok = rebar_file_utils:cp_r(Sources, Dest, Options), 20 | 21 | CONFIG. 22 | -------------------------------------------------------------------------------- /apps/erldist_filter/include/erldist_filter.hrl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% @author Andrew Bennett 10 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 11 | %%% @doc 12 | %%% 13 | %%% @end 14 | %%% Created : 20 Sep 2022 by Andrew Bennett 15 | %%%----------------------------------------------------------------------------- 16 | %% @oncall whatsapp_clr 17 | -ifndef(ERLDIST_FILTER_HRL). 18 | 19 | -define(ERLDIST_FILTER_HRL, 1). 20 | 21 | -include_lib("erldist_filter/include/vdist.hrl"). 22 | -include_lib("erldist_filter/include/vedf.hrl"). 23 | -include_lib("erldist_filter/include/vterm.hrl"). 24 | 25 | -endif. 26 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_decode_udist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_DECODE_UDIST_H 10 | #define ETF_DECODE_UDIST_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | // Don't include "vterm_env.h", just reference the type here. 23 | typedef struct vterm_env_s vterm_env_t; 24 | 25 | /* Function Declarations */ 26 | 27 | extern int etf_decode_udist_control(ErlNifEnv *caller_env, vterm_env_t *vtenv, bool is_external, bool skip_slow_terms, vec_t *slice, 28 | udist_t *up, ERL_NIF_TERM *err_termp); 29 | 30 | /* Inline Function Definitions */ 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/src/erldist_filter_test.app.src: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%%----------------------------------------------------------------------------- 9 | {application, erldist_filter_test, [ 10 | {description, "erldist_filter_test: test modules for Erlang distribution filtering"}, 11 | {vsn, "1.0.0"}, 12 | {mod, {erldist_filter_test_app, []}}, 13 | {modules, []}, 14 | {registered, []}, 15 | %% NOTE: Remember to sync changes to `applications` to 16 | %% the BUCK file in the application's base folder 17 | {applications, [ 18 | kernel, 19 | stdlib, 20 | common_test, 21 | proper, 22 | erldist_filter 23 | ]}, 24 | {env, []} 25 | ]}. 26 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/config/edf_config_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CONFIG_IMPL_H 10 | #define EDF_CONFIG_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_config.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_config_get_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | extern ERL_NIF_TERM erldist_filter_nif_config_get_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 28 | extern ERL_NIF_TERM erldist_filter_nif_config_set_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 29 | 30 | /* Inline Function Definitions */ 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/erldist_filter_dist_util_tracer.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%%----------------------------------------------------------------------------- 9 | -module(erldist_filter_dist_util_tracer). 10 | -moduledoc """ 11 | 12 | """. 13 | -moduledoc #{author => ["Andrew Bennett "]}. 14 | -moduledoc #{created => "2025-08-11", modified => "2025-08-11"}. 15 | -moduledoc #{copyright => "Meta Platforms, Inc. and affiliates."}. 16 | -compile(warn_missing_spec_all). 17 | -oncall("whatsapp_clr"). 18 | 19 | %% Behaviour 20 | -callback shutdown(Module, Line, Data, Reason) -> Ignored when 21 | Module :: module(), Line :: non_neg_integer(), Data :: dynamic(), Reason :: dynamic(), Ignored :: no_return(). 22 | -------------------------------------------------------------------------------- /codegen/templates0/apps/erldist_filter/c_src/nif/channel/edf_channel_stats.c.j2: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #include "edf_channel_stats.h" 10 | 11 | static void edf_channel_stats_dop_init_empty(edf_channel_stats_dop_t *dop); 12 | 13 | void 14 | edf_channel_stats_init_empty(edf_channel_stats_t *stats) 15 | { 16 | /* clang-format off */ //- 17 | {% for stat in ctx.channel.stats_list %} 18 | {% if stat.c_kind == "uint64_t" %} 19 | stats->{{ stat.key }} = 0; 20 | {% else %} 21 | (void)edf_channel_stats_dop_init_empty(&stats->{{ stat.key }}); 22 | {% endif %} 23 | {% endfor %} 24 | /* clang-format on */ //- 25 | return; 26 | } 27 | 28 | inline void 29 | edf_channel_stats_dop_init_empty(edf_channel_stats_dop_t *dop) 30 | { 31 | dop->seen = 0; 32 | dop->emit = 0; 33 | dop->drop = 0; 34 | return; 35 | } 36 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | defmodule ErldistFilterElixirTests.MixProject do 8 | use Mix.Project 9 | 10 | def project() do 11 | [ 12 | app: :erldist_filter_elixir_tests, 13 | version: "1.28.3", 14 | elixir: "~> 1.17", 15 | deps: deps(), 16 | elixirc_paths: elixirc_paths(Mix.env()) 17 | ] 18 | end 19 | 20 | def application() do 21 | [extra_applications: [:logger, :observer, :runtime_tools, :erldist_filter, :erldist_filter_test]] 22 | end 23 | 24 | # Run "mix help deps" to learn about dependencies. 25 | defp deps() do 26 | [ 27 | {:erldist_filter, path: "apps/erldist_filter", override: true}, 28 | {:erldist_filter_test, path: "apps/erldist_filter_test", override: true} 29 | ] 30 | end 31 | 32 | defp elixirc_paths(:test), do: ["lib", "test/support"] 33 | defp elixirc_paths(_), do: ["lib"] 34 | end 35 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/config/edf_config.c: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT: this file was generated by 'just codegen' 2 | // @generated SignedSource<<0e2280aa15c536ff9145c99289c6d4ee>> 3 | /* 4 | * Copyright (c) Meta Platforms, Inc. and affiliates. 5 | * Copyright (c) WhatsApp LLC 6 | * 7 | * This source code is licensed under the MIT license found in the 8 | * LICENSE.md file in the root directory of this source tree. 9 | */ 10 | 11 | #include "edf_config.h" 12 | 13 | /* Global Variables */ 14 | 15 | static edf_config_t edf_config_internal = { 16 | .compact_fragments = false, 17 | .deep_packet_inspection = false, 18 | .logging = false, 19 | .otp_name_blocklist = false, 20 | .redirect_dist_operations = false, 21 | .untrusted = false, 22 | }; 23 | edf_config_t *edf_config_global = &edf_config_internal; 24 | 25 | /* Function Definitions */ 26 | 27 | int 28 | edf_config_load(ErlNifEnv *env) 29 | { 30 | int retval = 0; 31 | (void)env; 32 | return retval; 33 | } 34 | 35 | void 36 | edf_config_unload(ErlNifEnv *env) 37 | { 38 | (void)env; 39 | return; 40 | } 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `erldist_filter` 2 | 3 | [![Build Status](https://github.com/WhatsApp/erldist_filter/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/WhatsApp/erldist_filter/actions) [![Hex.pm](https://img.shields.io/hexpm/v/erldist_filter.svg)](https://hex.pm/packages/erldist_filter) 4 | 5 | `erldist_filter` NIF for filtering and logging [Erlang Dist Protocol](https://www.erlang.org/doc/apps/erts/erl_dist_protocol.html) messages. 6 | 7 | See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out. 8 | 9 | ## Installation 10 | 11 | Add `erldist_filter` to your project's dependencies in `mix.exs` 12 | 13 | ```elixir 14 | defp deps() do 15 | [ 16 | {:erldist_filter, "~> 1.28"} 17 | ] 18 | end 19 | ``` 20 | 21 | Add `erldist_filter` to your project's dependencies in your `Makefile` for [`erlang.mk`](https://github.com/ninenines/erlang.mk) or the following to your `rebar.config` 22 | 23 | ```erlang 24 | {deps, [ 25 | {erldist_filter, "~> 1.28"} 26 | ]}. 27 | ``` 28 | 29 | ## License 30 | 31 | `erldist_filter` is MIT licensed, as found in the [LICENSE](LICENSE.md) file. 32 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/channel/edf_channel_inspect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CHANNEL_INSPECT_H 10 | #define EDF_CHANNEL_INSPECT_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_channel.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern int edf_channel_inspect_atom_cache(ErlNifEnv *env, edf_atom_cache_t *cache, ERL_NIF_TERM *termp); 27 | extern int edf_channel_inspect_entry(ErlNifEnv *env, edf_channel_t *channel, ERL_NIF_TERM *termp); 28 | extern int edf_channel_inspect_rx(ErlNifEnv *env, edf_channel_t *channel, ERL_NIF_TERM *termp); 29 | extern int edf_channel_inspect_stats(ErlNifEnv *env, edf_channel_stats_t *stats, ERL_NIF_TERM *termp); 30 | 31 | /* Inline Function Definitions */ 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /justfiles/python.just: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | [linux] 8 | setup-python: 9 | # Use the latest available pip 10 | pip install --upgrade pip 11 | # Use the latest available poetry 12 | pip install --upgrade poetry 13 | # Setup poetry export plugin 14 | poetry self add poetry-plugin-export 15 | # Ensure that virtualenvs are installed in .venv 16 | poetry config virtualenvs.in-project true 17 | # Setup poetry shell plugin 18 | poetry self add poetry-plugin-shell 19 | 20 | [linux] 21 | [working-directory: '/project/codegen'] 22 | poetry-install: 23 | poetry install --no-interaction 24 | 25 | [linux] 26 | [working-directory: '/project/codegen'] 27 | poetry-lock: 28 | poetry lock --no-interaction 29 | poetry install --no-interaction 30 | (poetry export --no-interaction --without-hashes --without-urls --format=requirements.txt | awk '{ print $1 }' FS=';' | awk '{$1=$1};1') > requirements.txt 31 | -------------------------------------------------------------------------------- /justfiles/docker.just: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | docker_image := "erlang-edf-codegen" 8 | 9 | [macos] 10 | _docker-exec +args: docker-build 11 | docker run --rm --volume $(pwd):/project {{docker_image}} {{args}} 12 | 13 | [macos] 14 | _docker-interactive +args: docker-build 15 | docker run --rm --volume $(pwd):/project -it {{docker_image}} {{args}} 16 | 17 | [group('docker')] 18 | [macos] 19 | docker-build: 20 | docker build -f ./codegen/Dockerfile -t {{docker_image}} . 21 | 22 | [group('docker')] 23 | [macos] 24 | docker-codegen: 25 | @just _docker-exec just codegen 26 | 27 | [group('docker')] 28 | [macos] 29 | docker-format: 30 | @just _docker-exec just format 31 | 32 | [group('docker')] 33 | [macos] 34 | docker-lock: 35 | @just _docker-exec just poetry-lock 36 | 37 | [group('docker')] 38 | [macos] 39 | docker-shell: 40 | @just _docker-interactive /bin/bash 41 | 42 | [group('docker')] 43 | [macos] 44 | docker-sign: 45 | @just _docker-exec just sign 46 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_the_non_value.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_the_non_value). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | 18 | %% API 19 | -export([ 20 | new/0 21 | ]). 22 | 23 | %% Types 24 | -type t() :: #vterm_the_non_value{}. 25 | 26 | -export_type([ 27 | t/0 28 | ]). 29 | 30 | %%%============================================================================= 31 | %%% API functions 32 | %%%============================================================================= 33 | 34 | -spec new() -> T when T :: t(). 35 | new() -> 36 | #vterm_the_non_value{}. 37 | -------------------------------------------------------------------------------- /codegen/templates0/apps/erldist_filter/c_src/nif/channel/edf_channel_stats.h.j2: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CHANNEL_STATS_H 10 | #define EDF_CHANNEL_STATS_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "../erldist_filter_nif.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | typedef struct edf_channel_stats_s edf_channel_stats_t; 23 | typedef struct edf_channel_stats_dop_s edf_channel_stats_dop_t; 24 | 25 | struct edf_channel_stats_dop_s { 26 | uint64_t seen; 27 | uint64_t emit; 28 | uint64_t drop; 29 | }; 30 | 31 | struct edf_channel_stats_s { 32 | /* clang-format off */ //- 33 | {% for stat in ctx.channel.stats_list %} 34 | {{ stat.c_kind }} {{ stat.key }}; 35 | {% endfor %} /* clang-format on */ //- 36 | }; 37 | 38 | /* Function Declarations */ 39 | 40 | extern void edf_channel_stats_init_empty(edf_channel_stats_t *stats); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | =========== 3 | 4 | Copyright (c) Meta Platforms, Inc. and affiliates. 5 | 6 | Copyright (c) WhatsApp LLC 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | -------------------------------------------------------------------------------- /apps/erldist_filter/include/erldist_filter_otp_27_net_address.hrl: -------------------------------------------------------------------------------- 1 | %% NOTE: This file is imported from https://raw.githubusercontent.com/erlang/otp/refs/heads/maint-27/lib/kernel/include/net_address.hrl 2 | %% @oncall whatsapp_clr 3 | 4 | %% 5 | %% %CopyrightBegin% 6 | %% 7 | %% Copyright Ericsson AB 1997-2016. All Rights Reserved. 8 | %% 9 | %% Licensed under the Apache License, Version 2.0 (the "License"); 10 | %% you may not use this file except in compliance with the License. 11 | %% You may obtain a copy of the License at 12 | %% 13 | %% http://www.apache.org/licenses/LICENSE-2.0 14 | %% 15 | %% Unless required by applicable law or agreed to in writing, software 16 | %% distributed under the License is distributed on an "AS IS" BASIS, 17 | %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | %% See the License for the specific language governing permissions and 19 | %% limitations under the License. 20 | %% 21 | %% %CopyrightEnd% 22 | %% 23 | 24 | %% Generic address format 25 | 26 | -record(net_address, 27 | { 28 | address, %% opaque address 29 | host, %% host name 30 | protocol, %% protocol 31 | family %% address family 32 | }). 33 | -------------------------------------------------------------------------------- /codegen/templates1/apps/erldist_filter/c_src/nif/erldist_filter_nif_atoms.h.j2: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ERLDIST_FILTER_NIF_ATOMS_H 10 | #define ERLDIST_FILTER_NIF_ATOMS_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | 18 | /* Type Definitions */ 19 | 20 | typedef struct erldist_filter_nif_atom_table_s erldist_filter_nif_atom_table_t; 21 | 22 | struct erldist_filter_nif_atom_table_s { 23 | /* clang-format off */ //- 24 | {%- for atom in ctx.nif.atoms_list %} 25 | ERL_NIF_TERM ATOM_{{ atom.name }}; 26 | {% endfor %} 27 | /* clang-format on */ //- 28 | }; 29 | 30 | /* Global Variables */ 31 | 32 | extern erldist_filter_nif_atom_table_t *erldist_filter_nif_atom_table; 33 | 34 | /* Macros */ 35 | 36 | #define ATOM(Id) erldist_filter_nif_atom_table->ATOM_##Id 37 | 38 | /* Function Declarations */ 39 | 40 | extern void erldist_filter_nif_make_atoms(ErlNifEnv *env); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.28.3 (2025-09-05) 4 | 5 | * Minor fix: remove unnecessary codesigning. 6 | 7 | ## 1.28.2 (2025-09-05) 8 | 9 | * Minor fix: codesigning and formatting. 10 | 11 | ## 1.28.1 (2025-09-05) 12 | 13 | * Use stricter `CFLAGS` and `CXXFLAGS` for warnings. 14 | * Fix warnings exposed. 15 | * Use codegen version instead of unstable builtin macros. 16 | * Detect whether `clang` is being used and add warning flags if applicable. 17 | * Update [`elp` (erlang-language-platform) to 2025-09-01](https://github.com/WhatsApp/erlang-language-platform/releases/tag/2025-09-01). 18 | * Fix typing errors found from `make lint`. 19 | 20 | ## 1.28.0 (2025-09-04) 21 | 22 | * Add support for Erlang/OTP 27 and 28. 23 | * Support `DOP_ALTACT_SIG_SEND` dist operation. 24 | * Add `otp_name_blocklist` configuration option to block OTP named processes. 25 | * Fix 0-byte tick crash when connection is idle. 26 | * Improve test reliability. 27 | 28 | ## 1.1.0 (2023-10-04) 29 | 30 | * Added "fastpath" and "slowpath" branching for faster filtering of smaller messages. 31 | * I/O request and reply are dropped by default now (may be allowed by enabled `untrusted` mode with a custom handler). 32 | 33 | ## 1.0.0 (2023-09-07) 34 | 35 | * Initial release. 36 | -------------------------------------------------------------------------------- /apps/erldist_filter/include/erldist_filter_otp_28_net_address.hrl: -------------------------------------------------------------------------------- 1 | %% NOTE: This file is imported from https://raw.githubusercontent.com/erlang/otp/refs/heads/maint-28/lib/kernel/include/net_address.hrl 2 | %% @oncall whatsapp_clr 3 | 4 | %% 5 | %% %CopyrightBegin% 6 | %% 7 | %% SPDX-License-Identifier: Apache-2.0 8 | %% 9 | %% Copyright Ericsson AB 1997-2025. All Rights Reserved. 10 | %% 11 | %% Licensed under the Apache License, Version 2.0 (the "License"); 12 | %% you may not use this file except in compliance with the License. 13 | %% You may obtain a copy of the License at 14 | %% 15 | %% http://www.apache.org/licenses/LICENSE-2.0 16 | %% 17 | %% Unless required by applicable law or agreed to in writing, software 18 | %% distributed under the License is distributed on an "AS IS" BASIS, 19 | %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | %% See the License for the specific language governing permissions and 21 | %% limitations under the License. 22 | %% 23 | %% %CopyrightEnd% 24 | %% 25 | 26 | %% Generic address format 27 | 28 | -record(net_address, 29 | { 30 | address, %% opaque address 31 | host, %% host name 32 | protocol, %% protocol 33 | family %% address family 34 | }). 35 | -------------------------------------------------------------------------------- /apps/erldist_filter/rebar.config: -------------------------------------------------------------------------------- 1 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 2 | %%% Copyright (c) WhatsApp LLC 3 | %%% 4 | %%% This source code is licensed under the MIT license found in the 5 | %%% LICENSE.md file in the root directory of this source tree. 6 | %%% % @format 7 | {erl_opts, [debug_info]}. 8 | 9 | {deps, []}. 10 | 11 | {pre_hooks, [ 12 | {"(linux|darwin|solaris)", compile, "make -j -C c_src"}, 13 | {"(freebsd)", compile, "gmake -j -C c_src"}, 14 | {"(win32)", compile, "cd c_src && nmake /F Makefile.win"} 15 | ]}. 16 | 17 | {post_hooks, [ 18 | {"(linux|darwin|solaris)", clean, "make -C c_src clean distclean"}, 19 | {"(freebsd)", clean, "gmake -C c_src clean distclean"}, 20 | {"(win32)", compile, "cd c_src && nmake /F Makefile.win clean distclean"} 21 | ]}. 22 | 23 | {shell, 24 | % {config, "config/sys.config"}, 25 | [{apps, [erldist_filter]}]}. 26 | 27 | {ex_doc, [ 28 | {source_url, <<"https://github.com/WhatsApp/erldist_filter">>}, 29 | {extras, [ 30 | <<"README.md">>, 31 | <<"LICENSE.md">>, 32 | <<"../../CHANGELOG.md">>, 33 | <<"../../CODE_OF_CONDUCT.md">>, 34 | <<"../../CONTRIBUTING.md">> 35 | ]}, 36 | {main, <<"readme">>} 37 | ]}. 38 | 39 | {hex, [{doc, ex_doc}]}. 40 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/primitive/memset_explicit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef CORE_MEMSET_EXPLICIT_H 10 | #define CORE_MEMSET_EXPLICIT_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | 18 | /* Part of C23, but not available everywhere, yet. */ 19 | 20 | #ifndef memset_explicit 21 | #define memset_explicit(dest, ch, count) __core_memset_explicit(dest, ch, count) 22 | 23 | /* Function Declarations */ 24 | 25 | static void *__core_memset_explicit(void *dest, int ch, size_t count); 26 | 27 | /* Inline Function Definitions */ 28 | 29 | inline void * 30 | __core_memset_explicit(void *dest, int ch, size_t count) 31 | { 32 | // Use builtin memset function to set the memory. 33 | (void)memset(dest, ch, count); 34 | // avoid dead store elimination 35 | // The asm itself should also be sufficient to behave as a compiler barrier. 36 | __asm__ __volatile__("" ::"r"(dest) : "memory"); 37 | return dest; 38 | } 39 | 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /apps/erldist_filter/rebar.config.script: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%%----------------------------------------------------------------------------- 9 | 10 | AppDir = filename:dirname(SCRIPT), 11 | SourceDir = rebar_file_utils:absolute_path(filename:join([AppDir, "src"])), 12 | AppSrcFile = rebar_file_utils:absolute_path(filename:join([SourceDir, "erldist_filter.app.src"])), 13 | 14 | {ok, [{application, erldist_filter, Desc}]} = file:consult(AppSrcFile), 15 | {vsn, Vsn} = lists:keyfind(vsn, 1, Desc), 16 | SourceUrlPattern = erlang:iolist_to_binary( 17 | io_lib:format("https://github.com/WhatsApp/erldist_filter/blob/v~ts/apps/erldist_filter/%{path}#L%{line}", [Vsn]) 18 | ), 19 | 20 | Config1 = CONFIG, 21 | {value, {ex_doc, ExDocConfig1}, Config2} = lists:keytake(ex_doc, 1, Config1), 22 | ExDocConfig2 = lists:keystore(source_url_pattern, 1, ExDocConfig1, {source_url_pattern, SourceUrlPattern}), 23 | Config3 = lists:keystore(ex_doc, 1, Config2, {ex_doc, ExDocConfig2}), 24 | 25 | Config3. 26 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/primitive/unreachable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef CORE_UNREACHABLE_H 10 | #define CORE_UNREACHABLE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | // unreachable() is part of the C23 standard 17 | // See https://en.cppreference.com/w/c/program/unreachable 18 | #include 19 | 20 | #if !defined(unreachable) 21 | // Uses compiler specific extensions if possible. 22 | #ifdef __GNUC__ // GCC, Clang, ICC 23 | #define unreachable() (__builtin_unreachable()) 24 | #elif defined(_MSC_VER) // MSVC 25 | #define unreachable() (__assume(false)) 26 | #else 27 | // Even if no extension is used, undefined behavior is still raised by 28 | // the empty function body and the noreturn attribute. 29 | // The external definition of unreachable_impl must be emitted in a separated TU 30 | // due to the rule for inline functions in C. 31 | [[noreturn]] inline void 32 | unreachable_impl() 33 | { 34 | } 35 | #define unreachable() (unreachable_impl()) 36 | #endif 37 | #endif 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/blocklist/edf_otp_name_blocklist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_OTP_NAME_BLOCKLIST_H 10 | #define EDF_OTP_NAME_BLOCKLIST_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "../erldist_filter_nif.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | typedef struct edf_otp_name_blocklist_s edf_otp_name_blocklist_t; 23 | 24 | /* Global Declarations */ 25 | 26 | extern edf_otp_name_blocklist_t *edf_otp_name_blocklist; 27 | 28 | /* Function Declarations */ 29 | 30 | extern int edf_otp_name_blocklist_load(ErlNifEnv *env); 31 | extern void edf_otp_name_blocklist_unload(ErlNifEnv *env); 32 | extern bool edf_otp_name_is_blocked(ERL_NIF_TERM name); 33 | extern ERL_NIF_TERM erldist_filter_nif_otp_name_blocklist_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 34 | extern ERL_NIF_TERM erldist_filter_nif_otp_name_is_blocked_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 35 | 36 | /* Inline Function Definitions */ 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /codegen/pyproject.toml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | [project] 8 | name = "erlang-edf-codegen" 9 | version = "0.1.0" 10 | description = "Generate C and Erlang code from YAML configuration using Jinja2." 11 | authors = [ 12 | {name = "Andrew Bennett", email = "potatosaladx@meta.com"} 13 | ] 14 | license = {text = "MIT"} 15 | readme = "README.md" 16 | requires-python = ">=3.13" 17 | dependencies = [ 18 | "click (>=8.2.1,<9.0.0)", 19 | "jinja2 (>=3.1.6,<4.0.0)", 20 | "pyyaml (>=6.0.2,<7.0.0)", 21 | "pydantic (>=2.11.7,<3.0.0)", 22 | "jsonschema (>=4.25.0,<5.0.0)" 23 | ] 24 | 25 | [project.scripts] 26 | erlang_edf_codegen = "erlang_edf_codegen.__main__:main" 27 | 28 | [build-system] 29 | requires = ["poetry-core>=2.1.3,<3.0.0"] 30 | build-backend = "poetry.core.masonry.api" 31 | 32 | [tool.black] 33 | line-length = 132 34 | 35 | [tool.poetry] 36 | packages = [{include = "erlang_edf_codegen", from = "src"}] 37 | 38 | [tool.poetry.group.dev.dependencies] 39 | black = "^25.1.0" 40 | pytest = "^8.4.1" 41 | 42 | [tool.pytest.ini_options] 43 | testpaths = ["tests"] 44 | python_files = ["test_*.py"] 45 | -------------------------------------------------------------------------------- /codegen/templates1/apps/erldist_filter/c_src/nif/erldist_filter_nif_atoms.c.j2: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #include "erldist_filter_nif_atoms.h" 10 | 11 | /* Global Variables */ 12 | 13 | static erldist_filter_nif_atom_table_t erldist_filter_nif_atom_table_internal; 14 | erldist_filter_nif_atom_table_t *erldist_filter_nif_atom_table = &erldist_filter_nif_atom_table_internal; 15 | 16 | /* Function Definitions */ 17 | 18 | void 19 | erldist_filter_nif_make_atoms(ErlNifEnv *env) 20 | { 21 | #define MAKE_ATOM(Id, Value) \ 22 | { \ 23 | erldist_filter_nif_atom_table->ATOM_##Id = enif_make_atom(env, Value); \ 24 | } 25 | /* clang-format off */ //- 26 | {% for atom in ctx.nif.atoms_list %} 27 | MAKE_ATOM({{atom.name}}, "{{ atom.name }}"); 28 | {% endfor %} 29 | /* clang-format on */ //- 30 | #undef MAKE_ATOM 31 | } 32 | -------------------------------------------------------------------------------- /codegen/src/erlang_edf_codegen/context/nif.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | """Context NIF models for codegen.""" 8 | import bisect 9 | from abc import abstractclassmethod 10 | from collections import OrderedDict 11 | from dataclasses import dataclass, field 12 | from typing import Any, Iterator, Optional 13 | 14 | from . import Atom, Context 15 | 16 | 17 | @dataclass 18 | class NIF: 19 | ctx: Context = field(repr=False) 20 | # _raw_config: Any = field(repr=False) 21 | atoms_dict: OrderedDict[str, Atom] = field(init=False) 22 | atoms_list: list[Atom] = field(init=False) 23 | # stats: "Stats" = field(init=False) 24 | 25 | def __post_init__(self) -> None: 26 | # from .stats import Stats 27 | 28 | self.atoms_dict = OrderedDict() 29 | self.atoms_list = [] 30 | # self.stats = Stats(self, self._raw_config["stats"]) 31 | 32 | def make_atom(self, name: str) -> Atom: 33 | if name not in self.atoms_dict: 34 | atom: Atom = Atom(self.ctx, name) 35 | self.atoms_dict[name] = atom 36 | bisect.insort(self.atoms_list, atom, key=lambda x: x.name) 37 | return self.atoms_dict[name] 38 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/vterm/vterm_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef VTERM_IMPL_H 10 | #define VTERM_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "vterm.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_dist_ext_to_vdist_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | extern ERL_NIF_TERM erldist_filter_nif_dist_ext_to_vterm_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 28 | extern ERL_NIF_TERM erldist_filter_nif_dist_ext_to_vterm_3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 29 | extern ERL_NIF_TERM erldist_filter_nif_dist_int_to_vdist_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 30 | extern ERL_NIF_TERM erldist_filter_nif_dist_int_to_vterm_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 31 | extern ERL_NIF_TERM erldist_filter_nif_dist_int_to_vterm_3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 32 | 33 | /* Inline Function Definitions */ 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/channel/edf_channel_recv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CHANNEL_RECV_H 10 | #define EDF_CHANNEL_RECV_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_channel.h" 17 | #include "../trap/edf_trap.h" 18 | #include "../etf/etf_decode.h" 19 | #include "../etf/etf_encode.h" 20 | #include "../avec.h" 21 | 22 | /* Macro Definitions */ 23 | 24 | /* Type Definitions */ 25 | 26 | typedef struct edf_channel_recv_trap_s edf_channel_recv_trap_t; 27 | 28 | struct edf_channel_recv_trap_s { 29 | edf_trap_t super; 30 | edf_channel_resource_t *resource; 31 | edf_channel_t *channel; 32 | avec_t actions; 33 | edf_external_t *external; 34 | size_t fragment_index; 35 | size_t packet_count; 36 | }; 37 | 38 | /* Global Declarations */ 39 | 40 | /* Function Declarations */ 41 | 42 | extern ERL_NIF_TERM edf_channel_recv_trap_open(ErlNifEnv *env, edf_channel_resource_t *resource, edf_channel_t *channel, 43 | edf_channel_recv_trap_t **trapp); 44 | 45 | /* Inline Function Definitions */ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_pid.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_pid). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | 18 | -export([ 19 | sequence_id/1 20 | ]). 21 | 22 | -spec sequence_id(vterm:pid_t()) -> non_neg_integer(). 23 | sequence_id(#vterm_new_pid_ext{id = Id, serial = Serial, creation = Creation}) -> 24 | hash_u64(Id, Serial, Creation); 25 | sequence_id(#vterm_pid_ext{id = Id, serial = Serial, creation = Creation}) -> 26 | hash_u64(Id, Serial, Creation). 27 | 28 | -spec hash_u64(non_neg_integer(), non_neg_integer(), non_neg_integer()) -> non_neg_integer(). 29 | hash_u64(Id, Serial, Creation) -> 30 | ((erlang:phash2({Creation, Serial, Id}, 16#FFFFFFFF) bsl 32) bor erlang:phash2({Id, Serial, Creation}, 16#FFFFFFFF)) band 31 | 16#FFFFFFFFFFFFFFFF. 32 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/logger/edf_logger_queue_recv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_LOGGER_QUEUE_RECV_H 10 | #define EDF_LOGGER_QUEUE_RECV_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_logger.h" 17 | #include "../trap/edf_trap.h" 18 | 19 | /* Macro Definitions */ 20 | 21 | /* Type Definitions */ 22 | 23 | typedef struct edf_logger_queue_recv_trap_s edf_logger_queue_recv_trap_t; 24 | 25 | struct edf_logger_queue_recv_trap_s { 26 | edf_trap_t super; 27 | edf_logger_resource_t *resource; 28 | edf_logger_t *logger; 29 | ipc_batch_t *batch; 30 | }; 31 | 32 | /* Global Declarations */ 33 | 34 | /* Function Declarations */ 35 | 36 | extern int edf_logger_queue_recv(ErlNifEnv *env, edf_logger_resource_t *resource, edf_logger_t *logger, ipc_batch_t *batch, 37 | ERL_NIF_TERM *out_term); 38 | extern ERL_NIF_TERM edf_logger_queue_recv_trap_open(ErlNifEnv *env, edf_logger_resource_t *resource, edf_logger_t *logger, 39 | ipc_batch_t *batch, edf_logger_queue_recv_trap_t **trapp); 40 | 41 | /* Inline Function Definitions */ 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build/ 3 | /apps/erldist_filter/_build/ 4 | /apps/erldist_filter_test/_build/ 5 | 6 | # If you run "mix test --cover", coverage assets end up here. 7 | /cover/ 8 | 9 | # The directory Mix downloads your dependencies sources to. 10 | /deps/ 11 | /apps/erldist_filter/deps/ 12 | /apps/erldist_filter_test/deps/ 13 | 14 | # Where third-party dependencies like ExDoc output generated docs. 15 | /doc/ 16 | /apps/erldist_filter/doc/ 17 | /apps/erldist_filter_test/doc/ 18 | 19 | # Ignore .fetch files in case you like to edit your project deps locally. 20 | /.fetch 21 | 22 | # If the VM crashes, it generates a dump, let's ignore it too. 23 | erl_crash.dump 24 | 25 | # Also ignore archive artifacts (built via "mix archive.build"). 26 | *.ez 27 | 28 | # Ignore package tarball (built via "mix hex.build"). 29 | erldist_filter-*.tar 30 | erldist_filter_test-*.tar 31 | 32 | # Temporary files, for example, from tests. 33 | /tmp/ 34 | 35 | # rebar3 and erlang.mk related files. 36 | .rebar3 37 | _* 38 | .eunit 39 | *.o 40 | *.beam 41 | *.plt 42 | *.swp 43 | *.swo 44 | .erlang.cookie 45 | ebin 46 | log 47 | erl_crash.dump 48 | .rebar 49 | logs 50 | _build 51 | .idea 52 | .vscode 53 | *.iml 54 | rebar3.crashdump 55 | *~ 56 | /.elixir_ls/ 57 | /.erlang.mk/ 58 | /apps/erldist_filter/c_src/env.mk 59 | /apps/erldist_filter/priv/*.dll 60 | /apps/erldist_filter/priv/*.dylib 61 | /apps/erldist_filter/priv/*.so 62 | /erlfmt 63 | /rebar3 64 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/logger/edf_logger_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_LOGGER_IMPL_H 10 | #define EDF_LOGGER_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_logger.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_logger_open_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | extern ERL_NIF_TERM erldist_filter_nif_logger_close_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 28 | extern ERL_NIF_TERM erldist_filter_nif_logger_inspect_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 29 | extern ERL_NIF_TERM erldist_filter_nif_logger_list_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 30 | extern ERL_NIF_TERM erldist_filter_nif_logger_recv_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 31 | extern ERL_NIF_TERM erldist_filter_nif_logger_set_capacity_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 32 | extern ERL_NIF_TERM erldist_filter_nif_logger_set_controlling_process_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 33 | 34 | /* Inline Function Definitions */ 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_reference.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_reference). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | 18 | -export([ 19 | sequence_id/1 20 | ]). 21 | 22 | -spec sequence_id(vterm:reference_t()) -> non_neg_integer(). 23 | sequence_id(#vterm_newer_reference_ext{creation = Creation, ids = Ids}) -> 24 | hash_u64(Ids, Creation); 25 | sequence_id(#vterm_new_reference_ext{creation = Creation, ids = Ids}) -> 26 | hash_u64(Ids, Creation); 27 | sequence_id(#vterm_reference_ext{id = Id, creation = Creation}) -> 28 | hash_u64([Id], Creation). 29 | 30 | -spec hash_u64(Ids, Creation) -> Hash when 31 | Ids :: [non_neg_integer()], Creation :: non_neg_integer(), Hash :: non_neg_integer(). 32 | hash_u64(Ids, Creation) -> 33 | ((erlang:phash2({Creation, Ids}, 16#FFFFFFFF) bsl 32) bor erlang:phash2({Ids, Creation}, 16#FFFFFFFF)) band 34 | 16#FFFFFFFFFFFFFFFF. 35 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/erts/atom.h: -------------------------------------------------------------------------------- 1 | /* 2 | * %CopyrightBegin% 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Copyright Ericsson AB 1996-2025. All Rights Reserved. 7 | * Copyright (c) Meta Platforms, Inc. and affiliates. 8 | * Copyright (c) WhatsApp LLC 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * 22 | * %CopyrightEnd% 23 | */ 24 | 25 | #ifndef EDF_ERTS_ATOM_H 26 | #define EDF_ERTS_ATOM_H 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #include 33 | 34 | #include "../erl_nif_trampoline.h" 35 | 36 | /// See 37 | /// [erts/emulator/beam/atom.h](https://github.com/erlang/otp/blob/OTP-28.0.2/erts/emulator/beam/atom.h) 38 | /// in the Erlang/OTP source code. 39 | 40 | #define MAX_ATOM_CHARACTERS 255 41 | #define MAX_ATOM_SZ_FROM_LATIN1 (2 * MAX_ATOM_CHARACTERS) 42 | #define MAX_ATOM_SZ_LIMIT (4 * MAX_ATOM_CHARACTERS) /* theoretical byte limit */ 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_header_encode.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_header_encode). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | 18 | -callback encode_header(T :: vdist:header_t()) -> binary(). 19 | 20 | -export([ 21 | encode_header/1 22 | ]). 23 | 24 | %%%============================================================================= 25 | %%% API functions 26 | %%%============================================================================= 27 | 28 | -spec encode_header(T :: vdist:header_t()) -> binary(). 29 | encode_header(T = #vdist_fragment_cont{}) -> 30 | vdist_fragment_cont:encode_header(T); 31 | encode_header(T = #vdist_fragment_header{}) -> 32 | vdist_fragment_header:encode_header(T); 33 | encode_header(T = #vdist_normal_header{}) -> 34 | vdist_normal_header:encode_header(T); 35 | encode_header(T = #vdist_pass_through_header{}) -> 36 | vdist_pass_through_header:encode_header(T). 37 | -------------------------------------------------------------------------------- /apps/erldist_filter/include/vedf.hrl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% @author Andrew Bennett 10 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 11 | %%% @doc 12 | %%% 13 | %%% @end 14 | %%% Created : 19 Jun 2023 by Andrew Bennett 15 | %%%----------------------------------------------------------------------------- 16 | %% @oncall whatsapp_clr 17 | -ifndef(VEDF_HRL). 18 | 19 | -define(VEDF_HRL, 1). 20 | 21 | -record(vedf_channel, { 22 | packet_size = 0 :: 0 | 1 | 2 | 4 | 8, 23 | dflags = 0 :: vterm:u64(), 24 | rx_sequences = maps:new() :: #{vdist:sequence_id() => vdist_external:t()}, 25 | rx_atom_cache = undefined :: undefined | vdist_atom_cache:t(), 26 | rx_logger_time = 0 :: non_neg_integer(), 27 | rx_router_name :: atom(), 28 | rx_sort = 0 :: non_neg_integer(), 29 | compact_fragments = false :: boolean(), 30 | deep_packet_inspection = false :: boolean(), 31 | logging = false :: boolean(), 32 | otp_name_blocklist = false :: boolean(), 33 | redirect_dist_operations = false :: boolean(), 34 | sysname = undefined :: undefined | erldist_filter_nif:sysname(), 35 | untrusted = false :: boolean() 36 | }). 37 | 38 | -endif. 39 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/edf.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 17 Jun 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(edf). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | %% Internal API 17 | -export([ 18 | req/3 19 | ]). 20 | 21 | %%%============================================================================= 22 | %%% Internal API functions 23 | %%%============================================================================= 24 | 25 | -spec req(Sysname, {Module, FunctionName, Arity}, Arguments) -> no_return() | dynamic() when 26 | Sysname :: node(), 27 | Module :: module(), 28 | FunctionName :: atom(), 29 | Arity :: non_neg_integer(), 30 | Arguments :: [dynamic()]. 31 | req(Sysname, {Module, FunctionName, Arity}, Arguments) when length(Arguments) =:= Arity -> 32 | case erldist_filter:handler_get() of 33 | undefined -> 34 | erlang:apply(Module, FunctionName, Arguments); 35 | Handler when is_atom(Handler) -> 36 | Handler:spawn_request_init(Sysname, Module, FunctionName, Arguments) 37 | end. 38 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_pass_through_header.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_pass_through_header). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vdist_header_encode). 17 | 18 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 19 | % -include("erldist_filter_erts_dist.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/0, 25 | encode_header/1 26 | ]). 27 | 28 | %% Types 29 | -type t() :: #vdist_pass_through_header{}. 30 | 31 | -export_type([ 32 | t/0 33 | ]). 34 | 35 | %%%============================================================================= 36 | %%% API functions 37 | %%%============================================================================= 38 | 39 | -spec new() -> T when T :: t(). 40 | new() -> 41 | #vdist_pass_through_header{}. 42 | 43 | -spec encode_header(T) -> binary() when T :: t(). 44 | encode_header(#vdist_pass_through_header{}) -> 45 | <>. 46 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_rollback_atom_cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_ROLLBACK_ATOM_CACHE_H 10 | #define ETF_ROLLBACK_ATOM_CACHE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | enum etf_rollback_atom_cache_trap_state_t { 23 | ETF_ROLLBACK_ATOM_CACHE_TRAP_STATE_INIT = 0, 24 | ETF_ROLLBACK_ATOM_CACHE_TRAP_STATE_ALLOC, 25 | ETF_ROLLBACK_ATOM_CACHE_TRAP_STATE_ENCODE, 26 | ETF_ROLLBACK_ATOM_CACHE_TRAP_STATE_DONE, 27 | }; 28 | 29 | typedef struct etf_rollback_atom_cache_trap_s etf_rollback_atom_cache_trap_t; 30 | typedef enum etf_rollback_atom_cache_trap_state_t etf_rollback_atom_cache_trap_state_t; 31 | 32 | struct etf_rollback_atom_cache_trap_s { 33 | edf_trap_t super; 34 | etf_rollback_atom_cache_trap_state_t state; 35 | edf_external_t *external; 36 | int internal_index; 37 | size_t rollback_size; 38 | }; 39 | 40 | /* Function Declarations */ 41 | 42 | extern ERL_NIF_TERM etf_rollback_atom_cache_trap_open(ErlNifEnv *env, edf_external_t *external, 43 | etf_rollback_atom_cache_trap_t **trapp); 44 | 45 | /* Inline Function Definitions */ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /codegen/templates0/apps/erldist_filter/c_src/nif/config/edf_config.h.j2: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CONFIG_H 10 | #define EDF_CONFIG_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "../erldist_filter_nif.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | typedef struct edf_config_s edf_config_t; 23 | 24 | struct edf_config_s { 25 | /* clang-format off */ //- 26 | {% for field in ctx.config.fields_list %} 27 | alignas(uintptr_t) bool {{ field.key }}; 28 | {% endfor %} 29 | /* clang-format on */ //- 30 | }; 31 | 32 | /* Global Declarations */ 33 | 34 | extern edf_config_t *edf_config_global; 35 | 36 | /* Function Declarations */ 37 | 38 | extern int edf_config_load(ErlNifEnv *env); 39 | extern void edf_config_unload(ErlNifEnv *env); 40 | 41 | /* clang-format off */ //- 42 | {% for field in ctx.config.fields_list %} 43 | static bool edf_config_is_{{ field.key }}_enabled(void); 44 | {% endfor %} 45 | /* clang-format on */ //- 46 | 47 | /* Inline Function Definitions */ 48 | 49 | /* clang-format off */ //- 50 | {% for field in ctx.config.fields_list %} 51 | inline bool 52 | edf_config_is_{{ field.key }}_enabled(void) 53 | { 54 | return (edf_config_global->{{ field.key }}); 55 | } 56 | 57 | {% endfor %} 58 | /* clang-format on */ //- 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/channel/edf_channel_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CHANNEL_IMPL_H 10 | #define EDF_CHANNEL_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_channel.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_channel_open_5(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | extern ERL_NIF_TERM erldist_filter_nif_channel_close_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 28 | extern ERL_NIF_TERM erldist_filter_nif_channel_inspect_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 29 | extern ERL_NIF_TERM erldist_filter_nif_channel_list_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 30 | extern ERL_NIF_TERM erldist_filter_nif_channel_list_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 31 | extern ERL_NIF_TERM erldist_filter_nif_channel_recv_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 32 | extern ERL_NIF_TERM erldist_filter_nif_channel_set_controlling_process_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 33 | extern ERL_NIF_TERM erldist_filter_nif_channel_set_tracing_process_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 34 | 35 | /* Inline Function Definitions */ 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_atom). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | 18 | -export([ 19 | sequence_id/1 20 | ]). 21 | 22 | -spec sequence_id(T) -> non_neg_integer() when T :: vterm:atom_t(). 23 | sequence_id(#vterm_atom_cache_ref_resolved{term = Term}) -> 24 | sequence_id(vterm:expand_atom(Term)); 25 | sequence_id(#vterm_atom_ext{len = Len, name = Name}) -> 26 | hash_u64(Len, Name); 27 | sequence_id(#vterm_atom_utf8_ext{len = Len, name = Name}) -> 28 | hash_u64(Len, Name); 29 | sequence_id(#vterm_small_atom_ext{len = Len, name = Name}) -> 30 | hash_u64(Len, Name); 31 | sequence_id(#vterm_small_atom_utf8_ext{len = Len, name = Name}) -> 32 | hash_u64(Len, Name). 33 | 34 | -spec hash_u64(Len, Name) -> Hash when Len :: non_neg_integer(), Name :: binary(), Hash :: non_neg_integer(). 35 | hash_u64(Len, Name) -> 36 | ((erlang:phash2({Name, Len}, 16#FFFFFFFF) bsl 32) bor erlang:phash2({Len, Name}, 16#FFFFFFFF)) band 37 | 16#FFFFFFFFFFFFFFFF. 38 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom_cache_ref.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_atom_cache_ref). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | 18 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 19 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 20 | 21 | %% API 22 | -export([ 23 | new/1, 24 | internal_vterm_to_binary/2 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vterm_atom_cache_ref{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(Index) -> T when Index :: vterm:u8(), T :: t(). 39 | new(Index) when ?is_u8(Index) -> 40 | #vterm_atom_cache_ref{index = Index}. 41 | 42 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 43 | internal_vterm_to_binary(#vterm_atom_cache_ref{index = Index}, #{allow_atom_cache_refs := true}) -> 44 | <>. 45 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_nil_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_nil_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/0, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_nil_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new() -> T when T :: t(). 41 | new() -> 42 | #vterm_nil_ext{}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_nil_ext{}, _Opts) -> 46 | <>. 47 | 48 | -spec simplify(T) -> [] when T :: t(). 49 | simplify(#vterm_nil_ext{}) -> 50 | []. 51 | -------------------------------------------------------------------------------- /codegen/src/erlang_edf_codegen/context/dpi.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | """Context Test models for codegen.""" 8 | import bisect 9 | from abc import abstractclassmethod 10 | from collections import OrderedDict 11 | from dataclasses import dataclass, field 12 | import re 13 | from typing import Any, Iterator, Optional, Union 14 | 15 | from ..schema import ( 16 | Dpi as DpiSchema, 17 | ) 18 | from . import Atom, Context 19 | 20 | 21 | @dataclass 22 | class Dpi: 23 | ctx: Context = field(repr=False) 24 | schema: DpiSchema = field(repr=False) 25 | otp_name_blockdict: OrderedDict[str, "DpiOtpNameBlock"] = field(init=False) 26 | otp_name_blocklist: list["DpiOtpNameBlock"] = field(init=False) 27 | 28 | def __post_init__(self) -> None: 29 | self.otp_name_blockdict = OrderedDict() 30 | self.otp_name_blocklist = [] 31 | 32 | for otp_name_block in self.schema.otp_name_blocklist: 33 | if otp_name_block in self.otp_name_blockdict: 34 | raise ValueError(f"Duplicate DpiOtpNameBlock key: {otp_name_block}") 35 | child: "DpiOtpNameBlock" = DpiOtpNameBlock(ctx=self.ctx, schema=otp_name_block) 36 | self.otp_name_blockdict[child.key] = child 37 | self.otp_name_blocklist.append(child) 38 | 39 | 40 | @dataclass 41 | class DpiOtpNameBlock: 42 | ctx: Context = field(repr=False) 43 | schema: str = field(repr=True) 44 | 45 | @property 46 | def key(self) -> str: 47 | return self.schema 48 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/erldist_filter_app.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 10 Aug 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(erldist_filter_app). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(application). 17 | 18 | %% application callbacks 19 | -export([ 20 | start/2, 21 | stop/1 22 | ]). 23 | 24 | %%%============================================================================= 25 | %%% application callbacks 26 | %%%============================================================================= 27 | 28 | -spec start(StartType, StartArgs) -> {ok, Pid} | {ok, Pid, State} | {error, Reason} when 29 | StartType :: application:start_type(), 30 | StartArgs :: term(), 31 | Pid :: pid(), 32 | State :: term(), 33 | Reason :: term(). 34 | start(_StartType, _StartArgs) -> 35 | {ok, SupPid} = erldist_filter_sup:start_link(), 36 | {ok, SupPid}. 37 | 38 | -spec stop(State) -> Ignored when 39 | State :: term(), 40 | Ignored :: term(). 41 | stop(_State) -> 42 | ok. 43 | 44 | %%%----------------------------------------------------------------------------- 45 | %%% Internal functions 46 | %%%----------------------------------------------------------------------------- 47 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/channel/edf_external_sequence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_EXTERNAL_SEQUENCE_H 10 | #define EDF_EXTERNAL_SEQUENCE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_external.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Function Declarations */ 23 | 24 | static void edf_external_sequence_init_empty(edf_external_t *ext); 25 | static bool edf_external_sequence_is_linked(edf_external_t *ext); 26 | extern void edf_external_sequence_destroy_all(edf_external_t **root); 27 | extern edf_external_t *edf_external_sequence_lookup(edf_external_t *root, uint64_t sequence_id); 28 | extern edf_external_t *edf_external_sequence_lookup_insert(edf_external_t **root, edf_external_t *ext); 29 | extern void edf_external_sequence_unlink(edf_external_t **root, edf_external_t *ext); 30 | 31 | /* Inline Function Definitions */ 32 | 33 | inline void 34 | edf_external_sequence_init_empty(edf_external_t *ext) 35 | { 36 | ext->_sequence.parent = NULL; 37 | ext->_sequence.left = NULL; 38 | ext->_sequence.right = NULL; 39 | ext->_sequence.is_red = 0; 40 | ext->_sequence.is_linked = 0; 41 | return; 42 | } 43 | 44 | inline bool 45 | edf_external_sequence_is_linked(edf_external_t *ext) 46 | { 47 | if (ext == NULL || ext->_sequence.is_linked == 0) { 48 | return false; 49 | } 50 | return true; 51 | } 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to `erldist_filter` 2 | 3 | We want to make contributing to this project as easy and transparent as possible. 4 | 5 | ## Our Development Process 6 | 7 | `erldist_filter` is currently developed in Meta's internal repositories and then exported out to GitHub by a Meta team member; however, we invite you to submit pull requests as described below. 8 | 9 | ## Pull Requests 10 | 11 | We actively welcome your pull requests. 12 | 13 | 1. Fork the repo and create your branch from `main`. 14 | 2. If you've added code that should be tested, add tests. 15 | 3. If you've changed APIs, update the documentation. 16 | 4. Ensure the test suite passes. 17 | 5. Make sure your code lints. 18 | 6. If you haven't already, complete the Contributor License Agreement ("CLA"). 19 | 20 | ## Contributor License Agreement ("CLA") 21 | 22 | In order to accept your pull request, we need you to submit a CLA. You only need to do this once to work on any of Meta's open source projects. 23 | 24 | Complete your CLA here: 25 | 26 | ## Issues 27 | 28 | We use GitHub issues to track public bugs. Please ensure your description is clear and has sufficient instructions to be able to reproduce the issue. 29 | 30 | Meta has a [bounty program](https://www.facebook.com/whitehat/) for the safe disclosure of security bugs. In those cases, please go through the process outlined on that page and do not file a public issue. 31 | 32 | ## Coding Style 33 | 34 | Please run `make format` before submitting your changes. 35 | 36 | ## License 37 | 38 | By contributing to `erldist_filter`, you agree that your contributions will be licensed under the MIT license found in the LICENSE.md file in the root directory of this source tree. 39 | -------------------------------------------------------------------------------- /codegen/src/erlang_edf_codegen/context/config.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | """Context Config models for codegen.""" 8 | import bisect 9 | from abc import abstractclassmethod 10 | from collections import OrderedDict 11 | from dataclasses import dataclass, field 12 | from typing import Any, Iterator, Optional, Union 13 | 14 | from ..schema import ( 15 | Config as ConfigSchema, 16 | ConfigField as ConfigFieldSchema, 17 | ) 18 | from . import Atom, Context 19 | 20 | 21 | @dataclass 22 | class Config: 23 | ctx: Context = field(repr=False) 24 | schema: ConfigSchema = field(repr=False) 25 | fields_dict: OrderedDict[str, "ConfigField"] = field(init=False) 26 | fields_list: list["ConfigField"] = field(init=False) 27 | 28 | def __post_init__(self) -> None: 29 | self.fields_dict = OrderedDict() 30 | self.fields_list = [] 31 | 32 | for field_schema in self.schema.fields: 33 | if field_schema.key in self.fields_dict: 34 | raise ValueError(f"Duplicate ConfigField key: {field_schema.key}") 35 | field = ConfigField(ctx=self.ctx, schema=field_schema) 36 | self.fields_dict[field.key] = field 37 | self.fields_list.append(field) 38 | 39 | 40 | @dataclass 41 | class ConfigField: 42 | ctx: Context = field(repr=False) 43 | schema: ConfigFieldSchema = field(repr=False) 44 | 45 | @property 46 | def key(self) -> str: 47 | return self.schema.key 48 | 49 | @property 50 | def kind(self) -> str: 51 | return self.schema.kind.value 52 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/primitive/slice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef SLICE_H 10 | #define SLICE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | /* Macro Definitions */ 21 | 22 | #define SLICE_INIT_EMPTY() \ 23 | { \ 24 | .head = NULL, \ 25 | .tail = NULL, \ 26 | } 27 | 28 | /* Type Definitions */ 29 | 30 | typedef struct slice_s slice_t; 31 | 32 | struct slice_s { 33 | const uint8_t *head; 34 | const uint8_t *tail; 35 | }; 36 | 37 | /* Function Declarations */ 38 | 39 | static int slice_is_empty(const slice_t *slice); 40 | static size_t slice_len(const slice_t *slice); 41 | 42 | /* Inline Function Definitions */ 43 | 44 | inline int 45 | slice_is_empty(const slice_t *slice) 46 | { 47 | return (slice == NULL || slice->head == NULL || slice->tail == NULL); 48 | } 49 | 50 | inline size_t 51 | slice_len(const slice_t *slice) 52 | { 53 | return (size_t)(slice->tail - slice->head); 54 | } 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_rewrite_fragment_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_REWRITE_FRAGMENT_HEADER_H 10 | #define ETF_REWRITE_FRAGMENT_HEADER_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | enum etf_rewrite_fragment_header_trap_state_t { 23 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_INIT = 0, 24 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_FIND_CONFLICTS, 25 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_RESOLVE_ATOMS, 26 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_ALLOC, 27 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_ENCODE, 28 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_DONE, 29 | }; 30 | 31 | typedef struct etf_rewrite_fragment_header_trap_s etf_rewrite_fragment_header_trap_t; 32 | typedef enum etf_rewrite_fragment_header_trap_state_t etf_rewrite_fragment_header_trap_state_t; 33 | 34 | struct etf_rewrite_fragment_header_trap_s { 35 | edf_trap_t super; 36 | etf_rewrite_fragment_header_trap_state_t state; 37 | edf_external_t *external; 38 | int internal_index; 39 | bool maybe_rewrite; 40 | size_t rewrite_size; 41 | }; 42 | 43 | /* Function Declarations */ 44 | 45 | extern ERL_NIF_TERM etf_rewrite_fragment_header_trap_open(ErlNifEnv *env, edf_external_t *external, 46 | etf_rewrite_fragment_header_trap_t **trapp); 47 | 48 | /* Inline Function Definitions */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/primitive/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef SPINLOCK_H 10 | #define SPINLOCK_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | 18 | #include "portable_hint.h" 19 | 20 | /* Type Definitions */ 21 | 22 | typedef struct spinlock_s spinlock_t; 23 | 24 | struct spinlock_s { 25 | atomic_flag value; 26 | }; 27 | 28 | /* Function Declarations */ 29 | 30 | static void spinlock_init(volatile spinlock_t *s); 31 | static void spinlock_lock(volatile spinlock_t *s); 32 | static void spinlock_unlock(volatile spinlock_t *s); 33 | 34 | /* Inline Function Definitions */ 35 | 36 | inline void 37 | spinlock_init(volatile spinlock_t *s) 38 | { 39 | (void)atomic_flag_clear_explicit(&s->value, memory_order_seq_cst); 40 | } 41 | 42 | inline void 43 | spinlock_lock(volatile spinlock_t *s) 44 | { 45 | 46 | #if defined(__GNUC__) 47 | #define INTRINSICS_UNLIKELY(x) (__builtin_expect(!!(x), 0)) 48 | #else 49 | #define INTRINSICS_UNLIKELY(x) x 50 | #endif 51 | 52 | while (INTRINSICS_UNLIKELY(atomic_flag_test_and_set_explicit(&s->value, memory_order_relaxed))) { 53 | HINT_SPIN_LOOP(); 54 | } 55 | // (void)atomic_thread_fence(memory_order_acquire); 56 | (void)atomic_signal_fence(memory_order_acquire); 57 | return; 58 | 59 | #undef INTRINSICS_UNLIKELY 60 | } 61 | 62 | inline void 63 | spinlock_unlock(volatile spinlock_t *s) 64 | { 65 | (void)atomic_flag_clear_explicit(&s->value, memory_order_release); 66 | return; 67 | } 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_integer_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_integer_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/1, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_integer_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Value) -> T when Value :: vterm:i32(), T :: t(). 41 | new(Value) when ?is_i32(Value) -> 42 | #vterm_integer_ext{value = Value}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_integer_ext{value = Value}, _Opts) -> 46 | <>. 47 | 48 | -spec simplify(T) -> Value when T :: t(), Value :: vterm:i32(). 49 | simplify(#vterm_integer_ext{value = Value}) -> 50 | Value. 51 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_integer_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_small_integer_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/1, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_small_integer_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Value) -> T when Value :: vterm:u8(), T :: t(). 41 | new(Value) when ?is_u8(Value) -> 42 | #vterm_small_integer_ext{value = Value}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_small_integer_ext{value = Value}, _Opts) -> 46 | <>. 47 | 48 | -spec simplify(T) -> Value when T :: t(), Value :: vterm:u8(). 49 | simplify(#vterm_small_integer_ext{value = Value}) -> 50 | Value. 51 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/src/erldist_filter_test_app.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%%----------------------------------------------------------------------------- 9 | -module(erldist_filter_test_app). 10 | -moduledoc """ 11 | """. 12 | -moduledoc #{author => ["Andrew Bennett "]}. 13 | -moduledoc #{created => "2025-08-26", modified => "2025-08-26"}. 14 | -moduledoc #{copyright => "Meta Platforms, Inc. and affiliates."}. 15 | -compile(warn_missing_spec_all). 16 | -oncall("whatsapp_clr"). 17 | 18 | -behaviour(application). 19 | 20 | %% application callbacks 21 | -export([ 22 | start/2, 23 | stop/1 24 | ]). 25 | 26 | %%%============================================================================= 27 | %%% application callbacks 28 | %%%============================================================================= 29 | 30 | -spec start(StartType, StartArgs) -> {ok, Pid} | {ok, Pid, State} | {error, Reason} when 31 | StartType :: application:start_type(), 32 | StartArgs :: term(), 33 | Pid :: pid(), 34 | State :: term(), 35 | Reason :: term(). 36 | start(_StartType, _StartArgs) -> 37 | {ok, SupPid} = erldist_filter_test_sup:start_link(), 38 | {ok, SupPid}. 39 | 40 | -spec stop(State) -> Ignored when 41 | State :: term(), 42 | Ignored :: term(). 43 | stop(_State) -> 44 | ok. 45 | 46 | %%%----------------------------------------------------------------------------- 47 | %%% Internal functions 48 | %%%----------------------------------------------------------------------------- 49 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_fragment_cont.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_fragment_cont). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vdist_header_encode). 17 | 18 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 19 | % -include("erldist_filter_erts_dist.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | encode_header/1 26 | ]). 27 | 28 | %% Types 29 | -type t() :: #vdist_fragment_cont{}. 30 | 31 | -export_type([ 32 | t/0 33 | ]). 34 | 35 | %%%============================================================================= 36 | %%% API functions 37 | %%%============================================================================= 38 | 39 | -spec new(SequenceId, FragmentId) -> T when 40 | SequenceId :: vdist:sequence_id(), FragmentId :: vdist:fragment_id(), T :: t(). 41 | new(SequenceId, FragmentId) when ?is_u64(SequenceId) andalso ?is_u64(FragmentId) -> 42 | #vdist_fragment_cont{sequence_id = SequenceId, fragment_id = FragmentId}. 43 | 44 | -spec encode_header(T) -> binary() when T :: t(). 45 | encode_header(#vdist_fragment_cont{sequence_id = SequenceId, fragment_id = FragmentId}) -> 46 | <>. 47 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/erldist_filter.app.src: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | {application, erldist_filter, [ 9 | {description, "erldist_filter: Erlang distribution filtering"}, 10 | {vsn, "1.28.3"}, 11 | {mod, {erldist_filter_app, []}}, 12 | {modules, []}, 13 | {registered, []}, 14 | %% NOTE: Remember to sync changes to `applications` to 15 | %% the BUCK file in the application's base folder 16 | {applications, [ 17 | kernel, 18 | stdlib, 19 | inets, 20 | ssl 21 | ]}, 22 | {env, []}, 23 | {doc, "doc"}, 24 | {build_tools, ["mix", "rebar3"]}, 25 | {exclude_patterns, [ 26 | %% emacs temp files 27 | "~$", 28 | %% c object files 29 | "\\.o$", 30 | %% compiled NIF libraries 31 | "\\.dll$", 32 | "\\.dylib$", 33 | "\\.so$", 34 | %% make temp files 35 | "env\\.mk$", 36 | %% vim swap files 37 | "\\.swp$", 38 | %% Hex.pm package related 39 | "erldist_filter\\.app\\.src\\.script$", 40 | %% local development 41 | "erldist_filter_play\\.erl$" 42 | ]}, 43 | {files, [ 44 | "c_src", 45 | "CHANGELOG*", 46 | "include", 47 | "lib", 48 | "LICENSE*", 49 | "mix.exs", 50 | "priv", 51 | "README*", 52 | "rebar.config", 53 | "rebar.lock", 54 | "src" 55 | ]}, 56 | {licenses, ["MIT"]}, 57 | {links, #{ 58 | "GitHub" => "https://github.com/WhatsApp/erldist_filter" 59 | }} 60 | ]}. 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_lazy_term.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_lazy_term). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | 21 | %% API 22 | -export([ 23 | new/1, 24 | internal_vterm_to_binary/2, 25 | simplify/1 26 | ]). 27 | 28 | %% Types 29 | -type t() :: #vterm_lazy_term{}. 30 | 31 | -export_type([ 32 | t/0 33 | ]). 34 | 35 | %%%============================================================================= 36 | %%% API functions 37 | %%%============================================================================= 38 | 39 | -spec new(Slice) -> T when Slice :: binary(), T :: t(). 40 | new(Slice) -> 41 | #vterm_lazy_term{slice = Slice}. 42 | 43 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 44 | internal_vterm_to_binary(#vterm_lazy_term{slice = Slice}, Opts) -> 45 | {ok, VTerm, <<>>} = vterm_decode:internal_binary_to_vterm(Slice), 46 | Slice = vterm_encode:internal_vterm_to_binary(VTerm, Opts), 47 | Slice. 48 | 49 | -spec simplify(T) -> term() when T :: t(). 50 | simplify(#vterm_lazy_term{slice = Slice}) -> 51 | {ok, VTerm, <<>>} = vterm_decode:internal_binary_to_vterm(Slice), 52 | vterm:simplify(VTerm). 53 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_atom_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_atom_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Len, Name) -> T when Len :: vterm:u16(), Name :: binary(), T :: t(). 41 | new(Len, Name) when ?is_u16(Len) andalso is_binary(Name) andalso Len =:= byte_size(Name) -> 42 | #vterm_atom_ext{len = Len, name = Name}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_atom_ext{len = Len, name = Name}, _Opts) when Len =:= byte_size(Name) -> 46 | <>. 47 | 48 | -spec simplify(t()) -> atom(). 49 | simplify(#vterm_atom_ext{name = Name}) -> 50 | erlang:binary_to_atom(Name, latin1). 51 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_binary_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_binary_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_binary_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Len, Data) -> T when Len :: vterm:u32(), Data :: binary(), T :: t(). 41 | new(Len, Data) when ?is_u32(Len) andalso is_binary(Data) andalso Len =:= byte_size(Data) -> 42 | #vterm_binary_ext{len = Len, data = Data}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_binary_ext{len = Len, data = Data}, _Opts) when Len =:= byte_size(Data) -> 46 | <>. 47 | 48 | -spec simplify(T) -> Data when T :: t(), Data :: binary(). 49 | simplify(#vterm_binary_ext{data = Data}) -> 50 | Data. 51 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom_utf8_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_atom_utf8_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_atom_utf8_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Len, Name) -> T when Len :: vterm:u16(), Name :: binary(), T :: t(). 41 | new(Len, Name) when ?is_u16(Len) andalso is_binary(Name) andalso Len =:= byte_size(Name) -> 42 | #vterm_atom_utf8_ext{len = Len, name = Name}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_atom_utf8_ext{len = Len, name = Name}, _Opts) when Len =:= byte_size(Name) -> 46 | <>. 47 | 48 | -spec simplify(T) -> A when T :: t(), A :: atom(). 49 | simplify(#vterm_atom_utf8_ext{name = Name}) -> 50 | erlang:binary_to_atom(Name, utf8). 51 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_decode_dist_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_DECODE_DIST_HEADER_H 10 | #define ETF_DECODE_DIST_HEADER_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | enum etf_decode_dist_header_trap_state_t { 23 | ETF_DECODE_DIST_HEADER_TRAP_STATE_INIT = 0, 24 | ETF_DECODE_DIST_HEADER_TRAP_STATE_READ_FLAGS, 25 | ETF_DECODE_DIST_HEADER_TRAP_STATE_DONE, 26 | }; 27 | 28 | typedef struct etf_decode_dist_header_trap_s etf_decode_dist_header_trap_t; 29 | typedef enum etf_decode_dist_header_trap_state_t etf_decode_dist_header_trap_state_t; 30 | 31 | struct etf_decode_dist_header_trap_s { 32 | edf_trap_t super; 33 | etf_decode_dist_header_trap_state_t state; 34 | edf_external_t *external; 35 | vec_t vec; 36 | size_t skip; 37 | uint8_t number_of_atom_cache_refs; 38 | size_t flags_size; 39 | const uint8_t *flagsp; 40 | bool long_atoms; 41 | int got_flags; 42 | int table_index; 43 | const uint8_t *head; 44 | const uint8_t *tail; 45 | }; 46 | 47 | /* Function Declarations */ 48 | 49 | extern ERL_NIF_TERM etf_decode_dist_header_trap_open(ErlNifEnv *env, edf_external_t *external, 50 | etf_decode_dist_header_trap_t **trapp); 51 | extern int etf_fast_decode_dist_header(ErlNifEnv *caller_env, edf_channel_t *channel, edf_atom_translation_table_t *attab, 52 | vec_reader_t *vr, int *external_flags, slice_t *headers, ERL_NIF_TERM *err_termp); 53 | 54 | /* Inline Function Definitions */ 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_atom_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_small_atom_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_small_atom_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Len, Name) -> T when Len :: vterm:u8(), Name :: binary(), T :: t(). 41 | new(Len, Name) when ?is_u8(Len) andalso is_binary(Name) andalso Len =:= byte_size(Name) -> 42 | #vterm_small_atom_ext{len = Len, name = Name}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_small_atom_ext{len = Len, name = Name}, _Opts) when Len =:= byte_size(Name) -> 46 | <>. 47 | 48 | -spec simplify(T) -> A when T :: t(), A :: atom(). 49 | simplify(#vterm_small_atom_ext{name = Name}) -> 50 | erlang:binary_to_atom(Name, latin1). 51 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_atom_utf8_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_small_atom_utf8_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_small_atom_utf8_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Len, Name) -> T when Len :: vterm:u8(), Name :: binary(), T :: t(). 41 | new(Len, Name) when ?is_u8(Len) andalso is_binary(Name) andalso Len =:= byte_size(Name) -> 42 | #vterm_small_atom_utf8_ext{len = Len, name = Name}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_small_atom_utf8_ext{len = Len, name = Name}, _Opts) when Len =:= byte_size(Name) -> 46 | <>. 47 | 48 | -spec simplify(t()) -> atom(). 49 | simplify(#vterm_small_atom_utf8_ext{name = Name}) -> 50 | erlang:binary_to_atom(Name, utf8). 51 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_send.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_send). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/2, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_send{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(Unused, ToPid) -> T when 39 | Unused :: vterm:t(), ToPid :: vterm:pid_t(), T :: t(). 40 | new(Unused, ToPid) when 41 | ?is_vterm_t(Unused) andalso ?is_vterm_pid_t(ToPid) 42 | -> 43 | #vdist_dop_send{unused = Unused, to_pid = ToPid}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_send{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_send{unused = Unused, to_pid = ToPid}) -> 51 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_SEND), Unused, ToPid]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_send{}) -> 55 | 0. 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_new_float_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_new_float_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/1, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_new_float_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(IEEEFloat) -> T when IEEEFloat :: <<_:64>>, T :: t(). 41 | new(IEEEFloat) when is_binary(IEEEFloat) andalso bit_size(IEEEFloat) =:= 64 -> 42 | #vterm_new_float_ext{ieee_float = IEEEFloat}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_new_float_ext{ieee_float = IEEEFloat}, _Opts) when bit_size(IEEEFloat) =:= 64 -> 46 | <>. 47 | 48 | -spec simplify(t()) -> term(). 49 | simplify(VTerm = #vterm_new_float_ext{}) -> 50 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 51 | Term. 52 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_float_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_float_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/1, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_float_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(FloatString) -> T when FloatString :: <<_:248>>, T :: t(). 41 | new(FloatString) when is_binary(FloatString) andalso byte_size(FloatString) =:= 31 -> 42 | #vterm_float_ext{float_string = FloatString}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_float_ext{float_string = FloatString}, _Opts) when byte_size(FloatString) =:= 31 -> 46 | <>. 47 | 48 | -spec simplify(T) -> term() when T :: t(). 49 | simplify(VTerm = #vterm_float_ext{}) -> 50 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 51 | Term. 52 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/src/property_test/erldist_filter_nif_spbt_prop.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Sep 2022 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(erldist_filter_nif_spbt_prop). 12 | -author("potatosaladx@meta.com"). 13 | -oncall("whatsapp_clr"). 14 | -compile(warn_missing_spec_all). 15 | 16 | -include_lib("erldist_filter_test/include/proper_erldist_filter_test.hrl"). 17 | 18 | %% Properties 19 | -export([ 20 | prop_serial_statem/1, 21 | prop_parallel_statem/1 22 | ]). 23 | 24 | %% Macros 25 | -define(STATEM, erldist_filter_nif_spbt_statem). 26 | 27 | %%%============================================================================= 28 | %%% Properties 29 | %%%============================================================================= 30 | 31 | -spec prop_serial_statem(ct_suite:ct_config()) -> proper:test(). 32 | prop_serial_statem(Config) -> 33 | ?FORALL( 34 | Commands, 35 | commands(?STATEM), 36 | begin 37 | RunResult = {_History, _State, _Result} = run_commands(?STATEM, Commands), 38 | erldist_filter_proper:present_result(?MODULE, Commands, RunResult, Config) 39 | end 40 | ). 41 | 42 | -spec prop_parallel_statem(ct_suite:ct_config()) -> proper:test(). 43 | prop_parallel_statem(Config) -> 44 | ?FORALL( 45 | Commands, 46 | parallel_commands(?STATEM), 47 | begin 48 | RunResult = {_History, _State, _Result} = run_parallel_commands(?STATEM, Commands), 49 | erldist_filter_proper:present_result(?MODULE, Commands, RunResult, Config) 50 | end 51 | ). 52 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_string_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_string_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_string_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Len, Characters) -> T when Len :: vterm:u16(), Characters :: binary(), T :: t(). 41 | new(Len, Characters) when ?is_u16(Len) andalso is_binary(Characters) andalso Len =:= byte_size(Characters) -> 42 | #vterm_string_ext{len = Len, characters = Characters}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_string_ext{len = Len, characters = Characters}, _Opts) when 46 | Len =:= byte_size(Characters) 47 | -> 48 | <>. 49 | 50 | -spec simplify(t()) -> string(). 51 | simplify(#vterm_string_ext{characters = Characters}) -> 52 | erlang:binary_to_list(Characters). 53 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_link.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_link). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/2, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_link{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 40 | new(FromPid, ToPid) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 41 | #vdist_dop_link{from_pid = FromPid, to_pid = ToPid}. 42 | 43 | -spec has_payload(T) -> boolean() when T :: t(). 44 | has_payload(#vdist_dop_link{}) -> 45 | false. 46 | 47 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 48 | into_control_message_vterm(#vdist_dop_link{from_pid = FromPid, to_pid = ToPid}) -> 49 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_LINK), FromPid, ToPid]). 50 | 51 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 52 | sequence_id(#vdist_dop_link{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 53 | vterm_pid:sequence_id(FromPid). 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_old_atom_cache_ref_entry.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_old_atom_cache_ref_entry). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/1, 22 | encode_header_flag/1, 23 | encode_header_reference/2 24 | ]). 25 | 26 | %% Types 27 | -type t() :: #vdist_old_atom_cache_ref_entry{}. 28 | 29 | -export_type([ 30 | t/0 31 | ]). 32 | 33 | %%%============================================================================= 34 | %%% API functions 35 | %%%============================================================================= 36 | 37 | -spec new(AtomCacheIndex) -> T when AtomCacheIndex :: vdist:atom_cache_index(), T :: t(). 38 | new(AtomCacheIndex) when ?is_atom_cache_index(AtomCacheIndex) -> 39 | #vdist_old_atom_cache_ref_entry{atom_cache_index = AtomCacheIndex}. 40 | 41 | -spec encode_header_flag(T) -> bitstring() when T :: t(). 42 | encode_header_flag(#vdist_old_atom_cache_ref_entry{atom_cache_index = AtomCacheIndex}) -> 43 | SegmentIndex = ((AtomCacheIndex bsr 8) band 7), 44 | <<0:1, SegmentIndex:3>>. 45 | 46 | -spec encode_header_reference(T, LongAtoms) -> bitstring() when T :: t(), LongAtoms :: boolean(). 47 | encode_header_reference(#vdist_old_atom_cache_ref_entry{atom_cache_index = AtomCacheIndex}, _LongAtoms) -> 48 | InternalSegmentIndex = (AtomCacheIndex band 16#FF), 49 | <>. 50 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom_cache_ref_resolved.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_atom_cache_ref_resolved). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_atom_cache_ref_resolved{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Index, Term) -> T when Index :: vterm:u8(), Term :: atom(), T :: t(). 41 | new(Index, Term) when ?is_u8(Index) andalso is_atom(Term) -> 42 | #vterm_atom_cache_ref_resolved{index = Index, term = Term}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_atom_cache_ref_resolved{index = Index}, #{allow_atom_cache_refs := true}) -> 46 | <>; 47 | internal_vterm_to_binary(#vterm_atom_cache_ref_resolved{term = Term}, _Opts) when is_atom(Term) -> 48 | vterm_encode:internal_term_to_binary(Term). 49 | 50 | -spec simplify(t()) -> atom(). 51 | simplify(#vterm_atom_cache_ref_resolved{term = Term}) when is_atom(Term) -> 52 | Term. 53 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_unlink.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_unlink). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/2, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_unlink{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 40 | new(FromPid, ToPid) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 41 | #vdist_dop_unlink{from_pid = FromPid, to_pid = ToPid}. 42 | 43 | -spec has_payload(T) -> boolean() when T :: t(). 44 | has_payload(#vdist_dop_unlink{}) -> 45 | false. 46 | 47 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 48 | into_control_message_vterm(#vdist_dop_unlink{from_pid = FromPid, to_pid = ToPid}) -> 49 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_UNLINK), FromPid, ToPid]). 50 | 51 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 52 | sequence_id(#vdist_dop_unlink{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 53 | vterm_pid:sequence_id(FromPid). 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_big_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_small_big_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/3, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_small_big_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(N, Sign, D) -> T when N :: vterm:u8(), Sign :: 0..1, D :: binary(), T :: t(). 41 | new(N, Sign, D) when ?is_u8(N) andalso (Sign =:= 0 orelse Sign =:= 1) andalso N =:= byte_size(D) -> 42 | #vterm_small_big_ext{n = N, sign = Sign, d = D}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_small_big_ext{n = N, sign = Sign, d = D}, _Opts) when 46 | ?is_u8(N) andalso (Sign =:= 0 orelse Sign =:= 1) andalso N =:= byte_size(D) 47 | -> 48 | <>. 49 | 50 | -spec simplify(t()) -> term(). 51 | simplify(VTerm = #vterm_small_big_ext{}) -> 52 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 53 | Term. 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_large_big_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_large_big_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/3, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_large_big_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(N, Sign, D) -> T when N :: vterm:u32(), Sign :: 0..1, D :: binary(), T :: t(). 41 | new(N, Sign, D) when ?is_u32(N) andalso (Sign =:= 0 orelse Sign =:= 1) andalso N =:= byte_size(D) -> 42 | #vterm_large_big_ext{n = N, sign = Sign, d = D}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_large_big_ext{n = N, sign = Sign, d = D}, _Opts) when 46 | ?is_u32(N) andalso (Sign =:= 0 orelse Sign =:= 1) andalso N =:= byte_size(D) 47 | -> 48 | <>. 49 | 50 | -spec simplify(T) -> term() when T :: t(). 51 | simplify(VTerm = #vterm_large_big_ext{}) -> 52 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 53 | Term. 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_group_leader.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_group_leader). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/2, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_group_leader{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 40 | new(FromPid, ToPid) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 41 | #vdist_dop_group_leader{from_pid = FromPid, to_pid = ToPid}. 42 | 43 | -spec has_payload(T) -> boolean() when T :: t(). 44 | has_payload(#vdist_dop_group_leader{}) -> 45 | false. 46 | 47 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 48 | into_control_message_vterm(#vdist_dop_group_leader{from_pid = FromPid, to_pid = ToPid}) -> 49 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_GROUP_LEADER), FromPid, ToPid]). 50 | 51 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 52 | sequence_id(#vdist_dop_group_leader{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 53 | vterm_pid:sequence_id(FromPid). 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_alias_send.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_alias_send). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/2, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_alias_send{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, Alias) -> T when 39 | FromPid :: vterm:pid_t(), Alias :: vterm:reference_t(), T :: t(). 40 | new(FromPid, Alias) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_reference_t(Alias) 42 | -> 43 | #vdist_dop_alias_send{from_pid = FromPid, alias = Alias}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_alias_send{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_alias_send{from_pid = FromPid, alias = Alias}) -> 51 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_ALIAS_SEND), FromPid, Alias]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_alias_send{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 55 | vterm_pid:sequence_id(FromPid). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_send_sender.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_send_sender). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/2, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_send_sender{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 40 | new(FromPid, ToPid) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) 42 | -> 43 | #vdist_dop_send_sender{from_pid = FromPid, to_pid = ToPid}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_send_sender{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_send_sender{from_pid = FromPid, to_pid = ToPid}) -> 51 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_SEND_SENDER), FromPid, ToPid]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_send_sender{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 55 | vterm_pid:sequence_id(FromPid). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_payload_exit.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_payload_exit). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/2, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_payload_exit{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 40 | new(FromPid, ToPid) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) 42 | -> 43 | #vdist_dop_payload_exit{from_pid = FromPid, to_pid = ToPid}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_payload_exit{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_payload_exit{from_pid = FromPid, to_pid = ToPid}) -> 51 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_PAYLOAD_EXIT), FromPid, ToPid]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_payload_exit{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 55 | vterm_pid:sequence_id(FromPid). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_payload_exit2.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_payload_exit2). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/2, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_payload_exit2{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 40 | new(FromPid, ToPid) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) 42 | -> 43 | #vdist_dop_payload_exit2{from_pid = FromPid, to_pid = ToPid}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_payload_exit2{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_payload_exit2{from_pid = FromPid, to_pid = ToPid}) -> 51 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_PAYLOAD_EXIT2), FromPid, ToPid]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_payload_exit2{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 55 | vterm_pid:sequence_id(FromPid). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_send_tt.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_send_tt). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_send_tt{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(Unused, ToPid, TraceToken) -> T when 39 | Unused :: vterm:t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), T :: t(). 40 | new(Unused, ToPid, TraceToken) when 41 | ?is_vterm_t(Unused) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) 42 | -> 43 | #vdist_dop_send_tt{unused = Unused, to_pid = ToPid, trace_token = TraceToken}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_send_tt{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_send_tt{unused = Unused, to_pid = ToPid, trace_token = TraceToken}) -> 51 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_SEND_TT), Unused, ToPid, TraceToken]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_send_tt{}) -> 55 | 0. 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/primitive/spinwait.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef SPINWAIT_H 10 | #define SPINWAIT_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | #include "c11threads.h" 20 | #include "portable_hint.h" 21 | #include "steady_clock.h" 22 | 23 | /* Type Definitions */ 24 | 25 | typedef struct spinwait_s spinwait_t; 26 | 27 | struct spinwait_s { 28 | uint32_t counter; 29 | uint64_t yielded_nsec; 30 | }; 31 | 32 | /* Function Declarations */ 33 | 34 | static void spinwait_init(volatile spinwait_t *w); 35 | static bool spinwait_try_spin(volatile spinwait_t *w); 36 | static void spinwait_spin_no_yield(volatile spinwait_t *w); 37 | 38 | /* Inline Function Definitions */ 39 | 40 | inline void 41 | spinwait_init(volatile spinwait_t *w) 42 | { 43 | w->counter = 0; 44 | w->yielded_nsec = 0; 45 | } 46 | 47 | inline bool 48 | spinwait_try_spin(volatile spinwait_t *w) 49 | { 50 | if (w->counter >= 10) { 51 | return false; 52 | } 53 | w->counter += 1; 54 | if (w->counter <= 3) { 55 | int i = (1 << ((int)(w->counter))); 56 | while (i--) { 57 | HINT_SPIN_LOOP(); 58 | } 59 | } else { 60 | steady_clock_t start = STEADY_CLOCK_INIT; 61 | steady_clock_t end = STEADY_CLOCK_INIT; 62 | (void)steady_clock_now(&start); 63 | (void)thrd_yield(); 64 | (void)steady_clock_now(&end); 65 | w->yielded_nsec += steady_clock_diff_nsec(&start, &end); 66 | } 67 | return true; 68 | } 69 | 70 | inline void 71 | spinwait_spin_no_yield(volatile spinwait_t *w) 72 | { 73 | int i; 74 | w->counter += 1; 75 | if (w->counter > 10) { 76 | w->counter = 10; 77 | } 78 | i = (1 << ((int)(w->counter))); 79 | while (i--) { 80 | HINT_SPIN_LOOP(); 81 | } 82 | return; 83 | } 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_nif_term.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_nif_term). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | 21 | %% API 22 | -export([ 23 | new/1, 24 | internal_vterm_to_binary/2, 25 | simplify/1 26 | ]). 27 | 28 | %% Types 29 | -type t() :: #vterm_nif_term{}. 30 | 31 | -export_type([ 32 | t/0 33 | ]). 34 | 35 | %%%============================================================================= 36 | %%% API functions 37 | %%%============================================================================= 38 | 39 | -spec new(Term) -> T when Term :: vterm:t() | term(), T :: t(). 40 | new(Term) -> 41 | #vterm_nif_term{term = Term}. 42 | 43 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 44 | internal_vterm_to_binary(#vterm_nif_term{term = VTerm}, _Opts) when ?is_vterm_the_non_value_t(VTerm) -> 45 | erlang:error(notsup); 46 | internal_vterm_to_binary(#vterm_nif_term{term = VTerm}, Opts) when ?is_vterm_t(VTerm) -> 47 | vterm_encode:internal_vterm_to_binary(VTerm, Opts); 48 | internal_vterm_to_binary(#vterm_nif_term{term = Term}, _Opts) -> 49 | vterm_encode:internal_term_to_binary(Term). 50 | 51 | -spec simplify(T) -> term() when T :: t(). 52 | simplify(#vterm_nif_term{term = VTerm}) when ?is_vterm_the_non_value_t(VTerm) -> 53 | erlang:error(notsup); 54 | simplify(#vterm_nif_term{term = VTerm}) when ?is_vterm_t(VTerm) -> 55 | vterm:simplify(VTerm); 56 | simplify(#vterm_nif_term{term = Term}) -> 57 | Term. 58 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_exit.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_exit). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_exit{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid, Reason) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), Reason :: vterm:t(), T :: t(). 40 | new(FromPid, ToPid, Reason) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(Reason) -> 41 | #vdist_dop_exit{from_pid = FromPid, to_pid = ToPid, reason = Reason}. 42 | 43 | -spec has_payload(T) -> boolean() when T :: t(). 44 | has_payload(#vdist_dop_exit{}) -> 45 | false. 46 | 47 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 48 | into_control_message_vterm(#vdist_dop_exit{from_pid = FromPid, to_pid = ToPid, reason = Reason}) -> 49 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_EXIT), FromPid, ToPid, Reason]). 50 | 51 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 52 | sequence_id(#vdist_dop_exit{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 53 | vterm_pid:sequence_id(FromPid). 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/mix.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | defmodule ErldistFilter.MixProject do 8 | use Mix.Project 9 | 10 | def project() do 11 | {app, desc} = load_app() 12 | 13 | [ 14 | app: app, 15 | version: to_string(Keyword.fetch!(desc, :vsn)), 16 | description: to_string(Keyword.fetch!(desc, :description)), 17 | elixir: "~> 1.17", 18 | compilers: [:elixir_make] ++ Mix.compilers(), 19 | make_args: ["-j"], 20 | make_env: %{"MIX_ENV" => to_string(Mix.env())}, 21 | make_clean: ["clean"], 22 | make_cwd: "c_src", 23 | deps: deps(), 24 | elixirc_paths: elixirc_paths(Mix.env()), 25 | package: package() 26 | ] 27 | end 28 | 29 | def application() do 30 | {_app, desc} = load_app() 31 | [mod: Keyword.fetch!(desc, :mod)] 32 | end 33 | 34 | # Run "mix help deps" to learn about dependencies. 35 | defp deps() do 36 | [ 37 | {:elixir_make, "~> 0.9", runtime: false} 38 | ] 39 | end 40 | 41 | defp elixirc_paths(:test), do: ["lib", "test/support"] 42 | defp elixirc_paths(_), do: ["lib"] 43 | 44 | defp package() do 45 | {_app, desc} = load_app() 46 | 47 | [ 48 | build_tools: Enum.map(Keyword.fetch!(desc, :build_tools), &to_string/1), 49 | description: to_string(Keyword.fetch!(desc, :description)), 50 | exclude_patterns: 51 | Enum.map(Keyword.fetch!(desc, :exclude_patterns), fn pattern -> 52 | Regex.compile!(to_string(pattern)) 53 | end), 54 | files: Enum.map(Keyword.fetch!(desc, :files), &to_string/1), 55 | licenses: Enum.map(Keyword.fetch!(desc, :licenses), &to_string/1), 56 | links: 57 | Enum.into(Keyword.fetch!(desc, :links), Map.new(), fn {key, value} -> 58 | {to_string(key), to_string(value)} 59 | end) 60 | ] 61 | end 62 | 63 | defp load_app() do 64 | {:ok, [{:application, name, desc}]} = :file.consult(~c"src/erldist_filter.app.src") 65 | {name, desc} 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_exit2.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_exit2). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_exit2{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid, Reason) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), Reason :: vterm:t(), T :: t(). 40 | new(FromPid, ToPid, Reason) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(Reason) -> 41 | #vdist_dop_exit2{from_pid = FromPid, to_pid = ToPid, reason = Reason}. 42 | 43 | -spec has_payload(T) -> boolean() when T :: t(). 44 | has_payload(#vdist_dop_exit2{}) -> 45 | false. 46 | 47 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 48 | into_control_message_vterm(#vdist_dop_exit2{from_pid = FromPid, to_pid = ToPid, reason = Reason}) -> 49 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_EXIT2), FromPid, ToPid, Reason]). 50 | 51 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 52 | sequence_id(#vdist_dop_exit2{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 53 | vterm_pid:sequence_id(FromPid). 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_unlink_id.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_unlink_id). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_unlink_id{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(Id, FromPid, ToPid) -> T when 39 | Id :: vterm:integer_t(), FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 40 | new(Id, FromPid, ToPid) when ?is_vterm_integer_t(Id) andalso ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 41 | #vdist_dop_unlink_id{id = Id, from_pid = FromPid, to_pid = ToPid}. 42 | 43 | -spec has_payload(T) -> boolean() when T :: t(). 44 | has_payload(#vdist_dop_unlink_id{}) -> 45 | false. 46 | 47 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 48 | into_control_message_vterm(#vdist_dop_unlink_id{id = Id, from_pid = FromPid, to_pid = ToPid}) -> 49 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_UNLINK_ID), Id, FromPid, ToPid]). 50 | 51 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 52 | sequence_id(#vdist_dop_unlink_id{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 53 | vterm_pid:sequence_id(FromPid). 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_tuple_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_small_tuple_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_small_tuple_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Arity, Elements) -> T when Arity :: vterm:u8(), Elements :: [vterm:t()], T :: t(). 41 | new(Arity, Elements) when ?is_u8(Arity) andalso is_list(Elements) andalso Arity =:= length(Elements) -> 42 | #vterm_small_tuple_ext{arity = Arity, elements = Elements}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_small_tuple_ext{arity = Arity, elements = Elements}, Opts) when 46 | ?is_u8(Arity) andalso is_list(Elements) andalso Arity =:= length(Elements) 47 | -> 48 | EncodedElements = vterm_encode:internal_vterm_elements_to_binary(Elements, Opts), 49 | <>. 50 | 51 | -spec simplify(t()) -> tuple(). 52 | simplify(#vterm_small_tuple_ext{elements = Elements}) -> 53 | erlang:list_to_tuple([vterm:simplify(Element) || Element <- Elements]). 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_v4_port_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_v4_port_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/3, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_v4_port_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Node, Id, Creation) -> T when Node :: vterm:atom_t(), Id :: vterm:u64(), Creation :: vterm:u32(), T :: t(). 41 | new(Node, Id, Creation) when ?is_vterm_atom_t(Node) andalso ?is_u64(Id) andalso ?is_u32(Creation) -> 42 | #vterm_v4_port_ext{node = Node, id = Id, creation = Creation}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_v4_port_ext{node = Node0, id = Id, creation = Creation}, Opts) when 46 | ?is_vterm_atom_t(Node0) andalso ?is_u64(Id) andalso ?is_u32(Creation) 47 | -> 48 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 49 | <>. 50 | 51 | -spec simplify(t()) -> term(). 52 | simplify(VTerm = #vterm_v4_port_ext{}) -> 53 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 54 | Term. 55 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_bit_binary_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_bit_binary_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/3, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_bit_binary_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Len, Bits, Data) -> T when Len :: vterm:u32(), Bits :: 1..8, Data :: binary(), T :: t(). 41 | new(Len, Bits, Data) when 42 | ?is_u32(Len) andalso (is_integer(Bits) andalso Bits >= 1 andalso Bits =< 8) andalso is_binary(Data) andalso 43 | Len =:= byte_size(Data) 44 | -> 45 | #vterm_bit_binary_ext{len = Len, bits = Bits, data = Data}. 46 | 47 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 48 | internal_vterm_to_binary(#vterm_bit_binary_ext{len = Len, bits = Bits, data = Data}, _Opts) when 49 | Len =:= byte_size(Data) 50 | -> 51 | <>. 52 | 53 | -spec simplify(T) -> Data when T :: t(), Data :: bitstring(). 54 | simplify(#vterm_bit_binary_ext{bits = Bits, data = Data}) -> 55 | BitSize = bit_size(Data) - (8 - Bits), 56 | <> = Data, 57 | BitBinary. 58 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_new_port_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_new_port_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/3, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_new_port_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Node, Id, Creation) -> T when Node :: vterm:atom_t(), Id :: vterm:u32(), Creation :: vterm:u32(), T :: t(). 41 | new(Node, Id, Creation) when ?is_vterm_atom_t(Node) andalso ?is_u32(Id) andalso ?is_u32(Creation) -> 42 | #vterm_new_port_ext{node = Node, id = Id, creation = Creation}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_new_port_ext{node = Node0, id = Id, creation = Creation}, Opts) when 46 | ?is_vterm_atom_t(Node0) andalso ?is_u32(Id) andalso ?is_u32(Creation) 47 | -> 48 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 49 | <>. 50 | 51 | -spec simplify(t()) -> term(). 52 | simplify(VTerm = #vterm_new_port_ext{}) -> 53 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 54 | Term. 55 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_unlink_id_ack.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_unlink_id_ack). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_unlink_id_ack{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(Id, FromPid, ToPid) -> T when 39 | Id :: vterm:integer_t(), FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 40 | new(Id, FromPid, ToPid) when ?is_vterm_integer_t(Id) andalso ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 41 | #vdist_dop_unlink_id_ack{id = Id, from_pid = FromPid, to_pid = ToPid}. 42 | 43 | -spec has_payload(T) -> boolean() when T :: t(). 44 | has_payload(#vdist_dop_unlink_id_ack{}) -> 45 | false. 46 | 47 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 48 | into_control_message_vterm(#vdist_dop_unlink_id_ack{id = Id, from_pid = FromPid, to_pid = ToPid}) -> 49 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_UNLINK_ID_ACK), Id, FromPid, ToPid]). 50 | 51 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 52 | sequence_id(#vdist_dop_unlink_id_ack{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 53 | vterm_pid:sequence_id(FromPid). 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_large_tuple_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_large_tuple_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_large_tuple_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Arity, Elements) -> T when Arity :: vterm:u32(), Elements :: [vterm:t()], T :: t(). 41 | new(Arity, Elements) when ?is_u32(Arity) andalso is_list(Elements) andalso Arity =:= length(Elements) -> 42 | #vterm_large_tuple_ext{arity = Arity, elements = Elements}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_large_tuple_ext{arity = Arity, elements = Elements}, Opts) when 46 | ?is_u32(Arity) andalso is_list(Elements) andalso Arity =:= length(Elements) 47 | -> 48 | EncodedElements = vterm_encode:internal_vterm_elements_to_binary(Elements, Opts), 49 | <>. 50 | 51 | -spec simplify(T) -> Data when T :: t(), Data :: tuple(). 52 | simplify(#vterm_large_tuple_ext{elements = Elements}) -> 53 | erlang:list_to_tuple([vterm:simplify(Element) || Element <- Elements]). 54 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_reg_send.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_reg_send). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_reg_send{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, Unused, ToName) -> T when 39 | FromPid :: vterm:pid_t(), Unused :: vterm:t(), ToName :: vterm:atom_t(), T :: t(). 40 | new(FromPid, Unused, ToName) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_t(Unused) andalso ?is_vterm_atom_t(ToName) 42 | -> 43 | #vdist_dop_reg_send{from_pid = FromPid, unused = Unused, to_name = ToName}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_reg_send{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_reg_send{from_pid = FromPid, unused = Unused, to_name = ToName}) -> 51 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_REG_SEND), FromPid, Unused, ToName]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_reg_send{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 55 | vterm_pid:sequence_id(FromPid). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/src/property_test/erldist_filter_peer_spbt_prop.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 22 Sep 2022 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(erldist_filter_peer_spbt_prop). 12 | -author("potatosaladx@meta.com"). 13 | -oncall("whatsapp_clr"). 14 | -compile(warn_missing_spec_all). 15 | 16 | -include_lib("erldist_filter_test/include/proper_erldist_filter_test.hrl"). 17 | 18 | %% Properties 19 | -export([ 20 | prop_serial_statem/1, 21 | prop_parallel_statem/1 22 | ]). 23 | 24 | %% Macros 25 | -define(MODEL, erldist_filter_peer_spbt_model). 26 | -define(STATEM, erldist_filter_peer_spbt_statem). 27 | 28 | %%%============================================================================= 29 | %%% Properties 30 | %%%============================================================================= 31 | 32 | -spec prop_serial_statem(ct_suite:ct_config()) -> proper:test(). 33 | prop_serial_statem(Config) -> 34 | {p2p, P2P} = lists:keyfind(p2p, 1, Config), 35 | ?FORALL( 36 | Commands, 37 | commands(?STATEM, ?MODEL:initial_state(#{p2p => P2P})), 38 | begin 39 | RunResult = {_History, _State, _Result} = run_commands(?STATEM, Commands), 40 | erldist_filter_proper:present_result(?MODULE, Commands, RunResult, Config) 41 | end 42 | ). 43 | 44 | -spec prop_parallel_statem(ct_suite:ct_config()) -> proper:test(). 45 | prop_parallel_statem(Config) -> 46 | {p2p, P2P} = lists:keyfind(p2p, 1, Config), 47 | ?FORALL( 48 | Commands, 49 | parallel_commands(?STATEM, ?MODEL:initial_state(#{p2p => P2P})), 50 | begin 51 | RunResult = {_History, _State, _Result} = run_parallel_commands(?STATEM, Commands), 52 | erldist_filter_proper:present_result(?MODULE, Commands, RunResult, Config) 53 | end 54 | ). 55 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_alias_send_tt.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_alias_send_tt). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_alias_send_tt{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, Alias, Token) -> T when 39 | FromPid :: vterm:pid_t(), Alias :: vterm:reference_t(), Token :: vterm:t(), T :: t(). 40 | new(FromPid, Alias, Token) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_reference_t(Alias) andalso ?is_vterm_t(Token) 42 | -> 43 | #vdist_dop_alias_send_tt{from_pid = FromPid, alias = Alias, token = Token}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_alias_send_tt{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_alias_send_tt{from_pid = FromPid, alias = Alias, token = Token}) -> 51 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_ALIAS_SEND_TT), FromPid, Alias, Token]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_alias_send_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 55 | vterm_pid:sequence_id(FromPid). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/primitive/linklist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef LINKLIST_H 10 | #define LINKLIST_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | /* Type Definitions */ 20 | 21 | typedef struct linklist_s linklist_t; 22 | 23 | struct linklist_s { 24 | linklist_t *next; 25 | linklist_t *prev; 26 | }; 27 | 28 | /* Function Declarations */ 29 | 30 | static void linklist_init_anchor(linklist_t *anchor); 31 | static int linklist_is_empty(linklist_t *anchor); 32 | static int linklist_is_linked(linklist_t *node); 33 | static void linklist_insert(linklist_t *pos, linklist_t *node); 34 | static void linklist_insert_list(linklist_t *pos, linklist_t *list); 35 | static void linklist_unlink(linklist_t *node); 36 | 37 | /* Inline Function Definitions */ 38 | 39 | inline void 40 | linklist_init_anchor(linklist_t *anchor) 41 | { 42 | anchor->next = anchor->prev = anchor; 43 | } 44 | 45 | inline int 46 | linklist_is_linked(linklist_t *node) 47 | { 48 | return node->next != NULL; 49 | } 50 | 51 | inline int 52 | linklist_is_empty(linklist_t *anchor) 53 | { 54 | return anchor->next == anchor; 55 | } 56 | 57 | inline void 58 | linklist_insert(linklist_t *pos, linklist_t *node) 59 | { 60 | assert(!linklist_is_linked(node)); 61 | 62 | node->prev = pos->prev; 63 | node->next = pos; 64 | node->prev->next = node; 65 | node->next->prev = node; 66 | } 67 | 68 | inline void 69 | linklist_insert_list(linklist_t *pos, linklist_t *list) 70 | { 71 | if (linklist_is_empty(list)) 72 | return; 73 | list->next->prev = pos->prev; 74 | list->prev->next = pos; 75 | pos->prev->next = list->next; 76 | pos->prev = list->prev; 77 | (void)linklist_init_anchor(list); 78 | } 79 | 80 | inline void 81 | linklist_unlink(linklist_t *node) 82 | { 83 | node->next->prev = node->prev; 84 | node->prev->next = node->next; 85 | node->next = node->prev = NULL; 86 | } 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_monitor_p.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_monitor_p). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_monitor_p{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToProc, Ref) -> T when 39 | FromPid :: vterm:pid_t(), ToProc :: vterm:pid_t() | vterm:atom_t(), Ref :: vterm:reference_t(), T :: t(). 40 | new(FromPid, ToProc, Ref) when 41 | ?is_vterm_pid_t(FromPid) andalso (?is_vterm_pid_t(ToProc) orelse ?is_vterm_atom_t(ToProc)) andalso 42 | ?is_vterm_reference_t(Ref) 43 | -> 44 | #vdist_dop_monitor_p{from_pid = FromPid, to_proc = ToProc, ref = Ref}. 45 | 46 | -spec has_payload(T) -> boolean() when T :: t(). 47 | has_payload(#vdist_dop_monitor_p{}) -> 48 | false. 49 | 50 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 51 | into_control_message_vterm(#vdist_dop_monitor_p{from_pid = FromPid, to_proc = ToProc, ref = Ref}) -> 52 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_MONITOR_P), FromPid, ToProc, Ref]). 53 | 54 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 55 | sequence_id(#vdist_dop_monitor_p{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 56 | vterm_pid:sequence_id(FromPid). 57 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_port_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_port_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/3, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_port_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %% Macros 37 | -define(is_creation(X), (is_integer(X) andalso (X) >= 0 andalso (X) =< 3)). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(Node, Id, Creation) -> T when Node :: vterm:atom_t(), Id :: vterm:u32(), Creation :: 0..3, T :: t(). 44 | new(Node, Id, Creation) when ?is_vterm_atom_t(Node) andalso ?is_u32(Id) andalso ?is_creation(Creation) -> 45 | #vterm_port_ext{node = Node, id = Id, creation = Creation}. 46 | 47 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 48 | internal_vterm_to_binary(#vterm_port_ext{node = Node0, id = Id, creation = Creation}, Opts) when 49 | ?is_vterm_atom_t(Node0) andalso ?is_u32(Id) andalso ?is_creation(Creation) 50 | -> 51 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 52 | <>. 53 | 54 | -spec simplify(t()) -> term(). 55 | simplify(VTerm = #vterm_port_ext{}) -> 56 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 57 | Term. 58 | -------------------------------------------------------------------------------- /justfiles/tools.just: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | [linux] 8 | [working-directory: '/project/codegen'] 9 | codegen: poetry-install format 10 | poetry run erlang_edf_codegen json-schema /project/codegen/schema.json 11 | poetry run erlang_edf_codegen generate /project/codegen/config.yaml /project /project/codegen/templates0 /project/codegen/templates1 12 | just format-c-targets 13 | 14 | [macos] 15 | codegen: docker-codegen 16 | gmake format 17 | just sign 18 | 19 | [linux] 20 | format: format-c-targets format-c-templates format-python-src 21 | 22 | [linux] 23 | format-c-targets: 24 | #!/usr/bin/env bash 25 | files=$(find /project/apps/erldist_filter/c_src \( -type l -o -type f \) \( -name '*.c' -o -name '*.C' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.c.h' -o -name '*.hpp' \) | grep -v " ") 26 | # set -x 27 | clang-format --version 28 | exec clang-format --style="file:/project/apps/erldist_filter/c_src/.clang-format" -i ${files} 29 | 30 | [linux] 31 | format-c-templates: 32 | #!/usr/bin/env bash 33 | files=$(find /project/codegen/{templates0,templates1} \( -type l -o -type f \) \( -name '*.c.j2' -o -name '*.C.j2' -o -name '*.cc.j2' -o -name '*.cpp.j2' -o -name '*.h.j2' -o -name '*.c.h.j2' -o -name '*.hpp.j2' \) | grep -v " ") 34 | # set -x 35 | clang-format --version 36 | exec clang-format --style="file:/project/apps/erldist_filter/c_src/.clang-format" -i ${files} 37 | 38 | [linux] 39 | [working-directory: '/project/codegen'] 40 | format-python-src: 41 | poetry run black /project/codegen/src/ 42 | 43 | [macos] 44 | format: docker-format 45 | gmake format 46 | 47 | [linux] 48 | lock: 49 | just poetry-lock 50 | 51 | [macos] 52 | lock: docker-lock 53 | 54 | [macos] 55 | shell: docker-shell 56 | 57 | [linux] 58 | [working-directory: '/project/codegen'] 59 | sign: poetry-install 60 | poetry run erlang_edf_codegen sign /project/codegen/config.yaml /project /project/codegen/templates0 /project/codegen/templates1 61 | 62 | [macos] 63 | sign: docker-sign 64 | 65 | [macos] 66 | watch: 67 | watchexec -w codegen -- just codegen 68 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_send_sender_tt.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_send_sender_tt). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_send_sender_tt{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid, TraceToken) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), T :: t(). 40 | new(FromPid, ToPid, TraceToken) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) 42 | -> 43 | #vdist_dop_send_sender_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_send_sender_tt{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_send_sender_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}) -> 51 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_SEND_SENDER_TT), FromPid, ToPid, TraceToken]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_send_sender_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 55 | vterm_pid:sequence_id(FromPid). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_demonitor_p.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_demonitor_p). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_demonitor_p{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToProc, Ref) -> T when 39 | FromPid :: vterm:pid_t(), ToProc :: vterm:pid_t() | vterm:atom_t(), Ref :: vterm:reference_t(), T :: t(). 40 | new(FromPid, ToProc, Ref) when 41 | ?is_vterm_pid_t(FromPid) andalso (?is_vterm_pid_t(ToProc) orelse ?is_vterm_atom_t(ToProc)) andalso 42 | ?is_vterm_reference_t(Ref) 43 | -> 44 | #vdist_dop_demonitor_p{from_pid = FromPid, to_proc = ToProc, ref = Ref}. 45 | 46 | -spec has_payload(T) -> boolean() when T :: t(). 47 | has_payload(#vdist_dop_demonitor_p{}) -> 48 | false. 49 | 50 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 51 | into_control_message_vterm(#vdist_dop_demonitor_p{from_pid = FromPid, to_proc = ToProc, ref = Ref}) -> 52 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_DEMONITOR_P), FromPid, ToProc, Ref]). 53 | 54 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 55 | sequence_id(#vdist_dop_demonitor_p{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 56 | vterm_pid:sequence_id(FromPid). 57 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_payload_exit_tt.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_payload_exit_tt). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_payload_exit_tt{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid, TraceToken) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), T :: t(). 40 | new(FromPid, ToPid, TraceToken) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) 42 | -> 43 | #vdist_dop_payload_exit_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_payload_exit_tt{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_payload_exit_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}) -> 51 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_PAYLOAD_EXIT_TT), FromPid, ToPid, TraceToken]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_payload_exit_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 55 | vterm_pid:sequence_id(FromPid). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_payload_exit2_tt.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_payload_exit2_tt). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/3, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_payload_exit2_tt{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid, TraceToken) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), T :: t(). 40 | new(FromPid, ToPid, TraceToken) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) 42 | -> 43 | #vdist_dop_payload_exit2_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_payload_exit2_tt{}) -> 47 | true. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_payload_exit2_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}) -> 51 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_PAYLOAD_EXIT2_TT), FromPid, ToPid, TraceToken]). 52 | 53 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 54 | sequence_id(#vdist_dop_payload_exit2_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 55 | vterm_pid:sequence_id(FromPid). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_map_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_map_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/2, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_map_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %%%============================================================================= 37 | %%% API functions 38 | %%%============================================================================= 39 | 40 | -spec new(Arity, Pairs) -> T when Arity :: vterm:u32(), Pairs :: [{vterm:t(), vterm:t()}], T :: t(). 41 | new(Arity, Pairs) when ?is_u32(Arity) andalso is_list(Pairs) andalso Arity =:= length(Pairs) -> 42 | #vterm_map_ext{arity = Arity, pairs = Pairs}. 43 | 44 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 45 | internal_vterm_to_binary(#vterm_map_ext{arity = Arity, pairs = Pairs}, Opts) when 46 | ?is_u32(Arity) andalso is_list(Pairs) andalso Arity =:= length(Pairs) 47 | -> 48 | % EncodedPairs = vterm_encode:internal_vterm_pairs_to_binary(Pairs, Opts), 49 | EncodedPairs = erlang:iolist_to_binary([ 50 | [vterm_encode:internal_vterm_to_binary(K, Opts), vterm_encode:internal_vterm_to_binary(V, Opts)] 51 | || {K, V} <- Pairs 52 | ]), 53 | <>. 54 | 55 | -spec simplify(T) -> Data when T :: t(), Data :: map(). 56 | simplify(#vterm_map_ext{pairs = Pairs}) -> 57 | #{vterm:simplify(K) => vterm:simplify(V) || {K, V} <- Pairs}. 58 | -------------------------------------------------------------------------------- /codegen/src/erlang_edf_codegen/__main__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | """Command-line interface for codegen.""" 8 | import click 9 | import json 10 | from pathlib import Path 11 | 12 | from . import CodeGenerator, Root 13 | 14 | 15 | @click.group() 16 | def main(): 17 | """Command-line utility for codegen and schema validation.""" 18 | pass 19 | 20 | 21 | @main.command("generate") 22 | @click.argument("config_file", type=click.Path(exists=True)) 23 | @click.argument("output_path", type=click.Path()) 24 | @click.argument("templates0_path", type=click.Path(exists=True, file_okay=False, dir_okay=True)) 25 | @click.argument("templates1_path", type=click.Path(exists=True, file_okay=False, dir_okay=True)) 26 | def generate(config_file: str, output_path: str, templates0_path: str, templates1_path: str): 27 | """Generate C and Erlang code from YAML configuration using Jinja2.""" 28 | 29 | code_generator: CodeGenerator = CodeGenerator(config_file, output_path, templates0_path, templates1_path) 30 | 31 | code_generator.render() 32 | 33 | 34 | @main.command("json-schema") 35 | @click.argument("output_path", type=click.Path()) 36 | def json_schema(output_path: str): 37 | """Generate a JSON schema for the configuration file.""" 38 | 39 | Path(output_path).write_text(json.dumps(Root.model_json_schema(), indent=2)) 40 | print(f"Wrote JSON schema to: {output_path}") 41 | 42 | 43 | @main.command("sign") 44 | @click.argument("config_file", type=click.Path(exists=True)) 45 | @click.argument("output_path", type=click.Path()) 46 | @click.argument("templates0_path", type=click.Path(exists=True, file_okay=False, dir_okay=True)) 47 | @click.argument("templates1_path", type=click.Path(exists=True, file_okay=False, dir_okay=True)) 48 | def sign(config_file: str, output_path: str, templates0_path: str, templates1_path: str): 49 | """Sign C and Erlang code from YAML configuration using Jinja2.""" 50 | 51 | code_generator: CodeGenerator = CodeGenerator(config_file, output_path, templates0_path, templates1_path) 52 | 53 | code_generator.sign() 54 | 55 | 56 | if __name__ == "__main__": 57 | main() # type: ignore 58 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_reference_ext.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vterm_reference_ext). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -behaviour(vterm_encode). 17 | -behaviour(vterm_simplify). 18 | 19 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 20 | -include_lib("erldist_filter/include/erldist_filter_erts_external.hrl"). 21 | 22 | %% API 23 | -export([ 24 | new/3, 25 | internal_vterm_to_binary/2, 26 | simplify/1 27 | ]). 28 | 29 | %% Types 30 | -type t() :: #vterm_reference_ext{}. 31 | 32 | -export_type([ 33 | t/0 34 | ]). 35 | 36 | %% Macros 37 | -define(is_creation(X), (is_integer(X) andalso (X) >= 0 andalso (X) =< 3)). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(Node, Id, Creation) -> T when Node :: vterm:atom_t(), Id :: vterm:u32(), Creation :: 0..3, T :: t(). 44 | new(Node, Id, Creation) when ?is_vterm_atom_t(Node) andalso ?is_u32(Id) andalso ?is_creation(Creation) -> 45 | #vterm_reference_ext{node = Node, id = Id, creation = Creation}. 46 | 47 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 48 | internal_vterm_to_binary(#vterm_reference_ext{node = Node0, id = Id, creation = Creation}, Opts) when 49 | ?is_vterm_atom_t(Node0) andalso ?is_u32(Id) andalso ?is_creation(Creation) 50 | -> 51 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 52 | <>. 53 | 54 | -spec simplify(t()) -> term(). 55 | simplify(VTerm = #vterm_reference_ext{}) -> 56 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 57 | Term. 58 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_exit_tt.erl: -------------------------------------------------------------------------------- 1 | %%% % @format 2 | %%%----------------------------------------------------------------------------- 3 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 4 | %%% Copyright (c) WhatsApp LLC 5 | %%% 6 | %%% This source code is licensed under the MIT license found in the 7 | %%% LICENSE.md file in the root directory of this source tree. 8 | %%% 9 | %%% Created : 27 Mar 2023 by Andrew Bennett 10 | %%%----------------------------------------------------------------------------- 11 | -module(vdist_dop_exit_tt). 12 | -compile(warn_missing_spec_all). 13 | -author("potatosaladx@meta.com"). 14 | -oncall("whatsapp_clr"). 15 | 16 | -include_lib("erldist_filter/include/erldist_filter.hrl"). 17 | -include_lib("erldist_filter/include/erldist_filter_erts_dist.hrl"). 18 | 19 | %% API 20 | -export([ 21 | new/4, 22 | has_payload/1, 23 | into_control_message_vterm/1, 24 | sequence_id/1 25 | ]). 26 | 27 | %% Types 28 | -type t() :: #vdist_dop_exit_tt{}. 29 | 30 | -export_type([ 31 | t/0 32 | ]). 33 | 34 | %%%============================================================================= 35 | %%% API functions 36 | %%%============================================================================= 37 | 38 | -spec new(FromPid, ToPid, TraceToken, Reason) -> T when 39 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), Reason :: vterm:t(), T :: t(). 40 | new(FromPid, ToPid, TraceToken, Reason) when 41 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) andalso ?is_vterm_t(Reason) 42 | -> 43 | #vdist_dop_exit_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken, reason = Reason}. 44 | 45 | -spec has_payload(T) -> boolean() when T :: t(). 46 | has_payload(#vdist_dop_exit_tt{}) -> 47 | false. 48 | 49 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 50 | into_control_message_vterm(#vdist_dop_exit_tt{ 51 | from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken, reason = Reason 52 | }) -> 53 | vterm_small_tuple_ext:new(5, [vterm_small_integer_ext:new(?DOP_EXIT_TT), FromPid, ToPid, TraceToken, Reason]). 54 | 55 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 56 | sequence_id(#vdist_dop_exit_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 57 | vterm_pid:sequence_id(FromPid). 58 | --------------------------------------------------------------------------------