jcs's openbsd hax
openbsd
at jcs 105 lines 3.4 kB view raw
1/* $OpenBSD: db_usrreq.c,v 1.23 2025/05/19 21:48:28 kettenis Exp $ */ 2 3/* 4 * Copyright (c) 1996 Michael Shalayeff. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/param.h> 28#include <sys/systm.h> 29#include <sys/proc.h> 30#include <sys/tty.h> 31#include <sys/sysctl.h> 32#include <dev/cons.h> 33 34#include <ddb/db_var.h> 35 36int db_log = 1; 37int db_profile; /* Allow dynamic profiling */ 38int db_suspend; 39 40const struct sysctl_bounded_args ddb_vars[] = { 41 { DBCTL_RADIX, &db_radix, 8, 16 }, 42 { DBCTL_MAXWIDTH, &db_max_width, 0, INT_MAX }, 43 { DBCTL_TABSTOP, &db_tab_stop_width, 1, 16 }, 44 { DBCTL_MAXLINE, &db_max_line, 0, INT_MAX }, 45 { DBCTL_LOG, &db_log, 0, 1 }, 46 { DBCTL_SUSPEND, &db_suspend, 0, 1 }, 47}; 48 49int 50ddb_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, 51 size_t newlen, struct proc *p) 52{ 53 /* All sysctl names at this level are terminal. */ 54 if (namelen != 1) 55 return (ENOTDIR); 56 57 switch (name[0]) { 58 case DBCTL_PANIC: 59 if (securelevel > 0) 60 return (sysctl_int_lower(oldp, oldlenp, newp, newlen, 61 &db_panic)); 62 else { 63 return (sysctl_int_bounded(oldp, oldlenp, newp, newlen, 64 &db_panic, 0, 1)); 65 } 66 break; 67 case DBCTL_CONSOLE: 68 if (securelevel > 0) 69 return (sysctl_int_lower(oldp, oldlenp, newp, newlen, 70 &db_console)); 71 else { 72 return (sysctl_int_bounded(oldp, oldlenp, newp, newlen, 73 &db_console, 0, 1)); 74 } 75 break; 76 case DBCTL_TRIGGER: 77 if (newp && db_console) { 78 struct process *pr = curproc->p_p; 79 80 if (securelevel < 1 || 81 (pr->ps_flags & PS_CONTROLT && cn_tab && 82 cn_tab->cn_dev == pr->ps_session->s_ttyp->t_dev)) { 83 db_enter(); 84 newp = NULL; 85 } else 86 return (ENODEV); 87 } 88 return (sysctl_rdint(oldp, oldlenp, newp, 0)); 89#if defined(DDBPROF) 90 case DBCTL_PROFILE: 91 if (securelevel > 0) 92 return (sysctl_int_lower(oldp, oldlenp, newp, newlen, 93 &db_profile)); 94 else { 95 return (sysctl_int_bounded(oldp, oldlenp, newp, newlen, 96 &db_profile, 0, 1)); 97 } 98 break; 99#endif /* DDBPROF */ 100 default: 101 return (sysctl_bounded_arr(ddb_vars, nitems(ddb_vars), name, 102 namelen, oldp, oldlenp, newp, newlen)); 103 } 104 /* NOTREACHED */ 105}