This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problem with stack size in pthreads


On Mon, Jul 16, 2001 at 07:52:34AM -0700, H . J . Lu wrote:
> On Mon, Jul 16, 2001 at 12:29:21AM -0700, Ulrich Drepper wrote:
> > Actually, I think the constructor should call
> > __pthread_init_max_stacksize.  Otherwise it could have been already
> > too late to limit the stack size.  Please check the patch I've just
> > checked in.
> > 
> 
> It is similar to my first patch:
> 
> http://sources.redhat.com/ml/libc-alpha/2001-07/msg00223.html
> 
> It will cause posix/tst-regex to fail:
> 
> # ldd posix/tst-regex
>         librt.so.1 => /lib/librt.so.1 (0x40024000)
>         libc.so.6 => /lib/libc.so.6 (0x40036000)
>         libpthread.so.0 => /lib/libpthread.so.0 (0x40168000)
>         /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
> 
> With your patch, all programs linked with librt will have the 2MB stack
> limit. For the initial thread, the limit is not necessary. My second
> patch tries to call __pthread_init_max_stacksize when we know the
> stack limit will make a difference:
> 

This patch seems to work for me.


H.J.
---
2001-07-17  H.J. Lu  <hjl@gnu.org>

	* posix/tst-regex.c (main): Limit the size of the content of
	the file read into memory.

--- posix/tst-regex.c.stack	Sat Jul  7 16:45:41 2001
+++ posix/tst-regex.c	Tue Jul 17 21:37:55 2001
@@ -70,16 +70,28 @@ main (void)
   if (fd == -1)
     error (EXIT_FAILURE, errno, "cannot open %s", basename (file));
 
+/* We canot read in the whole file since we are loading libpthread.so
+   at the run time, brought in librt.so and libpthread.so may impose
+   the 2MB stack limit.  */
+#define START_OFFSET	184000
+#define READ_SIZE	103000
+
   if (fstat (fd, &st) != 0)
     error (EXIT_FAILURE, errno, "cannot stat %s", basename (file));
-  memlen = st.st_size;
+  if (st.st_size < START_OFFSET + READ_SIZE)
+    error (EXIT_FAILURE, 0, "%s is too small", basename (file));
+
+  memlen = START_OFFSET;
 
   mem = (char *) malloc (memlen + 1);
   if (mem == NULL)
     error (EXIT_FAILURE, errno, "while allocating buffer");
 
+  if (lseek (fd, START_OFFSET, SEEK_SET) != START_OFFSET)
+    error (EXIT_FAILURE, errno, "cannot seek in %s", basename (file));
+
   if (read (fd, mem, memlen) != memlen)
-    error (EXIT_FAILURE, 0, "cannot read entire file");
+    error (EXIT_FAILURE, errno, "cannot read %s", basename (file));
   mem[memlen] = '\0';
 
   close (fd);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]