missing error check in lwkt_alloc_thread

Simon 'corecode' Schubert corecode at fs.ei.tum.de
Fri Feb 23 07:05:08 PST 2007


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);
       stack = libcaps_alloc_stack(stksize);
       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().


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   / \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgp00019.pgp
Type: application/octet-stream
Size: 252 bytes
Desc: "Description: OpenPGP digital signature"
URL: <http://lists.dragonflybsd.org/pipermail/kernel/attachments/20070223/d74641d1/attachment-0019.obj>

More information about the Kernel mailing list