156777f967
On some historic 32-bit platforms (and 64-bit SuperH), __NR_getrlimit corresponds to a non-SuS-compatible version that uses a hardcoded value of 0x7fffffff as infinity. Moreover, in order to provide a backwards compatibility with that behaviour, some architectures (mips, sparc, and alpha, with latter being especially peculiar in its ways) just defined RLIM_INFINITY to that value (with alpha defining RLIM_INFINITY to 2^63-1) instead of employing sys_old_getrlimit syscall and providing __NR_ugetrlimit with proper implementation, as other arches did. Overall, that led to conclusion that printing "RLIM_INFINITY" is never enough and the actial value should be printed as well. * linux/i386/syscallent.h ([76]): Changing decoder to old_getrlimit. * linux/m68k/syscallent.h ([76]): Likewise. * linux/microblaze/syscallent.h ([76]): Likewise. * linux/powerpc/syscallent.h ([76]): Likewise. * linux/s390/syscallent.h ([76]): Likewise. * linux/sh/syscallent.h ([76]): Likewise. * linux/sh64/syscallent.h ([76]): Likewise. * resource.c (sprint_rlim64, sprint_rlim32, print_rlimit64, print_rlimit32): Remove. (STRACE_RLIM_INFINITY, STRACE_M32_RLIM_INFINITY, STRACE_RLIM64_INFINITY, OLD_GETLIMIT_INFINITY): New macro constants. (enum rlimit_decode_mode): New enumeration. (struct rlimit_64): Move type definition out of print_rlimit64. (print_rlim_t): New function, printer of an rlimit value, in accordance with rlimit decode mode and xlat verbosity mode. (print_rlimit): Printer of a fetched rlimit_64 structure. (decode_rlimit): Fetches struct rlimit/rlimit64 in accordance with current mode and personality, uses print_rlimit for printing. (do_getrlimit): New function, decodes old_getrlimit/getrlimit syscalls. (SYS_FUNC(getrlimit)): Call do_getrlimit with RDM_NORMAL mode. (SYS_FUNC(old_getrlimit)): New function, calls do_getrlimit with RDM_OLD_GETRLIMIT mode. (SYS_FUNC(setrlimit)): Call decode_rlimit with RDM_NORMAL mode. (SYS_FUNC(prlimit64)): Call decode_rlimit with RDM_PRLIMIT64 mode instead of print_rlimit64. * tests/xgetrlimit.c (sprint_rlim): Rename to... (print_rlim): ...this, print to terminal instead of string buffer in accordance with the output format expected. (main): Accomodate sprint_rlim -> print_rlim change, use sprintrc. * tests/getrlimit.c (INFINITY, INFINITY_STR): New macros. * tests/setrlimit.c: Likewise. * tests/ugetrlimit.c: Likewise.
267 lines
6.8 KiB
C
267 lines
6.8 KiB
C
/*
|
|
* Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
|
|
* Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
|
|
* Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
|
|
* Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
|
|
* Copyright (c) 1999-2018 The strace developers.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include "defs.h"
|
|
#include <sys/resource.h>
|
|
|
|
#include "xstring.h"
|
|
|
|
#include "xlat/resources.h"
|
|
|
|
/* Normally, RLIM_INFINITY is defined to ~0LU, but we have some very special
|
|
* architectures here.
|
|
*/
|
|
|
|
#if defined ALPHA
|
|
/* arch/alpha/include/uapi/asm/resource.h */
|
|
# define STRACE_RLIM_INFINITY 0x7fffffffffffffffUL
|
|
#endif
|
|
|
|
#if defined MIPS || defined SPARC || defined SPARC64
|
|
# if SIZEOF_LONG > 4
|
|
/* arch/{mips,sparc}/include/asm/compat.h */
|
|
# define STRACE_M32_RLIM_INFINITY 0x7fffffff
|
|
# else
|
|
/* arch/{mips,sparc}/include/uapi/asm/resource.h */
|
|
# define STRACE_RLIM_INFINITY 0x7fffffff
|
|
# endif
|
|
#endif
|
|
|
|
/* Generic RLIM_INFINITY definition */
|
|
#ifndef STRACE_RLIM_INFINITY
|
|
# define STRACE_RLIM_INFINITY ((kernel_ulong_t) ~0ULL)
|
|
# ifdef RLIM_INFINITY
|
|
static_assert(STRACE_RLIM_INFINITY == RLIM_INFINITY,
|
|
"Discrepancy in RLIM_INFINITY definition");
|
|
# endif
|
|
#endif /* !STRACE_RLIM_INFINITY */
|
|
|
|
#ifndef STRACE_M32_RLIM_INFINITY
|
|
# define STRACE_M32_RLIM_INFINITY (~0U)
|
|
#endif
|
|
|
|
#define STRACE_RLIM64_INFINITY (~0ULL)
|
|
#ifdef RLIM64_INFINITY
|
|
static_assert(STRACE_RLIM64_INFINITY == RLIM64_INFINITY,
|
|
"Discrepancy in RLIM64_INFINITY definition");
|
|
#endif
|
|
|
|
#define OLD_GETLIMIT_INFINITY 0x7fffffff
|
|
|
|
enum rlimit_decode_mode {
|
|
RDM_NORMAL, /* RLIM_INFINITY or its compat value */
|
|
RDM_OLD_GETRLIMIT, /* Use INT_MAX instead of RLIM_INFINITY */
|
|
RDM_PRLIMIT64, /* prlimit64 always uses RLIM64_INFINITY */
|
|
};
|
|
|
|
struct rlimit_64 {
|
|
uint64_t rlim_cur;
|
|
uint64_t rlim_max;
|
|
};
|
|
|
|
static void
|
|
print_rlim_t(uint64_t lim, enum rlimit_decode_mode mode)
|
|
{
|
|
uint64_t inf;
|
|
const char *inf_str;
|
|
enum xlat_style xst;
|
|
|
|
if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
|
|
tprintf("%" PRIu64, lim);
|
|
if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
|
|
return;
|
|
|
|
switch (mode) {
|
|
case RDM_NORMAL:
|
|
inf = (current_personality == 1) ? STRACE_M32_RLIM_INFINITY
|
|
: STRACE_RLIM_INFINITY;
|
|
inf_str = "RLIM_INFINITY";
|
|
xst = XLAT_STYLE_VERBOSE;
|
|
break;
|
|
case RDM_OLD_GETRLIMIT:
|
|
inf = OLD_GETLIMIT_INFINITY;
|
|
inf_str = "old getrlimit() infinity";
|
|
xst = XLAT_STYLE_VERBOSE;
|
|
break;
|
|
case RDM_PRLIMIT64:
|
|
inf = STRACE_RLIM64_INFINITY;
|
|
inf_str = "RLIM64_INFINITY";
|
|
xst = xlat_verbosity;
|
|
break;
|
|
}
|
|
|
|
if (lim == inf) {
|
|
if (xlat_verbose(xst) == XLAT_STYLE_VERBOSE) {
|
|
if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV)
|
|
tprintf("%" PRIu64, lim);
|
|
tprints_comment(inf_str);
|
|
} else {
|
|
tprints(inf_str);
|
|
}
|
|
} else if (lim > 1024 && lim % 1024 == 0) {
|
|
(xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV
|
|
? tprintf : tprintf_comment)("%" PRIu64 "*1024",
|
|
lim / 1024);
|
|
} else {
|
|
if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV)
|
|
tprintf("%" PRIu64, lim);
|
|
}
|
|
}
|
|
|
|
static void
|
|
print_rlimit(struct tcb *const tcp, const struct rlimit_64 *rlim,
|
|
enum rlimit_decode_mode mode)
|
|
{
|
|
tprints("{rlim_cur=");
|
|
print_rlim_t(rlim->rlim_cur, mode);
|
|
tprints(", rlim_max=");
|
|
print_rlim_t(rlim->rlim_max, mode);
|
|
tprints("}");
|
|
}
|
|
|
|
static void
|
|
decode_rlimit(struct tcb *const tcp, const kernel_ulong_t addr,
|
|
enum rlimit_decode_mode mode)
|
|
{
|
|
struct rlimit_64 rlim;
|
|
|
|
/*
|
|
* i386 is the only personality on X86_64 and X32
|
|
* with 32-bit rlim_t.
|
|
* When current_personality is X32, current_wordsize
|
|
* equals to 4 but rlim_t is 64-bit.
|
|
*/
|
|
if (current_klongsize == 4 && mode != RDM_PRLIMIT64) {
|
|
struct rlimit_32 {
|
|
uint32_t rlim_cur;
|
|
uint32_t rlim_max;
|
|
} m32_rlim;
|
|
|
|
if (umove_or_printaddr(tcp, addr, &m32_rlim))
|
|
return;
|
|
|
|
rlim.rlim_cur = m32_rlim.rlim_cur;
|
|
rlim.rlim_max = m32_rlim.rlim_max;
|
|
} else {
|
|
if (umove_or_printaddr(tcp, addr, &rlim))
|
|
return;
|
|
}
|
|
|
|
print_rlimit(tcp, &rlim, mode);
|
|
}
|
|
|
|
static int
|
|
do_getrlimit(struct tcb * const tcp, enum rlimit_decode_mode mode)
|
|
{
|
|
if (entering(tcp)) {
|
|
printxval(resources, tcp->u_arg[0], "RLIMIT_???");
|
|
tprints(", ");
|
|
} else {
|
|
decode_rlimit(tcp, tcp->u_arg[1], mode);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
SYS_FUNC(getrlimit)
|
|
{
|
|
return do_getrlimit(tcp, RDM_NORMAL);
|
|
}
|
|
|
|
SYS_FUNC(old_getrlimit)
|
|
{
|
|
return do_getrlimit(tcp, RDM_OLD_GETRLIMIT);
|
|
}
|
|
|
|
SYS_FUNC(setrlimit)
|
|
{
|
|
printxval(resources, tcp->u_arg[0], "RLIMIT_???");
|
|
tprints(", ");
|
|
decode_rlimit(tcp, tcp->u_arg[1], RDM_NORMAL);
|
|
|
|
return RVAL_DECODED;
|
|
}
|
|
|
|
SYS_FUNC(prlimit64)
|
|
{
|
|
if (entering(tcp)) {
|
|
tprintf("%d, ", (int) tcp->u_arg[0]);
|
|
printxval(resources, tcp->u_arg[1], "RLIMIT_???");
|
|
tprints(", ");
|
|
decode_rlimit(tcp, tcp->u_arg[2], RDM_PRLIMIT64);
|
|
tprints(", ");
|
|
} else {
|
|
decode_rlimit(tcp, tcp->u_arg[3], RDM_PRLIMIT64);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#include "xlat/usagewho.h"
|
|
|
|
SYS_FUNC(getrusage)
|
|
{
|
|
if (entering(tcp)) {
|
|
printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
|
|
tprints(", ");
|
|
} else
|
|
printrusage(tcp, tcp->u_arg[1]);
|
|
return 0;
|
|
}
|
|
|
|
#ifdef ALPHA
|
|
SYS_FUNC(osf_getrusage)
|
|
{
|
|
if (entering(tcp)) {
|
|
printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
|
|
tprints(", ");
|
|
} else
|
|
printrusage32(tcp, tcp->u_arg[1]);
|
|
return 0;
|
|
}
|
|
#endif /* ALPHA */
|
|
|
|
#include "xlat/priorities.h"
|
|
|
|
SYS_FUNC(getpriority)
|
|
{
|
|
printxval(priorities, tcp->u_arg[0], "PRIO_???");
|
|
tprintf(", %d", (int) tcp->u_arg[1]);
|
|
|
|
return RVAL_DECODED;
|
|
}
|
|
|
|
SYS_FUNC(setpriority)
|
|
{
|
|
printxval(priorities, tcp->u_arg[0], "PRIO_???");
|
|
tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);
|
|
|
|
return RVAL_DECODED;
|
|
}
|