(root)/
strace-6.5/
tests/
prctl-no-args.c
       1  /*
       2   * Check decoding of prctl operations without arguments and return code parsing:
       3   * PR_GET_KEEPCAPS, PR_GET_SECCOMP, PR_GET_TIMERSLACK, PR_GET_TIMING,
       4   * PR_TASK_PERF_EVENTS_DISABLE, PR_TASK_PERF_EVENTS_ENABLE, and
       5   * PR_GET_TAGGED_ADDR_CTRL.
       6   *
       7   * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
       8   * Copyright (c) 2016-2021 The strace developers.
       9   * All rights reserved.
      10   *
      11   * SPDX-License-Identifier: GPL-2.0-or-later
      12   */
      13  
      14  #include "tests.h"
      15  #include "scno.h"
      16  
      17  #include <stdio.h>
      18  #include <unistd.h>
      19  #include <linux/prctl.h>
      20  
      21  int
      22  main(void)
      23  {
      24  	static const kernel_ulong_t bogus_op_bits =
      25  		(kernel_ulong_t) 0xbadc0ded00000000ULL;
      26  	static const kernel_ulong_t bogus_arg =
      27  		(kernel_ulong_t) 0xfacefeeddeadbeefULL;
      28  	static const struct {
      29  		kernel_ulong_t val;
      30  		const char *str;
      31  	} options[] = {
      32  		{  7, "PR_GET_KEEPCAPS" },
      33  		{ 13, "PR_GET_TIMING" },
      34  		{ 21, "PR_GET_SECCOMP" },
      35  		{ 30, "PR_GET_TIMERSLACK" },
      36  		{ 31, "PR_TASK_PERF_EVENTS_DISABLE" },
      37  		{ 32, "PR_TASK_PERF_EVENTS_ENABLE" },
      38  	};
      39  
      40  	TAIL_ALLOC_OBJECT_CONST_PTR(unsigned int, ptr);
      41  
      42  	prctl_marker();
      43  
      44  	for (unsigned int i = 0; i < ARRAY_SIZE(options); i++) {
      45  		long rc = syscall(__NR_prctl, options[i].val | bogus_op_bits,
      46  				  bogus_arg);
      47  		printf("prctl(%s) = %s\n", options[i].str, sprintrc(rc));
      48  	}
      49  
      50  	puts("+++ exited with 0 +++");
      51  	return 0;
      52  }