(root)/
strace-6.5/
tests-mx32/
setns.c
       1  /*
       2   * Check decoding of setns syscall.
       3   *
       4   * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
       5   * Copyright (c) 2016-2022 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  #include <stdio.h>
      15  #include <unistd.h>
      16  
      17  static const char *errstr;
      18  
      19  static long
      20  k_setns(const int fd, const unsigned int flags)
      21  {
      22  	const kernel_ulong_t fill = (kernel_ulong_t) 0x0defaced00000000ULL;
      23  	const kernel_ulong_t bad  = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
      24  	const kernel_ulong_t arg1 = fill | (unsigned int) fd;
      25  	const kernel_ulong_t arg2 = fill | flags;
      26  	const long rc = syscall(__NR_setns,
      27  				arg1, arg2, bad, bad, bad, bad);
      28  	errstr = sprintrc(rc);
      29  	return rc;
      30  }
      31  
      32  int
      33  main(void)
      34  {
      35  	static const int bogus_fd = 0xdeadc0de;
      36  
      37  	static struct {
      38  		unsigned int val;
      39  		const char *str;
      40  	} nstypes[] = {
      41  		{ 0, "0" },
      42  		{ 0x00000080U, "CLONE_NEWTIME" },
      43  		{ 0x00020000U, "CLONE_NEWNS" },
      44  		{ 0x02000000U, "CLONE_NEWCGROUP" },
      45  		{ 0x04000000U, "CLONE_NEWUTS" },
      46  		{ 0x08000000U, "CLONE_NEWIPC" },
      47  		{ 0x10000000U, "CLONE_NEWUSER" },
      48  		{ 0x20000000U, "CLONE_NEWPID" },
      49  		{ 0x40000000U, "CLONE_NEWNET" },
      50  		{ 0x81fdff7fU, "0x81fdff7f /* CLONE_NEW??? */" },
      51  		{ -1U,
      52  		  "CLONE_NEWTIME|CLONE_NEWNS|CLONE_NEWCGROUP|CLONE_NEWUTS|"
      53  		  "CLONE_NEWIPC|CLONE_NEWUSER|CLONE_NEWPID|CLONE_NEWNET|"
      54  		  "0x81fdff7f" },
      55  	};
      56  
      57  	for (unsigned int i = 0; i < ARRAY_SIZE(nstypes); ++i) {
      58  		k_setns(bogus_fd, nstypes[i].val);
      59  		printf("setns(%d, %s) = %s\n",
      60  		       bogus_fd, nstypes[i].str, errstr);
      61  	}
      62  
      63  	puts("+++ exited with 0 +++");
      64  
      65  	return 0;
      66  }