(root)/
strace-6.5/
tests-mx32/
kernel_version.c
       1  /*
       2   * Check kernel version decoding.
       3   *
       4   * Copyright (c) 2015-2023 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  #include <stddef.h>
      13  #include <stdio.h>
      14  #include <stdint.h>
      15  #include <string.h>
      16  #include <unistd.h>
      17  
      18  #include "scno.h"
      19  
      20  #ifdef HAVE_LINUX_BPF_H
      21  # include <linux/bpf.h>
      22  #endif
      23  
      24  #include "bpf_attr.h"
      25  #include "print_fields.h"
      26  
      27  #include "xlat.h"
      28  #include "xlat/bpf_commands.h"
      29  
      30  #define CMD_STR(x) #x
      31  static const char *errstr;
      32  
      33  static void
      34  print_bpf_attr(void)
      35  {
      36  #if XLAT_RAW
      37  	printf("{prog_type=0x21"
      38  #else
      39  	printf("{prog_type=0x21 /* BPF_PROG_TYPE_??? */"
      40  #endif
      41  		", insn_cnt=3134983661"
      42  		", insns=NULL"
      43  		", license=NULL"
      44  		", log_level=24"
      45  		", log_size=3141592653"
      46  		", log_buf=NULL"
      47  #if XLAT_RAW
      48  		", kern_version=0xcafef00d"
      49  #elif XLAT_VERBOSE
      50  		", kern_version=0xcafef00d"
      51  		" /* KERNEL_VERSION(51966, 240, 13) */"
      52  #else
      53  		", kern_version=KERNEL_VERSION(51966, 240, 13)"
      54  #endif
      55  		", prog_flags=0"
      56  		", prog_name=\"\""
      57  		", prog_ifindex=0"
      58  		", expected_attach_type="
      59  #if XLAT_RAW
      60  		"0"
      61  #elif XLAT_VERBOSE
      62  		"0 /* BPF_CGROUP_INET_INGRESS */"
      63  #else /* XLAT_ABBREV */
      64  		"BPF_CGROUP_INET_INGRESS"
      65  #endif
      66  		", prog_btf_fd=0"
      67  		", func_info_rec_size=0"
      68  		", func_info=NULL"
      69  		", func_info_cnt=0"
      70  		", line_info_rec_size=0"
      71  		", line_info=NULL"
      72  		", line_info_cnt=0"
      73  		", attach_btf_id=0"
      74  		", attach_prog_fd=0"
      75  		", fd_array=NULL}");
      76  }
      77  
      78  int
      79  main(void)
      80  {
      81  	long ret;
      82  	struct BPF_PROG_LOAD_struct prog = {
      83  		.prog_type = 33,
      84  		.insn_cnt = 0xbadc0ded,
      85  		.insns = 0,
      86  		.license = 0,
      87  		.log_level = 24,
      88  		.log_size = 3141592653U,
      89  		.log_buf = 0,
      90  		.kern_version = 0xcafef00d,
      91  		.prog_flags = 0,
      92  	};
      93  	ret = syscall(__NR_bpf, BPF_PROG_LOAD, &prog, sizeof(prog));
      94  	errstr = sprintrc(ret);
      95  #if XLAT_RAW
      96  	printf("bpf(%#x, ", BPF_PROG_LOAD);
      97  #elif XLAT_VERBOSE
      98  	printf("bpf(%#x /* %s */, ", BPF_PROG_LOAD, CMD_STR(BPF_PROG_LOAD));
      99  #else
     100  	printf("bpf(%s, ", CMD_STR(BPF_PROG_LOAD));
     101  #endif
     102  	print_bpf_attr();
     103  	printf(", %u) = %s\n", (unsigned int) sizeof(prog), errstr);
     104  	puts("+++ exited with 0 +++");
     105  	return 0;
     106  }