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.
|
|
|
|
*/
|
|
|
|
|
2003-06-10 17:02:51 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-08-22 02:24:02 +00:00
|
|
|
#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>
|
2003-04-22 18:23:49 +00:00
|
|
|
#include <sys/syscallsubr.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;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(clone)) {
|
2003-04-16 20:05:42 +00:00
|
|
|
printf(ARGS(clone, "flags %x, stack %p"),
|
|
|
|
(unsigned int)args->flags, args->stack);
|
2001-02-16 16:40:43 +00:00
|
|
|
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;
|
|
|
|
|
2003-04-18 20:54:41 +00:00
|
|
|
error = fork1(td, ff, 0, &p2);
|
|
|
|
if (error)
|
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-09-11 08:13:56 +00:00
|
|
|
TD_SET_CAN_RUN(td2);
|
2004-09-01 02:11:28 +00:00
|
|
|
setrunqueue(td2, SRQ_BORING);
|
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))
|
2003-04-16 20:05:42 +00:00
|
|
|
printf(ARGS(mmap, "%p, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx"),
|
2001-02-16 16:40:43 +00:00
|
|
|
(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))
|
2003-04-16 19:28:13 +00:00
|
|
|
printf(ARGS(mmap, "%p, 0x%lx, 0x%x, 0x%x, 0x%x, 0x%lx"),
|
2001-02-16 16:40:43 +00:00
|
|
|
(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))
|
2003-04-16 19:28:13 +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;
|
2003-04-22 18:23:49 +00:00
|
|
|
sigset_t bmask;
|
2000-08-22 02:24:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-02-16 16:40:43 +00:00
|
|
|
if (ldebug(rt_sigsuspend))
|
2003-04-16 20:05:42 +00:00
|
|
|
printf(ARGS(rt_sigsuspend, "%p, %zd"),
|
2001-02-16 16:40:43 +00:00
|
|
|
(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);
|
|
|
|
|
2003-04-22 18:23:49 +00:00
|
|
|
linux_to_bsd_sigset(&lmask, &bmask);
|
|
|
|
return (kern_sigsuspend(td, bmask));
|
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))
|
2003-04-16 20:05:42 +00:00
|
|
|
printf(ARGS(mprotect, "%p, 0x%zx, 0x%lx"),
|
2001-02-16 16:40:43 +00:00
|
|
|
(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))
|
2003-04-16 19:28:13 +00:00
|
|
|
printf(ARGS(munmap, "%p, 0x%lx"),
|
2001-02-16 16:40:43 +00:00
|
|
|
(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 =
|
2003-03-03 09:14:26 +00:00
|
|
|
copyin(uap->rlim, &rlim, sizeof (struct rlimit))))
|
2000-10-23 08:36:59 +00:00
|
|
|
return (error);
|
2004-02-04 21:52:57 +00:00
|
|
|
return (kern_setrlimit(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
|
|
|
{
|
2004-02-04 21:52:57 +00:00
|
|
|
struct rlimit rlim;
|
2000-10-23 08:36:59 +00:00
|
|
|
u_int which;
|
2004-02-04 21:52:57 +00:00
|
|
|
int error;
|
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
|
|
|
|
2004-02-04 21:52:57 +00:00
|
|
|
PROC_LOCK(td->td_proc);
|
|
|
|
lim_rlimit(td->td_proc, which, &rlim);
|
|
|
|
PROC_UNLOCK(td->td_proc);
|
|
|
|
error = copyout(&rlim, uap->rlim, sizeof (struct rlimit));
|
|
|
|
return (error);
|
2000-08-22 02:24:02 +00:00
|
|
|
}
|