Changeset 62c8ca0 in rtems-libbsd


Ignore:
Timestamp:
May 18, 2017, 7:35:46 AM (2 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
647dd08ae2aa69b935c2847ea450fb824322ecae, c6261f97870562d4c797cfb1ff1ba0affb85a916
Children:
d61f731
Parents:
5be4f06
git-author:
Sebastian Huber <sebastian.huber@…> (05/18/17 07:35:46)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/20/17 12:59:55)
Message:

Fix INVARIANTS support

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • freebsd/sys/kern/kern_event.c

    r5be4f06 r62c8ca0  
    21092109{
    21102110
     2111#ifndef __rtems__
    21112112        KASSERT(kq->kq_fdp == NULL,
    21122113            ("kqueue still attached to a file descriptor"));
     2114#endif /* __rtems__ */
    21132115        seldrain(&kq->kq_sel);
    21142116        knlist_destroy(&kq->kq_sel.si_note);
  • freebsd/sys/kern/subr_lock.c

    r5be4f06 r62c8ca0  
    8585
    8686        /* Check for double-init and zero object. */
     87#ifndef __rtems__
    8788        KASSERT(flags & LO_NEW || !lock_initialized(lock),
    8889            ("lock \"%s\" %p already initialized", name, lock));
     90#endif /* __rtems__ */
    8991
    9092        /* Look up lock class to find its index. */
  • freebsd/sys/sys/rmlock.h

    r5be4f06 r62c8ca0  
    113113#define rm_runlock(rm, tracker) do { (void)tracker; rw_runlock(rm); } while (0)
    114114#define rm_sleep rw_sleep
     115#define _rm_assert _rw_assert
    115116#endif /* __rtems__ */
    116117
  • freebsd/sys/sys/rwlock.h

    r5be4f06 r62c8ca0  
    165165int     _rw_try_upgrade(struct rwlock *rw, const char *file, int line);
    166166void    _rw_downgrade(struct rwlock *rw, const char *file, int line);
     167#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
     168void    _rw_assert(const struct rwlock *rw, int what, const char *file,
     169            int line);
     170#endif
    167171#endif /* __rtems__ */
    168172
  • freebsd/sys/sys/systm.h

    r5be4f06 r62c8ca0  
    106106
    107107#if defined(WITNESS) || defined(INVARIANT_SUPPORT)
     108#ifndef __rtems__
    108109void    kassert_panic(const char *fmt, ...)  __printflike(1, 2);
     110#else /* __rtems__ */
     111#define kassert_panic panic
     112#endif /* __rtems__ */
    109113#endif
    110114
  • freebsd/sys/vm/uma_core.c

    r5be4f06 r62c8ca0  
    22052205                    "uma_zalloc_arg: zone \"%s\"", zone->uz_name);
    22062206        }
     2207#ifndef __rtems__
    22072208        KASSERT(curthread->td_critnest == 0 || SCHEDULER_STOPPED(),
    22082209            ("uma_zalloc_arg: called with spinlock or critical section held"));
     2210#endif /* __rtems__ */
    22092211
    22102212#ifdef DEBUG_MEMGUARD
     
    27432745            zone->uz_name);
    27442746
     2747#ifndef __rtems__
    27452748        KASSERT(curthread->td_critnest == 0 || SCHEDULER_STOPPED(),
    27462749            ("uma_zfree_arg: called with spinlock or critical section held"));
     2750#endif /* __rtems__ */
    27472751
    27482752        /* uma_zfree(..., NULL) does nothing, to match free(9). */
  • rtemsbsd/include/machine/rtems-bsd-muteximpl.h

    r5be4f06 r62c8ca0  
    210210}
    211211
     212static inline Thread_Control *
     213rtems_bsd_mutex_owner(const rtems_bsd_mutex *m)
     214{
     215
     216        return (m->queue.Queue.owner);
     217}
     218
    212219static inline int
    213 rtems_bsd_mutex_owned(rtems_bsd_mutex *m)
    214 {
    215 
    216         return (m->queue.Queue.owner == _Thread_Get_executing());
     220rtems_bsd_mutex_owned(const rtems_bsd_mutex *m)
     221{
     222
     223        return (rtems_bsd_mutex_owner(m) == _Thread_Get_executing());
    217224}
    218225
    219226static inline int
    220 rtems_bsd_mutex_recursed(rtems_bsd_mutex *m)
    221 {
    222 
    223         return (m->nest_level);
     227rtems_bsd_mutex_recursed(const rtems_bsd_mutex *m)
     228{
     229
     230        return (m->nest_level != 0);
     231}
     232
     233static inline const char *
     234rtems_bsd_mutex_name(const rtems_bsd_mutex *m)
     235{
     236
     237        return (m->queue.Queue.name);
    224238}
    225239
  • rtemsbsd/rtems/rtems-kernel-mutex.c

    r5be4f06 r62c8ca0  
    165165_mtx_assert(struct mtx *m, int what, const char *file, int line)
    166166{
    167 
    168   if (panicstr != NULL || dumping)
    169     return;
    170   switch (what) {
    171   case MA_OWNED:
    172   case MA_OWNED | MA_RECURSED:
    173   case MA_OWNED | MA_NOTRECURSED:
    174     if (!mtx_owned(m))
    175       panic("mutex %s not owned at %s:%d",
    176           m->lock_object.lo_name, file, line);
    177     if (mtx_recursed(m)) {
    178       if ((what & MA_NOTRECURSED) != 0)
    179         panic("mutex %s recursed at %s:%d",
    180             m->lock_object.lo_name, file, line);
    181     } else if ((what & MA_RECURSED) != 0) {
    182       panic("mutex %s unrecursed at %s:%d",
    183           m->lock_object.lo_name, file, line);
    184     }
    185     break;
    186   case MA_NOTOWNED:
    187     if (mtx_owned(m))
    188       panic("mutex %s owned at %s:%d",
    189           m->lock_object.lo_name, file, line);
    190     break;
    191   default:
    192     panic("unknown mtx_assert at %s:%d", file, line);
    193   }
     167        const char *name = rtems_bsd_mutex_name(&m->mutex);
     168
     169        switch (what) {
     170        case MA_OWNED:
     171        case MA_OWNED | MA_RECURSED:
     172        case MA_OWNED | MA_NOTRECURSED:
     173                if (!mtx_owned(m))
     174                        panic("mutex %s not owned at %s:%d", name, file, line);
     175                if (mtx_recursed(m)) {
     176                        if ((what & MA_NOTRECURSED) != 0)
     177                                panic("mutex %s recursed at %s:%d", name, file,
     178                                    line);
     179                } else if ((what & MA_RECURSED) != 0) {
     180                        panic("mutex %s unrecursed at %s:%d", name, file,
     181                            line);
     182                }
     183                break;
     184        case MA_NOTOWNED:
     185                if (mtx_owned(m))
     186                        panic("mutex %s owned at %s:%d", name, file, line);
     187                break;
     188        default:
     189                panic("unknown mtx_assert at %s:%d", file, line);
     190        }
    194191}
    195192#endif
  • rtemsbsd/rtems/rtems-kernel-rwlock.c

    r5be4f06 r62c8ca0  
    8080};
    8181
    82 #define rw_wowner(rw) ((rw)->mutex.owner)
    83 
    84 #define rw_recursed(rw) ((rw)->mutex.nest_level != 0)
     82#define rw_wowner(rw) rtems_bsd_mutex_owner(&(rw)->mutex)
     83
     84#define rw_recursed(rw) rtems_bsd_mutex_recursed(&(rw)->mutex)
    8585
    8686void
     
    208208
    209209#ifdef INVARIANT_SUPPORT
    210 #ifndef INVARIANTS
    211 #undef _rw_assert
    212 #endif
    213 
    214210/*
    215211 * In the non-WITNESS case, rw_assert() can only detect that at least
     
    218214 */
    219215void
    220 _rw_assert(struct rwlock *rw, int what, const char *file, int line)
    221 {
    222 
    223   if (panicstr != NULL)
    224     return;
    225   switch (what) {
    226   case RA_LOCKED:
    227   case RA_LOCKED | RA_RECURSED:
    228   case RA_LOCKED | RA_NOTRECURSED:
    229   case RA_RLOCKED:
    230 #ifndef __rtems__
     216_rw_assert(const struct rwlock *rw, int what, const char *file, int line)
     217{
     218        const char *name = rtems_bsd_mutex_name(&rw->mutex);
     219
     220        switch (what) {
     221        case RA_LOCKED:
     222        case RA_LOCKED | RA_RECURSED:
     223        case RA_LOCKED | RA_NOTRECURSED:
     224        case RA_RLOCKED:
     225        case RA_RLOCKED | RA_RECURSED:
     226        case RA_RLOCKED | RA_NOTRECURSED:
     227        case RA_WLOCKED:
     228        case RA_WLOCKED | RA_RECURSED:
     229        case RA_WLOCKED | RA_NOTRECURSED:
     230                if (rw_wowner(rw) != _Thread_Get_executing())
     231                        panic("Lock %s not exclusively locked @ %s:%d\n",
     232                            name, file, line);
     233                if (rw_recursed(rw)) {
     234                        if (what & RA_NOTRECURSED)
     235                                panic("Lock %s recursed @ %s:%d\n", name, file,
     236                                    line);
     237                } else if (what & RA_RECURSED)
     238                        panic("Lock %s not recursed @ %s:%d\n", name, file,
     239                            line);
     240                break;
     241        case RA_UNLOCKED:
    231242#ifdef WITNESS
    232     witness_assert(&rw->lock_object, what, file, line);
     243                witness_assert(&rw->lock_object, what, file, line);
    233244#else
    234     /*
    235      * If some other thread has a write lock or we have one
    236      * and are asserting a read lock, fail.  Also, if no one
    237      * has a lock at all, fail.
    238      */
    239     if (rw->rw_lock == RW_UNLOCKED ||
    240         (!(rw->rw_lock & RW_LOCK_READ) && (what == RA_RLOCKED ||
    241         rw_wowner(rw) != curthread)))
    242       panic("Lock %s not %slocked @ %s:%d\n",
    243           rw->lock_object.lo_name, (what == RA_RLOCKED) ?
    244           "read " : "", file, line);
    245 
    246     if (!(rw->rw_lock & RW_LOCK_READ)) {
    247       if (rw_recursed(rw)) {
    248         if (what & RA_NOTRECURSED)
    249           panic("Lock %s recursed @ %s:%d\n",
    250               rw->lock_object.lo_name, file,
    251               line);
    252       } else if (what & RA_RECURSED)
    253         panic("Lock %s not recursed @ %s:%d\n",
    254             rw->lock_object.lo_name, file, line);
    255     }
    256 #endif
    257     break;
    258 #else /* __rtems__ */
    259     /* FALLTHROUGH */
    260 #endif /* __rtems__ */
    261   case RA_WLOCKED:
    262   case RA_WLOCKED | RA_RECURSED:
    263   case RA_WLOCKED | RA_NOTRECURSED:
    264     if (rw_wowner(rw) != _Thread_Get_executing())
    265       panic("Lock %s not exclusively locked @ %s:%d\n",
    266           rw->lock_object.lo_name, file, line);
    267     if (rw_recursed(rw)) {
    268       if (what & RA_NOTRECURSED)
    269         panic("Lock %s recursed @ %s:%d\n",
    270             rw->lock_object.lo_name, file, line);
    271     } else if (what & RA_RECURSED)
    272       panic("Lock %s not recursed @ %s:%d\n",
    273           rw->lock_object.lo_name, file, line);
    274     break;
    275   case RA_UNLOCKED:
    276 #ifdef WITNESS
    277     witness_assert(&rw->lock_object, what, file, line);
    278 #else
    279     /*
    280      * If we hold a write lock fail.  We can't reliably check
    281      * to see if we hold a read lock or not.
    282      */
    283     if (rw_wowner(rw) == _Thread_Get_executing())
    284       panic("Lock %s exclusively locked @ %s:%d\n",
    285           rw->lock_object.lo_name, file, line);
    286 #endif
    287     break;
    288   default:
    289     panic("Unknown rw lock assertion: %d @ %s:%d", what, file,
    290         line);
    291   }
     245                /*
     246                 * If we hold a write lock fail.  We can't reliably check
     247                 * to see if we hold a read lock or not.
     248                 */
     249                if (rw_wowner(rw) == _Thread_Get_executing())
     250                        panic("Lock %s exclusively locked @ %s:%d\n", name,
     251                            file, line);
     252#endif
     253                break;
     254        default:
     255                panic("Unknown rw lock assertion: %d @ %s:%d", what, file,
     256                    line);
     257        }
    292258}
    293259#endif /* INVARIANT_SUPPORT */
  • rtemsbsd/rtems/rtems-kernel-sx.c

    r5be4f06 r62c8ca0  
    4848#include <sys/sx.h>
    4949
    50 #ifndef INVARIANTS
    51 #define _sx_assert(sx, what, file, line)
    52 #endif
    53 
    5450static void assert_sx(struct lock_object *lock, int what);
    5551static void lock_sx(struct lock_object *lock, int how);
     
    7369};
    7470
    75 #define sx_xholder(sx) ((sx)->mutex.owner)
    76 
    77 #define sx_recursed(sx) ((sx)->mutex.nest_level != 0)
     71#define sx_xholder(sx) rtems_bsd_mutex_owner(&(sx)->mutex)
     72
     73#define sx_recursed(sx) rtems_bsd_mutex_recursed(&(sx)->mutex)
    7874
    7975void
     
    171167
    172168#ifdef INVARIANT_SUPPORT
    173 #ifndef INVARIANTS
    174 #undef  _sx_assert
    175 #endif
    176 
    177169/*
    178170 * In the non-WITNESS case, sx_assert() can only detect that at least
     
    181173 */
    182174void
    183 _sx_assert(struct sx *sx, int what, const char *file, int line)
    184 {
    185 #ifndef __rtems__
    186 #ifndef WITNESS
    187   int slocked = 0;
    188 #endif
    189 #endif /* __rtems__ */
    190 
    191   if (panicstr != NULL)
    192     return;
    193   switch (what) {
    194   case SA_SLOCKED:
    195   case SA_SLOCKED | SA_NOTRECURSED:
    196   case SA_SLOCKED | SA_RECURSED:
    197 #ifndef __rtems__
    198 #ifndef WITNESS
    199     slocked = 1;
    200     /* FALLTHROUGH */
    201 #endif
    202 #endif /* __rtems__ */
    203   case SA_LOCKED:
    204   case SA_LOCKED | SA_NOTRECURSED:
    205   case SA_LOCKED | SA_RECURSED:
    206 #ifndef __rtems__
     175_sx_assert(const struct sx *sx, int what, const char *file, int line)
     176{
     177        const char *name = rtems_bsd_mutex_name(&sx->mutex);
     178
     179        switch (what) {
     180        case SA_SLOCKED:
     181        case SA_SLOCKED | SA_NOTRECURSED:
     182        case SA_SLOCKED | SA_RECURSED:
     183        case SA_LOCKED:
     184        case SA_LOCKED | SA_NOTRECURSED:
     185        case SA_LOCKED | SA_RECURSED:
     186        case SA_XLOCKED:
     187        case SA_XLOCKED | SA_NOTRECURSED:
     188        case SA_XLOCKED | SA_RECURSED:
     189                if (sx_xholder(sx) != _Thread_Get_executing())
     190                        panic("Lock %s not exclusively locked @ %s:%d\n", name,
     191                            file, line);
     192                if (sx_recursed(sx)) {
     193                        if (what & SA_NOTRECURSED)
     194                                panic("Lock %s recursed @ %s:%d\n", name, file,
     195                                    line);
     196                } else if (what & SA_RECURSED)
     197                        panic("Lock %s not recursed @ %s:%d\n", name, file,
     198                            line);
     199                break;
     200        case SA_UNLOCKED:
    207201#ifdef WITNESS
    208     witness_assert(&sx->lock_object, what, file, line);
     202                witness_assert(&sx->lock_object, what, file, line);
    209203#else
    210     /*
    211      * If some other thread has an exclusive lock or we
    212      * have one and are asserting a shared lock, fail.
    213      * Also, if no one has a lock at all, fail.
    214      */
    215     if (sx->sx_lock == SX_LOCK_UNLOCKED ||
    216         (!(sx->sx_lock & SX_LOCK_SHARED) && (slocked ||
    217         sx_xholder(sx) != curthread)))
    218       panic("Lock %s not %slocked @ %s:%d\n",
    219           sx->lock_object.lo_name, slocked ? "share " : "",
    220           file, line);
    221 
    222     if (!(sx->sx_lock & SX_LOCK_SHARED)) {
    223       if (sx_recursed(sx)) {
    224         if (what & SA_NOTRECURSED)
    225           panic("Lock %s recursed @ %s:%d\n",
    226               sx->lock_object.lo_name, file,
    227               line);
    228       } else if (what & SA_RECURSED)
    229         panic("Lock %s not recursed @ %s:%d\n",
    230             sx->lock_object.lo_name, file, line);
    231     }
    232 #endif
    233     break;
    234 #else /* __rtems__ */
    235     /* FALLTHROUGH */
    236 #endif /* __rtems__ */
    237   case SA_XLOCKED:
    238   case SA_XLOCKED | SA_NOTRECURSED:
    239   case SA_XLOCKED | SA_RECURSED:
    240     if (sx_xholder(sx) != _Thread_Get_executing())
    241       panic("Lock %s not exclusively locked @ %s:%d\n",
    242           sx->lock_object.lo_name, file, line);
    243     if (sx_recursed(sx)) {
    244       if (what & SA_NOTRECURSED)
    245         panic("Lock %s recursed @ %s:%d\n",
    246             sx->lock_object.lo_name, file, line);
    247     } else if (what & SA_RECURSED)
    248       panic("Lock %s not recursed @ %s:%d\n",
    249           sx->lock_object.lo_name, file, line);
    250     break;
    251   case SA_UNLOCKED:
    252 #ifdef WITNESS
    253     witness_assert(&sx->lock_object, what, file, line);
    254 #else
    255     /*
    256      * If we hold an exclusve lock fail.  We can't
    257      * reliably check to see if we hold a shared lock or
    258      * not.
    259      */
    260     if (sx_xholder(sx) == _Thread_Get_executing())
    261       panic("Lock %s exclusively locked @ %s:%d\n",
    262           sx->lock_object.lo_name, file, line);
    263 #endif
    264     break;
    265   default:
    266     panic("Unknown sx lock assertion: %d @ %s:%d", what, file,
    267         line);
    268   }
     204                /*
     205                 * If we hold an exclusve lock fail.  We can't
     206                 * reliably check to see if we hold a shared lock or
     207                 * not.
     208                 */
     209                if (sx_xholder(sx) == _Thread_Get_executing())
     210                        panic("Lock %s exclusively locked @ %s:%d\n", name,
     211                            file, line);
     212#endif
     213                break;
     214        default:
     215                panic("Unknown sx lock assertion: %d @ %s:%d", what, file,
     216                    line);
     217        }
    269218}
    270219#endif  /* INVARIANT_SUPPORT */
Note: See TracChangeset for help on using the changeset viewer.