Files
mercury/mdbcomp/shared_utilities.m
Peter Wang 72f174b4e2 Don't print value of errno in MR_fatal_error.
The majority of calls to MR_fatal_error do not follow an operation that
sets errno, so printing out an error message unrelated to the reason for
the fatal error will lead to confusion. It can also cause test failures
if errno happens to be set to non-zero some time prior to an expected
call to MR_fatal_error. Fixes bug #464.

runtime/mercury_misc.c:
    Don't print value of errno in MR_fatal_error.

runtime/mercury_context.c:
runtime/mercury_thread.c:
    Pass strerror strings to MR_fatal_error where appropriate.

runtime/mercury_memory_zones.c:
runtime/mercury_memory_zones.h:
    Pass strerror strings to MR_fatal_error following failures of
    MR_protect_pages. Document that this assumes MR_protect_pages sets
    errno on error.

    Skip unnecessary call to sprintf before MR_fatal_error.

runtime/mercury_deep_profiling.c:
    Skip unnecessary call to sprintf before MR_fatal_error.

    Reduce size of some buffers.

runtime/mercury_overflow.c:
runtime/mercury_stack_trace.c:
    Pass a fixed format string to MR_fatal_error just in case
    the message string may contain percentage signs.

runtime/mercury_tabling.c:
    Skip unnecessary call to sprintf before MR_fatal_error.

deep_profiler/timeout.m:
library/thread.m:
mdbcomp/shared_utilities.m:
    Pass strerror strings to MR_fatal_error where appropriate.

trace/mercury_trace.c:
    Skip unnecessary call to sprintf before MR_fatal_error.

trace/mercury_trace_external.c:
    Pass a fixed format string to MR_fatal_error just in case.
2018-08-19 12:19:19 +10:00

74 lines
2.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 2012 The University of Melbourne.
% Copyright (C) 2014, 2018 The Mercury team.
% This file is distributed under the terms specified in COPYING.LIB.
%---------------------------------------------------------------------------%
%
% This module contains utility predicates that may be useful in several
% directories of the Mercury system.
:- module mdbcomp.shared_utilities.
:- interface.
:- import_module io.
% When the deep profiler is compiled in hlc grades, on many systems
% large profiling data files cannot be processed using only the default
% size of the C stack. Similarly, when the compiler is compiled in hlc
% grades, it often runs out of stack when compiling large input files.
%
% This predicate tells the OS to allow the system stack to grow
% as large as it needs to, subject only to the hard limits enforced
% by the system.
%
% In llc grades, this predicate has no useful effect. The stack size
% limit can be lifted in such grades by using their .stseg versions.
%
:- pred unlimit_stack(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- pragma foreign_decl("C", "
/*
** On some systems (e.g. Mac OS X 10.3) RLIMIT_STACK is defined in the
** header sys/resource.h.
*/
#if defined(MR_HAVE_SYS_RESOURCE_H)
#include <sys/resource.h>
#endif
").
:- pragma foreign_proc("C",
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;
char errbuf[MR_STRERROR_BUF_SIZE];
if (getrlimit(RLIMIT_STACK, &limit_struct) != 0) {
MR_fatal_error(""could not get current stack limit: %s"",
MR_strerror(errno, errbuf, sizeof(errbuf)));
}
max_value = limit_struct.rlim_max;
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);
#endif
").
% Clause for non-C backends.
%
unlimit_stack(!IO).
%---------------------------------------------------------------------------%