vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / bus_managers / scsi / scsi_lock.h
blob596486424de191b3bc87f475eba91b67441ee519
1 /*
2 ** Copyright 2002/03, Thomas Kurschel. All rights reserved.
3 ** Distributed under the terms of the MIT License.
4 */
6 /*
7 Part of Open SCSI bus manager
9 Special locks
11 The only one defined herein is a spinlock that automatically
12 disabled IRQs on enter and restores them on leave. Probably,
13 this should be made public as it's quite basic.
16 #ifndef __SCSI_LOCK_H__
17 #define __SCSI_LOCK_H__
19 #include <KernelExport.h>
22 // enhanced spinlock that automatically disables irqs when lock is hold
23 typedef struct spinlock_irq {
24 spinlock lock; // normal spinlock
25 cpu_status prev_irq_state; // irq state before spinlock was entered
26 } spinlock_irq;
29 static inline void
30 spinlock_irq_init(spinlock_irq *lock)
32 B_INITIALIZE_SPINLOCK(&lock->lock);
35 static inline void
36 acquire_spinlock_irq(spinlock_irq *lock)
38 cpu_status prev_irq_state = disable_interrupts();
40 acquire_spinlock(&lock->lock);
41 lock->prev_irq_state = prev_irq_state;
44 static inline void
45 release_spinlock_irq(spinlock_irq *lock)
47 cpu_status prev_irq_state = lock->prev_irq_state;
49 release_spinlock(&lock->lock);
50 restore_interrupts(prev_irq_state);
53 #endif