(root)/
strace-6.5/
tests/
prctl-pac-reset-keys.c
       1  /*
       2   * Check decoding of prctl PR_PAC_RESET_KEYS operation.
       3   *
       4   * Copyright (c) 2021 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include "scno.h"
      12  #include <stdio.h>
      13  #include <unistd.h>
      14  #include <linux/prctl.h>
      15  #include <linux/capability.h>
      16  
      17  int
      18  main(void)
      19  {
      20  	long rc;
      21  
      22  	prctl_marker();
      23  
      24  	rc = syscall(__NR_prctl, PR_PAC_RESET_KEYS, 0x20, 0, 0, 0);
      25  	if (rc >= 0) {
      26  		error_msg_and_fail("prctl(PR_PAC_RESET_KEYS, 0x20) unexpected "
      27  				   "success");
      28  	}
      29  	printf("prctl(PR_PAC_RESET_KEYS, 0x20 /* PR_PAC_??? */, 0, 0, 0)"
      30  	       " = %s\n", sprintrc(rc));
      31  
      32  	static const struct {
      33  		kernel_ulong_t val;
      34  		const char *str;
      35  	} arg2[] = {
      36  		{ ARG_STR(0) },
      37  		{ ARG_STR(PR_PAC_APIAKEY) },
      38  		{ ARG_STR(PR_PAC_APIBKEY|PR_PAC_APDAKEY|PR_PAC_APDBKEY|PR_PAC_APGAKEY|0xcae0) },
      39  #if SIZEOF_KERNEL_LONG_T == 8
      40  		{ ARG_ULL_STR(0xbadc0deddadface0) " /* PR_PAC_??? */" }
      41  #else
      42  		{ ARG_STR(0xbadface0) " /* PR_PAC_??? */" },
      43  #endif
      44  	};
      45  
      46  	for (size_t i = 0; i < ARRAY_SIZE(arg2); i++) {
      47  		rc = syscall(__NR_prctl, PR_PAC_RESET_KEYS, arg2[i].val,
      48  			     1, 2, 3);
      49  		printf("prctl(PR_PAC_RESET_KEYS, %s, 0x1, 0x2, 0x3) = %s\n",
      50  		       arg2[i].str, sprintrc(rc));
      51  	}
      52  
      53  	puts("+++ exited with 0 +++");
      54  	return 0;
      55  }