Theoretically this is supposed to be interchangeable with real
kernel code. Use kmem_alloc/free instead of some wily homerolled rump interfaces for memory allocation.
This commit is contained in:
parent
2c7914f588
commit
deeebf9713
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: auth.c,v 1.4 2008/01/02 18:15:14 pooka Exp $ */
|
/* $NetBSD: auth.c,v 1.5 2008/01/03 02:48:02 pooka Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||||
@ -31,6 +31,7 @@
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
#include <sys/kauth.h>
|
#include <sys/kauth.h>
|
||||||
|
#include <sys/kmem.h>
|
||||||
|
|
||||||
#include "rump.h"
|
#include "rump.h"
|
||||||
#include "rumpuser.h"
|
#include "rumpuser.h"
|
||||||
@ -40,19 +41,16 @@ struct kauth_cred {
|
|||||||
gid_t cr_gid;
|
gid_t cr_gid;
|
||||||
|
|
||||||
size_t cr_ngroups;
|
size_t cr_ngroups;
|
||||||
gid_t cr_groups[0];
|
gid_t cr_groups[NGROUPS];
|
||||||
};
|
};
|
||||||
|
|
||||||
kauth_cred_t
|
kauth_cred_t
|
||||||
rump_cred_create(uid_t uid, gid_t gid, size_t ngroups, gid_t *groups)
|
rump_cred_create(uid_t uid, gid_t gid, size_t ngroups, gid_t *groups)
|
||||||
{
|
{
|
||||||
kauth_cred_t cred;
|
kauth_cred_t cred;
|
||||||
size_t credsize;
|
|
||||||
|
|
||||||
KASSERT(ngroups <= NGROUPS);
|
KASSERT(ngroups <= NGROUPS);
|
||||||
|
cred = kmem_alloc(sizeof(struct kauth_cred), KM_SLEEP);
|
||||||
credsize = sizeof(struct kauth_cred) + ngroups * sizeof(gid_t);
|
|
||||||
cred = rumpuser_malloc(credsize, 0);
|
|
||||||
|
|
||||||
cred->cr_uid = uid;
|
cred->cr_uid = uid;
|
||||||
cred->cr_gid = gid;
|
cred->cr_gid = gid;
|
||||||
@ -66,7 +64,7 @@ void
|
|||||||
rump_cred_destroy(kauth_cred_t cred)
|
rump_cred_destroy(kauth_cred_t cred)
|
||||||
{
|
{
|
||||||
|
|
||||||
rumpuser_free(cred);
|
kmem_free(cred, sizeof(struct kauth_cred));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: pool.c,v 1.5 2008/01/02 18:15:14 pooka Exp $ */
|
/* $NetBSD: pool.c,v 1.6 2008/01/03 02:48:03 pooka Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||||
@ -113,7 +113,7 @@ pool_get(struct pool *pp, int flags)
|
|||||||
if (pp->pr_size == 0)
|
if (pp->pr_size == 0)
|
||||||
panic("%s: pool unit size 0. not initialized?", __func__);
|
panic("%s: pool unit size 0. not initialized?", __func__);
|
||||||
|
|
||||||
rv = rumpuser_malloc(pp->pr_size, 1);
|
rv = kmem_alloc(pp->pr_size, KM_NOSLEEP);
|
||||||
if (rv == NULL && (flags & PR_WAITOK && (flags & PR_LIMITFAIL) == 0))
|
if (rv == NULL && (flags & PR_WAITOK && (flags & PR_LIMITFAIL) == 0))
|
||||||
panic("%s: out of memory and PR_WAITOK", __func__);
|
panic("%s: out of memory and PR_WAITOK", __func__);
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ void
|
|||||||
pool_put(struct pool *pp, void *item)
|
pool_put(struct pool *pp, void *item)
|
||||||
{
|
{
|
||||||
|
|
||||||
rumpuser_free(item);
|
kmem_free(item, pp->pr_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: rump.c,v 1.27 2008/01/02 18:15:14 pooka Exp $ */
|
/* $NetBSD: rump.c,v 1.28 2008/01/03 02:48:03 pooka Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||||
@ -138,8 +138,7 @@ rump_mnt_init(struct vfsops *vfsops, int mntflags)
|
|||||||
{
|
{
|
||||||
struct mount *mp;
|
struct mount *mp;
|
||||||
|
|
||||||
mp = rumpuser_malloc(sizeof(struct mount), 0);
|
mp = kmem_zalloc(sizeof(struct mount), KM_SLEEP);
|
||||||
memset(mp, 0, sizeof(struct mount));
|
|
||||||
|
|
||||||
mp->mnt_op = vfsops;
|
mp->mnt_op = vfsops;
|
||||||
mp->mnt_flag = mntflags;
|
mp->mnt_flag = mntflags;
|
||||||
@ -172,7 +171,7 @@ rump_mnt_destroy(struct mount *mp)
|
|||||||
{
|
{
|
||||||
|
|
||||||
mount_finispecific(mp);
|
mount_finispecific(mp);
|
||||||
rumpuser_free(mp);
|
kmem_free(mp, sizeof(*mp));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct componentname *
|
struct componentname *
|
||||||
@ -181,8 +180,7 @@ rump_makecn(u_long nameiop, u_long flags, const char *name, size_t namelen,
|
|||||||
{
|
{
|
||||||
struct componentname *cnp;
|
struct componentname *cnp;
|
||||||
|
|
||||||
cnp = rumpuser_malloc(sizeof(struct componentname), 0);
|
cnp = kmem_zalloc(sizeof(struct componentname), KM_SLEEP);
|
||||||
memset(cnp, 0, sizeof(struct componentname));
|
|
||||||
|
|
||||||
cnp->cn_nameiop = nameiop;
|
cnp->cn_nameiop = nameiop;
|
||||||
cnp->cn_flags = flags;
|
cnp->cn_flags = flags;
|
||||||
@ -210,7 +208,7 @@ rump_freecn(struct componentname *cnp, int flags)
|
|||||||
} else {
|
} else {
|
||||||
PNBUF_PUT(cnp->cn_pnbuf);
|
PNBUF_PUT(cnp->cn_pnbuf);
|
||||||
}
|
}
|
||||||
rumpuser_free(cnp);
|
kmem_free(cnp, sizeof(*cnp));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -250,7 +248,7 @@ rump_fakeblk_register(const char *path)
|
|||||||
if (rumpuser_realpath(path, buf, &error) == NULL)
|
if (rumpuser_realpath(path, buf, &error) == NULL)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
fblk = rumpuser_malloc(sizeof(struct fakeblk), 1);
|
fblk = kmem_alloc(sizeof(struct fakeblk), KM_NOSLEEP);
|
||||||
if (fblk == NULL)
|
if (fblk == NULL)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
@ -277,7 +275,7 @@ rump_fakeblk_deregister(const char *path)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
LIST_REMOVE(fblk, entries);
|
LIST_REMOVE(fblk, entries);
|
||||||
rumpuser_free(fblk);
|
kmem_free(fblk, sizeof(*fblk));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -314,7 +312,7 @@ rump_vattr_init()
|
|||||||
{
|
{
|
||||||
struct vattr *vap;
|
struct vattr *vap;
|
||||||
|
|
||||||
vap = rumpuser_malloc(sizeof(struct vattr), 0);
|
vap = kmem_alloc(sizeof(struct vattr), KM_SLEEP);
|
||||||
vattr_null(vap);
|
vattr_null(vap);
|
||||||
|
|
||||||
return vap;
|
return vap;
|
||||||
@ -345,7 +343,7 @@ void
|
|||||||
rump_vattr_free(struct vattr *vap)
|
rump_vattr_free(struct vattr *vap)
|
||||||
{
|
{
|
||||||
|
|
||||||
rumpuser_free(vap);
|
kmem_free(vap, sizeof(*vap));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -386,8 +384,8 @@ rump_uio_setup(void *buf, size_t bufsize, off_t offset, enum rump_uiorw rw)
|
|||||||
panic("%s: invalid rw %d", __func__, rw);
|
panic("%s: invalid rw %d", __func__, rw);
|
||||||
}
|
}
|
||||||
|
|
||||||
uio = rumpuser_malloc(sizeof(struct uio), 0);
|
uio = kmem_alloc(sizeof(struct uio), KM_SLEEP);
|
||||||
uio->uio_iov = rumpuser_malloc(sizeof(struct iovec), 0);
|
uio->uio_iov = kmem_alloc(sizeof(struct iovec), KM_SLEEP);
|
||||||
|
|
||||||
uio->uio_iov->iov_base = buf;
|
uio->uio_iov->iov_base = buf;
|
||||||
uio->uio_iov->iov_len = bufsize;
|
uio->uio_iov->iov_len = bufsize;
|
||||||
@ -421,8 +419,8 @@ rump_uio_free(struct uio *uio)
|
|||||||
size_t resid;
|
size_t resid;
|
||||||
|
|
||||||
resid = uio->uio_resid;
|
resid = uio->uio_resid;
|
||||||
rumpuser_free(uio->uio_iov);
|
kmem_free(uio->uio_iov, sizeof(*uio->uio_iov));
|
||||||
rumpuser_free(uio);
|
kmem_free(uio, sizeof(*uio));
|
||||||
|
|
||||||
return resid;
|
return resid;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: specfs.c,v 1.15 2008/01/02 18:15:14 pooka Exp $ */
|
/* $NetBSD: specfs.c,v 1.16 2008/01/03 02:48:03 pooka Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||||
@ -219,7 +219,7 @@ rump_specstrategy(void *v)
|
|||||||
if (bp->b_flags & B_ASYNC) {
|
if (bp->b_flags & B_ASYNC) {
|
||||||
struct rumpuser_aio *rua;
|
struct rumpuser_aio *rua;
|
||||||
|
|
||||||
rua = rumpuser_malloc(sizeof(struct rumpuser_aio), 0);
|
rua = kmem_alloc(sizeof(struct rumpuser_aio), KM_SLEEP);
|
||||||
rua->rua_fd = sp->rsp_fd;
|
rua->rua_fd = sp->rsp_fd;
|
||||||
rua->rua_data = bp->b_data;
|
rua->rua_data = bp->b_data;
|
||||||
rua->rua_dlen = bp->b_bcount;
|
rua->rua_dlen = bp->b_bcount;
|
||||||
@ -239,7 +239,7 @@ rump_specstrategy(void *v)
|
|||||||
* so for now set N_AIOS high and FIXXXME some day.
|
* so for now set N_AIOS high and FIXXXME some day.
|
||||||
*/
|
*/
|
||||||
if ((rua_head+1) % N_AIOS == rua_tail) {
|
if ((rua_head+1) % N_AIOS == rua_tail) {
|
||||||
rumpuser_free(rua);
|
kmem_free(rua, sizeof(*rua));
|
||||||
rumpuser_mutex_exit(&rua_mtx);
|
rumpuser_mutex_exit(&rua_mtx);
|
||||||
goto syncfallback;
|
goto syncfallback;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: vfs.c,v 1.27 2008/01/03 02:44:05 pooka Exp $ */
|
/* $NetBSD: vfs.c,v 1.28 2008/01/03 02:48:03 pooka Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||||
@ -84,8 +84,7 @@ getnewvnode(enum vtagtype tag, struct mount *mp, int (**vops)(void *),
|
|||||||
{
|
{
|
||||||
struct vnode *vp;
|
struct vnode *vp;
|
||||||
|
|
||||||
vp = rumpuser_malloc(sizeof(struct vnode), 0);
|
vp = kmem_zalloc(sizeof(struct vnode), KM_SLEEP);
|
||||||
memset(vp, 0, sizeof(struct vnode));
|
|
||||||
vp->v_mount = mp;
|
vp->v_mount = mp;
|
||||||
vp->v_tag = tag;
|
vp->v_tag = tag;
|
||||||
vp->v_op = vops;
|
vp->v_op = vops;
|
||||||
@ -110,9 +109,9 @@ rump_putnode(struct vnode *vp)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (vp->v_specinfo)
|
if (vp->v_specinfo)
|
||||||
rumpuser_free(vp->v_specinfo);
|
kmem_free(vp->v_specinfo, sizeof(*vp->v_specinfo));
|
||||||
UVM_OBJ_DESTROY(&vp->v_uobj);
|
UVM_OBJ_DESTROY(&vp->v_uobj);
|
||||||
rumpuser_free(vp);
|
kmem_free(vp, sizeof(*vp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -307,7 +306,7 @@ makevnode(struct stat *sb, const char *path)
|
|||||||
struct vnode *vp;
|
struct vnode *vp;
|
||||||
struct rump_specpriv *sp;
|
struct rump_specpriv *sp;
|
||||||
|
|
||||||
vp = rumpuser_malloc(sizeof(struct vnode), 0);
|
vp = kmem_alloc(sizeof(struct vnode), KM_SLEEP);
|
||||||
vp->v_size = vp->v_writesize = sb->st_size;
|
vp->v_size = vp->v_writesize = sb->st_size;
|
||||||
vp->v_type = mode2vt(sb->st_mode);
|
vp->v_type = mode2vt(sb->st_mode);
|
||||||
if (vp->v_type != VBLK)
|
if (vp->v_type != VBLK)
|
||||||
@ -317,9 +316,9 @@ makevnode(struct stat *sb, const char *path)
|
|||||||
if (vp->v_type != VBLK)
|
if (vp->v_type != VBLK)
|
||||||
panic("namei: only VBLK results supported currently");
|
panic("namei: only VBLK results supported currently");
|
||||||
|
|
||||||
vp->v_specinfo = rumpuser_malloc(sizeof(struct specinfo), 0);
|
vp->v_specinfo = kmem_alloc(sizeof(struct specinfo), KM_SLEEP);
|
||||||
vp->v_rdev = sb->st_dev;
|
vp->v_rdev = sb->st_dev;
|
||||||
sp = rumpuser_malloc(sizeof(struct rump_specpriv), 0);
|
sp = kmem_alloc(sizeof(struct rump_specpriv), KM_SLEEP);
|
||||||
strcpy(sp->rsp_path, path);
|
strcpy(sp->rsp_path, path);
|
||||||
vp->v_data = sp;
|
vp->v_data = sp;
|
||||||
vp->v_op = spec_vnodeop_p;
|
vp->v_op = spec_vnodeop_p;
|
||||||
@ -443,7 +442,7 @@ checkalias(struct vnode *nvp, dev_t nvp_rdev, struct mount *mp)
|
|||||||
|
|
||||||
/* Can this cause any funnies? */
|
/* Can this cause any funnies? */
|
||||||
|
|
||||||
nvp->v_specinfo = rumpuser_malloc(sizeof(struct specinfo), 0);
|
nvp->v_specinfo = kmem_alloc(sizeof(struct specinfo), KM_SLEEP);
|
||||||
nvp->v_rdev = nvp_rdev;
|
nvp->v_rdev = nvp_rdev;
|
||||||
return NULLVP;
|
return NULLVP;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: vm.c,v 1.26 2008/01/02 15:44:04 pooka Exp $ */
|
/* $NetBSD: vm.c,v 1.27 2008/01/03 02:48:03 pooka Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||||
@ -97,13 +97,11 @@ rumpvm_makepage(struct uvm_object *uobj, voff_t off)
|
|||||||
{
|
{
|
||||||
struct vm_page *pg;
|
struct vm_page *pg;
|
||||||
|
|
||||||
pg = rumpuser_malloc(sizeof(struct vm_page), 0);
|
pg = kmem_zalloc(sizeof(struct vm_page), KM_SLEEP);
|
||||||
memset(pg, 0, sizeof(struct vm_page));
|
|
||||||
pg->offset = off;
|
pg->offset = off;
|
||||||
pg->uobject = uobj;
|
pg->uobject = uobj;
|
||||||
|
|
||||||
pg->uanon = (void *)rumpuser_malloc(PAGE_SIZE, 0);
|
pg->uanon = (void *)kmem_zalloc(PAGE_SIZE, KM_SLEEP);
|
||||||
memset((void *)pg->uanon, 0, PAGE_SIZE);
|
|
||||||
pg->flags = PG_CLEAN|PG_BUSY|PG_FAKE;
|
pg->flags = PG_CLEAN|PG_BUSY|PG_FAKE;
|
||||||
|
|
||||||
TAILQ_INSERT_TAIL(&uobj->memq, pg, listq);
|
TAILQ_INSERT_TAIL(&uobj->memq, pg, listq);
|
||||||
@ -125,8 +123,8 @@ uvm_pagefree(struct vm_page *pg)
|
|||||||
wakeup(pg);
|
wakeup(pg);
|
||||||
|
|
||||||
TAILQ_REMOVE(&uobj->memq, pg, listq);
|
TAILQ_REMOVE(&uobj->memq, pg, listq);
|
||||||
rumpuser_free((void *)pg->uanon);
|
kmem_free((void *)pg->uanon, PAGE_SIZE);
|
||||||
rumpuser_free(pg);
|
kmem_free(pg, sizeof(*pg));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct rumpva {
|
struct rumpva {
|
||||||
@ -143,7 +141,7 @@ rumpvm_enterva(vaddr_t addr, struct vm_page *pg)
|
|||||||
{
|
{
|
||||||
struct rumpva *rva;
|
struct rumpva *rva;
|
||||||
|
|
||||||
rva = rumpuser_malloc(sizeof(struct rumpva), 0);
|
rva = kmem_alloc(sizeof(struct rumpva), KM_SLEEP);
|
||||||
rva->addr = addr;
|
rva->addr = addr;
|
||||||
rva->pg = pg;
|
rva->pg = pg;
|
||||||
mutex_enter(&rvamtx);
|
mutex_enter(&rvamtx);
|
||||||
@ -159,7 +157,7 @@ rumpvm_flushva()
|
|||||||
mutex_enter(&rvamtx);
|
mutex_enter(&rvamtx);
|
||||||
while ((rva = LIST_FIRST(&rvahead)) != NULL) {
|
while ((rva = LIST_FIRST(&rvahead)) != NULL) {
|
||||||
LIST_REMOVE(rva, entries);
|
LIST_REMOVE(rva, entries);
|
||||||
rumpuser_free(rva);
|
kmem_free(rva, sizeof(*rva));
|
||||||
}
|
}
|
||||||
mutex_exit(&rvamtx);
|
mutex_exit(&rvamtx);
|
||||||
}
|
}
|
||||||
@ -252,8 +250,7 @@ uao_create(vsize_t size, int flags)
|
|||||||
{
|
{
|
||||||
struct uvm_object *uobj;
|
struct uvm_object *uobj;
|
||||||
|
|
||||||
uobj = rumpuser_malloc(sizeof(struct uvm_object), 0);
|
uobj = kmem_zalloc(sizeof(struct uvm_object), KM_SLEEP);
|
||||||
memset(uobj, 0, sizeof(struct uvm_object));
|
|
||||||
uobj->pgops = &aobj_pager;
|
uobj->pgops = &aobj_pager;
|
||||||
TAILQ_INIT(&uobj->memq);
|
TAILQ_INIT(&uobj->memq);
|
||||||
mutex_init(&uobj->vmobjlock, MUTEX_DEFAULT, IPL_NONE);
|
mutex_init(&uobj->vmobjlock, MUTEX_DEFAULT, IPL_NONE);
|
||||||
@ -266,7 +263,7 @@ uao_detach(struct uvm_object *uobj)
|
|||||||
{
|
{
|
||||||
|
|
||||||
ao_put(uobj, 0, 0, PGO_ALLPAGES | PGO_FREE);
|
ao_put(uobj, 0, 0, PGO_ALLPAGES | PGO_FREE);
|
||||||
rumpuser_free(uobj);
|
kmem_free(uobj, sizeof(*uobj));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user