#if defined(_KERNEL)
-struct lwbuf *lwbuf_alloc(vm_page_t);
+struct lwbuf *lwbuf_alloc(vm_page_t, struct lwbuf *);
void lwbuf_free(struct lwbuf *);
vm_offset_t lwbuf_kva(struct lwbuf *lwb);
void lwbuf_set_global(struct lwbuf *);
}
struct lwbuf *
-lwbuf_alloc(vm_page_t m)
+lwbuf_alloc(vm_page_t m, struct lwbuf *lwb_dummy __unused)
{
struct mdglobaldata *gd = mdcpu;
struct lwbuf *lwb;
#ifndef _MACHINE_ATOMIC_H_
#include <machine/atomic.h>
#endif
+#ifndef _MACHINE_VMPARAM_H_
+#include <machine/vmparam.h>
+#endif
#if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
#error "This file should not be included by userland programs."
#endif
struct lwbuf {
- vm_page_t m; /* currently mapped page */
- vm_offset_t kva; /* va of mapping */
+ vm_page_t m; /* currently mapped page */
+ vm_offset_t kva; /* va of mapping */
};
static __inline vm_page_t
-lwbuf_page(struct lwbuf *lwb) {
- return (lwb->m);
+lwbuf_page(struct lwbuf *lwb)
+{
+ return (lwb->m);
}
static __inline vm_offset_t
-lwbuf_kva(struct lwbuf *lwb) {
- return (lwb->kva);
+lwbuf_kva(struct lwbuf *lwb)
+{
+ return (lwb->kva);
+}
+
+static __inline struct lwbuf *
+lwbuf_alloc(vm_page_t m, struct lwbuf *lwb_cache)
+{
+ struct lwbuf *lwb = lwb_cache;
+
+ lwb->m = m;
+ lwb->kva = PHYS_TO_DMAP(VM_PAGE_TO_PHYS(lwb->m));
+
+ return (lwb);
+}
+
+static __inline void
+lwbuf_free(struct lwbuf *lwb)
+{
+ lwb->m = NULL; /* safety */
}
#define lwbuf_set_global(lwb)
#if defined(_KERNEL)
-struct lwbuf *lwbuf_alloc(vm_page_t);
-void lwbuf_free(struct lwbuf *);
-
#endif
#endif /* !_CPU_LWBUF_H_ */
#include <cpu/lwbuf.h>
#include <machine/param.h>
+#if 0
+/*
+ * NO LONGER USED - See inlines
+ */
+
static void lwbuf_init(void *);
SYSINIT(sock_lwb, SI_BOOT2_MACHDEP, SI_ORDER_ANY, lwbuf_init, NULL);
&lwbuf_malloc_args);
}
+#endif
+
+#if 0
+/*
+ * NO LONGER USED - See inlines
+ */
+
struct lwbuf *
-lwbuf_alloc(vm_page_t m)
+lwbuf_alloc(vm_page_t m, struct lwbuf *lwb_cache)
{
- struct lwbuf *lwb;
-
- if ((lwb = objcache_get(lwbuf_cache, M_WAITOK)) == NULL)
- return (NULL);
+ struct lwbuf *lwb = lwb_cache;
lwb->m = m;
lwb->kva = PHYS_TO_DMAP(VM_PAGE_TO_PHYS(lwb->m));
void
lwbuf_free(struct lwbuf *lwb)
{
- lwb->m = NULL;
-
- objcache_put(lwbuf_cache, lwb);
+ lwb->m = NULL; /* safety */
}
+
+#endif
Elf_Brandinfo *match = NULL;
const Elf_Note *tmp_note;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
const char *page;
char *data = NULL;
Elf_Off off;
if (len < sizeof(Elf_Note) || len > PAGE_SIZE)
return NULL; /* ENOEXEC? */
+ lwb = &lwb_cache;
if (exec_map_page(imgp, off >> PAGE_SHIFT, &lwb, &page))
return NULL;
bcopy(page + firstoff, data, firstlen);
exec_unmap_page(lwb);
+ lwb = &lwb_cache;
if (exec_map_page(imgp, (off >> PAGE_SHIFT) + 1, &lwb, &page)) {
kfree(data, M_TEMP);
return NULL;
if (copy_len != 0) {
vm_page_t m;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
m = vm_fault_object_page(object, trunc_page(offset + filsz),
VM_PROT_READ, 0, &error);
if (m) {
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
error = copyout((caddr_t)lwbuf_kva(lwb),
(caddr_t)map_addr, copy_len);
lwbuf_free(lwb);
vm_page_wakeup(m); /* unbusy the page */
lwkt_reltoken(&vm_token);
- *plwb = lwbuf_alloc(m);
+ *plwb = lwbuf_alloc(m, *plwb);
*pdata = (void *)lwbuf_kva(*plwb);
return (0);
if (imgp->firstpage)
exec_unmap_first_page(imgp);
+ imgp->firstpage = &imgp->firstpage_cache;
err = exec_map_page(imgp, 0, &imgp->firstpage, &imgp->image_header);
if (err)
if ((sf = objcache_get(sf_buf_cache, M_WAITOK)) == NULL)
goto done;
- if ((sf->lwbuf = lwbuf_alloc(m)) == NULL) {
+ if ((sf->lwbuf = lwbuf_alloc(m, &sf->lwbuf_cache)) == NULL) {
objcache_put(sf_buf_cache, sf);
sf = NULL;
goto done;
int
uiomove_fromphys(vm_page_t *ma, vm_offset_t offset, size_t n, struct uio *uio)
{
+ struct lwbuf lwb_cache;
struct lwbuf *lwb;
struct thread *td = curthread;
struct iovec *iov;
page_offset = offset & PAGE_MASK;
cnt = min(cnt, PAGE_SIZE - page_offset);
m = ma[offset >> PAGE_SHIFT];
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
cp = (char *)lwbuf_kva(lwb) + page_offset;
switch (uio->uio_segflg) {
case UIO_USERSPACE:
int
sys_umtx_sleep(struct umtx_sleep_args *uap)
{
- int error = EBUSY;
+ struct lwbuf lwb_cache;
struct lwbuf *lwb;
struct vm_page_action action;
vm_page_t m;
void *waddr;
int offset;
int timeout;
+ int error = EBUSY;
if (uap->timeout < 0)
return (EINVAL);
error = EFAULT;
goto done;
}
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
offset = (vm_offset_t)uap->ptr & PAGE_MASK;
/*
int offset;
vm_page_t m;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
if (uoffset + bytes > xio->xio_bytes)
return(EFAULT);
++i
) {
m = xio->xio_pages[i];
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
error = copyout((char *)lwbuf_kva(lwb) + offset, uptr, n);
lwbuf_free(lwb);
if (error)
int offset;
vm_page_t m;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
if (bytes + uoffset > xio->xio_bytes)
return(EFAULT);
++i
) {
m = xio->xio_pages[i];
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
bcopy((char *)lwbuf_kva(lwb) + offset, kptr, n);
lwbuf_free(lwb);
bytes -= n;
int offset;
vm_page_t m;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
if (uoffset + bytes > xio->xio_bytes)
return(EFAULT);
++i
) {
m = xio->xio_pages[i];
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
error = copyin(uptr, (char *)lwbuf_kva(lwb) + offset, n);
lwbuf_free(lwb);
if (error)
int offset;
vm_page_t m;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
if (uoffset + bytes > xio->xio_bytes)
return(EFAULT);
++i
) {
m = xio->xio_pages[i];
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
bcopy(kptr, (char *)lwbuf_kva(lwb) + offset, n);
lwbuf_free(lwb);
bytes -= n;
{
struct vmspace *vm = curproc->p_vmspace;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
vm_page_t m;
int error;
size_t n;
n = PAGE_SIZE - ((vm_offset_t)udaddr & PAGE_MASK);
if (n > len)
n = len;
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
bcopy((char *)lwbuf_kva(lwb)+((vm_offset_t)udaddr & PAGE_MASK),
kaddr, n);
len -= n;
{
struct vmspace *vm = curproc->p_vmspace;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
vm_page_t m;
int error;
size_t n;
n = PAGE_SIZE - ((vm_offset_t)udaddr & PAGE_MASK);
if (n > len)
n = len;
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
bcopy(kaddr, (char *)lwbuf_kva(lwb) +
((vm_offset_t)udaddr & PAGE_MASK), n);
len -= n;
{
struct vmspace *vm = curproc->p_vmspace;
struct lwbuf *lwb;
+ struct lwbuf_cache lwb_cache;
vm_page_t m;
int error;
size_t n;
n = PAGE_SIZE - ((vm_offset_t)udaddr & PAGE_MASK);
if (n > len)
n = len;
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
bcopy((char *)lwbuf_kva(lwb)+((vm_offset_t)udaddr & PAGE_MASK),
kaddr, n);
len -= n;
{
struct vmspace *vm = curproc->p_vmspace;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
vm_page_t m;
int error;
size_t n;
n = PAGE_SIZE - ((vm_offset_t)udaddr & PAGE_MASK);
if (n > len)
n = len;
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
bcopy(kaddr, (char *)lwbuf_kva(lwb) +
((vm_offset_t)udaddr & PAGE_MASK), n);
len -= n;
#define _SYS_IMGACT_H_
#include <sys/mount.h>
+#include <cpu/lwbuf.h>
#define MAXSHELLCMDLEN 128
char interpreter_name[MAXSHELLCMDLEN]; /* name of the interpreter */
void *auxargs; /* ELF Auxinfo structure pointer */
struct lwbuf *firstpage; /* first page that we mapped */
+ struct lwbuf firstpage_cache;
unsigned long ps_strings; /* PS_STRINGS for BSD/OS binaries */
};
#endif
struct sf_buf {
- struct lwbuf *lwbuf; /* lightweight buffer */
- struct kref ref;
+ struct lwbuf *lwbuf; /* lightweight buffer */
+ struct kref ref;
+ struct lwbuf lwbuf_cache;
};
#define sf_buf_kva(sf) (lwbuf_kva((sf)->lwbuf))
vpte_t vpte, int fault_type)
{
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
int vshift = VPTE_FRAME_END - PAGE_SHIFT; /* index bits remaining */
int result = KERN_SUCCESS;
vpte_t *ptep;
* entry in the page table page.
*/
vshift -= VPTE_PAGE_BITS;
- lwb = lwbuf_alloc(fs->m);
+ lwb = lwbuf_alloc(fs->m, &lwb_cache);
ptep = ((vpte_t *)lwbuf_kva(lwb) +
((*pindex >> vshift) & VPTE_PAGE_MASK));
vpte = *ptep;
vm_pagezero(void __unused *arg)
{
vm_page_t m = NULL;
- struct lwbuf *buf = NULL;
+ struct lwbuf *lwb = NULL;
+ struct lwbuf lwb_cache;
enum zeroidle_state state = STATE_IDLE;
char *pg = NULL;
int npages = 0;
state = STATE_IDLE;
} else {
state = STATE_ZERO_PAGE;
- buf = lwbuf_alloc(m);
- pg = (char *)lwbuf_kva(buf);
+ lwb = lwbuf_alloc(m, &lwb_cache);
+ pg = (char *)lwbuf_kva(lwb);
i = 0;
}
}
state = STATE_RELEASE_PAGE;
break;
case STATE_RELEASE_PAGE:
- lwbuf_free(buf);
+ lwbuf_free(lwb);
vm_page_flag_set(m, PG_ZERO);
vm_page_free_toq(m);
state = STATE_GET_PAGE;
int base = (int)nsize & PAGE_MASK;
int size = PAGE_SIZE - base;
struct lwbuf *lwb;
+ struct lwbuf lwb_cache;
/*
* Clear out partial-page garbage in case
* This is byte aligned.
*/
vm_page_busy(m);
- lwb = lwbuf_alloc(m);
+ lwb = lwbuf_alloc(m, &lwb_cache);
kva = lwbuf_kva(lwb);
bzero((caddr_t)kva + base, size);
lwbuf_free(lwb);