(root)/
strace-6.5/
tests-mx32/
kern_features.c
       1  /*
       2   * Check decoding of SPARC-specific kern_features syscall.
       3   *
       4   * Copyright (c) 2018-2019 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  
      12  
      13  #include "raw_syscall.h"
      14  #include "scno.h"
      15  
      16  #if defined __NR_kern_features && defined raw_syscall_0
      17  
      18  # include <errno.h>
      19  # include <stdio.h>
      20  # include <stdlib.h>
      21  # include <unistd.h>
      22  
      23  static void
      24  test_kern_features(unsigned int num)
      25  {
      26  	/* The expected return codes, as enforced by fault injection */
      27  	static struct {
      28  		kernel_ulong_t ret;
      29  		const char *str;
      30  	} checks[] = {
      31  		{ 0, NULL },
      32  		{ 1, "KERN_FEATURE_MIXED_MODE_STACK" },
      33  		{ 2, "0x2" },
      34  		{ 0x7ffffffe, "0x7ffffffe" },
      35  		{ 0x7fffffff, "KERN_FEATURE_MIXED_MODE_STACK|0x7ffffffe" },
      36  		{ (kernel_ulong_t) 0xbadc0deddeadfaceULL,
      37  			sizeof(kernel_ulong_t) == 8 ?
      38  			"0xbadc0deddeadface" : "0xdeadface" },
      39  		{ (kernel_ulong_t) -1ULL,
      40  			sizeof(kernel_ulong_t) == 8 ?
      41  			"KERN_FEATURE_MIXED_MODE_STACK|0xfffffffffffffffe" :
      42  			"KERN_FEATURE_MIXED_MODE_STACK|0xfffffffe" },
      43  	};
      44  
      45  	kernel_ulong_t err = 0;
      46  	kernel_ulong_t rc = raw_syscall_0(__NR_kern_features, &err);
      47  
      48  	if (err) {
      49  		errno = rc;
      50  		printf("kern_features() = %s\n", sprintrc(-1));
      51  		return;
      52  	}
      53  
      54  	printf("kern_features() = %#llx", (unsigned long long) rc);
      55  
      56  	if (num < ARRAY_SIZE(checks)) {
      57  		if (rc != checks[num].ret)
      58  			error_msg_and_fail("Expected return value (%llx) "
      59  					   "doesn't match expected one (%#llx)",
      60  					   (unsigned long long) rc,
      61  					   (unsigned long long) checks[num].ret);
      62  
      63  		if (checks[num].str)
      64  			printf(" (%s)", checks[num].str);
      65  
      66  		printf(" (INJECTED)");
      67  	} else if (rc) {
      68  		printf(" (");
      69  
      70  		if (rc & 1)
      71  			printf("KERN_FEATURE_MIXED_MODE_STACK");
      72  
      73  		if (rc & ~1ULL) {
      74  			if (rc & 1)
      75  				printf("|");
      76  
      77  			printf("%#llx", rc & ~1ULL);
      78  		}
      79  
      80  		printf(")");
      81  	}
      82  
      83  	puts("");
      84  }
      85  
      86  int
      87  main(int ac, char **av)
      88  {
      89  	test_kern_features(ac > 1 ? atoi(av[1]) : -1);
      90  
      91  	puts("+++ exited with 0 +++");
      92  	return 0;
      93  }
      94  
      95  #else
      96  
      97  SKIP_MAIN_UNDEFINED("__NR_kern_features && raw_syscall_0");
      98  
      99  #endif