Skip to content

Commit

Permalink
Normalize all registry API names.
Browse files Browse the repository at this point in the history
  • Loading branch information
gtrevi committed Jul 31, 2023
1 parent 92cd59b commit a391fa2
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 119 deletions.
68 changes: 35 additions & 33 deletions libs/api_common/store_helper_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ _open_ebpf_store_key(_Out_ ebpf_store_key_t* store_key)

// First try to open the HKCU registry key.
ebpf_result_t result =
open_registry_key(root_registry_key_current_user, EBPF_STORE_REGISTRY_PATH, KEY_READ, store_key);
ebpf_open_registry_key(root_registry_key_current_user, EBPF_STORE_REGISTRY_PATH, KEY_READ, store_key);
if (result != ERROR_SUCCESS) {
// Failed to open ebpf store path in HKCU. Fall back to HKLM.
result = open_registry_key(root_registry_key_local_machine, EBPF_STORE_REGISTRY_PATH, KEY_READ, store_key);
result = ebpf_open_registry_key(root_registry_key_local_machine, EBPF_STORE_REGISTRY_PATH, KEY_READ, store_key);
}

return result;
Expand Down Expand Up @@ -54,7 +54,7 @@ _load_helper_prototype(
size_t expected_size = sizeof(helper_prototype->helper_id) + sizeof(helper_prototype->return_type) +
sizeof(helper_prototype->arguments);

status = read_registry_value_binary(
status = ebpf_read_registry_value_binary(
helper_info_key, EBPF_HELPER_DATA_PROTOTYPE, (uint8_t*)serialized_data, expected_size);
if (status != ERROR_SUCCESS) {
result = win32_error_code_to_ebpf_result(status);
Expand Down Expand Up @@ -84,7 +84,7 @@ _load_helper_prototype(

Exit:
if (helper_info_key) {
close_registry_key(static_cast<ebpf_store_key_t>(helper_info_key));
ebpf_close_registry_key(static_cast<ebpf_store_key_t>(helper_info_key));
}
return result;
}
Expand All @@ -111,8 +111,8 @@ _load_program_data_information(
*program_info = nullptr;

try {
result =
open_registry_key(program_data_key, program_type_string, KEY_READ, (ebpf_store_key_t*)&program_info_key);
result = ebpf_open_registry_key(
program_data_key, program_type_string, KEY_READ, (ebpf_store_key_t*)&program_info_key);
if (result != EBPF_SUCCESS) {
// Registry path is not present.
result = EBPF_FILE_NOT_FOUND;
Expand All @@ -125,13 +125,13 @@ _load_program_data_information(
goto Exit;
}

result = convert_string_to_guid(program_type_string, program_type);
result = ebpf_convert_string_to_guid(program_type_string, program_type);
if (result != EBPF_SUCCESS) {
goto Exit;
}

// Read the friendly program type name.
result = read_registry_value_string(program_info_key, EBPF_PROGRAM_DATA_NAME, &program_type_name);
result = ebpf_read_registry_value_string(program_info_key, EBPF_PROGRAM_DATA_NAME, &program_type_name);
if (result != EBPF_SUCCESS) {
goto Exit;
}
Expand All @@ -142,7 +142,7 @@ _load_program_data_information(
result = EBPF_NO_MEMORY;
goto Exit;
}
result = read_registry_value_binary(
result = ebpf_read_registry_value_binary(
program_info_key,
EBPF_PROGRAM_DATA_CONTEXT_DESCRIPTOR,
(uint8_t*)descriptor,
Expand All @@ -152,19 +152,19 @@ _load_program_data_information(
}

// Read "is_privileged".
result = read_registry_value_dword(program_info_key, EBPF_PROGRAM_DATA_PRIVILEGED, &is_privileged);
result = ebpf_read_registry_value_dword(program_info_key, EBPF_PROGRAM_DATA_PRIVILEGED, &is_privileged);
if (result != EBPF_SUCCESS) {
goto Exit;
}

// Read bpf program type.
result = read_registry_value_dword(program_info_key, EBPF_DATA_BPF_PROG_TYPE, &bpf_program_type);
result = ebpf_read_registry_value_dword(program_info_key, EBPF_DATA_BPF_PROG_TYPE, &bpf_program_type);
if (result != EBPF_SUCCESS) {
goto Exit;
}

// Read helper count.
result = read_registry_value_dword(program_info_key, EBPF_PROGRAM_DATA_HELPER_COUNT, &helper_count);
result = ebpf_read_registry_value_dword(program_info_key, EBPF_PROGRAM_DATA_HELPER_COUNT, &helper_count);
if (result != EBPF_SUCCESS) {
goto Exit;
}
Expand Down Expand Up @@ -279,13 +279,13 @@ _load_program_data_information(
ebpf_program_info_free(program_information);
}
if (program_info_key) {
close_registry_key(program_info_key);
ebpf_close_registry_key(program_info_key);
}
ebpf_free(program_type_name);
ebpf_free(program_type);

if (helper_key) {
close_registry_key(helper_key);
ebpf_close_registry_key(helper_key);
}
return result;
}
Expand Down Expand Up @@ -316,8 +316,8 @@ ebpf_store_load_program_information(
}

// Open program data registry path.
result =
open_registry_key(store_key, EBPF_PROGRAM_DATA_REGISTRY_PATH, KEY_READ, (ebpf_store_key_t*)&program_data_key);
result = ebpf_open_registry_key(
store_key, EBPF_PROGRAM_DATA_REGISTRY_PATH, KEY_READ, (ebpf_store_key_t*)&program_data_key);
if (result != EBPF_SUCCESS) {
if (result == EBPF_FILE_NOT_FOUND) {
result = EBPF_SUCCESS;
Expand Down Expand Up @@ -382,7 +382,7 @@ ebpf_store_load_program_information(
}

if (program_data_key) {
close_registry_key(program_data_key);
ebpf_close_registry_key(program_data_key);
}

return result;
Expand All @@ -404,7 +404,7 @@ _load_section_data_information(
ebpf_section_definition_t* section_information = nullptr;

try {
result = open_registry_key(section_data_key, section_name, KEY_READ, (ebpf_store_key_t*)&section_info_key);
result = ebpf_open_registry_key(section_data_key, section_name, KEY_READ, (ebpf_store_key_t*)&section_info_key);
if (result != EBPF_SUCCESS) {
// Registry path is not present.
result = EBPF_FILE_NOT_FOUND;
Expand All @@ -424,30 +424,32 @@ _load_section_data_information(
}

// Read program type.
result = read_registry_value_binary(
result = ebpf_read_registry_value_binary(
section_info_key, EBPF_SECTION_DATA_PROGRAM_TYPE, (uint8_t*)program_type, sizeof(ebpf_program_type_t));
if (result != EBPF_SUCCESS) {
__analysis_assume(result != EBPF_SUCCESS);
goto Exit;
}

// Read attach type.
result = read_registry_value_binary(
result = ebpf_read_registry_value_binary(
section_info_key, EBPF_SECTION_DATA_ATTACH_TYPE, (uint8_t*)attach_type, sizeof(ebpf_attach_type_t));
if (result != EBPF_SUCCESS) {
__analysis_assume(result != EBPF_SUCCESS);
goto Exit;
}

// Read bpf program type.
result = read_registry_value_dword(section_info_key, EBPF_DATA_BPF_PROG_TYPE, (uint32_t*)&bpf_program_type);
result =
ebpf_read_registry_value_dword(section_info_key, EBPF_DATA_BPF_PROG_TYPE, (uint32_t*)&bpf_program_type);
if (result != EBPF_SUCCESS) {
bpf_program_type = BPF_PROG_TYPE_UNSPEC;
result = EBPF_SUCCESS;
}

// Read bpf attach type.
result = read_registry_value_dword(section_info_key, EBPF_DATA_BPF_ATTACH_TYPE, (uint32_t*)&bpf_attach_type);
result =
ebpf_read_registry_value_dword(section_info_key, EBPF_DATA_BPF_ATTACH_TYPE, (uint32_t*)&bpf_attach_type);
if (result != EBPF_SUCCESS) {
bpf_attach_type = BPF_ATTACH_TYPE_UNSPEC;
result = EBPF_SUCCESS;
Expand Down Expand Up @@ -486,7 +488,7 @@ _load_section_data_information(
ebpf_free(section_information);
}
if (section_info_key) {
close_registry_key(section_info_key);
ebpf_close_registry_key(section_info_key);
}
return result;
}
Expand Down Expand Up @@ -582,7 +584,7 @@ ebpf_store_load_section_information(
}
}
if (section_data_key) {
close_registry_key(section_data_key);
ebpf_close_registry_key(section_data_key);
}
return result;
}
Expand Down Expand Up @@ -615,7 +617,7 @@ ebpf_store_load_global_helper_information(
}

// Open program data registry path.
result = open_registry_key(
result = ebpf_open_registry_key(
store_key, EBPF_GLOBAL_HELPERS_REGISTRY_PATH, KEY_READ, (ebpf_store_key_t*)&global_helpers_key);
if (result != EBPF_SUCCESS) {
if (result == EBPF_FILE_NOT_FOUND) {
Expand Down Expand Up @@ -690,7 +692,7 @@ ebpf_store_load_global_helper_information(

Exit:
if (global_helpers_key) {
close_registry_key(global_helpers_key);
ebpf_close_registry_key(global_helpers_key);
}
if (result != EBPF_SUCCESS) {
if (helper_prototype) {
Expand All @@ -712,7 +714,7 @@ ebpf_store_clear(_In_ const ebpf_store_key_t root_key_path)
ebpf_result_t result = EBPF_FAILED;

// Open root registry key.
result = open_registry_key(root_key_path, EBPF_ROOT_RELATIVE_PATH, REG_CREATE_FLAGS, &root_handle);
result = ebpf_open_registry_key(root_key_path, EBPF_ROOT_RELATIVE_PATH, REG_CREATE_FLAGS, &root_handle);
if (result != EBPF_SUCCESS) {
if (result == EBPF_FILE_NOT_FOUND) {
result = EBPF_SUCCESS;
Expand All @@ -721,7 +723,7 @@ ebpf_store_clear(_In_ const ebpf_store_key_t root_key_path)
}

// Open "providers" registry key.
result = open_registry_key(root_handle, EBPF_PROVIDERS_REGISTRY_PATH, REG_CREATE_FLAGS, &provider_handle);
result = ebpf_open_registry_key(root_handle, EBPF_PROVIDERS_REGISTRY_PATH, REG_CREATE_FLAGS, &provider_handle);
if (result != EBPF_SUCCESS) {
if (result == EBPF_FILE_NOT_FOUND) {
result = EBPF_SUCCESS;
Expand All @@ -730,14 +732,14 @@ ebpf_store_clear(_In_ const ebpf_store_key_t root_key_path)
}

// Delete subtree of provider reg key.
result = delete_registry_tree(provider_handle, NULL);
result = ebpf_delete_registry_tree(provider_handle, NULL);
if (result != EBPF_SUCCESS) {
goto Exit;
}
close_registry_key(provider_handle);
ebpf_close_registry_key(provider_handle);
provider_handle = nullptr;

result = delete_registry_key(root_handle, EBPF_PROVIDERS_REGISTRY_PATH);
result = ebpf_delete_registry_key(root_handle, EBPF_PROVIDERS_REGISTRY_PATH);
if (result != EBPF_SUCCESS) {
goto Exit;
}
Expand All @@ -746,10 +748,10 @@ ebpf_store_clear(_In_ const ebpf_store_key_t root_key_path)

Exit:
if (provider_handle) {
close_registry_key(provider_handle);
ebpf_close_registry_key(provider_handle);
}
if (root_handle) {
close_registry_key(root_handle);
ebpf_close_registry_key(root_handle);
}

return result;
Expand Down
Loading

0 comments on commit a391fa2

Please sign in to comment.