Included NewOS change 1642 (argument checking)

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1182 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2002-09-26 01:01:54 +00:00
parent 5f20abf004
commit 71c882e5f5
+42 -28
View File
@@ -20,7 +20,7 @@ struct io_handler {
struct io_handler *next; struct io_handler *next;
struct io_handler *prev; struct io_handler *prev;
interrupt_handler func; interrupt_handler func;
void* data; void *data;
}; };
struct io_vector { struct io_vector {
@@ -30,6 +30,7 @@ struct io_vector {
static struct io_vector *io_vectors = NULL; static struct io_vector *io_vectors = NULL;
int int
int_init(kernel_args *ka) int_init(kernel_args *ka)
{ {
@@ -51,18 +52,22 @@ int_init2(kernel_args *ka)
return arch_int_init2(ka); return arch_int_init2(ka);
} }
/* install_interrupt_handler
* This function is used internally to install a handler on the given vector. /** This function is used internally to install a handler on the given vector.
* NB this does NOT take an IRQ, but a system interrupt value. * NB this does NOT take an IRQ, but a system interrupt value.
* As this is intended for system use this function doe NOT call * As this is intended for system use this function does NOT call
* arch_int_enable_io_interrupt() as it only works for IRQ values * arch_int_enable_io_interrupt() as it only works for IRQ values
*/ */
long install_interrupt_handler(long vector, interrupt_handler handler,
void* data) long
install_interrupt_handler(long vector, interrupt_handler handler, void *data)
{ {
struct io_handler *io = NULL; struct io_handler *io = NULL;
int state; int state;
if (vector < 0 || vector >= NUM_IO_VECTORS)
return B_BAD_VALUE;
/* find the chain of handlers for this irq. /* find the chain of handlers for this irq.
* NB there can be multiple handlers for the same IRQ, especially for * NB there can be multiple handlers for the same IRQ, especially for
* PCI drivers. Where we have multiple handlers we will call each in turn * PCI drivers. Where we have multiple handlers we will call each in turn
@@ -84,19 +89,22 @@ long install_interrupt_handler(long vector, interrupt_handler handler,
* and then insert the handler */ * and then insert the handler */
state = disable_interrupts(); state = disable_interrupts();
acquire_spinlock(&io_vectors[vector].vector_lock); acquire_spinlock(&io_vectors[vector].vector_lock);
insque(io, &io_vectors[vector].handler_list); insque(io, &io_vectors[vector].handler_list);
release_spinlock(&io_vectors[vector].vector_lock); release_spinlock(&io_vectors[vector].vector_lock);
restore_interrupts(state); restore_interrupts(state);
return 0; return 0;
} }
/* install_io_interrupt_handler
* install a handler to be called when an interrupt is triggered /** install a handler to be called when an interrupt is triggered
* for the given irq with data as the argument * for the given irq with data as the argument
*/ */
long install_io_interrupt_handler(long irq, interrupt_handler handler,
void* data, ulong flags) long
install_io_interrupt_handler(long irq, interrupt_handler handler, void *data, ulong flags)
{ {
long vector = irq + 0x20; long vector = irq + 0x20;
long rv = install_interrupt_handler(vector, handler, data); long rv = install_interrupt_handler(vector, handler, data);
@@ -114,17 +122,21 @@ long install_io_interrupt_handler(long irq, interrupt_handler handler,
return 0; return 0;
} }
/* remove_interrupt_handler
* read notes for install_interrupt_handler /** read notes for install_interrupt_handler */
*/
long remove_interrupt_handler(long vector, interrupt_handler handler, long
void* data) remove_interrupt_handler(long vector, interrupt_handler handler, void *data)
{ {
struct io_handler *io = NULL; struct io_handler *io = NULL;
long rv = EINVAL; long rv = EINVAL;
int state;
if (vector < 0 || vector >= NUM_IO_VECTORS)
return B_BAD_VALUE;
/* lock the structures down so it is not modified while we search */ /* lock the structures down so it is not modified while we search */
int state = disable_interrupts(); state = disable_interrupts();
acquire_spinlock(&io_vectors[vector].vector_lock); acquire_spinlock(&io_vectors[vector].vector_lock);
/* loop through the available handlers and try to find a match. /* loop through the available handlers and try to find a match.
@@ -152,11 +164,11 @@ long remove_interrupt_handler(long vector, interrupt_handler handler,
return rv; return rv;
} }
/* remove_io_interrupt_handler
* remove an interrupt handler previously inserted /** remove an interrupt handler previously inserted */
*/
long remove_io_interrupt_handler(long irq, interrupt_handler handler, long
void* data) remove_io_interrupt_handler(long irq, interrupt_handler handler, void *data)
{ {
long vector = irq + 0x20; long vector = irq + 0x20;
long rv = remove_interrupt_handler(vector, handler, data); long rv = remove_interrupt_handler(vector, handler, data);
@@ -171,11 +183,13 @@ long remove_io_interrupt_handler(long irq, interrupt_handler handler,
return 0; return 0;
} }
/* int_io_interrupt_handler
* actually process an interrupt via the handlers registered for that /** actually process an interrupt via the handlers registered for that
* vector (irq) * vector (irq)
*/ */
int int_io_interrupt_handler(int vector)
int
int_io_interrupt_handler(int vector)
{ {
int ret = B_UNHANDLED_INTERRUPT; int ret = B_UNHANDLED_INTERRUPT;