Print this page
11530 badseg test creates cores

Split Close
Expand all
Collapse all
          --- old/usr/src/test/os-tests/tests/i386/badseg.c
          +++ new/usr/src/test/os-tests/tests/i386/badseg_exec.c
↓ open down ↓ 2 lines elided ↑ open up ↑
   3    3   * Common Development and Distribution License ("CDDL"), version 1.0.
   4    4   * You may only use this file in accordance with the terms of version
   5    5   * 1.0 of the CDDL.
   6    6   *
   7    7   * A full copy of the text of the CDDL should have accompanied this
   8    8   * source.  A copy of the CDDL is also available via the Internet at
   9    9   * http://www.illumos.org/license/CDDL.
  10   10   */
  11   11  
  12   12  /*
  13      - * Copyright 2018 Joyent, Inc.
       13 + * Copyright 2019 Joyent, Inc.
  14   14   */
  15   15  
  16   16  #include <stdlib.h>
  17   17  #include <ucontext.h>
  18   18  #include <sys/wait.h>
  19   19  #include <unistd.h>
  20   20  #include <sys/regset.h>
       21 +#include <sys/resource.h>
       22 +#include <err.h>
  21   23  
  22   24  /*
  23   25   * Load a bunch of bad selectors into the seg regs: this will typically cause
  24   26   * the child process to core dump, but it shouldn't panic the kernel...
  25   27   *
  26   28   * It's especially interesting to run this on CPU0.
  27   29   */
  28   30  
  29   31  unsigned short selector;
  30   32  
↓ open down ↓ 79 lines elided ↑ open up ↑
 110  112  }
 111  113  
 112  114  static void
 113  115  inchild(void (*func)())
 114  116  {
 115  117          pid_t pid;
 116  118  
 117  119          switch ((pid = fork())) {
 118  120          case 0:
 119  121                  func();
 120      -                exit(0);
      122 +                exit(EXIT_SUCCESS);
 121  123          case -1:
 122      -                exit(1);
      124 +                exit(EXIT_FAILURE);
 123  125          default:
 124  126                  (void) waitpid(pid, NULL, 0);
 125  127                  return;
 126  128          }
 127  129  
 128  130  }
 129  131  
 130  132  int
 131  133  main(int argc, char *argv[])
 132  134  {
      135 +        struct rlimit rl = { 0, };
      136 +
      137 +        if (setrlimit(RLIMIT_CORE, &rl) != 0) {
      138 +                err(EXIT_FAILURE, "failed to disable cores");
      139 +        }
      140 +
 133  141          for (selector = 0; selector < 8194; selector++) {
 134  142                  inchild(resetcs);
 135  143                  inchild(resetds);
 136  144                  inchild(resetes);
 137  145                  inchild(resetfs);
 138  146                  inchild(resetgs);
 139  147                  inchild(resetss);
 140  148                  inchild(badds);
 141  149                  inchild(bades);
 142  150                  inchild(badfs);
 143  151                  inchild(badgs);
 144  152                  inchild(badss);
 145  153          }
 146  154  
 147      -        exit(0);
      155 +        exit(EXIT_SUCCESS);
 148  156  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX