1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <errno.h>
  30 #include <sys/types.h>
  31 #include <sys/lx_debug.h>
  32 #include <sys/lx_misc.h>
  33 #include <sys/lx_syscall.h>
  34 #include <sys/lx_types.h>
  35 #include <sys/resource.h>
  36 #include <sys/lx_misc.h>
  37 
  38 int
  39 lx_getpriority(uintptr_t p1, uintptr_t p2)
  40 {
  41         uint_t  which = (int)p1;
  42         id_t    who  = (id_t)p2;
  43         int     ret;
  44 
  45         /*
  46          * The only valid values for 'which' are positive integers, and unlike
  47          * Solaris, linux doesn't support anything past PRIO_USER.
  48          */
  49         if (which > PRIO_USER)
  50                 return (-EINVAL);
  51 
  52         lx_debug("\tgetpriority(%d, %d)", which, who);
  53 
  54         errno = 0;
  55 
  56         if ((which == PRIO_PROCESS) && (who == 1))
  57                 who = zoneinit_pid;
  58 
  59         ret = getpriority(which, who);
  60         if (ret == -1 && errno != 0)
  61                 return (-errno);
  62 
  63         /*
  64          * The return value of the getpriority syscall is biased by 20 to avoid
  65          * returning negative values when successful.
  66          */
  67         return (20 - ret);
  68 }
  69 
  70 int
  71 lx_setpriority(uintptr_t p1, uintptr_t p2, uintptr_t p3)
  72 {
  73         int which = (int)p1;
  74         id_t who  = (id_t)p2;
  75         int prio  = (int)p3;
  76         int rval;
  77 
  78         if (which > PRIO_USER)
  79                 return (-EINVAL);
  80 
  81         lx_debug("\tsetpriority(%d, %d, %d)", which, who, prio);
  82 
  83         if ((which == PRIO_PROCESS) && (who == 1))
  84                 who = zoneinit_pid;
  85 
  86         rval = setpriority(which, who, prio);
  87 
  88         return ((rval == -1) ? -errno : rval);
  89 }