Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
NEEDSTACK(3)		   Library Functions Manual		  NEEDSTACK(3)

NAME
       needstack - check for execution stack overflow

SYNOPSIS
       #include	<u.h>

       #include	<libc.h>

       int  needstack(int n)

DESCRIPTION
       Stack  overflow	in the thread library leads to bugs that are difficult
       to diagnose.  The Plan 9	libraries are  careful	about  not  allocating
       large  structures on the	stack, so typically four or eight kilobytes is
       plenty of stack for a thread.  Other libraries are not always as	 care-
       ful.   Calling needstack	indicates to the thread	library	that an	exter-
       nal routine is about to be called that will require n  bytes  of	 stack
       space.	If there is not	enough space left on the stack,	the thread li-
       brary prints an error and  terminates  the  program.   The  call	 need-
       stack(0)	 can  be  used	to  check whether the stack is currently over-
       flowed.

       Needstack is defined in	libc.h	so  that  library  functions  used  in
       threaded	 and non-threaded contexts can call it.	 The implementation of
       needstack in lib9 is a no-op.

       Needstack should	be thought of as a comment checked at run time,	like

EXAMPLE
       The X Window library implementation  of	XLookupString  allocates  some
       very large buffers on the stack,	so /src/cmd/devdraw/x11-itrans.c calls
       needstack(64*1024) before making	calls to XLookupString.	 If  a	thread
       (in  this  case,	 the  keyboard-reading thread used inside the library)
       does not	allocate a large enough	stack, the problem is diagnosed	 imme-
       diately rather than left	to corrupt memory.

SOURCE
       /src/lib9/needstack.c
       /src/libthread

SEE ALSO
								  NEEDSTACK(3)

NAME | SYNOPSIS | DESCRIPTION | EXAMPLE | SOURCE | SEE ALSO

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=needstack&sektion=3&manpath=FreeBSD+13.1-RELEASE+and+Ports>

home | help