Skip to content

Commit ab362f0

Browse files
committed
Update map type names across documentation, examples, and tests to use hash and array instead of HashMap and Array. Ensure consistency in naming conventions for eBPF map types.
1 parent a63eb0f commit ab362f0

Some content is hidden

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

49 files changed

+414
-525
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,14 @@ Built-in support for all eBPF map types:
132132

133133
```kernelscript
134134
// Pinned maps persist across program restarts
135-
pin var connection_count : HashMap<IpAddress, Counter>(1024)
135+
pin var connection_count : hash<IpAddress, Counter>(1024)
136136
137137
// Per-CPU maps for better performance
138-
var cpu_stats : PercpuArray<u32, u64>(256)
138+
var cpu_stats : percpu_array<u32, u64>(256)
139139
140140
// LRU maps for automatic eviction
141-
var recent_packets : LruHash<IpAddress, PacketInfo>(1000)
141+
var recent_packets : lru_hash<IpAddress, PacketInfo>(1000)
142142
143-
// Ring buffers for event streaming
144-
pin var event_log : RingBuffer<u32, u8>(65536)
145143
```
146144

147145
### Functions and Helpers
@@ -205,7 +203,7 @@ KernelScript can coordinate multiple eBPF programs:
205203

206204
```kernelscript
207205
// Shared map between programs
208-
pin var shared_counter : HashMap<u32, u32>(1024)
206+
pin var shared_counter : hash<u32, u32>(1024)
209207
210208
// XDP program increments counter
211209
@xdp fn packet_counter(ctx: *xdp_md) -> xdp_action {

SPEC.md

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ u8[64] // 64-byte buffer
2525
u32[16] // 16 u32 values
2626
2727
// Simple map declarations
28-
var counters : Array<u32, u64>(256)
29-
var flows : HashMap<IpAddress, PacketStats>(1024)
28+
var counters : array<u32, u64>(256)
29+
var flows : hash<IpAddress, PacketStats>(1024)
3030
3131
// No complex template metaprogramming - just practical, concrete types
3232
```
@@ -43,7 +43,7 @@ KernelScript uses a simple and clear scoping model that eliminates ambiguity:
4343
```kernelscript
4444
// Shared resources (accessible by both kernel and userspace)
4545
config system { debug: bool = false }
46-
var counters : Array<u32, u64>(256)
46+
var counters : array<u32, u64>(256)
4747
4848
// Kernel-shared functions (accessible by all eBPF programs)
4949
@helper
@@ -480,7 +480,7 @@ struct PinnedGlobals {
480480
481481
// Single-entry pinned map
482482
@flags(BPF_F_NO_PREALLOC)
483-
pin var __pinned_globals : Array<u32, PinnedGlobals>(1)
483+
pin var __pinned_globals : array<u32, PinnedGlobals>(1)
484484
485485
// Access wrappers (transparent to user):
486486
// packet_count access becomes: __pinned_globals[0].packet_count
@@ -561,7 +561,7 @@ config monitoring {
561561
packets_processed: u64 = 0,
562562
}
563563
564-
var global_stats : HashMap<u32, PacketStats>(1024)
564+
var global_stats : hash<u32, PacketStats>(1024)
565565
566566
// Userspace types
567567
struct PacketStats {
@@ -1356,7 +1356,7 @@ struct tcp_congestion_ops {
13561356
}
13571357
13581358
// Initialize shared state before registration
1359-
var connection_state : HashMap<u32, BbrState>(1024)
1359+
var connection_state : hash<u32, BbrState>(1024)
13601360
13611361
// Implement struct_ops using impl block syntax
13621362
@struct_ops("tcp_congestion_ops")
@@ -2031,7 +2031,7 @@ fn ebpf_function_parameters() {
20312031
#### 4.6.7 Map Integration with Pointers
20322032

20332033
```kernelscript
2034-
var flow_map : HashMap<FlowKey, FlowData>(1024)
2034+
var flow_map : hash<FlowKey, FlowData>(1024)
20352035
20362036
@helper
20372037
fn map_pointer_operations(flow_key: FlowKey) {
@@ -2089,8 +2089,7 @@ fn bounds_safety_example(ctx: *xdp_md) -> xdp_action {
20892089
```ebnf
20902090
map_declaration = [ "pin" ] [ "@flags" "(" flag_expression ")" ] "var" identifier ":" map_type "<" key_type "," value_type ">" "(" map_config ")"
20912091
2092-
map_type = "HashMap" | "Array" | "ProgArray" | "PerCpuHash" | "PerCpuArray" |
2093-
"LruHash" | "RingBuffer" | "PerfEvent" | "StackTrace"
2092+
map_type = "hash" | "array" | "percpu_hash" | "percpu_array" | "lru_hash"
20942093
20952094
map_config = max_entries [ "," additional_config ]
20962095
flag_expression = identifier | ( identifier { "|" identifier } )
@@ -2115,11 +2114,11 @@ Map flags can be specified using the `@flags` attribute:
21152114
```kernelscript
21162115
// Map with flags
21172116
@flags(BPF_F_NO_PREALLOC | BPF_F_NO_COMMON_LRU)
2118-
var dynamic_cache : HashMap<u32, PacketData>(1024)
2117+
var dynamic_cache : hash<u32, PacketData>(1024)
21192118
21202119
// Pinned map with flags
21212120
@flags(BPF_F_NO_PREALLOC)
2122-
pin var persisted_flows : HashMap<u32, FlowData>(2048)
2121+
pin var persisted_flows : hash<u32, FlowData>(2048)
21232122
```
21242123

21252124
**Supported flags:**
@@ -2148,16 +2147,16 @@ Pinned maps are automatically stored at `/sys/fs/bpf/<PROJECT_NAME>/maps/<MAP_NA
21482147
// Global maps - automatically shared between all programs
21492148
21502149
// Pinned maps - persisted to filesystem (/sys/fs/bpf/<PROJECT>/maps/<NAME>)
2151-
pin var global_flows : HashMap<FlowKey, FlowStats>(10000)
2152-
pin var interface_stats : Array<u32, InterfaceStats>(256)
2153-
pin var security_events : RingBuffer<SecurityEvent>(1024 * 1024)
2150+
pin var global_flows : hash<FlowKey, FlowStats>(10000)
2151+
pin var interface_stats : array<u32, InterfaceStats>(256)
2152+
pin var security_events : hash<SecurityEvent, u64>(1024)
21542153
21552154
// Non-pinned maps - shared during runtime but not persisted
2156-
var session_cache : HashMap<u32, TempData>(512)
2155+
var session_cache : hash<u32, TempData>(512)
21572156
21582157
// Maps with flags
21592158
@flags(BPF_F_NO_PREALLOC)
2160-
pin var global_config : Array<ConfigKey, ConfigValue>(64)
2159+
pin var global_config : array<ConfigKey, ConfigValue>(64)
21612160
21622161
// Program 1: Can access all global maps
21632162
@xdp
@@ -2234,8 +2233,8 @@ fn security_analyzer(ctx: LsmContext) -> i32 {
22342233

22352234
```kernelscript
22362235
// Global maps - accessible by all eBPF programs
2237-
pin var global_counters : Array<u32, GlobalCounter>(256)
2238-
pin var event_stream : RingBuffer<Event>(1024 * 1024)
2236+
pin var global_counters : array<u32, GlobalCounter>(256)
2237+
pin var event_stream : hash<u32, Event>(1024)
22392238
22402239
@kprobe("sys_read")
22412240
fn producer(fd: u32, buf: *u8, count: usize) -> i32 {
@@ -2274,15 +2273,15 @@ fn consumer(fd: u32, buf: *u8, count: usize) -> i32 {
22742273
### 5.4 Map Examples
22752274
```kernelscript
22762275
// Global maps accessible by all programs
2277-
pin var packet_stats : HashMap<u32, PacketStats>(1024)
2276+
pin var packet_stats : hash<u32, PacketStats>(1024)
22782277
2279-
pin var counters : PerCpuArray<u32, u64>(256)
2278+
pin var counters : percpu_array<u32, u64>(256)
22802279
2281-
pin var active_flows : LruHash<FlowKey, FlowInfo>(10000)
2280+
pin var active_flows : lru_hash<FlowKey, FlowInfo>(10000)
22822281
2283-
pin var events : RingBuffer<PacketEvent>(1024 * 1024)
2282+
pin var events : hash<u32, PacketEvent>(1024)
22842283
2285-
pin var config_map : Array<ConfigKey, ConfigValue>(16)
2284+
pin var config_map : array<ConfigKey, ConfigValue>(16)
22862285
22872286
@xdp
22882287
fn simple_monitor(ctx: *xdp_md) -> xdp_action {
@@ -2373,7 +2372,7 @@ fn packet_counter(ctx: *xdp_md) -> xdp_action {
23732372
}
23742373
23752374
// Map operations with compound assignment
2376-
var flow_stats : HashMap<u32, FlowStats>(1024)
2375+
var flow_stats : hash<u32, FlowStats>(1024)
23772376
23782377
@helper
23792378
fn update_flow_stats(flow_id: u32, packet_size: u32) {
@@ -2761,7 +2760,7 @@ fn invalid_examples(ctx: *xdp_md) -> xdp_action {
27612760

27622761
#### 7.4.3 Implementation Details
27632762

2764-
**Automatic ProgArray Management:**
2763+
**Automatic Program Array Management:**
27652764
The compiler automatically generates and manages eBPF program arrays behind the scenes:
27662765

27672766
```kernelscript
@@ -3196,11 +3195,11 @@ fn main() -> i32 {
31963195
### 9.2 Top-Level Userspace Coordination with Global Maps
31973196
```kernelscript
31983197
// Global maps (accessible from all programs and userspace)
3199-
pin var global_flows : HashMap<FlowKey, FlowStats>(10000)
3198+
pin var global_flows : hash<FlowKey, FlowStats>(10000)
32003199
3201-
pin var global_events : RingBuffer<Event>(1024 * 1024)
3200+
pin var global_events : hash<u32, Event>(1024)
32023201
3203-
pin var global_config : Array<ConfigKey, ConfigValue>(64)
3202+
pin var global_config : array<ConfigKey, ConfigValue>(64)
32043203
32053204
// Multiple eBPF programs working together
32063205
@xdp fn network_monitor(ctx: *xdp_md) -> xdp_action {
@@ -3242,7 +3241,7 @@ struct SystemCoordinator {
32423241
32433242
// Global map access (shared across all programs)
32443243
global_flows: *FlowStatsMap,
3245-
global_events: *EventRingBuffer,
3244+
global_events: *EventHash,
32463245
global_config: *ConfigMap,
32473246
}
32483247
@@ -3415,7 +3414,7 @@ fn safe_userspace_access(data: *u8, len: u32) -> u8 {
34153414
The compiler transparently uses eBPF's dynamic pointer (dynptr) APIs when beneficial, without exposing complexity to the programmer.
34163415

34173416
```kernelscript
3418-
var event_log : RingBuffer<Event>(1024 * 1024)
3417+
var event_log : hash<u32, Event>(1024)
34193418
34203419
@helper
34213420
fn transparent_dynptr_usage(event_data: *u8, data_len: u32) {
@@ -3509,7 +3508,7 @@ fn resource_safe_processing(input: *u8, len: u32) -> ProcessResult {
35093508
}
35103509
35113510
// Map value pointer lifetime tracking
3512-
var cache_map : HashMap<u32, DataCache>(1024)
3511+
var cache_map : hash<u32, DataCache>(1024)
35133512
35143513
@helper
35153514
fn map_lifetime_safety(key: u32) {
@@ -4140,9 +4139,9 @@ fn main(args: Args) -> i32 {
41404139
### 14.3 Performance Monitoring
41414140
```kernelscript
41424141
// Global maps for performance data
4143-
var active_calls : HashMap<u32, CallInfo>(1024)
4144-
var read_stats : Array<u32, u64>(1024)
4145-
var write_stats : Array<u32, u64>(1024)
4142+
var active_calls : hash<u32, CallInfo>(1024)
4143+
var read_stats : array<u32, u64>(1024)
4144+
var write_stats : array<u32, u64>(1024)
41464145
41474146
struct CallInfo {
41484147
start_time: u64,
@@ -4312,8 +4311,7 @@ global_declaration = config_declaration | map_declaration | type_declaration |
43124311
(* Map declarations - global scope *)
43134312
map_declaration = [ "pin" ] [ "@flags" "(" flag_expression ")" ] "var" identifier ":" map_type "<" key_type "," value_type ">" "(" map_config ")"
43144313
4315-
map_type = "HashMap" | "Array" | "PerCpuHash" | "PerCpuArray" | "LruHash" |
4316-
"RingBuffer" | "PerfEvent" | "StackTrace" | "ProgArray"
4314+
map_type = "hash" | "array" | "percpu_hash" | "percpu_array" | "lru_hash"
43174315
43184316
map_config = integer_literal [ "," map_config_item { "," map_config_item } ]
43194317
map_config_item = identifier "=" literal

examples/break_continue_unbound.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum xdp_action {
2020
// Example demonstrating break and continue in truly unbound loops
2121
// This should force bpf_loop() usage
2222

23-
var counter_map : HashMap<u32, u32>(10)
23+
var counter_map : hash<u32, u32>(10)
2424

2525
@xdp fn packet_filter(ctx: *xdp_md) -> xdp_action {
2626
var end_value = 1000 // Large value to make it unbound

examples/dynptr.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct DataBuffer {
2626
size: u32
2727
}
2828

29-
var buffer_map : HashMap<u32, DataBuffer>(1024)
29+
var buffer_map : hash<u32, DataBuffer>(1024)
3030

3131
@helper
3232
fn process_map_data(buffer_ptr: *DataBuffer) -> u32 {

examples/error_handling_demo.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum xdp_action {
1818
}
1919

2020
// Minimal error handling demo
21-
var counters : HashMap<u32, u64>(1024)
21+
var counters : hash<u32, u64>(1024)
2222

2323
@xdp fn error_demo(ctx: *xdp_md) -> xdp_action {
2424
var key = 42

examples/map_operations_demo.ks

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ struct PerCpuData {
7373
// Global maps shared across multiple programs with the new simplified syntax
7474

7575
// Global counter with automatic path: /sys/fs/bpf/map_operations_demo/maps/global_counter
76-
pin var global_counter : HashMap<u32, u64>(10000)
76+
pin var global_counter : hash<u32, u64>(10000)
7777

7878
// Statistics map with read-only flags
79-
@flags(rdonly) pin var shared_stats : HashMap<u32, Statistics>(1000)
79+
@flags(rdonly) pin var shared_stats : hash<u32, Statistics>(1000)
8080

8181
// Per-CPU data with automatic pinning path: /sys/fs/bpf/map_operations_demo/maps/percpu_data
82-
pin var percpu_data : PercpuHash<u32, PerCpuData>(256)
82+
pin var percpu_data : percpu_hash<u32, PerCpuData>(256)
8383

8484
// Event stream ring buffer with no preallocation flag
85-
@flags(no_prealloc) pin var event_stream : RingBuffer<u32, u32>(65536)
85+
@flags(no_prealloc) pin var event_stream : hash<u32, u32>(65536)
8686

8787
// Sequential data array - not pinned (local to program)
88-
var sequential_data : Array<u32, ArrayElement>(1024)
88+
var sequential_data : array<u32, ArrayElement>(1024)
8989

9090
struct Event {
9191
timestamp: u64,

examples/maps_demo.ks

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ struct PacketStats {
4444
// Global maps with different configurations
4545

4646
// 1. Simple array map for per-CPU counters (pinned to filesystem)
47-
pin var cpu_counters : Array<u32, Counter>(256)
47+
pin var cpu_counters : array<u32, Counter>(256)
4848

4949
// 2. Hash map for IP address tracking (pinned to filesystem)
50-
pin var ip_stats : HashMap<IpAddress, PacketStats>(10000)
50+
pin var ip_stats : hash<IpAddress, PacketStats>(10000)
5151

5252
// 3. LRU hash map for recent connections (local to program)
53-
var recent_connections : LruHash<IpAddress, u64>(1000)
53+
var recent_connections : lru_hash<IpAddress, u64>(1000)
5454

5555
// 4. Ring buffer for event logging (pinned to filesystem)
56-
pin var event_log : RingBuffer<u32, u8>(65536)
56+
pin var event_log : hash<u32, u8>(65536)
5757

5858
// 5. Local state map (not pinned)
59-
var local_state : HashMap<u32, u32>(100)
59+
var local_state : hash<u32, u32>(100)
6060

6161
// 6. Per-CPU bandwidth tracking (pinned to filesystem)
62-
pin var bandwidth_usage : PercpuArray<u32, u64>(256)
62+
pin var bandwidth_usage : percpu_array<u32, u64>(256)
6363

6464
@helper
6565
fn get_cpu_id() -> u32 {

examples/multi_programs.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum tc_action {
4040
TC_ACT_REDIRECT = 7,
4141
}
4242

43-
pin var shared_counter : HashMap<u32, u32>(1024)
43+
pin var shared_counter : hash<u32, u32>(1024)
4444

4545
// First eBPF program - packet counter
4646
@xdp fn packet_counter(ctx: *xdp_md) -> xdp_action {

examples/object_allocation.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct ConnStats {
2828
}
2929

3030
// Map to store connection statistics
31-
var conn_tracker : HashMap<u32, *ConnStats>(1024)
31+
var conn_tracker : hash<u32, *ConnStats>(1024)
3232

3333
@xdp fn packet_inspector(ctx: *xdp_md) -> xdp_action {
3434
// Simple source IP extraction (in real code, would parse ethernet/IP headers)

examples/rate_limiter.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum xdp_action {
1717
XDP_TX = 4,
1818
}
1919

20-
var packet_counts : HashMap<u32, u64>(1024)
20+
var packet_counts : hash<u32, u64>(1024)
2121

2222
config network {
2323
limit : u32,

0 commit comments

Comments
 (0)