MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / copy_user_stack

Function copy_user_stack

crates/memtrack/src/ebpf/c/stack_capture.bpf.h:107–117  ·  view source on GitHub ↗

Copy the user stack at sp in STACK_COPY_CHUNK reads, stopping at the first * unreadable chunk. Returns the bytes copied, a multiple of STACK_COPY_CHUNK. * The loop is bounded by stack_copy_budget (a frozen rodata constant) so every * write into the reservation is provably in range. */

Source from the content-addressed store, hash-verified

105 * The loop is bounded by stack_copy_budget (a frozen rodata constant) so every
106 * write into the reservation is provably in range. */
107static __always_inline __u32 copy_user_stack(__u8* bytes, __u64 sp) {
108 __u32 got = 0;
109#pragma clang loop unroll(disable)
110 for (__u32 off = 0; off + STACK_COPY_CHUNK <= stack_copy_budget; off += STACK_COPY_CHUNK) {
111 if (bpf_probe_read_user(bytes + off, STACK_COPY_CHUNK, (void*)(sp + off)) != 0) {
112 break;
113 }
114 got = off + STACK_COPY_CHUNK;
115 }
116 return got;
117}
118
119/* Hash the first len bytes, one chunk at a time. The loop has the same budget
120 * bound as the copy so the verifier accepts the reads; len ends it early. */

Callers 1

capture_stack_innerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected