10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52565Sudpa * Common Development and Distribution License (the "License"). 62565Sudpa * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 224153Sdv142724 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 290Sstevel@tonic-gate #include <mdb/mdb_ks.h> 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/types.h> 320Sstevel@tonic-gate #include <sys/mman.h> 330Sstevel@tonic-gate #include <sys/project.h> 340Sstevel@tonic-gate #include <sys/ipc_impl.h> 350Sstevel@tonic-gate #include <sys/shm_impl.h> 360Sstevel@tonic-gate #include <sys/sem_impl.h> 370Sstevel@tonic-gate #include <sys/msg_impl.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #include <vm/anon.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate #define CMN_HDR_START "%<u>" 420Sstevel@tonic-gate #define CMN_HDR_END "%</u>\n" 430Sstevel@tonic-gate #define CMN_INDENT (4) 440Sstevel@tonic-gate #define CMN_INACTIVE "%s facility inactive.\n" 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* 470Sstevel@tonic-gate * Bitmap data for page protection flags suitable for use with %b. 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate const mdb_bitmask_t prot_flag_bits[] = { 500Sstevel@tonic-gate { "PROT_READ", PROT_READ, PROT_READ }, 510Sstevel@tonic-gate { "PROT_WRITE", PROT_WRITE, PROT_WRITE }, 520Sstevel@tonic-gate { "PROT_EXEC", PROT_EXEC, PROT_EXEC }, 530Sstevel@tonic-gate { "PROT_USER", PROT_USER, PROT_USER }, 540Sstevel@tonic-gate { NULL, 0, 0 } 550Sstevel@tonic-gate }; 560Sstevel@tonic-gate 570Sstevel@tonic-gate static void 580Sstevel@tonic-gate printtime_nice(const char *str, time_t time) 590Sstevel@tonic-gate { 600Sstevel@tonic-gate if (time) 610Sstevel@tonic-gate mdb_printf("%s%Y\n", str, time); 620Sstevel@tonic-gate else 630Sstevel@tonic-gate mdb_printf("%sn/a\n", str); 640Sstevel@tonic-gate } 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * Print header common to all IPC types. 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate static void 700Sstevel@tonic-gate ipcperm_header() 710Sstevel@tonic-gate { 720Sstevel@tonic-gate mdb_printf(CMN_HDR_START "%?s %5s %5s %8s %5s %5s %6s %5s %5s %5s %5s" 730Sstevel@tonic-gate CMN_HDR_END, "ADDR", "REF", "ID", "KEY", "MODE", "PRJID", "ZONEID", 740Sstevel@tonic-gate "OWNER", "GROUP", "CREAT", "CGRP"); 750Sstevel@tonic-gate } 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * Print data common to all IPC types. 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate static void 810Sstevel@tonic-gate ipcperm_print(uintptr_t addr, kipc_perm_t *perm) 820Sstevel@tonic-gate { 830Sstevel@tonic-gate kproject_t proj; 840Sstevel@tonic-gate int res; 850Sstevel@tonic-gate 860Sstevel@tonic-gate res = mdb_vread(&proj, sizeof (kproject_t), (uintptr_t)perm->ipc_proj); 870Sstevel@tonic-gate 880Sstevel@tonic-gate if (res == -1) 890Sstevel@tonic-gate mdb_warn("failed to read kproject_t at %#p", perm->ipc_proj); 900Sstevel@tonic-gate 910Sstevel@tonic-gate mdb_printf("%0?p %5d %5d", addr, perm->ipc_ref, perm->ipc_id); 920Sstevel@tonic-gate if (perm->ipc_key) 930Sstevel@tonic-gate mdb_printf(" %8x", perm->ipc_key); 940Sstevel@tonic-gate else 950Sstevel@tonic-gate mdb_printf(" %8s", "private"); 960Sstevel@tonic-gate mdb_printf(" %5#o", perm->ipc_mode & 07777); 970Sstevel@tonic-gate if (res == -1) 980Sstevel@tonic-gate mdb_printf(" %5s %5s", "<flt>", "<flt>"); 990Sstevel@tonic-gate else 1000Sstevel@tonic-gate mdb_printf(" %5d %6d", proj.kpj_id, proj.kpj_zoneid); 1010Sstevel@tonic-gate mdb_printf(" %5d %5d %5d %5d\n", perm->ipc_uid, perm->ipc_gid, 1020Sstevel@tonic-gate perm->ipc_cuid, perm->ipc_cgid); 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate } 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /*ARGSUSED*/ 1070Sstevel@tonic-gate static int 1080Sstevel@tonic-gate ipcperm(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1090Sstevel@tonic-gate { 1100Sstevel@tonic-gate kipc_perm_t perm; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 1130Sstevel@tonic-gate return (DCMD_USAGE); 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 1160Sstevel@tonic-gate ipcperm_header(); 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate if (mdb_vread(&perm, sizeof (kipc_perm_t), addr) == -1) { 1190Sstevel@tonic-gate mdb_warn("failed to read kipc_perm_t at %#lx", addr); 1200Sstevel@tonic-gate return (DCMD_ERR); 1210Sstevel@tonic-gate } 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate ipcperm_print(addr, &perm); 1240Sstevel@tonic-gate return (DCMD_OK); 1250Sstevel@tonic-gate } 1260Sstevel@tonic-gate 1274153Sdv142724 1284153Sdv142724 static int 1294153Sdv142724 msgq_check_for_rwaiters(list_t *walk_this, int min, int max, 1304153Sdv142724 int copy_wait, uintptr_t addr) 1314153Sdv142724 1324153Sdv142724 { 1334153Sdv142724 int found = 0; 1344153Sdv142724 int ii; 135*4158Sdv142724 msgq_wakeup_t *walker, next; 1364153Sdv142724 uintptr_t head; 1374153Sdv142724 1384153Sdv142724 for (ii = min; ii < max; ii++) { 1394153Sdv142724 head = ((ulong_t)addr) + sizeof (list_t)*ii + 1404153Sdv142724 sizeof (list_node_t); 1414153Sdv142724 if (head != (uintptr_t)walk_this[ii].list_head.list_next) { 1424153Sdv142724 walker = 1434153Sdv142724 (msgq_wakeup_t *)walk_this[ii].list_head.list_next; 1444153Sdv142724 while (head != (uintptr_t)walker) { 1454153Sdv142724 if (mdb_vread(&next, sizeof (msgq_wakeup_t), 1464153Sdv142724 (uintptr_t)walker) == -1) { 1474153Sdv142724 mdb_warn( 1484153Sdv142724 "Failed to read message queue\n"); 1494153Sdv142724 return (0); 1504153Sdv142724 } 1514153Sdv142724 mdb_printf("%15lx\t%6d\t%15lx\t%15s\n", 1524153Sdv142724 next.msgw_thrd, next.msgw_type, 1534153Sdv142724 walker + (uintptr_t) 1544153Sdv142724 OFFSETOF(msgq_wakeup_t, msgw_wake_cv), 1554153Sdv142724 (copy_wait ? "yes":"no")); 1564153Sdv142724 found++; 1574153Sdv142724 walker = 1584153Sdv142724 (msgq_wakeup_t *)next.msgw_list.list_next; 1594153Sdv142724 } 1604153Sdv142724 } 1614153Sdv142724 } 1624153Sdv142724 return (found); 1634153Sdv142724 } 1644153Sdv142724 1650Sstevel@tonic-gate static void 1660Sstevel@tonic-gate msq_print(kmsqid_t *msqid, uintptr_t addr) 1670Sstevel@tonic-gate { 1684153Sdv142724 int total = 0; 1692565Sudpa 1700Sstevel@tonic-gate mdb_printf("&list: %-?p\n", addr + OFFSETOF(kmsqid_t, msg_list)); 1710Sstevel@tonic-gate mdb_printf("cbytes: 0t%lu qnum: 0t%lu qbytes: 0t%lu" 1720Sstevel@tonic-gate " qmax: 0t%lu\n", msqid->msg_cbytes, msqid->msg_qnum, 1730Sstevel@tonic-gate msqid->msg_qbytes, msqid->msg_qmax); 1740Sstevel@tonic-gate mdb_printf("lspid: 0t%d lrpid: 0t%d\n", 1750Sstevel@tonic-gate (int)msqid->msg_lspid, (int)msqid->msg_lrpid); 1760Sstevel@tonic-gate printtime_nice("stime: ", msqid->msg_stime); 1770Sstevel@tonic-gate printtime_nice("rtime: ", msqid->msg_rtime); 1780Sstevel@tonic-gate printtime_nice("ctime: ", msqid->msg_ctime); 1792565Sudpa mdb_printf("snd_cnt: 0t%lld snd_cv: %hd (%p)\n", 1802565Sudpa msqid->msg_snd_cnt, msqid->msg_snd_cv._opaque, 1812565Sudpa addr + (uintptr_t)OFFSETOF(kmsqid_t, msg_snd_cv)); 1824153Sdv142724 mdb_printf("Blocked recievers\n"); 1834153Sdv142724 mdb_printf("%15s\t%6s\t%15s\t%15s\n", "Thread Addr", 1844153Sdv142724 "Type", "cv addr", "copyout-wait?"); 1854153Sdv142724 total += msgq_check_for_rwaiters(&msqid->msg_cpy_block, 1864153Sdv142724 0, 1, 1, addr + OFFSETOF(kmsqid_t, msg_cpy_block)); 1874153Sdv142724 total += msgq_check_for_rwaiters(msqid->msg_wait_snd, 1884153Sdv142724 0, MSG_MAX_QNUM + 1, 0, addr + OFFSETOF(kmsqid_t, msg_wait_snd)); 1894153Sdv142724 total += msgq_check_for_rwaiters(msqid->msg_wait_snd_ngt, 1904153Sdv142724 0, MSG_MAX_QNUM + 1, 0, 1914153Sdv142724 addr + OFFSETOF(kmsqid_t, msg_wait_snd_ngt)); 1924153Sdv142724 mdb_printf("Total number of waiters: %d\n", total); 1930Sstevel@tonic-gate } 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate /*ARGSUSED1*/ 1970Sstevel@tonic-gate static void 1980Sstevel@tonic-gate shm_print(kshmid_t *shmid, uintptr_t addr) 1990Sstevel@tonic-gate { 2000Sstevel@tonic-gate shmatt_t nattch; 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate nattch = shmid->shm_perm.ipc_ref - (IPC_FREE(&shmid->shm_perm) ? 0 : 1); 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate mdb_printf(CMN_HDR_START "%10s %?s %5s %7s %7s %7s %7s" CMN_HDR_END, 2050Sstevel@tonic-gate "SEGSZ", "AMP", "LKCNT", "LPID", "CPID", "NATTCH", "CNATTCH"); 2060Sstevel@tonic-gate mdb_printf("%10#lx %?p %5u %7d %7d %7lu %7lu\n", 2070Sstevel@tonic-gate shmid->shm_segsz, shmid->shm_amp, shmid->shm_lkcnt, 2080Sstevel@tonic-gate (int)shmid->shm_lpid, (int)shmid->shm_cpid, nattch, 2090Sstevel@tonic-gate shmid->shm_ismattch); 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate printtime_nice("atime: ", shmid->shm_atime); 2120Sstevel@tonic-gate printtime_nice("dtime: ", shmid->shm_dtime); 2130Sstevel@tonic-gate printtime_nice("ctime: ", shmid->shm_ctime); 2140Sstevel@tonic-gate mdb_printf("sptinfo: %-?p sptseg: %-?p\n", 2150Sstevel@tonic-gate shmid->shm_sptinfo, shmid->shm_sptseg); 2160Sstevel@tonic-gate mdb_printf("sptprot: <%lb>\n", shmid->shm_sptprot, prot_flag_bits); 2170Sstevel@tonic-gate } 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate /*ARGSUSED1*/ 2210Sstevel@tonic-gate static void 2220Sstevel@tonic-gate sem_print(ksemid_t *semid, uintptr_t addr) 2230Sstevel@tonic-gate { 2240Sstevel@tonic-gate mdb_printf("base: %-?p nsems: 0t%u\n", 2250Sstevel@tonic-gate semid->sem_base, semid->sem_nsems); 2260Sstevel@tonic-gate printtime_nice("otime: ", semid->sem_otime); 2270Sstevel@tonic-gate printtime_nice("ctime: ", semid->sem_ctime); 2280Sstevel@tonic-gate mdb_printf("binary: %s\n", semid->sem_binary ? "yes" : "no"); 2290Sstevel@tonic-gate } 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate typedef struct ipc_ops_vec { 2320Sstevel@tonic-gate char *iv_wcmd; /* walker name */ 2330Sstevel@tonic-gate char *iv_ocmd; /* output dcmd */ 2340Sstevel@tonic-gate char *iv_service; /* service pointer */ 2350Sstevel@tonic-gate void (*iv_print)(void *, uintptr_t); /* output callback */ 2360Sstevel@tonic-gate size_t iv_idsize; 2370Sstevel@tonic-gate } ipc_ops_vec_t; 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate ipc_ops_vec_t msq_ops_vec = { 2400Sstevel@tonic-gate "msq", 2410Sstevel@tonic-gate "kmsqid", 2420Sstevel@tonic-gate "msq_svc", 2430Sstevel@tonic-gate (void(*)(void *, uintptr_t))msq_print, 2440Sstevel@tonic-gate sizeof (kmsqid_t) 2450Sstevel@tonic-gate }; 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate ipc_ops_vec_t shm_ops_vec = { 2480Sstevel@tonic-gate "shm", 2490Sstevel@tonic-gate "kshmid", 2500Sstevel@tonic-gate "shm_svc", 2510Sstevel@tonic-gate (void(*)(void *, uintptr_t))shm_print, 2520Sstevel@tonic-gate sizeof (kshmid_t) 2530Sstevel@tonic-gate }; 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate ipc_ops_vec_t sem_ops_vec = { 2560Sstevel@tonic-gate "sem", 2570Sstevel@tonic-gate "ksemid", 2580Sstevel@tonic-gate "sem_svc", 2590Sstevel@tonic-gate (void(*)(void *, uintptr_t))sem_print, 2600Sstevel@tonic-gate sizeof (ksemid_t) 2610Sstevel@tonic-gate }; 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate /* 2650Sstevel@tonic-gate * Generic IPC data structure display code 2660Sstevel@tonic-gate */ 2670Sstevel@tonic-gate static int 2680Sstevel@tonic-gate ds_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv, 2690Sstevel@tonic-gate ipc_ops_vec_t *iv) 2700Sstevel@tonic-gate { 2710Sstevel@tonic-gate void *iddata; 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 2740Sstevel@tonic-gate uint_t oflags = 0; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate if (mdb_getopts(argc, argv, 'l', MDB_OPT_SETBITS, 1, &oflags, 2770Sstevel@tonic-gate NULL) != argc) 2780Sstevel@tonic-gate return (DCMD_USAGE); 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate if (mdb_walk_dcmd(iv->iv_wcmd, oflags ? iv->iv_ocmd : "ipcperm", 2810Sstevel@tonic-gate argc, argv) == -1) { 2820Sstevel@tonic-gate mdb_warn("can't walk '%s'", iv->iv_wcmd); 2830Sstevel@tonic-gate return (DCMD_ERR); 2840Sstevel@tonic-gate } 2850Sstevel@tonic-gate return (DCMD_OK); 2860Sstevel@tonic-gate } 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate iddata = mdb_alloc(iv->iv_idsize, UM_SLEEP | UM_GC); 2890Sstevel@tonic-gate if (mdb_vread(iddata, iv->iv_idsize, addr) == -1) { 2900Sstevel@tonic-gate mdb_warn("failed to read %s at %#lx", iv->iv_ocmd, addr); 2910Sstevel@tonic-gate return (DCMD_ERR); 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate if (!DCMD_HDRSPEC(flags) && iv->iv_print) 2950Sstevel@tonic-gate mdb_printf("\n"); 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate if (DCMD_HDRSPEC(flags) || iv->iv_print) 2980Sstevel@tonic-gate ipcperm_header(); 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate ipcperm_print(addr, (struct kipc_perm *)iddata); 3010Sstevel@tonic-gate if (iv->iv_print) { 3020Sstevel@tonic-gate mdb_inc_indent(CMN_INDENT); 3030Sstevel@tonic-gate iv->iv_print(iddata, addr); 3040Sstevel@tonic-gate mdb_dec_indent(CMN_INDENT); 3050Sstevel@tonic-gate } 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate return (DCMD_OK); 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate /* 3120Sstevel@tonic-gate * Stubs to call ds_print with the appropriate ops vector 3130Sstevel@tonic-gate */ 3140Sstevel@tonic-gate static int 3150Sstevel@tonic-gate cmd_kshmid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3160Sstevel@tonic-gate { 3170Sstevel@tonic-gate return (ds_print(addr, flags, argc, argv, &shm_ops_vec)); 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate static int 3220Sstevel@tonic-gate cmd_kmsqid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3230Sstevel@tonic-gate { 3240Sstevel@tonic-gate return (ds_print(addr, flags, argc, argv, &msq_ops_vec)); 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate static int 3280Sstevel@tonic-gate cmd_ksemid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3290Sstevel@tonic-gate { 3300Sstevel@tonic-gate return (ds_print(addr, flags, argc, argv, &sem_ops_vec)); 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate /* 3340Sstevel@tonic-gate * Generic IPC walker 3350Sstevel@tonic-gate */ 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate static int 3380Sstevel@tonic-gate ds_walk_init(mdb_walk_state_t *wsp) 3390Sstevel@tonic-gate { 3400Sstevel@tonic-gate ipc_ops_vec_t *iv = wsp->walk_arg; 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate if (wsp->walk_arg != NULL && wsp->walk_addr != NULL) 3430Sstevel@tonic-gate mdb_printf("ignoring provided address\n"); 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate if (wsp->walk_arg) 3460Sstevel@tonic-gate if (mdb_readvar(&wsp->walk_addr, iv->iv_service) == -1) { 3470Sstevel@tonic-gate mdb_printf("failed to read '%s'; module not present\n", 3480Sstevel@tonic-gate iv->iv_service); 3490Sstevel@tonic-gate return (WALK_DONE); 3500Sstevel@tonic-gate } 3510Sstevel@tonic-gate else 3520Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr + 3530Sstevel@tonic-gate OFFSETOF(ipc_service_t, ipcs_usedids); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate if (mdb_layered_walk("list", wsp) == -1) 3560Sstevel@tonic-gate return (WALK_ERR); 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate return (WALK_NEXT); 3590Sstevel@tonic-gate } 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate static int 3630Sstevel@tonic-gate ds_walk_step(mdb_walk_state_t *wsp) 3640Sstevel@tonic-gate { 3650Sstevel@tonic-gate return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer, 3660Sstevel@tonic-gate wsp->walk_cbdata)); 3670Sstevel@tonic-gate } 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate /* 3700Sstevel@tonic-gate * Generic IPC ID/key to pointer code 3710Sstevel@tonic-gate */ 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate static int 3740Sstevel@tonic-gate ipcid_impl(uintptr_t svcptr, uintptr_t id, uintptr_t *addr) 3750Sstevel@tonic-gate { 3760Sstevel@tonic-gate ipc_service_t service; 3770Sstevel@tonic-gate kipc_perm_t perm; 3780Sstevel@tonic-gate ipc_slot_t slot; 3790Sstevel@tonic-gate uintptr_t slotptr; 3800Sstevel@tonic-gate uint_t index; 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate if (id > INT_MAX) { 3830Sstevel@tonic-gate mdb_warn("id out of range\n"); 3840Sstevel@tonic-gate return (DCMD_ERR); 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate if (mdb_vread(&service, sizeof (ipc_service_t), svcptr) == -1) { 3880Sstevel@tonic-gate mdb_warn("failed to read ipc_service_t at %#lx", svcptr); 3890Sstevel@tonic-gate return (DCMD_ERR); 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate index = (uint_t)id & (service.ipcs_tabsz - 1); 3930Sstevel@tonic-gate slotptr = (uintptr_t)(service.ipcs_table + index); 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate if (mdb_vread(&slot, sizeof (ipc_slot_t), slotptr) == -1) { 3960Sstevel@tonic-gate mdb_warn("failed to read ipc_slot_t at %#lx", slotptr); 3970Sstevel@tonic-gate return (DCMD_ERR); 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate if (slot.ipct_data == NULL) 4010Sstevel@tonic-gate return (DCMD_ERR); 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate if (mdb_vread(&perm, sizeof (kipc_perm_t), 4040Sstevel@tonic-gate (uintptr_t)slot.ipct_data) == -1) { 4050Sstevel@tonic-gate mdb_warn("failed to read kipc_perm_t at %#p", 4060Sstevel@tonic-gate slot.ipct_data); 4070Sstevel@tonic-gate return (DCMD_ERR); 4080Sstevel@tonic-gate } 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate if (perm.ipc_id != (uint_t)id) 4110Sstevel@tonic-gate return (DCMD_ERR); 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate *addr = (uintptr_t)slot.ipct_data; 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate return (DCMD_OK); 4160Sstevel@tonic-gate } 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate typedef struct findkey_data { 4200Sstevel@tonic-gate key_t fk_key; 4210Sstevel@tonic-gate uintptr_t fk_addr; 4220Sstevel@tonic-gate boolean_t fk_found; 4230Sstevel@tonic-gate } findkey_data_t; 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate static int 4260Sstevel@tonic-gate findkey(uintptr_t addr, kipc_perm_t *perm, findkey_data_t *arg) 4270Sstevel@tonic-gate { 4280Sstevel@tonic-gate if (perm->ipc_key == arg->fk_key) { 4290Sstevel@tonic-gate arg->fk_found = B_TRUE; 4300Sstevel@tonic-gate arg->fk_addr = addr; 4310Sstevel@tonic-gate return (WALK_DONE); 4320Sstevel@tonic-gate } 4330Sstevel@tonic-gate return (WALK_NEXT); 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate static int 4370Sstevel@tonic-gate ipckey_impl(uintptr_t svcptr, uintptr_t key, uintptr_t *addr) 4380Sstevel@tonic-gate { 4390Sstevel@tonic-gate ipc_service_t service; 4400Sstevel@tonic-gate findkey_data_t fkdata; 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate if ((key == IPC_PRIVATE) || (key > INT_MAX)) { 4430Sstevel@tonic-gate mdb_warn("key out of range\n"); 4440Sstevel@tonic-gate return (DCMD_ERR); 4450Sstevel@tonic-gate } 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate if (mdb_vread(&service, sizeof (ipc_service_t), svcptr) == -1) { 4480Sstevel@tonic-gate mdb_warn("failed to read ipc_service_t at %#lx", svcptr); 4490Sstevel@tonic-gate return (DCMD_ERR); 4500Sstevel@tonic-gate } 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate fkdata.fk_key = (key_t)key; 4530Sstevel@tonic-gate fkdata.fk_found = B_FALSE; 4540Sstevel@tonic-gate if ((mdb_pwalk("avl", (mdb_walk_cb_t)findkey, &fkdata, 4550Sstevel@tonic-gate svcptr + OFFSETOF(ipc_service_t, ipcs_keys)) == -1) || 4560Sstevel@tonic-gate !fkdata.fk_found) 4570Sstevel@tonic-gate return (DCMD_ERR); 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate *addr = fkdata.fk_addr; 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate return (DCMD_OK); 4620Sstevel@tonic-gate } 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate static int 4650Sstevel@tonic-gate ipckeyid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv, 4660Sstevel@tonic-gate int(*fp)(uintptr_t, uintptr_t, uintptr_t *)) 4670Sstevel@tonic-gate { 4680Sstevel@tonic-gate uintmax_t val; 4690Sstevel@tonic-gate uintptr_t raddr; 4700Sstevel@tonic-gate int result; 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || (argc != 1)) 4730Sstevel@tonic-gate return (DCMD_USAGE); 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate if (argv[0].a_type == MDB_TYPE_IMMEDIATE) 4760Sstevel@tonic-gate val = argv[0].a_un.a_val; 4770Sstevel@tonic-gate else if (argv[0].a_type == MDB_TYPE_STRING) 4780Sstevel@tonic-gate val = mdb_strtoull(argv[0].a_un.a_str); 4790Sstevel@tonic-gate else 4800Sstevel@tonic-gate return (DCMD_USAGE); 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate result = fp(addr, val, &raddr); 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate if (result == DCMD_OK) 4850Sstevel@tonic-gate mdb_printf("%lx", raddr); 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate return (result); 4880Sstevel@tonic-gate } 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate static int 4910Sstevel@tonic-gate ipckey(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4920Sstevel@tonic-gate { 4930Sstevel@tonic-gate return (ipckeyid(addr, flags, argc, argv, ipckey_impl)); 4940Sstevel@tonic-gate } 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate static int 4970Sstevel@tonic-gate ipcid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4980Sstevel@tonic-gate { 4990Sstevel@tonic-gate return (ipckeyid(addr, flags, argc, argv, ipcid_impl)); 5000Sstevel@tonic-gate } 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate static int 5030Sstevel@tonic-gate ds_ptr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv, 5040Sstevel@tonic-gate ipc_ops_vec_t *iv) 5050Sstevel@tonic-gate { 5060Sstevel@tonic-gate uint_t kflag = FALSE; 5070Sstevel@tonic-gate uintptr_t svcptr, raddr; 5080Sstevel@tonic-gate int result; 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 5110Sstevel@tonic-gate return (DCMD_USAGE); 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate if (mdb_getopts(argc, argv, 5140Sstevel@tonic-gate 'k', MDB_OPT_SETBITS, TRUE, &kflag, NULL) != argc) 5150Sstevel@tonic-gate return (DCMD_USAGE); 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate if (mdb_readvar(&svcptr, iv->iv_service) == -1) { 5180Sstevel@tonic-gate mdb_warn("failed to read '%s'; module not present\n", 5190Sstevel@tonic-gate iv->iv_service); 5200Sstevel@tonic-gate return (DCMD_ERR); 5210Sstevel@tonic-gate } 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate result = kflag ? ipckey_impl(svcptr, addr, &raddr) : 5240Sstevel@tonic-gate ipcid_impl(svcptr, addr, &raddr); 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate if (result == DCMD_OK) 5270Sstevel@tonic-gate mdb_printf("%lx", raddr); 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate return (result); 5300Sstevel@tonic-gate } 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate /* 5330Sstevel@tonic-gate * Stubs to call ds_ptr with the appropriate ops vector 5340Sstevel@tonic-gate */ 5350Sstevel@tonic-gate static int 5360Sstevel@tonic-gate id2shm(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5370Sstevel@tonic-gate { 5380Sstevel@tonic-gate return (ds_ptr(addr, flags, argc, argv, &shm_ops_vec)); 5390Sstevel@tonic-gate } 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate static int 5420Sstevel@tonic-gate id2msq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5430Sstevel@tonic-gate { 5440Sstevel@tonic-gate return (ds_ptr(addr, flags, argc, argv, &msq_ops_vec)); 5450Sstevel@tonic-gate } 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate static int 5480Sstevel@tonic-gate id2sem(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5490Sstevel@tonic-gate { 5500Sstevel@tonic-gate return (ds_ptr(addr, flags, argc, argv, &sem_ops_vec)); 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate /* 5550Sstevel@tonic-gate * The message queue contents walker 5560Sstevel@tonic-gate */ 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate static int 5590Sstevel@tonic-gate msg_walk_init(mdb_walk_state_t *wsp) 5600Sstevel@tonic-gate { 5610Sstevel@tonic-gate wsp->walk_addr += OFFSETOF(kmsqid_t, msg_list); 5620Sstevel@tonic-gate if (mdb_layered_walk("list", wsp) == -1) 5630Sstevel@tonic-gate return (WALK_ERR); 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate return (WALK_NEXT); 5660Sstevel@tonic-gate } 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate static int 5690Sstevel@tonic-gate msg_walk_step(mdb_walk_state_t *wsp) 5700Sstevel@tonic-gate { 5710Sstevel@tonic-gate return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer, 5720Sstevel@tonic-gate wsp->walk_cbdata)); 5730Sstevel@tonic-gate } 5740Sstevel@tonic-gate 5750Sstevel@tonic-gate /* 5760Sstevel@tonic-gate * The "::ipcs" command itself. Just walks each IPC type in turn. 5770Sstevel@tonic-gate */ 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate /*ARGSUSED*/ 5800Sstevel@tonic-gate static int 5810Sstevel@tonic-gate ipcs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5820Sstevel@tonic-gate { 5830Sstevel@tonic-gate uint_t oflags = 0; 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) || mdb_getopts(argc, argv, 'l', 5860Sstevel@tonic-gate MDB_OPT_SETBITS, 1, &oflags, NULL) != argc) 5870Sstevel@tonic-gate return (DCMD_USAGE); 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate mdb_printf("Message queues:\n"); 5900Sstevel@tonic-gate if (mdb_walk_dcmd("msq", oflags ? "kmsqid" : "ipcperm", argc, argv) == 5910Sstevel@tonic-gate -1) { 5920Sstevel@tonic-gate mdb_warn("can't walk 'msq'"); 5930Sstevel@tonic-gate return (DCMD_ERR); 5940Sstevel@tonic-gate } 5950Sstevel@tonic-gate 5960Sstevel@tonic-gate mdb_printf("\nShared memory:\n"); 5970Sstevel@tonic-gate if (mdb_walk_dcmd("shm", oflags ? "kshmid" : "ipcperm", argc, argv) == 5980Sstevel@tonic-gate -1) { 5990Sstevel@tonic-gate mdb_warn("can't walk 'shm'"); 6000Sstevel@tonic-gate return (DCMD_ERR); 6010Sstevel@tonic-gate } 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate mdb_printf("\nSemaphores:\n"); 6040Sstevel@tonic-gate if (mdb_walk_dcmd("sem", oflags ? "ksemid" : "ipcperm", argc, argv) == 6050Sstevel@tonic-gate -1) { 6060Sstevel@tonic-gate mdb_warn("can't walk 'sem'"); 6070Sstevel@tonic-gate return (DCMD_ERR); 6080Sstevel@tonic-gate } 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate return (DCMD_OK); 6110Sstevel@tonic-gate } 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate static int 6140Sstevel@tonic-gate msgprint(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 6150Sstevel@tonic-gate { 6160Sstevel@tonic-gate struct msg message; 6170Sstevel@tonic-gate uint_t lflag = FALSE; 6180Sstevel@tonic-gate long type = 0; 6190Sstevel@tonic-gate char *tflag = NULL; 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || (mdb_getopts(argc, argv, 6220Sstevel@tonic-gate 'l', MDB_OPT_SETBITS, TRUE, &lflag, 6230Sstevel@tonic-gate 't', MDB_OPT_STR, &tflag, NULL) != argc)) 6240Sstevel@tonic-gate return (DCMD_USAGE); 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate /* 6270Sstevel@tonic-gate * Handle negative values. 6280Sstevel@tonic-gate */ 6290Sstevel@tonic-gate if (tflag != NULL) { 6300Sstevel@tonic-gate if (*tflag == '-') { 6310Sstevel@tonic-gate tflag++; 6320Sstevel@tonic-gate type = -1; 6330Sstevel@tonic-gate } else { 6340Sstevel@tonic-gate type = 1; 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate type *= mdb_strtoull(tflag); 6370Sstevel@tonic-gate } 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 6400Sstevel@tonic-gate mdb_printf("%<u>%?s %?s %8s %8s %8s%</u>\n", 6410Sstevel@tonic-gate "ADDR", "TEXT", "SIZE", "TYPE", "REF"); 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate if (mdb_vread(&message, sizeof (struct msg), addr) == -1) { 6440Sstevel@tonic-gate mdb_warn("failed to read msg at %#lx", addr); 6450Sstevel@tonic-gate return (DCMD_ERR); 6460Sstevel@tonic-gate } 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate /* 6490Sstevel@tonic-gate * If we are meeting our type contraints, display the message. 6500Sstevel@tonic-gate * If -l was specified, we will also display the message 6510Sstevel@tonic-gate * contents. 6520Sstevel@tonic-gate */ 6530Sstevel@tonic-gate if ((type == 0) || 6540Sstevel@tonic-gate (type > 0 && message.msg_type == type) || 6550Sstevel@tonic-gate (type < 0 && message.msg_type <= -type)) { 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate if (lflag && !DCMD_HDRSPEC(flags)) 6580Sstevel@tonic-gate mdb_printf("\n"); 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate mdb_printf("%0?lx %?p %8ld %8ld %8ld\n", addr, message.msg_addr, 6610Sstevel@tonic-gate message.msg_size, message.msg_type, message.msg_copycnt); 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate if (lflag) { 6640Sstevel@tonic-gate mdb_printf("\n"); 6650Sstevel@tonic-gate mdb_inc_indent(CMN_INDENT); 6660Sstevel@tonic-gate if (mdb_dumpptr( 6670Sstevel@tonic-gate (uintptr_t)message.msg_addr, message.msg_size, 6680Sstevel@tonic-gate MDB_DUMP_RELATIVE | MDB_DUMP_TRIM | 6690Sstevel@tonic-gate MDB_DUMP_ASCII | MDB_DUMP_HEADER | 6700Sstevel@tonic-gate MDB_DUMP_GROUP(4), 6710Sstevel@tonic-gate (mdb_dumpptr_cb_t)mdb_vread, NULL)) { 6720Sstevel@tonic-gate mdb_dec_indent(CMN_INDENT); 6730Sstevel@tonic-gate return (DCMD_ERR); 6740Sstevel@tonic-gate } 6750Sstevel@tonic-gate mdb_dec_indent(CMN_INDENT); 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate } 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate return (DCMD_OK); 6800Sstevel@tonic-gate } 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate /* 6830Sstevel@tonic-gate * MDB module linkage 6840Sstevel@tonic-gate */ 6850Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 6860Sstevel@tonic-gate /* Generic routines */ 6870Sstevel@tonic-gate { "ipcperm", ":", "display an IPC perm structure", ipcperm }, 6880Sstevel@tonic-gate { "ipcid", ":id", "perform an IPC id lookup", ipcid }, 6890Sstevel@tonic-gate { "ipckey", ":key", "perform an IPC key lookup", ipckey }, 6900Sstevel@tonic-gate 6910Sstevel@tonic-gate /* Specific routines */ 6920Sstevel@tonic-gate { "kshmid", "?[-l]", "display a struct kshmid", cmd_kshmid }, 6930Sstevel@tonic-gate { "kmsqid", "?[-l]", "display a struct kmsqid", cmd_kmsqid }, 6940Sstevel@tonic-gate { "ksemid", "?[-l]", "display a struct ksemid", cmd_ksemid }, 6950Sstevel@tonic-gate { "msg", ":[-l] [-t type]", "display contents of a message", msgprint }, 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate /* Convenience routines */ 6980Sstevel@tonic-gate { "id2shm", ":[-k]", "convert shared memory ID to pointer", id2shm }, 6990Sstevel@tonic-gate { "id2msq", ":[-k]", "convert message queue ID to pointer", id2msq }, 7000Sstevel@tonic-gate { "id2sem", ":[-k]", "convert semaphore ID to pointer", id2sem }, 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate { "ipcs", "[-l]", "display System V IPC information", ipcs }, 7030Sstevel@tonic-gate { NULL } 7040Sstevel@tonic-gate }; 7050Sstevel@tonic-gate 7060Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 7070Sstevel@tonic-gate { "ipcsvc", "walk a System V IPC service", 7080Sstevel@tonic-gate ds_walk_init, ds_walk_step }, 7090Sstevel@tonic-gate { "shm", "walk the active shmid_ds structures", 7100Sstevel@tonic-gate ds_walk_init, ds_walk_step, NULL, &shm_ops_vec }, 7110Sstevel@tonic-gate { "msq", "walk the active msqid_ds structures", 7120Sstevel@tonic-gate ds_walk_init, ds_walk_step, NULL, &msq_ops_vec }, 7130Sstevel@tonic-gate { "sem", "walk the active semid_ds structures", 7140Sstevel@tonic-gate ds_walk_init, ds_walk_step, NULL, &sem_ops_vec }, 7150Sstevel@tonic-gate { "msgqueue", "walk messages on a message queue", 7160Sstevel@tonic-gate msg_walk_init, msg_walk_step }, 7170Sstevel@tonic-gate { NULL } 7180Sstevel@tonic-gate }; 7190Sstevel@tonic-gate 7200Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers }; 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate const mdb_modinfo_t * 7230Sstevel@tonic-gate _mdb_init(void) 7240Sstevel@tonic-gate { 7250Sstevel@tonic-gate return (&modinfo); 7260Sstevel@tonic-gate } 727