kern_xxx.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* $OpenBSD: kern_xxx.c,v 1.28 2015/03/14 03:38:50 jsg Exp $ */
  2. /* $NetBSD: kern_xxx.c,v 1.32 1996/04/22 01:38:41 christos Exp $ */
  3. /*
  4. * Copyright (c) 1982, 1986, 1989, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93
  32. */
  33. #include <sys/param.h>
  34. #include <sys/systm.h>
  35. #include <sys/kernel.h>
  36. #include <sys/reboot.h>
  37. #include <sys/sysctl.h>
  38. #include <sys/mount.h>
  39. #include <sys/syscallargs.h>
  40. /* ARGSUSED */
  41. int
  42. sys_reboot(struct proc *p, void *v, register_t *retval)
  43. {
  44. struct sys_reboot_args /* {
  45. syscallarg(int) opt;
  46. } */ *uap = v;
  47. int error;
  48. if ((error = suser(p, 0)) != 0)
  49. return (error);
  50. #ifdef MULTIPROCESSOR
  51. sched_stop_secondary_cpus();
  52. KASSERT(CPU_IS_PRIMARY(curcpu()));
  53. #endif
  54. reboot(SCARG(uap, opt));
  55. /* NOTREACHED */
  56. return (0);
  57. }
  58. __dead void
  59. reboot(int howto)
  60. {
  61. KASSERT((howto & RB_NOSYNC) || curproc != NULL);
  62. boot(howto);
  63. /* NOTREACHED */
  64. }
  65. #if !defined(NO_PROPOLICE)
  66. void __stack_smash_handler(char [], int __attribute__((unused)));
  67. void
  68. __stack_smash_handler(char func[], int damaged)
  69. {
  70. panic("smashed stack in %s", func);
  71. }
  72. #endif
  73. #ifdef SYSCALL_DEBUG
  74. #define SCDEBUG_CALLS 0x0001 /* show calls */
  75. #define SCDEBUG_RETURNS 0x0002 /* show returns */
  76. #define SCDEBUG_ALL 0x0004 /* even syscalls that are implemented */
  77. #define SCDEBUG_SHOWARGS 0x0008 /* show arguments to calls */
  78. int scdebug = SCDEBUG_CALLS|SCDEBUG_RETURNS|SCDEBUG_SHOWARGS;
  79. void
  80. scdebug_call(struct proc *p, register_t code, const register_t args[])
  81. {
  82. struct sysent *sy;
  83. struct emul *em;
  84. int i;
  85. if (!(scdebug & SCDEBUG_CALLS))
  86. return;
  87. em = p->p_p->ps_emul;
  88. sy = &em->e_sysent[code];
  89. if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= em->e_nsysent ||
  90. sy->sy_call == sys_nosys))
  91. return;
  92. printf("proc %d (%s): %s num ", p->p_pid, p->p_comm, em->e_name);
  93. if (code < 0 || code >= em->e_nsysent)
  94. printf("OUT OF RANGE (%d)", code);
  95. else {
  96. printf("%d call: %s", code, em->e_syscallnames[code]);
  97. if (scdebug & SCDEBUG_SHOWARGS) {
  98. printf("(");
  99. for (i = 0; i < sy->sy_argsize / sizeof(register_t);
  100. i++)
  101. printf("%s0x%lx", i == 0 ? "" : ", ",
  102. (long)args[i]);
  103. printf(")");
  104. }
  105. }
  106. printf("\n");
  107. }
  108. void
  109. scdebug_ret(struct proc *p, register_t code, int error,
  110. const register_t retval[])
  111. {
  112. struct sysent *sy;
  113. struct emul *em;
  114. if (!(scdebug & SCDEBUG_RETURNS))
  115. return;
  116. em = p->p_p->ps_emul;
  117. sy = &em->e_sysent[code];
  118. if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= em->e_nsysent ||
  119. sy->sy_call == sys_nosys))
  120. return;
  121. printf("proc %d (%s): %s num ", p->p_pid, p->p_comm, em->e_name);
  122. if (code < 0 || code >= em->e_nsysent)
  123. printf("OUT OF RANGE (%d)", code);
  124. else
  125. printf("%d ret: err = %d, rv = 0x%lx,0x%lx", code,
  126. error, (long)retval[0], (long)retval[1]);
  127. printf("\n");
  128. }
  129. #endif /* SYSCALL_DEBUG */