tools/testing/selftests/signal/sas.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/signal/sas.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/signal/sas.c- Extension
.c- Size
- 4839 bytes
- Lines
- 198
- 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
signal.hstdio.hstdlib.hsys/mman.hucontext.halloca.hstring.hassert.herrno.hsys/auxv.hkselftest.hcurrent_stack_pointer.h
Detected Declarations
struct stk_datafunction my_usr1function my_usr2function switch_fnfunction main
Annotated Snippet
struct stk_data {
char msg[128];
int flag;
};
void my_usr1(int sig, siginfo_t *si, void *u)
{
char *aa;
int err;
stack_t stk;
struct stk_data *p;
if (sp < (unsigned long)sstack ||
sp >= (unsigned long)sstack + stack_size) {
ksft_exit_fail_msg("SP is not on sigaltstack\n");
}
/* put some data on stack. other sighandler will try to overwrite it */
aa = alloca(1024);
assert(aa);
p = (struct stk_data *)(aa + 512);
strcpy(p->msg, msg);
p->flag = 1;
ksft_print_msg("[RUN]\tsignal USR1\n");
err = sigaltstack(NULL, &stk);
if (err) {
ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (stk.ss_flags != SS_DISABLE)
ksft_test_result_fail("tss_flags=%x, should be SS_DISABLE\n",
stk.ss_flags);
else
ksft_test_result_pass(
"sigaltstack is disabled in sighandler\n");
swapcontext(&sc, &uc);
ksft_print_msg("%s\n", p->msg);
if (!p->flag) {
ksft_exit_fail_msg("[RUN]\tAborting\n");
exit(EXIT_FAILURE);
}
}
void my_usr2(int sig, siginfo_t *si, void *u)
{
char *aa;
struct stk_data *p;
ksft_print_msg("[RUN]\tsignal USR2\n");
aa = alloca(1024);
/* dont run valgrind on this */
/* try to find the data stored by previous sighandler */
p = memmem(aa, 1024, msg, strlen(msg));
if (p) {
ksft_test_result_fail("sigaltstack re-used\n");
/* corrupt the data */
strcpy(p->msg, msg2);
/* tell other sighandler that his data is corrupted */
p->flag = 0;
}
}
static void switch_fn(void)
{
ksft_print_msg("[RUN]\tswitched to user ctx\n");
raise(SIGUSR2);
setcontext(&sc);
}
int main(void)
{
struct sigaction act;
stack_t stk;
int err;
/* Make sure more than the required minimum. */
stack_size = getauxval(AT_MINSIGSTKSZ) + SIGSTKSZ;
ksft_print_msg("[NOTE]\tthe stack size is %u\n", stack_size);
ksft_print_header();
ksft_set_plan(3);
sigemptyset(&act.sa_mask);
act.sa_flags = SA_ONSTACK | SA_SIGINFO;
act.sa_sigaction = my_usr1;
sigaction(SIGUSR1, &act, NULL);
act.sa_sigaction = my_usr2;
sigaction(SIGUSR2, &act, NULL);
sstack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
if (sstack == MAP_FAILED) {
Annotation
- Immediate include surface: `signal.h`, `stdio.h`, `stdlib.h`, `sys/mman.h`, `ucontext.h`, `alloca.h`, `string.h`, `assert.h`.
- Detected declarations: `struct stk_data`, `function my_usr1`, `function my_usr2`, `function switch_fn`, `function main`.
- 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.