(root)/
strace-6.5/
tests/
delete_module.c
       1  /*
       2   * Check decoding of delete_module syscall.
       3   *
       4   * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
       5   * Copyright (c) 2016-2021 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  #include "scno.h"
      13  
      14  #if defined(__NR_delete_module)
      15  
      16  # include <stdio.h>
      17  # include <unistd.h>
      18  
      19  # include "kernel_fcntl.h"
      20  # include "init_delete_module.h"
      21  
      22  int
      23  main(void)
      24  {
      25  	static const struct {
      26  		kernel_ulong_t val;
      27  		const char *str;
      28  		unsigned int val_prefix, val_suffix;
      29  	} flags[] = {
      30  		{ ARG_STR(0), 0, 0 },
      31  		{ F8ILL_KULONG_MASK | O_NONBLOCK, "O_NONBLOCK", 0, 0 },
      32  		{ (kernel_ulong_t) 0xbadc0dedfacef157ULL & ~(O_NONBLOCK | O_TRUNC),
      33  			" /* O_??? */", 0xfacef157U & ~(O_NONBLOCK | O_TRUNC), 0},
      34  		{ (kernel_ulong_t) (0xfacef157deade71cULL & ~O_NONBLOCK) | O_TRUNC,
      35  			"O_TRUNC", 0, 0xdeade71c & ~(O_NONBLOCK | O_TRUNC)},
      36  		{ -1LL, "O_NONBLOCK|O_TRUNC", 0, -1U & ~(O_NONBLOCK | O_TRUNC)},
      37  	};
      38  
      39  	long rc;
      40  	char *bogus_param1 = tail_alloc(PARAM1_LEN);
      41  	char *bogus_param2 = tail_alloc(PARAM2_LEN);
      42  	const char *errstr;
      43  
      44  	fill_memory_ex(bogus_param1, PARAM1_LEN, PARAM1_BASE, PARAM1_LEN);
      45  	fill_memory_ex(bogus_param2, PARAM2_LEN, PARAM2_BASE, PARAM2_LEN);
      46  
      47  	rc = syscall(__NR_delete_module, NULL, F8ILL_KULONG_MASK);
      48  	printf("delete_module(NULL, 0) = %s\n", sprintrc(rc));
      49  
      50  	rc = syscall(__NR_delete_module, bogus_param1, flags[0].val);
      51  	errstr = sprintrc(rc);
      52  
      53  	printf("delete_module(\"");
      54  	print_str(PARAM1_BASE, MAX_STRLEN, false);
      55  	printf("\"..., %s) = %s\n", flags[0].str, errstr);
      56  
      57  	bogus_param1[PARAM1_LEN - 1] = '\0';
      58  
      59  	rc = syscall(__NR_delete_module, bogus_param1, flags[1].val);
      60  	errstr = sprintrc(rc);
      61  
      62  	printf("delete_module(\"");
      63  	print_str(PARAM1_BASE, MAX_STRLEN, false);
      64  	printf("\", %s) = %s\n", flags[1].str, errstr);
      65  
      66  	rc = syscall(__NR_delete_module, bogus_param2 + PARAM2_LEN,
      67  		flags[2].val);
      68  	printf("delete_module(%p, %#x%s) = %s\n",
      69  	       bogus_param2 + PARAM2_LEN, flags[2].val_prefix,
      70  	       flags[2].str, sprintrc(rc));
      71  
      72  	rc = syscall(__NR_delete_module, bogus_param2, flags[3].val);
      73  	printf("delete_module(%p, %s|%#x) = %s\n",
      74  	       bogus_param2, flags[3].str, flags[3].val_suffix, sprintrc(rc));
      75  
      76  	bogus_param2[PARAM2_LEN - 1] = '\0';
      77  
      78  	rc = syscall(__NR_delete_module, bogus_param2, flags[4].val);
      79  	errstr = sprintrc(rc);
      80  
      81  	printf("delete_module(\"");
      82  	print_str(PARAM2_BASE, PARAM2_LEN - 1, true);
      83  	printf("\", %s|%#x) = %s\n", flags[4].str, flags[4].val_suffix, errstr);
      84  
      85  	puts("+++ exited with 0 +++");
      86  
      87  	return 0;
      88  }
      89  
      90  #else
      91  
      92  SKIP_MAIN_UNDEFINED("__NR_delete_module");
      93  
      94  #endif