Print this page
5042 stop using deprecated atomic functions

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/sparc/v9/syscall/install_utrap.c
          +++ new/usr/src/uts/sparc/v9/syscall/install_utrap.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  27      -
  28   26  #include <sys/types.h>
  29   27  #include <sys/errno.h>
  30   28  #include <sys/systm.h>
  31   29  #include <sys/atomic.h>
  32   30  #include <sys/kmem.h>
  33   31  #include <sys/machpcb.h>
  34   32  #include <sys/utrap.h>
  35   33  #include <sys/model.h>
  36   34  
  37   35  int
↓ open down ↓ 36 lines elided ↑ open up ↑
  74   72           * generation and avoid a messy quadruple cast.
  75   73           */
  76   74          nv32 = (caddr32_t)(uintptr_t)new_handler;
  77   75          nv = (utrap_handler_t *)(uintptr_t)nv32;
  78   76          if (nv != UTRAP_UTH_NOCHANGE) {
  79   77                  if (((uintptr_t)nv) & 0x3)
  80   78                          return ((int)set_errno(EINVAL));
  81   79          }
  82   80          /*
  83   81           * Allocate proc space for saving the addresses to these user
  84      -         * trap handlers, which must later be freed. Use casptr to
       82 +         * trap handlers, which must later be freed. Use atomic_cas_ptr to
  85   83           * do this atomically.
  86   84           */
  87   85          if (p->p_utraps == NULL) {
  88   86                  pv = sv = kmem_zalloc((UT_PRECISE_MAXTRAPS+1) *
  89   87                      sizeof (utrap_handler_t *), KM_SLEEP);
  90      -                tmp = casptr(&p->p_utraps, NULL, sv);
       88 +                tmp = atomic_cas_ptr(&p->p_utraps, NULL, sv);
  91   89                  if (tmp != NULL) {
  92   90                          kmem_free(pv, (UT_PRECISE_MAXTRAPS+1) *
  93   91                              sizeof (utrap_handler_t *));
  94   92                  }
  95   93          }
  96   94          ASSERT(p->p_utraps != NULL);
  97   95  
  98   96          /*
  99      -         * Use casptr to atomically install the handler.
       97 +         * Use atomic_cas_ptr to atomically install the handler.
 100   98           */
 101   99          ov = p->p_utraps[idx];
 102  100          if (new_handler != (utrap_handler_t)UTRAP_UTH_NOCHANGE) {
 103  101                  for (;;) {
 104      -                        tmp = casptr(&p->p_utraps[idx], ov, nv);
      102 +                        tmp = atomic_cas_ptr(&p->p_utraps[idx], ov, nv);
 105  103                          if (ov == tmp)
 106  104                                  break;
 107  105                          ov = tmp;
 108  106                  }
 109  107          }
 110  108          if (old_handlerp != NULL) {
 111  109                  if (suword32(old_handlerp, (uint32_t)(uintptr_t)ov) == -1)
 112  110                          return ((int)set_errno(EINVAL));
 113  111          }
 114  112          return (0);
↓ open down ↓ 103 lines elided ↑ open up ↑
 218  216           * There are no deferred traps, so ignore them.
 219  217           */
 220  218          nvp = (utrap_handler_t *)new_precise;
 221  219          if (nvp != UTRAP_UTH_NOCHANGE) {
 222  220                  if (((uintptr_t)nvp) & 0x3)
 223  221                          return ((int)set_errno(EINVAL));
 224  222          }
 225  223  
 226  224          /*
 227  225           * Allocate proc space for saving the addresses to these user
 228      -         * trap handlers, which must later be freed. Use casptr to
      226 +         * trap handlers, which must later be freed. Use atomic_cas_ptr to
 229  227           * do this atomically.
 230  228           */
 231  229          if (p->p_utraps == NULL) {
 232  230                  pv = sv = kmem_zalloc((UT_PRECISE_MAXTRAPS+1) *
 233  231                      sizeof (utrap_handler_t *), KM_SLEEP);
 234      -                tmp = casptr(&p->p_utraps, NULL, sv);
      232 +                tmp = atomic_cas_ptr(&p->p_utraps, NULL, sv);
 235  233                  if (tmp != NULL) {
 236  234                          kmem_free(pv, (UT_PRECISE_MAXTRAPS+1) *
 237  235                              sizeof (utrap_handler_t *));
 238  236                  }
 239  237          }
 240  238          ASSERT(p->p_utraps != NULL);
 241  239  
 242  240          /*
 243      -         * Use casptr to atomically install the handlers.
      241 +         * Use atomic_cas_ptr to atomically install the handlers.
 244  242           */
 245  243          ov = p->p_utraps[idx];
 246  244          if (new_precise != (utrap_handler_t)UTH_NOCHANGE) {
 247  245                  for (;;) {
 248      -                        tmp = casptr(&p->p_utraps[idx], ov, nvp);
      246 +                        tmp = atomic_cas_ptr(&p->p_utraps[idx], ov, nvp);
 249  247                          if (ov == tmp)
 250  248                                  break;
 251  249                          ov = tmp;
 252  250                  }
 253  251          }
 254  252          if (old_precise != NULL) {
 255  253                  if (suword64(old_precise, (uint64_t)ov) == -1)
 256  254                          return ((int)set_errno(EINVAL));
 257  255          }
 258  256          return (0);
 259  257  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX