summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-03-07 19:49:20 +0000
committerJim Meyering <jim@meyering.net>2003-03-07 19:49:20 +0000
commit300807cd2fdfa8c449359df669f243f233a564c0 (patch)
tree992f1154df8d879c5904912c000d002d9f9db7be /lib
parentbce28b3573275c8cf3a51030e11ab92a132e10c7 (diff)
downloadcoreutils-300807cd2fdfa8c449359df669f243f233a564c0.tar.xz
.
Diffstat (limited to 'lib')
-rw-r--r--lib/mmap-stack.c112
-rw-r--r--lib/mmap-stack.h54
2 files changed, 0 insertions, 166 deletions
diff --git a/lib/mmap-stack.c b/lib/mmap-stack.c
deleted file mode 100644
index 30d1da8d1..000000000
--- a/lib/mmap-stack.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/* Run with a larger (mmap'd) stack.
-
- Copyright (C) 2003 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-
-/* Written by Jim Meyering. */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <assert.h>
-#include <unistd.h>
-#include <stdarg.h>
-#if HAVE_SYS_MMAN_H
-# include <sys/mman.h>
-#endif
-#if HAVE_UCONTEXT_H
-# include <ucontext.h>
-#endif
-
-#include "mmap-stack.h"
-
-#ifndef MAP_ANONYMOUS
-# ifdef MAP_ANON
-# define MAP_ANONYMOUS MAP_ANON
-# else
-# define MAP_ANONYMOUS 0
-# endif
-#endif
-
-/* Set up context, *CTX, so that it may be used via makecontext,
- using a block of SIZE bytes of mmap'd memory for its stack.
- Return nonzero upon error. */
-static int
-get_context (ucontext_t *ctx, size_t size)
-{
- void *stack;
- int fd = -1; /* This must be -1 in order for Solaris' MAP_ANON to work. */
-
- if (getcontext (ctx))
- return 1;
-
- /* use tmpfile if MAP_ANONYMOUS is not useful. */
-#if MAP_ANONYMOUS == 0
- {
- FILE *fp = tmpfile ();
- if (!fp)
- return 1;
- fd = fileno (fp);
- }
-#endif
-
- stack = mmap (NULL, size,
- PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, fd, 0);
- if (stack == MAP_FAILED)
- return 1;
- ctx->uc_stack.ss_sp = stack;
- ctx->uc_stack.ss_size = size;
- ctx->uc_link = NULL;
- return 0;
-}
-
-/* Yep, this is arbitrary. tough :-) */
-#define ARGC_MAX 6
-
-/* Set up a context without conventional stack limitations,
- then call function FUNC with the specified number (ARGC) of arguments.
- If get_context and setcontext succeed, this function does not return,
- so FUNC must be sure to exit appropriately. Otherwise, this function
- does return, and the caller should diagnose the failure. */
-void
-run_on_mmaped_stack (void (*func) (void), size_t argc, ...)
-{
- ucontext_t ctx;
- size_t size = 256 * 1024 * 1024;
- long argv[ARGC_MAX];
- unsigned i;
- va_list ap;
-
- assert (argc <= ARGC_MAX);
- va_start (ap, argc);
- for (i = 0; i < argc; i++)
- argv[i] = va_arg (ap, long);
- va_end (ap);
-
- if (get_context (&ctx, size) == 0)
- {
- makecontext (&ctx, func, argc,
- argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5]);
- setcontext (&ctx);
- }
-
- /* get_context or setcontext failed;
- Resort to using the conventional stack. */
-}
diff --git a/lib/mmap-stack.h b/lib/mmap-stack.h
deleted file mode 100644
index f4924d7b2..000000000
--- a/lib/mmap-stack.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* Run with a larger (mmap'd) stack.
-
- Copyright (C) 2003 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-
-
-/* FIXME: disable this, for now.
- The whole idea feels a bit too kludgey.
- Although it seems to work just fine on Linux, it doesn't
- work on Solaris or HPUX. */
-#undef HAVE_MMAP_STACK
-
-#if HAVE_MMAP_STACK
-# define RUN_WITH_BIG_STACK_2(F, A, B) \
- do \
- { \
- run_on_mmaped_stack ((void (*) (void)) F, 2, A, B); \
- error (0, errno, _("warning: unable to use large stack")); \
- F (A, B); \
- } \
- while (0)
-#else
-# define RUN_WITH_BIG_STACK_2(F, A, B) \
- do { F (A, B); } while (0)
-#endif
-
-#if HAVE_MMAP_STACK
-# define RUN_WITH_BIG_STACK_4(F, A, B, C, D) \
- do \
- { \
- run_on_mmaped_stack ((void (*) (void)) F, 4, A, B, C, D); \
- error (0, errno, _("warning: unable to use large stack")); \
- F (A, B, C, D); \
- } \
- while (0)
-#else
-# define RUN_WITH_BIG_STACK_4(F, A, B, C, D) \
- do { F (A, B, C, D); } while (0)
-#endif
-
-void run_on_mmaped_stack (void (*func_) (void), size_t argc_, ...);