diff options
25 files changed, 130 insertions, 204 deletions
@@ -10158,7 +10158,6 @@ d usr/lib/mdb/proc/amd64 0755 root sys f usr/lib/mdb/proc/amd64/ld.so 0555 root sys f usr/lib/mdb/proc/amd64/libavl.so 0555 root sys f usr/lib/mdb/proc/amd64/libc.so 0555 root sys -f usr/lib/mdb/proc/amd64/libcmdutils.so 0555 root sys f usr/lib/mdb/proc/amd64/libnvpair.so 0555 root sys f usr/lib/mdb/proc/amd64/libproc.so 0555 root sys f usr/lib/mdb/proc/amd64/libpython2.6.so 0555 root sys @@ -10168,6 +10167,7 @@ f usr/lib/mdb/proc/amd64/libtopo.so 0555 root sys f usr/lib/mdb/proc/amd64/libumem.so 0555 root sys f usr/lib/mdb/proc/amd64/libuutil.so 0555 root sys f usr/lib/mdb/proc/amd64/libzpool.so 0555 root sys +f usr/lib/mdb/proc/amd64/list.so 0555 root sys f usr/lib/mdb/proc/amd64/mdb_ds.so 0555 root sys f usr/lib/mdb/proc/amd64/mdb_test.so 0555 root sys f usr/lib/mdb/proc/eft.so 0555 root sys @@ -10175,7 +10175,6 @@ f usr/lib/mdb/proc/fmd.so 0555 root sys f usr/lib/mdb/proc/ld.so 0555 root sys f usr/lib/mdb/proc/libavl.so 0555 root sys f usr/lib/mdb/proc/libc.so 0555 root sys -f usr/lib/mdb/proc/libcmdutils.so 0555 root sys f usr/lib/mdb/proc/libmlsvc.so 0555 root sys f usr/lib/mdb/proc/libnvpair.so 0555 root sys f usr/lib/mdb/proc/libproc.so 0555 root sys @@ -10186,6 +10185,7 @@ f usr/lib/mdb/proc/libtopo.so 0555 root sys f usr/lib/mdb/proc/libumem.so 0555 root sys f usr/lib/mdb/proc/libuutil.so 0555 root sys f usr/lib/mdb/proc/libzpool.so 0555 root sys +f usr/lib/mdb/proc/list.so 0555 root sys f usr/lib/mdb/proc/mdb_ds.so 0555 root sys f usr/lib/mdb/proc/mdb_test.so 0555 root sys f usr/lib/mdb/proc/svc.configd.so 0555 root sys diff --git a/usr/src/cmd/mdb/Makefile.common b/usr/src/cmd/mdb/Makefile.common index 99387fd065..0d637f2da6 100644 --- a/usr/src/cmd/mdb/Makefile.common +++ b/usr/src/cmd/mdb/Makefile.common @@ -34,7 +34,6 @@ COMMON_MODULES_PROC = \ dof \ libavl \ libc \ - libcmdutils \ libfknsmb \ libfksmbfs \ libfksmbsrv \ @@ -47,6 +46,7 @@ COMMON_MODULES_PROC = \ libumem \ libuutil \ libzpool \ + list \ mdb_ds \ mdb_test diff --git a/usr/src/cmd/mdb/common/mdb/mdb_module_load.c b/usr/src/cmd/mdb/common/mdb/mdb_module_load.c index 141aa3a5cd..37f0109663 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_module_load.c +++ b/usr/src/cmd/mdb/common/mdb/mdb_module_load.c @@ -23,6 +23,7 @@ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012 by Delphix. All rights reserved. * Copyright 2019 Joyent, Inc. + * Copyright 2021 Oxide Computer Company */ #include <sys/param.h> @@ -182,6 +183,16 @@ module_load(void *fp, const mdb_map_t *map, const char *fullname) return (module_load(fp, map, "libc.so.1")); } + if (strstr(fullname, "ld.so") != NULL) { + /* + * This is even more of a kludge. But if we find something has + * basically tried to load ld, we will always implicitly load + * the list dmod because several binaries and libraries just + * build it as a .o and include it in their ELF object. + */ + (void) mdb_module_load("list", mld->mld_mode); + } + return (0); } diff --git a/usr/src/cmd/mdb/common/modules/libproc/libproc.c b/usr/src/cmd/mdb/common/modules/libproc/libproc.c index 09530ea322..5ec551d5b1 100644 --- a/usr/src/cmd/mdb/common/modules/libproc/libproc.c +++ b/usr/src/cmd/mdb/common/modules/libproc/libproc.c @@ -22,6 +22,9 @@ * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +/* + * Copyright 2021 Oxide Computer Company + */ #include <libproc.h> #include <Pcontrol.h> @@ -221,64 +224,28 @@ pr_addr2map(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) * * Given a ps_prochandle_t, walk all its file_info_t structures. */ -typedef struct { - uintptr_t fiw_next; - int fiw_count; -} file_info_walk_t; - static int pr_file_info_walk_init(mdb_walk_state_t *wsp) { - ps_prochandle_t psp; - file_info_walk_t *fiw; - if (wsp->walk_addr == 0) { mdb_warn("pr_file_info doesn't support global walks\n"); return (WALK_ERR); } - if (mdb_vread(&psp, sizeof (ps_prochandle_t), wsp->walk_addr) == -1) { - mdb_warn("failed to read ps_prochandle at %p", wsp->walk_addr); + wsp->walk_addr += offsetof(ps_prochandle_t, file_head); + if (mdb_layered_walk("list", wsp) == -1) { + mdb_warn("failed to walk layered 'list'"); return (WALK_ERR); } - fiw = mdb_alloc(sizeof (file_info_walk_t), UM_SLEEP); - - fiw->fiw_next = (uintptr_t)psp.file_head.list_forw; - fiw->fiw_count = psp.num_files; - wsp->walk_data = fiw; - return (WALK_NEXT); } static int pr_file_info_walk_step(mdb_walk_state_t *wsp) { - file_info_walk_t *fiw = wsp->walk_data; - file_info_t f; - int status; - - if (fiw->fiw_count == 0) - return (WALK_DONE); - - if (mdb_vread(&f, sizeof (file_info_t), fiw->fiw_next) == -1) { - mdb_warn("failed to read file_info_t at %p", fiw->fiw_next); - return (WALK_ERR); - } - - status = wsp->walk_callback(fiw->fiw_next, &f, wsp->walk_cbdata); - - fiw->fiw_next = (uintptr_t)f.file_list.list_forw; - fiw->fiw_count--; - - return (status); -} - -static void -pr_file_info_walk_fini(mdb_walk_state_t *wsp) -{ - file_info_walk_t *fiw = wsp->walk_data; - mdb_free(fiw, sizeof (file_info_walk_t)); + return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer, + wsp->walk_cbdata)); } /* @@ -358,8 +325,7 @@ static const mdb_dcmd_t dcmds[] = { static const mdb_walker_t walkers[] = { { "pr_file_info", "given a ps_prochandle, walk its file_info " - "structures", pr_file_info_walk_init, pr_file_info_walk_step, - pr_file_info_walk_fini }, + "structures", pr_file_info_walk_init, pr_file_info_walk_step }, { "pr_map_info", "given a ps_prochandle, walk its map_info structures", pr_map_info_walk_init, pr_map_info_walk_step, pr_map_info_walk_fini }, diff --git a/usr/src/cmd/mdb/common/modules/libcmdutils/libcmdutils.c b/usr/src/cmd/mdb/common/modules/list/listmod.c index bff3f1b733..bff3f1b733 100644 --- a/usr/src/cmd/mdb/common/modules/libcmdutils/libcmdutils.c +++ b/usr/src/cmd/mdb/common/modules/list/listmod.c diff --git a/usr/src/cmd/mdb/intel/amd64/libcmdutils/Makefile b/usr/src/cmd/mdb/intel/amd64/list/Makefile index 8ca2a87ffe..145b59fa91 100644 --- a/usr/src/cmd/mdb/intel/amd64/libcmdutils/Makefile +++ b/usr/src/cmd/mdb/intel/amd64/list/Makefile @@ -22,10 +22,10 @@ # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. # -MODULE = libcmdutils.so +MODULE = list.so MDBTGT = proc -MODSRCS = libcmdutils.c \ +MODSRCS = listmod.c \ list.c include ../../../../Makefile.cmd diff --git a/usr/src/cmd/mdb/intel/ia32/libcmdutils/Makefile b/usr/src/cmd/mdb/intel/ia32/list/Makefile index de337c3563..d2f6c709ce 100644 --- a/usr/src/cmd/mdb/intel/ia32/libcmdutils/Makefile +++ b/usr/src/cmd/mdb/intel/ia32/list/Makefile @@ -22,10 +22,10 @@ # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. # -MODULE = libcmdutils.so +MODULE = list.so MDBTGT = proc -MODSRCS = libcmdutils.c \ +MODSRCS = listmod.c \ list.c include ../../../../Makefile.cmd diff --git a/usr/src/cmd/mdb/sparc/v7/libcmdutils/Makefile b/usr/src/cmd/mdb/sparc/v7/list/Makefile index d41231e3e0..88c634f575 100644 --- a/usr/src/cmd/mdb/sparc/v7/libcmdutils/Makefile +++ b/usr/src/cmd/mdb/sparc/v7/list/Makefile @@ -22,10 +22,10 @@ # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. # -MODULE = libcmdutils.so +MODULE = list.so MDBTGT = proc -MODSRCS = libcmdutils.c \ +MODSRCS = listmod.c \ list.c include ../../../../Makefile.cmd diff --git a/usr/src/cmd/mdb/sparc/v9/libcmdutils/Makefile b/usr/src/cmd/mdb/sparc/v9/list/Makefile index 9e1f58c3bf..db1490f81f 100644 --- a/usr/src/cmd/mdb/sparc/v9/libcmdutils/Makefile +++ b/usr/src/cmd/mdb/sparc/v9/list/Makefile @@ -22,10 +22,10 @@ # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. # -MODULE = libcmdutils.so +MODULE = list.so MDBTGT = proc -MODSRCS = libcmdutils.c \ +MODSRCS = listmod.c \ list.c include ../../../../Makefile.cmd diff --git a/usr/src/lib/libproc/Makefile.com b/usr/src/lib/libproc/Makefile.com index 9bc99f1b40..b2f7e00e69 100644 --- a/usr/src/lib/libproc/Makefile.com +++ b/usr/src/lib/libproc/Makefile.com @@ -30,6 +30,7 @@ LIBRARY = libproc.a VERS = .1 CMNOBJS = \ + list.o \ P32ton.o \ Pcontrol.o \ Pcore.o \ @@ -122,6 +123,6 @@ objs/%.o pics/%.o: %.c $(COMPILE.c) -o $@ $< $(POST_PROCESS_O) -objs/%.o pics/%.o: $(SRC)/common/saveargs/%.c +objs/%.o pics/%.o: $(SRC)/common/list/%.c $(COMPILE.c) -o $@ $< $(POST_PROCESS_O) diff --git a/usr/src/lib/libproc/common/Pcontrol.c b/usr/src/lib/libproc/common/Pcontrol.c index eda2737d91..3438109e55 100644 --- a/usr/src/lib/libproc/common/Pcontrol.c +++ b/usr/src/lib/libproc/common/Pcontrol.c @@ -28,6 +28,7 @@ * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright 2015, Joyent, Inc. * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. + * Copyright 2021 Oxide Computer Company */ #include <assert.h> @@ -507,6 +508,7 @@ Pxcreate(const char *file, /* executable file name */ P->agentstatfd = -1; Pinit_ops(&P->ops, &P_live_ops); Pinitsym(P); + Pinitfd(P); /* * Open the /proc/pid files. @@ -810,6 +812,7 @@ again: /* Come back here if we lose it in the Window of Vulnerability */ P->agentstatfd = -1; Pinit_ops(&P->ops, &P_live_ops); Pinitsym(P); + Pinitfd(P); /* * Open the /proc/pid files @@ -1188,6 +1191,7 @@ void Pfree(struct ps_prochandle *P) { uint_t i; + fd_info_t *fip; if (P->ucaddrs != NULL) { free(P->ucaddrs); @@ -1205,16 +1209,15 @@ Pfree(struct ps_prochandle *P) free(P->hashtab); } - while (P->num_fd > 0) { - fd_info_t *fip = list_next(&P->fd_head); - list_unlink(fip); + while ((fip = list_remove_head(&P->fd_head)) != NULL) { proc_fdinfo_free(fip->fd_info); free(fip); - P->num_fd--; } (void) mutex_unlock(&P->proc_lock); (void) mutex_destroy(&P->proc_lock); + free(P->zoneroot); + if (P->agentctlfd >= 0) (void) close(P->agentctlfd); if (P->agentstatfd >= 0) @@ -1679,7 +1682,7 @@ Prelease(struct ps_prochandle *P, int flags) } if (P->state == PS_IDLE) { - file_info_t *fptr = list_next(&P->file_head); + file_info_t *fptr = list_head(&P->file_head); dprintf("Prelease: releasing handle %p PS_IDLE of file %s\n", (void *)P, fptr->file_pname); Pfree(P); @@ -2974,10 +2977,10 @@ Plwp_iter(struct ps_prochandle *P, proc_lwp_f *func, void *cd) */ if (P->state == PS_DEAD) { core_info_t *core = P->data; - lwp_info_t *lwp = list_prev(&core->core_lwp_head); - uint_t i; + lwp_info_t *lwp; - for (i = 0; i < core->core_nlwp; i++, lwp = list_prev(lwp)) { + for (lwp = list_tail(&core->core_lwp_head); lwp != NULL; + lwp = list_prev(&core->core_lwp_head, lwp)) { if (lwp->lwp_psinfo.pr_sname != 'Z' && (rv = func(cd, &lwp->lwp_status)) != 0) break; @@ -3046,10 +3049,10 @@ retry: */ if (P->state == PS_DEAD) { core_info_t *core = P->data; - lwp_info_t *lwp = list_prev(&core->core_lwp_head); - uint_t i; + lwp_info_t *lwp; - for (i = 0; i < core->core_nlwp; i++, lwp = list_prev(lwp)) { + for (lwp = list_tail(&core->core_lwp_head); lwp != NULL; + lwp = list_prev(&core->core_lwp_head, lwp)) { sp = (lwp->lwp_psinfo.pr_sname == 'Z')? NULL : &lwp->lwp_status; if ((rv = func(cd, sp, &lwp->lwp_psinfo)) != 0) @@ -3960,6 +3963,7 @@ Pgrab_ops(pid_t pid, void *data, const ps_ops_t *ops, int flags) P->agentctlfd = -1; P->agentstatfd = -1; Pinitsym(P); + Pinitfd(P); P->data = data; Pread_status(P); diff --git a/usr/src/lib/libproc/common/Pcontrol.h b/usr/src/lib/libproc/common/Pcontrol.h index 6121a7e79b..d701140173 100644 --- a/usr/src/lib/libproc/common/Pcontrol.h +++ b/usr/src/lib/libproc/common/Pcontrol.h @@ -27,6 +27,7 @@ * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright 2018 Joyent, Inc. * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. + * Copyright 2021 Oxide Computer Company */ #ifndef _PCONTROL_H @@ -48,6 +49,7 @@ #include <libproc.h> #include <thread.h> #include <sys/secflags.h> +#include <sys/list.h> #ifdef __cplusplus extern "C" { @@ -94,7 +96,7 @@ typedef struct sym_tbl { /* symbol table */ } sym_tbl_t; typedef struct file_info { /* symbol information for a mapped file */ - plist_t file_list; /* linked list */ + list_node_t file_list; /* linked list */ char file_pname[PATH_MAX]; /* name from prmap_t */ struct map_info *file_map; /* primary (text) mapping */ int file_ref; /* references from map_info_t structures */ @@ -137,7 +139,7 @@ typedef struct map_info { /* description of an address space mapping */ } map_info_t; typedef struct lwp_info { /* per-lwp information from core file */ - plist_t lwp_list; /* linked list */ + list_node_t lwp_list; /* linked list */ lwpid_t lwp_id; /* lwp identifier */ lwpsinfo_t lwp_psinfo; /* /proc/<pid>/lwp/<lwpid>/lwpsinfo data */ lwpstatus_t lwp_status; /* /proc/<pid>/lwp/<lwpid>/lwpstatus data */ @@ -150,7 +152,7 @@ typedef struct lwp_info { /* per-lwp information from core file */ } lwp_info_t; typedef struct fd_info { - plist_t fd_list; /* linked list */ + list_node_t fd_list; /* linked list */ prfdinfo_t *fd_info; /* fd info */ } fd_info_t; @@ -158,9 +160,8 @@ typedef struct core_info { /* information specific to core files */ char core_dmodel; /* data model for core file */ char core_osabi; /* ELF OS ABI */ int core_errno; /* error during initialization if != 0 */ - plist_t core_lwp_head; /* head of list of lwp info */ + list_t core_lwp_head; /* head of list of lwp info */ lwp_info_t *core_lwp; /* current lwp information */ - uint_t core_nlwp; /* number of lwp's in list */ off64_t core_size; /* size of core file in bytes */ char *core_platform; /* platform string from core file */ struct utsname *core_uts; /* uname(2) data from core file */ @@ -225,7 +226,7 @@ struct ps_prochandle { size_t map_count; /* number of mappings */ size_t map_alloc; /* number of mappings allocated */ uint_t num_files; /* number of file elements in file_info */ - plist_t file_head; /* head of mapped files w/ symbol table info */ + list_t file_head; /* head of mapped files w/ symbol table info */ char *execname; /* name of the executable file */ auxv_t *auxv; /* the process's aux vector */ int nauxv; /* number of aux vector entries */ @@ -236,8 +237,7 @@ struct ps_prochandle { uintptr_t *ucaddrs; /* ucontext-list addresses */ uint_t ucnelems; /* number of elements in the ucaddrs list */ char *zoneroot; /* cached path to zone root */ - plist_t fd_head; /* head of file desc info list */ - int num_fd; /* number of file descs in list */ + list_t fd_head; /* head of file desc info list */ uintptr_t map_missing; /* first missing mapping in core due to sig */ siginfo_t killinfo; /* signal that interrupted core dump */ psinfo_t spymaster; /* agent LWP's spymaster, if any */ @@ -275,6 +275,7 @@ extern int dupfd(int, int); extern int set_minfd(void); extern int Pscantext(struct ps_prochandle *); extern void Pinitsym(struct ps_prochandle *); +extern void Pinitfd(struct ps_prochandle *); extern void Preadauxvec(struct ps_prochandle *); extern void optimize_symtab(sym_tbl_t *); extern void Pbuild_file_symtab(struct ps_prochandle *, file_info_t *); diff --git a/usr/src/lib/libproc/common/Pcore.c b/usr/src/lib/libproc/common/Pcore.c index 39424fad67..ab7b75f807 100644 --- a/usr/src/lib/libproc/common/Pcore.c +++ b/usr/src/lib/libproc/common/Pcore.c @@ -28,6 +28,7 @@ * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright 2015 Gary Mills * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. + * Copyright 2021 Oxide Computer Company */ #include <sys/types.h> @@ -213,11 +214,9 @@ Pfini_core(struct ps_prochandle *P, void *data) if (core != NULL) { extern void __priv_free_info(void *); - lwp_info_t *nlwp, *lwp = list_next(&core->core_lwp_head); - int i; + lwp_info_t *lwp; - for (i = 0; i < core->core_nlwp; i++, lwp = nlwp) { - nlwp = list_next(lwp); + while ((lwp = list_remove_head(&core->core_lwp_head)) != NULL) { #ifdef __sparc if (lwp->lwp_gwins != NULL) free(lwp->lwp_gwins); @@ -348,11 +347,10 @@ static lwp_info_t * lwpid2info(struct ps_prochandle *P, lwpid_t id) { core_info_t *core = P->data; - lwp_info_t *lwp = list_next(&core->core_lwp_head); - lwp_info_t *next; - uint_t i; + lwp_info_t *lwp, *prev; - for (i = 0; i < core->core_nlwp; i++, lwp = list_next(lwp)) { + for (lwp = list_head(&core->core_lwp_head); lwp != NULL; + lwp = list_next(&core->core_lwp_head, lwp)) { if (lwp->lwp_id == id) { core->core_lwp = lwp; return (lwp); @@ -362,15 +360,14 @@ lwpid2info(struct ps_prochandle *P, lwpid_t id) } } - next = lwp; + prev = lwp; if ((lwp = calloc(1, sizeof (lwp_info_t))) == NULL) return (NULL); - list_link(lwp, next); + list_insert_before(&core->core_lwp_head, prev, lwp); lwp->lwp_id = id; core->core_lwp = lwp; - core->core_nlwp++; return (lwp); } @@ -2396,6 +2393,7 @@ Pfgrab_core(int core_fd, const char *aout_path, int *perr) Pinit_ops(&P->ops, &P_core_ops); Pinitsym(P); + Pinitfd(P); /* * Fstat and open the core file and make sure it is a valid ELF core. @@ -2418,7 +2416,8 @@ Pfgrab_core(int core_fd, const char *aout_path, int *perr) } P->data = core_info; - list_link(&core_info->core_lwp_head, NULL); + list_create(&core_info->core_lwp_head, sizeof (lwp_info_t), + offsetof(lwp_info_t, lwp_list)); core_info->core_size = stbuf.st_size; /* * In the days before adjustable core file content, this was the @@ -2611,17 +2610,15 @@ Pfgrab_core(int core_fd, const char *aout_path, int *perr) #ifdef __x86 if (from_linux) { - size_t tcount, pid; + size_t pid; lwp_info_t *lwp; P->status.pr_dmodel = core_info->core_dmodel; - lwp = list_next(&core_info->core_lwp_head); - pid = P->status.pr_pid; - for (tcount = 0; tcount < core_info->core_nlwp; - tcount++, lwp = list_next(lwp)) { + for (lwp = list_head(&core_info->core_lwp_head); lwp != NULL; + lwp = list_next(&core_info->core_lwp_head, lwp)) { dprintf("Linux thread with id %d\n", lwp->lwp_id); /* @@ -2810,7 +2807,7 @@ Pfgrab_core(int core_fd, const char *aout_path, int *perr) (void) memset(fp, 0, sizeof (file_info_t)); - list_link(fp, &P->file_head); + list_insert_head(&P->file_head, fp); tmp->map_file = fp; P->num_files++; diff --git a/usr/src/lib/libproc/common/Pfdinfo.c b/usr/src/lib/libproc/common/Pfdinfo.c index c822ec8434..36978d8e60 100644 --- a/usr/src/lib/libproc/common/Pfdinfo.c +++ b/usr/src/lib/libproc/common/Pfdinfo.c @@ -15,6 +15,7 @@ /* * Copyright (c) 2013 Joyent, Inc. All Rights reserved. * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. + * Copyright 2021 Oxide Computer Company */ #include <limits.h> @@ -24,6 +25,7 @@ #include <dirent.h> #include <ctype.h> #include <string.h> +#include <stddef.h> #include <sys/mkdev.h> #include "libproc.h" @@ -34,6 +36,13 @@ * Pfdinfo.c - obtain open file information. */ +void +Pinitfd(struct ps_prochandle *P) +{ + list_create(&P->fd_head, sizeof (fd_info_t), + offsetof(fd_info_t, fd_list)); +} + /* * Allocate an fd_info structure and stick it on the list. * (Unless one already exists.) The list is sorted in @@ -43,16 +52,10 @@ fd_info_t * Pfd2info(struct ps_prochandle *P, int fd) { - fd_info_t *fip = list_next(&P->fd_head); - fd_info_t *next; - int i; - - if (fip == NULL) { - list_link(&P->fd_head, NULL); - fip = list_next(&P->fd_head); - } + fd_info_t *fip, *next = NULL; - for (i = 0; i < P->num_fd; i++, fip = list_next(fip)) { + for (fip = list_head(&P->fd_head); fip != NULL; + fip = list_next(&P->fd_head, fip)) { if (fip->fd_info == NULL) continue; @@ -68,8 +71,7 @@ Pfd2info(struct ps_prochandle *P, int fd) if ((fip = calloc(1, sizeof (*fip))) == NULL) return (NULL); - list_link(fip, next ? next : (void *)&(P->fd_head)); - P->num_fd++; + list_insert_before(&P->fd_head, next, fip); return (fip); } @@ -108,7 +110,7 @@ load_fdinfo(struct ps_prochandle *P) * This is an edge case it isn't worth adding additional state to * to eliminate. */ - if (P->num_fd > 0) + if (!list_is_empty(&P->fd_head)) return; if (P->state == PS_DEAD || P->state == PS_IDLE) @@ -128,9 +130,8 @@ Pfdinfo_iter(struct ps_prochandle *P, proc_fdinfo_f *func, void *cd) /* NB: We walk the list backwards. */ - for (fip = list_prev(&P->fd_head); - fip != (void *)&P->fd_head && fip != NULL; - fip = list_prev(fip)) { + for (fip = list_tail(&P->fd_head); fip != NULL; + fip = list_prev(&P->fd_head, fip)) { if ((rv = func(cd, fip->fd_info)) != 0) return (rv); } diff --git a/usr/src/lib/libproc/common/Pgcore.c b/usr/src/lib/libproc/common/Pgcore.c index 8890d85efc..874579f055 100644 --- a/usr/src/lib/libproc/common/Pgcore.c +++ b/usr/src/lib/libproc/common/Pgcore.c @@ -636,14 +636,13 @@ count_sections(pgcore_t *pgc) { struct ps_prochandle *P = pgc->P; file_info_t *fptr; - uint_t cnt; uint_t nshdrs = 0; if (!(pgc->pgc_content & (CC_CONTENT_CTF | CC_CONTENT_SYMTAB))) return (0); - fptr = list_next(&P->file_head); - for (cnt = P->num_files; cnt > 0; cnt--, fptr = list_next(fptr)) { + for (fptr = list_head(&P->file_head); fptr != NULL; + fptr = list_next(&P->file_head, fptr)) { int hit_symtab = 0; Pbuild_file_symtab(P, fptr); @@ -773,14 +772,13 @@ dump_sections(pgcore_t *pgc) { struct ps_prochandle *P = pgc->P; file_info_t *fptr; - uint_t cnt; uint_t index = 1; if (!(pgc->pgc_content & (CC_CONTENT_CTF | CC_CONTENT_SYMTAB))) return (0); - fptr = list_next(&P->file_head); - for (cnt = P->num_files; cnt > 0; cnt--, fptr = list_next(fptr)) { + for (fptr = list_head(&P->file_head); fptr != NULL; + fptr = list_next(&P->file_head, fptr)) { int hit_symtab = 0; Pbuild_file_symtab(P, fptr); diff --git a/usr/src/lib/libproc/common/Pidle.c b/usr/src/lib/libproc/common/Pidle.c index db00268f9b..eaf6c63078 100644 --- a/usr/src/lib/libproc/common/Pidle.c +++ b/usr/src/lib/libproc/common/Pidle.c @@ -191,6 +191,7 @@ Pgrab_file(const char *fname, int *perr) P->info_valid = -1; Pinit_ops(&P->ops, &P_idle_ops); Pinitsym(P); + Pinitfd(P); if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { *perr = G_ELF; @@ -241,7 +242,7 @@ Pgrab_file(const char *fname, int *perr) } P->num_files++; - list_link(fp, &P->file_head); + list_insert_head(&P->file_head, fp); if (gelf_getehdr(elf, &ehdr) == NULL) { *perr = G_STRANGE; diff --git a/usr/src/lib/libproc/common/Plwpregs.c b/usr/src/lib/libproc/common/Plwpregs.c index bf35c91ccf..ffc3c6e1e3 100644 --- a/usr/src/lib/libproc/common/Plwpregs.c +++ b/usr/src/lib/libproc/common/Plwpregs.c @@ -52,10 +52,10 @@ static lwp_info_t * getlwpcore(struct ps_prochandle *P, lwpid_t lwpid) { core_info_t *core = P->data; - lwp_info_t *lwp = list_next(&core->core_lwp_head); - uint_t i; + lwp_info_t *lwp; - for (i = 0; i < core->core_nlwp; i++, lwp = list_next(lwp)) { + for (lwp = list_head(&core->core_lwp_head); lwp != NULL; + lwp = list_next(&core->core_lwp_head, lwp)) { if (lwp->lwp_id == lwpid) return (lwp); } diff --git a/usr/src/lib/libproc/common/Pservice.c b/usr/src/lib/libproc/common/Pservice.c index 03d013364f..361cf4ab98 100644 --- a/usr/src/lib/libproc/common/Pservice.c +++ b/usr/src/lib/libproc/common/Pservice.c @@ -177,10 +177,10 @@ ps_lgetxregsize(struct ps_prochandle *P, lwpid_t lwpid, int *xrsize) if (P->state == PS_DEAD) { core_info_t *core = P->data; - lwp_info_t *lwp = list_next(&core->core_lwp_head); - uint_t i; + lwp_info_t *lwp; - for (i = 0; i < core->core_nlwp; i++, lwp = list_next(lwp)) { + for (lwp = list_head(&core->core_lwp_head); lwp != NULL; + lwp = list_next(&core->core_lwp_head, lwp)) { if (lwp->lwp_id == lwpid) { if (lwp->lwp_xregs != NULL) *xrsize = sizeof (prxregset_t); @@ -332,7 +332,7 @@ ps_pbrandname(struct ps_prochandle *P, char *buf, size_t len) */ ps_err_e ps_pglobal_lookup(struct ps_prochandle *P, const char *object_name, - const char *sym_name, psaddr_t *sym_addr) + const char *sym_name, psaddr_t *sym_addr) { GElf_Sym sym; @@ -355,7 +355,7 @@ ps_pglobal_lookup(struct ps_prochandle *P, const char *object_name, */ ps_err_e ps_pglobal_sym(struct ps_prochandle *P, const char *object_name, - const char *sym_name, ps_sym_t *symp) + const char *sym_name, ps_sym_t *symp) { #if defined(_ILP32) GElf_Sym sym; diff --git a/usr/src/lib/libproc/common/Psymtab.c b/usr/src/lib/libproc/common/Psymtab.c index 4d89eba672..7527c7e10c 100644 --- a/usr/src/lib/libproc/common/Psymtab.c +++ b/usr/src/lib/libproc/common/Psymtab.c @@ -23,6 +23,7 @@ * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2016 Joyent, Inc. * Copyright (c) 2013 by Delphix. All rights reserved. + * Copyright 2021 Oxide Computer Company */ #include <assert.h> @@ -197,7 +198,7 @@ file_info_new(struct ps_prochandle *P, map_info_t *mptr) if ((fptr = calloc(1, sizeof (file_info_t))) == NULL) return (NULL); - list_link(fptr, &P->file_head); + list_insert_tail(&P->file_head, fptr); (void) strcpy(fptr->file_pname, mptr->map_pmap.pr_mapname); mptr->map_file = fptr; fptr->file_ref = 1; @@ -262,7 +263,7 @@ static void file_info_free(struct ps_prochandle *P, file_info_t *fptr) { if (--fptr->file_ref == 0) { - list_unlink(fptr); + list_remove(&P->file_head, fptr); if (fptr->file_symtab.sym_elf) { (void) elf_end(fptr->file_symtab.sym_elf); free(fptr->file_symtab.sym_elfmem); @@ -297,10 +298,8 @@ file_info_free(struct ps_prochandle *P, file_info_t *fptr) (void) elf_end(fptr->file_dbgelf); if (fptr->file_dbgfile >= 0) (void) close(fptr->file_dbgfile); - if (fptr->file_ctfp) { - ctf_close(fptr->file_ctfp); - free(fptr->file_ctf_buf); - } + ctf_close(fptr->file_ctfp); + free(fptr->file_ctf_buf); if (fptr->file_saddrs) free(fptr->file_saddrs); free(fptr); @@ -591,12 +590,11 @@ void Pupdate_syms(struct ps_prochandle *P) { file_info_t *fptr; - int i; Pupdate_maps(P); - for (i = 0, fptr = list_next(&P->file_head); i < P->num_files; - i++, fptr = list_next(fptr)) { + for (fptr = list_head(&P->file_head); fptr != NULL; + fptr = list_next(&P->file_head, fptr)) { Pbuild_file_symtab(P, fptr); (void) Pbuild_file_ctf(P, fptr); } @@ -916,7 +914,7 @@ Plmid_to_ctf(struct ps_prochandle *P, Lmid_t lmid, const char *name) */ if (P->state == PS_IDLE && name == PR_OBJ_EXEC && P->info_valid == 1 && P->num_files == 1 && P->mappings == NULL) { - fptr = list_next(&P->file_head); + fptr = list_head(&P->file_head); } if (fptr == NULL) { @@ -1050,7 +1048,6 @@ build_map_symtab(struct ps_prochandle *P, map_info_t *mptr) { prmap_t *pmap = &mptr->map_pmap; file_info_t *fptr; - uint_t i; if ((fptr = mptr->map_file) != NULL) { Pbuild_file_symtab(P, fptr); @@ -1064,8 +1061,8 @@ build_map_symtab(struct ps_prochandle *P, map_info_t *mptr) * Attempt to find a matching file. * (A file can be mapped at several different addresses.) */ - for (i = 0, fptr = list_next(&P->file_head); i < P->num_files; - i++, fptr = list_next(fptr)) { + for (fptr = list_head(&P->file_head); fptr != NULL; + fptr = list_next(&P->file_head, fptr)) { if (strcmp(fptr->file_pname, pmap->pr_mapname) == 0 && fptr->file_lo && is_mapping_in_file(P, mptr, fptr)) { mptr->map_file = fptr; @@ -2967,7 +2964,7 @@ Pxlookup_by_name( /* create all the file_info_t's for all the mappings */ (void) Prd_agent(P); cnt = P->num_files; - fptr = list_next(&P->file_head); + fptr = list_head(&P->file_head); } else { cnt = 1; if ((mptr = object_name_to_map(P, lmid, oname)) == NULL || @@ -2982,7 +2979,7 @@ Pxlookup_by_name( * This means that a name such as "puts" will match the puts function * in libc instead of matching the puts PLT entry in the a.out file. */ - for (; cnt > 0; cnt--, fptr = list_next(fptr)) { + for (; cnt > 0; cnt--, fptr = list_next(&P->file_head, fptr)) { Pbuild_file_symtab(P, fptr); if (fptr->file_elf == NULL) @@ -3100,14 +3097,13 @@ i_Pobject_iter(struct ps_prochandle *P, boolean_t lmresolve, { map_info_t *mptr; file_info_t *fptr; - uint_t cnt; int rc = 0; (void) Prd_agent(P); /* create file_info_t's for all the mappings */ Pupdate_maps(P); - for (cnt = P->num_files, fptr = list_next(&P->file_head); - cnt; cnt--, fptr = list_next(fptr)) { + for (fptr = list_head(&P->file_head); fptr != NULL; + fptr = list_next(&P->file_head, fptr)) { const char *lname; if (lmresolve && (fptr->file_rname != NULL)) @@ -3414,7 +3410,8 @@ void Pinitsym(struct ps_prochandle *P) { P->num_files = 0; - list_link(&P->file_head, NULL); + list_create(&P->file_head, sizeof (file_info_t), + offsetof(file_info_t, file_list)); } /* diff --git a/usr/src/lib/libproc/common/Putil.c b/usr/src/lib/libproc/common/Putil.c index e42ac08de5..ae66e08c85 100644 --- a/usr/src/lib/libproc/common/Putil.c +++ b/usr/src/lib/libproc/common/Putil.c @@ -37,40 +37,6 @@ #include "Putil.h" /* - * Place the new element on the list prior to the existing element. - */ -void -list_link(void *new, void *existing) -{ - plist_t *p = new; - plist_t *q = existing; - - if (q) { - p->list_forw = q; - p->list_back = q->list_back; - q->list_back->list_forw = p; - q->list_back = p; - } else { - p->list_forw = p->list_back = p; - } -} - -/* - * Unchain the specified element from a list. - */ -void -list_unlink(void *old) -{ - plist_t *p = old; - - if (p->list_forw != p) { - p->list_back->list_forw = p->list_forw; - p->list_forw->list_back = p->list_back; - } - p->list_forw = p->list_back = p; -} - -/* * Routines to manipulate sigset_t, fltset_t, or sysset_t. These routines * are provided as equivalents for the <sys/procfs.h> macros prfillset, * premptyset, praddset, and prdelset. These functions are preferable diff --git a/usr/src/lib/libproc/common/Putil.h b/usr/src/lib/libproc/common/Putil.h index 57814a9a7f..381d164a69 100644 --- a/usr/src/lib/libproc/common/Putil.h +++ b/usr/src/lib/libproc/common/Putil.h @@ -35,23 +35,6 @@ extern "C" { #endif /* - * Circular doubly-linked list: - */ -typedef struct P_list { - struct P_list *list_forw; - struct P_list *list_back; -} plist_t; - -/* - * Routines to manipulate linked lists: - */ -extern void list_link(void *, void *); -extern void list_unlink(void *); - -#define list_next(elem) (void *)(((plist_t *)(elem))->list_forw) -#define list_prev(elem) (void *)(((plist_t *)(elem))->list_back) - -/* * Routines to manipulate sigset_t, fltset_t, or sysset_t. */ extern void prset_fill(void *, size_t); diff --git a/usr/src/lib/libproc/sparc/Pisadep.c b/usr/src/lib/libproc/sparc/Pisadep.c index c3bbd99788..29575d05ae 100644 --- a/usr/src/lib/libproc/sparc/Pisadep.c +++ b/usr/src/lib/libproc/sparc/Pisadep.c @@ -188,11 +188,11 @@ read_gwin(struct ps_prochandle *P, struct rwindow *rwp, uintptr_t sp) if (P->state == PS_DEAD) { core_info_t *core = P->data; - lwp_info_t *lwp = list_next(&core->core_lwp_head); - uint_t n; + lwp_info_t *lwp; int i; - for (n = 0; n < core->core_nlwp; n++, lwp = list_next(lwp)) { + for (lwp = list_head(&core->core_lwp_head); lwp != NULL; + lwp = list_next(&core->core_lwp_head, lwp)) { gwindows_t *gwin = lwp->lwp_gwins; if (gwin == NULL) @@ -253,7 +253,7 @@ ucontext_n_to_prgregs(const ucontext_t *src, prgregset_t dst) int Pstack_iter(struct ps_prochandle *P, const prgregset_t regs, - proc_stack_f *func, void *arg) + proc_stack_f *func, void *arg) { prgreg_t *prevfp = NULL; uint_t pfpsize = 0; diff --git a/usr/src/lib/libproc/sparcv9/Pisadep.c b/usr/src/lib/libproc/sparcv9/Pisadep.c index 6aff474ec0..69a212f998 100644 --- a/usr/src/lib/libproc/sparcv9/Pisadep.c +++ b/usr/src/lib/libproc/sparcv9/Pisadep.c @@ -236,11 +236,11 @@ read_gwin(struct ps_prochandle *P, struct rwindow *rwp, uintptr_t sp) if (P->state == PS_DEAD) { core_info_t *core = P->data; - lwp_info_t *lwp = list_next(&core->core_lwp_head); - uint_t n; + lwp_info_t *lwp; int i; - for (n = 0; n < core->core_nlwp; n++, lwp = list_next(lwp)) { + for (lwp = list_head(&core->core_lwp_head); lwp != NULL; + lwp = list_next(&core->core_lwp_head, lwp)) { gwindows_t *gwin = lwp->lwp_gwins; if (gwin == NULL) @@ -335,7 +335,7 @@ ucontext_32_to_prgregs(const ucontext32_t *src, prgregset_t dst) int Pstack_iter(struct ps_prochandle *P, const prgregset_t regs, - proc_stack_f *func, void *arg) + proc_stack_f *func, void *arg) { prgreg_t *prevfp = NULL; uint_t pfpsize = 0; diff --git a/usr/src/pkg/manifests/developer-debug-mdb.mf b/usr/src/pkg/manifests/developer-debug-mdb.mf index 63c7982c3c..4e2322ad1c 100644 --- a/usr/src/pkg/manifests/developer-debug-mdb.mf +++ b/usr/src/pkg/manifests/developer-debug-mdb.mf @@ -211,7 +211,6 @@ file path=usr/lib/mdb/kvm/$(ARCH64)/usba.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/ld.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libavl.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libc.so group=sys mode=0555 -file path=usr/lib/mdb/proc/$(ARCH64)/libcmdutils.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libnvpair.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libproc.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libpython$(PYTHON_VERSION).so group=sys \ @@ -222,13 +221,13 @@ file path=usr/lib/mdb/proc/$(ARCH64)/libsysevent.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libtopo.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libumem.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libuutil.so group=sys mode=0555 +file path=usr/lib/mdb/proc/$(ARCH64)/list.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/mdb_ds.so group=sys mode=0555 $(i386_ONLY)file path=usr/lib/mdb/proc/$(ARCH64)/mdb_test.so group=sys \ mode=0555 file path=usr/lib/mdb/proc/ld.so group=sys mode=0555 file path=usr/lib/mdb/proc/libavl.so group=sys mode=0555 file path=usr/lib/mdb/proc/libc.so group=sys mode=0555 -file path=usr/lib/mdb/proc/libcmdutils.so group=sys mode=0555 file path=usr/lib/mdb/proc/libnvpair.so group=sys mode=0555 file path=usr/lib/mdb/proc/libproc.so group=sys mode=0555 file path=usr/lib/mdb/proc/libpython$(PYTHON_VERSION).so group=sys mode=0555 @@ -237,6 +236,7 @@ file path=usr/lib/mdb/proc/libsysevent.so group=sys mode=0555 file path=usr/lib/mdb/proc/libtopo.so group=sys mode=0555 file path=usr/lib/mdb/proc/libumem.so group=sys mode=0555 file path=usr/lib/mdb/proc/libuutil.so group=sys mode=0555 +file path=usr/lib/mdb/proc/list.so group=sys mode=0555 file path=usr/lib/mdb/proc/mdb_ds.so group=sys mode=0555 file path=usr/lib/mdb/proc/svc.configd.so group=sys mode=0555 file path=usr/lib/mdb/proc/svc.startd.so group=sys mode=0555 diff --git a/usr/src/tools/scripts/onu.sh.in b/usr/src/tools/scripts/onu.sh.in index c461dfcf11..fb77577de8 100644 --- a/usr/src/tools/scripts/onu.sh.in +++ b/usr/src/tools/scripts/onu.sh.in @@ -104,7 +104,7 @@ prepare_image() print "**\n** Preparing for ONU from $distribution\n**" case $distribution in - omnios) + omnios|helios) # This removes files from the image that cause conflicts with # stock illumos-gate, and removes omnios-only kernel drivers # etc. @@ -162,7 +162,7 @@ case $distribution in openindiana) nlbrand=nlipkg ;; - omnios) + omnios|helios) nlbrand=ipkg ;; *) |