Print this page
patch mdb_var_alloc


  21  */
  22 /*
  23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <mdb/mdb_debug.h>
  30 #include <mdb/mdb_string.h>
  31 #include <mdb/mdb_modapi.h>
  32 #include <mdb/mdb_err.h>
  33 #include <mdb/mdb_nv.h>
  34 #include <mdb/mdb.h>
  35 
  36 #define NV_NAME(v) \
  37         (((v)->v_flags & MDB_NV_EXTNAME) ? (v)->v_ename : (v)->v_lname)
  38 
  39 #define NV_SIZE(v) \
  40         (((v)->v_flags & MDB_NV_EXTNAME) ? sizeof (mdb_var_t) : \
  41         sizeof (mdb_var_t) + MDB_NV_NAMELEN - 1)
  42 
  43 #define NV_HASHSZ       211
  44 
  45 static size_t
  46 nv_hashstring(const char *key)
  47 {
  48         size_t g, h = 0;
  49         const char *p;
  50 
  51         ASSERT(key != NULL);
  52 
  53         for (p = key; *p != '\0'; p++) {
  54                 h = (h << 4) + *p;
  55 
  56                 if ((g = (h & 0xf0000000)) != 0) {
  57                         h ^= (g >> 24);
  58                         h ^= g;
  59                 }
  60         }
  61 
  62         return (h);
  63 }
  64 
  65 static mdb_var_t *
  66 nv_var_alloc(const char *name, const mdb_nv_disc_t *disc,
  67         uintmax_t value, uint_t flags, uint_t um_flags, mdb_var_t *next)
  68 {
  69         size_t nbytes = (flags & MDB_NV_EXTNAME) ? sizeof (mdb_var_t) :
  70             (sizeof (mdb_var_t) + MDB_NV_NAMELEN - 1);





  71 
  72         mdb_var_t *v = mdb_alloc(nbytes, um_flags);
  73 
  74         if (v == NULL)
  75                 return (NULL);
  76 
  77         if (flags & MDB_NV_EXTNAME) {
  78                 v->v_ename = name;
  79                 v->v_lname[0] = 0;
  80         } else {
  81                 (void) strncpy(v->v_lname, name, MDB_NV_NAMELEN - 1);
  82                 v->v_lname[MDB_NV_NAMELEN - 1] = '\0';
  83                 v->v_ename = NULL;
  84         }
  85 
  86         v->v_uvalue = value;
  87         v->v_flags = flags & ~(MDB_NV_SILENT | MDB_NV_INTERPOS);
  88         v->v_disc = disc;
  89         v->v_next = next;
  90 
  91         return (v);
  92 }
  93 
  94 static void
  95 nv_var_free(mdb_var_t *v, uint_t um_flags)
  96 {
  97         if (um_flags & UM_GC)
  98                 return;
  99 
 100         if (v->v_flags & MDB_NV_OVERLOAD) {
 101                 mdb_var_t *w, *nw;
 102 




  21  */
  22 /*
  23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <mdb/mdb_debug.h>
  30 #include <mdb/mdb_string.h>
  31 #include <mdb/mdb_modapi.h>
  32 #include <mdb/mdb_err.h>
  33 #include <mdb/mdb_nv.h>
  34 #include <mdb/mdb.h>
  35 
  36 #define NV_NAME(v) \
  37         (((v)->v_flags & MDB_NV_EXTNAME) ? (v)->v_ename : (v)->v_lname)
  38 
  39 #define NV_SIZE(v) \
  40         (((v)->v_flags & MDB_NV_EXTNAME) ? sizeof (mdb_var_t) : \
  41         sizeof (mdb_var_t) + strlen((v)->v_lname))
  42 
  43 #define NV_HASHSZ       211
  44 
  45 static size_t
  46 nv_hashstring(const char *key)
  47 {
  48         size_t g, h = 0;
  49         const char *p;
  50 
  51         ASSERT(key != NULL);
  52 
  53         for (p = key; *p != '\0'; p++) {
  54                 h = (h << 4) + *p;
  55 
  56                 if ((g = (h & 0xf0000000)) != 0) {
  57                         h ^= (g >> 24);
  58                         h ^= g;
  59                 }
  60         }
  61 
  62         return (h);
  63 }
  64 
  65 static mdb_var_t *
  66 nv_var_alloc(const char *name, const mdb_nv_disc_t *disc,
  67         uintmax_t value, uint_t flags, uint_t um_flags, mdb_var_t *next)
  68 {
  69         size_t nbytes;
  70         mdb_var_t *v;
  71 
  72         if (flags & MDB_NV_EXTNAME)
  73                 nbytes = sizeof (mdb_var_t);
  74         else
  75                 nbytes = sizeof (mdb_var_t) + strlen(name);
  76 
  77         v = mdb_alloc(nbytes, um_flags);
  78 
  79         if (v == NULL)
  80                 return (NULL);
  81 
  82         if (flags & MDB_NV_EXTNAME) {
  83                 v->v_ename = name;
  84                 v->v_lname[0] = '\0';
  85         } else {
  86                 strcpy(v->v_lname, name);

  87                 v->v_ename = NULL;
  88         }
  89 
  90         v->v_uvalue = value;
  91         v->v_flags = flags & ~(MDB_NV_SILENT | MDB_NV_INTERPOS);
  92         v->v_disc = disc;
  93         v->v_next = next;
  94 
  95         return (v);
  96 }
  97 
  98 static void
  99 nv_var_free(mdb_var_t *v, uint_t um_flags)
 100 {
 101         if (um_flags & UM_GC)
 102                 return;
 103 
 104         if (v->v_flags & MDB_NV_OVERLOAD) {
 105                 mdb_var_t *w, *nw;
 106