Page MenuHomeFreeBSD
Authored By
olce
Sep 25 2024, 4:36 PM
Size
3 KB
Referenced Files
None
Subscribers
None

D46747-olce.patch

diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index 8362efb967f9..be23e91f29c6 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -810,19 +810,95 @@ static int
getrlimitusage_one(struct proc *p, u_int which, int flags, rlim_t *res)
{
struct thread *td;
- struct uidinfo *ui;
- struct vmspace *vm;
- uid_t uid;
- int error;
- error = 0;
- PROC_LOCK(p);
- uid = (flags & GETRLIMITUSAGE_EUID) == 0 ? p->p_ucred->cr_ruid :
- p->p_ucred->cr_uid;
- PROC_UNLOCK(p);
+ switch (which) {
+ struct uidinfo *ui;
+ uid_t uid;
+ case RLIMIT_NPROC:
+ case RLIMIT_SBSIZE:
+ case RLIMIT_NPTS:
+ case RLIMIT_SWAP:
+ case RLIMIT_KQUEUES:
+ case RLIMIT_UMTXP:
+ case RLIMIT_PIPEBUF:
+ if (p == curproc) {
+ uid = (flags & GETRLIMITUSAGE_EUID) == 0 ?
+ curthread->td_ucred->cr_ruid :
+ curthread->td_ucred->cr_uid;
+ } else {
+ PROC_LOCK(p);
+ uid = (flags & GETRLIMITUSAGE_EUID) == 0 ?
+ p->p_ucred->cr_ruid :
+ p->p_ucred->cr_uid;
+ PROC_UNLOCK(p);
+ }
+ ui = uifind(uid);
- ui = uifind(uid);
- vm = vmspace_acquire_ref(p);
+ switch (which) {
+ case RLIMIT_NPROC:
+ *res = ui->ui_proccnt;
+ break;
+ case RLIMIT_SBSIZE:
+ *res = ui->ui_sbsize;
+ break;
+ case RLIMIT_NPTS:
+ *res = ui->ui_ptscnt;
+ break;
+ case RLIMIT_SWAP:
+ *res = ui->ui_vmsize;
+ break;
+ case RLIMIT_KQUEUES:
+ *res = ui->ui_kqcnt;
+ break;
+ case RLIMIT_UMTXP:
+ *res = ui->ui_umtxcnt;
+ break;
+ case RLIMIT_PIPEBUF:
+ *res = ui->ui_pipecnt;
+ break;
+ default:
+ __assert_unreachable();
+ }
+
+ uifree(ui);
+ return (0);
+ }
+
+ switch (which) {
+ struct vmspace *vm;
+
+ case RLIMIT_DATA:
+ case RLIMIT_STACK:
+ case RLIMIT_RSS:
+ case RLIMIT_MEMLOCK:
+ case RLIMIT_VMEM:
+ vm = vmspace_acquire_ref(p);
+ if (vm == NULL)
+ return (ENXIO);
+
+ switch (which) {
+ case RLIMIT_DATA:
+ *res = vm->vm_dsize * PAGE_SIZE;
+ break;
+ case RLIMIT_STACK:
+ *res = vm->vm_ssize * PAGE_SIZE;
+ break;
+ case RLIMIT_RSS:
+ *res = vmspace_resident_count(vm) * PAGE_SIZE;
+ break;
+ case RLIMIT_MEMLOCK:
+ *res = pmap_wired_count(vmspace_pmap(vm)) * PAGE_SIZE;
+ break;
+ case RLIMIT_VMEM:
+ *res = vm->vm_map.size;
+ break;
+ default:
+ __assert_unreachable();
+ }
+
+ vmspace_free(vm);
+ return (0);
+ }
switch (which) {
case RLIMIT_CPU:
@@ -830,78 +906,21 @@ getrlimitusage_one(struct proc *p, u_int which, int flags, rlim_t *res)
PROC_STATLOCK(p);
FOREACH_THREAD_IN_PROC(p, td)
ruxagg(p, td);
+ *res = p->p_rux.rux_runtime;
PROC_STATUNLOCK(p);
- *res = p->p_rux.rux_runtime / cpu_tickrate();
PROC_UNLOCK(p);
- break;
- case RLIMIT_FSIZE:
- error = ENXIO;
- break;
- case RLIMIT_DATA:
- if (vm == NULL)
- error = ENXIO;
- else
- *res = vm->vm_dsize * PAGE_SIZE;
- break;
- case RLIMIT_STACK:
- if (vm == NULL)
- error = ENXIO;
- else
- *res = vm->vm_ssize * PAGE_SIZE;
- break;
- case RLIMIT_CORE:
- error = ENXIO;
- break;
- case RLIMIT_RSS:
- if (vm == NULL)
- error = ENXIO;
- else
- *res = vmspace_resident_count(vm) * PAGE_SIZE;
- break;
- case RLIMIT_MEMLOCK:
- if (vm == NULL)
- error = ENXIO;
- else
- *res = pmap_wired_count(vmspace_pmap(vm)) * PAGE_SIZE;
- break;
- case RLIMIT_NPROC:
- *res = ui->ui_proccnt;
+ *res /= cpu_tickrate();
break;
case RLIMIT_NOFILE:
*res = proc_nfiles(p);
break;
- case RLIMIT_SBSIZE:
- *res = ui->ui_sbsize;
- break;
- case RLIMIT_VMEM:
- if (vm == NULL)
- error = ENXIO;
- else
- *res = vm->vm_map.size;
- break;
- case RLIMIT_NPTS:
- *res = ui->ui_ptscnt;
- break;
- case RLIMIT_SWAP:
- *res = ui->ui_vmsize;
- break;
- case RLIMIT_KQUEUES:
- *res = ui->ui_kqcnt;
- break;
- case RLIMIT_UMTXP:
- *res = ui->ui_umtxcnt;
- break;
- case RLIMIT_PIPEBUF:
- *res = ui->ui_pipecnt;
- break;
+ case RLIMIT_FSIZE:
+ case RLIMIT_CORE:
+ return (ENXIO);
default:
- error = EINVAL;
- break;
+ return (EINVAL);
}
-
- vmspace_free(vm);
- uifree(ui);
- return (error);
+ return (0);
}
int

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
12847435
Default Alt Text
D46747-olce.patch (3 KB)

Event Timeline