[m-rev.] diff: unlimit stacks in hlc grades

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Mar 28 13:17:15 AEDT 2012


On Wed, 28 Mar 2012, Zoltan Somogyi wrote:

> The concept has already been reviewed by Julien, and the implementation is
> trivial.
>
> Zoltan.
>
> Prevent not just the deep profiler, but also the other programs in the
> Mercury system from running out of stack in hlc grades.
>
> mdbcomp/shared_utilities.m:
> 	A new module to contain the predicate that increases OS limits
> 	on stack usage as much as possible.
>
> mdbcomp/mdbcomp.m:
> 	Include the new module in this package.
>
> deep_profiler/startup.m:
> 	Remove the stack unlimit predicate that is now in
> 	mdbcomp/shared_utilities.m.
>
> deep_profiler/Mmakefile:
> slice/Mmakefile:
> 	Copy the new file over from mdbcomp, along with the rest of the files
> 	in the mdbcomp package.
>
> compiler/mercury_compile.m:
> slice/mcov.m:
> slice/mdice.m:
> slice/mslice.m:
> slice/mtc_diff.m:
> slice/mtc_union.m:
> 	Invoke the stack unlimit predicate.
>
> mdbcomp/prim_data.m:
> 	Fix a missing divider.

I have committed the following in order allow Mercury to still compile
on systems that don't support setrlimit().

-------------------

Branches: main

Do not attempt to use setrlimit on systems that do not support it.

configure.in:
 	Test for the presence of the setrlimit function

runtime/mercury_conf.h.in:
 	Define the macro MR_HAVE_SETRLIMIT if setrlimit is
 	present.

mdbcomp/shared_utilities.m:
 	Only attempt to modify the stack limit if MR_HAVE_SETRLIMIT
 	is defined.

 	Use don't-care variables for the I/O state in the foreign_proc.
 	(Avoids warnings from MSVC.)

Index: configure.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/configure.in,v
retrieving revision 1.611
diff -u -r1.611 configure.in
--- configure.in	24 Jan 2012 05:59:12 -0000	1.611
+++ configure.in	28 Mar 2012 02:09:16 -0000
@@ -1282,7 +1282,7 @@
          grantpt unlockpt ptsname tcgetattr tcsetattr ioctl \
          access sleep opendir readdir closedir mkdir symlink readlink \
          gettimeofday setenv putenv _putenv posix_spawn sched_setaffinity \
-        sched_getaffinity sched_getcpu sched_yield mkstemp
+        sched_getaffinity sched_getcpu sched_yield mkstemp setrlimit

  #-----------------------------------------------------------------------------#

Index: mdbcomp/shared_utilities.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/mdbcomp/shared_utilities.m,v
retrieving revision 1.1
diff -u -r1.1 shared_utilities.m
--- mdbcomp/shared_utilities.m	27 Mar 2012 23:29:14 -0000	1.1
+++ mdbcomp/shared_utilities.m	28 Mar 2012 02:10:56 -0000
@@ -31,9 +31,10 @@
  :- implementation.

  :- pragma foreign_proc("C",
-    unlimit_stack(S0::di, S::uo),
+    unlimit_stack(_S0::di, _S::uo),
      [will_not_call_mercury, promise_pure],
-"{
+"
+#if defined(MR_HAVE_SETRLIMIT)
      struct rlimit   limit_struct;
      rlim_t          max_value;

@@ -45,8 +46,7 @@
      limit_struct.rlim_cur = limit_struct.rlim_max;
      /* If this fails, we have no recourse, so ignore any failure. */
      (void) setrlimit(RLIMIT_STACK, &limit_struct);
-
-    S = S0;
-}").
+#endif
+").

  %---------------------------------------------------------------------------%
Index: runtime/mercury_conf.h.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_conf.h.in,v
retrieving revision 1.74
diff -u -r1.74 mercury_conf.h.in
--- runtime/mercury_conf.h.in	8 Dec 2011 23:24:14 -0000	1.74
+++ runtime/mercury_conf.h.in	28 Mar 2012 02:08:39 -0000
@@ -285,6 +285,7 @@
  **	MR_HAVE_PTHREAD_MUTEXATTR_SETPSHARED we have the
  **				pthread_mutexattr_setpshared() function.
  **	MR_HAVE_MKSTEMP		we have the mkstemp() function.
+**	MR_HAVE_SETRLIMIT	we have the setrlimit() funciton.
  */
  #undef	MR_HAVE_GETPID
  #undef	MR_HAVE_SETPGID
@@ -353,6 +354,7 @@
  #undef	MR_HAVE_SCHED_YIELD
  #undef	MR_HAVE_PTHREAD_MUTEXATTR_SETPSHARED
  #undef	MR_HAVE_MKSTEMP
+#undef  MR_HAVE_SETRLIMIT

  /*
  ** We use mprotect() and signals to catch stack and heap overflows.




--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list