17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*19397407SSherry Moore * Common Development and Distribution License (the "License"). 6*19397407SSherry Moore * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*19397407SSherry Moore * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * Sysevent Driver for GPEC 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/param.h> 337c478bd9Sstevel@tonic-gate #include <sys/cred.h> 347c478bd9Sstevel@tonic-gate #include <sys/file.h> 357c478bd9Sstevel@tonic-gate #include <sys/stat.h> 367c478bd9Sstevel@tonic-gate #include <sys/conf.h> 377c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 387c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 397c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 407c478bd9Sstevel@tonic-gate #include <sys/open.h> /* OTYP_CHR definition */ 417c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> /* L_BITSMINOR definition */ 427c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 437c478bd9Sstevel@tonic-gate #include <sys/sysevent.h> 447c478bd9Sstevel@tonic-gate #include <sys/sysevent_impl.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate static dev_info_t *sysevent_devi; 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* Definitions for binding handle array */ 497c478bd9Sstevel@tonic-gate static ulong_t sysevent_bitmap_initial = 1; /* index 0 indicates error */ 507c478bd9Sstevel@tonic-gate static ulong_t *sysevent_minor_bitmap = &sysevent_bitmap_initial; 517c478bd9Sstevel@tonic-gate static size_t sysevent_minor_bits = BT_NBIPUL; 527c478bd9Sstevel@tonic-gate static kmutex_t sysevent_minor_mutex; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * evchan_ctl acts as a container for the binding handle 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate typedef struct evchan_ctl { 587c478bd9Sstevel@tonic-gate evchan_t *chp; 597c478bd9Sstevel@tonic-gate } evchan_ctl_t; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate static void *evchan_ctlp; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * Check if it's a null terminated array - to avoid DoS attack 657c478bd9Sstevel@tonic-gate * It is supposed that string points to an array with 667c478bd9Sstevel@tonic-gate * a minimum length of len. len must be strlen + 1. 677c478bd9Sstevel@tonic-gate * Checks for printable characters are already done in library. 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate static int 707c478bd9Sstevel@tonic-gate sysevent_isstrend(char *string, size_t len) 717c478bd9Sstevel@tonic-gate { 727c478bd9Sstevel@tonic-gate /* Return 0 if string has length of zero */ 737c478bd9Sstevel@tonic-gate if (len > 0) { 747c478bd9Sstevel@tonic-gate return (string[len - 1] == '\0' ? 1 : 0); 757c478bd9Sstevel@tonic-gate } else { 767c478bd9Sstevel@tonic-gate return (0); 777c478bd9Sstevel@tonic-gate } 787c478bd9Sstevel@tonic-gate } 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Following sysevent_minor_* routines map 827c478bd9Sstevel@tonic-gate * a binding handle (evchan_t *) to a minor number 837c478bd9Sstevel@tonic-gate * Has to be called w/ locks held. 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate static ulong_t * 867c478bd9Sstevel@tonic-gate sysevent_minor_alloc(void) 877c478bd9Sstevel@tonic-gate { 887c478bd9Sstevel@tonic-gate ulong_t *bhst = sysevent_minor_bitmap; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* Increase bitmap by one BT_NBIPUL */ 917c478bd9Sstevel@tonic-gate if (sysevent_minor_bits + BT_NBIPUL > SYSEVENT_MINOR_MAX) { 927c478bd9Sstevel@tonic-gate return ((ulong_t *)NULL); 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate sysevent_minor_bitmap = kmem_zalloc( 957c478bd9Sstevel@tonic-gate BT_SIZEOFMAP(sysevent_minor_bits + BT_NBIPUL), KM_SLEEP); 967c478bd9Sstevel@tonic-gate bcopy(bhst, sysevent_minor_bitmap, BT_SIZEOFMAP(sysevent_minor_bits)); 977c478bd9Sstevel@tonic-gate if (bhst != &sysevent_bitmap_initial) 987c478bd9Sstevel@tonic-gate kmem_free(bhst, BT_SIZEOFMAP(sysevent_minor_bits)); 997c478bd9Sstevel@tonic-gate sysevent_minor_bits += BT_NBIPUL; 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate return (sysevent_minor_bitmap); 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate static void 1057c478bd9Sstevel@tonic-gate sysevent_minor_free(ulong_t *bitmap) 1067c478bd9Sstevel@tonic-gate { 1077c478bd9Sstevel@tonic-gate if (bitmap != &sysevent_bitmap_initial) 1087c478bd9Sstevel@tonic-gate kmem_free(bitmap, BT_SIZEOFMAP(sysevent_minor_bits)); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate static index_t 1127c478bd9Sstevel@tonic-gate sysevent_minor_get(void) 1137c478bd9Sstevel@tonic-gate { 1147c478bd9Sstevel@tonic-gate index_t idx; 1157c478bd9Sstevel@tonic-gate ulong_t *bhst; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* Search for an available index */ 1187c478bd9Sstevel@tonic-gate mutex_enter(&sysevent_minor_mutex); 1197c478bd9Sstevel@tonic-gate if ((idx = bt_availbit(sysevent_minor_bitmap, 1207c478bd9Sstevel@tonic-gate sysevent_minor_bits)) == -1) { 1217c478bd9Sstevel@tonic-gate /* All busy - allocate additional binding handle bitmap space */ 1227c478bd9Sstevel@tonic-gate if ((bhst = sysevent_minor_alloc()) == NULL) { 1237c478bd9Sstevel@tonic-gate /* Reached our maximum of id's == SHRT_MAX */ 1247c478bd9Sstevel@tonic-gate mutex_exit(&sysevent_minor_mutex); 1257c478bd9Sstevel@tonic-gate return (0); 1267c478bd9Sstevel@tonic-gate } else { 1277c478bd9Sstevel@tonic-gate sysevent_minor_bitmap = bhst; 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate idx = bt_availbit(sysevent_minor_bitmap, sysevent_minor_bits); 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate BT_SET(sysevent_minor_bitmap, idx); 1327c478bd9Sstevel@tonic-gate mutex_exit(&sysevent_minor_mutex); 1337c478bd9Sstevel@tonic-gate return (idx); 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate static void 1377c478bd9Sstevel@tonic-gate sysevent_minor_rele(index_t idx) 1387c478bd9Sstevel@tonic-gate { 1397c478bd9Sstevel@tonic-gate mutex_enter(&sysevent_minor_mutex); 1407c478bd9Sstevel@tonic-gate ASSERT(BT_TEST(sysevent_minor_bitmap, idx) == 1); 1417c478bd9Sstevel@tonic-gate BT_CLEAR(sysevent_minor_bitmap, idx); 1427c478bd9Sstevel@tonic-gate mutex_exit(&sysevent_minor_mutex); 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate static void 1467c478bd9Sstevel@tonic-gate sysevent_minor_init(void) 1477c478bd9Sstevel@tonic-gate { 1487c478bd9Sstevel@tonic-gate mutex_init(&sysevent_minor_mutex, NULL, MUTEX_DEFAULT, NULL); 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1527c478bd9Sstevel@tonic-gate static int 1537c478bd9Sstevel@tonic-gate sysevent_publish(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 1547c478bd9Sstevel@tonic-gate { 1557c478bd9Sstevel@tonic-gate int km_flags; 1567c478bd9Sstevel@tonic-gate sev_publish_args_t uargs; 1577c478bd9Sstevel@tonic-gate sysevent_impl_t *ev; 1587c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 1617c478bd9Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL) 1627c478bd9Sstevel@tonic-gate return (ENXIO); 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_publish_args_t)) != 0) 1657c478bd9Sstevel@tonic-gate return (EFAULT); 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * This limits the size of an event 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate if (uargs.ev.len > MAX_EV_SIZE_LEN) 1717c478bd9Sstevel@tonic-gate return (EOVERFLOW); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate /* 1747c478bd9Sstevel@tonic-gate * Check for valid uargs.flags 1757c478bd9Sstevel@tonic-gate */ 1767c478bd9Sstevel@tonic-gate if (uargs.flags & ~(EVCH_NOSLEEP | EVCH_SLEEP | EVCH_QWAIT)) 1777c478bd9Sstevel@tonic-gate return (EINVAL); 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate * Check that at least one of EVCH_NOSLEEP or EVCH_SLEEP is 1817c478bd9Sstevel@tonic-gate * specified 1827c478bd9Sstevel@tonic-gate */ 1837c478bd9Sstevel@tonic-gate km_flags = uargs.flags & (EVCH_NOSLEEP | EVCH_SLEEP); 1847c478bd9Sstevel@tonic-gate if (km_flags != EVCH_NOSLEEP && km_flags != EVCH_SLEEP) 1857c478bd9Sstevel@tonic-gate return (EINVAL); 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate ev = evch_usrallocev(uargs.ev.len, uargs.flags); 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.ev.name, ev, uargs.ev.len) != 0) { 1907c478bd9Sstevel@tonic-gate evch_usrfreeev(ev); 1917c478bd9Sstevel@tonic-gate return (EFAULT); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate return (evch_usrpostevent(ctl->chp, ev, uargs.flags)); 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate /* Event will be freed internally */ 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * sysevent_chan_open - used to open a channel in the GPEC channel layer 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2047c478bd9Sstevel@tonic-gate static int 2057c478bd9Sstevel@tonic-gate sysevent_chan_open(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 2067c478bd9Sstevel@tonic-gate { 2077c478bd9Sstevel@tonic-gate sev_bind_args_t uargs; 2087c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 2097c478bd9Sstevel@tonic-gate char *chan_name; 2107c478bd9Sstevel@tonic-gate int ec; 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 2137c478bd9Sstevel@tonic-gate if (ctl == NULL) { 2147c478bd9Sstevel@tonic-gate return (ENXIO); 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_bind_args_t)) != 0) 2187c478bd9Sstevel@tonic-gate return (EFAULT); 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate if (uargs.chan_name.len > MAX_CHNAME_LEN) 2217c478bd9Sstevel@tonic-gate return (EINVAL); 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate chan_name = kmem_alloc(uargs.chan_name.len, KM_SLEEP); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.chan_name.name, chan_name, 2267c478bd9Sstevel@tonic-gate uargs.chan_name.len) != 0) { 2277c478bd9Sstevel@tonic-gate kmem_free(chan_name, uargs.chan_name.len); 2287c478bd9Sstevel@tonic-gate return (EFAULT); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate if (!sysevent_isstrend(chan_name, uargs.chan_name.len)) { 2327c478bd9Sstevel@tonic-gate kmem_free(chan_name, uargs.chan_name.len); 2337c478bd9Sstevel@tonic-gate return (EINVAL); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate /* 2377c478bd9Sstevel@tonic-gate * Check of uargs.flags and uargs.perms just to avoid DoS attacks. 2387c478bd9Sstevel@tonic-gate * libsysevent does this carefully 2397c478bd9Sstevel@tonic-gate */ 2407c478bd9Sstevel@tonic-gate ctl->chp = evch_usrchanopen((const char *)chan_name, 2417c478bd9Sstevel@tonic-gate uargs.flags & EVCH_B_FLAGS, &ec); 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate kmem_free(chan_name, uargs.chan_name.len); 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate if (ec != 0) { 2467c478bd9Sstevel@tonic-gate return (ec); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate return (0); 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2537c478bd9Sstevel@tonic-gate static int 2547c478bd9Sstevel@tonic-gate sysevent_chan_control(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 2557c478bd9Sstevel@tonic-gate { 2567c478bd9Sstevel@tonic-gate sev_control_args_t uargs; 2577c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 2587c478bd9Sstevel@tonic-gate int rc; 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 2617c478bd9Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL) 2627c478bd9Sstevel@tonic-gate return (ENXIO); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_control_args_t)) != 0) 2657c478bd9Sstevel@tonic-gate return (EFAULT); 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate switch (uargs.cmd) { 2687c478bd9Sstevel@tonic-gate case EVCH_GET_CHAN_LEN: 2697c478bd9Sstevel@tonic-gate case EVCH_GET_CHAN_LEN_MAX: 2707c478bd9Sstevel@tonic-gate rc = evch_usrcontrol_get(ctl->chp, uargs.cmd, &uargs.value); 2717c478bd9Sstevel@tonic-gate if (rc == 0) { 2727c478bd9Sstevel@tonic-gate if (copyout((void *)&uargs, arg, 2737c478bd9Sstevel@tonic-gate sizeof (sev_control_args_t)) != 0) { 2747c478bd9Sstevel@tonic-gate rc = EFAULT; 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate break; 2787c478bd9Sstevel@tonic-gate case EVCH_SET_CHAN_LEN: 2797c478bd9Sstevel@tonic-gate rc = evch_usrcontrol_set(ctl->chp, uargs.cmd, uargs.value); 2807c478bd9Sstevel@tonic-gate break; 2817c478bd9Sstevel@tonic-gate default: 2827c478bd9Sstevel@tonic-gate rc = EINVAL; 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate return (rc); 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2887c478bd9Sstevel@tonic-gate static int 2897c478bd9Sstevel@tonic-gate sysevent_subscribe(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 2907c478bd9Sstevel@tonic-gate { 2917c478bd9Sstevel@tonic-gate sev_subscribe_args_t uargs; 2927c478bd9Sstevel@tonic-gate char *sid; 2937c478bd9Sstevel@tonic-gate char *class_info = NULL; 2947c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 2957c478bd9Sstevel@tonic-gate int rc; 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 2987c478bd9Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL) 2997c478bd9Sstevel@tonic-gate return (ENXIO); 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_subscribe_args_t)) != 0) 3027c478bd9Sstevel@tonic-gate return (EFAULT); 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate if (uargs.sid.len > MAX_SUBID_LEN || 3057c478bd9Sstevel@tonic-gate uargs.class_info.len > MAX_CLASS_LEN) 3067c478bd9Sstevel@tonic-gate return (EINVAL); 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate sid = kmem_alloc(uargs.sid.len, KM_SLEEP); 3097c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.sid.name, 3107c478bd9Sstevel@tonic-gate sid, uargs.sid.len) != 0) { 3117c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 3127c478bd9Sstevel@tonic-gate return (EFAULT); 3137c478bd9Sstevel@tonic-gate } 3147c478bd9Sstevel@tonic-gate if (!sysevent_isstrend(sid, uargs.sid.len)) { 3157c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 3167c478bd9Sstevel@tonic-gate return (EINVAL); 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate /* If class string empty then class EC_ALL is assumed */ 3207c478bd9Sstevel@tonic-gate if (uargs.class_info.len != 0) { 3217c478bd9Sstevel@tonic-gate class_info = kmem_alloc(uargs.class_info.len, KM_SLEEP); 3227c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.class_info.name, class_info, 3237c478bd9Sstevel@tonic-gate uargs.class_info.len) != 0) { 3247c478bd9Sstevel@tonic-gate kmem_free(class_info, uargs.class_info.len); 3257c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 3267c478bd9Sstevel@tonic-gate return (EFAULT); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate if (!sysevent_isstrend(class_info, uargs.class_info.len)) { 3297c478bd9Sstevel@tonic-gate kmem_free(class_info, uargs.class_info.len); 3307c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 3317c478bd9Sstevel@tonic-gate return (EINVAL); 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate /* 3367c478bd9Sstevel@tonic-gate * Check of uargs.flags just to avoid DoS attacks 3377c478bd9Sstevel@tonic-gate * libsysevent does this carefully. 3387c478bd9Sstevel@tonic-gate */ 3397c478bd9Sstevel@tonic-gate rc = evch_usrsubscribe(ctl->chp, sid, class_info, 3407c478bd9Sstevel@tonic-gate (int)uargs.door_desc, uargs.flags); 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate kmem_free(class_info, uargs.class_info.len); 3437c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate return (rc); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate /* ARGSUSED */ 3497c478bd9Sstevel@tonic-gate static int 3507c478bd9Sstevel@tonic-gate sysevent_unsubscribe(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 3517c478bd9Sstevel@tonic-gate { 3527c478bd9Sstevel@tonic-gate sev_unsubscribe_args_t uargs; 3537c478bd9Sstevel@tonic-gate char *sid; 3547c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_unsubscribe_args_t)) != 0) 3577c478bd9Sstevel@tonic-gate return (EFAULT); 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 3607c478bd9Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL) 3617c478bd9Sstevel@tonic-gate return (ENXIO); 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate if (uargs.sid.len > MAX_SUBID_LEN) 3647c478bd9Sstevel@tonic-gate return (EINVAL); 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate /* Unsubscribe for all */ 3677c478bd9Sstevel@tonic-gate if (uargs.sid.len == 0) { 3687c478bd9Sstevel@tonic-gate evch_usrunsubscribe(ctl->chp, NULL, 0); 3697c478bd9Sstevel@tonic-gate return (0); 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate sid = kmem_alloc(uargs.sid.len, KM_SLEEP); 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.sid.name, 3757c478bd9Sstevel@tonic-gate sid, uargs.sid.len) != 0) { 3767c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 3777c478bd9Sstevel@tonic-gate return (EFAULT); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate evch_usrunsubscribe(ctl->chp, sid, 0); 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate return (0); 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate /* ARGSUSED */ 3887c478bd9Sstevel@tonic-gate static int 3897c478bd9Sstevel@tonic-gate sysevent_channames(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 3907c478bd9Sstevel@tonic-gate { 3917c478bd9Sstevel@tonic-gate sev_chandata_args_t uargs; 3927c478bd9Sstevel@tonic-gate char *buf; 3937c478bd9Sstevel@tonic-gate int len; 3947c478bd9Sstevel@tonic-gate int rc = 0; 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_chandata_args_t)) != 0) 3977c478bd9Sstevel@tonic-gate return (EFAULT); 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate if (uargs.out_data.len == 0 || uargs.out_data.len > EVCH_MAX_DATA_SIZE) 4007c478bd9Sstevel@tonic-gate return (EINVAL); 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate buf = kmem_alloc(uargs.out_data.len, KM_SLEEP); 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate if ((len = evch_usrgetchnames(buf, uargs.out_data.len)) == -1) { 4057c478bd9Sstevel@tonic-gate rc = EOVERFLOW; 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate if (rc == 0) { 4097c478bd9Sstevel@tonic-gate ASSERT(len <= uargs.out_data.len); 4107c478bd9Sstevel@tonic-gate if (copyout(buf, 4117c478bd9Sstevel@tonic-gate (void *)(uintptr_t)uargs.out_data.name, len) != 0) { 4127c478bd9Sstevel@tonic-gate rc = EFAULT; 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate } 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate kmem_free(buf, uargs.out_data.len); 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate return (rc); 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4227c478bd9Sstevel@tonic-gate static int 4237c478bd9Sstevel@tonic-gate sysevent_chandata(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate sev_chandata_args_t uargs; 4267c478bd9Sstevel@tonic-gate char *channel; 4277c478bd9Sstevel@tonic-gate char *buf; 4287c478bd9Sstevel@tonic-gate int len; 4297c478bd9Sstevel@tonic-gate int rc = 0; 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_chandata_args_t)) != 0) 4327c478bd9Sstevel@tonic-gate return (EFAULT); 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate if (uargs.in_data.len > MAX_CHNAME_LEN || 4357c478bd9Sstevel@tonic-gate uargs.out_data.len > EVCH_MAX_DATA_SIZE) 4367c478bd9Sstevel@tonic-gate return (EINVAL); 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate channel = kmem_alloc(uargs.in_data.len, KM_SLEEP); 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.in_data.name, channel, 4417c478bd9Sstevel@tonic-gate uargs.in_data.len) != 0) { 4427c478bd9Sstevel@tonic-gate kmem_free(channel, uargs.in_data.len); 4437c478bd9Sstevel@tonic-gate return (EFAULT); 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate if (!sysevent_isstrend(channel, uargs.in_data.len)) { 4477c478bd9Sstevel@tonic-gate kmem_free(channel, uargs.in_data.len); 4487c478bd9Sstevel@tonic-gate return (EINVAL); 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate buf = kmem_alloc(uargs.out_data.len, KM_SLEEP); 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate len = evch_usrgetchdata(channel, buf, uargs.out_data.len); 4547c478bd9Sstevel@tonic-gate if (len == 0) { 4557c478bd9Sstevel@tonic-gate rc = EOVERFLOW; 4567c478bd9Sstevel@tonic-gate } else if (len == -1) { 4577c478bd9Sstevel@tonic-gate rc = ENOENT; 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate if (rc == 0) { 4617c478bd9Sstevel@tonic-gate ASSERT(len <= uargs.out_data.len); 4627c478bd9Sstevel@tonic-gate if (copyout(buf, 4637c478bd9Sstevel@tonic-gate (void *)(uintptr_t)uargs.out_data.name, len) != 0) { 4647c478bd9Sstevel@tonic-gate rc = EFAULT; 4657c478bd9Sstevel@tonic-gate } 4667c478bd9Sstevel@tonic-gate } 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate kmem_free(buf, uargs.out_data.len); 4697c478bd9Sstevel@tonic-gate kmem_free(channel, uargs.in_data.len); 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate return (rc); 4727c478bd9Sstevel@tonic-gate } 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4757c478bd9Sstevel@tonic-gate static int 4767c478bd9Sstevel@tonic-gate sysevent_ioctl(dev_t dev, int cmd, intptr_t arg, 4777c478bd9Sstevel@tonic-gate int flag, cred_t *cr, int *rvalp) 4787c478bd9Sstevel@tonic-gate { 4797c478bd9Sstevel@tonic-gate int rc; 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate switch (cmd) { 4827c478bd9Sstevel@tonic-gate case SEV_PUBLISH: 4837c478bd9Sstevel@tonic-gate rc = sysevent_publish(dev, rvalp, (void *)arg, flag, cr); 4847c478bd9Sstevel@tonic-gate break; 4857c478bd9Sstevel@tonic-gate case SEV_CHAN_OPEN: 4867c478bd9Sstevel@tonic-gate rc = sysevent_chan_open(dev, rvalp, (void *)arg, flag, cr); 4877c478bd9Sstevel@tonic-gate break; 4887c478bd9Sstevel@tonic-gate case SEV_CHAN_CONTROL: 4897c478bd9Sstevel@tonic-gate rc = sysevent_chan_control(dev, rvalp, (void *)arg, flag, cr); 4907c478bd9Sstevel@tonic-gate break; 4917c478bd9Sstevel@tonic-gate case SEV_SUBSCRIBE: 4927c478bd9Sstevel@tonic-gate rc = sysevent_subscribe(dev, rvalp, (void *)arg, flag, cr); 4937c478bd9Sstevel@tonic-gate break; 4947c478bd9Sstevel@tonic-gate case SEV_UNSUBSCRIBE: 4957c478bd9Sstevel@tonic-gate rc = sysevent_unsubscribe(dev, rvalp, (void *)arg, flag, cr); 4967c478bd9Sstevel@tonic-gate break; 4977c478bd9Sstevel@tonic-gate case SEV_CHANNAMES: 4987c478bd9Sstevel@tonic-gate rc = sysevent_channames(dev, rvalp, (void *)arg, flag, cr); 4997c478bd9Sstevel@tonic-gate break; 5007c478bd9Sstevel@tonic-gate case SEV_CHANDATA: 5017c478bd9Sstevel@tonic-gate rc = sysevent_chandata(dev, rvalp, (void *)arg, flag, cr); 5027c478bd9Sstevel@tonic-gate break; 5037c478bd9Sstevel@tonic-gate default: 5047c478bd9Sstevel@tonic-gate rc = EINVAL; 5057c478bd9Sstevel@tonic-gate } 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate return (rc); 5087c478bd9Sstevel@tonic-gate } 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5117c478bd9Sstevel@tonic-gate static int 5127c478bd9Sstevel@tonic-gate sysevent_open(dev_t *devp, int flag, int otyp, cred_t *cr) 5137c478bd9Sstevel@tonic-gate { 5147c478bd9Sstevel@tonic-gate int minor; 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 5177c478bd9Sstevel@tonic-gate return (EINVAL); 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate if (getminor(*devp) != 0) 5207c478bd9Sstevel@tonic-gate return (ENXIO); 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate minor = sysevent_minor_get(); 5237c478bd9Sstevel@tonic-gate if (minor == 0) 5247c478bd9Sstevel@tonic-gate /* All minors are busy */ 5257c478bd9Sstevel@tonic-gate return (EBUSY); 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(evchan_ctlp, minor) 5287c478bd9Sstevel@tonic-gate != DDI_SUCCESS) { 5297c478bd9Sstevel@tonic-gate sysevent_minor_rele(minor); 5307c478bd9Sstevel@tonic-gate return (ENOMEM); 5317c478bd9Sstevel@tonic-gate } 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate *devp = makedevice(getmajor(*devp), minor); 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate return (0); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5397c478bd9Sstevel@tonic-gate static int 5407c478bd9Sstevel@tonic-gate sysevent_close(dev_t dev, int flag, int otyp, cred_t *cr) 5417c478bd9Sstevel@tonic-gate { 5427c478bd9Sstevel@tonic-gate int minor = (int)getminor(dev); 5437c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 5467c478bd9Sstevel@tonic-gate return (EINVAL); 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, minor); 5497c478bd9Sstevel@tonic-gate if (ctl == NULL) { 5507c478bd9Sstevel@tonic-gate return (ENXIO); 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate if (ctl->chp) { 5547c478bd9Sstevel@tonic-gate /* Release all non-persistant subscriptions */ 5557c478bd9Sstevel@tonic-gate evch_usrunsubscribe(ctl->chp, NULL, EVCH_SUB_KEEP); 5567c478bd9Sstevel@tonic-gate evch_usrchanclose(ctl->chp); 5577c478bd9Sstevel@tonic-gate } 5587c478bd9Sstevel@tonic-gate 5597c478bd9Sstevel@tonic-gate ddi_soft_state_free(evchan_ctlp, minor); 5607c478bd9Sstevel@tonic-gate sysevent_minor_rele(minor); 5617c478bd9Sstevel@tonic-gate 5627c478bd9Sstevel@tonic-gate return (0); 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5667c478bd9Sstevel@tonic-gate static int 5677c478bd9Sstevel@tonic-gate sysevent_info(dev_info_t *dip, ddi_info_cmd_t infocmd, 5687c478bd9Sstevel@tonic-gate void *arg, void **result) 5697c478bd9Sstevel@tonic-gate { 5707c478bd9Sstevel@tonic-gate switch (infocmd) { 5717c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 5727c478bd9Sstevel@tonic-gate *result = sysevent_devi; 5737c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5747c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 5757c478bd9Sstevel@tonic-gate *result = 0; 5767c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5797c478bd9Sstevel@tonic-gate } 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5827c478bd9Sstevel@tonic-gate static int 5837c478bd9Sstevel@tonic-gate sysevent_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 5847c478bd9Sstevel@tonic-gate { 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate if (cmd != DDI_ATTACH) { 5877c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5887c478bd9Sstevel@tonic-gate } 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(devi, "sysevent", S_IFCHR, 5917c478bd9Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 5927c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 5937c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate sysevent_devi = devi; 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate sysevent_minor_init(); 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate static int 6037c478bd9Sstevel@tonic-gate sysevent_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 6047c478bd9Sstevel@tonic-gate { 6057c478bd9Sstevel@tonic-gate if (cmd != DDI_DETACH) { 6067c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6077c478bd9Sstevel@tonic-gate } 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate sysevent_minor_free(sysevent_minor_bitmap); 6107c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 6117c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6127c478bd9Sstevel@tonic-gate } 6137c478bd9Sstevel@tonic-gate 6147c478bd9Sstevel@tonic-gate static struct cb_ops sysevent_cb_ops = { 6157c478bd9Sstevel@tonic-gate sysevent_open, /* open */ 6167c478bd9Sstevel@tonic-gate sysevent_close, /* close */ 6177c478bd9Sstevel@tonic-gate nodev, /* strategy */ 6187c478bd9Sstevel@tonic-gate nodev, /* print */ 6197c478bd9Sstevel@tonic-gate nodev, /* dump */ 6207c478bd9Sstevel@tonic-gate nodev, /* read */ 6217c478bd9Sstevel@tonic-gate nodev, /* write */ 6227c478bd9Sstevel@tonic-gate sysevent_ioctl, /* ioctl */ 6237c478bd9Sstevel@tonic-gate nodev, /* devmap */ 6247c478bd9Sstevel@tonic-gate nodev, /* mmap */ 6257c478bd9Sstevel@tonic-gate nodev, /* segmap */ 6267c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 6277c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 6287c478bd9Sstevel@tonic-gate 0, /* streamtab */ 6297c478bd9Sstevel@tonic-gate D_NEW|D_MP, /* flag */ 6307c478bd9Sstevel@tonic-gate NULL, /* aread */ 6317c478bd9Sstevel@tonic-gate NULL /* awrite */ 6327c478bd9Sstevel@tonic-gate }; 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate static struct dev_ops sysevent_ops = { 6357c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 6367c478bd9Sstevel@tonic-gate 0, /* refcnt */ 6377c478bd9Sstevel@tonic-gate sysevent_info, /* info */ 6387c478bd9Sstevel@tonic-gate nulldev, /* identify */ 6397c478bd9Sstevel@tonic-gate nulldev, /* probe */ 6407c478bd9Sstevel@tonic-gate sysevent_attach, /* attach */ 6417c478bd9Sstevel@tonic-gate sysevent_detach, /* detach */ 6427c478bd9Sstevel@tonic-gate nodev, /* reset */ 6437c478bd9Sstevel@tonic-gate &sysevent_cb_ops, /* driver operations */ 6447c478bd9Sstevel@tonic-gate (struct bus_ops *)0, /* no bus operations */ 645*19397407SSherry Moore nulldev, /* power */ 646*19397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */ 6477c478bd9Sstevel@tonic-gate }; 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 650*19397407SSherry Moore &mod_driverops, "sysevent driver", &sysevent_ops 6517c478bd9Sstevel@tonic-gate }; 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 6547c478bd9Sstevel@tonic-gate MODREV_1, &modldrv, NULL 6557c478bd9Sstevel@tonic-gate }; 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate int 6587c478bd9Sstevel@tonic-gate _init(void) 6597c478bd9Sstevel@tonic-gate { 6607c478bd9Sstevel@tonic-gate int s; 6617c478bd9Sstevel@tonic-gate 6627c478bd9Sstevel@tonic-gate s = ddi_soft_state_init(&evchan_ctlp, sizeof (evchan_ctl_t), 1); 6637c478bd9Sstevel@tonic-gate if (s != 0) 6647c478bd9Sstevel@tonic-gate return (s); 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate if ((s = mod_install(&modlinkage)) != 0) 6677c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&evchan_ctlp); 6687c478bd9Sstevel@tonic-gate return (s); 6697c478bd9Sstevel@tonic-gate } 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate int 6727c478bd9Sstevel@tonic-gate _fini(void) 6737c478bd9Sstevel@tonic-gate { 6747c478bd9Sstevel@tonic-gate int s; 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate if ((s = mod_remove(&modlinkage)) != 0) 6777c478bd9Sstevel@tonic-gate return (s); 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&evchan_ctlp); 6807c478bd9Sstevel@tonic-gate return (s); 6817c478bd9Sstevel@tonic-gate } 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate int 6847c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 6857c478bd9Sstevel@tonic-gate { 6867c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 6877c478bd9Sstevel@tonic-gate } 688