├── .clang-format ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .gitmodules ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── SECURITY.md ├── SUPPORT.md ├── VERSION ├── azure-pipelines.yml ├── cgmanifest.json ├── cmake_modules ├── CTestCustom.cmake └── CodeCoverage.cmake ├── deploy ├── mariner.Dockerfile ├── ubuntu22.04.Dockerfile └── ubuntu24.04.Dockerfile ├── docs ├── add_helper_function.md ├── add_new_hook.md ├── conceptual_example.png ├── data_io.md ├── dependencies.md ├── integrate_lib.md ├── jbpf_oss_architecture.png ├── life_cycle_management.md ├── maps.md ├── overview.md ├── security.md ├── serde.md ├── understand_first_codelet.md └── verifier.md ├── examples ├── .gitignore ├── CMakeLists.txt ├── Makefile ├── experimental │ └── first_example_standalone_json_udp │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── README.md │ │ ├── codeletset_load_request.yaml │ │ ├── codeletset_unload_request.yaml │ │ ├── common.h │ │ ├── example_app.cpp │ │ ├── example_codelet.c │ │ ├── json_udp_receiver.cpp │ │ ├── load.sh │ │ ├── run_app.sh │ │ ├── serde_io_lib_example.cpp │ │ └── unload.sh ├── first_example_ipc │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── codeletset_load_request.yaml │ ├── codeletset_unload_request.yaml │ ├── common.h │ ├── example_app.cpp │ ├── example_codelet.c │ ├── example_collect_control.cpp │ ├── load.sh │ ├── run_app.sh │ ├── run_collect_control.sh │ └── unload.sh ├── first_example_standalone │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── codeletset_load_request.yaml │ ├── codeletset_unload_request.yaml │ ├── common.h │ ├── example_app.cpp │ ├── example_codelet.c │ ├── load.sh │ ├── run_app.sh │ └── unload.sh └── reverse_proxy │ ├── .gitignore │ ├── CMakeLists.txt │ ├── README.md │ ├── listener.cpp │ ├── listener.hpp │ ├── load.sh │ ├── main.cpp │ ├── parser.cpp │ ├── parser.hpp │ ├── run_proxy.sh │ └── unload.sh ├── git-hooks ├── check-commit-message.sh ├── clang-format-pre-commit.sh └── cppcheck-pre-commit.sh ├── helper_build_files ├── approved_libraries.txt ├── build_jbpf_lib.sh ├── build_utils.sh ├── check_linked_libraries.py ├── clang-format-check.sh ├── cppcheck.sh ├── symver.map.in ├── test_build_utils.sh └── update_version_info.cmake ├── init_and_patch_submodules.sh ├── jbpf_tests ├── CMakeLists.txt ├── README.md ├── common │ ├── jbpf_agent_common.c │ ├── jbpf_agent_common.h │ ├── jbpf_test_def.h │ ├── jbpf_test_lib.c │ ├── jbpf_test_lib.h │ └── jbpf_verifier_extension_defs.h ├── concurrency │ ├── CMakeLists.txt │ ├── atomic │ │ ├── CMakeLists.txt │ │ └── atomic_concurrency_test.c │ ├── control_input │ │ ├── CMakeLists.txt │ │ ├── codelet_control_input_concurrency_atomic_test.c │ │ └── codelet_control_input_concurrency_test.c │ ├── hashmap │ │ ├── CMakeLists.txt │ │ ├── codelet_hashmap_concurrency_read_test.c │ │ └── codelet_per_hashmap_array_concurrency_test.c │ ├── hooks │ │ ├── CMakeLists.txt │ │ └── concurrent_hook_execution_unload_test.c │ ├── mem │ │ ├── CMakeLists.txt │ │ ├── mem_consumer.c │ │ ├── mem_stress.c │ │ └── mem_threading.c │ └── ringbuf │ │ ├── CMakeLists.txt │ │ └── codelet_ringbuf_concurrency_test.c ├── e2e_examples │ ├── CMakeLists.txt │ ├── jbpf_e2e_ipc_test.c │ ├── jbpf_e2e_lcm_ipc_standalone_test.c │ └── jbpf_e2e_standalone_test.c ├── functional │ ├── CMakeLists.txt │ ├── array │ │ ├── CMakeLists.txt │ │ └── array_access_test.c │ ├── codeletSets │ │ ├── CMakeLists.txt │ │ ├── codeletSet_LinkedMaps_cyclicCodelets.c │ │ ├── codeletSet_loadTwice.c │ │ ├── codeletSet_multiple_withSameHook.c │ │ ├── codeletSet_priority.c │ │ └── codeletSet_unload_Unknown.c │ ├── codelets │ │ ├── CMakeLists.txt │ │ ├── codelet_InChannel_flood.c │ │ ├── codelet_OutChannel_flood.c │ │ ├── codelet_hook_max.c │ │ ├── codelet_hook_sameSuffix.c │ │ └── codelet_multiThread_perThreadArray.c │ ├── ctrl_hooks │ │ ├── CMakeLists.txt │ │ ├── ctrlHook_checkReturns.c │ │ ├── ctrlHook_multipleCodeletSets.c │ │ └── ctrlHook_multipleCodelets.c │ ├── helper_functions │ │ ├── CMakeLists.txt │ │ ├── jbpf_fixpoint_codelet_test.c │ │ ├── jbpf_hash_codelet_test.c │ │ └── replacing_time_event_helper_function_test.c │ ├── io │ │ ├── CMakeLists.txt │ │ ├── jbpf_io_ipc_test.c │ │ └── jbpf_io_local_test.c │ ├── jbpf_agent.cpp │ ├── jbpf_unit_test.c │ ├── load_unload │ │ ├── CMakeLists.txt │ │ ├── graceful_stop.c │ │ ├── load_unload_repeated.c │ │ ├── max_loaded_codeletSets.c │ │ ├── max_loaded_codeletSets_exceeded.c │ │ ├── max_loaded_codelets.c │ │ └── max_loaded_codelets_exceeded.c │ ├── request_validation │ │ ├── CMakeLists.txt │ │ ├── codeletSet_CodeletDescriptors_empty.c │ │ ├── codeletSet_CodeletDescriptors_max.c │ │ ├── codeletSet_CodeletDescriptors_maxExceeded.c │ │ ├── codeletSet_CodeletDescriptors_null.c │ │ ├── codeletSet_Id_maxLen.c │ │ ├── codeletSet_Id_notSet.c │ │ ├── codeletSet_Id_tooLong.c │ │ ├── codeletSet_duplicateCodeletNames.c │ │ ├── codeletSet_duplicateStreamIds.c │ │ ├── codelet_InChannel_Name_maxLen.c │ │ ├── codelet_InChannel_Name_notSet.c │ │ ├── codelet_InChannel_Name_tooLong.c │ │ ├── codelet_InChannel_Serde_maxLen.c │ │ ├── codelet_InChannel_Serde_notSet.c │ │ ├── codelet_InChannel_Serde_tooLong.c │ │ ├── codelet_InChannel_Serde_unknown.c │ │ ├── codelet_InChannel_map_unknown.c │ │ ├── codelet_InChannel_mismatch.c │ │ ├── codelet_InChannel_null.c │ │ ├── codelet_InChannels_max.c │ │ ├── codelet_InChannels_maxExceeded.c │ │ ├── codelet_LinkedMap_LinkedCodeletName_unknown.c │ │ ├── codelet_LinkedMap_LinkedMapName_InputChannel.c │ │ ├── codelet_LinkedMap_LinkedMapName_OutputChannel.c │ │ ├── codelet_LinkedMap_LinkedMapName_unknown.c │ │ ├── codelet_LinkedMap_MapName_InputChannel.c │ │ ├── codelet_LinkedMap_MapName_OutputChannel.c │ │ ├── codelet_LinkedMap_MapName_unknown.c │ │ ├── codelet_LinkedMap_mismatchedSize.c │ │ ├── codelet_LinkedMap_null.c │ │ ├── codelet_LinkedMap_sameCodelet.c │ │ ├── codelet_LinkedMaps_Names_maxLen.c │ │ ├── codelet_LinkedMaps_duplicate_linked_map_name.c │ │ ├── codelet_LinkedMaps_duplicate_map_name.c │ │ ├── codelet_LinkedMaps_max.c │ │ ├── codelet_LinkedMaps_maxExceeded.c │ │ ├── codelet_OutChannel_Name_maxLen.c │ │ ├── codelet_OutChannel_Name_notSet.c │ │ ├── codelet_OutChannel_Name_tooLong.c │ │ ├── codelet_OutChannel_Serde_maxLen.c │ │ ├── codelet_OutChannel_Serde_notSet.c │ │ ├── codelet_OutChannel_Serde_tooLong.c │ │ ├── codelet_OutChannel_Serde_unknown.c │ │ ├── codelet_OutChannel_map_unknown.c │ │ ├── codelet_OutChannel_mismatch.c │ │ ├── codelet_OutChannel_null.c │ │ ├── codelet_OutChannels_max.c │ │ ├── codelet_OutChannels_maxExceeded.c │ │ ├── codelet_Path_maxLen.c │ │ ├── codelet_Path_notKnown.c │ │ ├── codelet_Path_notSet.c │ │ ├── codelet_Path_tooLong.c │ │ ├── codelet_badObject.c │ │ ├── codelet_hook_notSet.c │ │ ├── codelet_hook_tooLong.c │ │ ├── codelet_hook_unknown.c │ │ ├── codelet_name_maxLen.c │ │ ├── codelet_name_notSet.c │ │ └── codelet_name_tooLong.c │ └── verifier_extensions │ │ ├── CMakeLists.txt │ │ ├── all_maps.cpp │ │ ├── helper_func_all_argTypes.cpp │ │ ├── helper_func_max.cpp │ │ └── jbpf_external_helper_test.c ├── stress_tests │ ├── CMakeLists.txt │ └── io │ │ ├── CMakeLists.txt │ │ └── jbpf_io_stress_test.c ├── test_files │ ├── codelets │ │ ├── Makefile │ │ ├── Makefile.common │ │ ├── Makefile.defs │ │ ├── atomics-example │ │ │ ├── Makefile │ │ │ ├── atomics-example.c │ │ │ └── atomics-example.o │ │ ├── codelet-array │ │ │ ├── Makefile │ │ │ ├── codelet-array.c │ │ │ └── codelet-array.o │ │ ├── codelet-control-input-output │ │ │ ├── Makefile │ │ │ ├── codelet-control-input.c │ │ │ └── codelet-control-input.o │ │ ├── codelet-control-input-withFailures │ │ │ ├── Makefile │ │ │ ├── codelet-control-input-withFailures.c │ │ │ └── codelet-control-input-withFailures.o │ │ ├── codelet-control-input │ │ │ ├── Makefile │ │ │ ├── codelet-control-input.c │ │ │ └── codelet-control-input.o │ │ ├── codelet-hashmap │ │ │ ├── Makefile │ │ │ ├── codelet-hashmap.c │ │ │ └── codelet-hashmap.o │ │ ├── codelet-large-map-output │ │ │ ├── Makefile │ │ │ ├── codelet-large-map.c │ │ │ └── codelet-large-map.o │ │ ├── codelet-large-map │ │ │ ├── Makefile │ │ │ ├── codelet-large-map.c │ │ │ └── codelet-large-map.o │ │ ├── codelet-map-array │ │ │ ├── Makefile │ │ │ ├── codelet-map-array.c │ │ │ └── codelet-map-array.o │ │ ├── codelet-multithreading-output │ │ │ ├── Makefile │ │ │ ├── codelet-multithreading.c │ │ │ └── codelet-multithreading.o │ │ ├── codelet-per-thread │ │ │ ├── Makefile │ │ │ ├── codelet-per-thread.c │ │ │ └── codelet-per-thread.o │ │ ├── codelet-ringbuf-multithreading │ │ │ ├── Makefile │ │ │ ├── codelet-ringbuf-multithreading.c │ │ │ └── codelet-ringbuf-multithreading.o │ │ ├── error_infinite_loop │ │ │ ├── Makefile │ │ │ ├── error_infinite_loop.c │ │ │ └── error_infinite_loop.o │ │ ├── error_invalid_ctx │ │ │ ├── Makefile │ │ │ ├── error_invalid_ctx.c │ │ │ └── error_invalid_ctx.o │ │ ├── error_unknown_helper │ │ │ ├── Makefile │ │ │ ├── error_unknown_helper.c │ │ │ └── error_unknown_helper.o │ │ ├── helper-function-jbpf-hash │ │ │ ├── Makefile │ │ │ ├── jbpf_helper_example.c │ │ │ └── jbpf_helper_example.o │ │ ├── helper_funcs │ │ │ ├── Makefile │ │ │ ├── all_maps.c │ │ │ ├── all_maps.o │ │ │ ├── helper_funcs_all_argTypes.c │ │ │ ├── helper_funcs_all_argTypes.o │ │ │ ├── helper_funcs_max_output.c │ │ │ └── helper_funcs_max_output.o │ │ ├── helper_function_fixpoint │ │ │ ├── Makefile │ │ │ ├── jbpf_helper_fixpoint.c │ │ │ └── jbpf_helper_fixpoint.o │ │ ├── max_input_shared │ │ │ ├── Makefile │ │ │ ├── max_input_shared.c │ │ │ └── max_input_shared.o │ │ ├── max_output_shared │ │ │ ├── Makefile │ │ │ ├── max_output_shared.c │ │ │ └── max_output_shared.o │ │ ├── new_helper │ │ │ ├── Makefile │ │ │ ├── new_helper.c │ │ │ └── new_helper.o │ │ ├── simple_input_largeShared │ │ │ ├── Makefile │ │ │ ├── simple_input_largeShared.c │ │ │ └── simple_input_largeShared.o │ │ ├── simple_input_output │ │ │ ├── Makefile │ │ │ ├── simple_input_output.c │ │ │ └── simple_input_output.o │ │ ├── simple_input_output_atomic │ │ │ ├── Makefile │ │ │ ├── simple_input_output_atomic.c │ │ │ └── simple_input_output_atomic.o │ │ ├── simple_input_shared │ │ │ ├── Makefile │ │ │ ├── simple_input_shared.c │ │ │ └── simple_input_shared.o │ │ ├── simple_input_shared_maxLen │ │ │ ├── Makefile │ │ │ ├── simple_input_shared_maxLen.c │ │ │ └── simple_input_shared_maxLen.o │ │ ├── simple_output │ │ │ ├── Makefile │ │ │ ├── simple_output.c │ │ │ └── simple_output.o │ │ ├── simple_output_2shared │ │ │ ├── Makefile │ │ │ ├── simple_output_2shared.c │ │ │ └── simple_output_2shared.o │ │ ├── simple_output_floodChannel │ │ │ ├── Makefile │ │ │ ├── simple_output_floodChannel.c │ │ │ └── simple_output_floodChannel.o │ │ ├── simple_output_shared │ │ │ ├── Makefile │ │ │ ├── simple_output_shared.c │ │ │ └── simple_output_shared.o │ │ ├── simple_output_shared_counter │ │ │ ├── Makefile │ │ │ ├── simple_output_shared_counter.c │ │ │ └── simple_output_shared_counter.o │ │ ├── simple_output_shared_counter_perThread │ │ │ ├── Makefile │ │ │ ├── simple_output_shared_counter_perThread.c │ │ │ └── simple_output_shared_counter_perThread.o │ │ ├── simple_output_shared_maxLen │ │ │ ├── Makefile │ │ │ ├── simple_output_shared_maxLen.c │ │ │ └── simple_output_shared_maxLen.o │ │ ├── simple_test1 │ │ │ ├── Makefile │ │ │ ├── simple_test1.c │ │ │ └── simple_test1.o │ │ ├── simple_test1_shared │ │ │ ├── Makefile │ │ │ ├── simple_test1_shared.c │ │ │ └── simple_test1_shared.o │ │ ├── simple_test2 │ │ │ ├── Makefile │ │ │ ├── simple_test2.c │ │ │ └── simple_test2.o │ │ ├── simple_test2_shared │ │ │ ├── Makefile │ │ │ ├── simple_test2_shared.c │ │ │ └── simple_test2_shared.o │ │ ├── simple_test_shared_multiple_maps │ │ │ ├── Makefile │ │ │ ├── simple_test1_shared_multiple_maps.c │ │ │ ├── simple_test1_shared_multiple_maps.o │ │ │ ├── simple_test2_shared_multiple_maps.c │ │ │ └── simple_test2_shared_multiple_maps.o │ │ ├── time_events │ │ │ ├── Makefile │ │ │ ├── time_events.c │ │ │ └── time_events.o │ │ └── verifier_extensions │ │ │ ├── Makefile │ │ │ ├── verifier_extensions.c │ │ │ └── verifier_extensions.o │ └── serde_test_libs │ │ ├── CMakeLists.txt │ │ ├── serde_lib_test_struct.c │ │ └── serde_lib_test_struct2.c ├── tools │ └── lcm_cli │ │ ├── CMakeLists.txt │ │ ├── codeletset_req_c1.yaml │ │ ├── codeletset_req_error.yaml │ │ ├── codeletset_req_with_linked_map.yaml │ │ ├── codeletset_unload_req_c1.yaml │ │ ├── codeletset_unload_req_error.yaml │ │ ├── codeletset_unload_req_with_linked_map.yaml │ │ ├── jbpf_lcm_cli_loader_e2e_test.cpp │ │ ├── jbpf_lcm_cli_loader_test_with_linked_map.cpp │ │ ├── jbpf_lcm_cli_parser_test.cpp │ │ └── jbpf_lcm_cli_stream_id_test.cpp ├── unit_tests │ ├── CMakeLists.txt │ ├── array │ │ ├── CMakeLists.txt │ │ └── jbpf_map_type_array_test.c │ ├── bitmap │ │ ├── CMakeLists.txt │ │ └── jbpf_bitmap_test.c │ ├── hashmap │ │ ├── CMakeLists.txt │ │ ├── jbpf_map_type_hashmap_test.c │ │ └── jbpf_map_type_per_thread_hashmap_test.c │ ├── helper_functions │ │ ├── CMakeLists.txt │ │ ├── jbpf_get_sys_time_diff_ns_test.c │ │ ├── jbpf_hash_test.c │ │ ├── jbpf_helper_utils_test.c │ │ ├── jbpf_rand_test.c │ │ └── jbpf_runtime_threshold_test.c │ ├── io_mem │ │ ├── CMakeLists.txt │ │ └── io_mem_unit_test.c │ ├── mem │ │ ├── CMakeLists.txt │ │ └── jbpf_mem_system_test.c │ └── validate_string_param │ │ ├── CMakeLists.txt │ │ └── validate_string_param_test.c └── verifier │ ├── CMakeLists.txt │ ├── jbpf_basic_verifier_test.cpp │ └── jbpf_verifier_extension_test.cpp ├── patches ├── ck.patch ├── ebpf_verifier.patch └── mimalloc.patch ├── pipeline ├── build-for-os.yaml ├── build-lib.yaml ├── doxygen.yaml ├── house-keeping.yaml ├── kill-port-process.sh ├── print-debug-info.yaml ├── setup-on-vm.yaml ├── standard-tests.yaml └── submodules.yaml ├── setup_jbpf_env.sh ├── src ├── common │ ├── .gitignore │ ├── jbpf_common.h │ ├── jbpf_common_types.h │ ├── jbpf_defs.h │ ├── jbpf_helper_api_defs_ext.h │ ├── jbpf_hook_defs_ext.h │ └── jbpf_version.h.in ├── core │ ├── CMakeLists.txt │ ├── jbpf.c │ ├── jbpf.h │ ├── jbpf_agent_hooks.h │ ├── jbpf_bitmap.h │ ├── jbpf_bpf_array.c │ ├── jbpf_bpf_array.h │ ├── jbpf_bpf_hashmap.c │ ├── jbpf_bpf_hashmap.h │ ├── jbpf_bpf_hashmap_int.h │ ├── jbpf_bpf_spsc_hashmap.c │ ├── jbpf_bpf_spsc_hashmap.h │ ├── jbpf_bpf_spsc_hashmap_int.h │ ├── jbpf_config.h │ ├── jbpf_device_defs.h │ ├── jbpf_helper.h │ ├── jbpf_helper_api_defs.h │ ├── jbpf_helper_impl.c │ ├── jbpf_helper_impl.h │ ├── jbpf_helper_utils.h │ ├── jbpf_hook.c │ ├── jbpf_hook.h │ ├── jbpf_hook_defs.h │ ├── jbpf_int.h │ ├── jbpf_lookup3.c │ ├── jbpf_lookup3.h │ ├── jbpf_memory.c │ ├── jbpf_memory.h │ ├── jbpf_perf.c │ ├── jbpf_perf.h │ ├── jbpf_perf_ext.h │ ├── jbpf_types.h │ ├── jbpf_utils.c │ └── jbpf_utils.h ├── io │ ├── CMakeLists.txt │ ├── jbpf_io.c │ ├── jbpf_io.h │ ├── jbpf_io_channel.c │ ├── jbpf_io_channel.h │ ├── jbpf_io_channel_defs.h │ ├── jbpf_io_channel_int.h │ ├── jbpf_io_defs.h │ ├── jbpf_io_hash.h │ ├── jbpf_io_int.h │ ├── jbpf_io_ipc.c │ ├── jbpf_io_ipc.h │ ├── jbpf_io_ipc_int.h │ ├── jbpf_io_ipc_msg.h │ ├── jbpf_io_local.c │ ├── jbpf_io_local.h │ ├── jbpf_io_queue.c │ ├── jbpf_io_queue.h │ ├── jbpf_io_queue_int.h │ ├── jbpf_io_thread_mgmt.c │ ├── jbpf_io_thread_mgmt.h │ ├── jbpf_io_utils.c │ └── jbpf_io_utils.h ├── lcm │ ├── CMakeLists.txt │ ├── jbpf_lcm_api.h │ ├── jbpf_lcm_ipc.c │ ├── jbpf_lcm_ipc.h │ └── jbpf_lcm_ipc_msg.h ├── logger │ ├── CMakeLists.txt │ ├── jbpf_logging.c │ └── jbpf_logging.h ├── mem_mgmt │ ├── CMakeLists.txt │ ├── jbpf_mem_mgmt.c │ ├── jbpf_mem_mgmt.h │ ├── jbpf_mem_mgmt_int.h │ ├── jbpf_mem_mgmt_utils.h │ ├── jbpf_mempool.c │ ├── jbpf_mempool.h │ └── jbpf_mempool_int.h └── verifier │ ├── CMakeLists.txt │ ├── jbpf_platform.cpp │ ├── jbpf_platform.hpp │ ├── jbpf_verifier.cpp │ ├── jbpf_verifier.hpp │ ├── jbpf_verifier_cli.cpp │ └── specs │ ├── jbpf_prototypes.cpp │ └── spec_type_descriptors.hpp ├── symver.map └── tools ├── lcm_cli ├── CMakeLists.txt ├── loader.cpp ├── loader.hpp ├── main.cpp ├── parser.cpp ├── parser.hpp ├── stream_id.cpp └── stream_id.hpp └── stats_report ├── Makefile ├── jbpf_stats_report.c ├── jbpf_stats_report.h ├── jbpf_stats_report.o ├── jbpf_stats_report_codeletset.yaml └── jbpf_stats_report_codeletset_period_hook.yaml /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | IndentWidth: 4 3 | ColumnLimit: 120 4 | AlignEscapedNewlines: Left 5 | AlignAfterOpenBracket: AlwaysBreak 6 | # 7 | # Bind * to the type rather than the name. 8 | PointerAlignment: Left 9 | # 10 | # Put function name on separate line from return type. 11 | AlwaysBreakAfterReturnType: All 12 | # 13 | # Put arguments either all on same line or on separate lines. 14 | BinPackArguments: false 15 | # 16 | # Put function parameters on separate lines. 17 | BinPackParameters: false 18 | # 19 | # Open brace goes on new line only when starting a new struct, enum, or func. 20 | BreakBeforeBraces: Mozilla 21 | # 22 | # Don't sort includes in alphabetical order because Windows headers are odd. 23 | SortIncludes: false 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *~ 3 | *.pyc 4 | build 5 | debug_output.txt 6 | *.tmp 7 | helper_build_files/symver.map 8 | tools/jbpf_defs.py 9 | libck-jbpf 10 | out/ 11 | .vscode/ 12 | *.swp 13 | *.swo 14 | *.swn 15 | tools/preemption_patcher/jbpf_defs.py 16 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3p/ck"] 2 | path = 3p/ck 3 | url = https://github.com/concurrencykit/ck.git 4 | [submodule "3p/mimalloc"] 5 | path = 3p/mimalloc 6 | url = https://github.com/microsoft/mimalloc.git 7 | [submodule "3p/ubpf"] 8 | path = 3p/ubpf 9 | url = https://github.com/iovisor/ubpf.git 10 | [submodule "3p/ebpf-verifier"] 11 | path = 3p/ebpf-verifier 12 | url = https://github.com/vbpf/ebpf-verifier.git 13 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: local 3 | hooks: 4 | - id: clang-format 5 | name: clang-format 6 | entry: ./git-hooks/clang-format-pre-commit.sh 7 | language: system 8 | files: \.(c|cpp|h|hpp)$ 9 | stages: [commit] 10 | - id: check-commit-message 11 | name: Check Commit Message 12 | entry: ./git-hooks/check-commit-message.sh 13 | language: script 14 | stages: [commit-msg] 15 | - id: cppcheck 16 | name: cppcheck 17 | entry: ./git-hooks/cppcheck-pre-commit.sh 18 | language: system 19 | files: \.(c|cpp|h|hpp)$ 20 | stages: [commit] 21 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | - Employees can reach out at [aka.ms/opensource/moderation-support](https://aka.ms/opensource/moderation-support) 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation. 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | ## How to file issues and get help 4 | 5 | This project uses GitHub Issues to track bugs and feature requests. Please search the existing 6 | issues before filing new issues to avoid duplicates. For new issues, file your bug or 7 | feature request as a new Issue. 8 | 9 | For help and questions about using this project, please use GitHub Discussions. Please search the existing discussions before starting a new one, to avoid duplication. 10 | 11 | ## Microsoft Support Policy 12 | 13 | Support for jbpf is limited to the resources listed above. 14 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | VERSION_MAJOR 0 2 | VERSION_MINOR 1 3 | VERSION_PATCH 0 4 | 5 | C_API_VERSION 0 6 | -------------------------------------------------------------------------------- /cmake_modules/CTestCustom.cmake: -------------------------------------------------------------------------------- 1 | ## ignore the tests in submodule 2 | set(CTEST_CUSTOM_TESTS_IGNORE 3 | stress_test 4 | unit_test 5 | local_primary_test 6 | concurrency_test 7 | system_test 8 | local_ipc_test 9 | ) 10 | -------------------------------------------------------------------------------- /deploy/mariner.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/azurelinux/base/core:3.0 2 | 3 | RUN echo "*** Installing packages" 4 | RUN tdnf upgrade tdnf --refresh -y 5 | RUN tdnf -y update 6 | RUN tdnf -y install build-essential cmake git 7 | RUN tdnf -y install yaml-cpp-devel yaml-cpp-static boost-devel gcovr clang python3 8 | RUN tdnf -y install doxygen 9 | ## clang-format 10 | RUN tdnf -y install clang-tools-extra 11 | 12 | WORKDIR /jbpf 13 | COPY . /jbpf 14 | ENTRYPOINT ["./helper_build_files/build_jbpf_lib.sh"] 15 | -------------------------------------------------------------------------------- /deploy/ubuntu22.04.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/mirror/docker/library/ubuntu:22.04 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | SHELL ["/bin/bash", "-c"] 5 | ENV CLANG_FORMAT_CHECK=1 6 | ENV CPP_CHECK=1 7 | 8 | RUN echo "*** Installing packages" 9 | RUN apt update --fix-missing 10 | RUN apt install -y cmake build-essential libboost-dev git libboost-program-options-dev \ 11 | wget gcovr doxygen libboost-filesystem-dev libasan6 python3 12 | 13 | RUN apt install -y clang-format cppcheck 14 | RUN apt install -y clang gcc-multilib 15 | RUN apt install -y libyaml-cpp-dev 16 | 17 | WORKDIR /jbpf 18 | COPY . /jbpf 19 | ENTRYPOINT ["./helper_build_files/build_jbpf_lib.sh"] 20 | -------------------------------------------------------------------------------- /deploy/ubuntu24.04.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/mirror/docker/library/ubuntu:24.04 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | SHELL ["/bin/bash", "-c"] 5 | ENV CPP_CHECK=1 6 | 7 | RUN echo "*** Installing packages" 8 | RUN apt update --fix-missing 9 | RUN apt install -y cmake build-essential libboost-dev git libboost-program-options-dev \ 10 | wget gcovr doxygen libboost-filesystem-dev libasan6 python3 11 | 12 | RUN apt install -y clang-format cppcheck 13 | RUN apt install -y clang gcc-multilib 14 | RUN apt install -y libyaml-cpp-dev 15 | 16 | WORKDIR /jbpf 17 | COPY . /jbpf 18 | ENTRYPOINT ["./helper_build_files/build_jbpf_lib.sh"] 19 | -------------------------------------------------------------------------------- /docs/conceptual_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/docs/conceptual_example.png -------------------------------------------------------------------------------- /docs/data_io.md: -------------------------------------------------------------------------------- 1 | # Data input and output architecture 2 | 3 | *jbpf* provides shared memory API to collect data from a codelet and send the data to it. 4 | This API is marked as *Output API* and *Input API* in the figure below. 5 | Developers needs to provide code that will consume the API in a safe and scalable way. 6 | This is marked as *Data collection and control* in the figure below. 7 | 8 | ![Architectural overview](./jbpf_oss_architecture.png) 9 | 10 | 11 | ## Thread mode 12 | 13 | The default mode is a *thread-mode*, which is also easiest to get started. 14 | An example is given [here](../examples/first_example_standalone). 15 | In this mode, *jbpf* starts a thread that performs the *Data collection and control* functionality. 16 | It attaches to the *output API* of *jbpf* and checks for any data delivered by *jbpf*. 17 | Every time a message is created by the codelet, the threads calls a callback, previously registered. 18 | In this example, the callback prints the received message and also sends its sequence number back to the codelet to demonstrate that functionality. 19 | 20 | 21 | ## IPC mode 22 | 23 | A more involved example will require a developer to build their own *Data collection and control* framework. 24 | This is given in an example [here](../examples/first_example_ipc). 25 | In this example developers writes their own *Data collection and control* [framework](../examples/first_example_ipc/example_collection_control.cpp). 26 | It creates an inter-process shared memory pool with the application and it polls the pool for new messages. 27 | -------------------------------------------------------------------------------- /docs/dependencies.md: -------------------------------------------------------------------------------- 1 | # Install dependencies 2 | 3 | To build *jbpf* or to integrate it into your own project, you will need to install various dependencies. 4 | This process is documented with [Dockerfiles](../deploy) for Ubuntu and Azure Linux distributions that are used for *jbpf* pipeline tests. 5 | The `deploy/.Dockerfile` builds *jbpf*, following similar process as described in [README](../README.md) (but also runs extra pipeline checks). 6 | 7 | Please note that it is your responsibility to secure the software supply chain by carefully managing the software versions. 8 | See [here](./security.md) for more discussion. 9 | 10 | 11 | -------------------------------------------------------------------------------- /docs/jbpf_oss_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/docs/jbpf_oss_architecture.png -------------------------------------------------------------------------------- /docs/security.md: -------------------------------------------------------------------------------- 1 | # Best security principles 2 | 3 | 4 | ## Secure build process 5 | 6 | *jbpf* build process depends on multiple open source projects that are downloaded from the Internet. 7 | Some are consumed in form of packages (`.Dockerfile`, see also [here](./integrate_lib.md)), and some as git [submodules](../.gitmodules). 8 | In our pipelines, we always test with the latest versions of the packages. 9 | The submodule versions are fixed, but we try to update them frequently, to test with the newest releases and patches. 10 | 11 | However, when integrating in your own project, you will want to set up your own security process for the supply chain, and in particular: 12 | - Fix the package versions when installing it. For example, in Ubuntu, use: `apt-get install =` 13 | - Fix the versions of the submodules. 14 | You will want to regularly monitor dependencies for security risks and update accordingly. 15 | 16 | 17 | ## Secure codelet storage 18 | 19 | Since the codelets get detailed access to and potentially control of the host application, it is very important to manage them safely. 20 | One of the [design decisions](./life_cycle_management.md) is that only codelet stored on a local secure store can be loaded. 21 | It is a responsibility of the application developers to provide a local, secure codelet storage. 22 | 23 | The best way to create a secure storage depends on the environment. 24 | This document is only meant to provide suggestions on how to achieve this, not a solution. 25 | On a Linux deployment, one may want to create a directory and limit access to it. 26 | In a Kubernetes environment, one may want to create a secure persistent volume, map it to a pod as a directory, and store codelets there. 27 | Many cloud environments offer secure and encrypted storage classes for Kubernetes that can be used for this purpose. 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | *.json 2 | *.pb.h -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message($ENV{JBPF_OUT_DIR}) 2 | 3 | add_custom_target(examples ALL 4 | COMMAND BUILD_TYPE=$ JBPF_OUT_DIR=$ENV{JBPF_OUT_DIR} JBPF_PATH=$ENV{JBPF_PATH} make all 5 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 6 | 7 | 8 | 9 | add_dependencies(examples jbpf::core_lib) 10 | 11 | add_subdirectory(reverse_proxy) 12 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved 2 | 3 | SUBDIRS := $(shell find . -type f -name Makefile -exec dirname {} \; | grep -v ^\.$) 4 | 5 | # Default target: Build all projects 6 | .PHONY: all 7 | all: $(SUBDIRS) 8 | 9 | # Rule to go into each subdirectory and run 'make' 10 | $(SUBDIRS): 11 | @echo "Entering directory '$@'" 12 | @$(MAKE) -C $@ all 13 | 14 | # Clean rule to clean all subdirectories 15 | .PHONY: clean 16 | clean: 17 | @for dir in $(SUBDIRS); do \ 18 | $(MAKE) -C $$dir clean; \ 19 | done 20 | 21 | # Phony targets to avoid conflicts with files 22 | .PHONY: $(SUBDIRS) 23 | -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/.gitignore: -------------------------------------------------------------------------------- 1 | example_codelet.o 2 | example_app 3 | -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ifeq ($(BUILD_TYPE),Debug) 3 | DEBUG_CFLAGS = -g 4 | DEBUG_LDFLAGS = -lgcov 5 | else ifeq ($(BUILD_TYPE),AddressSanitizer) 6 | DEBUG_CFLAGS = -fsanitize=address 7 | endif 8 | 9 | AGENT_NAME := example_app 10 | SERDE_NAME := libserde_io_lib_example.so 11 | RECEIVER_NAME := json_udp_receiver 12 | CODELET_NAME := example_codelet.o 13 | INCLUDES := -I${JBPF_OUT_DIR}/inc 14 | LDFLAGS := -L${JBPF_OUT_DIR}/lib -ljbpf -lck -lubpf -lmimalloc -lpthread -ldl -lrt ${DEBUG_LDFLAGS} 15 | AGENT_FILE := example_app.cpp 16 | RECEIVER_FILE := json_udp_receiver.cpp 17 | SERDE_FILE := serde_io_lib_example.cpp 18 | CODELET_FILE := example_codelet.c 19 | CODELET_CC := clang 20 | 21 | CODELET_CFLAGS := -O2 -target bpf -Wall -DJBPF_DEBUG_ENABLED -D__x86_64__ 22 | 23 | .PHONY: all clean 24 | 25 | all: clean codelet agent receiver serde 26 | 27 | codelet: ${CODELET_FILE} 28 | ${CODELET_CC} ${CODELET_CFLAGS} ${INCLUDES} -c ${CODELET_FILE} -o ${CODELET_NAME} 29 | 30 | agent: 31 | g++ -std=c++17 $(INCLUDES) -o ${AGENT_NAME} ${AGENT_FILE} ${DEBUG_CFLAGS} ${LDFLAGS} 32 | 33 | receiver: 34 | g++ -o ${RECEIVER_NAME} ${RECEIVER_FILE} 35 | 36 | serde: 37 | g++ -o $(INCLUDES) -o ${SERDE_NAME} ${SERDE_FILE} -fPIC -shared 38 | 39 | clean: 40 | rm -f ${AGENT_NAME} ${SERVER_NAME} ${CODELET_NAME} ${SERDE_NAME} 41 | 42 | -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/README.md: -------------------------------------------------------------------------------- 1 | # Example of JSON serialization 2 | 3 | **Note: This example leverages an experimental feature. It is not meant to be used in production environments. 4 | For the example to work as expected, you must explicitly build jbpf with the flag `-DJBPF_EXPERIMENTAL_FEATURES=on`.** 5 | 6 | This example replicates the [first_example_standalone](../../first_example_standalone), but adds JSON serialization and transmission of messages via UDP. 7 | It loads a codelet along with a serialization library, which allows the codelet output messages to be serialized in JSON format 8 | and sent out via a UDP socket. 9 | A UDP receiver collects the messages, parses them and prints the JSON message on screen. 10 | 11 | ## How to build and run 12 | 13 | For the example to work, you need to make sure that `$JBPF_PATH` is correctly set. 14 | 15 | The example is automatically built through the cmake build system. 16 | It can also be built by running `make` in the root directory. 17 | 18 | On one terminal, bring up the example_app, by running: 19 | ```bash 20 | example_app 21 | ``` 22 | 23 | On a second terminal, bring up the UDP receiver: 24 | ```bash 25 | json_udp_receiver 26 | ``` 27 | 28 | Finally, load the codelet to the example_app, by running the `load.sh` script. 29 | 30 | If all worked well, you should see the received JSON messages printed on the screen of the receiver: 31 | ```json 32 | Received message: { 33 | "seq_no": "12", 34 | "value": "-12", 35 | "name": "instance 12" 36 | } 37 | ``` 38 | 39 | To unload the codelet, run the `unload.sh` script. 40 | -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/codeletset_load_request.yaml: -------------------------------------------------------------------------------- 1 | codelet_descriptor: 2 | - codelet_name: example_codelet 3 | codelet_path: ${JBPF_PATH}/examples/experimental/first_example_standalone_json_udp/example_codelet.o 4 | hook_name: example 5 | in_io_channel: 6 | - name: inmap 7 | stream_id: '11111111111111111111111111111111' 8 | out_io_channel: 9 | - name: outmap 10 | stream_id: 00112233445566778899AABBCCDDEEFF 11 | serde: 12 | file_path: ./libserde_io_lib_example.so 13 | priority: 1 14 | codeletset_id: example_codeletset 15 | -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/codeletset_unload_request.yaml: -------------------------------------------------------------------------------- 1 | codeletset_id: example_codeletset 2 | -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct Packet 4 | { 5 | int seq_no; 6 | int value; 7 | char name[32]; 8 | }; 9 | 10 | struct PacketResp 11 | { 12 | int seq_no; 13 | }; -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/load.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | $JBPF_PATH/out/bin/jbpf_lcm_cli -l -c codeletset_load_request.yaml 4 | -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/run_app.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JBPF_PATH/out/lib ./example_app 4 | -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/serde_io_lib_example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #define BOOST_BIND_GLOBAL_PLACEHOLDERS 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "common.h" 12 | 13 | boost::property_tree::ptree 14 | toPtree(const Packet& packet) 15 | { 16 | boost::property_tree::ptree pt; 17 | pt.put("seq_no", packet.seq_no); 18 | pt.put("value", packet.value); 19 | pt.put("name", std::string(packet.name)); 20 | return pt; 21 | } 22 | 23 | std::string 24 | toJson(const boost::property_tree::ptree& pt) 25 | { 26 | std::ostringstream oss; 27 | boost::property_tree::write_json(oss, pt); 28 | return oss.str(); 29 | }; 30 | 31 | size_t 32 | copy_string_to_c_array(const std::string& source, char* destination, size_t max_len) 33 | { 34 | size_t length_to_copy = std::min(source.size(), max_len - 1); 35 | strncpy(destination, source.c_str(), length_to_copy); 36 | destination[length_to_copy] = '\0'; 37 | return length_to_copy; 38 | } 39 | 40 | #ifdef __cplusplus 41 | extern "C" 42 | { 43 | #endif 44 | 45 | int 46 | jbpf_io_serialize( 47 | void* input_msg_buf, size_t input_msg_buf_size, char* serialized_data_buf, size_t serialized_data_buf_size) 48 | { 49 | Packet p = *static_cast(input_msg_buf); 50 | 51 | boost::property_tree::ptree pt = toPtree(p); 52 | std::string json = toJson(pt); 53 | 54 | size_t len = copy_string_to_c_array(json, serialized_data_buf, serialized_data_buf_size); 55 | return len; 56 | } 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /examples/experimental/first_example_standalone_json_udp/unload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | $JBPF_PATH/out/bin/jbpf_lcm_cli -u -c codeletset_unload_request.yaml 4 | -------------------------------------------------------------------------------- /examples/first_example_ipc/.gitignore: -------------------------------------------------------------------------------- 1 | example_codelet.o 2 | example_collect_control 3 | example_app 4 | -------------------------------------------------------------------------------- /examples/first_example_ipc/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ifeq ($(BUILD_TYPE),Debug) 3 | DEBUG_CFLAGS = -g 4 | DEBUG_LDFLAGS = -lgcov 5 | else ifeq ($(BUILD_TYPE),AddressSanitizer) 6 | DEBUG_CFLAGS = -fsanitize=address 7 | endif 8 | 9 | AGENT_NAME := example_app 10 | PRIMARY_NAME := example_collect_control 11 | CODELET_NAME := example_codelet.o 12 | INCLUDES := -I${JBPF_OUT_DIR}/inc -I${JBPF_PATH}/src/common 13 | AGENT_LDFLAGS := -L${JBPF_OUT_DIR}/lib -ljbpf -lck -lubpf -lmimalloc -lpthread -ldl -lrt ${DEBUG_LDFLAGS} 14 | PRIMARY_LDFLAGS := -L${JBPF_OUT_DIR}/lib -ljbpf_io -lck -lmimalloc -lpthread -ldl -lrt ${DEBUG_LDFLAGS} 15 | AGENT_FILE := example_app.cpp 16 | PRIMARY_FILE := example_collect_control.cpp 17 | CODELET_FILE := example_codelet.c 18 | CODELET_CC := clang 19 | 20 | CODELET_CFLAGS := -O2 -target bpf -Wall -DJBPF_DEBUG_ENABLED -D__x86_64__ 21 | 22 | .PHONY: all clean 23 | 24 | all: clean codelet agent primary 25 | 26 | codelet: ${CODELET_FILE} 27 | ${CODELET_CC} ${CODELET_CFLAGS} ${INCLUDES} -c ${CODELET_FILE} -o ${CODELET_NAME} 28 | 29 | agent: 30 | g++ -std=c++17 $(INCLUDES) -o ${AGENT_NAME} $(AGENT_FILE) ${DEBUG_CFLAGS} ${AGENT_LDFLAGS} 31 | 32 | primary: 33 | g++ -std=c++17 $(INCLUDES) -o ${PRIMARY_NAME} $(PRIMARY_FILE) ${DEBUG_CFLAGS} ${PRIMARY_LDFLAGS} 34 | 35 | clean: 36 | rm -f ${AGENT_NAME} ${PRIMARY_NAME} ${CODELET_NAME} 37 | 38 | -------------------------------------------------------------------------------- /examples/first_example_ipc/codeletset_load_request.yaml: -------------------------------------------------------------------------------- 1 | codelet_descriptor: 2 | - codelet_name: example_codelet 3 | codelet_path: ${JBPF_PATH}/examples/first_example_ipc/example_codelet.o 4 | hook_name: example 5 | in_io_channel: 6 | - name: inmap 7 | stream_id: "11111111111111111111111111111111" 8 | out_io_channel: 9 | - name: outmap 10 | stream_id: 00112233445566778899AABBCCDDEEFF 11 | codeletset_id: example_codeletset 12 | -------------------------------------------------------------------------------- /examples/first_example_ipc/codeletset_unload_request.yaml: -------------------------------------------------------------------------------- 1 | codeletset_id: example_codeletset 2 | -------------------------------------------------------------------------------- /examples/first_example_ipc/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct Packet 4 | { 5 | int seq_no; 6 | int value; 7 | char name[32]; 8 | }; 9 | 10 | struct PacketResp 11 | { 12 | int seq_no; 13 | }; -------------------------------------------------------------------------------- /examples/first_example_ipc/load.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | $JBPF_PATH/out/bin/jbpf_lcm_cli -l -c codeletset_load_request.yaml 4 | -------------------------------------------------------------------------------- /examples/first_example_ipc/run_app.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JBPF_PATH/out/lib ./example_app 4 | -------------------------------------------------------------------------------- /examples/first_example_ipc/run_collect_control.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JBPF_PATH/out/lib ./example_collect_control 4 | -------------------------------------------------------------------------------- /examples/first_example_ipc/unload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | $JBPF_PATH/out/bin/jbpf_lcm_cli -u -c codeletset_unload_request.yaml 4 | -------------------------------------------------------------------------------- /examples/first_example_standalone/.gitignore: -------------------------------------------------------------------------------- 1 | example_codelet.o 2 | example_app 3 | -------------------------------------------------------------------------------- /examples/first_example_standalone/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ifeq ($(BUILD_TYPE),Debug) 3 | DEBUG_CFLAGS = -g 4 | DEBUG_LDFLAGS = -lgcov 5 | else ifeq ($(BUILD_TYPE),AddressSanitizer) 6 | DEBUG_CFLAGS = -fsanitize=address 7 | endif 8 | 9 | AGENT_NAME := example_app 10 | CODELET_NAME := example_codelet.o 11 | INCLUDES := -I${JBPF_OUT_DIR}/inc 12 | LDFLAGS := -L${JBPF_OUT_DIR}/lib -ljbpf -lck -lubpf -lmimalloc -lpthread -ldl -lrt ${DEBUG_LDFLAGS} 13 | AGENT_FILE := example_app.cpp 14 | CODELET_FILE := example_codelet.c 15 | CODELET_CC := clang 16 | 17 | CODELET_CFLAGS := -O2 -target bpf -Wall -DJBPF_DEBUG_ENABLED -D__x86_64__ 18 | 19 | .PHONY: all clean 20 | 21 | all: clean codelet agent 22 | 23 | codelet: ${CODELET_FILE} 24 | ${CODELET_CC} ${CODELET_CFLAGS} ${INCLUDES} -c ${CODELET_FILE} -o ${CODELET_NAME} 25 | 26 | agent: 27 | g++ -std=c++17 $(INCLUDES) -o ${AGENT_NAME} $(AGENT_FILE) ${DEBUG_CFLAGS} ${LDFLAGS} 28 | 29 | clean: 30 | rm -f ${AGENT_NAME} ${CODELET_NAME} 31 | 32 | -------------------------------------------------------------------------------- /examples/first_example_standalone/codeletset_load_request.yaml: -------------------------------------------------------------------------------- 1 | codelet_descriptor: 2 | - codelet_name: example_codelet 3 | codelet_path: ${JBPF_PATH}/examples/first_example_standalone/example_codelet.o 4 | hook_name: example 5 | in_io_channel: 6 | - name: inmap 7 | stream_id: '11111111111111111111111111111111' 8 | out_io_channel: 9 | - name: outmap 10 | stream_id: 00112233445566778899AABBCCDDEEFF 11 | priority: 1 12 | codeletset_id: example_codeletset 13 | -------------------------------------------------------------------------------- /examples/first_example_standalone/codeletset_unload_request.yaml: -------------------------------------------------------------------------------- 1 | codeletset_id: example_codeletset 2 | -------------------------------------------------------------------------------- /examples/first_example_standalone/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct Packet 4 | { 5 | int seq_no; 6 | int value; 7 | char name[32]; 8 | }; 9 | 10 | struct PacketResp 11 | { 12 | int seq_no; 13 | }; -------------------------------------------------------------------------------- /examples/first_example_standalone/load.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | $JBPF_PATH/out/bin/jbpf_lcm_cli -l -c codeletset_load_request.yaml 4 | -------------------------------------------------------------------------------- /examples/first_example_standalone/run_app.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JBPF_PATH/out/lib ./example_app 4 | -------------------------------------------------------------------------------- /examples/first_example_standalone/unload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | $JBPF_PATH/out/bin/jbpf_lcm_cli -u -c codeletset_unload_request.yaml 4 | -------------------------------------------------------------------------------- /examples/reverse_proxy/.gitignore: -------------------------------------------------------------------------------- 1 | proxy 2 | -------------------------------------------------------------------------------- /examples/reverse_proxy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | # Project name 4 | project(ProxyProject LANGUAGES CXX) 5 | 6 | # Set C++ standard 7 | set(CMAKE_CXX_STANDARD 17) 8 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 9 | set(CMAKE_CXX_EXTENSIONS OFF) 10 | SET(CMAKE_CXX_FLAGS "-std=c++17") 11 | 12 | # Binary name 13 | set(BINARY_NAME proxy) 14 | set(LIBRARY_NAME reverse_proxy) 15 | 16 | # Include directories 17 | include_directories( 18 | $ENV{JBPF_PATH}/src/io 19 | $ENV{JBPF_PATH}/src/common 20 | $ENV{JBPF_PATH}/src/lcm 21 | $ENV{JBPF_PATH}/src/mem_mgmt 22 | $ENV{JBPF_PATH}/tools/lcm_cli 23 | $ENV{JBPF_PATH}/src/verifier 24 | $ENV{JBPF_PATH}/3p/ebpf-verifier/src 25 | ) 26 | 27 | # Linker flags 28 | set(LINK_LIBS 29 | jbpf_lcm 30 | jbpf 31 | boost_program_options 32 | jbpf_verifier 33 | ck 34 | mimalloc 35 | pthread 36 | dl 37 | rt 38 | ) 39 | 40 | list(APPEND LINK_LIBS libubpf) 41 | 42 | link_directories($ENV{JBPF_OUT_DIR}/lib) 43 | 44 | # Source files for the library (everything except main.cpp) 45 | set(LIB_SOURCES 46 | parser.cpp listener.cpp 47 | $ENV{JBPF_PATH}/tools/lcm_cli/stream_id.cpp 48 | ) 49 | 50 | # Create a static library from the source files 51 | add_library(${LIBRARY_NAME} STATIC ${LIB_SOURCES}) 52 | 53 | # store library in the current directory 54 | set_target_properties(${LIBRARY_NAME} 55 | PROPERTIES 56 | ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 57 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 58 | ) 59 | 60 | # Add executable for main.cpp and link with the static library 61 | add_executable(${BINARY_NAME} main.cpp) 62 | 63 | # store executable in the current directory 64 | set_target_properties(${BINARY_NAME} 65 | PROPERTIES 66 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 67 | ) 68 | 69 | # Link the static library and additional libraries with the executable 70 | target_link_libraries(${BINARY_NAME} ${LIBRARY_NAME} ${LINK_LIBS} ${LINK_FLAGS}) 71 | 72 | add_library(jbpf::reverse_proxy_lib ALIAS ${LIBRARY_NAME}) -------------------------------------------------------------------------------- /examples/reverse_proxy/README.md: -------------------------------------------------------------------------------- 1 | # Reverse Proxy 2 | 3 | This example showcases how to map network requests to *jbpf* LCM unix socket api. **It is not meant for production environments.** 4 | 5 | This example is a companion to [first_example_ipc](../first_example_ipc/). This proxy app can be started alongside the *jbpf* agent to load and unload codelets with a REST request. 6 | 7 | 8 | 9 | The example is a [boost.beast](https://github.com/boostorg/beast) simple REST server with two methods implemented. `POST` to load a codelet set and `DELETE` to unload. The request body for the load request matches the configuration file used in the [lcm_cli](../../tools/lcm_cli/). 10 | 11 | Prerequisites (for Ubuntu 22.04, modify for your development environment): 12 | * cmake 13 | * build-essential 14 | * libboost-dev 15 | * libboost-program-options-dev 16 | 17 | ## Usage 18 | 19 | Firstly, run the set up for [first_example_ipc](../first_example_ipc/) without loading or unloading a codelet. 20 | 21 | You have `./run_collect_control.sh` and `./run_app.sh` running in two terminals from the `first_example_ipc` instructions. 22 | In a third terminal start the proxy: 23 | ```sh 24 | $ source ../../setup_jbpf_env.sh 25 | $ ./run_proxy.sh 26 | ``` 27 | 28 | If successful you will see the following lines: 29 | ``` 30 | Forwarding messages to: /var/run/jbpf/jbpf_lcm_ipc 31 | Listening on: 0.0.0.0:8080 32 | ``` 33 | 34 | Now you can load and unload the codelet using a REST request: 35 | ```sh 36 | # Load the codelet: 37 | ./load.sh 38 | ``` 39 | 40 | You should get the following output: 41 | ``` 42 | Loading codelet set: example_codeletset 43 | ``` 44 | And you can now observe in the primary and agent terminals that data is being produced. 45 | 46 | Finally. 47 | ```sh 48 | # Unload the codelet 49 | ./unload.sh 50 | ``` 51 | -------------------------------------------------------------------------------- /examples/reverse_proxy/listener.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef LISTENER_HPP 4 | #define LISTENER_HPP 5 | 6 | namespace jbpf_reverse_proxy { 7 | namespace listener { 8 | 9 | int 10 | run_listener(int ac, char** av); 11 | 12 | } // namespace listener 13 | } // namespace jbpf_reverse_proxy 14 | 15 | #endif // LISTENER_HPP 16 | -------------------------------------------------------------------------------- /examples/reverse_proxy/load.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 4 | 5 | curl -X POST -H "Content-Type: application/json" \ 6 | http://localhost:8080 \ 7 | --data @"$CURRENT_DIR/codeletset_load_request.json" 8 | -------------------------------------------------------------------------------- /examples/reverse_proxy/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "listener.hpp" 3 | #include "parser.hpp" 4 | #include "jbpf_verifier.hpp" 5 | 6 | int 7 | main(int ac, char** av) 8 | { 9 | // register the "jbpf_verify" function 10 | jbpf_reverse_proxy::parser::parser_jbpf_set_verify_func(jbpf_verify); 11 | 12 | // run the listener 13 | return jbpf_reverse_proxy::listener::run_listener(ac, av); 14 | } -------------------------------------------------------------------------------- /examples/reverse_proxy/parser.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef PARSER_HPP 4 | #define PARSER_HPP 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "jbpf_lcm_api.h" 11 | #include "jbpf_verifier.hpp" 12 | 13 | namespace jbpf_reverse_proxy { 14 | namespace parser { 15 | enum parse_req_outcome 16 | { 17 | JBPF_LCM_PARSE_REQ_SUCCESS, 18 | JBPF_LCM_PARSE_VERIFIER_FAILED, 19 | JBPF_LCM_PARSE_REQ_FAILED, 20 | }; 21 | 22 | void 23 | parser_jbpf_set_verify_func(jbpf_verify_func_t func); 24 | 25 | parse_req_outcome 26 | parse_jbpf_codeletset_load_req( 27 | const boost::property_tree::ptree pt, jbpf_codeletset_load_req* dest, std::vector codeletset_elems); 28 | parse_req_outcome 29 | parse_jbpf_codeletset_unload_req(const boost::property_tree::ptree pt, jbpf_codeletset_unload_req* dest); 30 | std::string 31 | expand_environment_variables(const std::string& input); 32 | } // namespace parser 33 | } // namespace jbpf_reverse_proxy 34 | 35 | #endif // PARSER_HPP 36 | -------------------------------------------------------------------------------- /examples/reverse_proxy/run_proxy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo JBPF_PATH=$JBPF_PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JBPF_PATH/out/lib ./proxy 4 | -------------------------------------------------------------------------------- /examples/reverse_proxy/unload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl --request DELETE http://localhost:8080/example_codeletset 4 | -------------------------------------------------------------------------------- /git-hooks/check-commit-message.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Running check-commit-message pre-commit hook..." 4 | # Read the commit message from the argument 5 | commit_message_file="$1" 6 | 7 | # Extract the first line of the commit message 8 | first_line=$(head -n 1 "$commit_message_file") 9 | 10 | # Check the length of the first line 11 | max_length=72 12 | if [ ${#first_line} -gt $max_length ]; then 13 | echo "Error: The first line of the commit message is too long (more than $max_length characters)." 14 | echo "Please limit the first line to $max_length characters or less." 15 | exit 1 16 | fi 17 | 18 | # If the first line is within the limit, allow the commit 19 | exit 0 20 | -------------------------------------------------------------------------------- /git-hooks/clang-format-pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Running clang-format pre-commit hook..." 3 | 4 | # Define the clang-format executable 5 | CLANG_FORMAT_BIN=clang-format 6 | 7 | # Check if clang-format is installed 8 | if ! command -v ${CLANG_FORMAT_BIN} > /dev/null; then 9 | echo "Error: clang-format is not installed." 10 | exit 1 11 | fi 12 | 13 | # Get a list of all staged files 14 | STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(c|cpp|h|hpp)$') 15 | 16 | # Exit if there are no files to format 17 | if [ -z "$STAGED_FILES" ]; then 18 | echo "No C/C++ files staged for commit." 19 | exit 0 20 | fi 21 | 22 | # If the env AUTO_FORMAT is set to 1, format the files 23 | if [ "$AUTO_FORMAT" = "1" ]; then 24 | echo "Auto-formatting staged files..." 25 | for FILE in ${STAGED_FILES}; do 26 | ${CLANG_FORMAT_BIN} --style=file -i "${FILE}" 27 | done 28 | exit 0 29 | fi 30 | 31 | # Check the formatting of each staged file 32 | FORMAT_ERRORS=0 33 | for FILE in ${STAGED_FILES}; do 34 | echo "Checking formatting of: ${FILE} ..." 35 | ${CLANG_FORMAT_BIN} --style=file --dry-run --Werror "${FILE}" 36 | if [ $? -ne 0 ]; then 37 | FORMAT_ERRORS=1 38 | fi 39 | done 40 | 41 | # If there were formatting errors, fail the commit 42 | if [ $FORMAT_ERRORS -ne 0 ]; then 43 | echo "Error: Some files are not formatted correctly. Please run clang-format and stage the changes." 44 | exit 1 45 | fi 46 | 47 | # Exit successfully 48 | exit 0 49 | -------------------------------------------------------------------------------- /git-hooks/cppcheck-pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Running cppcheck pre-commit hook..." 3 | 4 | # Define the cppcheck executable 5 | CPPCHECK_BIN=cppcheck 6 | 7 | # disable cppcheck flag 8 | if [ "$DISABLE_CPPCHECK" = "1" ]; then 9 | echo "cppcheck pre-commit hook disabled." 10 | exit 0 11 | fi 12 | 13 | # Check if cppcheck is installed 14 | if ! command -v ${CPPCHECK_BIN} > /dev/null; then 15 | echo "Error: cppcheck is not installed." 16 | exit 0 17 | fi 18 | 19 | # Get a list of all staged files 20 | STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(c|cpp|h|hpp)$') 21 | 22 | # Exit if there are no files to check 23 | if [ -z "$STAGED_FILES" ]; then 24 | echo "No C/C++ files staged for commit." 25 | exit 0 26 | fi 27 | 28 | # Run cppcheck on each staged file 29 | CHECK_ERRORS=0 30 | for FILE in ${STAGED_FILES}; do 31 | echo "Running cppcheck on: ${FILE} ..." 32 | $JBPF_PATH/helper_build_files/cppcheck.sh "${FILE}" 33 | if [ $? -ne 0 ]; then 34 | CHECK_ERRORS=1 35 | fi 36 | done 37 | 38 | # If cppcheck found any issues, fail the commit 39 | if [ $CHECK_ERRORS -ne 0 ]; then 40 | echo "Error: cppcheck found issues. Please fix them before committing." 41 | exit 1 42 | fi 43 | 44 | # Exit successfully 45 | exit 0 46 | -------------------------------------------------------------------------------- /helper_build_files/approved_libraries.txt: -------------------------------------------------------------------------------- 1 | libatomic.so 2 | libc.so 3 | ld-linux-x86-64.so 4 | libpthread.a 5 | libebpfverifier.a 6 | libasan.so 7 | libck.a 8 | libbpf_conformance.a 9 | libmimalloc.a 10 | librt.a 11 | libubpf.a 12 | libmimalloc-debug.a 13 | libmimalloc-addresssanitizer.a 14 | libjbpf_lcm_ipc.so 15 | libjbpf_logger.a 16 | libjbpf_verifier.a 17 | libjbpf_io.a 18 | libjbpf_mem_mgmt.a 19 | libjbpf.a 20 | libpthread.so 21 | libdl.so 22 | librt.so 23 | libjbpf_lcm.a 24 | libreverse_proxy.a 25 | -------------------------------------------------------------------------------- /helper_build_files/clang-format-check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for i in "$@"; do 4 | ## if given parameter is file 5 | if [ -f "$i" ]; then 6 | clang-format --dry-run --Werror "$i" 7 | else 8 | find . -name "$i" -iname "*.c" -o -iname "*.h" -o -iname "*.cpp" -o -iname "*.hpp" | xargs clang-format --dry-run --Werror 9 | fi 10 | done 11 | -------------------------------------------------------------------------------- /helper_build_files/cppcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -xe 3 | 4 | cppcheck \ 5 | --enable=all \ 6 | --suppress=missingInclude \ 7 | --suppress=unusedStructMember \ 8 | --suppress=missingIncludeSystem \ 9 | --suppress=unusedFunction \ 10 | --suppress=variableScope \ 11 | --suppress=unknownMacro \ 12 | --suppress=unreadVariable \ 13 | --suppress=constParameter \ 14 | --suppress=unassignedVariable \ 15 | --suppress=unmatchedSuppression \ 16 | --suppress=passedByValue \ 17 | --suppress=comparePointers \ 18 | --suppress=knownConditionTrueFalse \ 19 | --suppress=constParameterPointer \ 20 | --suppress=checkersReport \ 21 | --suppress=constParameterCallback \ 22 | --suppress=constVariablePointer \ 23 | --error-exitcode=1 \ 24 | --std=c++17 \ 25 | "$@" 26 | -------------------------------------------------------------------------------- /helper_build_files/symver.map.in: -------------------------------------------------------------------------------- 1 | jbpf_ver_0 { 2 | global: 3 | jbpf*; 4 | }; 5 | -------------------------------------------------------------------------------- /init_and_patch_submodules.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rf 3p/ebpf-verifier 3p/mimalloc 3p/ck 3p/ubpf 4 | git submodule update --init --recursive 5 | 6 | cp patches/ck.patch 3p/ck 7 | cp patches/mimalloc.patch 3p/mimalloc 8 | cp patches/ebpf_verifier.patch 3p/ebpf-verifier/ 9 | 10 | cd 3p/ck 11 | git apply ck.patch 12 | 13 | cd ../mimalloc 14 | git apply mimalloc.patch 15 | 16 | cd ../ebpf-verifier/ 17 | git apply ebpf_verifier.patch 18 | -------------------------------------------------------------------------------- /jbpf_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | include(ExternalProject) 4 | project(jbpf-tests) 5 | include(CTest) 6 | 7 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 8 | 9 | ### Test Files 10 | set(TEST_FILES test_files) 11 | set(TESTS_BASE ${PROJECT_SOURCE_DIR}) 12 | set(TESTS_COMMON ${TESTS_BASE}/common) 13 | set(TEST_HEADER_FILES ${TESTS_COMMON}) 14 | 15 | add_subdirectory(${TEST_FILES}/serde_test_libs) 16 | 17 | ### Add tests 18 | add_subdirectory(e2e_examples) 19 | add_subdirectory(functional) 20 | add_subdirectory(tools/lcm_cli) 21 | add_subdirectory(verifier) 22 | add_subdirectory(unit_tests) 23 | add_subdirectory(stress_tests) 24 | add_subdirectory(concurrency) 25 | 26 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 27 | -------------------------------------------------------------------------------- /jbpf_tests/common/jbpf_agent_common.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "jbpf_logging.h" 8 | #include "jbpf_test_def.h" 9 | #include "jbpf.h" 10 | 11 | static int sig_handler_called = 0; 12 | 13 | static const char* LOG_LEVEL_STR[] = {FOREACH_LOG_LEVEL(GENERATE_STRING)}; 14 | 15 | void 16 | jbpf_agent_logger(jbpf_logging_level level, const char* s, ...) 17 | { 18 | if (level >= jbpf_get_logging_level()) { 19 | char output[LOGGING_BUFFER_LEN]; 20 | snprintf(output, LOGGING_BUFFER_LEN, "%s%s", LOG_LEVEL_STR[level], s); 21 | va_list ap; 22 | va_start(ap, s); 23 | FILE* where = level >= ERROR ? stderr : stdout; 24 | vfprintf(where, output, ap); 25 | va_end(ap); 26 | } 27 | } 28 | 29 | void 30 | sig_handler(int signo) 31 | { 32 | if (sig_handler_called == 1) { 33 | return; 34 | } 35 | sig_handler_called = 1; 36 | jbpf_logger(JBPF_INFO, "Exiting jbpf...\n"); 37 | jbpf_stop(); 38 | jbpf_logger(JBPF_INFO, "OK! Goodbye!\n"); 39 | exit(EXIT_SUCCESS); 40 | } 41 | 42 | int 43 | handle_signal(void) 44 | { 45 | if (signal(SIGINT, sig_handler) == SIG_ERR) { 46 | return 0; 47 | } 48 | if (signal(SIGTERM, sig_handler) == SIG_ERR) { 49 | return 0; 50 | } 51 | return -1; 52 | } 53 | 54 | // Fisher-Yates algorithm, which guarantees an unbiased shuffle 55 | void 56 | shuffle(int* array, size_t n) 57 | { 58 | if (n > 1) { 59 | srand(time(NULL)); 60 | size_t i; 61 | for (i = 0; i < n - 1; i++) { 62 | // Generate a random index 63 | size_t j = i + rand() / (RAND_MAX / (n - i) + 1); 64 | // Swap array[i] and array[j] 65 | int temp = array[i]; 66 | array[i] = array[j]; 67 | array[j] = temp; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /jbpf_tests/common/jbpf_test_lib.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_TEST_LIB_H 2 | #define JBPF_TEST_LIB_H 3 | 4 | /* Function prototype for test functions. */ 5 | typedef void (*jbpf_test_function_t)(void** state); 6 | 7 | /* Function prototype for setup functions. */ 8 | typedef int (*jbpf_setup_function_t)(void** state); 9 | 10 | /* Function prototype for teardown functions. */ 11 | typedef int (*jbpf_teardown_function_t)(void** state); 12 | 13 | typedef struct jbpf_test_t 14 | { 15 | char name[256]; 16 | jbpf_test_function_t test_func; 17 | jbpf_setup_function_t setup_func; 18 | jbpf_teardown_function_t teardown_func; 19 | void* initial_state; 20 | } jbpf_test; 21 | 22 | jbpf_test 23 | __jbpf_create_test( 24 | jbpf_test_function_t test_func, 25 | jbpf_setup_function_t setup_func, 26 | jbpf_teardown_function_t teardown_func, 27 | void* initial_state, 28 | char* name); 29 | 30 | int 31 | jbpf_run_test( 32 | const jbpf_test* tests, 33 | int num_tests, 34 | jbpf_setup_function_t group_setup_func, 35 | jbpf_teardown_function_t group_teardown_func); 36 | 37 | #define JBPF_CREATE_TEST(test_func, setup_func, teardown_func, initial_state) \ 38 | __jbpf_create_test(test_func, setup_func, teardown_func, initial_state, #test_func) 39 | 40 | #endif // JBPF_TEST_LIB_H -------------------------------------------------------------------------------- /jbpf_tests/common/jbpf_verifier_extension_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_VERIFIER_EXTENSION_DEFS_H 2 | #define JBPF_VERIFIER_EXTENSION_DEFS_H 3 | 4 | #include "jbpf_defs.h" 5 | 6 | // Context definiton extension 7 | struct my_new_jbpf_ctx 8 | { 9 | uint64_t data; 10 | uint64_t data_end; 11 | uint64_t meta_data; 12 | uint32_t static_field1; 13 | uint16_t static_field2; 14 | uint8_t static_field3; 15 | }; 16 | 17 | #endif -------------------------------------------------------------------------------- /jbpf_tests/concurrency/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 4 | set(TESTS_CONCURRENCY ${TESTS_BASE}/concurrency) 5 | 6 | ## add tests from subdirectories 7 | add_subdirectory(mem) 8 | add_subdirectory(hashmap) 9 | add_subdirectory(control_input) 10 | add_subdirectory(ringbuf) 11 | add_subdirectory(hooks) 12 | add_subdirectory(atomic) 13 | 14 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 15 | -------------------------------------------------------------------------------- /jbpf_tests/concurrency/atomic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ## atomic concurrency tests 3 | set(ATOMIC_CONCURRENCY_TESTS ${TESTS_CONCURRENCY}/atomic) 4 | file(GLOB ATOMIC_CONCURRENCY_TESTS_SOURCES ${ATOMIC_CONCURRENCY_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${ATOMIC_CONCURRENCY_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c ${JBPF_HASHMAP_MGMT_SOURCES}) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_HASHMAP_MGMT_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME concurrency/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS concurrency/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 27 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 28 | endforeach() 29 | -------------------------------------------------------------------------------- /jbpf_tests/concurrency/control_input/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ## control input concurrency tests 3 | set(CONTROL_INPUT_CONCURRENCY_TESTS ${TESTS_CONCURRENCY}/control_input) 4 | file(GLOB CONTROL_INPUT_CONCURRENCY_TESTS_SOURCES ${CONTROL_INPUT_CONCURRENCY_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${CONTROL_INPUT_CONCURRENCY_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c ${JBPF_HASHMAP_MGMT_SOURCES}) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_HASHMAP_MGMT_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME concurrency/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS concurrency/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 27 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 28 | endforeach() 29 | -------------------------------------------------------------------------------- /jbpf_tests/concurrency/hashmap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ## hashmap concurrency tests 3 | set(HASHMAP_CONCURRENCY_TESTS ${TESTS_CONCURRENCY}/hashmap) 4 | file(GLOB HASHMAP_CONCURRENCY_TESTS_SOURCES ${HASHMAP_CONCURRENCY_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${HASHMAP_CONCURRENCY_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c ${JBPF_HASHMAP_MGMT_SOURCES}) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_HASHMAP_MGMT_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME concurrency/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS concurrency/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 27 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 28 | endforeach() 29 | -------------------------------------------------------------------------------- /jbpf_tests/concurrency/hooks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ## hooks concurrency tests 3 | set(HOOKS_CONCURRENCY_TESTS ${TESTS_CONCURRENCY}/codelets) 4 | file(GLOB HOOKS_CONCURRENCY_TESTS_SOURCES ${HOOKS_CONCURRENCY_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${HOOKS_CONCURRENCY_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c ${JBPF_HASHMAP_MGMT_SOURCES}) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_HASHMAP_MGMT_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME concurrency/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS concurrency/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 27 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 28 | endforeach() 29 | -------------------------------------------------------------------------------- /jbpf_tests/concurrency/mem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright(c) Microsoft Corporation.All rights reserved. 2 | ## mem concurrency tests 3 | set(MEM_CONCURRENCY_TESTS ${TESTS_CONCURRENCY}/mem) 4 | file(GLOB MEM_CONCURRENCY_TESTS_SOURCES ${MEM_CONCURRENCY_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${MEM_CONCURRENCY_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c ${JBPF_MEM_MGMT_SOURCES}) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_MEM_MGMT_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME concurrency/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS concurrency/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 27 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 28 | endforeach() 29 | -------------------------------------------------------------------------------- /jbpf_tests/concurrency/ringbuf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ## RINGBUF concurrency tests 3 | set(RINGBUF_CONCURRENCY_TESTS ${TESTS_CONCURRENCY}/ringbuf) 4 | file(GLOB RINGBUF_CONCURRENCY_TESTS_SOURCES ${RINGBUF_CONCURRENCY_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${RINGBUF_CONCURRENCY_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c ${JBPF_RINGBUF_MGMT_SOURCES}) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_RINGBUF_MGMT_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME concurrency/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS concurrency/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 27 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 28 | endforeach() 29 | -------------------------------------------------------------------------------- /jbpf_tests/functional/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | include(ExternalProject) 4 | project(jbpf-tests-functional) 5 | include(CTest) 6 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 7 | 8 | #set(JBPF_CONCURRENCY_TEST jbpf_concurrency_test) 9 | set(JBPF_AGENT_CPP_TEST jbpf_agent_cpp_test) 10 | set(JBPF_SYSTEM_TEST jbpf_system_test) 11 | set(JBPF_UNIT_TEST jbpf_unit_test) 12 | set(JBPF_BASIC_UNIT_TEST jbpf_basic_unit_test) 13 | set(TESTS_FUNCTIONAL ${TESTS_BASE}/functional) 14 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 15 | 16 | ## agent cpp 17 | set(JBPF_AGENT_CPP_SOURCES ${TESTS_FUNCTIONAL}/jbpf_agent.cpp ${TESTS_COMMON}/jbpf_agent_common.c) 18 | add_executable(${JBPF_AGENT_CPP_TEST} ${JBPF_AGENT_CPP_SOURCES}) 19 | target_link_libraries(${JBPF_AGENT_CPP_TEST} PUBLIC jbpf::core_lib) 20 | target_include_directories(${JBPF_AGENT_CPP_TEST} PUBLIC ${JBPF_CK_INCLUDES} ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 21 | list(APPEND JBPF_TESTS ${JBPF_AGENT_CPP_TEST}) 22 | add_clang_format_check(${JBPF_AGENT_CPP_TEST} ${JBPF_AGENT_CPP_SOURCES}) 23 | add_cppcheck(${JBPF_AGENT_CPP_TEST} ${JBPF_AGENT_CPP_SOURCES}) 24 | 25 | add_subdirectory(request_validation) 26 | add_subdirectory(codeletSets) 27 | add_subdirectory(codelets) 28 | add_subdirectory(io) 29 | add_subdirectory(load_unload) 30 | add_subdirectory(verifier_extensions) 31 | add_subdirectory(ctrl_hooks) 32 | add_subdirectory(helper_functions) 33 | add_subdirectory(array) 34 | 35 | -------------------------------------------------------------------------------- /jbpf_tests/functional/array/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ## array tests 3 | set(ARRAY_FUNCTIONAL_TESTS ${TESTS_FUNCTIONAL}/array) 4 | file(GLOB ARRAY_FUNCTIONAL_TESTS_SOURCES ${ARRAY_FUNCTIONAL_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${ARRAY_FUNCTIONAL_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c ${JBPF_HASHMAP_MGMT_SOURCES}) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_HASHMAP_MGMT_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME FUNCTIONAL/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS FUNCTIONAL/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 27 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 28 | endforeach() 29 | -------------------------------------------------------------------------------- /jbpf_tests/functional/codeletSets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## codeletSets tests 2 | set(CODELET_SETS_TESTS ./) 3 | file(GLOB CODELET_SETS_TESTS_SOURCES ${CODELET_SETS_TESTS}/*.c) 4 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 5 | # Loop through each test file and create an executable 6 | foreach(TEST_FILE ${CODELET_SETS_TESTS_SOURCES}) 7 | # Get the filename without the path 8 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 9 | 10 | # Create an executable target for the test 11 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c) 12 | 13 | # Link the necessary libraries 14 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib) 15 | 16 | # Set the include directories 17 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 18 | 19 | # Add the test to the list of tests to be executed 20 | add_test(NAME codeletSets/${TEST_NAME} COMMAND ${TEST_NAME}) 21 | 22 | # Test Coverage 23 | list(APPEND JBPF_TESTS codeletSets/${TEST_NAME}) 24 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 25 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 26 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 27 | endforeach() 28 | -------------------------------------------------------------------------------- /jbpf_tests/functional/codelets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## codelet tests 2 | set(CODELETS_TESTS ${TESTS_FUNCTIONAL}/codelets) 3 | file(GLOB CODELETS_TESTS_SOURCES ${CODELETS_TESTS}/*.c) 4 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 5 | # Loop through each test file and create an executable 6 | foreach(TEST_FILE ${CODELETS_TESTS_SOURCES}) 7 | # Get the filename without the path 8 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 9 | 10 | # Create an executable target for the test 11 | add_executable(${TEST_NAME} ${TEST_FILE}) 12 | 13 | # Link the necessary libraries 14 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib) 15 | 16 | # Set the include directories 17 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 18 | 19 | # Add the test to the list of tests to be executed 20 | add_test(NAME codelets/${TEST_NAME} COMMAND ${TEST_NAME}) 21 | 22 | # Test coverage 23 | list(APPEND JBPF_TESTS codelets/${TEST_NAME}) 24 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 25 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 26 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 27 | endforeach() 28 | -------------------------------------------------------------------------------- /jbpf_tests/functional/ctrl_hooks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## request validation tests 2 | set(CTRL_HOOKS_TESTS ./) 3 | file(GLOB CTRL_HOOKS_TESTS_SOURCES ${CTRL_HOOKS_TESTS}/*.c) 4 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 5 | # Loop through each test file and create an executable 6 | foreach(TEST_FILE ${CTRL_HOOKS_TESTS_SOURCES}) 7 | # Get the filename without the path 8 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 9 | 10 | # Create an executable target for the test 11 | add_executable(${TEST_NAME} ${TEST_FILE}) 12 | 13 | # Link the necessary libraries 14 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib) 15 | 16 | # Set the include directories 17 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 18 | 19 | # Add the test to the list of tests to be executed 20 | add_test(NAME ctrl_hooks/${TEST_NAME} COMMAND ${TEST_NAME}) 21 | 22 | # Test Coverage 23 | list(APPEND JBPF_TESTS ctrl_hooks/${TEST_NAME}) 24 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 25 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 26 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 27 | endforeach() 28 | -------------------------------------------------------------------------------- /jbpf_tests/functional/helper_functions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ## array tests 3 | set(HELPER_FUNCTION_TESTS ${TESTS_FUNCTIONAL}/helper_functions) 4 | file(GLOB HELPER_FUNCTION_TESTS_SOURCES ${HELPER_FUNCTION_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${HELPER_FUNCTION_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c ${JBPF_HASHMAP_MGMT_SOURCES}) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_HASHMAP_MGMT_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME FUNCTIONAL/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS FUNCTIONAL/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 27 | endforeach() 28 | -------------------------------------------------------------------------------- /jbpf_tests/functional/io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## io tests 2 | set(IO_TESTS ${TESTS_FUNCTIONAL}/io) 3 | file(GLOB IO_TESTS_SOURCES ${IO_TESTS}/*.c) 4 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 5 | # Loop through each test file and create an executable 6 | foreach(TEST_FILE ${IO_TESTS_SOURCES}) 7 | # Get the filename without the path 8 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 9 | 10 | # Create an executable target for the test 11 | add_executable(${TEST_NAME} ${TEST_FILE}) 12 | # Link the necessary libraries 13 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::io_lib jbpf::mem_mgmt_lib jbpf::logger_lib ${CK_STATIC_LIB}) 14 | 15 | # Set the include directories 16 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_IO_HEADER_FILES} ${JBPF_MEM_MGMT_HEADER_FILES} ${TEST_HEADER_FILES}) 17 | 18 | # Add the test to the list of tests to be executed 19 | add_test(NAME io/${TEST_NAME} COMMAND ${TEST_NAME} $ $ ${RUNTIME_OUTPUT_DIRECTORY}) 20 | 21 | # Test coverage 22 | list(APPEND JBPF_TESTS io/${TEST_NAME}) 23 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 24 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 25 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 26 | endforeach() -------------------------------------------------------------------------------- /jbpf_tests/functional/jbpf_agent.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /** 3 | * This is more like an example to show that we can integrate jbpf to C++ applications 4 | */ 5 | #include 6 | #include 7 | 8 | #include "jbpf.h" 9 | #include "jbpf_hook.h" 10 | #include "jbpf_logging.h" 11 | #include "jbpf_test_def.h" 12 | #include "jbpf_agent_common.h" 13 | 14 | #include 15 | using namespace std; 16 | 17 | void* 18 | worker1(void* ctx) 19 | { 20 | jbpf_register_thread(); 21 | struct packet p = {1, 2}; 22 | 23 | while (1) { 24 | hook_test1(&p, 1); 25 | hook_test2(&p, 1); 26 | usleep(100000); 27 | } 28 | 29 | jbpf_cleanup_thread(); 30 | } 31 | 32 | int 33 | main(int argc, char** argv) 34 | { 35 | cout << "====== C++ Version of jbpf ======" << endl; 36 | int ret = 0; 37 | // pthread_t id1, id2, id3; 38 | // set your own logging 39 | jbpf_set_logging_level(DEBUG); 40 | jbpf_logger(JBPF_INFO, "Starting jbpf...\n"); 41 | 42 | // init jbpf 43 | struct jbpf_config* jbpf_config = static_cast(malloc(sizeof(struct jbpf_config))); 44 | jbpf_set_default_config_options(jbpf_config); 45 | 46 | if (!handle_signal()) { 47 | jbpf_logger(JBPF_WARN, "Could not handle SIGINT signal\n"); 48 | } 49 | 50 | if (jbpf_init(jbpf_config) < 0) { 51 | return -1; 52 | } 53 | 54 | // pthread_create(&id1, NULL, worker1, NULL); 55 | // pthread_create(&id2, NULL, worker1, NULL); 56 | // pthread_create(&id3, NULL, worker1, NULL); 57 | 58 | jbpf_register_thread(); 59 | 60 | struct packet p = {1, 2}; 61 | 62 | while (1) { 63 | hook_test1(&p, 1); 64 | hook_test2(&p, 1); 65 | usleep(100000); 66 | } 67 | 68 | jbpf_stop(); 69 | 70 | return ret; 71 | } 72 | -------------------------------------------------------------------------------- /jbpf_tests/functional/load_unload/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## request validation tests 2 | set(LOAD_UNLOAD_TESTS ./) 3 | file(GLOB LOAD_UNLOAD_TESTS_SOURCES ${LOAD_UNLOAD_TESTS}/*.c) 4 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 5 | # Loop through each test file and create an executable 6 | foreach(TEST_FILE ${LOAD_UNLOAD_TESTS_SOURCES}) 7 | # Get the filename without the path 8 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 9 | 10 | # Create an executable target for the test 11 | add_executable(${TEST_NAME} ${TEST_FILE}) 12 | 13 | # Link the necessary libraries 14 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib) 15 | 16 | # Set the include directories 17 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 18 | 19 | # Add the test to the list of tests to be executed 20 | add_test(NAME load_unload/${TEST_NAME} COMMAND ${TEST_NAME}) 21 | 22 | # Test Coverage 23 | list(APPEND JBPF_TESTS load_unload/${TEST_NAME}) 24 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 25 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 26 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 27 | endforeach() 28 | -------------------------------------------------------------------------------- /jbpf_tests/functional/request_validation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## request validation tests 2 | set(REQUEST_VALIDATION_TESTS ./) 3 | file(GLOB REQUEST_VALIDATION_TESTS_SOURCES ${REQUEST_VALIDATION_TESTS}/*.c) 4 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 5 | # Loop through each test file and create an executable 6 | foreach(TEST_FILE ${REQUEST_VALIDATION_TESTS_SOURCES}) 7 | # Get the filename without the path 8 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 9 | 10 | # Create an executable target for the test 11 | add_executable(${TEST_NAME} ${TEST_FILE}) 12 | 13 | # Link the necessary libraries 14 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib) 15 | 16 | # Set the include directories 17 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 18 | 19 | # Add the test to the list of tests to be executed 20 | add_test(NAME request_validation/${TEST_NAME} COMMAND ${TEST_NAME}) 21 | 22 | # Test Coverage 23 | list(APPEND JBPF_TESTS request_validation/${TEST_NAME}) 24 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 25 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 26 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 27 | endforeach() 28 | -------------------------------------------------------------------------------- /jbpf_tests/functional/request_validation/codeletSet_CodeletDescriptors_empty.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The purpose of this test is to ensure that at least 1 codelet is given, it is captured during validation 3 | * checks. 4 | * 5 | * This test does the following: 6 | * 1. It pupulates a codeletset with 0 codelets. 7 | * 2. It asserts that the return code from the jbpf_codeletset_load call is JBPF_CODELET_PARAM_INVALID). 8 | */ 9 | 10 | #include 11 | 12 | #include "jbpf.h" 13 | #include "jbpf_agent_common.h" 14 | #include "jbpf_utils.h" 15 | 16 | // Contains the struct and hook definitions 17 | #include "jbpf_test_def.h" 18 | 19 | jbpf_io_stream_id_t stream_id_c1 = { 20 | .id = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}}; 21 | 22 | int 23 | main(int argc, char** argv) 24 | { 25 | struct jbpf_codeletset_load_req codeletset_req_c1 = {0}; 26 | struct jbpf_config config = {0}; 27 | jbpf_codeletset_load_error_s err_msg = {0}; 28 | 29 | JBPF_UNUSED(err_msg); 30 | 31 | jbpf_set_default_config_options(&config); 32 | 33 | config.lcm_ipc_config.has_lcm_ipc_thread = false; 34 | 35 | assert(jbpf_init(&config) == 0); 36 | 37 | // The thread will be calling hooks, so we need to register it 38 | jbpf_register_thread(); 39 | 40 | // The name of the codeletset 41 | strcpy(codeletset_req_c1.codeletset_id.name, "simple_output_codeletset"); 42 | 43 | // set num to zero to indicate zero codelets 44 | codeletset_req_c1.num_codelet_descriptors = 0; 45 | 46 | // Load the codeletset 47 | assert(jbpf_codeletset_load(&codeletset_req_c1, &err_msg) == JBPF_CODELET_PARAM_INVALID); 48 | assert(strlen(err_msg.err_msg) > 0); 49 | 50 | // Stop 51 | jbpf_stop(); 52 | 53 | printf("Test completed successfully\n"); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /jbpf_tests/functional/verifier_extensions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## codelet tests 2 | set(VERIFIER_EXTENSIONS_TESTS ${TESTS_FUNCTIONAL}/verifier_extensions) 3 | 4 | file(GLOB VERIFIER_EXTENSIONS_TESTS_CPP_SOURCES ${VERIFIER_EXTENSIONS_TESTS}/*.cpp) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | 7 | # Loop through each test file and create an executable 8 | foreach(TEST_FILE ${VERIFIER_EXTENSIONS_TESTS_CPP_SOURCES}) 9 | # Get the filename without the path 10 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 11 | 12 | # Create an executable target for the test 13 | add_executable(${TEST_NAME} ${TEST_FILE}) 14 | 15 | # Link the necessary libraries 16 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib PUBLIC jbpf::verifier_lib) 17 | 18 | # Set the include directories 19 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${JBPF_VERIFIER_HEADERS} ${TEST_HEADER_FILES}) 20 | 21 | # Add the test to the list of tests to be executed 22 | add_test(NAME verifier_extensions/${TEST_NAME} COMMAND ${TEST_NAME}) 23 | 24 | # Test coverage 25 | list(APPEND JBPF_TESTS verifier_extensions/${TEST_NAME}) 26 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 27 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 28 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 29 | endforeach() 30 | -------------------------------------------------------------------------------- /jbpf_tests/stress_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 4 | set(TESTS_STRESS_BASE ${TESTS_BASE}/stress_tests) 5 | add_subdirectory(io) 6 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 7 | -------------------------------------------------------------------------------- /jbpf_tests/stress_tests/io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## io tests 2 | file(GLOB IO_STRESS_TESTS_SOURCES ${TESTS_STRESS_BASE}/io/*.c) 3 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 4 | 5 | # Loop through each test file and create an executable 6 | foreach(TEST_FILE ${IO_STRESS_TESTS_SOURCES}) 7 | # Get the filename without the path 8 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 9 | 10 | # Create an executable target for the test 11 | add_executable(${TEST_NAME} ${TEST_FILE}) 12 | 13 | # Link the necessary libraries 14 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::io_lib jbpf::mem_mgmt_lib jbpf::logger_lib ${CK_STATIC_LIB}) 15 | 16 | # Set the include directories 17 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_IO_HEADER_FILES} ${TEST_HEADER_FILES}) 18 | 19 | # Add the test to the list of tests to be executed 20 | add_test(NAME io_stress/${TEST_NAME} COMMAND ${TEST_NAME}) 21 | 22 | # Test coverage 23 | list(APPEND JBPF_TESTS io_stress/${TEST_NAME}) 24 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 25 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 26 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 27 | endforeach() 28 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/Makefile: -------------------------------------------------------------------------------- 1 | all: codelets-all 2 | 3 | clean: codelets-cleanall 4 | 5 | include Makefile.defs 6 | include Makefile.common 7 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/Makefile.common: -------------------------------------------------------------------------------- 1 | SUBDIRS := $(wildcard */) 2 | SUBDIRS_WITH_MAKEFILES := $(filter %/Makefile,$(foreach dir,$(SUBDIRS),$(wildcard $(dir)Makefile))) 3 | 4 | #DIRS := $(shell find . -type d) 5 | 6 | all: $(OBJECTS) 7 | 8 | $(OBJECTS): %.o : %.c 9 | $(CC) $(INC) $(CFLAGS) -c $< 10 | 11 | clean: 12 | rm -f $(OBJECTS) 13 | 14 | .PHONY: codelets-all 15 | codelets-all: 16 | @for lib in $(SUBDIRS) ; do \ 17 | $(MAKE) -C $$lib $(OBJECTS) || exit 1; \ 18 | done 19 | 20 | .PHONY: codelets-cleanall 21 | codelets-cleanall: 22 | @for lib in $(SUBDIRS) ; do \ 23 | $(MAKE) -C $$lib clean || 1 ; \ 24 | done 25 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/Makefile.defs: -------------------------------------------------------------------------------- 1 | CC = clang 2 | INC= -I${JBPF_PATH}/src/common -I${JBPF_PATH}/jbpf_tests/common -I${JBPF_PATH}/src/core 3 | CFLAGS = -O2 -target bpf -Wall -DJBPF_DEBUG_ENABLED -D__x86_64__ 4 | SOURCES = $(wildcard *.c) 5 | OBJECTS = $(SOURCES:.c=.o) 6 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/atomics-example/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/atomics-example/atomics-example.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/atomics-example/atomics-example.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-array/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-array/codelet-array.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-array/codelet-array.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-control-input-output/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-control-input-output/codelet-control-input.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the concurrency of the control input API. 4 | Only one thread will be able to write to the control input at a time. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_control_input_map(input_map1, custom_api, 100); 14 | 15 | jbpf_control_input_map(input_map2, custom_api2, 100); 16 | 17 | jbpf_output_map(output_map1, custom_api, 1000); 18 | 19 | jbpf_output_map(output_map2, custom_api2, 1000); 20 | 21 | SEC("jbpf_generic") 22 | uint64_t 23 | jbpf_main(void* state) 24 | { 25 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 26 | struct packet4* data = (struct packet4*)ctx->data; 27 | struct packet4* data_end = (struct packet4*)ctx->data_end; 28 | if (data + 1 > data_end) { 29 | return 1; 30 | } 31 | 32 | custom_api api; 33 | custom_api2 api2; 34 | 35 | if (jbpf_control_input_receive(&input_map1, &api, sizeof(custom_api)) > 0) { 36 | data->counter_a++; 37 | custom_api* out1; 38 | out1 = jbpf_get_output_buf(&output_map1); 39 | if (!out1) { 40 | return 1; 41 | } 42 | memcpy(out1, &api, sizeof(custom_api)); 43 | if (jbpf_send_output(&output_map1) < 0) { 44 | return 1; 45 | } 46 | } else { 47 | data->counter_b++; 48 | } 49 | if (jbpf_control_input_receive(&input_map2, &api2, sizeof(custom_api2)) > 0) { 50 | data->counter_c++; 51 | custom_api2* out2; 52 | out2 = jbpf_get_output_buf(&output_map2); 53 | if (!out2) { 54 | return 1; 55 | } 56 | memcpy(out2, &api2, sizeof(custom_api2)); 57 | if (jbpf_send_output(&output_map2) < 0) { 58 | return 1; 59 | } 60 | } else { 61 | data->counter_d++; 62 | } 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-control-input-output/codelet-control-input.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-control-input-output/codelet-control-input.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-control-input-withFailures/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-control-input-withFailures/codelet-control-input-withFailures.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests different return codes from a codelet. 4 | Only one thread will be able to write to the control input at a time. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_control_input_map(input_map, custom_api, 100); 14 | 15 | jbpf_output_map(output_map, custom_api, 1000); 16 | 17 | SEC("jbpf_generic") 18 | uint64_t 19 | jbpf_main(void* state) 20 | { 21 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 22 | struct counter_vals* data = (struct counter_vals*)ctx->data; 23 | struct counter_vals* data_end = (struct counter_vals*)ctx->data_end; 24 | if (data + 1 > data_end) { 25 | return 1; 26 | } 27 | 28 | custom_api api; 29 | 30 | if (jbpf_control_input_receive(&input_map, &api, sizeof(custom_api)) > 0) { 31 | if ((data->u32_counter % 2) == 0) { 32 | return data->u32_counter; 33 | } else { 34 | custom_api* out; 35 | out = jbpf_get_output_buf(&output_map); 36 | if (!out) { 37 | return data->u32_and_flag; 38 | } 39 | out->command = data->u32_counter; 40 | if (jbpf_send_output(&output_map) < 0) { 41 | return data->u32_and_flag; 42 | } 43 | } 44 | } else { 45 | return data->u32_or_flag; 46 | } 47 | return data->u32_xor_flag; 48 | } 49 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-control-input-withFailures/codelet-control-input-withFailures.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-control-input-withFailures/codelet-control-input-withFailures.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-control-input/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-control-input/codelet-control-input.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the concurrency of the control input API. 4 | Only one thread will be able to write to the control input at a time. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_control_input_map(input_map1, custom_api, 100) 14 | 15 | jbpf_control_input_map(input_map2, custom_api2, 100) 16 | 17 | jbpf_ringbuf_map(output_map1, custom_api, 100) 18 | 19 | jbpf_ringbuf_map(output_map2, custom_api2, 100) 20 | 21 | SEC("jbpf_generic") uint64_t jbpf_main(void* state) 22 | { 23 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 24 | struct packet4* data = (struct packet4*)ctx->data; 25 | struct packet4* data_end = (struct packet4*)ctx->data_end; 26 | if (data + 1 > data_end) { 27 | return 1; 28 | } 29 | 30 | custom_api api; 31 | custom_api2 api2; 32 | 33 | if (jbpf_control_input_receive(&input_map1, &api, sizeof(custom_api)) > 0) { 34 | data->counter_a++; 35 | if (jbpf_ringbuf_output(&output_map1, &api, sizeof(custom_api)) < 0) { 36 | return 1; 37 | } 38 | } else { 39 | data->counter_b++; 40 | } 41 | if (jbpf_control_input_receive(&input_map2, &api2, sizeof(custom_api2)) > 0) { 42 | data->counter_c++; 43 | if (jbpf_ringbuf_output(&output_map2, &api2, sizeof(custom_api2)) < 0) { 44 | return 1; 45 | } 46 | } else { 47 | data->counter_d++; 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-control-input/codelet-control-input.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-control-input/codelet-control-input.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-hashmap/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-hashmap/codelet-hashmap.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet is used to test the hash map read and write 4 | if the counter_a is negative, we increment map[key] 5 | otherwise, we increment counter_b by map[key] 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include "jbpf_defs.h" 11 | #include "jbpf_helper.h" 12 | #include "jbpf_test_def.h" 13 | #include 14 | 15 | struct jbpf_load_map_def SEC("maps") map1 = { 16 | .type = JBPF_MAP_TYPE_HASHMAP, 17 | .key_size = sizeof(uint64_t), 18 | .value_size = sizeof(int), 19 | .max_entries = 1, 20 | }; 21 | 22 | SEC("jbpf_generic") 23 | uint64_t 24 | jbpf_main(void* state) 25 | { 26 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 27 | struct packet* data = (struct packet*)ctx->data; 28 | struct packet* data_end = (struct packet*)ctx->data_end; 29 | if (data + 1 > data_end) { 30 | return 1; 31 | } 32 | uint64_t key = 0; 33 | // if counter_a is negative we increment the map[key] by counter_b 34 | // else we set the counter_b from reading map[key] 35 | if (data->counter_a < 0) { 36 | // get the value from the map and increment it 37 | int* val = (int*)jbpf_map_lookup_elem(&map1, &key); 38 | int new_val = 0; 39 | if (val) { 40 | new_val = *val; 41 | } 42 | new_val++; 43 | // then we update the map with the new value 44 | if (jbpf_map_try_update_elem(&map1, &key, &new_val, 0) != JBPF_MAP_SUCCESS) { 45 | return 1; 46 | } 47 | } else { 48 | int* val = (int*)jbpf_map_lookup_elem(&map1, &key); 49 | if (val) { 50 | data->counter_b += *val; 51 | } 52 | } 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-hashmap/codelet-hashmap.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-hashmap/codelet-hashmap.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-large-map-output/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-large-map-output/codelet-large-map.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-large-map-output/codelet-large-map.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-large-map/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-large-map/codelet-large-map.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-large-map/codelet-large-map.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-map-array/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-map-array/codelet-map-array.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-map-array/codelet-map-array.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-multithreading-output/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-multithreading-output/codelet-multithreading.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the concurrency of jbpf_send_output - only 1 is allowed, and others will fail 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include "jbpf_defs.h" 9 | #include "jbpf_helper.h" 10 | #include "jbpf_test_def.h" 11 | #include 12 | 13 | jbpf_output_map(map1, req_resp, 1000); 14 | 15 | SEC("jbpf_generic") 16 | uint64_t 17 | jbpf_main(void* state) 18 | { 19 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 20 | struct packet* data = (struct packet*)ctx->data; 21 | struct packet* data_end = (struct packet*)ctx->data_end; 22 | if (data + 1 > data_end) { 23 | return 1; 24 | } 25 | // if success counter_a ++ otherwise counter_b ++; 26 | req_resp* out1; 27 | out1 = jbpf_get_output_buf(&map1); 28 | if (!out1) { 29 | data->counter_b++; 30 | return 0; 31 | } 32 | out1->req_or_resp.resp.id = data->counter_a; 33 | out1->which_req_or_resp = 2; 34 | if (jbpf_send_output(&map1) < 0) { 35 | data->counter_b++; 36 | } else { 37 | data->counter_a++; 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-multithreading-output/codelet-multithreading.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-multithreading-output/codelet-multithreading.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-per-thread/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-per-thread/codelet-per-thread.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-per-thread/codelet-per-thread.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-ringbuf-multithreading/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-ringbuf-multithreading/codelet-ringbuf-multithreading.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | The codelet calls jbpf_ringbuf_output. And if the call is successful, it increments the counter_a in the packet struct. 4 | Otherwise, it increments the counter_b. 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | #include 13 | 14 | jbpf_ringbuf_map(map1, req_resp, 10000) 15 | 16 | SEC("jbpf_generic") uint64_t jbpf_main(void* state) 17 | { 18 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 19 | struct packet* data = (struct packet*)ctx->data; 20 | struct packet* data_end = (struct packet*)ctx->data_end; 21 | if (data + 1 > data_end) { 22 | return 1; 23 | } 24 | req_resp out_data = {0}; 25 | out_data.which_req_or_resp = 2; 26 | // if success counter_a ++ otherwise counter_b ++; 27 | if (0 == jbpf_ringbuf_output(&map1, &out_data, sizeof(req_resp))) { 28 | data->counter_a++; 29 | } else { 30 | data->counter_b++; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/codelet-ringbuf-multithreading/codelet-ringbuf-multithreading.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/codelet-ringbuf-multithreading/codelet-ringbuf-multithreading.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/error_infinite_loop/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/error_infinite_loop/error_infinite_loop.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | 7 | struct packet 8 | { 9 | int counter_a; 10 | int counter_b; 11 | }; 12 | 13 | SEC("jbpf_generic") 14 | uint64_t 15 | jbpf_main(void* state) 16 | { 17 | 18 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 19 | 20 | struct packet* p = (struct packet*)(long)ctx->data; 21 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 22 | 23 | if (p + 1 > p_end) 24 | return 1; 25 | 26 | while (1) { 27 | p->counter_a++; 28 | } 29 | /* Example of how to use the printf helper function */ 30 | // jbpf_printf_debug("The output is %d\n", p->counter_a); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/error_infinite_loop/error_infinite_loop.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/error_infinite_loop/error_infinite_loop.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/error_invalid_ctx/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/error_invalid_ctx/error_invalid_ctx.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | 7 | struct packet 8 | { 9 | int counter_a; 10 | int counter_b; 11 | }; 12 | 13 | // Context that does not match the type of program ("jbpf_generic") 14 | struct jbpf_unknown_ctx 15 | { 16 | uint64_t data; 17 | uint64_t data_end; 18 | uint64_t meta_data; 19 | uint32_t ctx_id; 20 | uint32_t unknown_field1; 21 | uint32_t unknown_field2; 22 | }; 23 | 24 | SEC("jbpf_generic") 25 | uint64_t 26 | jbpf_main(void* state) 27 | { 28 | 29 | struct jbpf_unknown_ctx* ctx = (struct jbpf_unknown_ctx*)state; 30 | 31 | struct packet* p = (struct packet*)(long)ctx->data; 32 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 33 | 34 | if (p + 1 > p_end) 35 | return 1; 36 | 37 | p->counter_a = ctx->unknown_field2; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/error_invalid_ctx/error_invalid_ctx.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/error_invalid_ctx/error_invalid_ctx.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/error_unknown_helper/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/error_unknown_helper/error_unknown_helper.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | 7 | struct packet 8 | { 9 | int counter_a; 10 | int counter_b; 11 | }; 12 | 13 | // Use relocation value 100, which does not exist 14 | static void (*unknown_helper_function)(int, int, int) = (void*)MAX_HELPER_FUNC; 15 | 16 | SEC("jbpf_generic") 17 | uint64_t 18 | jbpf_main(void* state) 19 | { 20 | 21 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 22 | 23 | struct packet* p = (struct packet*)(long)ctx->data; 24 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 25 | 26 | if (p + 1 > p_end) 27 | return 1; 28 | 29 | p->counter_a++; 30 | 31 | unknown_helper_function(p->counter_a, p->counter_b, 100); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/error_unknown_helper/error_unknown_helper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/error_unknown_helper/error_unknown_helper.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/helper-function-jbpf-hash/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/helper-function-jbpf-hash/jbpf_helper_example.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the jbpf_hash helper function. 4 | This codelet serves and example of how to use the jbpf_hash helper function. 5 | */ 6 | 7 | #include 8 | #include "jbpf_helper.h" 9 | #include "jbpf_test_def.h" 10 | 11 | SEC("jbpf_generic") 12 | uint64_t 13 | jbpf_main(void* state) 14 | { 15 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 16 | struct test_packet* data = (struct test_packet*)ctx->data; 17 | struct test_packet* data_end = (struct test_packet*)ctx->data_end; 18 | if (data + 1 > data_end) { 19 | return 1; 20 | } 21 | char msg[14] = {0}; 22 | strcpy(msg, "Hello, World!"); 23 | uint32_t hash = jbpf_hash(msg, 14); 24 | // jbpf_printf_debug("Hash: %x\n", hash); 25 | data->test_passed = hash == 0xb3a4ed74; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/helper-function-jbpf-hash/jbpf_helper_example.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/helper-function-jbpf-hash/jbpf_helper_example.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/helper_funcs/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/helper_funcs/all_maps.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/helper_funcs/all_maps.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/helper_funcs/helper_funcs_all_argTypes.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/helper_funcs/helper_funcs_all_argTypes.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/helper_funcs/helper_funcs_max_output.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/helper_funcs/helper_funcs_max_output.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/helper_function_fixpoint/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/helper_function_fixpoint/jbpf_helper_fixpoint.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/helper_function_fixpoint/jbpf_helper_fixpoint.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/max_input_shared/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/max_input_shared/max_input_shared.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/max_input_shared/max_input_shared.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/max_output_shared/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/max_output_shared/max_output_shared.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/max_output_shared/max_output_shared.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/new_helper/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/new_helper/new_helper.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | #include "jbpf_verifier_extension_defs.h" 7 | 8 | // Helper function extension 9 | static int (*unknown_helper_function)(void*, int, int, int) = (void*)CUSTOM_HELPER_START_ID; 10 | 11 | struct packet 12 | { 13 | int counter_a; 14 | int counter_b; 15 | }; 16 | 17 | // New program type "jbpf_my_prog_type" 18 | SEC("jbpf_generic") 19 | uint64_t 20 | jbpf_main(void* state) 21 | { 22 | 23 | // New type of context defined in "jbpf_verifier_extension_defs.h" 24 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 25 | 26 | int res = 0; 27 | 28 | struct packet* p = (struct packet*)(long)ctx->data; 29 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 30 | 31 | if (p + 1 > p_end) 32 | return 0; 33 | 34 | res = unknown_helper_function(ctx, 100, 200, 300); 35 | jbpf_time_get_ns(); 36 | 37 | p->counter_a = res; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/new_helper/new_helper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/new_helper/new_helper.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_largeShared/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_largeShared/simple_input_largeShared.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the concurrency of the control input API. 4 | Only one thread will be able to write to the control input at a time. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_control_input_map(input_map, custom_api, 100); 14 | 15 | struct jbpf_load_map_def SEC("maps") shared_map = { 16 | .type = JBPF_MAP_TYPE_ARRAY, 17 | .key_size = sizeof(int), 18 | .value_size = sizeof(int), 19 | .max_entries = 1000, 20 | }; 21 | 22 | SEC("jbpf_generic") 23 | uint64_t 24 | jbpf_main(void* state) 25 | { 26 | uint32_t index = 0; 27 | custom_api api = {0}; 28 | 29 | if (jbpf_control_input_receive(&input_map, &api, sizeof(custom_api)) > 0) { 30 | if (jbpf_map_update_elem(&shared_map, &index, &api.command, 0) < 0) { 31 | return 1; 32 | } 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_largeShared/simple_input_largeShared.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_input_largeShared/simple_input_largeShared.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_output/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_output/simple_input_output.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet receives a command from the control input and sends it to the output. 4 | */ 5 | 6 | #include 7 | 8 | #include "jbpf_defs.h" 9 | #include "jbpf_helper.h" 10 | #include "jbpf_test_def.h" 11 | 12 | jbpf_control_input_map(input_map, custom_api, 10000); 13 | 14 | jbpf_output_map(output_map, int, 10000); 15 | 16 | SEC("jbpf_generic") 17 | uint64_t 18 | jbpf_main(void* state) 19 | { 20 | custom_api api = {0}; 21 | int* output; 22 | 23 | if (jbpf_control_input_receive(&input_map, &api, sizeof(custom_api)) > 0) { 24 | output = jbpf_get_output_buf(&output_map); 25 | 26 | if (!output) { 27 | return 1; 28 | } 29 | *output = api.command; 30 | 31 | if (jbpf_send_output(&output_map) < 0) { 32 | return 1; 33 | } 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_output/simple_input_output.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_input_output/simple_input_output.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_output_atomic/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_output_atomic/simple_input_output_atomic.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet receives a command from the control input and increments a counter using atomic operations. 4 | If the control input is received, the counter_a is incremented, otherwise counter_b is incremented. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_control_input_map(input_map, custom_api, 10000); 14 | 15 | SEC("jbpf_generic") 16 | uint64_t 17 | jbpf_main(void* state) 18 | { 19 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 20 | struct packet* data = (struct packet*)ctx->data; 21 | struct packet* data_end = (struct packet*)ctx->data_end; 22 | if (data + 1 > data_end) { 23 | return 1; 24 | } 25 | custom_api api = {0}; 26 | 27 | if (jbpf_control_input_receive(&input_map, &api, sizeof(custom_api)) > 0) { 28 | __sync_fetch_and_add(&data->counter_a, 1); 29 | } else { 30 | __sync_fetch_and_add(&data->counter_b, 1); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_output_atomic/simple_input_output_atomic.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_input_output_atomic/simple_input_output_atomic.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_shared/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_shared/simple_input_shared.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the concurrency of the control input API. 4 | Only one thread will be able to write to the control input at a time. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_control_input_map(input_map, custom_api, 100); 14 | 15 | struct jbpf_load_map_def SEC("maps") shared_map = { 16 | .type = JBPF_MAP_TYPE_ARRAY, 17 | .key_size = sizeof(int), 18 | .value_size = sizeof(int), 19 | .max_entries = 1, 20 | }; 21 | 22 | SEC("jbpf_generic") 23 | uint64_t 24 | jbpf_main(void* state) 25 | { 26 | uint32_t index = 0; 27 | custom_api api = {0}; 28 | 29 | if (jbpf_control_input_receive(&input_map, &api, sizeof(custom_api)) > 0) { 30 | if (jbpf_map_try_update_elem(&shared_map, &index, &api.command, 0) < 0) { 31 | return 1; 32 | } 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_shared/simple_input_shared.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_input_shared/simple_input_shared.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_shared_maxLen/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_input_shared_maxLen/simple_input_shared_maxLen.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_input_shared_maxLen/simple_input_shared_maxLen.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output/simple_output.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_test_def.h" 6 | #include "jbpf_helper.h" 7 | 8 | // Send a single int value out 9 | jbpf_ringbuf_map(output_map, int, 10); 10 | 11 | SEC("jbpf_generic") 12 | uint64_t 13 | jbpf_main(void* state) 14 | { 15 | 16 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 17 | 18 | struct packet* p = (struct packet*)(long)ctx->data; 19 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 20 | 21 | if (p + 1 > p_end) 22 | return 1; 23 | 24 | if (jbpf_ringbuf_output(&output_map, &p->counter_a, sizeof(int)) < 0) { 25 | return 1; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output/simple_output.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_output/simple_output.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_2shared/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_2shared/simple_output_2shared.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the concurrency of the control input API. 4 | Only one thread will be able to write to the control input at a time. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_output_map(output_map, int, 100); 14 | 15 | struct jbpf_load_map_def SEC("maps") shared_map_output0 = { 16 | .type = JBPF_MAP_TYPE_ARRAY, 17 | .key_size = sizeof(int), 18 | .value_size = sizeof(int), 19 | .max_entries = 1, 20 | }; 21 | 22 | struct jbpf_load_map_def SEC("maps") shared_map_output1 = { 23 | .type = JBPF_MAP_TYPE_ARRAY, 24 | .key_size = sizeof(int), 25 | .value_size = sizeof(int), 26 | .max_entries = 1, 27 | }; 28 | 29 | SEC("jbpf_generic") 30 | uint64_t 31 | jbpf_main(void* state) 32 | { 33 | uint32_t index = 0; 34 | int* output; 35 | int* outvar; 36 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 37 | struct packet* p = (struct packet*)(long)ctx->data; 38 | 39 | output = jbpf_map_lookup_elem(&shared_map_output0, &index); 40 | if (!output) { 41 | return 1; 42 | } 43 | 44 | *output = *output + p->counter_a; 45 | 46 | outvar = jbpf_get_output_buf(&output_map); 47 | if (!outvar) { 48 | return 1; 49 | } 50 | *outvar = *output; 51 | if (jbpf_send_output(&output_map) < 0) { 52 | return 1; 53 | } 54 | 55 | output = jbpf_map_lookup_elem(&shared_map_output1, &index); 56 | if (!output) { 57 | return 1; 58 | } 59 | 60 | *output = *output + p->counter_a; 61 | 62 | outvar = jbpf_get_output_buf(&output_map); 63 | if (!outvar) { 64 | return 1; 65 | } 66 | *outvar = *output; 67 | if (jbpf_send_output(&output_map) < 0) { 68 | return 1; 69 | } 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_2shared/simple_output_2shared.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_output_2shared/simple_output_2shared.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_floodChannel/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_floodChannel/simple_output_floodChannel.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_test_def.h" 6 | #include "jbpf_helper.h" 7 | 8 | // Send a single int value out 9 | jbpf_ringbuf_map(output_map, int, 10); 10 | 11 | struct jbpf_load_map_def SEC("maps") shared_counter_map = { 12 | .type = JBPF_MAP_TYPE_ARRAY, 13 | .key_size = sizeof(int), 14 | .value_size = sizeof(int), 15 | .max_entries = 1, 16 | }; 17 | 18 | SEC("jbpf_generic") 19 | uint64_t 20 | jbpf_main(void* state) 21 | { 22 | uint32_t index = 0; 23 | int* output; 24 | int i = 0; 25 | 26 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 27 | 28 | struct packet* p = (struct packet*)(long)ctx->data; 29 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 30 | 31 | if (p + 1 > p_end) 32 | return 1; 33 | 34 | output = jbpf_map_lookup_elem(&shared_counter_map, &index); 35 | if (!output) { 36 | return 1; 37 | } 38 | *output = *output + 1; 39 | 40 | // jbpf_printf_debug("Output: %d\n", *output); 41 | for (i = 0; i < 100; i++) { 42 | // dont check return code here. We are flooding the output 43 | if (jbpf_ringbuf_output(&output_map, output, sizeof(int)) < 0) { 44 | // failure 45 | p->counter_a++; 46 | } else { 47 | // success 48 | p->counter_b++; 49 | } 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_floodChannel/simple_output_floodChannel.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_output_floodChannel/simple_output_floodChannel.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared/simple_output_shared.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the concurrency of the control input API. 4 | Only one thread will be able to write to the control input at a time. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_output_map(output_map, int, 100); 14 | 15 | struct jbpf_load_map_def SEC("maps") shared_map_output = { 16 | .type = JBPF_MAP_TYPE_ARRAY, 17 | .key_size = sizeof(int), 18 | .value_size = sizeof(int), 19 | .max_entries = 1, 20 | }; 21 | 22 | SEC("jbpf_generic") 23 | uint64_t 24 | jbpf_main(void* state) 25 | { 26 | 27 | uint32_t index = 0; 28 | int* output; 29 | int* outvar; 30 | 31 | output = jbpf_map_lookup_elem(&shared_map_output, &index); 32 | if (!output) { 33 | return 1; 34 | } 35 | 36 | outvar = jbpf_get_output_buf(&output_map); 37 | 38 | if (!outvar) { 39 | return 1; 40 | } 41 | 42 | *outvar = *output; 43 | if (jbpf_send_output(&output_map) < 0) { 44 | return 1; 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared/simple_output_shared.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_output_shared/simple_output_shared.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared_counter/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared_counter/simple_output_shared_counter.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the concurrency of the control input API. 4 | Only one thread will be able to write to the control input at a time. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_ringbuf_map(output_map, int, 10); 14 | 15 | struct jbpf_load_map_def SEC("maps") shared_counter_map = { 16 | .type = JBPF_MAP_TYPE_ARRAY, 17 | .key_size = sizeof(int), 18 | .value_size = sizeof(int), 19 | .max_entries = 1, 20 | }; 21 | 22 | SEC("jbpf_generic") 23 | uint64_t 24 | jbpf_main(void* state) 25 | { 26 | 27 | uint32_t index = 0; 28 | int* output; 29 | 30 | output = jbpf_map_lookup_elem(&shared_counter_map, &index); 31 | if (!output) { 32 | return 1; 33 | } 34 | 35 | *output = *output + 1; 36 | // jbpf_printf_debug("Output: %d\n", *output); 37 | 38 | if (jbpf_ringbuf_output(&output_map, output, sizeof(int)) < 0) { 39 | return 1; 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared_counter/simple_output_shared_counter.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_output_shared_counter/simple_output_shared_counter.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared_counter_perThread/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared_counter_perThread/simple_output_shared_counter_perThread.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | /* 3 | This codelet tests the concurrency of the control input API. 4 | Only one thread will be able to write to the control input at a time. 5 | */ 6 | 7 | #include 8 | 9 | #include "jbpf_defs.h" 10 | #include "jbpf_helper.h" 11 | #include "jbpf_test_def.h" 12 | 13 | jbpf_ringbuf_map(output_map, int, 10); 14 | 15 | struct jbpf_load_map_def SEC("maps") shared_counter_map = { 16 | .type = JBPF_MAP_TYPE_PER_THREAD_ARRAY, 17 | .key_size = sizeof(int), 18 | .value_size = sizeof(int), 19 | .max_entries = 1, 20 | }; 21 | 22 | SEC("jbpf_generic") 23 | uint64_t 24 | jbpf_main(void* state) 25 | { 26 | 27 | uint32_t index = 0; 28 | int* output; 29 | 30 | output = jbpf_map_lookup_elem(&shared_counter_map, &index); 31 | if (!output) { 32 | return 1; 33 | } 34 | 35 | *output = *output + 1; 36 | // jbpf_printf_debug("Output: %d\n", *output); 37 | 38 | if (jbpf_ringbuf_output(&output_map, output, sizeof(int)) < 0) { 39 | return 1; 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared_counter_perThread/simple_output_shared_counter_perThread.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_output_shared_counter_perThread/simple_output_shared_counter_perThread.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared_maxLen/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common 3 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_output_shared_maxLen/simple_output_shared_maxLen.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_output_shared_maxLen/simple_output_shared_maxLen.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test1/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test1/simple_test1.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | 7 | struct packet 8 | { 9 | int counter_a; 10 | int counter_b; 11 | }; 12 | 13 | SEC("jbpf_generic") 14 | uint64_t 15 | jbpf_main(void* state) 16 | { 17 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 18 | 19 | struct packet* p = (struct packet*)(long)ctx->data; 20 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 21 | 22 | if (p + 1 > p_end) 23 | return 1; 24 | 25 | p->counter_a++; 26 | 27 | /* Example of how to use the printf helper function */ 28 | // jbpf_printf_debug("The output is %d\n", p->counter_a); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test1/simple_test1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_test1/simple_test1.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test1_shared/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test1_shared/simple_test1_shared.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | 7 | struct jbpf_load_map_def SEC("maps") counter_a = { 8 | .type = JBPF_MAP_TYPE_ARRAY, 9 | .key_size = sizeof(uint32_t), 10 | .value_size = sizeof(long), 11 | .max_entries = 1, 12 | }; 13 | 14 | struct packet 15 | { 16 | int counter_a; 17 | int counter_b; 18 | }; 19 | 20 | SEC("jbpf_generic") 21 | uint64_t 22 | jbpf_main(void* state) 23 | { 24 | void* c; 25 | long counter; 26 | uint32_t index = 0; 27 | 28 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 29 | 30 | struct packet* p = (struct packet*)(long)ctx->data; 31 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 32 | 33 | /* Counter that checks if round is even or odd */ 34 | c = jbpf_map_lookup_elem(&counter_a, &index); 35 | if (!c) 36 | return 1; 37 | counter = *(long*)c; 38 | counter++; 39 | 40 | if (p + 1 > p_end) 41 | return 1; 42 | 43 | p->counter_a = counter; 44 | 45 | if (jbpf_map_try_update_elem(&counter_a, &index, &counter, 0) != JBPF_MAP_SUCCESS) { 46 | return 1; 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test1_shared/simple_test1_shared.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_test1_shared/simple_test1_shared.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test2/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test2/simple_test2.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | 7 | struct jbpf_load_map_def SEC("maps") counter_a = { 8 | .type = JBPF_MAP_TYPE_ARRAY, 9 | .key_size = sizeof(uint32_t), 10 | .value_size = sizeof(long), 11 | .max_entries = 1, 12 | }; 13 | 14 | struct packet 15 | { 16 | int counter_a; 17 | int counter_b; 18 | }; 19 | 20 | SEC("jbpf_generic") 21 | uint64_t 22 | jbpf_main(void* state) 23 | { 24 | void* c; 25 | long counter; 26 | uint32_t index = 0; 27 | 28 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 29 | 30 | struct packet* p = (struct packet*)(long)ctx->data; 31 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 32 | 33 | /* Counter that checks if round is even or odd */ 34 | c = jbpf_map_lookup_elem(&counter_a, &index); 35 | if (!c) 36 | return 1; 37 | counter = *(int*)c; 38 | counter = (counter + 1); 39 | 40 | if (counter == 2) 41 | counter = 0; 42 | 43 | if (p + 1 > p_end) 44 | return 1; 45 | 46 | if (counter == 0) { 47 | p->counter_a++; 48 | } 49 | if (jbpf_map_try_update_elem(&counter_a, &index, &counter, 0) != JBPF_MAP_SUCCESS) { 50 | return 1; 51 | } 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test2/simple_test2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_test2/simple_test2.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test2_shared/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test2_shared/simple_test2_shared.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | 7 | struct jbpf_load_map_def SEC("maps") counter_a = { 8 | .type = JBPF_MAP_TYPE_ARRAY, 9 | .key_size = sizeof(uint32_t), 10 | .value_size = sizeof(long), 11 | .max_entries = 1, 12 | }; 13 | 14 | struct packet 15 | { 16 | int counter_a; 17 | int counter_b; 18 | }; 19 | 20 | SEC("jbpf_generic") 21 | uint64_t 22 | jbpf_main(void* state) 23 | { 24 | void* c; 25 | long counter; 26 | uint32_t index = 0; 27 | 28 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 29 | 30 | struct packet* p = (struct packet*)(long)ctx->data; 31 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 32 | 33 | /* Counter that checks if round is even or odd */ 34 | c = jbpf_map_lookup_elem(&counter_a, &index); 35 | if (!c) 36 | return 1; 37 | counter = *(int*)c; 38 | counter++; 39 | 40 | if (p + 1 > p_end) 41 | return 1; 42 | 43 | p->counter_a = counter; 44 | 45 | if (jbpf_map_try_update_elem(&counter_a, &index, &counter, 0) != JBPF_MAP_SUCCESS) { 46 | return 1; 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test2_shared/simple_test2_shared.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_test2_shared/simple_test2_shared.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test_shared_multiple_maps/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test_shared_multiple_maps/simple_test1_shared_multiple_maps.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | #include "jbpf_test_def.h" 7 | 8 | struct jbpf_load_map_def SEC("maps") counter_a = { 9 | .type = JBPF_MAP_TYPE_ARRAY, 10 | .key_size = sizeof(uint32_t), 11 | .value_size = sizeof(long), 12 | .max_entries = 1, 13 | }; 14 | 15 | struct jbpf_load_map_def SEC("maps") private_map = { 16 | .type = JBPF_MAP_TYPE_ARRAY, 17 | .key_size = sizeof(uint32_t), 18 | .value_size = sizeof(long), 19 | .max_entries = 20, 20 | }; 21 | 22 | SEC("jbpf_generic") 23 | uint64_t 24 | jbpf_main(void* state) 25 | { 26 | void* c; 27 | long counter, private_counter; 28 | uint32_t index = 0; 29 | uint32_t private_index = 10; 30 | 31 | struct jbpf_generic_ctx* ctx = (struct jbpf_generic_ctx*)state; 32 | 33 | struct packet* p = (struct packet*)(long)ctx->data; 34 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 35 | 36 | /* Counter that checks if round is even or odd */ 37 | c = jbpf_map_lookup_elem(&counter_a, &index); 38 | if (!c) 39 | return 1; 40 | counter = *(int*)c; 41 | counter++; 42 | 43 | if (p + 1 > p_end) 44 | return 1; 45 | 46 | p->counter_a = counter; 47 | 48 | if (jbpf_map_try_update_elem(&counter_a, &index, &counter, 0) != JBPF_MAP_SUCCESS) { 49 | return 1; 50 | } 51 | 52 | /* Counter that checks if round is even or odd */ 53 | c = jbpf_map_lookup_elem(&private_map, &private_index); 54 | if (!c) 55 | return 1; 56 | private_counter = *(int*)c; 57 | private_counter++; 58 | 59 | p->counter_b = private_counter; 60 | 61 | if (jbpf_map_try_update_elem(&private_map, &private_index, &private_counter, 0) != JBPF_MAP_SUCCESS) { 62 | return 1; 63 | } 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test_shared_multiple_maps/simple_test1_shared_multiple_maps.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_test_shared_multiple_maps/simple_test1_shared_multiple_maps.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/simple_test_shared_multiple_maps/simple_test2_shared_multiple_maps.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/simple_test_shared_multiple_maps/simple_test2_shared_multiple_maps.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/time_events/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/time_events/time_events.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // This codelet sends a single output value to the output ring buffer. 3 | // The value is the jbpf_time_get_ns() which we can emulate in the emulator. 4 | 5 | #include 6 | #include "jbpf_defs.h" 7 | #include "jbpf_test_def.h" 8 | #include "jbpf_helper.h" 9 | 10 | // Send a single int value out 11 | jbpf_ringbuf_map(output_map, uint64_t, 1000); 12 | 13 | SEC("jbpf_generic") 14 | uint64_t 15 | jbpf_main(void* state) 16 | { 17 | 18 | uint64_t a = jbpf_time_get_ns(); 19 | 20 | if (jbpf_ringbuf_output(&output_map, &a, sizeof(uint64_t)) < 0) { 21 | return 1; 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/time_events/time_events.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/time_events/time_events.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/verifier_extensions/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.defs 2 | include ../Makefile.common -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/verifier_extensions/verifier_extensions.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include "jbpf_defs.h" 5 | #include "jbpf_helper.h" 6 | #include "jbpf_verifier_extension_defs.h" 7 | 8 | // Helper function extension 9 | static int (*unknown_helper_function)(void*, int, int, int) = (void*)CUSTOM_HELPER_START_ID; 10 | 11 | // New type of map extension defined in "jbpf_verifier_extension_defs.h" 12 | struct jbpf_load_map_def SEC("maps") my_custom_map = { 13 | .type = CUSTOM_MAP_START_ID, 14 | .key_size = sizeof(uint32_t), 15 | .value_size = sizeof(long), 16 | .max_entries = 1, 17 | }; 18 | 19 | struct packet 20 | { 21 | int counter_a; 22 | }; 23 | 24 | // New program type "jbpf_my_prog_type" 25 | SEC("jbpf_my_prog_type") 26 | uint64_t 27 | jbpf_main(void* state) 28 | { 29 | 30 | // New type of context defined in "jbpf_verifier_extension_defs.h" 31 | struct my_new_jbpf_ctx* ctx = (struct my_new_jbpf_ctx*)state; 32 | 33 | int res = 0; 34 | int val_a = ctx->static_field1; 35 | int val_b = ctx->static_field2; 36 | int val_c = ctx->static_field3; 37 | 38 | struct packet* p = (struct packet*)(long)ctx->data; 39 | struct packet* p_end = (struct packet*)(long)ctx->data_end; 40 | 41 | if (p + 1 > p_end) 42 | return 1; 43 | 44 | res = unknown_helper_function(&my_custom_map, 100, 200, 300); 45 | 46 | // Set the computed value to counter_a, so that it can be checked by the testing program 47 | p->counter_a = val_a + val_b + val_c + res; 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/codelets/verifier_extensions/verifier_extensions.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/jbpf_tests/test_files/codelets/verifier_extensions/verifier_extensions.o -------------------------------------------------------------------------------- /jbpf_tests/test_files/serde_test_libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | project(serde_test_libs) 4 | 5 | set(TEST_SERDE_LIB test_serde) 6 | set(TEST_SERDE2_LIB test_serde2) 7 | 8 | set(SERDE_TEST_SRC_BASE ${PROJECT_SOURCE_DIR}) 9 | 10 | set(TEST_SERDE_LIB_SRC ${SERDE_TEST_SRC_BASE}/serde_lib_test_struct.c) 11 | set(TEST_SERDE2_LIB_SRC ${SERDE_TEST_SRC_BASE}/serde_lib_test_struct2.c) 12 | 13 | add_library(${TEST_SERDE_LIB} SHARED ${TEST_SERDE_LIB_SRC}) 14 | add_library(jbpf::test_serde ALIAS ${TEST_SERDE_LIB}) 15 | add_library(${TEST_SERDE2_LIB} SHARED ${TEST_SERDE2_LIB_SRC}) 16 | add_library(jbpf::test_serde2 ALIAS ${TEST_SERDE2_LIB}) -------------------------------------------------------------------------------- /jbpf_tests/test_files/serde_test_libs/serde_lib_test_struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | struct test_struct 7 | { 8 | uint32_t counter_a; 9 | uint32_t counter_b; 10 | }; 11 | 12 | // Function to find a key in the JSON string and return its integer value 13 | int 14 | get_json_value(const char* json, const char* key) 15 | { 16 | const char* pos = strstr(json, key); 17 | if (pos != NULL) { 18 | pos = strchr(pos, ':'); 19 | if (pos != NULL) { 20 | return atoi(pos + 1); 21 | } 22 | } 23 | return -1; 24 | } 25 | 26 | // Function to parse JSON and populate the struct 27 | int 28 | parse_json_to_struct(const char* json_string, struct test_struct* output_struct) 29 | { 30 | output_struct->counter_a = get_json_value(json_string, "counter_a"); 31 | output_struct->counter_b = get_json_value(json_string, "counter_b"); 32 | 33 | return (output_struct->counter_a != -1 && output_struct->counter_b != -1) ? 0 : -1; 34 | } 35 | 36 | int 37 | jbpf_io_serialize( 38 | void* input_msg_buf, size_t input_msg_buf_size, char* serialized_data_buf, size_t serialized_data_buf_size) 39 | { 40 | 41 | int res; 42 | char* str = "{ \"counter_a\": %u, \"counter_b\": %u }"; 43 | 44 | struct test_struct* s = input_msg_buf; 45 | res = snprintf(serialized_data_buf, serialized_data_buf_size, str, s->counter_a, s->counter_b); 46 | 47 | return res; 48 | } 49 | 50 | int 51 | jbpf_io_deserialize( 52 | char* serialized_data_buf, size_t serialized_data_buf_size, void* output_msg_buf, size_t output_msg_buf_size) 53 | { 54 | 55 | struct test_struct* output_struct = output_msg_buf; 56 | 57 | if (parse_json_to_struct(serialized_data_buf, output_struct) == 0) { 58 | return 1; 59 | } else { 60 | return 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /jbpf_tests/test_files/serde_test_libs/serde_lib_test_struct2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | struct test_struct2 7 | { 8 | int counter_a; 9 | }; 10 | 11 | // Function to find a key in the JSON string and return its integer value 12 | int 13 | get_json_value(const char* json, const char* key) 14 | { 15 | const char* pos = strstr(json, key); 16 | if (pos != NULL) { 17 | pos = strchr(pos, ':'); 18 | if (pos != NULL) { 19 | return atoi(pos + 1); 20 | } 21 | } 22 | return -1; 23 | } 24 | 25 | // Function to parse JSON and populate the struct 26 | int 27 | parse_json_to_struct(const char* json_string, struct test_struct2* output_struct) 28 | { 29 | output_struct->counter_a = get_json_value(json_string, "counter_a"); 30 | 31 | return (output_struct->counter_a != -1) ? 0 : -1; 32 | } 33 | 34 | int 35 | jbpf_io_serialize( 36 | void* input_msg_buf, size_t input_msg_buf_size, char* serialized_data_buf, size_t serialized_data_buf_size) 37 | { 38 | 39 | int res; 40 | char* str = "{ \"counter_a\": %d }"; 41 | 42 | struct test_struct2* s = input_msg_buf; 43 | res = snprintf(serialized_data_buf, serialized_data_buf_size, str, s->counter_a); 44 | 45 | return res; 46 | } 47 | 48 | int 49 | jbpf_io_deserialize( 50 | char* serialized_data_buf, size_t serialized_data_buf_size, void* output_msg_buf, size_t output_msg_buf_size) 51 | { 52 | 53 | struct test_struct2* output_struct = output_msg_buf; 54 | 55 | if (parse_json_to_struct(serialized_data_buf, output_struct) == 0) { 56 | return 1; 57 | } else { 58 | return 0; 59 | } 60 | } -------------------------------------------------------------------------------- /jbpf_tests/tools/lcm_cli/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | project(jbpf-tests-tools-lcm-cli) 3 | 4 | find_package(yaml-cpp REQUIRED) 5 | include_directories(${YAML_CPP_INCLUDE_DIRS}) 6 | 7 | ## lcm tests 8 | file(GLOB LCM_CLI_TESTS_SOURCES ${TESTS_BASE}/tools/lcm_cli/*.cpp) 9 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 10 | set(TEST_LCM_FILES ${JBPF_LCM_IPC_CLI_SRC_DIR}/loader.cpp ${JBPF_LCM_IPC_CLI_SRC_DIR}/parser.cpp ${JBPF_LCM_IPC_CLI_SRC_DIR}/stream_id.cpp) 11 | 12 | # Loop through each test file and create an executable 13 | foreach(TEST_FILE ${LCM_CLI_TESTS_SOURCES}) 14 | # Get the filename without the path 15 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 16 | 17 | # Create an executable target for the test 18 | add_executable(${TEST_NAME} ${TEST_FILE} ${TEST_LCM_FILES}) 19 | 20 | # Link the necessary libraries 21 | target_link_libraries(${TEST_NAME} PUBLIC 22 | ${YAML_CPP_LIBRARIES} 23 | jbpf::core_lib 24 | jbpf::verifier_lib 25 | jbpf::lcm_ipc_lib 26 | jbpf::logger_lib 27 | jbpf::mem_mgmt_lib 28 | jbpf::io_lib ${JBPF_CK_STATIC_LIB} 29 | --coverage) 30 | 31 | # Set the include directories 32 | target_include_directories(${TEST_NAME} PUBLIC ${TEST_HEADER_FILES} ${JBPF_LCM_IPC_HEADER_FILES} ${JBPF_LCM_IPC_CLI_HEADER_FILES}) 33 | 34 | # Add the test to the list of tests to be executed 35 | add_test(NAME lcm_cli_tests/${TEST_NAME} COMMAND ${TEST_NAME}) 36 | 37 | # Test coverage 38 | list(APPEND JBPF_TESTS lcm_cli_tests/${TEST_NAME}) 39 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 40 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 41 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 42 | endforeach() 43 | -------------------------------------------------------------------------------- /jbpf_tests/tools/lcm_cli/codeletset_req_c1.yaml: -------------------------------------------------------------------------------- 1 | codelet_descriptor: 2 | - codelet_name: simple_output 3 | codelet_path: ${JBPF_PATH}/jbpf_tests/test_files/codelets/simple_output/simple_output.o 4 | hook_name: test1 5 | out_io_channel: 6 | - name: output_map 7 | stream_id: 00112233445566778899AABBCCDDEEFF 8 | codeletset_id: simple_output_codeletset 9 | -------------------------------------------------------------------------------- /jbpf_tests/tools/lcm_cli/codeletset_req_error.yaml: -------------------------------------------------------------------------------- 1 | codelet_descriptor: 2 | - codelet_name: simple_output 3 | codelet_path: ${JBPF_PATH}/jbpf_tests/test_files/codelets/simple_output/simple_output.o 4 | hook_name: hook404 5 | codeletset_id: error_codeletset 6 | -------------------------------------------------------------------------------- /jbpf_tests/tools/lcm_cli/codeletset_req_with_linked_map.yaml: -------------------------------------------------------------------------------- 1 | codelet_descriptor: 2 | - codelet_name: max_input_shared 3 | codelet_path: ${JBPF_PATH}/jbpf_tests/test_files/codelets/max_input_shared/max_input_shared.o 4 | hook_name: test1 5 | in_io_channel: 6 | - name: input_map0 7 | stream_id: "00000000000000000000000000000000" 8 | - name: input_map1 9 | stream_id: "00000000000000000000000000000001" 10 | - name: input_map2 11 | stream_id: "00000000000000000000000000000002" 12 | - name: input_map3 13 | stream_id: "00000000000000000000000000000003" 14 | - name: input_map4 15 | stream_id: "00000000000000000000000000000004" 16 | - codelet_name: max_output_shared 17 | codelet_path: ${JBPF_PATH}/jbpf_tests/test_files/codelets/max_output_shared/max_output_shared.o 18 | hook_name: test1 19 | linked_maps: 20 | - linked_codelet_name: max_input_shared 21 | linked_map_name: shared_map0 22 | map_name: shared_map_output0 23 | - linked_codelet_name: max_input_shared 24 | linked_map_name: shared_map1 25 | map_name: shared_map_output1 26 | - linked_codelet_name: max_input_shared 27 | linked_map_name: shared_map2 28 | map_name: shared_map_output2 29 | - linked_codelet_name: max_input_shared 30 | linked_map_name: shared_map3 31 | map_name: shared_map_output3 32 | - linked_codelet_name: max_input_shared 33 | linked_map_name: shared_map4 34 | map_name: shared_map_output4 35 | out_io_channel: 36 | - name: output_map0 37 | stream_id: "00000000000000000000000000000000" 38 | - name: output_map1 39 | stream_id: "00000000000000000000000000000001" 40 | - name: output_map2 41 | stream_id: "00000000000000000000000000000002" 42 | - name: output_map3 43 | stream_id: "00000000000000000000000000000003" 44 | - name: output_map4 45 | stream_id: "00000000000000000000000000000004" 46 | codeletset_id: max_linked_map_codeletset 47 | -------------------------------------------------------------------------------- /jbpf_tests/tools/lcm_cli/codeletset_unload_req_c1.yaml: -------------------------------------------------------------------------------- 1 | codeletset_id: simple_output_codeletset 2 | -------------------------------------------------------------------------------- /jbpf_tests/tools/lcm_cli/codeletset_unload_req_error.yaml: -------------------------------------------------------------------------------- 1 | codeletset_id: non-existent-codeletset 2 | -------------------------------------------------------------------------------- /jbpf_tests/tools/lcm_cli/codeletset_unload_req_with_linked_map.yaml: -------------------------------------------------------------------------------- 1 | codeletset_id: max_linked_map_codeletset 2 | -------------------------------------------------------------------------------- /jbpf_tests/unit_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 4 | add_subdirectory(validate_string_param) 5 | add_subdirectory(bitmap) 6 | add_subdirectory(mem) 7 | add_subdirectory(io_mem) 8 | add_subdirectory(array) 9 | add_subdirectory(helper_functions) 10 | add_subdirectory(hashmap) 11 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) -------------------------------------------------------------------------------- /jbpf_tests/unit_tests/array/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ## array unit tests 3 | set(ARRAY_UNIT_TESTS ${TESTS_BASE}/unit_tests/array/) 4 | file(GLOB ARRAY_UNIT_TESTS_SOURCES ${ARRAY_UNIT_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${ARRAY_UNIT_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME unit_tests/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS unit_tests/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 27 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 28 | endforeach() 29 | -------------------------------------------------------------------------------- /jbpf_tests/unit_tests/bitmap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | ## bitmap tests 4 | set(JBPF_BITMAP_TEST jbpf_bitmap_test) 5 | set(JBPF_BITMAP_TESTS_SOURCE jbpf_bitmap_test.c ${TESTS_COMMON}/jbpf_test_lib.c) 6 | add_executable(${JBPF_BITMAP_TEST} ${JBPF_BITMAP_TESTS_SOURCE}) 7 | if(JBPF_STATIC) 8 | target_link_libraries(${JBPF_BITMAP_TEST} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 9 | else() 10 | target_link_libraries(${JBPF_BITMAP_TEST} PUBLIC jbpf::core_lib) 11 | endif() 12 | target_include_directories(${JBPF_BITMAP_TEST} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_LOGGER_HEADERS}) 13 | add_test(NAME unit_tests/${JBPF_BITMAP_TEST} COMMAND ${JBPF_BITMAP_TEST}) 14 | list(APPEND JBPF_TESTS unit_tests/${JBPF_BITMAP_TEST}) 15 | add_clang_format_check(${JBPF_BITMAP_TEST} ${JBPF_BITMAP_TESTS_SOURCE}) 16 | add_cppcheck(${JBPF_BITMAP_TEST} ${JBPF_BITMAP_TESTS_SOURCE}) 17 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 18 | -------------------------------------------------------------------------------- /jbpf_tests/unit_tests/hashmap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | ## hashmap unit tests 3 | set(HASHMAP_UNIT_TESTS ${TESTS_BASE}/unit_tests/hashmap/) 4 | file(GLOB HASHMAP_UNIT_TESTS_SOURCES ${HASHMAP_UNIT_TESTS}/*.c) 5 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 6 | # Loop through each test file and create an executable 7 | foreach(TEST_FILE ${HASHMAP_UNIT_TESTS_SOURCES}) 8 | # Get the filename without the path 9 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 10 | 11 | # Create an executable target for the test 12 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c) 13 | 14 | # Link the necessary libraries 15 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 16 | 17 | # Set the include directories 18 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 19 | 20 | # Add the test to the list of tests to be executed 21 | add_test(NAME unit_tests/${TEST_NAME} COMMAND ${TEST_NAME}) 22 | 23 | # Test coverage 24 | list(APPEND JBPF_TESTS unit_tests/${TEST_NAME}) 25 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 26 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 27 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 28 | endforeach() 29 | -------------------------------------------------------------------------------- /jbpf_tests/unit_tests/helper_functions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | ## unit tests for helper functions 4 | set(HELPER_FUNCTION_UNIT_TESTS ${TESTS_BASE}/unit_tests/helper_functions/) 5 | file(GLOB HELPER_FUNCTION_UNIT_TESTS_SOURCES ${HELPER_FUNCTION_UNIT_TESTS}/*.c) 6 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 7 | # Loop through each test file and create an executable 8 | foreach(TEST_FILE ${HELPER_FUNCTION_UNIT_TESTS_SOURCES}) 9 | # Get the filename without the path 10 | get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) 11 | 12 | # Create an executable target for the test 13 | add_executable(${TEST_NAME} ${TEST_FILE} ${TESTS_COMMON}/jbpf_test_lib.c) 14 | 15 | # Link the necessary libraries 16 | target_link_libraries(${TEST_NAME} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 17 | 18 | # Set the include directories 19 | target_include_directories(${TEST_NAME} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 20 | 21 | # Add the test to the list of tests to be executed 22 | add_test(NAME unit_tests/${TEST_NAME} COMMAND ${TEST_NAME}) 23 | 24 | # Test coverage 25 | list(APPEND JBPF_TESTS unit_tests/${TEST_NAME}) 26 | add_clang_format_check(${TEST_NAME} ${TEST_FILE}) 27 | add_cppcheck(${TEST_NAME} ${TEST_FILE}) 28 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 29 | endforeach() 30 | -------------------------------------------------------------------------------- /jbpf_tests/unit_tests/helper_functions/jbpf_runtime_threshold_test.c: -------------------------------------------------------------------------------- 1 | 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | /** 4 | * Unit tests for the following functions: 5 | * - __jbpf_runtime_limit_exceeded 6 | * - __jbpf_mark_runtime_init 7 | * 8 | * This tests the following scenarios: 9 | * 1. Set the runtime threshold to 1 second and check if the runtime limit is exceeded before and after the threshold. 10 | * 2. Set the runtime threshold to 500 ns and check if the runtime limit is exceeded after 1 second consistently. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "jbpf_test_lib.h" 19 | #include "jbpf_helper_impl.h" 20 | #include "jbpf_perf.h" 21 | 22 | static int 23 | test_setup(void** state) 24 | { 25 | __jbpf_mark_runtime_init(); 26 | _jbpf_calibrate_ticks(); 27 | return 0; 28 | } 29 | 30 | static void 31 | test_runtime_threshold_before_and_after(void** state) 32 | { 33 | // set threshold to 1 second 34 | __jbpf_set_e_runtime_threshold(1000 * 1000 * 1000); 35 | assert(__jbpf_runtime_limit_exceeded() == 0); 36 | assert(__jbpf_runtime_limit_exceeded() == 0); 37 | assert(__jbpf_runtime_limit_exceeded() == 0); 38 | sleep(1); 39 | assert(__jbpf_runtime_limit_exceeded() == 1); 40 | } 41 | 42 | static void 43 | test_runtime_threshold_consistent_passed(void** state) 44 | { 45 | __jbpf_set_e_runtime_threshold(500); 46 | sleep(1); 47 | assert(__jbpf_runtime_limit_exceeded() == 1); 48 | assert(__jbpf_runtime_limit_exceeded() == 1); 49 | } 50 | 51 | int 52 | main(int argc, char** argv) 53 | { 54 | const jbpf_test tests[] = { 55 | JBPF_CREATE_TEST(test_runtime_threshold_before_and_after, test_setup, NULL, NULL), 56 | JBPF_CREATE_TEST(test_runtime_threshold_consistent_passed, test_setup, NULL, NULL), 57 | }; 58 | 59 | int num_tests = sizeof(tests) / sizeof(jbpf_test); 60 | return jbpf_run_test(tests, num_tests, NULL, NULL); 61 | } 62 | -------------------------------------------------------------------------------- /jbpf_tests/unit_tests/io_mem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## jbpf_io unit tests 2 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 3 | set(JBPF_IO_MEM_UNIT_TESTS jbpf_io_mem_unit_test) 4 | set(JBPF_IO_MEM_UNIT_TESTS_SOURCE io_mem_unit_test.c ${TESTS_COMMON}/jbpf_test_lib.c ${JBPF_MEM_MGMT_SOURCES}) 5 | add_executable(${JBPF_IO_MEM_UNIT_TESTS} ${JBPF_IO_MEM_UNIT_TESTS_SOURCE}) 6 | target_link_libraries(${JBPF_IO_MEM_UNIT_TESTS} PUBLIC jbpf::core_lib jbpf::logger_lib jbpf::mem_mgmt_lib) 7 | target_include_directories(${JBPF_IO_MEM_UNIT_TESTS} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES} ${JBPF_MEM_MGMT_HEADER_FILES}) 8 | add_test(NAME unit_tests/${JBPF_IO_MEM_UNIT_TESTS} COMMAND ${JBPF_IO_MEM_UNIT_TESTS}) 9 | list(APPEND JBPF_TESTS ${JBPF_IO_MEM_UNIT_TESTS}) 10 | add_clang_format_check(${JBPF_IO_MEM_UNIT_TESTS} ${JBPF_IO_MEM_UNIT_TESTS_SOURCE}) 11 | add_cppcheck(${JBPF_IO_MEM_UNIT_TESTS} ${JBPF_IO_MEM_UNIT_TESTS_SOURCE}) 12 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) -------------------------------------------------------------------------------- /jbpf_tests/unit_tests/mem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## jbpf_io system tests 2 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 3 | set(JBPF_MEM_SYSTEM_TESTS jbpf_mem_system_test) 4 | set(JBPF_MEM_SYSTEM_TESTS_SOURCE jbpf_mem_system_test.c ${TESTS_COMMON}/jbpf_test_lib.c) 5 | add_executable(${JBPF_MEM_SYSTEM_TESTS} ${JBPF_MEM_SYSTEM_TESTS_SOURCE}) 6 | target_link_libraries(${JBPF_MEM_SYSTEM_TESTS} PUBLIC jbpf::core_lib) 7 | target_include_directories(${JBPF_MEM_SYSTEM_TESTS} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 8 | add_test(NAME unit_tests/${JBPF_MEM_SYSTEM_TESTS} COMMAND ${JBPF_MEM_SYSTEM_TESTS}) 9 | list(APPEND JBPF_TESTS ${JBPF_MEM_SYSTEM_TESTS}) 10 | add_clang_format_check(${JBPF_MEM_SYSTEM_TESTS} ${JBPF_MEM_SYSTEM_TESTS_SOURCE}) 11 | add_cppcheck(${JBPF_MEM_SYSTEM_TESTS} ${JBPF_MEM_SYSTEM_TESTS_SOURCE}) 12 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) -------------------------------------------------------------------------------- /jbpf_tests/unit_tests/validate_string_param/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## validate_string_param 4 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 5 | set(JBPF_UNIT_TEST_VALID_STRING_PARAM jbpf_unit_test_valid_string_param) 6 | set(JBPF_UNIT_TEST_VALID_STRING_PARAM_SOURCE validate_string_param_test.c ${TESTS_COMMON}/jbpf_test_lib.c) 7 | add_executable(${JBPF_UNIT_TEST_VALID_STRING_PARAM} ${JBPF_UNIT_TEST_VALID_STRING_PARAM_SOURCE}) 8 | target_link_libraries(${JBPF_UNIT_TEST_VALID_STRING_PARAM} PUBLIC jbpf::core_lib) 9 | target_include_directories(${JBPF_UNIT_TEST_VALID_STRING_PARAM} PUBLIC ${JBPF_LIB_HEADER_FILES} ${TEST_HEADER_FILES}) 10 | add_test(NAME unit_tests/${JBPF_UNIT_TEST_VALID_STRING_PARAM} COMMAND ${JBPF_UNIT_TEST_VALID_STRING_PARAM}) 11 | list(APPEND JBPF_TESTS ${JBPF_UNIT_TEST_VALID_STRING_PARAM}) 12 | add_clang_format_check(${JBPF_UNIT_TEST_VALID_STRING_PARAM} ${JBPF_UNIT_TEST_VALID_STRING_PARAM_SOURCE}) 13 | add_cppcheck(${JBPF_UNIT_TEST_VALID_STRING_PARAM} ${JBPF_UNIT_TEST_VALID_STRING_PARAM_SOURCE}) 14 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) -------------------------------------------------------------------------------- /jbpf_tests/verifier/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | include(ExternalProject) 4 | project(jbpf-tests-verifier) 5 | include(CTest) 6 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 7 | 8 | set(TESTS_VERIFIER ${TESTS_BASE}/verifier) 9 | set(JBPF_BASIC_VERIFIER_TEST jbpf_basic_verifier_test) 10 | set(JBPF_BASIC_VERIFIER_TEST_SOURCES ${TESTS_VERIFIER}/jbpf_basic_verifier_test.cpp) 11 | set(JBPF_VERIFIER_EXTENSION_TEST jbpf_verifier_extension_test) 12 | set(JBPF_VERIFIER_EXTENSION_TEST_SOURCES ${TESTS_VERIFIER}/jbpf_verifier_extension_test.cpp) 13 | 14 | add_executable(${JBPF_BASIC_VERIFIER_TEST} ${JBPF_BASIC_VERIFIER_TEST_SOURCES}) 15 | target_link_libraries(${JBPF_BASIC_VERIFIER_TEST} PUBLIC jbpf::verifier_lib) 16 | target_include_directories(${JBPF_BASIC_VERIFIER_TEST} PUBLIC ${JBPF_VERIFIER_HEADERS} ${TEST_HEADER_FILES}) 17 | add_test(NAME ${JBPF_BASIC_VERIFIER_TEST} COMMAND ${JBPF_BASIC_VERIFIER_TEST}) 18 | list(APPEND JBPF_TESTS ${JBPF_BASIC_VERIFIER_TEST}) 19 | add_clang_format_check(${JBPF_BASIC_VERIFIER_TEST} ${JBPF_BASIC_VERIFIER_TEST_SOURCES}) 20 | add_cppcheck(${JBPF_BASIC_VERIFIER_TEST} ${JBPF_BASIC_VERIFIER_TEST_SOURCES}) 21 | 22 | add_executable(${JBPF_VERIFIER_EXTENSION_TEST} ${JBPF_VERIFIER_EXTENSION_TEST_SOURCES}) 23 | target_link_libraries(${JBPF_VERIFIER_EXTENSION_TEST} PUBLIC jbpf::verifier_lib) 24 | target_include_directories(${JBPF_VERIFIER_EXTENSION_TEST} PUBLIC ${JBPF_VERIFIER_HEADERS} ${TEST_HEADER_FILES}) 25 | add_test(NAME ${JBPF_VERIFIER_EXTENSION_TEST} COMMAND ${JBPF_VERIFIER_EXTENSION_TEST}) 26 | list(APPEND JBPF_TESTS ${JBPF_VERIFIER_EXTENSION_TEST}) 27 | add_clang_format_check(${JBPF_VERIFIER_EXTENSION_TEST} ${JBPF_VERIFIER_EXTENSION_TEST_SOURCES}) 28 | add_cppcheck(${JBPF_VERIFIER_EXTENSION_TEST} ${JBPF_VERIFIER_EXTENSION_TEST_SOURCES}) 29 | 30 | set(JBPF_TESTS ${JBPF_TESTS} PARENT_SCOPE) 31 | -------------------------------------------------------------------------------- /patches/ck.patch: -------------------------------------------------------------------------------- 1 | diff --git a/include/ck_stack.h b/include/ck_stack.h 2 | index eb2b685..9dc7195 100644 3 | --- a/include/ck_stack.h 4 | +++ b/include/ck_stack.h 5 | @@ -152,7 +152,7 @@ ck_stack_batch_pop_upmc(struct ck_stack *target) 6 | { 7 | struct ck_stack_entry *entry; 8 | 9 | - entry = ck_pr_fas_ptr(&target->head, NULL); 10 | + entry = (struct ck_stack_entry *)ck_pr_fas_ptr(&target->head, NULL); 11 | ck_pr_fence_load(); 12 | return entry; 13 | } 14 | @@ -276,7 +276,7 @@ ck_stack_push_mpnc(struct ck_stack *target, struct ck_stack_entry *entry) 15 | 16 | entry->next = NULL; 17 | ck_pr_fence_store_atomic(); 18 | - stack = ck_pr_fas_ptr(&target->head, entry); 19 | + stack = (struct ck_stack_entry *)ck_pr_fas_ptr(&target->head, entry); 20 | ck_pr_store_ptr(&entry->next, stack); 21 | ck_pr_fence_store(); 22 | 23 | -------------------------------------------------------------------------------- /patches/ebpf_verifier.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/crab/ebpf_domain.cpp b/src/crab/ebpf_domain.cpp 2 | index 3f173cc..7c96b6d 100644 3 | --- a/src/crab/ebpf_domain.cpp 4 | +++ b/src/crab/ebpf_domain.cpp 5 | @@ -61,7 +61,7 @@ static linear_constraint_t neq(variable_t a, variable_t b) { 6 | return {a - b, constraint_kind_t::NOT_ZERO}; 7 | } 8 | 9 | -constexpr int MAX_PACKET_SIZE = 0xffff; 10 | +constexpr int MAX_PACKET_SIZE = 0xffffff; 11 | constexpr int64_t MY_INT_MAX = INT_MAX; 12 | constexpr int64_t PTR_MAX = MY_INT_MAX - MAX_PACKET_SIZE; 13 | 14 | -------------------------------------------------------------------------------- /patches/mimalloc.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/heap.c b/src/heap.c 2 | index f6f23549..43fe62a0 100644 3 | --- a/src/heap.c 4 | +++ b/src/heap.c 5 | @@ -59,7 +59,10 @@ static bool mi_heap_page_is_valid(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_ 6 | MI_UNUSED(pq); 7 | mi_assert_internal(mi_page_heap(page) == heap); 8 | mi_segment_t* segment = _mi_page_segment(page); 9 | +#pragma GCC diagnostic push 10 | +#pragma GCC diagnostic ignored "-Wstringop-overflow" 11 | mi_assert_internal(segment->thread_id == heap->thread_id); 12 | +#pragma GCC diagnostic pop 13 | mi_assert_expensive(_mi_page_is_valid(page)); 14 | return true; 15 | } 16 | -------------------------------------------------------------------------------- /pipeline/build-lib.yaml: -------------------------------------------------------------------------------- 1 | parameters: 2 | - name: dockerType 3 | type: string 4 | default: "" 5 | 6 | steps: 7 | - template: submodules.yaml 8 | 9 | - template: images/build.v2.yaml@templates 10 | parameters: 11 | arguments: "" 12 | dockerfile: deploy/${{ parameters.dockerType }}.Dockerfile 13 | registry: $(containerRegistry) 14 | repository: jbpf-lib-${{ parameters.dockerType }} 15 | tags: | 16 | $(imageTag) 17 | 18 | -------------------------------------------------------------------------------- /pipeline/doxygen.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - template: agentpool/cleanup.yaml@templates 3 | - template: print-debug-info.yaml 4 | - template: build-lib.yaml 5 | parameters: 6 | dockerType: ubuntu22.04 7 | - bash: | 8 | set -x 9 | if ! docker run -v `pwd`:/jbpf_out_lib -e DOXYGEN=1 $(containerRegistry)/jbpf-lib-ubuntu22.04:$(imageTag); then 10 | echo ERROR make doc 11 | exit 1 12 | fi 13 | cp -R out/docs/html $(Build.ArtifactStagingDirectory)/doxygen 14 | displayName: make doc 15 | continueOnError: false 16 | - task: PublishBuildArtifacts@1 17 | condition: always() 18 | inputs: 19 | ArtifactName: artifacts 20 | - template: agentpool/cleanup.yaml@templates 21 | -------------------------------------------------------------------------------- /pipeline/house-keeping.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - template: environment/cloc.yaml@templates 3 | parameters: 4 | args: "--exclude-dir=3p,api,build,cmake_modules,out" 5 | 6 | - bash: | 7 | ## This checks the C/CPP source code to see if there are any code smells like #define A X*Y which should be fixed to #define A (X*Y) 8 | ## The constant was defined as: 9 | ## #define JBPF_MAX_UE_SUPPORTED 16*5 10 | ## it should be 11 | ## #define JBPF_MAX_UE_SUPPORTED (16*5) 12 | ## Otherwise, expressions like i % JBPF_MAX_UE_SUPPORTED are producing unexpected outputs and tricky bugs. 13 | 14 | echo "Checking C source code for code smells like #define X*Y" 15 | c_code_smells=$(find ./src -name "*.c" -type f -exec awk '/#define [A-Za-z0-9_]+ [0-9]+[*/+-][0-9]+([*/+-][0-9]+)*$/' {} \; | wc -l) 16 | if [ "$c_code_smells" -gt 0 ]; then 17 | echo "Please fix the following C Code Smells:" 18 | find ./src -name "*.c" -type f -exec awk '/#define [A-Za-z0-9_]+ [0-9]+[*/+-][0-9]+([*/+-][0-9]+)*$/' {} \; 19 | exit 1 20 | else 21 | echo "No C Code Smells found." 22 | fi 23 | displayName: Check for C Code Smells 24 | -------------------------------------------------------------------------------- /pipeline/kill-port-process.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -eq 0 ]] ; then 4 | echo 'Usage: ./kill-port-process.sh ...' 5 | exit 0 6 | fi 7 | 8 | SUDO_CMD="" 9 | if [[ $EUID -ne 0 && `which sudo` ]]; then 10 | SUDO_CMD="sudo" 11 | fi 12 | 13 | cnt=0 14 | for port in $@; do 15 | while :; do 16 | processid=$($SUDO_CMD lsof -i :$port | tail -1 | awk '{print $2}') 17 | if [[ ! -z "$processid" ]]; then 18 | echo "Killing process $processid" 19 | $SUDO_CMD kill -9 $processid 20 | cnt=$((cnt+1)) 21 | else 22 | break 23 | fi 24 | done 25 | done 26 | 27 | exit $cnt 28 | -------------------------------------------------------------------------------- /pipeline/print-debug-info.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - bash: | 3 | echo "****************CPU Arch**********" 4 | lscpu 5 | 6 | echo "****************CPU***************" 7 | cat /proc/cpuinfo 8 | 9 | echo "****************MEM***************" 10 | cat /proc/meminfo 11 | 12 | echo "****************DISK**************" 13 | df -h 14 | 15 | echo "****************FREE**************" 16 | free -m 17 | 18 | echo "****************HOST**************" 19 | echo "Agent.MachineName: $(Agent.MachineName)" 20 | echo "Agent.Name: $(Agent.Name)" 21 | echo "System.HostType: $(System.HostType)" 22 | 23 | if [ "$requiredCpuModel" == "" ];then 24 | exit 0 25 | fi 26 | 27 | echo "****************CPU Model*********" 28 | lscpu 29 | displayName: "Show Pipeline VM Information" 30 | -------------------------------------------------------------------------------- /pipeline/setup-on-vm.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - bash: | 3 | set -x 4 | sudo usermod -aG docker ${USER} 5 | displayName: "Setup on VM" 6 | continueOnError: false 7 | -------------------------------------------------------------------------------- /pipeline/submodules.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - checkout: self 3 | submodules: recursive 4 | -------------------------------------------------------------------------------- /setup_jbpf_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export JBPF_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" 4 | export JBPF_TESTS=$JBPF_PATH/jbpf_tests 5 | export JBPF_OUT_DIR=$JBPF_PATH/out 6 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JBPF_PATH/out/lib 7 | -------------------------------------------------------------------------------- /src/common/.gitignore: -------------------------------------------------------------------------------- 1 | jbpf_version.h 2 | -------------------------------------------------------------------------------- /src/common/jbpf_common.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #ifndef JBPF_COMMON_H_ 3 | #define JBPF_COMMON_H_ 4 | 5 | // #define JBPF_DEFAULT_RUN_PATH "/tmp/jbpf" 6 | 7 | /** 8 | * @brief Default path for the jbpf run directory. 9 | * @ingroup core 10 | */ 11 | #define JBPF_DEFAULT_RUN_PATH "/tmp" 12 | 13 | /** 14 | * @brief Length of the jbpf hook name. 15 | * @ingroup core 16 | */ 17 | #define JBPF_RUN_PATH_LEN (64U) 18 | 19 | #define JBPF_DEFAULT_NAMESPACE "jbpf" 20 | 21 | #define JBPF_NAMESPACE_LEN (32U) 22 | 23 | #define JBPF_PATH_NAMESPACE_LEN (128U) 24 | 25 | #endif -------------------------------------------------------------------------------- /src/common/jbpf_common_types.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #ifndef JBPF_COMMON_TYPES_H 3 | #define JBPF_COMMON_TYPES_H 4 | 5 | /** 6 | * @brief Length of the jbpf hook name. 7 | * @details This is the maximum length of the hook name. 8 | * @ingroup core 9 | */ 10 | #define JBPF_HOOK_NAME_LEN (256U) 11 | 12 | /** 13 | * @brief Type representing the name of a jbpf hook. 14 | * @ingroup core 15 | */ 16 | typedef char jbpf_hook_name_t[JBPF_HOOK_NAME_LEN]; 17 | 18 | /** 19 | * @brief Default priority for a jbpf codelet. 20 | * @details This is the default priority for a jbpf codelet. 21 | * @ingroup core 22 | */ 23 | #define JBPF_CODELET_PRIORITY_DEFAULT (1U) 24 | 25 | /** 26 | * @brief Priority of the codelet. 27 | * @details The priority is used to determine the order in which the codelets are executed. 28 | * @note The lowest priority is 0, the highest priority is UINT_MAX. 29 | * The default priority is defined by `JBPF_CODELET_PRIORITY_DEFAULT`. 30 | * @ingroup core 31 | */ 32 | typedef uint32_t jbpf_codelet_priority_t; 33 | 34 | /** 35 | * @brief Runtime threshold type for jbpf. 36 | * @details This represents the time threshold in microseconds. 37 | * @note Value of 0 means no threshold checking is performed. 38 | * @ingroup core 39 | */ 40 | typedef uint64_t jbpf_runtime_threshold_t; 41 | 42 | /** 43 | * @brief Length of the jbpf IO channel name. 44 | * @details This is the maximum length of the IO channel name. 45 | * @ingroup core 46 | */ 47 | #define JBPF_IO_CHANNEL_NAME_LEN (256U) 48 | 49 | /** 50 | * @brief Type representing the name of a jbpf IO channel. 51 | * @ingroup core 52 | */ 53 | typedef char jbpf_io_channel_name_t[JBPF_IO_CHANNEL_NAME_LEN]; 54 | 55 | #endif /* JBPF_COMMON_TYPES_H */ 56 | -------------------------------------------------------------------------------- /src/common/jbpf_helper_api_defs_ext.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_HELPER_API_DEFS_EXT_H 2 | #define JBPF_HELPER_API_DEFS_EXT_H 3 | 4 | // Maximum supported number of helper functions 5 | #define MAX_HELPER_FUNC (64) 6 | 7 | // start ID for custom helper functions 8 | #define CUSTOM_HELPER_START_ID (32) 9 | 10 | // start ID for custom programs 11 | #define CUSTOM_MAP_START_ID (16) 12 | 13 | // start ID for custom programs 14 | #define CUSTOM_PROGRAM_START_ID (8) 15 | 16 | #endif -------------------------------------------------------------------------------- /src/common/jbpf_hook_defs_ext.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #ifndef JBPF_HOOK_DEFS_EXT_H 3 | #define JBPF_HOOK_DEFS_EXT_H 4 | 5 | /** 6 | * @brief Default Control Operation: by default control jbpf programs are expected to return this value. 7 | * @ingroup core 8 | */ 9 | #define JBPF_DEFAULT_CTRL_OP 0ULL 10 | 11 | #endif -------------------------------------------------------------------------------- /src/common/jbpf_version.h.in: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_VERSION_H 2 | #define JBPF_VERSION_H 3 | 4 | #define JBPF_VERSION_MAJOR "${JBPF_VERSION_MAJOR}" 5 | #define JBPF_VERSION_MINOR "${JBPF_VERSION_MINOR}" 6 | #define JBPF_VERSION_PATCH "${JBPF_VERSION_PATCH}" 7 | 8 | #define C_API_VERSION "${C_API_VERSION}" 9 | 10 | #define JBPF_COMMIT_HASH "${JBPF_COMMIT_HASH}" 11 | #define JBPF_COMMIT_BRANCH "${JBPF_COMMIT_BRANCH}" 12 | 13 | // build parameters 14 | #define USE_NATIVE "${USE_NATIVE}" 15 | #define USE_JBPF_PERF_OPT "${USE_JBPF_PERF_OPT}" 16 | #define USE_JBPF_PRINTF_HELPER "${USE_JBPF_PRINTF_HELPER}" 17 | #define JBPF_STATIC "${JBPF_STATIC}" 18 | #define JBPF_THREADS_LARGE "${JBPF_THREADS_LARGE}" 19 | 20 | #endif /* JBPF_VERSION_H */ 21 | -------------------------------------------------------------------------------- /src/core/jbpf_agent_hooks.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #ifndef JBPF_AGENT_HOOKS_ 3 | #define JBPF_AGENT_HOOKS_ 4 | 5 | #include "jbpf_utils.h" 6 | #include "jbpf_hook.h" 7 | #include "jbpf_defs.h" 8 | 9 | /** 10 | * @brief Declare a jbpf hook: report_stats 11 | * @note This is called internally by the jbpf library to collect stats about the loaded codelets and their runtime. 12 | * @ingroup hooks 13 | * @ingroup core 14 | */ 15 | DECLARE_JBPF_HOOK( 16 | report_stats, 17 | struct jbpf_stats_ctx ctx, 18 | ctx, 19 | HOOK_PROTO(struct jbpf_perf_hook_list* hook_perfs, uint32_t meas_period), 20 | HOOK_ASSIGN(ctx.meas_period = meas_period; ctx.data = (uint64_t)(void*)hook_perfs; 21 | ctx.data_end = (uint64_t)((uint8_t*)hook_perfs + sizeof(struct jbpf_perf_hook_list));)) 22 | 23 | /** 24 | * @brief Declare a jbpf hook: periodic_call 25 | * @note This hook will be called periodically with the specified period. 26 | * @note We could use this hook to load codelets that need to perform periodic tasks, while being outside of any fast 27 | * path (e.g., aggregate data stored in shared maps and clear the maps). 28 | * @ingroup hooks 29 | * @ingroup core 30 | */ 31 | DECLARE_JBPF_HOOK( 32 | periodic_call, 33 | struct jbpf_stats_ctx ctx, 34 | ctx, 35 | HOOK_PROTO(uint32_t meas_period), 36 | HOOK_ASSIGN(ctx.meas_period = meas_period; ctx.data = (uint64_t)(void*)NULL; ctx.data_end = (uint64_t)(void*)NULL;)) 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/core/jbpf_bitmap.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_BITMAP_H_ 2 | #define JBPF_BITMAP_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "jbpf_memory.h" 10 | 11 | #define BITMAP_BITS_PER_WORD (sizeof(unsigned int) * 8) 12 | 13 | struct jbpf_bitmap 14 | { 15 | unsigned int* data; 16 | int num_blocks; 17 | size_t size; 18 | }; 19 | 20 | static inline void 21 | jbpf_init_bitmap(struct jbpf_bitmap* bitmap, size_t size) 22 | { 23 | size_t num_elems = (size + BITMAP_BITS_PER_WORD - 1) / BITMAP_BITS_PER_WORD; 24 | bitmap->data = (unsigned int*)jbpf_calloc_mem(num_elems, sizeof(unsigned int)); 25 | bitmap->size = size; 26 | bitmap->num_blocks = num_elems; 27 | } 28 | 29 | static inline int 30 | jbpf_allocate_bit(struct jbpf_bitmap* bitmap) 31 | { 32 | for (size_t i = 0; i < bitmap->size; i++) { 33 | unsigned int* word = &bitmap->data[i / BITMAP_BITS_PER_WORD]; 34 | unsigned int old_value = *word; 35 | unsigned int bit_mask = (1u << (i % BITMAP_BITS_PER_WORD)); 36 | if ((old_value & bit_mask) == 0) { 37 | unsigned int new_value = old_value | bit_mask; 38 | if (__sync_bool_compare_and_swap(word, old_value, new_value)) { 39 | return i; 40 | } 41 | } 42 | } 43 | return -1; // No free bits available 44 | } 45 | 46 | static inline void 47 | jbpf_free_bit(struct jbpf_bitmap* bitmap, int bit_index) 48 | { 49 | size_t index = bit_index / BITMAP_BITS_PER_WORD; 50 | if (index >= bitmap->num_blocks) 51 | return; 52 | unsigned int* word = &bitmap->data[index]; 53 | unsigned int bit_mask = (1u << (bit_index % BITMAP_BITS_PER_WORD)); 54 | __sync_fetch_and_and(word, ~bit_mask); 55 | } 56 | 57 | static inline void 58 | jbpf_destroy_bitmap(struct jbpf_bitmap* bitmap) 59 | { 60 | jbpf_free_mem(bitmap->data); 61 | } 62 | 63 | #endif /* JBPF_BITMAP_H_ */ 64 | -------------------------------------------------------------------------------- /src/core/jbpf_bpf_array.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #include 3 | #include 4 | 5 | #include "jbpf_bpf_array.h" 6 | #include "jbpf_memory.h" 7 | 8 | void* 9 | jbpf_bpf_array_create(const struct jbpf_load_map_def* map_def) 10 | { 11 | return jbpf_calloc_mem(map_def->max_entries, map_def->value_size); 12 | } 13 | 14 | void 15 | jbpf_bpf_array_destroy(struct jbpf_map* map) 16 | { 17 | jbpf_free_mem(map->data); 18 | } 19 | -------------------------------------------------------------------------------- /src/core/jbpf_bpf_hashmap_int.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef JBPF_BPF_HASHMAP_INT_H 4 | #define JBPF_BPF_HASHMAP_INT_H 5 | 6 | #include "ck_ht.h" 7 | #include "ck_epoch.h" 8 | #include "ck_spinlock.h" 9 | 10 | #include "jbpf_memory.h" 11 | 12 | struct jbpf_bpf_hashmap 13 | { 14 | unsigned int key_size; 15 | unsigned int value_size; 16 | unsigned int max_entries; 17 | ck_ht_t ht; 18 | jbpf_mempool_ctx_t* mempool; 19 | ck_spinlock_t lock; 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/core/jbpf_bpf_spsc_hashmap.c: -------------------------------------------------------------------------------- 1 | #include "jbpf_bpf_spsc_hashmap.h" 2 | #include "jbpf_utils.h" 3 | 4 | void* 5 | jbpf_bpf_spsc_hashmap_create(const struct jbpf_load_map_def* map_def) 6 | { 7 | 8 | struct jbpf_bpf_spsc_hashmap* hmap; 9 | 10 | if (!map_def) 11 | return NULL; 12 | 13 | hmap = jbpf_calloc_mem(1, sizeof(struct jbpf_bpf_spsc_hashmap)); 14 | 15 | if (!hmap) 16 | return NULL; 17 | 18 | hmap->key_size = map_def->key_size; 19 | hmap->value_size = map_def->value_size; 20 | hmap->max_entries = map_def->max_entries; 21 | hmap->count = 0; 22 | 23 | // Make hashtable to be power of 2 for faster lookups 24 | hmap->ht_size = round_up_pow_of_two(hmap->max_entries); 25 | 26 | // Each entry of the table has the following structure | used | key | value | 27 | // The "used" value designates whether an entry is empty (0) or used (1) 28 | hmap->ht = jbpf_calloc_mem(hmap->ht_size, hmap->key_size + hmap->value_size + 1); 29 | 30 | if (!hmap->ht) { 31 | jbpf_free_mem(hmap); 32 | return NULL; 33 | } 34 | 35 | return hmap; 36 | } 37 | 38 | void 39 | jbpf_bpf_spsc_hashmap_destroy(struct jbpf_map* map) 40 | { 41 | 42 | jbpf_spsc_hashmap_t* hmap; 43 | 44 | if (!map) 45 | return; 46 | 47 | hmap = (jbpf_spsc_hashmap_t*)map->data; 48 | 49 | jbpf_free_mem(hmap->ht); 50 | jbpf_free_mem(hmap); 51 | } 52 | -------------------------------------------------------------------------------- /src/core/jbpf_bpf_spsc_hashmap_int.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_BPF_SPSC_HASHMAP_INT_H 2 | #define JBPF_BPF_SPSC_HASHMAP_INT_H 3 | 4 | struct jbpf_bpf_spsc_hashmap 5 | { 6 | unsigned int key_size; 7 | unsigned int value_size; 8 | unsigned int max_entries; 9 | unsigned int ht_size; 10 | void* ht; 11 | int count; 12 | }; 13 | 14 | #endif -------------------------------------------------------------------------------- /src/core/jbpf_helper_api_defs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #ifndef JBPF_HELPER_API_DEFS_ 3 | #define JBPF_HELPER_API_DEFS_ 4 | 5 | #include 6 | 7 | #include "jbpf_helper_api_defs_ext.h" 8 | 9 | /** 10 | * @brief Success return value for map operations 11 | * @ingroup core 12 | */ 13 | #define JBPF_MAP_SUCCESS (0) 14 | 15 | /** 16 | * @brief Error return value for map operations 17 | * @ingroup core 18 | */ 19 | #define JBPF_MAP_ERROR (-1) 20 | 21 | /** 22 | * @brief Busy return value for map operations 23 | * @ingroup core 24 | */ 25 | #define JBPF_MAP_BUSY (-2) 26 | 27 | /** 28 | * @brief Return value for map operations when map is full 29 | * @ingroup core 30 | */ 31 | #define JBPF_MAP_FULL (-4) 32 | 33 | /** 34 | * @brief Maximum retry attempts for map operations 35 | * @ingroup core 36 | */ 37 | #define JBPF_MAP_RETRY_ATTEMPTS (100) 38 | 39 | #endif /* JBPF_HELPER_API_DEFS_ */ 40 | -------------------------------------------------------------------------------- /src/core/jbpf_helper_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_HELPER_IMPL_H 2 | #define JBPF_HELPER_IMPL_H 3 | 4 | #include "ubpf.h" 5 | 6 | void 7 | jbpf_register_helper_functions(struct ubpf_vm* vm); 8 | 9 | // wrapper functions for testing 10 | int 11 | __jbpf_rand(void); 12 | void 13 | __set_seed(unsigned int x); 14 | uint64_t 15 | __jbpf_get_sys_time_diff_ns(uint64_t start_time, uint64_t end_time); 16 | uint32_t 17 | __jbpf_hash(void* item, uint64_t size); 18 | void 19 | __jbpf_set_e_runtime_threshold(uint64_t threshold); 20 | void 21 | __jbpf_mark_runtime_init(void); 22 | int 23 | __jbpf_runtime_limit_exceeded(void); 24 | 25 | #endif -------------------------------------------------------------------------------- /src/core/jbpf_hook_defs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef JBPF_HOOK_DEFS_H 4 | #define JBPF_HOOK_DEFS_H 5 | 6 | #include 7 | 8 | #include "ubpf.h" 9 | 10 | #include "jbpf_hook_defs_ext.h" 11 | #include "jbpf_common_types.h" 12 | 13 | #include "ck_epoch.h" 14 | 15 | #define DEFAULT_RUNTIME_THRESHOLD 1000000 16 | 17 | #ifndef HOOKS_SECTION_ALIGNMENT 18 | #if defined(__LP64__) 19 | #define HOOKS_SECTION_ALIGNMENT 8 20 | #else 21 | #define HOOKS_SECTION_ALIGNMENT 4 22 | #endif 23 | #endif 24 | 25 | typedef ubpf_jit_fn jbpf_jit_fn; 26 | 27 | enum jbpf_hook_type 28 | { 29 | JBPF_HOOK_TYPE_MON = 0, 30 | JBPF_HOOK_TYPE_CTRL 31 | }; 32 | 33 | struct jbpf_hook_codelet 34 | { 35 | jbpf_jit_fn jbpf_codelet; 36 | jbpf_codelet_priority_t prio; 37 | jbpf_runtime_threshold_t time_thresh; 38 | ck_epoch_entry_t epoch_entry; 39 | }; 40 | 41 | struct jbpf_hook 42 | { 43 | const char* name; 44 | struct jbpf_hook_codelet* codelets; 45 | 46 | enum jbpf_hook_type hook_type; 47 | bool jbpf_perf_active; 48 | struct jbpf_perf_data* perf_data; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/core/jbpf_lookup3.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #ifndef LOOKUP3_H 3 | #define LOOKUP3_H 4 | 5 | #include /* defines printf for tests */ 6 | #include /* defines time_t for timings in the test */ 7 | #include /* defines uint32_t etc */ 8 | #include /* attempt to define endianness */ 9 | #ifdef linux 10 | #include /* attempt to define endianness */ 11 | #endif 12 | 13 | uint32_t 14 | hashword(const uint32_t* k, size_t length, uint32_t initval); 15 | void 16 | hashword2(const uint32_t* k, size_t length, uint32_t* pc, uint32_t* pb); 17 | uint32_t 18 | hashlittle(const void* key, size_t length, uint32_t initval); 19 | uint32_t 20 | hashbig(const void* key, size_t length, uint32_t initval); 21 | void 22 | hashlittle2(const void* key, size_t length, uint32_t* pc, uint32_t* pb); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/core/jbpf_memory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef JBPF_MEMORY_H 4 | #define JBPF_MEMORY_H 5 | 6 | #include 7 | 8 | #include "jbpf_utils.h" 9 | #include "jbpf_config.h" 10 | 11 | /* Number of BPF programs that are allowed to be loaded. 12 | * Currently only 254 are allowed */ 13 | enum jbpf_prog 14 | { 15 | /* Max number of programs supported */ 16 | JBPF_PROG_MAX = 0xfe, 17 | JBPF_PROG_TOTAL = 0xff 18 | }; 19 | 20 | #define MEMPOOL_NAME_LEN 32U 21 | #define MEMPOOL_CACHE_SIZE 32 22 | 23 | typedef struct 24 | { 25 | void* (*jbpf_malloc_mem_cb)(size_t size); 26 | void* (*jbpf_calloc_mem_cb)(size_t num, size_t size); 27 | void* (*jbpf_realloc_mem_cb)(void* ptr, size_t size); 28 | void (*jbpf_free_mem_cb)(void* ptr); 29 | } jbpf_alloc_cbs; 30 | 31 | typedef struct jbpf_mempool_ctx jbpf_mempool_ctx_t; 32 | 33 | jbpf_mempool_ctx_t* 34 | jbpf_init_data_mempool(uint32_t num_elems, size_t elem_size); 35 | 36 | void 37 | jbpf_destroy_data_mempool(jbpf_mempool_ctx_t* mempool); 38 | 39 | int 40 | jbpf_get_data_mempool_size(jbpf_mempool_ctx_t* mempool_ctx); 41 | 42 | /* Malloc type of memory allocation */ 43 | void* 44 | jbpf_alloc_mem(size_t size); 45 | 46 | /* Calloc type of memory allocation */ 47 | void* 48 | jbpf_calloc_mem(size_t num, size_t size); 49 | 50 | /* Realloc type of memory allocation */ 51 | void* 52 | jbpf_realloc_mem(void* ptr, size_t size); 53 | 54 | /* Malloc type of memory allocation for fast path */ 55 | void* 56 | jbpf_alloc_data_mem(jbpf_mempool_ctx_t* mempool_ctx); 57 | 58 | /* Free for slow path */ 59 | void 60 | jbpf_free_mem(void* ptr); 61 | 62 | /* Free for fast path */ 63 | void 64 | jbpf_free_data_mem(void* ptr); 65 | 66 | int 67 | jbpf_memory_setup(struct jbpf_agent_mem_config* mem_config); 68 | 69 | void 70 | jbpf_memory_teardown(void); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/core/jbpf_perf_ext.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef JBPF_PERF_EXT_H 4 | #define JBPF_PERF_EXT_H 5 | 6 | #include "jbpf_common_types.h" 7 | 8 | /* Change these values to adjust the histogram */ 9 | /** 10 | * @brief Number of histogram bins 11 | */ 12 | #define JBPF_NUM_HIST_BINS 64 13 | 14 | /** 15 | * @brief Number of nanoseconds per bin 16 | */ 17 | #define JBPF_NSECS_PER_BIN 100 18 | 19 | /** 20 | * @brief Maximum number of hooks 21 | */ 22 | #define MAX_NUM_HOOKS 128 23 | 24 | /** 25 | * @brief JBPF performance data structure 26 | * @param num Number of times the hook was called 27 | * @param min Minimum time taken by the hook 28 | * @param max Maximum time taken by the hook 29 | * @param hist Histogram of time taken by the hook 30 | * @param hook_name Name of the hook 31 | * @ingroup hooks 32 | * @ingroup core 33 | */ 34 | struct jbpf_perf_data 35 | { 36 | uint64_t num; 37 | uint64_t min; 38 | uint64_t max; 39 | uint32_t hist[JBPF_NUM_HIST_BINS]; 40 | jbpf_hook_name_t hook_name; 41 | }; 42 | 43 | /** 44 | * @brief JBPF performance hook list structure 45 | * @note This is the struct that is passed to the perf hook. See [here](../dosc/add_new_hook.md) for more information. 46 | * @param num_reported_hooks Number of hooks reported 47 | * @param perf_data Performance data for the hooks 48 | * @ingroup hooks 49 | * @ingroup core 50 | */ 51 | struct jbpf_perf_hook_list 52 | { 53 | uint8_t num_reported_hooks; 54 | struct jbpf_perf_data perf_data[MAX_NUM_HOOKS]; 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/core/jbpf_types.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef JBPF_TYPES_H_ 4 | #define JBPF_TYPES_H_ 5 | 6 | #ifdef __CHECKER__ 7 | #define JBPF_BITWISE __attribute__((bitwise)) 8 | #define JBPF_FORCE __attribute__((force)) 9 | #else 10 | #define JBPF_BITWISE 11 | #define JBPF_FORCE 12 | #endif 13 | 14 | /* The jbe types indicate that an object is in big-endian, not 15 | * native-endian, byte order. They are otherwise equivalent to uint_t. */ 16 | typedef uint16_t JBPF_BITWISE jbe16; 17 | typedef uint32_t JBPF_BITWISE jbe32; 18 | typedef uint64_t JBPF_BITWISE jbe64; 19 | 20 | typedef union 21 | { 22 | uint32_t u32[4]; 23 | struct 24 | { 25 | #ifdef WORDS_BIGENDIAN 26 | uint64_t hi, lo; 27 | #else 28 | uint64_t lo, hi; 29 | #endif 30 | } u64; 31 | } j_u128; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/io/jbpf_io_channel_int.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_IO_CHANNEL_INT_H 2 | #define JBPF_IO_CHANNEL_INT_H 3 | 4 | #include "jbpf_mem_mgmt.h" 5 | 6 | int 7 | jbpf_io_channel_list_init(struct jbpf_io_ctx* io_ctx); 8 | 9 | int 10 | jbpf_io_channel_list_destroy(struct jbpf_io_ctx* io_ctx); 11 | 12 | bool 13 | _jbpf_io_load_serde(struct jbpf_io_serde* serde, struct jbpf_io_stream_id* stream_id, char* lib_bin, size_t lib_len); 14 | 15 | struct jbpf_io_channel* 16 | _jbpf_io_create_channel( 17 | struct jbpf_io_channel_list* channel_list, struct jbpf_io_channel_request* chan_req, jbpf_mem_ctx_t* mem_ctx); 18 | 19 | void 20 | jbpf_io_destroy_out_channel(struct jbpf_io_channel_list* channel_list, struct jbpf_io_channel* io_channel); 21 | 22 | void 23 | jbpf_io_destroy_in_channel(struct jbpf_io_channel_list* channel_list, struct jbpf_io_channel* io_channel); 24 | 25 | void 26 | jbpf_io_wait_on_channel_update(struct jbpf_io_channel_list* channel_list); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/io/jbpf_io_ipc_int.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_IO_IPC_INT_H 2 | #define JBPF_IO_IPC_INT_H 3 | 4 | // Parser for the IPC address 5 | // The address should be in the format ://
, where protocol is one of "vsock" or "unix" (case 6 | // insensitive). If is unix, then
is a string with the name of the socket. If is vsock, 7 | // then
has the format cid:port. If CID is a name or 0, then VMADDR_CID_ANY is used instead, while if the port 8 | // is omitted, JBPF_IO_IPC_VSOCK_DEFAULT_PORT is used instead return 0 on success or -1 if failed. 9 | int 10 | _jbpf_io_ipc_parse_addr(const char* jbpf_run_path, const char* addr, struct jbpf_io_ipc_proto_addr* dipc_primary_addr); 11 | 12 | #endif -------------------------------------------------------------------------------- /src/io/jbpf_io_local.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #include 3 | 4 | #include "jbpf_io_local.h" 5 | #include "jbpf_mem_mgmt.h" 6 | #include "jbpf_io_int.h" 7 | #include "jbpf_io_queue.h" 8 | #include "jbpf_io_channel.h" 9 | #include "jbpf_logging.h" 10 | 11 | int 12 | jbpf_io_local_init(struct jbpf_io_local_cfg* local_cfg, struct jbpf_io_ctx* io_ctx) 13 | { 14 | 15 | int res = 0; 16 | 17 | if (!local_cfg || !io_ctx) 18 | return -1; 19 | 20 | jbpf_logger(JBPF_INFO, "Allocating memory for IO\n"); 21 | // For now we use mi-malloc for the allocation in this case. Might revisit in the future 22 | res = jbpf_init_memory(local_cfg->mem_cfg.memory_size, true); 23 | io_ctx->primary_ctx.local_ctx.mem_ctx = NULL; 24 | 25 | return res; 26 | } 27 | 28 | void 29 | jbpf_io_local_destroy(struct jbpf_io_ctx* io_ctx) 30 | { 31 | 32 | if (!io_ctx) 33 | return; 34 | 35 | jbpf_logger(JBPF_INFO, "Destroying local IO interface\n"); 36 | jbpf_destroy_memory(); 37 | } 38 | -------------------------------------------------------------------------------- /src/io/jbpf_io_local.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_IO_LOCAL_H 2 | #define JBPF_IO_LOCAL_H 3 | 4 | #include "jbpf_io_defs.h" 5 | 6 | int 7 | jbpf_io_local_init(struct jbpf_io_local_cfg* local_cfg, struct jbpf_io_ctx* io_ctx); 8 | 9 | void 10 | jbpf_io_local_destroy(struct jbpf_io_ctx* io_ctx); 11 | 12 | #endif -------------------------------------------------------------------------------- /src/io/jbpf_io_queue.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_IO_QUEUE_H 2 | #define JBPF_IO_QUEUE_H 3 | 4 | #include 5 | 6 | typedef struct jbpf_io_queue_ctx jbpf_io_queue_ctx_t; 7 | 8 | void* 9 | jbpf_io_queue_create(int max_entries, int elem_size, int type, jbpf_mem_ctx_t* mem_ctx); 10 | 11 | /* This assumes that no-one is using the queue any longer. 12 | However, it is still possible to have elements in the queue*/ 13 | void 14 | jbpf_io_queue_free(jbpf_io_queue_ctx_t* ioq_ctx); 15 | 16 | void* 17 | jbpf_io_queue_reserve(jbpf_io_queue_ctx_t* ioq_ctx); 18 | 19 | void 20 | jbpf_io_queue_release_all(jbpf_io_queue_ctx_t* ioq_ctx); 21 | 22 | void 23 | jbpf_io_queue_release(void* iobuf, bool clean); 24 | 25 | int 26 | jbpf_io_queue_enqueue(jbpf_io_queue_ctx_t* ioq_ctx); 27 | 28 | void* 29 | jbpf_io_queue_dequeue(jbpf_io_queue_ctx_t* ioq_ctx); 30 | 31 | int 32 | jbpf_io_queue_get_elem_size(jbpf_io_queue_ctx_t* ioq_ctx); 33 | 34 | int 35 | jbpf_io_queue_get_num_elems(jbpf_io_queue_ctx_t* ioq_ctx); 36 | 37 | #endif -------------------------------------------------------------------------------- /src/io/jbpf_io_queue_int.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_IO_QUEUE_INT_H 2 | #define JBPF_IO_QUEUE_INT_H 3 | 4 | #include "ck_ring.h" 5 | #include "jbpf_mempool.h" 6 | #include "jbpf_io_queue.h" 7 | #include "jbpf_io_thread_mgmt.h" 8 | #include "jbpf_io_channel.h" 9 | #include "jbpf_io_utils.h" 10 | 11 | struct jbpf_io_queue_ctx 12 | { 13 | void* alloc_ptr[JBPF_IO_MAX_NUM_THREADS]; 14 | jbpf_mempool_t* mempool; 15 | ck_ring_buffer_t* ringbuffer; 16 | ck_ring_t ring CK_CC_CACHELINE; 17 | uint32_t type; 18 | uint32_t elem_size; 19 | uint32_t num_elems; 20 | uint32_t ring_size; 21 | }; 22 | 23 | #endif // JBPF_IO_QUEUE_INT_H -------------------------------------------------------------------------------- /src/io/jbpf_io_thread_mgmt.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_IO_THREAD_MGMT_H 2 | #define JBPF_IO_THREAD_MGMT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifndef JBPF_IO_MAX_NUM_THREADS 9 | #define JBPF_IO_MAX_NUM_THREADS 32 10 | #endif 11 | 12 | void 13 | jbpf_io_thread_ctx_init(void); 14 | 15 | int16_t 16 | jbpf_io_get_thread_id(void); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/io/jbpf_io_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_IO_UTILS_H 2 | #define JBPF_IO_UTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define JBPF_IO_UNUSED(x) ((void)(x)) 9 | 10 | int 11 | _jbpf_io_tohex_str(char* in, size_t insz, char* out, size_t outsz); 12 | 13 | int 14 | _jbpf_io_kernel_below_3_17(void); 15 | 16 | int 17 | _jbpf_io_open_mem_fd(const char* name); 18 | 19 | int 20 | _jbpf_io_close_mem_fd(int shm_fd, const char* name); 21 | 22 | void* 23 | _jbpf_io_load_lib(int shm_fd, const char* name); 24 | 25 | int 26 | _jbpf_io_unload_lib(void* handle); 27 | 28 | int 29 | _jbpf_io_write_lib(void* data, size_t size, int fd); 30 | 31 | #define round_up_pow_of_two(x) \ 32 | ({ \ 33 | uint32_t v = x; \ 34 | v--; \ 35 | v |= v >> 1; \ 36 | v |= v >> 2; \ 37 | v |= v >> 4; \ 38 | v |= v >> 8; \ 39 | v |= v >> 16; \ 40 | ++v; \ 41 | }) 42 | 43 | #endif 44 | 45 | ssize_t 46 | recv_all(int sock_fd, void* buf, size_t len, int flags); 47 | 48 | ssize_t 49 | send_all(int sock_fd, const void* buf, size_t len, int flags); 50 | -------------------------------------------------------------------------------- /src/lcm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | cmake_minimum_required(VERSION 3.16) 3 | 4 | project(jbpf_lcm_ipc) 5 | 6 | set(JBPF_LCM_IPC_LIB jbpf_lcm) 7 | 8 | set(JBPF_LCM_IPC_SRC_DIR ${PROJECT_SOURCE_DIR}) 9 | 10 | set(JBPF_LCM_IPC_SOURCES ${JBPF_LCM_IPC_SRC_DIR}/jbpf_lcm_ipc.c) 11 | 12 | set(JBPF_LCM_IPC_HEADER_FILES ${JBPF_LCM_IPC_SRC_DIR} PARENT_SCOPE) 13 | 14 | 15 | add_library(${JBPF_LCM_IPC_LIB} ${JBPF_LCM_IPC_SOURCES}) 16 | add_library(jbpf::lcm_ipc_lib ALIAS ${JBPF_LCM_IPC_LIB}) 17 | target_link_libraries(${JBPF_LCM_IPC_LIB} PUBLIC jbpf::logger_lib) 18 | target_include_directories(${JBPF_LCM_IPC_LIB} PUBLIC ${JBPF_LCM_IPC_HEADER_FILES} 19 | ${JBPF_IO_HEADER_FILES} 20 | ${JBPF_MEM_MGMT_HEADER_FILES} 21 | ${JBPF_COMMON_HEADERS} 22 | ${JBPF_LOGGER_HEADERS}) 23 | 24 | add_custom_command(TARGET ${JBPF_LCM_IPC_LIB} POST_BUILD 25 | COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIR}/inc/ 26 | COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LCM_IPC_SRC_DIR}/jbpf_lcm_api.h ${OUTPUT_DIR}/inc/ 27 | COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LCM_IPC_SRC_DIR}/jbpf_lcm_ipc.h ${OUTPUT_DIR}/inc/ 28 | COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_LCM_IPC_SRC_DIR}/jbpf_lcm_ipc_msg.h ${OUTPUT_DIR}/inc/ 29 | ) 30 | 31 | set_target_properties(${JBPF_LCM_IPC_LIB} 32 | PROPERTIES 33 | ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" 34 | LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" 35 | ) 36 | -------------------------------------------------------------------------------- /src/lcm/jbpf_lcm_ipc.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_LCM_IPC_H_ 2 | #define JBPF_LCM_IPC_H_ 3 | 4 | #include "jbpf_lcm_ipc_msg.h" 5 | 6 | #pragma once 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | #define JBPF_LCM_IPC_NAME_LEN (512U) 13 | #define JBPF_LCM_IPC_ADDRESS_LEN (1024U) 14 | #define JBPF_LCM_IPC_REQ_BACKLOG (40U) 15 | #define JBPF_DEFAULT_LCM_SOCKET "jbpf_lcm_ipc" 16 | 17 | typedef struct jbpf_lcm_ipc_server_ctx* jbpf_lcm_ipc_server_ctx_t; 18 | 19 | typedef int (*jbpf_codeletset_load_cb)( 20 | struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_load_error_s* err); 21 | typedef int (*jbpf_codeletset_unload_cb)( 22 | struct jbpf_codeletset_unload_req* unload_req, jbpf_codeletset_load_error_s* err); 23 | 24 | typedef struct jbpf_lcm_ipc_address 25 | { 26 | char path[JBPF_LCM_IPC_ADDRESS_LEN]; 27 | } jbpf_lcm_ipc_address_t; 28 | 29 | typedef struct jbpf_lcm_ipc_server_config 30 | { 31 | jbpf_lcm_ipc_address_t address; 32 | jbpf_codeletset_load_cb load_cb; 33 | jbpf_codeletset_unload_cb unload_cb; 34 | } jbpf_lcm_ipc_server_config_t; 35 | 36 | jbpf_lcm_ipc_server_ctx_t 37 | jbpf_lcm_ipc_server_init(jbpf_lcm_ipc_server_config_t* config); 38 | void 39 | jbpf_lcm_ipc_server_destroy(jbpf_lcm_ipc_server_ctx_t server_ctx); 40 | void 41 | jbpf_lcm_ipc_server_stop(jbpf_lcm_ipc_server_ctx_t server_ctx); 42 | 43 | int 44 | jbpf_lcm_ipc_server_start(jbpf_lcm_ipc_server_ctx_t server_ctx); 45 | 46 | int 47 | jbpf_lcm_ipc_send_codeletset_load_req(jbpf_lcm_ipc_address_t* address, jbpf_codeletset_load_req_s* load_req); 48 | int 49 | jbpf_lcm_ipc_send_codeletset_unload_req(jbpf_lcm_ipc_address_t* path, jbpf_codeletset_unload_req_s* unload_req); 50 | 51 | #pragma once 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/lcm/jbpf_lcm_ipc_msg.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #ifndef JBPF_LCM_IPC_MSG_H_ 3 | #define JBPF_LCM_IPC_MSG_H_ 4 | 5 | #include "jbpf_lcm_api.h" 6 | 7 | /** 8 | * @brief JBPF LCM IPC request message type 9 | * @ingroup lcm 10 | */ 11 | typedef enum jbpf_lcm_ipc_req_msg_type 12 | { 13 | JBPF_LCM_IPC_CODELETSET_LOAD = 0, 14 | JBPF_LCM_IPC_CODELETSET_UNLOAD, 15 | } jbpf_lcm_ipc_req_msg_type_e; 16 | 17 | /** 18 | * @brief JBPF LCM IPC request outcome 19 | * @ingroup lcm 20 | */ 21 | typedef enum jbpf_lcm_ipc_req_outcome 22 | { 23 | JBPF_LCM_IPC_REQ_SUCCESS = 0, 24 | JBPF_LCM_IPC_REQ_FAIL, 25 | } jbpf_lcm_ipc_req_outcome_e; 26 | 27 | /** 28 | * @brief JBPF LCM IPC codeletset load request message 29 | * @ingroup lcm 30 | */ 31 | typedef struct __attribute__((packed)) jbpf_lcm_ipc_codeletset_load_req_msg 32 | { 33 | jbpf_codeletset_load_req_s req; 34 | } jbpf_lcm_ipc_codeletset_load_req_msg_s; 35 | 36 | /** 37 | * @brief JBPF LCM IPC codeletset unload request message 38 | * @ingroup lcm 39 | */ 40 | typedef struct __attribute__((packed)) jbpf_lcm_ipc_codeletset_unload_req_msg 41 | { 42 | jbpf_codeletset_unload_req_s req; 43 | } jbpf_lcm_ipc_codeletset_unload_req_msg_s; 44 | 45 | /** 46 | * @brief JBPF LCM IPC request message 47 | * @ingroup lcm 48 | */ 49 | typedef struct __attribute__((packed)) jbpf_lcm_ipc_req_msg 50 | { 51 | jbpf_lcm_ipc_req_msg_type_e msg_type; 52 | union 53 | { 54 | jbpf_lcm_ipc_codeletset_load_req_msg_s load_req_msg; 55 | jbpf_lcm_ipc_codeletset_unload_req_msg_s unload_req_msg; 56 | } msg; 57 | } jbpf_lcm_ipc_req_msg_s; 58 | 59 | /** 60 | * @brief JBPF LCM IPC response message 61 | * @ingroup lcm 62 | */ 63 | typedef struct __attribute__((packed)) jbpf_lcm_ipc_resp_msg 64 | { 65 | jbpf_lcm_ipc_req_outcome_e outcome; 66 | jbpf_codeletset_load_error_s err_msg; 67 | } jbpf_lcm_ipc_resp_msg_s; 68 | 69 | #endif -------------------------------------------------------------------------------- /src/logger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | cmake_minimum_required(VERSION 3.16) 3 | 4 | project(jbpf_logger) 5 | 6 | set(JBPF_LOGGER_LIB jbpf_logger) 7 | 8 | set(JBPF_LOGGER_SRC_DIR ${PROJECT_SOURCE_DIR}) 9 | 10 | set(JBPF_LOGGER_SOURCES ${JBPF_LOGGER_SRC_DIR}/jbpf_logging.c) 11 | set(JBPF_LOGGER_HEADERS ${JBPF_LOGGER_SRC_DIR} PARENT_SCOPE) 12 | 13 | add_library(${JBPF_LOGGER_LIB} ${JBPF_LOGGER_SOURCES}) 14 | add_library(jbpf::logger_lib ALIAS ${JBPF_LOGGER_LIB}) 15 | target_include_directories(${JBPF_LOGGER_LIB} PUBLIC ${JBPF_LOGGER_HEADERS}) 16 | set_target_properties(${JBPF_LOGGER_LIB} PROPERTIES POSITION_INDEPENDENT_CODE ON) 17 | 18 | add_clang_format_check(${JBPF_LOGGER_LIB} ${JBPF_LOGGER_SOURCES}) 19 | add_cppcheck(${JBPF_LOGGER_LIB} ${JBPF_LOGGER_SOURCES}) -------------------------------------------------------------------------------- /src/mem_mgmt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. All rights reserved. 2 | cmake_minimum_required(VERSION 3.16) 3 | 4 | project(jbpf_mem_mgmt) 5 | 6 | set(JBPF_MEM_MGMT_LIB jbpf_mem_mgmt) 7 | 8 | if(CMAKE_BUILD_TYPE MATCHES AddressSanitizer) 9 | if (ENABLE_POISONING) 10 | add_definitions(-DJBPF_IO_POISON) 11 | endif() 12 | endif() 13 | 14 | add_link_options(-Wl,--no-as-needed -ldl) 15 | 16 | set(JBPF_MEM_MGMT_DIR ${PROJECT_SOURCE_DIR}) 17 | 18 | set(JBPF_MEM_MGMT_SOURCES ${JBPF_MEM_MGMT_DIR}/jbpf_mem_mgmt.c 19 | ${JBPF_MEM_MGMT_DIR}/jbpf_mempool.c 20 | ) 21 | set(JBPF_MEM_MGMT_HEADER_FILES ${PROJECT_SOURCE_DIR} PARENT_SCOPE) 22 | 23 | add_library(${JBPF_MEM_MGMT_LIB} ${JBPF_MEM_MGMT_SOURCES} $) 24 | add_library(jbpf::mem_mgmt_lib ALIAS ${JBPF_MEM_MGMT_LIB}) 25 | target_link_libraries(${JBPF_MEM_MGMT_LIB} PUBLIC mimalloc-static) 26 | target_include_directories(${JBPF_MEM_MGMT_LIB} PUBLIC ${JBPF_MEM_MGMT_HEADER_FILES} ${JBPF_LOGGER_HEADERS} ${MIMALLOC_HEADERS} ${JBPF_CK_INCLUDES}) 27 | 28 | set_target_properties(${JBPF_MEM_MGMT_LIB} 29 | PROPERTIES 30 | ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" 31 | LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" 32 | ) 33 | 34 | add_dependencies(${JBPF_MEM_MGMT_LIB} jbpf_libck) 35 | 36 | add_custom_command(TARGET ${JBPF_MEM_MGMT_LIB} POST_BUILD 37 | COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIR}/inc/ 38 | COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_MEM_MGMT_DIR}/jbpf_mempool.h ${OUTPUT_DIR}/inc/ 39 | COMMAND ${CMAKE_COMMAND} -E copy ${JBPF_MEM_MGMT_DIR}/jbpf_mem_mgmt.h ${OUTPUT_DIR}/inc/ 40 | ) 41 | 42 | add_clang_format_check(${JBPF_MEM_MGMT_LIB} ${JBPF_MEM_MGMT_SOURCES}) 43 | add_cppcheck(${JBPF_MEM_MGMT_LIB} ${JBPF_MEM_MGMT_SOURCES}) -------------------------------------------------------------------------------- /src/mem_mgmt/jbpf_mem_mgmt_int.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_MEM_MGMT_INT_H 2 | #define JBPF_MEM_MGMT_INT_H 3 | 4 | #include "jbpf_mem_mgmt.h" 5 | #include 6 | #include "mimalloc.h" 7 | 8 | struct jbpf_huge_page_info 9 | { 10 | char mount_point[MAX_NAME_SIZE]; 11 | char file_system[MAX_NAME_SIZE]; 12 | uint64_t page_size; 13 | uint64_t n_reserved_pages; 14 | bool is_anonymous; 15 | }; 16 | 17 | struct jbpf_mem_ctx 18 | { 19 | mi_arena_id_t arena_id; 20 | mi_heap_t* heap; 21 | pthread_t mem_ctx_tid; 22 | struct jbpf_mmap_info mmap_info; 23 | }; 24 | 25 | #endif -------------------------------------------------------------------------------- /src/mem_mgmt/jbpf_mem_mgmt_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_MEM_MGMT_UTILS_H 2 | #define JBPF_MEM_MGMT_UTILS_H 3 | 4 | #include 5 | 6 | #define container_of(ptr, type, member) \ 7 | ({ \ 8 | const typeof(((type*)0)->member)* __mptr = (ptr); \ 9 | (type*)((char*)__mptr - offsetof(type, member)); \ 10 | }) 11 | 12 | #define round_up_pow_of_two(x) \ 13 | ({ \ 14 | uint32_t v = x; \ 15 | v--; \ 16 | v |= v >> 1; \ 17 | v |= v >> 2; \ 18 | v |= v >> 4; \ 19 | v |= v >> 8; \ 20 | v |= v >> 16; \ 21 | ++v; \ 22 | }) 23 | 24 | static inline size_t 25 | _jbpf_round_up_mem(size_t orig_size, size_t multiple_size) 26 | { 27 | if (multiple_size == 0) 28 | return orig_size; 29 | 30 | size_t remainder = orig_size % multiple_size; 31 | if (remainder == 0) 32 | return orig_size; 33 | else 34 | return orig_size + multiple_size - remainder; 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /src/mem_mgmt/jbpf_mempool_int.h: -------------------------------------------------------------------------------- 1 | #ifndef JBPF_MEMPOOL_INT_H 2 | #define JBPF_MEMPOOL_INT_H 3 | 4 | #include "ck_ring.h" 5 | 6 | typedef struct jbpf_ring_ctx 7 | { 8 | ck_ring_t ring CK_CC_CACHELINE; 9 | ck_ring_buffer_t* buf; 10 | } jbpf_ring_ctx_t; 11 | 12 | struct jbpf_mempool 13 | { 14 | void* data_array; 15 | jbpf_ring_ctx_t ring; 16 | jbpf_ring_ctx_t ring_destroy; 17 | jbpf_ring_ctx_t* ring_alloc; 18 | jbpf_ring_ctx_t* ring_free; 19 | jbpf_mbuf_t* ring_marker; 20 | uint32_t type; 21 | uint16_t num_elems; 22 | uint16_t elem_size; 23 | uint16_t mbuf_size; 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /src/verifier/jbpf_platform.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | extern const ebpf_platform_t g_ebpf_platform_jbpf; 5 | 6 | /** 7 | * Get the platform for the JIT compiler. 8 | * return Pointer to the platform. 9 | */ 10 | EbpfHelperPrototype 11 | jbpf_verifier_get_helper_prototype(int32_t n); 12 | 13 | /** 14 | * Check if a helper is usable. 15 | * param n The helper number. 16 | * return True if the helper is usable. 17 | */ 18 | bool 19 | jbpf_verifier_is_helper_usable(int32_t n); 20 | -------------------------------------------------------------------------------- /src/verifier/jbpf_verifier_cli.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #include "CLI11.hpp" 3 | 4 | #include "jbpf_verifier.hpp" 5 | 6 | int 7 | main(int argc, char** argv) 8 | { 9 | CLI::App app{"jbpf verifier"}; 10 | const char *asm_file, *section; 11 | jbpf_verifier_result_t result; 12 | 13 | std::string filename; 14 | app.add_option("path", filename, "Elf file to analyze")->required()->type_name("FILE"); 15 | 16 | std::string desired_section; 17 | app.add_option("section", desired_section, "Section to analyze")->type_name("SECTION"); 18 | 19 | std::string asmfile; 20 | app.add_option("--asm", asmfile, "Print disassembly to FILE")->type_name("FILE"); 21 | 22 | CLI11_PARSE(app, argc, argv); 23 | 24 | if (desired_section.empty()) { 25 | section = nullptr; 26 | } else { 27 | section = desired_section.c_str(); 28 | } 29 | 30 | if (asmfile.empty()) { 31 | asm_file = nullptr; 32 | } else { 33 | asm_file = asmfile.c_str(); 34 | } 35 | 36 | result = jbpf_verify(filename.c_str(), section, asm_file); 37 | 38 | int res; 39 | if (result.verification_pass) { 40 | res = 1; 41 | std::cout << result.verification_pass << "," << result.runtime_seconds << std::endl; 42 | std::cout << "Program terminates within " << result.max_instruction_count << " instructions\n"; 43 | } else { 44 | res = 0; 45 | std::cout << "Failure: " << result.err_msg << std::endl; 46 | } 47 | 48 | return !res; 49 | } -------------------------------------------------------------------------------- /src/verifier/specs/spec_type_descriptors.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "ebpf_vm_isa.hpp" 9 | 10 | /* struct jbpf_generic_ctx { 11 | uint64_t data; 12 | uint64_t data_end; 13 | uint64_t meta_data; 14 | uint32_t ctx_id; 15 | } */ 16 | /* Size of the context struct */ 17 | constexpr int jbpf_generic_regions = 3 * 8 + 4 * 1; 18 | 19 | /* struct jbpf_stats_ctx { 20 | uint64_t data; 21 | uint64_t data_end; 22 | uint64_t meta_data; 23 | uint32_t meas_period; 24 | } */ 25 | /* Size of the context struct */ 26 | constexpr int jbpf_stats_regions = 3 * 8 + 4 * 1; 27 | 28 | constexpr ebpf_context_descriptor_t jbpf_generic_descr = {jbpf_generic_regions, 0, 1 * 8, 2 * 8}; 29 | constexpr ebpf_context_descriptor_t jbpf_stats_descr = {jbpf_stats_regions, 0, 1 * 8, 2 * 8}; 30 | // If no context is given, treat it as generic 31 | constexpr ebpf_context_descriptor_t jbpf_unspec_descr = jbpf_generic_descr; 32 | 33 | extern const ebpf_context_descriptor_t g_jbpf_unspec_descr; 34 | extern const ebpf_context_descriptor_t g_jbpf_generic_descr; 35 | extern const ebpf_context_descriptor_t g_jbpf_stats_descr; 36 | -------------------------------------------------------------------------------- /symver.map: -------------------------------------------------------------------------------- 1 | jbpf_x.x { 2 | global: 3 | jbpf*; 4 | }; 5 | -------------------------------------------------------------------------------- /tools/lcm_cli/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | project(jbpf_lcm_ipc_cli) 4 | 5 | find_package(yaml-cpp REQUIRED) 6 | include_directories(${YAML_CPP_INCLUDE_DIRS}) 7 | 8 | set(JBPF_LCM_IPC_CLI jbpf_lcm_cli) 9 | 10 | set(JBPF_LCM_IPC_CLI_SRC_DIR ${PROJECT_SOURCE_DIR} PARENT_SCOPE) 11 | 12 | set(JBPF_LCM_IPC_CLI_SOURCES ${PROJECT_SOURCE_DIR}/stream_id.cpp 13 | ${PROJECT_SOURCE_DIR}/parser.cpp 14 | ${PROJECT_SOURCE_DIR}/loader.cpp 15 | ${PROJECT_SOURCE_DIR}/main.cpp) 16 | 17 | set(JBPF_LCM_IPC_CLI_HEADER_FILES ${PROJECT_SOURCE_DIR} PARENT_SCOPE) 18 | 19 | add_executable(${JBPF_LCM_IPC_CLI} ${JBPF_LCM_IPC_CLI_SOURCES}) 20 | target_include_directories(${JBPF_LCM_IPC_CLI} PUBLIC ${JBPF_LCM_HEADER_FILES} 21 | ${HEADER_FILES} 22 | ${JBPF_LCM_IPC_CLI_HEADER_FILES} 23 | ${JBPF_VERIFIER_HEADERS}) 24 | target_link_libraries(${JBPF_LCM_IPC_CLI} PUBLIC jbpf::core_lib ${YAML_CPP_LIBRARIES} jbpf::lcm_ipc_lib) 25 | 26 | set_target_properties(${JBPF_LCM_IPC_CLI} 27 | PROPERTIES 28 | RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/bin" 29 | ) -------------------------------------------------------------------------------- /tools/lcm_cli/loader.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef LOADER_HPP 4 | #define LOADER_HPP 5 | 6 | namespace jbpf_lcm_cli { 7 | namespace loader { 8 | enum load_req_outcome 9 | { 10 | JBPF_LCM_CLI_REQ_SUCCESS, 11 | JBPF_LCM_CLI_INVALID_ARGS, 12 | JBPF_LCM_CLI_VERIFIER_FAILED, 13 | JBPF_LCM_CLI_PARSE_FAILED, 14 | JBPF_LCM_CLI_REQ_FAILURE, 15 | JBPF_LCM_CLI_EXIT 16 | }; 17 | 18 | load_req_outcome 19 | run_loader(int ac, char** av); 20 | } // namespace loader 21 | } // namespace jbpf_lcm_cli 22 | 23 | #endif // LOADER_HPP 24 | -------------------------------------------------------------------------------- /tools/lcm_cli/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include "loader.hpp" 4 | 5 | int 6 | main(int ac, char** av) 7 | { 8 | return jbpf_lcm_cli::loader::run_loader(ac, av); 9 | } -------------------------------------------------------------------------------- /tools/lcm_cli/parser.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef PARSER_HPP 4 | #define PARSER_HPP 5 | 6 | #include "yaml-cpp/yaml.h" 7 | #include 8 | #include 9 | #include 10 | #include "jbpf_lcm_api.h" 11 | 12 | namespace jbpf_lcm_cli { 13 | namespace parser { 14 | enum parse_req_outcome 15 | { 16 | JBPF_LCM_PARSE_REQ_SUCCESS, 17 | JBPF_LCM_PARSE_VERIFIER_FAILED, 18 | JBPF_LCM_PARSE_REQ_FAILED, 19 | }; 20 | 21 | parse_req_outcome 22 | parse_jbpf_codeletset_load_req( 23 | YAML::Node cfg, jbpf_codeletset_load_req* dest, std::vector codeletset_elems); 24 | parse_req_outcome 25 | parse_jbpf_codeletset_unload_req(YAML::Node cfg, jbpf_codeletset_unload_req* dest); 26 | std::string 27 | expand_environment_variables(const std::string& input); 28 | } // namespace parser 29 | } // namespace jbpf_lcm_cli 30 | 31 | #endif // PARSER_HPP 32 | -------------------------------------------------------------------------------- /tools/lcm_cli/stream_id.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | #include 5 | 6 | #include "stream_id.hpp" 7 | 8 | namespace jbpf_lcm_cli { 9 | namespace stream_id { 10 | using namespace std; 11 | 12 | /** 13 | * @brief create deterministic stream id using simple 64 bit hash function 14 | * 15 | * @param seed text values used as seeds 16 | * @param dest output stream id 17 | * @return int 0 for success, else failure 18 | */ 19 | int 20 | generate_from_strings(vector seed, jbpf_io_stream_id_t* dest) 21 | { 22 | if (seed.size() == 0) { 23 | cerr << "No seed values" << endl; 24 | return EXIT_FAILURE; 25 | } 26 | 27 | std::hash hasher; 28 | std::size_t acc1 = 0; 29 | std::size_t acc2 = 0; 30 | int c = 0; 31 | for (auto& s : seed) { 32 | if (c % 2 == 0) { 33 | acc1 ^= hasher(s); 34 | } else { 35 | acc2 ^= hasher(s); 36 | } 37 | c++; 38 | } 39 | 40 | for (int i = 0; i < 8; i++) { 41 | dest->id[i] = static_cast((acc1 >> (8 * i)) & 0xFF); 42 | dest->id[i + 8] = static_cast((acc2 >> (8 * i)) & 0xFF); 43 | } 44 | 45 | return EXIT_SUCCESS; 46 | } 47 | 48 | /** 49 | * @brief create stream id from hexidecimal string 50 | * 51 | * @param hex input hex string 52 | * @param dest output stream id 53 | * @return int 0 for success, else failure 54 | */ 55 | int 56 | from_hex(string hex, jbpf_io_stream_id_t* dest) 57 | { 58 | vector stream_id; 59 | 60 | if (hex.length() != JBPF_IO_STREAM_ID_LEN * 2) { 61 | cerr << "Invalid hex string length" << endl; 62 | return EXIT_FAILURE; 63 | } 64 | 65 | for (unsigned int i = 0; i < hex.length(); i += 2) 66 | stream_id.push_back((char)strtol(hex.substr(i, 2).c_str(), NULL, 16)); 67 | 68 | copy(begin(stream_id), end(stream_id), begin(dest->id)); 69 | 70 | return EXIT_SUCCESS; 71 | } 72 | } // namespace stream_id 73 | } // namespace jbpf_lcm_cli 74 | -------------------------------------------------------------------------------- /tools/lcm_cli/stream_id.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #ifndef LCM_CLI_STREAM_ID_HPP 4 | #define LCM_CLI_STREAM_ID_HPP 5 | 6 | #include 7 | #include 8 | 9 | #include "jbpf_lcm_api.h" 10 | 11 | namespace jbpf_lcm_cli { 12 | namespace stream_id { 13 | int 14 | generate_from_strings(std::vector seed, jbpf_io_stream_id_t* dest); 15 | int 16 | from_hex(std::string hex, jbpf_io_stream_id_t* dest); 17 | } // namespace stream_id 18 | } // namespace jbpf_lcm_cli 19 | 20 | #endif // LCM_CLI_STREAM_ID_HPP 21 | -------------------------------------------------------------------------------- /tools/stats_report/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CC = clang 3 | INC= -I${JBPF_PATH}/src/common -I${JBPF_PATH}/jbpf_tests/common -I${JBPF_PATH}/src/core 4 | CFLAGS = -O2 -target bpf -Wall -DJBPF_DEBUG_ENABLED -D__x86_64__ 5 | SOURCES = $(wildcard *.c) 6 | OBJECTS = $(SOURCES:.c=.o) 7 | 8 | all: $(OBJECTS) 9 | 10 | $(OBJECTS): %.o : %.c 11 | $(CC) $(INC) $(CFLAGS) -c $< 12 | 13 | clean : 14 | rm -f *.o 15 | 16 | cleanall : clean 17 | rm -f *.pb.h *_pb2.py *.json *_ut.xml 18 | rm -rf tmp* 19 | -------------------------------------------------------------------------------- /tools/stats_report/jbpf_stats_report.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Struct definitions */ 4 | typedef struct jbpf_hook_perf 5 | { 6 | uint64_t num; 7 | uint64_t min; 8 | uint64_t max; 9 | uint32_t hist_count; 10 | uint32_t hist[64]; 11 | char hook_name[32]; 12 | } jbpf_hook_perf; 13 | 14 | typedef struct jbpf_out_perf_list 15 | { 16 | uint64_t timestamp; 17 | uint32_t meas_period; 18 | uint32_t hook_perf_count; 19 | jbpf_hook_perf hook_perf[32]; 20 | } jbpf_out_perf_list; -------------------------------------------------------------------------------- /tools/stats_report/jbpf_stats_report.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/jbpf/fcb33a2feb00949ba1bab8323b69c816dda06211/tools/stats_report/jbpf_stats_report.o -------------------------------------------------------------------------------- /tools/stats_report/jbpf_stats_report_codeletset.yaml: -------------------------------------------------------------------------------- 1 | codeletset_id: jbpf_stats_report 2 | jbpf_stats_report_codelet: 3 | codelet: jbpf_stats_report.o 4 | hook_name: report_stats 5 | priority: 2 6 | -------------------------------------------------------------------------------- /tools/stats_report/jbpf_stats_report_codeletset_period_hook.yaml: -------------------------------------------------------------------------------- 1 | codeletset_id: jbpf_stats_report 2 | jbpf_stats_report_codelet: 3 | codelet: jbpf_stats_report.o 4 | hook_name: periodic_call 5 | priority: 2 6 | --------------------------------------------------------------------------------