Date: Sun, 24 May 2015 15:18:20 +0000 (UTC) From: Dmitry Chagin <dchagin@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r283401 - in head/sys: amd64/linux32 compat/linux i386/linux Message-ID: <201505241518.t4OFIKeJ046306@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dchagin Date: Sun May 24 15:18:19 2015 New Revision: 283401 URL: https://svnweb.freebsd.org/changeset/base/283401 Log: Implement prlimit64() system call. Differential Revision: https://reviews.freebsd.org/D1050 Reviewed by: emaste, trasz Modified: head/sys/amd64/linux32/linux32_dummy.c head/sys/amd64/linux32/syscalls.master head/sys/compat/linux/linux_misc.c head/sys/compat/linux/linux_misc.h head/sys/i386/linux/linux_dummy.c head/sys/i386/linux/syscalls.master Modified: head/sys/amd64/linux32/linux32_dummy.c ============================================================================== --- head/sys/amd64/linux32/linux32_dummy.c Sun May 24 15:15:46 2015 (r283400) +++ head/sys/amd64/linux32/linux32_dummy.c Sun May 24 15:18:19 2015 (r283401) @@ -133,8 +133,6 @@ DUMMY(perf_event_open); DUMMY(recvmmsg); DUMMY(fanotify_init); DUMMY(fanotify_mark); -/* linux 2.6.36: */ -DUMMY(prlimit64); /* later: */ DUMMY(name_to_handle_at); DUMMY(open_by_handle_at); Modified: head/sys/amd64/linux32/syscalls.master ============================================================================== --- head/sys/amd64/linux32/syscalls.master Sun May 24 15:15:46 2015 (r283400) +++ head/sys/amd64/linux32/syscalls.master Sun May 24 15:18:19 2015 (r283401) @@ -554,7 +554,10 @@ 338 AUE_NULL STD { int linux_fanotify_init(void); } 339 AUE_NULL STD { int linux_fanotify_mark(void); } ; linux 2.6.36: -340 AUE_NULL STD { int linux_prlimit64(void); } +340 AUE_NULL STD { int linux_prlimit64(l_pid_t pid, \ + l_uint resource, \ + struct rlimit *new, \ + struct rlimit *old); } ; later: 341 AUE_NULL STD { int linux_name_to_handle_at(void); } 342 AUE_NULL STD { int linux_open_by_handle_at(void); } Modified: head/sys/compat/linux/linux_misc.c ============================================================================== --- head/sys/compat/linux/linux_misc.c Sun May 24 15:15:46 2015 (r283400) +++ head/sys/compat/linux/linux_misc.c Sun May 24 15:18:19 2015 (r283401) @@ -2034,6 +2034,79 @@ linux_sched_setaffinity(struct thread *t return (sys_cpuset_setaffinity(td, &csa)); } +struct linux_rlimit64 { + uint64_t rlim_cur; + uint64_t rlim_max; +}; + +int +linux_prlimit64(struct thread *td, struct linux_prlimit64_args *args) +{ + struct rlimit rlim, nrlim; + struct linux_rlimit64 lrlim; + struct proc *p; + u_int which; + int flags; + int error; + +#ifdef DEBUG + if (ldebug(prlimit64)) + printf(ARGS(prlimit64, "%d, %d, %p, %p"), args->pid, + args->resource, (void *)args->new, (void *)args->old); +#endif + + if (args->resource >= LINUX_RLIM_NLIMITS) + return (EINVAL); + + which = linux_to_bsd_resource[args->resource]; + if (which == -1) + return (EINVAL); + + if (args->new != NULL) { + /* + * Note. Unlike FreeBSD where rlim is signed 64-bit Linux + * rlim is unsigned 64-bit. FreeBSD treats negative limits + * as INFINITY so we do not need a conversion even. + */ + error = copyin(args->new, &nrlim, sizeof(nrlim)); + if (error != 0) + return (error); + } + + flags = PGET_HOLD | PGET_NOTWEXIT; + if (args->new != NULL) + flags |= PGET_CANDEBUG; + else + flags |= PGET_CANSEE; + error = pget(args->pid, flags, &p); + if (error != 0) + return (error); + + if (args->old != NULL) { + PROC_LOCK(p); + lim_rlimit(p, which, &rlim); + PROC_UNLOCK(p); + if (rlim.rlim_cur == RLIM_INFINITY) + lrlim.rlim_cur = LINUX_RLIM_INFINITY; + else + lrlim.rlim_cur = rlim.rlim_cur; + if (rlim.rlim_max == RLIM_INFINITY) + lrlim.rlim_max = LINUX_RLIM_INFINITY; + else + lrlim.rlim_max = rlim.rlim_max; + error = copyout(&lrlim, args->old, sizeof(lrlim)); + if (error != 0) + goto out; + } + + if (args->new != NULL) + error = kern_proc_setrlimit(td, p, which, &nrlim); + + out: + PRELE(p); + return (error); +} + int linux_sched_rr_get_interval(struct thread *td, struct linux_sched_rr_get_interval_args *uap) Modified: head/sys/compat/linux/linux_misc.h ============================================================================== --- head/sys/compat/linux/linux_misc.h Sun May 24 15:15:46 2015 (r283400) +++ head/sys/compat/linux/linux_misc.h Sun May 24 15:18:19 2015 (r283401) @@ -130,6 +130,7 @@ extern int stclohz; #define LINUX_P_PID 1 #define LINUX_P_PGID 2 +#define LINUX_RLIM_INFINITY (~0UL) int linux_common_wait(struct thread *td, int pid, int *status, int options, struct rusage *ru); Modified: head/sys/i386/linux/linux_dummy.c ============================================================================== --- head/sys/i386/linux/linux_dummy.c Sun May 24 15:15:46 2015 (r283400) +++ head/sys/i386/linux/linux_dummy.c Sun May 24 15:18:19 2015 (r283401) @@ -129,8 +129,6 @@ DUMMY(perf_event_open); DUMMY(recvmmsg); DUMMY(fanotify_init); DUMMY(fanotify_mark); -/* linux 2.6.36: */ -DUMMY(prlimit64); /* later: */ DUMMY(name_to_handle_at); DUMMY(open_by_handle_at); Modified: head/sys/i386/linux/syscalls.master ============================================================================== --- head/sys/i386/linux/syscalls.master Sun May 24 15:15:46 2015 (r283400) +++ head/sys/i386/linux/syscalls.master Sun May 24 15:18:19 2015 (r283401) @@ -562,7 +562,10 @@ 338 AUE_NULL STD { int linux_fanotify_init(void); } 339 AUE_NULL STD { int linux_fanotify_mark(void); } ; linux 2.6.36: -340 AUE_NULL STD { int linux_prlimit64(void); } +340 AUE_NULL STD { int linux_prlimit64(l_pid_t pid, \ + l_uint resource, \ + struct rlimit *new, \ + struct rlimit *old); } ; later: 341 AUE_NULL STD { int linux_name_to_handle_at(void); } 342 AUE_NULL STD { int linux_open_by_handle_at(void); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201505241518.t4OFIKeJ046306>