003 File Manager
Current Path:
/usr/src/cddl/contrib/opensolaris/lib/libdtrace/common
usr
/
src
/
cddl
/
contrib
/
opensolaris
/
lib
/
libdtrace
/
common
/
📁
..
📄
drti.c
(5.62 KB)
📄
dt_aggregate.c
(51.43 KB)
📄
dt_as.c
(13.49 KB)
📄
dt_as.h
(1.89 KB)
📄
dt_buf.c
(4.12 KB)
📄
dt_buf.h
(2.01 KB)
📄
dt_cc.c
(71.28 KB)
📄
dt_cg.c
(61.79 KB)
📄
dt_consume.c
(74.05 KB)
📄
dt_decl.c
(30.71 KB)
📄
dt_decl.h
(4.45 KB)
📄
dt_dis.c
(14.65 KB)
📄
dt_dof.c
(28.19 KB)
📄
dt_dof.h
(2.06 KB)
📄
dt_error.c
(8.15 KB)
📄
dt_errtags.h
(13.26 KB)
📄
dt_grammar.y
(23.18 KB)
📄
dt_handle.c
(11.62 KB)
📄
dt_ident.c
(26.34 KB)
📄
dt_ident.h
(7.79 KB)
📄
dt_impl.h
(32.49 KB)
📄
dt_inttab.c
(2.56 KB)
📄
dt_inttab.h
(2.28 KB)
📄
dt_lex.l
(23.64 KB)
📄
dt_link.c
(49.01 KB)
📄
dt_list.c
(2.67 KB)
📄
dt_list.h
(1.52 KB)
📄
dt_map.c
(10.91 KB)
📄
dt_module.c
(45.28 KB)
📄
dt_module.h
(2.1 KB)
📄
dt_open.c
(61.61 KB)
📄
dt_options.c
(25.04 KB)
📄
dt_parser.c
(144.81 KB)
📄
dt_parser.h
(11.64 KB)
📄
dt_pcb.c
(5.56 KB)
📄
dt_pcb.h
(4.38 KB)
📄
dt_pid.c
(24.9 KB)
📄
dt_pid.h
(2.03 KB)
📄
dt_pq.c
(2.83 KB)
📄
dt_pq.h
(1.26 KB)
📄
dt_pragma.c
(15.55 KB)
📄
dt_print.c
(18.57 KB)
📄
dt_printf.c
(55.53 KB)
📄
dt_printf.h
(4.87 KB)
📄
dt_proc.c
(36.39 KB)
📄
dt_proc.h
(4.54 KB)
📄
dt_program.c
(14.32 KB)
📄
dt_program.h
(1.86 KB)
📄
dt_provider.c
(22.95 KB)
📄
dt_provider.h
(4.37 KB)
📄
dt_regset.c
(2.88 KB)
📄
dt_regset.h
(1.57 KB)
📄
dt_string.c
(5.75 KB)
📄
dt_string.h
(1.31 KB)
📄
dt_strtab.c
(5.74 KB)
📄
dt_strtab.h
(2.42 KB)
📄
dt_subr.c
(22.59 KB)
📄
dt_sugar.c
(13.71 KB)
📄
dt_work.c
(8.12 KB)
📄
dt_xlator.c
(11.3 KB)
📄
dt_xlator.h
(3.09 KB)
📄
dtrace.h
(23.64 KB)
📄
mkerrno.sh
(1.2 KB)
📄
mkerrtags.sh
(1.4 KB)
📄
mknames.sh
(1.33 KB)
📄
mksignal.sh
(1.22 KB)
Editing: dt_strtab.c
/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Portions Copyright 2016 Pedro Giffuni. All rights reserved. */ #pragma ident "%Z%%M% %I% %E% SMI" #include <sys/types.h> #include <sys/sysmacros.h> #include <strings.h> #include <stdlib.h> #include <assert.h> #include <dt_strtab.h> #include <dt_impl.h> static int dt_strtab_grow(dt_strtab_t *sp) { char *ptr, **bufs; if ((ptr = malloc(sp->str_bufsz)) == NULL) return (-1); bufs = realloc(sp->str_bufs, (sp->str_nbufs + 1) * sizeof (char *)); if (bufs == NULL) { free(ptr); return (-1); } sp->str_nbufs++; sp->str_bufs = bufs; sp->str_ptr = ptr; sp->str_bufs[sp->str_nbufs - 1] = sp->str_ptr; return (0); } dt_strtab_t * dt_strtab_create(size_t bufsz) { dt_strtab_t *sp = malloc(sizeof (dt_strtab_t)); uint_t nbuckets = _dtrace_strbuckets; assert(bufsz != 0); if (sp == NULL) return (NULL); bzero(sp, sizeof (dt_strtab_t)); sp->str_hash = calloc(nbuckets, sizeof (dt_strhash_t *)); if (sp->str_hash == NULL) goto err; sp->str_hashsz = nbuckets; sp->str_bufs = NULL; sp->str_ptr = NULL; sp->str_nbufs = 0; sp->str_bufsz = bufsz; sp->str_nstrs = 1; sp->str_size = 1; if (dt_strtab_grow(sp) == -1) goto err; *sp->str_ptr++ = '\0'; return (sp); err: dt_strtab_destroy(sp); return (NULL); } void dt_strtab_destroy(dt_strtab_t *sp) { dt_strhash_t *hp, *hq; ulong_t i; for (i = 0; i < sp->str_hashsz; i++) { for (hp = sp->str_hash[i]; hp != NULL; hp = hq) { hq = hp->str_next; free(hp); } } for (i = 0; i < sp->str_nbufs; i++) free(sp->str_bufs[i]); if (sp->str_hash != NULL) free(sp->str_hash); if (sp->str_bufs != NULL) free(sp->str_bufs); free(sp); } ulong_t dt_strtab_hash(const char *key, size_t *len) { ulong_t g, h = 0; const char *p; size_t n = 0; for (p = key; *p != '\0'; p++, n++) { h = (h << 4) + *p; if ((g = (h & 0xf0000000)) != 0) { h ^= (g >> 24); h ^= g; } } if (len != NULL) *len = n; return (h); } static int dt_strtab_compare(dt_strtab_t *sp, dt_strhash_t *hp, const char *str, size_t len) { ulong_t b = hp->str_buf; const char *buf = hp->str_data; size_t resid, n; int rv; while (len != 0) { if (buf == sp->str_bufs[b] + sp->str_bufsz) buf = sp->str_bufs[++b]; resid = sp->str_bufs[b] + sp->str_bufsz - buf; n = MIN(resid, len); if ((rv = strncmp(buf, str, n)) != 0) return (rv); buf += n; str += n; len -= n; } return (0); } static int dt_strtab_copyin(dt_strtab_t *sp, const char *str, size_t len) { char *old_p = sp->str_ptr; ulong_t old_n = sp->str_nbufs; ulong_t b = sp->str_nbufs - 1; size_t resid, n; while (len != 0) { if (sp->str_ptr == sp->str_bufs[b] + sp->str_bufsz) { if (dt_strtab_grow(sp) == -1) goto err; b++; } resid = sp->str_bufs[b] + sp->str_bufsz - sp->str_ptr; n = MIN(resid, len); bcopy(str, sp->str_ptr, n); sp->str_ptr += n; str += n; len -= n; } return (0); err: while (sp->str_nbufs != old_n) free(sp->str_bufs[--sp->str_nbufs]); sp->str_ptr = old_p; return (-1); } boolean_t dt_strtab_empty(dt_strtab_t *sp) { /* Always contains "\0". */ return (sp->str_nstrs == 1); } ssize_t dt_strtab_index(dt_strtab_t *sp, const char *str) { dt_strhash_t *hp; size_t len; ulong_t h; if (str == NULL || str[0] == '\0') return (0); /* we keep a \0 at offset 0 to simplify things */ h = dt_strtab_hash(str, &len) % sp->str_hashsz; for (hp = sp->str_hash[h]; hp != NULL; hp = hp->str_next) { if (dt_strtab_compare(sp, hp, str, len + 1) == 0) return (hp->str_off); } return (-1); } ssize_t dt_strtab_insert(dt_strtab_t *sp, const char *str) { dt_strhash_t *hp; size_t len; ssize_t off; ulong_t h; if ((off = dt_strtab_index(sp, str)) != -1) return (off); h = dt_strtab_hash(str, &len) % sp->str_hashsz; /* * Create a new hash bucket, initialize it, and insert it at the front * of the hash chain for the appropriate bucket. */ if ((hp = malloc(sizeof (dt_strhash_t))) == NULL) return (-1L); hp->str_data = sp->str_ptr; hp->str_buf = sp->str_nbufs - 1; hp->str_off = sp->str_size; hp->str_len = len; hp->str_next = sp->str_hash[h]; /* * Now copy the string data into our buffer list, and then update * the global counts of strings and bytes. Return str's byte offset. */ if (dt_strtab_copyin(sp, str, len + 1) == -1) { free(hp); return (-1L); } sp->str_nstrs++; sp->str_size += len + 1; sp->str_hash[h] = hp; return (hp->str_off); } size_t dt_strtab_size(const dt_strtab_t *sp) { return (sp->str_size); } ssize_t dt_strtab_write(const dt_strtab_t *sp, dt_strtab_write_f *func, void *private) { ssize_t res, total = 0; ulong_t i; size_t n; for (i = 0; i < sp->str_nbufs; i++, total += res) { if (i == sp->str_nbufs - 1) n = sp->str_ptr - sp->str_bufs[i]; else n = sp->str_bufsz; if ((res = func(sp->str_bufs[i], n, total, private)) <= 0) break; } if (total == 0 && sp->str_size != 0) return (-1); return (total); }
Upload File
Create Folder