Hello,

Maximus Minter, le mar. 07 avril 2026 22:30:33 -0400, a ecrit:
> - Protect all_eventcounters array with a lock
> diff --git a/kern/eventcount.c b/kern/eventcount.c
> index 70b9f0d5..8f786846 100644
> --- a/kern/eventcount.c
> +++ b/kern/eventcount.c
> @@ -55,6 +55,10 @@
>  
>  #define      MAX_EVCS        10              /* xxx for now */
>  evc_t        all_eventcounters[MAX_EVCS];
> +static decl_simple_lock_data(, all_evc_lock);
> +
> +#define evc_array_lock()     simple_lock(&all_evc_lock)
> +#define evc_array_unlock()   simple_unlock(&all_evc_lock)

See evc_signal mentioned to be called from interrupt context, so we need
to use splsched()/splx() when taking it.

> @@ -139,13 +151,18 @@ kern_return_t evc_wait(natural_t ev_id)
>       kern_return_t   ret;
>       evc_t           ev;
>  
> +     evc_array_lock();
>       if ((ev_id >= MAX_EVCS) ||
>           ((ev = all_eventcounters[ev_id]) == 0) ||
>           (ev->ev_id != ev_id) || (ev->sanity != ev))
> +     {
> +             evc_array_unlock();
>               return KERN_INVALID_ARGUMENT;
> +     }
> +     simple_lock(&ev->lock);
> +     evc_array_unlock();
>  
>       s = splsched();
> -     simple_lock(&ev->lock);
>               /*
>                * The values assumed by the "count" field are
>                * as follows:
> @@ -166,8 +183,8 @@ kern_return_t evc_wait(natural_t ev_id)
>                               ev->count--;
>                               ev->waiting_thread = current_thread();
>                               assert_wait((event_t) 0, TRUE); /* ifnot race */
> -                             simple_unlock(&ev->lock);

?? why removing the unlock?

> @@ -212,7 +233,6 @@ kern_return_t evc_wait_clear(natural_t ev_id)
>                       ev->count = -1;
>                       ev->waiting_thread = current_thread();
>                       assert_wait((event_t) 0, TRUE); /* ifnot race */
> -                     simple_unlock(&ev->lock);

ditto

>                       thread_block(evc_continue);
>                       /* NOTREACHED */
>               }

Samuel

Reply via email to