2000-08-22 02:24:02 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Marcel Moolenaar
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
2000-11-01 08:49:48 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer
|
2000-08-22 02:24:02 +00:00
|
|
|
* in this position and unchanged.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
2000-08-25 07:32:24 +00:00
|
|
|
* derived from this software without specific prior written permission.
|
2000-08-22 02:24:02 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/lock.h>
|
2000-08-22 02:24:02 +00:00
|
|
|
#include <sys/mman.h>
|
2000-09-07 06:12:41 +00:00
|
|
|
#include <sys/mount.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/proc.h>
|
2000-08-22 02:24:02 +00:00
|
|
|
#include <sys/sysproto.h>
|
2000-11-10 23:04:31 +00:00
|
|
|
#include <sys/unistd.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/user.h>
|
2000-08-22 02:24:02 +00:00
|
|
|
|
2000-09-07 06:12:41 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
#include <vm/vm_map.h>
|
2000-08-22 02:24:02 +00:00
|
|
|
|
2000-09-07 06:12:41 +00:00
|
|
|
#include <alpha/linux/linux.h>
|
2000-12-03 01:30:31 +00:00
|
|
|
#include <alpha/linux/linux_proto.h>
|
2000-08-22 02:24:02 +00:00
|
|
|
#include <compat/linux/linux_signal.h>
|
|
|
|
#include <compat/linux/linux_util.h>
|
|
|
|
|
|
|
|
struct linux_select_argv {
|
|
|
|
int nfds;
|
|
|
|
fd_set *readfds;
|
|
|
|
fd_set *writefds;
|
|
|
|
fd_set *exceptfds;
|
|
|
|
struct timeval *timeout;
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_execve(struct thread *td, struct linux_execve_args *args)
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
|
|
|
struct execve_args bsd;
|
|
|
|
caddr_t sg;
|
|
|
|
|
|
|
|
sg = stackgap_init();
|
2001-09-20 04:55:06 +00:00
|
|
|
CHECKALTEXIST(td, &sg, args->path);
|
2000-08-22 02:24:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(execve))
|
|
|
|
printf(ARGS(execve, "%s"), args->path);
|
2000-08-22 02:24:02 +00:00
|
|
|
#endif
|
|
|
|
bsd.fname = args->path;
|
|
|
|
bsd.argv = args->argp;
|
|
|
|
bsd.envv = args->envp;
|
2001-09-20 04:55:06 +00:00
|
|
|
return (execve(td, &bsd));
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|
|
|
|
|
2001-10-26 20:35:52 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2000-08-22 02:24:02 +00:00
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_fork(struct thread *td, struct linux_fork_args *args)
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(fork))
|
|
|
|
printf(ARGS(fork, ""));
|
2000-08-22 02:24:02 +00:00
|
|
|
#endif
|
2001-09-20 04:55:06 +00:00
|
|
|
if ((error = fork(td, (struct fork_args *)args)) != 0)
|
2000-08-22 02:24:02 +00:00
|
|
|
return (error);
|
|
|
|
|
2001-09-20 04:55:06 +00:00
|
|
|
if (td->td_retval[1] == 1)
|
|
|
|
td->td_retval[0] = 0;
|
2000-10-23 08:36:59 +00:00
|
|
|
|
2000-08-22 02:24:02 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-10-26 20:35:52 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2000-08-22 02:24:02 +00:00
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_vfork(struct thread *td, struct linux_vfork_args *args)
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(vfork))
|
|
|
|
printf(ARGS(vfork, ""));
|
2000-08-22 02:24:02 +00:00
|
|
|
#endif
|
2001-09-20 04:55:06 +00:00
|
|
|
if ((error = vfork(td, (struct vfork_args *)args)) != 0)
|
2000-08-22 02:24:02 +00:00
|
|
|
return (error);
|
|
|
|
/* Are we the child? */
|
2001-09-20 04:55:06 +00:00
|
|
|
if (td->td_retval[1] == 1)
|
|
|
|
td->td_retval[0] = 0;
|
2000-08-22 02:24:02 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-10-23 08:36:59 +00:00
|
|
|
#define CLONE_VM 0x100
|
|
|
|
#define CLONE_FS 0x200
|
|
|
|
#define CLONE_FILES 0x400
|
|
|
|
#define CLONE_SIGHAND 0x800
|
|
|
|
#define CLONE_PID 0x1000
|
2000-08-22 02:24:02 +00:00
|
|
|
|
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_clone(struct thread *td, struct linux_clone_args *args)
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
2001-03-06 02:59:46 +00:00
|
|
|
int error, ff = RFPROC | RFSTOPPED;
|
2000-11-10 23:04:31 +00:00
|
|
|
struct proc *p2;
|
2002-02-08 08:56:01 +00:00
|
|
|
struct thread *td2;
|
2000-11-10 23:04:31 +00:00
|
|
|
int exit_signal;
|
|
|
|
vm_offset_t start;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(clone)) {
|
|
|
|
printf(ARGS(clone, "flags %x, stack %x"),
|
|
|
|
(unsigned int)args->flags, (unsigned int)args->stack);
|
|
|
|
if (args->flags & CLONE_PID)
|
|
|
|
printf(LMSG("CLONE_PID not yet supported"));
|
|
|
|
}
|
2000-11-10 23:04:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!args->stack)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
exit_signal = args->flags & 0x000000ff;
|
|
|
|
if (exit_signal >= LINUX_NSIG)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* if (exit_signal <= LINUX_SIGTBLSZ)
|
|
|
|
exit_signal = linux_to_bsd_signal[_SIG_IDX(exit_signal)];
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (args->flags & CLONE_VM)
|
|
|
|
ff |= RFMEM;
|
|
|
|
if (args->flags & CLONE_SIGHAND)
|
|
|
|
ff |= RFSIGSHARE;
|
|
|
|
if (!(args->flags & CLONE_FILES))
|
|
|
|
ff |= RFFDG;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
start = 0;
|
|
|
|
|
2001-09-20 04:55:06 +00:00
|
|
|
if ((error = fork1(td, ff, &p2)) != 0)
|
2000-11-10 23:04:31 +00:00
|
|
|
return (error);
|
|
|
|
|
2001-03-11 23:41:55 +00:00
|
|
|
PROC_LOCK(p2);
|
2000-11-10 23:04:31 +00:00
|
|
|
p2->p_sigparent = exit_signal;
|
2001-03-11 23:41:55 +00:00
|
|
|
PROC_UNLOCK(p2);
|
2002-02-08 08:56:01 +00:00
|
|
|
td2 = FIRST_THREAD_IN_PROC(p2);
|
|
|
|
td2->td_pcb->pcb_hw.apcb_usp = (unsigned long)args->stack;
|
2000-11-10 23:04:31 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(clone))
|
|
|
|
printf(LMSG("clone: successful rfork to %ld, stack %p sig = %d"),
|
|
|
|
(long)p2->p_pid, args->stack, exit_signal);
|
2000-11-10 23:04:31 +00:00
|
|
|
#endif
|
|
|
|
|
2001-03-06 02:59:46 +00:00
|
|
|
/*
|
|
|
|
* Make this runnable after we are finished with it.
|
|
|
|
*/
|
|
|
|
mtx_lock_spin(&sched_lock);
|
2002-02-07 20:58:47 +00:00
|
|
|
setrunqueue(FIRST_THREAD_IN_PROC(p2));
|
2001-03-06 02:59:46 +00:00
|
|
|
mtx_unlock_spin(&sched_lock);
|
|
|
|
|
2001-09-20 04:55:06 +00:00
|
|
|
td->td_retval[0] = p2->p_pid;
|
|
|
|
td->td_retval[1] = 0;
|
2000-11-10 23:04:31 +00:00
|
|
|
return (0);
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 06:12:41 +00:00
|
|
|
#define STACK_SIZE (2 * 1024 * 1024)
|
|
|
|
#define GUARD_SIZE (4 * PAGE_SIZE)
|
2000-08-22 02:24:02 +00:00
|
|
|
|
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_mmap(struct thread *td, struct linux_mmap_args *linux_args)
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
|
|
|
struct mmap_args /* {
|
|
|
|
caddr_t addr;
|
|
|
|
size_t len;
|
|
|
|
int prot;
|
|
|
|
int flags;
|
|
|
|
int fd;
|
|
|
|
long pad;
|
|
|
|
off_t pos;
|
|
|
|
} */ bsd_args;
|
|
|
|
int error;
|
2000-10-23 08:36:59 +00:00
|
|
|
|
2000-08-22 02:24:02 +00:00
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(mmap))
|
|
|
|
printf(ARGS(mmap, "%p, 0x%lx, 0x%x, 0x%x, 0x%x, 0x%lx"),
|
|
|
|
(void *)linux_args->addr, linux_args->len,
|
|
|
|
linux_args->prot, linux_args->flags, linux_args->fd,
|
|
|
|
linux_args->pos);
|
2000-08-22 02:24:02 +00:00
|
|
|
#endif
|
2000-09-07 06:12:41 +00:00
|
|
|
bsd_args.prot = linux_args->prot | PROT_READ; /* always required */
|
|
|
|
|
2000-08-22 02:24:02 +00:00
|
|
|
bsd_args.flags = 0;
|
2000-09-07 06:12:41 +00:00
|
|
|
if (linux_args->flags & LINUX_MAP_SHARED)
|
2000-08-22 02:24:02 +00:00
|
|
|
bsd_args.flags |= MAP_SHARED;
|
2000-09-07 06:12:41 +00:00
|
|
|
if (linux_args->flags & LINUX_MAP_PRIVATE)
|
2000-08-22 02:24:02 +00:00
|
|
|
bsd_args.flags |= MAP_PRIVATE;
|
2000-09-07 06:12:41 +00:00
|
|
|
if (linux_args->flags & LINUX_MAP_FIXED){
|
2000-08-22 02:24:02 +00:00
|
|
|
bsd_args.flags |= MAP_FIXED;
|
2000-09-07 06:12:41 +00:00
|
|
|
bsd_args.pos = trunc_page(linux_args->pos);
|
|
|
|
} else {
|
|
|
|
bsd_args.pos = linux_args->pos;
|
|
|
|
}
|
|
|
|
if (linux_args->flags & LINUX_MAP_ANON)
|
2000-08-22 02:24:02 +00:00
|
|
|
bsd_args.flags |= MAP_ANON;
|
2000-09-07 06:12:41 +00:00
|
|
|
if (linux_args->flags & LINUX_MAP_GROWSDOWN) {
|
2000-08-22 02:24:02 +00:00
|
|
|
bsd_args.flags |= MAP_STACK;
|
|
|
|
|
|
|
|
/* The linux MAP_GROWSDOWN option does not limit auto
|
|
|
|
* growth of the region. Linux mmap with this option
|
|
|
|
* takes as addr the inital BOS, and as len, the initial
|
|
|
|
* region size. It can then grow down from addr without
|
|
|
|
* limit. However, linux threads has an implicit internal
|
|
|
|
* limit to stack size of STACK_SIZE. Its just not
|
|
|
|
* enforced explicitly in linux. But, here we impose
|
|
|
|
* a limit of (STACK_SIZE - GUARD_SIZE) on the stack
|
|
|
|
* region, since we can do this with our mmap.
|
|
|
|
*
|
|
|
|
* Our mmap with MAP_STACK takes addr as the maximum
|
|
|
|
* downsize limit on BOS, and as len the max size of
|
|
|
|
* the region. It them maps the top SGROWSIZ bytes,
|
|
|
|
* and autgrows the region down, up to the limit
|
|
|
|
* in addr.
|
|
|
|
*
|
|
|
|
* If we don't use the MAP_STACK option, the effect
|
|
|
|
* of this code is to allocate a stack region of a
|
|
|
|
* fixed size of (STACK_SIZE - GUARD_SIZE).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This gives us TOS */
|
2001-09-08 19:07:04 +00:00
|
|
|
bsd_args.addr = (caddr_t)(linux_args->addr + linux_args->len);
|
2000-08-22 02:24:02 +00:00
|
|
|
|
|
|
|
/* This gives us our maximum stack size */
|
2000-09-07 06:12:41 +00:00
|
|
|
if (linux_args->len > STACK_SIZE - GUARD_SIZE)
|
|
|
|
bsd_args.len = linux_args->len;
|
2000-08-22 02:24:02 +00:00
|
|
|
else
|
|
|
|
bsd_args.len = STACK_SIZE - GUARD_SIZE;
|
|
|
|
|
|
|
|
/* This gives us a new BOS. If we're using VM_STACK, then
|
|
|
|
* mmap will just map the top SGROWSIZ bytes, and let
|
|
|
|
* the stack grow down to the limit at BOS. If we're
|
|
|
|
* not using VM_STACK we map the full stack, since we
|
|
|
|
* don't have a way to autogrow it.
|
|
|
|
*/
|
|
|
|
bsd_args.addr -= bsd_args.len;
|
2000-09-07 06:12:41 +00:00
|
|
|
bsd_args.addr = (caddr_t)round_page(bsd_args.addr); /* XXXX */
|
2000-08-22 02:24:02 +00:00
|
|
|
} else {
|
2001-09-08 19:07:04 +00:00
|
|
|
bsd_args.addr = (caddr_t)linux_args->addr;
|
2000-09-07 06:12:41 +00:00
|
|
|
bsd_args.len = linux_args->len;
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 06:12:41 +00:00
|
|
|
bsd_args.fd = linux_args->fd;
|
|
|
|
if(linux_args->fd == 0)
|
2000-08-22 02:24:02 +00:00
|
|
|
bsd_args.fd = -1;
|
|
|
|
|
2000-09-07 06:12:41 +00:00
|
|
|
bsd_args.pad = 0;
|
2000-08-22 02:24:02 +00:00
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(mmap))
|
|
|
|
printf(ARGS(mmap, "%p, 0x%lx, 0x%x, 0x%x, 0x%x, 0x%lx)",
|
|
|
|
(void *)bsd_args.addr,
|
|
|
|
bsd_args.len,
|
|
|
|
bsd_args.prot,
|
|
|
|
bsd_args.flags,
|
|
|
|
bsd_args.fd,
|
|
|
|
bsd_args.pos);
|
2000-08-22 02:24:02 +00:00
|
|
|
#endif
|
2000-09-07 06:12:41 +00:00
|
|
|
if (bsd_args.addr == 0)
|
|
|
|
bsd_args.addr = (caddr_t)0x40000000UL;
|
2001-09-20 04:55:06 +00:00
|
|
|
error = mmap(td, &bsd_args);
|
2000-09-07 06:12:41 +00:00
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(mmap))
|
2001-09-20 04:55:06 +00:00
|
|
|
printf(LMSG("mmap returns %d, 0x%lx", error, td->td_retval[0]);
|
2000-09-07 06:12:41 +00:00
|
|
|
#endif
|
|
|
|
return (error);
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_rt_sigsuspend(td, uap)
|
|
|
|
struct thread *td;
|
2000-09-07 06:12:41 +00:00
|
|
|
struct linux_rt_sigsuspend_args *uap;
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
2000-10-23 08:36:59 +00:00
|
|
|
int error;
|
2001-09-08 19:07:04 +00:00
|
|
|
l_sigset_t lmask;
|
2000-09-07 06:12:41 +00:00
|
|
|
sigset_t *bmask;
|
|
|
|
struct sigsuspend_args bsd;
|
2000-10-23 08:36:59 +00:00
|
|
|
caddr_t sg;
|
|
|
|
|
|
|
|
sg = stackgap_init();
|
2000-08-22 02:24:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(rt_sigsuspend))
|
|
|
|
printf(ARGS(rt_sigsuspend, "%p, %d"),
|
|
|
|
(void *)uap->newset, uap->sigsetsize);
|
2000-08-22 02:24:02 +00:00
|
|
|
#endif
|
2001-09-08 19:07:04 +00:00
|
|
|
if (uap->sigsetsize != sizeof(l_sigset_t))
|
2000-09-07 06:12:41 +00:00
|
|
|
return (EINVAL);
|
2000-08-22 02:24:02 +00:00
|
|
|
|
2001-09-08 19:07:04 +00:00
|
|
|
error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
|
2000-09-07 06:12:41 +00:00
|
|
|
if (error)
|
2000-08-22 02:24:02 +00:00
|
|
|
return (error);
|
|
|
|
|
2000-09-07 06:12:41 +00:00
|
|
|
bmask = stackgap_alloc(&sg, sizeof(sigset_t));
|
|
|
|
linux_to_bsd_sigset(&lmask, bmask);
|
|
|
|
bsd.sigmask = bmask;
|
2001-09-20 04:55:06 +00:00
|
|
|
return (sigsuspend(td, &bsd));
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_mprotect(td, uap)
|
|
|
|
struct thread *td;
|
2000-09-07 06:12:41 +00:00
|
|
|
struct linux_mprotect_args *uap;
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
2000-10-23 08:36:59 +00:00
|
|
|
|
2000-09-07 06:12:41 +00:00
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(mprotect))
|
|
|
|
printf(ARGS(mprotect, "%p, 0x%lx, 0x%x)",
|
|
|
|
(void *)uap->addr, uap->len, uap->prot);
|
2000-09-07 06:12:41 +00:00
|
|
|
#endif
|
2001-09-20 04:55:06 +00:00
|
|
|
return (mprotect(td, (void *)uap));
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_munmap(td, uap)
|
|
|
|
struct thread *td;
|
2000-09-07 06:12:41 +00:00
|
|
|
struct linux_munmap_args *uap;
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
2000-10-23 08:36:59 +00:00
|
|
|
|
2000-08-22 02:24:02 +00:00
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(munmap))
|
|
|
|
printf(ARGS(munmap, "%p, 0x%lx",
|
|
|
|
(void *)uap->addr, uap->len);
|
2000-08-22 02:24:02 +00:00
|
|
|
#endif
|
2001-09-20 04:55:06 +00:00
|
|
|
return (munmap(td, (void *)uap));
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|
|
|
|
|
2000-10-23 08:36:59 +00:00
|
|
|
static unsigned int linux_to_bsd_resource[LINUX_RLIM_NLIMITS] = {
|
|
|
|
RLIMIT_CPU, RLIMIT_FSIZE, RLIMIT_DATA, RLIMIT_STACK,
|
|
|
|
RLIMIT_CORE, RLIMIT_RSS, RLIMIT_NOFILE, -1,
|
|
|
|
RLIMIT_NPROC, RLIMIT_MEMLOCK
|
2000-09-07 06:12:41 +00:00
|
|
|
};
|
|
|
|
|
2000-08-22 02:24:02 +00:00
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_setrlimit(td, uap)
|
|
|
|
struct thread *td;
|
2000-10-23 08:36:59 +00:00
|
|
|
struct linux_setrlimit_args *uap;
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
2000-10-23 08:36:59 +00:00
|
|
|
struct rlimit rlim;
|
|
|
|
u_int which;
|
|
|
|
int error;
|
2000-08-22 02:24:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(setrlimit))
|
|
|
|
printf(ARGS(setrlimit, "%d, %p"),
|
|
|
|
uap->resource, (void *)uap->rlim);
|
2000-08-22 02:24:02 +00:00
|
|
|
#endif
|
2000-10-23 08:36:59 +00:00
|
|
|
if (uap->resource >= LINUX_RLIM_NLIMITS)
|
|
|
|
return EINVAL;
|
2000-08-22 02:24:02 +00:00
|
|
|
|
2000-10-23 08:36:59 +00:00
|
|
|
which = linux_to_bsd_resource[uap->resource];
|
2000-08-22 02:24:02 +00:00
|
|
|
|
2000-10-23 08:36:59 +00:00
|
|
|
if (which == -1)
|
|
|
|
return EINVAL;
|
2000-08-22 02:24:02 +00:00
|
|
|
|
2000-10-23 08:36:59 +00:00
|
|
|
if ((error =
|
|
|
|
copyin((caddr_t)uap->rlim, (caddr_t)&rlim, sizeof (struct rlimit))))
|
|
|
|
return (error);
|
2001-09-20 04:55:06 +00:00
|
|
|
return dosetrlimit(td, which, &rlim);
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-20 04:55:06 +00:00
|
|
|
linux_getrlimit(td, uap)
|
|
|
|
struct thread *td;
|
2000-10-23 08:36:59 +00:00
|
|
|
struct linux_getrlimit_args *uap;
|
2000-08-22 02:24:02 +00:00
|
|
|
{
|
2000-10-23 08:36:59 +00:00
|
|
|
u_int which;
|
2000-08-22 02:24:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(getrlimit))
|
|
|
|
printf(ARGS(getrlimit, "%d, %p"),
|
|
|
|
uap->resource, (void *)uap->rlim);
|
2000-08-22 02:24:02 +00:00
|
|
|
#endif
|
2000-10-23 08:36:59 +00:00
|
|
|
if (uap->resource >= LINUX_RLIM_NLIMITS)
|
|
|
|
return EINVAL;
|
2000-08-22 02:24:02 +00:00
|
|
|
|
2000-10-23 08:36:59 +00:00
|
|
|
which = linux_to_bsd_resource[uap->resource];
|
2000-08-22 02:24:02 +00:00
|
|
|
|
2000-10-23 08:36:59 +00:00
|
|
|
if (which == -1)
|
|
|
|
return EINVAL;
|
2000-08-22 02:24:02 +00:00
|
|
|
|
2001-09-20 04:55:06 +00:00
|
|
|
return (copyout((caddr_t)&td->td_proc->p_rlimit[which],
|
|
|
|
(caddr_t)uap->rlim, sizeof (struct rlimit)));
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|