Print this page
Code review comments from jeffpc

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/sys/sbrk.c
          +++ new/usr/src/lib/libc/port/sys/sbrk.c
↓ open down ↓ 114 lines elided ↑ open up ↑
 115  115   * not allow shrinking the heap.
 116  116   */
 117  117  void *
 118  118  _sbrk_grow_aligned(size_t min_size, size_t low_align, size_t high_align,
 119  119      size_t *actual_size)
 120  120  {
 121  121          uintptr_t old_brk;
 122  122          uintptr_t ret_brk;
 123  123          uintptr_t high_brk;
 124  124          uintptr_t new_brk;
 125      -        int brk_result;
      125 +        intptr_t brk_result;
 126  126  
 127  127          if (!primary_link_map) {
 128  128                  errno = ENOTSUP;
 129  129                  return ((void *)-1);
 130  130          }
 131  131          if ((low_align & (low_align - 1)) != 0 ||
 132  132              (high_align & (high_align - 1)) != 0) {
 133  133                  errno = EINVAL;
 134  134                  return ((void *)-1);
 135  135          }
 136  136          low_align = MAX(low_align, ALIGNSZ);
 137  137          high_align = MAX(high_align, ALIGNSZ);
 138  138  
 139  139          lmutex_lock(&__sbrk_lock);
 140  140  
 141      -        if (_nd == NULL) {
      141 +        if (_nd == NULL)
 142  142                  _nd = (void *)_brk_unlocked(0);
 143      -        }
 144  143  
 145  144          old_brk = (uintptr_t)BRKALIGN(_nd);
 146  145          ret_brk = P2ROUNDUP(old_brk, low_align);
 147  146          high_brk = ret_brk + min_size;
 148  147          new_brk = P2ROUNDUP(high_brk, high_align);
 149  148  
 150  149          /*
 151  150           * Check for overflow
 152  151           */
 153  152          if (ret_brk < old_brk || high_brk < ret_brk || new_brk < high_brk) {
 154  153                  lmutex_unlock(&__sbrk_lock);
 155  154                  errno = ENOMEM;
 156  155                  return ((void *)-1);
 157  156          }
 158  157  
 159      -        if ((brk_result = (int)_brk_unlocked((void *)new_brk)) == 0)
      158 +        if ((brk_result = _brk_unlocked((void *)new_brk)) == 0)
 160  159                  _nd = (void *)new_brk;
 161  160          lmutex_unlock(&__sbrk_lock);
 162  161  
 163  162          if (brk_result != 0)
 164  163                  return ((void *)-1);
 165  164  
 166  165          if (actual_size != NULL)
 167  166                  *actual_size = (new_brk - ret_brk);
 168  167          return ((void *)ret_brk);
 169  168  }
 170  169  
 171  170  int
 172  171  brk(void *new_brk)
 173  172  {
 174      -        int result;
      173 +        intptr_t result;
 175  174  
 176  175          /*
 177  176           * brk(2) will return the current brk if given an argument of 0, so we
 178  177           * need to fail it here
 179  178           */
 180  179          if (new_brk == 0) {
 181  180                  errno = ENOMEM;
 182  181                  return (-1);
 183  182          }
 184  183  
 185  184          if (!primary_link_map) {
 186  185                  errno = ENOTSUP;
 187  186                  return (-1);
 188  187          }
 189  188          /*
 190  189           * Need to align this here;  _brk_unlocked won't do it for us.
 191  190           */
 192  191          new_brk = BRKALIGN(new_brk);
 193  192  
 194  193          lmutex_lock(&__sbrk_lock);
 195      -        if ((result = (int)_brk_unlocked(new_brk)) == 0)
      194 +        if ((result = _brk_unlocked(new_brk)) == 0)
 196  195                  _nd = new_brk;
 197  196          lmutex_unlock(&__sbrk_lock);
 198  197  
 199  198          return (result);
 200  199  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX