Print this page
    
5513 KM_NORMALPRI should be documented in kmem_alloc(9f) and kmem_cache_create(9f) man pages
14465 Present KM_NOSLEEP_LAZY as documented interface
Change-Id: I002ec28ddf390650f1fcba1ca94f6abfdb241439
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/common/core/core_shstrtab.c
          +++ new/usr/src/common/core/core_shstrtab.c
   1    1  /*
   2    2   * This file and its contents are supplied under the terms of the
   3    3   * Common Development and Distribution License ("CDDL"), version 1.0.
   4    4   * You may only use this file in accordance with the terms of version
   5    5   * 1.0 of the CDDL.
   6    6   *
   7    7   * A full copy of the text of the CDDL should have accompanied this
   8    8   * source.  A copy of the CDDL is also available via the Internet at
   9    9   * http://www.illumos.org/license/CDDL.
  10   10   */
  11   11  
  12   12  /*
  13   13   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  14   14   * Use is subject to license terms.
  15   15   */
  16   16  
  17   17  /*
  18   18   * Copyright 2021 Oxide Computer Company
  19   19   */
  20   20  
  21   21  #ifndef _KERNEL
  22   22  #include <stdlib.h>
  23   23  #include <strings.h>
  24   24  #include <stddef.h>
  25   25  #else
  26   26  #include <sys/types.h>
  27   27  #include <sys/kmem.h>
  28   28  #include <sys/ddi.h>
  29   29  #include <sys/sunddi.h>
  30   30  #include <sys/stddef.h>
  31   31  #endif  /* _KERNEL */
  32   32  
  33   33  #include <core_shstrtab.h>
  34   34  
  35   35  const char *shstrtab_data[STR_NUM] = {
  36   36          "",
  37   37          ".SUNW_ctf",
  38   38          ".symtab",
  
    | 
      ↓ open down ↓ | 
    38 lines elided | 
    
      ↑ open up ↑ | 
  
  39   39          ".dynsym",
  40   40          ".strtab",
  41   41          ".dynstr",
  42   42          ".shstrtab"
  43   43  };
  44   44  
  45   45  static void *
  46   46  shstrtab_alloc(void)
  47   47  {
  48   48  #ifdef  _KERNEL
  49      -        return (kmem_zalloc(sizeof (shstrtab_ent_t),
  50      -            KM_NOSLEEP | KM_NORMALPRI));
       49 +        return (kmem_zalloc(sizeof (shstrtab_ent_t), KM_NOSLEEP_LAZY));
  51   50  #else
  52   51          return (calloc(1, sizeof (shstrtab_ent_t)));
  53   52  #endif
  54   53  }
  55   54  
  56   55  static void
  57   56  shstrtab_free(shstrtab_ent_t *ent)
  58   57  {
  59   58  #ifdef  _KERNEL
  60   59          if (ent->sste_name != NULL) {
  61   60                  strfree(ent->sste_name);
  62   61          }
  63   62          kmem_free(ent, sizeof (*ent));
  64   63  #else
  65   64          free(ent->sste_name);
  66   65          free(ent);
  67   66  #endif
  68   67  }
  69   68  
  70   69  
  71   70  boolean_t
  72   71  shstrtab_ndx(shstrtab_t *s, const char *name, Elf32_Word *offp)
  73   72  {
  74   73          shstrtab_ent_t *ent;
  75   74  
  76   75          for (ent = list_head(&s->sst_names); ent != NULL;
  77   76              ent = list_next(&s->sst_names, ent)) {
  78   77                  if (strcmp(name, ent->sste_name) == 0) {
  79   78                          if (offp != NULL)
  80   79                                  *offp = ent->sste_offset;
  81   80                          return (B_TRUE);
  82   81                  }
  83   82          }
  84   83  
  85   84          ent = shstrtab_alloc();
  86   85          if (ent == NULL) {
  87   86                  return (B_FALSE);
  88   87          }
  89   88  
  90   89          ent->sste_name = strdup(name);
  91   90          if (ent->sste_name == NULL) {
  92   91                  shstrtab_free(ent);
  93   92                  return (B_FALSE);
  94   93          }
  95   94          ent->sste_len = strlen(name) + 1;
  96   95          ent->sste_offset = s->sst_len;
  97   96          s->sst_len += ent->sste_len;
  98   97  
  99   98          list_insert_tail(&s->sst_names, ent);
 100   99  
 101  100          if (offp != NULL)
 102  101                  *offp = ent->sste_offset;
 103  102          return (B_TRUE);
 104  103  }
 105  104  
 106  105  boolean_t
 107  106  shstrtab_init(shstrtab_t *s)
 108  107  {
 109  108          bzero(s, sizeof (*s));
 110  109          list_create(&s->sst_names, sizeof (shstrtab_ent_t),
 111  110              offsetof(shstrtab_ent_t, sste_link));
 112  111  
 113  112          return (shstrtab_ndx(s, shstrtab_data[STR_NONE], NULL));
 114  113  }
 115  114  
 116  115  void
 117  116  shstrtab_fini(shstrtab_t *s)
 118  117  {
 119  118          shstrtab_ent_t *ent;
 120  119  
 121  120          if (s->sst_len == 0)
 122  121                  return;
 123  122  
 124  123          while ((ent = list_remove_head(&s->sst_names)) != NULL) {
 125  124                  shstrtab_free(ent);
 126  125          }
 127  126  }
 128  127  
 129  128  size_t
 130  129  shstrtab_size(const shstrtab_t *s)
 131  130  {
 132  131          return (s->sst_len);
 133  132  }
 134  133  
 135  134  void
 136  135  shstrtab_dump(shstrtab_t *s, void *buf)
 137  136  {
 138  137          size_t off = 0;
 139  138  
 140  139          for (shstrtab_ent_t *ent = list_head(&s->sst_names); ent != NULL;
 141  140              ent = list_next(&s->sst_names, ent)) {
 142  141                  bcopy(ent->sste_name, buf + off, ent->sste_len);
 143  142                  off += ent->sste_len;
 144  143          }
 145  144  }
  
    | 
      ↓ open down ↓ | 
    85 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX