Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys



YAMAMOTO Takashi wrote:

i think policy is necessary to convert priority.

So something like:

        error = do_sched_getparam(SCARG(uap, pid), 0, &policy, NULL);
        if (error)
                goto out;
        error = sched_native2linux(policy, NULL, &policy, NULL);
        if (error)
                goto out;

and we then have the Linux policy/params to do a proper conversion.

(and adjustment of the conversion code to not skip policy conversion as
it's always necessary.)

See attached.

-e.
Index: share/man/man9/kauth.9
===================================================================
RCS file: /cvsroot/src/share/man/man9/kauth.9,v
retrieving revision 1.68
diff -u -p -r1.68 kauth.9
--- share/man/man9/kauth.9      16 Feb 2008 16:39:34 -0000      1.68
+++ share/man/man9/kauth.9      20 Feb 2008 11:50:17 -0000
@@ -25,7 +25,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd February 16, 2008
+.Dd February 20, 2008
 .Dt KAUTH 9
 .Os
 .Sh NAME
@@ -422,18 +422,14 @@ indicates the class of information being
 .Dv KAUTH_REQ_PROCESS_CANSEE_ENV ,
 or
 .Dv KAUTH_REQ_PROCESS_CANSEE_OPENFILES .
-.It Dv KAUTH_PROCESS_SCHEDULER_GET
-Checks whether viewing the scheduler policy is allowed.
-.It Dv KAUTH_PROCESS_SCHEDULER_SET
-Checks whether setting the scheduler policy (class) is allowed.
 .It Dv KAUTH_PROCESS_SCHEDULER_GETAFFINITY
 Checks whether viewing the scheduler affinity is allowed.
 .It Dv KAUTH_PROCESS_SCHEDULER_SETAFFINITY
 Checks whether setting the scheduler affinity is allowed.
 .It Dv KAUTH_PROCESS_SCHEDULER_GETPARAMS
-Checks whether viewing scheduler parameters is allowed.
+Checks whether viewing the scheduler policy and parameters is allowed.
 .It Dv KAUTH_PROCESS_SCHEDULER_SETPARAMS
-Checks whether modifying scheduler parameters is allowed.
+Checks whether modifying the scheduler policy and parameters is allowed.
 .It Dv KAUTH_PROCESS_SIGNAL
 Checks whether an object with one set of credentials can post signals
 to another process.
Index: share/examples/secmodel/secmodel_example.c
===================================================================
RCS file: /cvsroot/src/share/examples/secmodel/secmodel_example.c,v
retrieving revision 1.23
diff -u -p -r1.23 secmodel_example.c
--- share/examples/secmodel/secmodel_example.c  16 Feb 2008 16:39:34 -0000      
1.23
+++ share/examples/secmodel/secmodel_example.c  20 Feb 2008 11:50:17 -0000
@@ -264,8 +264,6 @@ secmodel_example_process_cb(kauth_cred_t
        case KAUTH_PROCESS_KEVENT_FILTER:
        case KAUTH_PROCESS_NICE:
        case KAUTH_PROCESS_RLIMIT:
-       case KAUTH_PROCESS_SCHEDULER_GET:
-       case KAUTH_PROCESS_SCHEDULER_SET:
        case KAUTH_PROCESS_SCHEDULER_GETAFFINITY:
        case KAUTH_PROCESS_SCHEDULER_SETAFFINITY:
        case KAUTH_PROCESS_SCHEDULER_GETPARAM:
Index: sys/compat/linux/common/linux_sched.c
===================================================================
RCS file: /cvsroot/src/sys/compat/linux/common/linux_sched.c,v
retrieving revision 1.48
diff -u -p -r1.48 linux_sched.c
--- sys/compat/linux/common/linux_sched.c       16 Feb 2008 16:39:35 -0000      
1.48
+++ sys/compat/linux/common/linux_sched.c       20 Feb 2008 11:50:17 -0000
@@ -141,6 +141,72 @@ linux_sys_clone(struct lwp *l, const str
        return 0;
 }
 
+static int
+sched_linux2native(int linux_policy, struct linux_sched_param *linux_params,
+    int *native_policy, struct sched_param *native_params)
+{
+       int error;
+
+       error = 0;
+
+       switch (linux_policy) {
+       case LINUX_SCHED_OTHER:
+               *native_policy = SCHED_OTHER;
+               break;
+
+       case LINUX_SCHED_FIFO:
+               *native_policy = SCHED_FIFO;
+               break;
+
+       case LINUX_SCHED_RR:
+               *native_policy = SCHED_RR;
+               break;
+
+       default:
+               error = EINVAL;
+               break;
+       }
+
+       if (linux_params != NULL && native_params != NULL && !error) {
+               native_params = (struct sched_param *)linux_params;
+       }
+
+       return (error);
+}
+
+static int
+sched_native2linux(int native_policy, struct sched_param *native_params,
+    int *linux_policy, struct linux_sched_param *linux_params)
+{
+       int error;
+
+       error = 0;
+
+       switch (native_policy) {
+       case SCHED_OTHER:
+               *linux_policy = LINUX_SCHED_OTHER;
+               break;
+
+       case SCHED_FIFO:
+               *linux_policy = LINUX_SCHED_FIFO;
+               break;
+
+       case SCHED_RR:
+               *linux_policy = LINUX_SCHED_RR;
+               break;
+
+       default:
+               error = EINVAL;
+               break;
+       }
+
+       if (native_params != NULL && linux_params != NULL && !error) {
+               linux_params = (struct linux_sched_param *)native_params;
+       }
+
+       return (error);
+}
+
 int
 linux_sys_sched_setparam(struct lwp *l, const struct 
linux_sys_sched_setparam_args *uap, register_t *retval)
 {
@@ -148,31 +214,37 @@ linux_sys_sched_setparam(struct lwp *l, 
                syscallarg(linux_pid_t) pid;
                syscallarg(const struct linux_sched_param *) sp;
        } */
-       int error;
+       int error, policy;
        struct linux_sched_param lp;
-       struct proc *p;
+       struct sched_param sp;
 
-/*
- * We only check for valid parameters and return afterwards.
- */
-
-       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
-               return EINVAL;
+       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL) {
+               error = EINVAL;
+               goto out;
+       }
 
        error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
        if (error)
-               return error;
+               goto out;
 
-       if (SCARG(uap, pid) != 0) {
-               if ((p = pfind(SCARG(uap, pid))) == NULL)
-                       return ESRCH;
-
-               if (kauth_authorize_process(l->l_cred,
-                   KAUTH_PROCESS_SCHEDULER_SETPARAM, p, NULL, NULL, NULL) != 0)
-                       return EPERM;
-       }
+       /* We need the current policy in Linux terms. */
+       error = do_sched_getparam(SCARG(uap, pid), 0, &policy, NULL);
+       if (error)
+               goto out;
+       error = sched_native2linux(policy, NULL, &policy, NULL);
+       if (error)
+               goto out;
 
-       return 0;
+       error = sched_linux2native(policy, &lp, &policy, &sp);
+       if (error)
+               goto out;
+
+       error = do_sched_setparam(SCARG(uap, pid), 0, policy, &sp);
+       if (error)
+               goto out;
+
+ out:
+       return error;
 }
 
 int
@@ -182,26 +254,29 @@ linux_sys_sched_getparam(struct lwp *l, 
                syscallarg(linux_pid_t) pid;
                syscallarg(struct linux_sched_param *) sp;
        } */
-       struct proc *p;
        struct linux_sched_param lp;
+       struct sched_param sp;
+       int error;
 
-/*
- * We only check for valid parameters and return a dummy priority afterwards.
- */
-       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
-               return EINVAL;
+       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL) {
+               error = EINVAL;
+               goto out;
+       }
 
-       if (SCARG(uap, pid) != 0) {
-               if ((p = pfind(SCARG(uap, pid))) == NULL)
-                       return ESRCH;
+       error = do_sched_getparam(SCARG(uap, pid), 0, NULL, &sp);
+       if (error)
+               goto out;
 
-               if (kauth_authorize_process(l->l_cred,
-                   KAUTH_PROCESS_SCHEDULER_GETPARAM, p, NULL, NULL, NULL) != 0)
-                       return EPERM;
-       }
+       error = sched_native2linux(0, &sp, NULL, &lp);
+       if (error)
+               goto out;
+
+       error = copyout(&lp, SCARG(uap, sp), sizeof(lp));
+       if (error)
+               goto out;
 
-       lp.sched_priority = 0;
-       return copyout(&lp, SCARG(uap, sp), sizeof(lp));
+ out:
+       return error;
 }
 
 int
@@ -212,38 +287,29 @@ linux_sys_sched_setscheduler(struct lwp 
                syscallarg(int) policy;
                syscallarg(cont struct linux_sched_scheduler *) sp;
        } */
-       int error;
+       int error, policy;
        struct linux_sched_param lp;
-       struct proc *p;
+       struct sched_param sp;
 
-/*
- * We only check for valid parameters and return afterwards.
- */
-
-       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
-               return EINVAL;
+       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL) {
+               error = EINVAL;
+               goto out;
+       }
 
        error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
        if (error)
-               return error;
+               goto out;
 
-       if (SCARG(uap, pid) != 0) {
-               if ((p = pfind(SCARG(uap, pid))) == NULL)
-                       return ESRCH;
-
-               if (kauth_authorize_process(l->l_cred,
-                   KAUTH_PROCESS_SCHEDULER_SET, p, NULL, NULL, NULL) != 0)
-                       return EPERM;
-       }
+       error = sched_linux2native(SCARG(uap, policy), &lp, &policy, &sp);
+       if (error)
+               goto out;
 
-       return 0;
-/*
- * We can't emulate anything put the default scheduling policy.
- */
-       if (SCARG(uap, policy) != LINUX_SCHED_OTHER || lp.sched_priority != 0)
-               return EINVAL;
+       error = do_sched_setparam(SCARG(uap, pid), 0, policy, &sp);
+       if (error)
+               goto out;
 
-       return 0;
+ out:
+       return error;
 }
 
 int
@@ -252,27 +318,22 @@ linux_sys_sched_getscheduler(struct lwp 
        /* {
                syscallarg(linux_pid_t) pid;
        } */
-       struct proc *p;
+       int error, policy;
 
        *retval = -1;
-/*
- * We only check for valid parameters and return afterwards.
- */
 
-       if (SCARG(uap, pid) != 0) {
-               if ((p = pfind(SCARG(uap, pid))) == NULL)
-                       return ESRCH;
-
-               if (kauth_authorize_process(l->l_cred,
-                   KAUTH_PROCESS_SCHEDULER_GET, p, NULL, NULL, NULL) != 0)
-                       return EPERM;
-       }
+       error = do_sched_getparam(SCARG(uap, pid), 0, &policy, NULL);
+       if (error)
+               goto out;
 
-/*
- * We can't emulate anything put the default scheduling policy.
- */
-       *retval = LINUX_SCHED_OTHER;
-       return 0;
+       error = sched_native2linux(policy, NULL, &policy, NULL);
+       if (error)
+               goto out;
+
+       *retval = policy;
+
+ out:
+       return error;
 }
 
 int
Index: sys/compat/freebsd/freebsd_sched.c
===================================================================
RCS file: /cvsroot/src/sys/compat/freebsd/freebsd_sched.c,v
retrieving revision 1.16
diff -u -p -r1.16 freebsd_sched.c
--- sys/compat/freebsd/freebsd_sched.c  16 Feb 2008 16:39:35 -0000      1.16
+++ sys/compat/freebsd/freebsd_sched.c  20 Feb 2008 11:50:18 -0000
@@ -64,6 +64,73 @@ freebsd_sys_yield(struct lwp *l, const v
        return 0;
 }
 
+static int
+sched_freebsd2native(int freebsd_policy,
+    struct freebsd_sched_param *freebsd_params, int *native_policy,
+    struct sched_param *native_params)
+{
+       int error;
+
+       error = 0;
+
+       switch (freebsd_policy) {
+       case FREEBSD_SCHED_OTHER:
+               *native_policy = SCHED_OTHER;
+               break;
+
+       case FREEBSD_SCHED_FIFO:
+               *native_policy = SCHED_FIFO;
+               break;
+        
+       case FREEBSD_SCHED_RR:
+               *native_policy = SCHED_RR;
+               break;
+
+       default:
+               error = EINVAL;
+               break;
+       }
+ 
+       if (freebsd_params != NULL && native_params != NULL && !error) {
+               native_params = (struct sched_param *)freebsd_params;
+       }
+        
+       return (error)
+}
+
+static int
+sched_native2freebsd(int native_policy, struct sched_param *native_params,
+    int *freebsd_policy, struct freebsd_sched_param *freebsd_params)
+{
+       int error;
+
+       error = 0;
+
+       switch (native_policy) {
+       case SCHED_OTHER:
+               *freebsd_policy = FREEBSD_SCHED_OTHER;
+               break;
+
+       case SCHED_FIFO:
+               *freebsd_policy = FREEBSD_SCHED_FIFO;
+               break;
+        
+       case SCHED_RR:
+               *freebsd_policy = FREEBSD_SCHED_RR;
+               break;
+
+       default:
+               error = EINVAL;
+               break;
+       }
+ 
+       if (native_params != NULL && freebsd_params != NULL && !error) {
+               freebsd_params = (struct freebsd_sched_param *)native_params;
+       }
+        
+       return (error)
+}
+
 int
 freebsd_sys_sched_setparam(struct lwp *l, const struct 
freebsd_sys_sched_setparam_args *uap, register_t *retval)
 {
@@ -71,29 +138,36 @@ freebsd_sys_sched_setparam(struct lwp *l
                syscallarg(pid_t) pid;
                syscallarg(const struct freebsd_sched_param *) sp;
        } */
-       int error;
+       int error, policy;
        struct freebsd_sched_param lp;
-       struct proc *p;
+       struct sched_param sp;
 
-       /*
-        * We only check for valid parameters and return afterwards.
-        */
-       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
-               return EINVAL;
+       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL) {
+               error = EINVAL;
+               goto out;
+       }
 
        error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
        if (error)
-               return error;
+               goto out;
+
+       /* We need the current policy in FreeBSD terms. */
+       error = do_sched_getparam(SCARG(uap, pid), 0, &policy, NULL);
+       if (error)
+               goto out;
+       error = sched_native2freebsd(policy, NULL, &policy, NULL);
+       if (error)
+               goto out;
 
-       mutex_enter(&proclist_lock);
-       p = p_find(SCARG(uap, pid), PFIND_LOCKED | PFIND_UNLOCK_FAIL);
-       if (p == NULL)
-               error = ESRCH;
-       else
-               error = kauth_authorize_process(l->l_cred,
-                   KAUTH_PROCESS_SCHEDULER_SETPARAM, p, NULL, NULL, NULL);
-       mutex_exit(&proclist_lock);
+       error = sched_freebsd2native(policy, &lp, &policy, &sp);
+       if (error)
+               goto out;
 
+       error = do_sched_setparam(SCARG(uap, pid), 0, policy, &sp);
+       if (error)
+               goto out;
+
+ out:
        return error;
 }
 
@@ -105,30 +179,28 @@ freebsd_sys_sched_getparam(struct lwp *l
                syscallarg(struct freebsd_sched_param *) sp;
        } */
        struct freebsd_sched_param lp;
+       struct sched_param sp;
        int error;
-       struct proc *p;
 
-       /*
-        * We only check for valid parameters and return a dummy
-        * priority afterwards.
-        */
-       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
-               return EINVAL;
+       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL) {
+               error = EINVAL;
+               goto out;
+       }
 
-       mutex_enter(&proclist_lock);
-       p = p_find(SCARG(uap, pid), PFIND_LOCKED | PFIND_UNLOCK_FAIL);
-       if (p == NULL)
-               error = ESRCH;
-       else
-               error = kauth_authorize_process(l->l_cred,
-                   KAUTH_PROCESS_SCHEDULER_GETPARAM, p, NULL, NULL, NULL);
-       mutex_exit(&proclist_lock);
+       error = do_sched_getparam(SCARG(uap, pid), 0, NULL, &sp);
+       if (error)
+               goto out;
 
+       error = sched_native2freebsd(0, &sp, NULL, &lp);
        if (error)
-               return error;
+               goto out;
 
-       lp.sched_priority = 0;
-       return copyout(&lp, SCARG(uap, sp), sizeof(lp));
+       error = copyout(&lp, SCARG(uap, sp), sizeof(lp));
+       if (error)
+               goto out;
+
+ out:
+       return (error);
 }
 
 int
@@ -139,39 +211,29 @@ freebsd_sys_sched_setscheduler(struct lw
                syscallarg(int) policy;
                syscallarg(cont struct freebsd_sched_scheduler *) sp;
        } */
