Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copilot Instructions for eBPF for Windows

When working on the eBPF for Windows project, please follow these guidelines to ensure code quality and consistency.

## Comment Guidelines

### Comment Formatting
- **All comments MUST be complete sentences ending with proper punctuation (periods).**
- Single-line comments should start with `//` followed by a space and a complete sentence ending with a period.
- Multi-line comments should follow the same complete sentence rule for each line.
- Inline comments should also be complete sentences ending with periods.

**Examples:**
```c
// This is a correct comment.
/* This is also a correct multi-line comment. */

// Correct: Calculate the hash value for the key.
int hash = calculate_hash(key);

// Incorrect: Calculate the hash value for the key
// Incorrect: calculate hash value
```

### Comment Content
- Comments should be clear, concise, and add value to understanding the code.
- Avoid stating the obvious; focus on explaining why, not what.
- Use doxygen comments with `\[in,out\]` direction annotations for all public API headers.

## Coding Conventions

### Naming Conventions
- Use `lower_snake_case` for variable, member/field, and function names.
- Use `UPPER_SNAKE_CASE` for macro names and constants.
- Prefix eBPF specific names in the global namespace with `ebpf_` (e.g., `ebpf_result_t`).
- Prefix names with `_` to indicate internal and private fields or methods.
- Prefix struct definitions with `_` and always create a typedef with the suffix `_t`.
Comment on lines +32 to +37
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These duplicate text in docs/DevelopmentGuide.md which is fragile if someone changes one and not the other. Can we just tell copilot to follow the naming conventions in https://github.com/microsoft/ebpf-for-windows/blob/main/docs/DevelopmentGuide.md ?


### Type Usage
- Use fixed length types from `stdint.h` (e.g., `int64_t`, `uint8_t`) instead of language keywords.
- Use `const` and `static` modifiers to scope exposure appropriately.

### Code Structure
- Source lines MUST NOT exceed 120 columns.
- Single-line if/else/loop blocks MUST be enclosed in braces.
- Include local headers (with `""`) before system headers (with `<>`).
- List headers in alphabetical order where possible.
- Use `#pragma once` in all header files.

### License Header
Every code file must include this license header:
```c
// Copyright (c) eBPF for Windows contributors
// SPDX-License-Identifier: MIT
```

## What NOT to Do

- **DON'T** use global variables where possible.
- **DON'T** use abbreviations unless they are well-known terms.
- **DON'T** use hard-coded magic numbers; use `#define`, enum, or const values.
- **DON'T** use commented-out code or code in `#if 0` blocks.
- **DON'T** leave comments without proper punctuation.

## When Generating Code

1. Ensure all comments are grammatically complete sentences with proper punctuation.
2. Follow the established naming conventions consistently.
3. Include appropriate error handling and input validation.
4. Add doxygen comments for public APIs.
5. Follow the existing code structure and formatting patterns in the file being modified.
6. Use meaningful variable and function names that follow the project conventions.

## Pull Request Guidelines

- Ensure existing tests continue to pass.
- Provide tests for every bug/feature that is completed.
- Format code using clang-format before submitting.
- Verify that all comments follow the complete sentence rule.
- Check that the code follows the project's naming conventions.

Remember: Code clarity and consistency are paramount. When in doubt, follow the existing patterns in the codebase and ensure all comments are complete, well-formed sentences.
2 changes: 1 addition & 1 deletion libs/execution_context/ebpf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const NPI_MODULEID ebpf_general_helper_function_module_id = {
static ebpf_pinning_table_t* _ebpf_core_map_pinning_table = NULL;

// Assume enabled until we can query it.
// Extern variable defined in ebpf_core_jit.h
// Extern variable defined in ebpf_core_jit.h.
bool ebpf_platform_hypervisor_code_integrity_enabled = true;
static bool _ebpf_platform_test_signing_enabled = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table atomic_instruction_fetch_add##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/bad_map_name_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table bad_map_name##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table bindmonitor_bpf2bpf##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/bindmonitor_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table bindmonitor##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/bindmonitor_mt_tailcall_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table bindmonitor_mt_tailcall##_metadata_table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table bindmonitor_perf_event_array##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/bindmonitor_ringbuf_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table bindmonitor_ringbuf##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/bindmonitor_tailcall_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table bindmonitor_tailcall##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/bpf_call_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table bpf_call##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/bpf_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table bpf##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/cgroup_count_connect4_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table cgroup_count_connect4##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/cgroup_count_connect6_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table cgroup_count_connect6##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/cgroup_mt_connect4_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table cgroup_mt_connect4##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/cgroup_mt_connect6_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table cgroup_mt_connect6##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/cgroup_sock_addr2_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table cgroup_sock_addr2##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/cgroup_sock_addr_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table cgroup_sock_addr##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/divide_by_zero_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table divide_by_zero##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/global_vars_and_map_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table global_vars_and_map##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/global_vars_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table global_vars##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/hash_of_map_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table hash_of_map##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/inner_map_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table inner_map##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/map_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table map##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/map_in_map_btf_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table map_in_map_btf##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/map_in_map_legacy_id_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table map_in_map_legacy_id##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/map_in_map_legacy_idx_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table map_in_map_legacy_idx##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/map_reuse_2_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table map_reuse_2##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/map_reuse_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table map_reuse##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/map_synchronized_update_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table map_synchronized_update##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/multiple_programs_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table multiple_programs##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/pidtgid_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table pidtgid##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/printk_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table printk##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/printk_legacy_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table printk_legacy##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/process_start_key_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table process_start_key##_metadata_table
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/expected/sockops_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "bpf2c.h"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
#include <windows.h>

#define metadata_table sockops##_metadata_table
Expand Down
Loading
Loading