tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/breakpoints/breakpoint_test_arm64.c- Extension
.c- Size
- 5556 bytes
- Lines
- 251
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/ptrace.hsys/types.hsys/wait.hsys/ptrace.hsys/param.hsys/uio.hstdint.hstdbool.hstddef.hstring.hstdio.hunistd.helf.herrno.hsignal.hkselftest.h
Detected Declarations
function childfunction set_watchpointfunction run_testfunction sigalrm
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2016 Google, Inc.
*
* Original Code by Pavel Labath <labath@google.com>
*
* Code modified by Pratyush Anand <panand@redhat.com>
* for testing different byte select for each access size.
*/
#define _GNU_SOURCE
#include <asm/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <elf.h>
#include <errno.h>
#include <signal.h>
#include "kselftest.h"
static volatile uint8_t var[96] __attribute__((__aligned__(32)));
static void child(int size, int wr)
{
volatile uint8_t *addr = &var[32 + wr];
if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) {
ksft_print_msg(
"ptrace(PTRACE_TRACEME) failed: %s\n",
strerror(errno));
_exit(1);
}
if (raise(SIGSTOP) != 0) {
ksft_print_msg(
"raise(SIGSTOP) failed: %s\n", strerror(errno));
_exit(1);
}
if ((uintptr_t) addr % size) {
ksft_print_msg(
"Wrong address write for the given size: %s\n",
strerror(errno));
_exit(1);
}
switch (size) {
case 1:
*addr = 47;
break;
case 2:
*(uint16_t *)addr = 47;
break;
case 4:
*(uint32_t *)addr = 47;
break;
case 8:
*(uint64_t *)addr = 47;
break;
case 16:
__asm__ volatile ("stp x29, x30, %0" : "=m" (addr[0]));
break;
case 32:
__asm__ volatile ("stp q29, q30, %0" : "=m" (addr[0]));
break;
}
_exit(0);
}
static bool set_watchpoint(pid_t pid, int size, int wp)
{
const volatile uint8_t *addr = &var[32 + wp];
const int offset = (uintptr_t)addr % 8;
const unsigned int byte_mask = ((1 << size) - 1) << offset;
const unsigned int type = 2; /* Write */
const unsigned int enable = 1;
const unsigned int control = byte_mask << 5 | type << 3 | enable;
struct user_hwdebug_state dreg_state;
struct iovec iov;
Annotation
- Immediate include surface: `asm/ptrace.h`, `sys/types.h`, `sys/wait.h`, `sys/ptrace.h`, `sys/param.h`, `sys/uio.h`, `stdint.h`, `stdbool.h`.
- Detected declarations: `function child`, `function set_watchpoint`, `function run_test`, `function sigalrm`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.