/*-1* SPDX-License-Identifier: BSD-4-Clause2*3* Copyright (c) 1999 Adrian Chadd4* Copyright (c) 19935* The Regents of the University of California. All rights reserved.6*7* This code is derived from software contributed to Berkeley by8* Jan-Simon Pendry.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. All advertising materials mentioning features or use of this software19* must display the following acknowledgement:20* This product includes software developed by the University of21* California, Berkeley and its contributors.22* 4. Neither the name of the University nor the names of its contributors23* may be used to endorse or promote products derived from this software24* without specific prior written permission.25*26* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND27* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE29* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE30* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL31* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS32* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)33* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT34* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY35* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF36* SUCH DAMAGE.37*/3839/*40* To get resource.h to include our rlimit_ident[] array of rlimit identifiers41*/4243#define _RLIMIT_IDENT4445#include <sys/param.h>46#include <sys/lock.h>47#include <sys/mutex.h>48#include <sys/systm.h>49#include <sys/proc.h>50#include <sys/resourcevar.h>51#include <sys/resource.h>52#include <sys/sbuf.h>53#include <sys/types.h>54#include <sys/malloc.h>5556#include <fs/pseudofs/pseudofs.h>57#include <fs/procfs/procfs.h>5859_Static_assert(nitems(rlimit_ident) == RLIM_NLIMITS,60"resource.h RLIMIT_IDENT needs update");6162int63procfs_doprocrlimit(PFS_FILL_ARGS)64{65struct plimit *limp;66int i;6768/*69* Obtain a private reference to resource limits70*/7172PROC_LOCK(p);73limp = lim_hold(p->p_limit);74PROC_UNLOCK(p);7576for (i = 0; i < RLIM_NLIMITS; i++) {77/*78* Add the rlimit ident79*/8081sbuf_printf(sb, "%s ", rlimit_ident[i]);8283/*84* Replace RLIM_INFINITY with -1 in the string85*/8687/*88* current limit89*/9091if (limp->pl_rlimit[i].rlim_cur == RLIM_INFINITY) {92sbuf_printf(sb, "-1 ");93} else {94sbuf_printf(sb, "%llu ",95(unsigned long long)limp->pl_rlimit[i].rlim_cur);96}9798/*99* maximum limit100*/101102if (limp->pl_rlimit[i].rlim_max == RLIM_INFINITY) {103sbuf_printf(sb, "-1\n");104} else {105sbuf_printf(sb, "%llu\n",106(unsigned long long)limp->pl_rlimit[i].rlim_max);107}108}109110lim_free(limp);111return (0);112}113114115