DragonFly kernel List (threaded) for 2007-02
DragonFly BSD
DragonFly kernel List (threaded) for 2007-02
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

missing error check in lwkt_alloc_thread


From: "Simon 'corecode' Schubert" <corecode@xxxxxxxxxxxx>
Date: Fri, 23 Feb 2007 15:54:39 +0100

hey,

I just ran (via a programming mistake on my side) into a mall bug in lwkt_alloc_thread:

   if (stack == NULL) {
#ifdef _KERNEL
       stack = (void *)kmem_alloc(&kernel_map, stksize);
#else
       stack = libcaps_alloc_stack(stksize);
#endif
       flags |= TDF_ALLOCATED_STACK;
   }

kmem_alloc() however can return NULL if there is no free memory. Arguably, if there is no free memory to satisfy a thread stack, you're hosed anyways, but nevertheless.

I'm not sure how to fix this. Maybe something like this will be sufficient?

while (stack == NULL) {
 stack = (void *)kmem_alloc(&kernel_map, stksize);
 if (stack == NULL)
   tsleep(&kernel_map, 0, "stckalc", hz);
}

I know that there is nobody waking us up in this case, but one second should help the situation. Or we add the possibility of an error return to lwkt_alloc_thread().

comments?

cheers
 simon

--
Serve - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /"\
Work - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \

Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]