Print this page
3830 SIGQUEUE_MAX's limit of 32 is too low

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/sig.c
          +++ new/usr/src/uts/common/os/sig.c
↓ open down ↓ 2365 lines elided ↑ open up ↑
2366 2366                  case SI_QUEUE:
2367 2367                  case SI_TIMER:
2368 2368                  case SI_ASYNCIO:
2369 2369                  case SI_MESGQ:
2370 2370                          return (1);
2371 2371                  }
2372 2372          }
2373 2373          return (0);
2374 2374  }
2375 2375  
2376      -#ifndef UCHAR_MAX
2377      -#define UCHAR_MAX       255
     2376 +#ifndef INT_MAX
     2377 +#define INT_MAX 2147483647
2378 2378  #endif
2379 2379  
     2380 +#define _SIGQUEUE_PREALLOC      32      /* XXX: log scale? */
     2381 +
2380 2382  /*
2381      - * The entire pool (with maxcount entries) is pre-allocated at
2382      - * the first sigqueue/signotify call.
     2383 + * The pre-allocated pool (with _SIGQUEUE_PREALLOC entries) is
     2384 + * allocated at the first sigqueue/signotify call.
2383 2385   */
2384 2386  sigqhdr_t *
2385 2387  sigqhdralloc(size_t size, uint_t maxcount)
2386 2388  {
2387 2389          size_t i;
2388 2390          sigqueue_t *sq, *next;
2389 2391          sigqhdr_t *sqh;
2390 2392  
2391      -        i = (maxcount * size) + sizeof (sigqhdr_t);
2392      -        ASSERT(maxcount <= UCHAR_MAX && i <= USHRT_MAX);
     2393 +        i = (_SIGQUEUE_PREALLOC * size) + sizeof (sigqhdr_t);
     2394 +        ASSERT(maxcount <= INT_MAX);
2393 2395          sqh = kmem_alloc(i, KM_SLEEP);
2394      -        sqh->sqb_count = (uchar_t)maxcount;
2395      -        sqh->sqb_maxcount = (uchar_t)maxcount;
2396      -        sqh->sqb_size = (ushort_t)i;
     2396 +        sqh->sqb_count = maxcount;
     2397 +        sqh->sqb_maxcount = maxcount;
     2398 +        sqh->sqb_size = i;
2397 2399          sqh->sqb_pexited = 0;
2398 2400          sqh->sqb_sent = 0;
2399 2401          sqh->sqb_free = sq = (sigqueue_t *)(sqh + 1);
2400      -        for (i = maxcount - 1; i != 0; i--) {
     2402 +        for (i = _SIGQUEUE_PREALLOC - 1; i != 0; i--) {
2401 2403                  next = (sigqueue_t *)((uintptr_t)sq + size);
2402 2404                  sq->sq_next = next;
2403 2405                  sq = next;
2404 2406          }
2405 2407          sq->sq_next = NULL;
2406 2408          cv_init(&sqh->sqb_cv, NULL, CV_DEFAULT, NULL);
2407 2409          mutex_init(&sqh->sqb_lock, NULL, MUTEX_DEFAULT, NULL);
2408 2410          return (sqh);
2409 2411  }
2410 2412  
2411 2413  static void sigqrel(sigqueue_t *);
2412 2414  
2413 2415  /*
2414      - * allocate a sigqueue/signotify structure from the per process
2415      - * pre-allocated pool.
     2416 + * Allocate a sigqueue/signotify structure from the per process
     2417 + * pre-allocated pool or allocate a new sigqueue/signotify structure
     2418 + * if the pre-allocated pool is exhausted.
2416 2419   */
2417 2420  sigqueue_t *
2418 2421  sigqalloc(sigqhdr_t *sqh)
2419 2422  {
2420 2423          sigqueue_t *sq = NULL;
2421 2424  
2422 2425          ASSERT(MUTEX_HELD(&curproc->p_lock));
2423 2426  
2424 2427          if (sqh != NULL) {
2425 2428                  mutex_enter(&sqh->sqb_lock);
2426 2429                  if (sqh->sqb_count > 0) {
2427 2430                          sqh->sqb_count--;
2428      -                        sq = sqh->sqb_free;
2429      -                        sqh->sqb_free = sq->sq_next;
     2431 +                        if (sqh->sqb_free == NULL) {
     2432 +                                /*
     2433 +                                 * The pre-allocated pool is exhausted.
     2434 +                                 */
     2435 +                                sq = kmem_alloc(sizeof (sigqueue_t), KM_SLEEP);
     2436 +                                sq->sq_func = NULL;
     2437 +                        } else {
     2438 +                                sq = sqh->sqb_free;
     2439 +                                sq->sq_func = sigqrel;
     2440 +                                sqh->sqb_free = sq->sq_next;
     2441 +                        }
2430 2442                          mutex_exit(&sqh->sqb_lock);
2431 2443                          bzero(&sq->sq_info, sizeof (k_siginfo_t));
2432 2444                          sq->sq_backptr = sqh;
2433      -                        sq->sq_func = sigqrel;
2434 2445                          sq->sq_next = NULL;
2435 2446                          sq->sq_external = 0;
2436 2447                  } else {
2437 2448                          mutex_exit(&sqh->sqb_lock);
2438 2449                  }
2439 2450          }
2440 2451          return (sq);
2441 2452  }
2442 2453  
2443 2454  /*
↓ open down ↓ 420 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX