mirror of
https://github.com/aya-rs/aya.git
synced 2026-03-03 18:23:55 +01:00
Implement `PerfEventConfig::Breakpoint`, allowing users to attach hardware breakpoints. Generate `HW_BREAKPOINT_*` and `struct bpf_perf_event_data` in support of this feature and update the type of `PerfEventContext` accordingly. Add a test exercising R, W, RW, and X breakpoints. Note that R breakpoints are unsupported on x86, and this is asserted in the test. Extend the VM integration test harness and supporting infrastructure (e.g. `download_kernel_images.sh`) to download kernel debug packages and mount `System.map` in initramfs. This is needed (at least) on the aarch 6.1 Debian kernel which was not compiled with `CONFIG_KALLSYMS_ALL=y` for some reason, and the locations of globals are not available in kallsyms. To attach breakpoints to these symbols in the test pipeline, we need to read them from System.map and apply the KASLR offset to get their real address. The `System.map` file is not provided in the kernel package by default, so we need to extract it from the corresponding debug package. The KASLR offset is computed using `gunzip` which appears in kallsyms on all Debian kernels tested. Co-authored-by: Tamir Duberstein <tamird@gmail.com>
77 lines
2.7 KiB
Bash
Executable File
77 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
# Check for required arguments.
|
|
if [ "$#" -lt 3 ]; then
|
|
echo "Usage: $0 <output directory> <architecture> <version1> [<version2> ...]"
|
|
exit 1
|
|
fi
|
|
|
|
escape_regex() {
|
|
# Escape characters that have special meaning in extended regular expressions so that
|
|
# we can safely interpolate package names into grep patterns.
|
|
printf '%s\n' "$1" | sed 's/[][(){}.^$*+?|\\-]/\\&/g'
|
|
}
|
|
|
|
OUTPUT_DIR=$1
|
|
ARCHITECTURE=$2
|
|
shift 2
|
|
VERSIONS=("$@")
|
|
|
|
URLS=$(lynx -dump -listonly -nonumbers https://mirrors.wikimedia.org/debian/pool/main/l/linux/)
|
|
readonly URLS
|
|
|
|
# Find the latest revision of each kernel version.
|
|
FILES=()
|
|
for VERSION in "${VERSIONS[@]}"; do
|
|
REGEX="linux-image-${VERSION//./\\.}\\.[0-9]+(-[0-9]+)?(\+bpo|\+deb[0-9]+)?-cloud-${ARCHITECTURE}-unsigned_.*\\.deb"
|
|
match=$(printf '%s\n' "$URLS" | grep -E "$REGEX" | sort -V | tail -n1) || {
|
|
printf '%s\nVERSION=%s\nREGEX=%s\n' "$URLS" "$VERSION" "$REGEX" >&2
|
|
exit 1
|
|
}
|
|
FILES+=("$match")
|
|
|
|
# The debug package contains the actual System.map. Debian has transitioned
|
|
# between -dbg and -dbgsym suffixes, so match either for the specific kernel
|
|
# we just selected.
|
|
kernel_basename=$(basename "$match")
|
|
kernel_prefix=${kernel_basename%%_*}
|
|
kernel_suffix=${kernel_basename#${kernel_prefix}_}
|
|
base_prefix=${kernel_prefix%-unsigned}
|
|
|
|
base_prefix_regex=$(escape_regex "$base_prefix")
|
|
kernel_suffix_regex=$(escape_regex "$kernel_suffix")
|
|
|
|
DEBUG_REGEX="${base_prefix_regex}-dbg(sym)?_${kernel_suffix_regex}"
|
|
debug_match=$(printf '%s\n' "$URLS" | grep -E "$DEBUG_REGEX" | sort -V | tail -n1) || {
|
|
printf 'Failed to locate debug package matching %s\n%s\nVERSION=%s\nREGEX=%s\n' \
|
|
"$kernel_basename" "$URLS" "$VERSION" "$DEBUG_REGEX" >&2
|
|
exit 1
|
|
}
|
|
FILES+=("$debug_match")
|
|
done
|
|
|
|
# Note: `--etag-{compare,save}` are not idempotent until curl 8.9.0 which included
|
|
# https://github.com/curl/curl/commit/85efbb92b8e6679705e122cee45ce76c56414a3e. At the time of
|
|
# writing our CI uses Ubuntu 22.04 which has curl 7.81.0 and the latest available is Ubuntu 24.04
|
|
# which has curl 8.5.0. Since neither has a new enough curl, we don't bother to update, but we
|
|
# should do so when Ubuntu 24.10 or later is available.
|
|
mkdir -p "$OUTPUT_DIR"
|
|
KEEP=()
|
|
for FILE in "${FILES[@]}"; do
|
|
name=$(basename "$FILE")
|
|
etag_name="$name.etag"
|
|
KEEP+=("$name" "$etag_name")
|
|
|
|
etag="$OUTPUT_DIR/$etag_name"
|
|
curl -sfSL --output-dir "$OUTPUT_DIR" --remote-name-all --etag-compare "$etag" --etag-save "$etag" "$FILE"
|
|
done
|
|
|
|
# Remove any files that were previously downloaded that are no longer needed.
|
|
FIND_ARGS=()
|
|
for FILE in "${KEEP[@]}"; do
|
|
FIND_ARGS+=("!" "-name" "$FILE")
|
|
done
|
|
find "$OUTPUT_DIR" -type f "${FIND_ARGS[@]}" -exec rm {} +
|