aboutsummaryrefslogtreecommitdiff
path: root/sys/compat
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2015-06-10 10:48:12 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2015-06-10 10:48:12 +0000
commitf6f6d24062224a443ecd5e3945cf25127ee819fe (patch)
treedbbb077ee034cbfe839c1ba19dbe5ce374a5c6a3 /sys/compat
parent4ea6a9a28fd7ae3cc6e8697bc93f9ce5ea6b6262 (diff)
downloadsrc-f6f6d24062224a443ecd5e3945cf25127ee819fe.tar.gz
src-f6f6d24062224a443ecd5e3945cf25127ee819fe.zip
Implement lockless resource limits.
Use the same scheme implemented to manage credentials. Code needing to look at process's credentials (as opposed to thred's) is provided with *_proc variants of relevant functions. Places which possibly had to take the proc lock anyway still use the proc pointer to access limits.
Notes
Notes: svn path=/head/; revision=284215
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/linux/linux_misc.c14
-rw-r--r--sys/compat/svr4/imgact_svr4.c2
-rw-r--r--sys/compat/svr4/svr4_misc.c20
-rw-r--r--sys/compat/svr4/svr4_resource.c16
4 files changed, 14 insertions, 38 deletions
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index 65d27ba2f422..fa5feaf01daf 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -383,7 +383,7 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args)
*/
PROC_LOCK(td->td_proc);
if (a_out->a_text > maxtsiz ||
- a_out->a_data + bss_size > lim_cur(td->td_proc, RLIMIT_DATA) ||
+ a_out->a_data + bss_size > lim_cur_proc(td->td_proc, RLIMIT_DATA) ||
racct_set(td->td_proc, RACCT_DATA, a_out->a_data +
bss_size) != 0) {
PROC_UNLOCK(td->td_proc);
@@ -1420,7 +1420,6 @@ int
linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
{
struct l_rlimit rlim;
- struct proc *p = td->td_proc;
struct rlimit bsd_rlim;
u_int which;
@@ -1437,9 +1436,7 @@ linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
if (which == -1)
return (EINVAL);
- PROC_LOCK(p);
- lim_rlimit(p, which, &bsd_rlim);
- PROC_UNLOCK(p);
+ lim_rlimit(td, which, &bsd_rlim);
#ifdef COMPAT_LINUX32
rlim.rlim_cur = (unsigned int)bsd_rlim.rlim_cur;
@@ -1464,7 +1461,6 @@ int
linux_getrlimit(struct thread *td, struct linux_getrlimit_args *args)
{
struct l_rlimit rlim;
- struct proc *p = td->td_proc;
struct rlimit bsd_rlim;
u_int which;
@@ -1481,9 +1477,7 @@ linux_getrlimit(struct thread *td, struct linux_getrlimit_args *args)
if (which == -1)
return (EINVAL);
- PROC_LOCK(p);
- lim_rlimit(p, which, &bsd_rlim);
- PROC_UNLOCK(p);
+ lim_rlimit(td, which, &bsd_rlim);
rlim.rlim_cur = (l_ulong)bsd_rlim.rlim_cur;
rlim.rlim_max = (l_ulong)bsd_rlim.rlim_max;
@@ -2204,7 +2198,7 @@ linux_prlimit64(struct thread *td, struct linux_prlimit64_args *args)
if (args->old != NULL) {
PROC_LOCK(p);
- lim_rlimit(p, which, &rlim);
+ lim_rlimit_proc(p, which, &rlim);
PROC_UNLOCK(p);
if (rlim.rlim_cur == RLIM_INFINITY)
lrlim.rlim_cur = LINUX_RLIM_INFINITY;
diff --git a/sys/compat/svr4/imgact_svr4.c b/sys/compat/svr4/imgact_svr4.c
index f3bb09e51688..e61b49bb3640 100644
--- a/sys/compat/svr4/imgact_svr4.c
+++ b/sys/compat/svr4/imgact_svr4.c
@@ -109,7 +109,7 @@ exec_svr4_imgact(imgp)
*/
PROC_LOCK(imgp->proc);
if (a_out->a_text > maxtsiz ||
- a_out->a_data + bss_size > lim_cur(imgp->proc, RLIMIT_DATA) ||
+ a_out->a_data + bss_size > lim_cur_proc(imgp->proc, RLIMIT_DATA) ||
racct_set(imgp->proc, RACCT_DATA, a_out->a_data + bss_size) != 0) {
PROC_UNLOCK(imgp->proc);
return (ENOMEM);
diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c
index c0da170a5e3b..1b4a35eb77e4 100644
--- a/sys/compat/svr4/svr4_misc.c
+++ b/sys/compat/svr4/svr4_misc.c
@@ -910,9 +910,7 @@ svr4_sys_ulimit(td, uap)
switch (uap->cmd) {
case SVR4_GFILLIM:
- PROC_LOCK(td->td_proc);
- *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512;
- PROC_UNLOCK(td->td_proc);
+ *retval = lim_cur(td, RLIMIT_FSIZE) / 512;
if (*retval == -1)
*retval = 0x7fffffff;
return 0;
@@ -922,17 +920,13 @@ svr4_sys_ulimit(td, uap)
struct rlimit krl;
krl.rlim_cur = uap->newlimit * 512;
- PROC_LOCK(td->td_proc);
- krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE);
- PROC_UNLOCK(td->td_proc);
+ krl.rlim_max = lim_max(td, RLIMIT_FSIZE);
error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
if (error)
return error;
- PROC_LOCK(td->td_proc);
- *retval = lim_cur(td->td_proc, RLIMIT_FSIZE);
- PROC_UNLOCK(td->td_proc);
+ *retval = lim_cur(td, RLIMIT_FSIZE);
if (*retval == -1)
*retval = 0x7fffffff;
return 0;
@@ -943,9 +937,7 @@ svr4_sys_ulimit(td, uap)
struct vmspace *vm = td->td_proc->p_vmspace;
register_t r;
- PROC_LOCK(td->td_proc);
- r = lim_cur(td->td_proc, RLIMIT_DATA);
- PROC_UNLOCK(td->td_proc);
+ r = lim_cur(td, RLIMIT_DATA);
if (r == -1)
r = 0x7fffffff;
@@ -957,9 +949,7 @@ svr4_sys_ulimit(td, uap)
}
case SVR4_GDESLIM:
- PROC_LOCK(td->td_proc);
- *retval = lim_cur(td->td_proc, RLIMIT_NOFILE);
- PROC_UNLOCK(td->td_proc);
+ *retval = lim_cur(td, RLIMIT_NOFILE);
if (*retval == -1)
*retval = 0x7fffffff;
return 0;
diff --git a/sys/compat/svr4/svr4_resource.c b/sys/compat/svr4/svr4_resource.c
index efa0bcf4757d..667ee88c1d3f 100644
--- a/sys/compat/svr4/svr4_resource.c
+++ b/sys/compat/svr4/svr4_resource.c
@@ -130,9 +130,7 @@ svr4_sys_getrlimit(td, uap)
if (rl == -1)
return EINVAL;
- PROC_LOCK(td->td_proc);
- lim_rlimit(td->td_proc, rl, &blim);
- PROC_UNLOCK(td->td_proc);
+ lim_rlimit(td, rl, &blim);
/*
* Our infinity, is their maxfiles.
@@ -181,9 +179,7 @@ svr4_sys_setrlimit(td, uap)
if ((error = copyin(uap->rlp, &slim, sizeof(slim))) != 0)
return error;
- PROC_LOCK(td->td_proc);
- lim_rlimit(td->td_proc, rl, &curlim);
- PROC_UNLOCK(td->td_proc);
+ lim_rlimit(td, rl, &curlim);
/*
* if the limit is SVR4_RLIM_INFINITY, then we set it to our
@@ -228,9 +224,7 @@ svr4_sys_getrlimit64(td, uap)
if (rl == -1)
return EINVAL;
- PROC_LOCK(td->td_proc);
- lim_rlimit(td->td_proc, rl, &blim);
- PROC_UNLOCK(td->td_proc);
+ lim_rlimit(td, rl, &blim);
/*
* Our infinity, is their maxfiles.
@@ -279,9 +273,7 @@ svr4_sys_setrlimit64(td, uap)
if ((error = copyin(uap->rlp, &slim, sizeof(slim))) != 0)
return error;
- PROC_LOCK(td->td_proc);
- lim_rlimit(td->td_proc, rl, &curlim);
- PROC_UNLOCK(td->td_proc);
+ lim_rlimit(td, rl, &curlim);
/*
* if the limit is SVR4_RLIM64_INFINITY, then we set it to our