-       int error;
+       int error, policy;
        struct freebsd_sched_param lp;
-       struct proc *p;
+       struct sched_param sp;
 
-       /*
-        * We only check for valid parameters and return afterwards.
-        */
-       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
-               return EINVAL;
+       if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL) {
+               error = EINVAL;
+               goto out;
+       }
 
        error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
        if (error)
-               return error;
-
-       mutex_enter(&proclist_lock);
-       p = p_find(SCARG(uap, pid), PFIND_LOCKED | PFIND_UNLOCK_FAIL);
-       if (p == NULL)
-               error = ESRCH;
-       else
-               error = kauth_authorize_process(l->l_cred,
-                   KAUTH_PROCESS_SCHEDULER_SET, p, NULL, NULL, NULL);
-       mutex_exit(&proclist_lock);
+               goto out;
 
+       error = sched_freebsd2native(SCARG(uap, policy), &lp, &policy, &sp);
        if (error)
-               return error;
+               goto out;
 
-       /*
-        * We can't emulate anything put the default scheduling policy.
-        */
-       if (SCARG(uap, policy) != FREEBSD_SCHED_OTHER || lp.sched_priority != 0)
-               return EINVAL;
+       error = do_sched_setparam(SCARG(uap, pid), 0, policy, &sp);
+       if (error)
+               goto out;
 
-       return 0;
+ out:
+       return error;
 }
 
 int
@@ -180,31 +242,22 @@ freebsd_sys_sched_getscheduler(struct lw
        /* {
                syscallarg(pid_t) pid;
        } */
-       int error;
-       struct proc *p;
+       int error, policy;
 
        *retval = -1;
 
-       /*
-        * We only check for valid parameters and return afterwards.
-        */
-       mutex_enter(&proclist_lock);
-       p = p_find(SCARG(uap, pid), PFIND_LOCKED | PFIND_UNLOCK_FAIL);
-       if (p == NULL)
-               error = ESRCH;
-       else
-               error = kauth_authorize_process(l->l_cred,
-                   KAUTH_PROCESS_SCHEDULER_GET, p, NULL, NULL, NULL);
-       mutex_exit(&proclist_lock);
+       error = do_sched_getparam(l, SCARG(uap, pid), 0, &policy, NULL);
+       if (error)
+               goto out;
 
+       error = sched_native2freebsd(policy, NULL, &policy, NULL);
        if (error)
-               return error;
+               goto out;
 
-       /*
-        * We can't emulate anything put the default scheduling policy.
-        */
-       *retval = FREEBSD_SCHED_OTHER;
-       return 0;
+       *retval = policy;
+
+ out:
+       return error;
 }
 
 int
Index: sys/kern/sys_sched.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sys_sched.c,v
retrieving revision 1.12
diff -u -p -r1.12 sys_sched.c
--- sys/kern/sys_sched.c        17 Feb 2008 19:22:35 -0000      1.12
+++ sys/kern/sys_sched.c        20 Feb 2008 11:50:18 -0000
@@ -93,35 +93,19 @@ convert_pri(lwp_t *l, int policy, pri_t 
        return l->l_class;
 }
 
-/*
- * Set scheduling parameters.
- */
 int
