Print this page
patch as-lock-macro-simplification


 223 #define AH_DIR          0x1     /* direction flag mask */
 224 #define AH_LO           0x0     /* find lowest hole */
 225 #define AH_HI           0x1     /* find highest hole */
 226 #define AH_CONTAIN      0x2     /* hole must contain `addr' */
 227 
 228 extern struct as kas;           /* kernel's address space */
 229 
 230 /*
 231  * Macros for address space locking.  Note that we use RW_READER_STARVEWRITER
 232  * whenever we acquire the address space lock as reader to assure that it can
 233  * be used without regard to lock order in conjunction with filesystem locks.
 234  * This allows filesystems to safely induce user-level page faults with
 235  * filesystem locks held while concurrently allowing filesystem entry points
 236  * acquiring those same locks to be called with the address space lock held as
 237  * reader.  RW_READER_STARVEWRITER thus prevents reader/reader+RW_WRITE_WANTED
 238  * deadlocks in the style of fop_write()+as_fault()/as_*()+fop_putpage() and
 239  * fop_read()+as_fault()/as_*()+fop_getpage().  (See the Big Theory Statement
 240  * in rwlock.c for more information on the semantics of and motivation behind
 241  * RW_READER_STARVEWRITER.)
 242  */
 243 #define AS_LOCK_ENTER(as, lock, type)           rw_enter((lock), \
 244         (type) == RW_READER ? RW_READER_STARVEWRITER : (type))
 245 #define AS_LOCK_EXIT(as, lock)                  rw_exit((lock))
 246 #define AS_LOCK_DESTROY(as, lock)               rw_destroy((lock))
 247 #define AS_LOCK_TRYENTER(as, lock, type)        rw_tryenter((lock), \
 248         (type) == RW_READER ? RW_READER_STARVEWRITER : (type))
 249 
 250 /*
 251  * Macros to test lock states.
 252  */
 253 #define AS_LOCK_HELD(as, lock)          RW_LOCK_HELD((lock))
 254 #define AS_READ_HELD(as, lock)          RW_READ_HELD((lock))
 255 #define AS_WRITE_HELD(as, lock)         RW_WRITE_HELD((lock))
 256 
 257 /*
 258  * macros to walk thru segment lists
 259  */
 260 #define AS_SEGFIRST(as)         avl_first(&(as)->a_segtree)
 261 #define AS_SEGNEXT(as, seg)     AVL_NEXT(&(as)->a_segtree, (seg))
 262 #define AS_SEGPREV(as, seg)     AVL_PREV(&(as)->a_segtree, (seg))
 263 
 264 void    as_init(void);
 265 void    as_avlinit(struct as *);
 266 struct  seg *as_segat(struct as *as, caddr_t addr);
 267 void    as_rangelock(struct as *as);
 268 void    as_rangeunlock(struct as *as);
 269 struct  as *as_alloc();
 270 void    as_free(struct as *as);
 271 int     as_dup(struct as *as, struct proc *forkedproc);
 272 struct  seg *as_findseg(struct as *as, caddr_t addr, int tail);
 273 int     as_addseg(struct as *as, struct seg *newseg);
 274 struct  seg *as_removeseg(struct as *as, struct seg *seg);
 275 faultcode_t as_fault(struct hat *hat, struct as *as, caddr_t addr, size_t size,




 223 #define AH_DIR          0x1     /* direction flag mask */
 224 #define AH_LO           0x0     /* find lowest hole */
 225 #define AH_HI           0x1     /* find highest hole */
 226 #define AH_CONTAIN      0x2     /* hole must contain `addr' */
 227 
 228 extern struct as kas;           /* kernel's address space */
 229 
 230 /*
 231  * Macros for address space locking.  Note that we use RW_READER_STARVEWRITER
 232  * whenever we acquire the address space lock as reader to assure that it can
 233  * be used without regard to lock order in conjunction with filesystem locks.
 234  * This allows filesystems to safely induce user-level page faults with
 235  * filesystem locks held while concurrently allowing filesystem entry points
 236  * acquiring those same locks to be called with the address space lock held as
 237  * reader.  RW_READER_STARVEWRITER thus prevents reader/reader+RW_WRITE_WANTED
 238  * deadlocks in the style of fop_write()+as_fault()/as_*()+fop_putpage() and
 239  * fop_read()+as_fault()/as_*()+fop_getpage().  (See the Big Theory Statement
 240  * in rwlock.c for more information on the semantics of and motivation behind
 241  * RW_READER_STARVEWRITER.)
 242  */
 243 #define AS_LOCK_ENTER(as, type)         rw_enter(&(as)->a_lock, \
 244         (type) == RW_READER ? RW_READER_STARVEWRITER : (type))
 245 #define AS_LOCK_EXIT(as)                rw_exit(&(as)->a_lock)
 246 #define AS_LOCK_DESTROY(as)             rw_destroy(&(as)->a_lock)
 247 #define AS_LOCK_TRYENTER(as, type)      rw_tryenter(&(as)->a_lock, \
 248         (type) == RW_READER ? RW_READER_STARVEWRITER : (type))
 249 
 250 /*
 251  * Macros to test lock states.
 252  */
 253 #define AS_LOCK_HELD(as)                RW_LOCK_HELD(&(as)->a_lock)
 254 #define AS_READ_HELD(as)                RW_READ_HELD(&(as)->a_lock)
 255 #define AS_WRITE_HELD(as)               RW_WRITE_HELD(&(as)->a_lock)
 256 
 257 /*
 258  * macros to walk thru segment lists
 259  */
 260 #define AS_SEGFIRST(as)         avl_first(&(as)->a_segtree)
 261 #define AS_SEGNEXT(as, seg)     AVL_NEXT(&(as)->a_segtree, (seg))
 262 #define AS_SEGPREV(as, seg)     AVL_PREV(&(as)->a_segtree, (seg))
 263 
 264 void    as_init(void);
 265 void    as_avlinit(struct as *);
 266 struct  seg *as_segat(struct as *as, caddr_t addr);
 267 void    as_rangelock(struct as *as);
 268 void    as_rangeunlock(struct as *as);
 269 struct  as *as_alloc();
 270 void    as_free(struct as *as);
 271 int     as_dup(struct as *as, struct proc *forkedproc);
 272 struct  seg *as_findseg(struct as *as, caddr_t addr, int tail);
 273 int     as_addseg(struct as *as, struct seg *newseg);
 274 struct  seg *as_removeseg(struct as *as, struct seg *seg);
 275 faultcode_t as_fault(struct hat *hat, struct as *as, caddr_t addr, size_t size,