-sys__sched_setparam(struct lwp *l, const struct sys__sched_setparam_args *uap,
-    register_t *retval)
+do_sched_setparam(pid_t pid, lwpid_t lid, int policy,
+    const struct sched_param *params)
 {
-       /* {
-               syscallarg(pid_t) pid;
-               syscallarg(lwpid_t) lid;
-               syscallarg(int) policy;
-               syscallarg(const struct sched_param *) params;
-       } */
-       struct sched_param param;
        struct proc *p;
        struct lwp *t;
-       lwpid_t lid;
-       u_int lcnt;
-       int policy;
        pri_t pri;
+       u_int lcnt;
        int error;
 
-       /* Get the parameters from the user-space */
-       error = copyin(SCARG(uap, params), &param, sizeof(param));
-       if (error) {
-               return error;
-       }
-       pri = param.sched_priority;
-       policy = SCARG(uap, policy);
+       error = 0;
+
+       pri = params->sched_priority;
 
        /* If no parameters specified, just return (this should not happen) */
        if (pri == PRI_NONE && policy == SCHED_NONE)
@@ -135,9 +119,9 @@ sys__sched_setparam(struct lwp *l, const
        if (pri != PRI_NONE && (pri < SCHED_PRI_MIN || pri > SCHED_PRI_MAX))
                return EINVAL;
 
-       if (SCARG(uap, pid) != 0) {
+       if (pid != 0) {
                /* Find the process */
-               p = p_find(SCARG(uap, pid), PFIND_UNLOCK_FAIL);
+               p = p_find(pid, PFIND_UNLOCK_FAIL);
                if (p == NULL)
                        return ESRCH;
                mutex_enter(&p->p_smutex);
@@ -149,24 +133,25 @@ sys__sched_setparam(struct lwp *l, const
                }
        } else {
                /* Use the calling process */
-               p = l->l_proc;
+               p = curlwp->l_proc;
                mutex_enter(&p->p_smutex);
        }
 
        /* Find the LWP(s) */
        lcnt = 0;
-       lid = SCARG(uap, lid);
+       lid = lid;
        LIST_FOREACH(t, &p->p_lwps, l_sibling) {
                pri_t kpri;
                int lpolicy;
 
                if (lid && lid != t->l_lid)
                        continue;
+               lcnt++;
                KASSERT(pri != PRI_NONE || policy != SCHED_NONE);
                lwp_lock(t);
 
                if (policy == SCHED_NONE)
-                       lpolicy = l->l_class;
+                       lpolicy = t->l_class;
                else
                        lpolicy = policy;
 
@@ -177,11 +162,13 @@ sys__sched_setparam(struct lwp *l, const
                kpri = convert_pri(t, lpolicy, pri);
 
                /* Check the permission */
-               error = kauth_authorize_process(l->l_cred,
+               error = kauth_authorize_process(kauth_cred_get(),
                    KAUTH_PROCESS_SCHEDULER_SETPARAM, p, t, KAUTH_ARG(lpolicy),
                    KAUTH_ARG(kpri));
-               if (error)
+               if (error) {
+                       lwp_unlock(t);
                        break;
+               }
 
                /* Set the scheduling class */
                if (policy != SCHED_NONE)
@@ -192,38 +179,55 @@ sys__sched_setparam(struct lwp *l, const
                        lwp_changepri(t, kpri);
 
                lwp_unlock(t);
-               lcnt++;
        }
        mutex_exit(&p->p_smutex);
        return (lcnt == 0) ? ESRCH : error;
 }
 
 /*
- * Get scheduling parameters.
+ * Set scheduling parameters.
  */
 int
-sys__sched_getparam(struct lwp *l, const struct sys__sched_getparam_args *uap,
+sys__sched_setparam(struct lwp *l, const struct sys__sched_setparam_args *uap,
     register_t *retval)
 {
        /* {
                syscallarg(pid_t) pid;
                syscallarg(lwpid_t) lid;
-               syscallarg(int *) policy;
-               syscallarg(struct sched_param *) params;
+               syscallarg(int) policy;
+               syscallarg(const struct sched_param *) params;
        } */
-       struct sched_param param;
+       struct sched_param params;
+       int error;
+
+       /* Get the parameters from the user-space */
+       error = copyin(SCARG(uap, params), &params, sizeof(params));
+       if (error)
+               goto out;
+
+       error = do_sched_setparam(SCARG(uap, pid), SCARG(uap, lid),
+           SCARG(uap, policy), &params);
+
+ out:
+       return (error);
+}
+
+int
+do_sched_getparam(pid_t pid, lwpid_t lid, int *policy,
+    struct sched_param *params)
+{
+       struct sched_param lparams;
        struct lwp *t;
-       lwpid_t lid;
-       int error, policy;
+       int error, lpolicy;
 
        /* If not specified, use the first LWP */
-       lid = SCARG(uap, lid) == 0 ? 1 : SCARG(uap, lid);
+       lid = lid == 0 ? 1 : lid;
 
-       if (SCARG(uap, pid) != 0) {
+       if (pid != 0) {
                /* Locks the LWP */
-               t = lwp_find2(SCARG(uap, pid), lid);
+               t = lwp_find2(pid, lid);
        } else {
-               struct proc *p = l->l_proc;
+               struct proc *p = curlwp->l_proc;
                /* Use the calling process */
                mutex_enter(&p->p_smutex);
                t = lwp_find(p, lid);
@@ -237,34 +241,67 @@ sys__sched_getparam(struct lwp *l, const
        }
 
        /* Check the permission */
-       error = kauth_authorize_process(l->l_cred,
+       error = kauth_authorize_process(kauth_cred_get(),
            KAUTH_PROCESS_SCHEDULER_GETPARAM, t->l_proc, NULL, NULL, NULL);
        if (error != 0) {
                lwp_unlock(t);
                goto error;
        }
 
-       param.sched_priority = t->l_priority;
-       policy = t->l_class;
+       lparams.sched_priority = t->l_priority;
+       lpolicy = t->l_class;
        lwp_unlock(t);
 
-       switch (policy) {
+       switch (lpolicy) {
        case SCHED_OTHER:
-               param.sched_priority -= PRI_USER;
+               lparams.sched_priority -= PRI_USER;
                break;
        case SCHED_RR:
        case SCHED_FIFO:
-               param.sched_priority -= PRI_USER_RT;
+               lparams.sched_priority -= PRI_USER_RT;
                break;
        }
-       error = copyout(&param, SCARG(uap, params), sizeof(param));
-       if (error == 0 && SCARG(uap, policy) != NULL)
-               error = copyout(&policy, SCARG(uap, policy), sizeof(int));
+
+       if (policy != NULL)
+               *policy = lpolicy;
+
+       if (params != NULL)
+               *params = lparams;
+
 error:
        return error;
 }
 
 /*
+ * Get scheduling parameters.
+ */
+int
+sys__sched_getparam(struct lwp *l, const struct sys__sched_getparam_args *uap,
+    register_t *retval)
+{
+       /* {
+               syscallarg(pid_t) pid;
+               syscallarg(lwpid_t) lid;
+               syscallarg(int *) policy;
+               syscallarg(struct sched_param *) params;
+       } */
+       struct sched_param params;
+       int error, policy;
+
+       error = do_sched_getparam(SCARG(uap, pid), SCARG(uap, lid), &policy,
+           &params);
+       if (error)
+               goto out;
+
+       error = copyout(&params, SCARG(uap, params), sizeof(params));
+       if (error == 0 && SCARG(uap, policy) != NULL)
+               error = copyout(&policy, SCARG(uap, policy), sizeof(int));
+
+ out:
+       return (error);
+}
+
+/*
  * Set affinity.
  */
 int
Index: sys/sys/sched.h
===================================================================
RCS file: /cvsroot/src/sys/sys/sched.h,v
retrieving revision 1.47
diff -u -p -r1.47 sched.h
--- sys/sys/sched.h     9 Feb 2008 16:58:01 -0000       1.47
+++ sys/sys/sched.h     20 Feb 2008 11:50:18 -0000
@@ -253,5 +253,8 @@ int         mi_switch(struct lwp *);
 void           resched_cpu(struct lwp *);
 void           updatertime(lwp_t *, const struct bintime *);
 
+int            do_sched_setparam(pid_t, lwpid_t, int, const struct sched_param 
*);
+int            do_sched_getparam(pid_t, lwpid_t, int *, struct sched_param *);
+
 #endif /* _KERNEL */
 #endif /* _SYS_SCHED_H_ */
Index: sys/sys/kauth.h
===================================================================
RCS file: /cvsroot/src/sys/sys/kauth.h,v
retrieving revision 1.50
diff -u -p -r1.50 kauth.h
--- sys/sys/kauth.h     16 Feb 2008 16:39:34 -0000      1.50
+++ sys/sys/kauth.h     20 Feb 2008 11:50:19 -0000
@@ -138,8 +138,6 @@ enum {
        KAUTH_PROCESS_PROCFS,
        KAUTH_PROCESS_PTRACE,
        KAUTH_PROCESS_RLIMIT,
-       KAUTH_PROCESS_SCHEDULER_GET,
-       KAUTH_PROCESS_SCHEDULER_SET,
        KAUTH_PROCESS_SCHEDULER_GETAFFINITY,
        KAUTH_PROCESS_SCHEDULER_SETAFFINITY,
        KAUTH_PROCESS_SCHEDULER_GETPARAM,


Home | Main Index | Thread Index | Old Index