summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-03-14 12:02:36 -0400
committerIan Moffett <ian@osmora.org>2025-03-14 12:02:36 -0400
commit509942a2f0167032e96b5130aebf95dfa1d14c4c (patch)
tree4737ad5b9e6675cd17034e3e53d76784287fd415 /sys
parent6ceef43179c70852f001f1205ff92ebba4d0d4d7 (diff)
parentf7b53e3e49c428e7cee7ebe51ebcb261c9d4f02a (diff)
Merge branch 'expt'
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/cons/cons.c53
-rw-r--r--sys/fs/devfs.c36
-rw-r--r--sys/fs/initramfs.c1
-rw-r--r--sys/include/dev/cons/cons.h3
-rw-r--r--sys/include/sys/cdefs.h1
-rw-r--r--sys/include/sys/driver.h1
-rw-r--r--sys/include/sys/fcntl.h5
-rw-r--r--sys/include/sys/filedesc.h2
-rw-r--r--sys/include/sys/mmio.h4
-rw-r--r--sys/include/sys/syscall.h1
-rw-r--r--sys/include/sys/termios.h53
-rw-r--r--sys/include/sys/vfs.h1
-rw-r--r--sys/include/sys/vnode.h2
-rw-r--r--sys/include/vm/vm_pager.h5
-rw-r--r--sys/kern/init_main.c3
-rw-r--r--sys/kern/kern_descrip.c50
-rw-r--r--sys/kern/kern_syscall.c1
-rw-r--r--sys/kern/vfs_subr.c13
-rw-r--r--sys/kern/vfs_syscalls.c12
-rw-r--r--sys/vm/vm_anon.c116
-rw-r--r--sys/vm/vm_map.c4
-rw-r--r--sys/vm/vm_vnode.c2
22 files changed, 354 insertions, 15 deletions
diff --git a/sys/dev/cons/cons.c b/sys/dev/cons/cons.c
index c3a3197..4b85240 100644
--- a/sys/dev/cons/cons.c
+++ b/sys/dev/cons/cons.c
@@ -30,13 +30,16 @@
#include <sys/param.h>
#include <sys/types.h>
#include <sys/ascii.h>
+#include <sys/device.h>
#include <dev/video/fbdev.h>
#include <dev/cons/font.h>
#include <dev/cons/cons.h>
+#include <fs/devfs.h>
#include <vm/dynalloc.h>
#include <string.h>
struct cons_screen g_root_scr = {0};
+static struct cdevsw cons_cdevsw;
/*
* Create a chracter descriptor for drawing
@@ -89,7 +92,7 @@ static void
cons_draw_cursor(struct cons_screen *scr, uint32_t color)
{
size_t idx;
-
+
for (uint32_t cy = 0; cy < FONT_HEIGHT; ++cy) {
for (uint32_t cx = 0; cx < FONT_WIDTH; ++cx) {
idx = fbdev_get_index(&scr->fbdev, (scr->curs_col * FONT_WIDTH) + cx, (scr->curs_row * FONT_HEIGHT) + cy);
@@ -141,6 +144,24 @@ cons_handle_special(struct cons_screen *scr, char c)
return -1;
}
+/*
+ * Character device function.
+ */
+static int
+dev_write(dev_t dev, struct sio_txn *sio, int flags)
+{
+ char *p;
+
+ p = sio->buf;
+ spinlock_acquire(&g_root_scr.lock);
+
+ for (size_t i = 0; i < sio->len; ++i) {
+ cons_putch(&g_root_scr, p[i]);
+ }
+
+ spinlock_release(&g_root_scr.lock);
+ return sio->len;
+}
/*
* Put a character on the screen.
@@ -203,4 +224,34 @@ cons_init(void)
g_root_scr.nrows = fbdev.height / FONT_HEIGHT;
g_root_scr.ncols = fbdev.width / FONT_WIDTH;
g_root_scr.fbdev = fbdev;
+ memset(&g_root_scr.lock, 0, sizeof(g_root_scr.lock));
}
+
+/*
+ * Expose the console to /dev/console
+ */
+void
+cons_expose(void)
+{
+ static int once = 0;
+ char devname[] = "console";
+ devmajor_t major;
+ dev_t dev;
+
+ /* Only run once */
+ if (once) {
+ return;
+ }
+
+ /* Register the device here */
+ major = dev_alloc_major();
+ dev = dev_alloc(major);
+ dev_register(major, dev, &cons_cdevsw);
+ devfs_create_entry(devname, major, dev, 0444);
+ once ^= 1;
+}
+
+static struct cdevsw cons_cdevsw = {
+ .read = noread,
+ .write = dev_write
+};
diff --git a/sys/fs/devfs.c b/sys/fs/devfs.c
index 0589bbe..024239d 100644
--- a/sys/fs/devfs.c
+++ b/sys/fs/devfs.c
@@ -63,6 +63,22 @@ bdevsw_read(void *devsw, dev_t dev, struct sio_txn *sio)
return bdevsw->read(dev, sio, 0);
}
+static inline int
+cdevsw_write(void *devsw, dev_t dev, struct sio_txn *sio)
+{
+ struct cdevsw *cdevsw = devsw;
+
+ return cdevsw->write(dev, sio, 0);
+}
+
+static inline int
+bdevsw_write(void *devsw, dev_t dev, struct sio_txn *sio)
+{
+ struct bdevsw *bdevsw = devsw;
+
+ return bdevsw->write(dev, sio, 0);
+}
+
/*
* Get a devfs node by name.
*
@@ -174,6 +190,25 @@ devfs_read(struct vnode *vp, struct sio_txn *sio)
}
static int
+devfs_write(struct vnode *vp, struct sio_txn *sio)
+{
+ struct devfs_node *dnp;
+ void *devsw;
+
+ if ((dnp = vp->data) == NULL)
+ return -EIO;
+
+ devsw = dev_get(dnp->major, dnp->dev);
+
+ if (!dnp->is_block) {
+ return cdevsw_write(devsw, dnp->dev, sio);
+ }
+
+ /* Block device */
+ return bdevsw_write(devsw, dnp->dev, sio);
+}
+
+static int
devfs_init(struct fs_info *fip)
{
struct vnode *vp;
@@ -232,6 +267,7 @@ const struct vops g_devfs_vops = {
.lookup = devfs_lookup,
.reclaim = devfs_reclaim,
.read = devfs_read,
+ .write = devfs_write,
.getattr = devfs_getattr
};
diff --git a/sys/fs/initramfs.c b/sys/fs/initramfs.c
index acef462..fd746ef 100644
--- a/sys/fs/initramfs.c
+++ b/sys/fs/initramfs.c
@@ -275,6 +275,7 @@ initramfs_init(struct fs_info *fip)
const struct vops g_initramfs_vops = {
.lookup = initramfs_lookup,
.read = initramfs_read,
+ .write = NULL,
.reclaim = initramfs_reclaim,
.getattr = initramfs_getattr
};
diff --git a/sys/include/dev/cons/cons.h b/sys/include/dev/cons/cons.h
index fe7eb6d..8e2c2c6 100644
--- a/sys/include/dev/cons/cons.h
+++ b/sys/include/dev/cons/cons.h
@@ -31,6 +31,7 @@
#define _DEV_CONS_H_
#include <sys/types.h>
+#include <sys/spinlock.h>
#include <dev/video/fbdev.h>
struct cons_char {
@@ -53,9 +54,11 @@ struct cons_screen {
uint32_t curs_col; /* Cursor col */
uint32_t curs_row; /* Cursor row */
struct cons_char last_chr;
+ struct spinlock lock;
};
void cons_init(void);
+void cons_expose(void);
int cons_putch(struct cons_screen *scr, char c);
extern struct cons_screen g_root_scr;
diff --git a/sys/include/sys/cdefs.h b/sys/include/sys/cdefs.h
index 4103896..37e15d7 100644
--- a/sys/include/sys/cdefs.h
+++ b/sys/include/sys/cdefs.h
@@ -42,6 +42,7 @@
#define __likely(exp) __builtin_expect(((exp) != 0), 1)
#define __unlikely(exp) __builtin_expect(((exp) != 0), 0)
#define __static_assert _Static_assert
+#define __barrier() __ASMV("" ::: "memory")
#if defined(__cplusplus)
#define __BEGIN_DECLS extern "C" {
diff --git a/sys/include/sys/driver.h b/sys/include/sys/driver.h
index f88e286..05c40fa 100644
--- a/sys/include/sys/driver.h
+++ b/sys/include/sys/driver.h
@@ -55,4 +55,3 @@ extern char __drivers_init_end[];
}
#endif /* _KERNEL */
#endif /* !_SYS_DRIVER_H_ */
-
diff --git a/sys/include/sys/fcntl.h b/sys/include/sys/fcntl.h
index 7a62cdd..122a378 100644
--- a/sys/include/sys/fcntl.h
+++ b/sys/include/sys/fcntl.h
@@ -34,4 +34,9 @@
#define O_WRONLY 0x0001
#define O_RDWR 0x0002
+/* Makes seal checking easier */
+#if defined(_KERNEL)
+#define O_ALLOW_WR (O_RDWR | O_WRONLY)
+#endif
+
#endif /* !_SYS_FCTNL_H_ */
diff --git a/sys/include/sys/filedesc.h b/sys/include/sys/filedesc.h
index 9a6230a..a544811 100644
--- a/sys/include/sys/filedesc.h
+++ b/sys/include/sys/filedesc.h
@@ -39,12 +39,14 @@ struct filedesc {
off_t offset;
bool is_dir;
int refcnt;
+ int flags;
struct vnode *vp;
struct spinlock lock;
};
int fd_close(unsigned int fd);
int fd_read(unsigned int fd, void *buf, size_t count);
+int fd_write(unsigned int fd, void *buf, size_t count);
int fd_alloc(struct filedesc **fd_out);
int fd_open(const char *pathname, int flags);
diff --git a/sys/include/sys/mmio.h b/sys/include/sys/mmio.h
index cdc6a46..9f6e4e2 100644
--- a/sys/include/sys/mmio.h
+++ b/sys/include/sys/mmio.h
@@ -67,7 +67,7 @@
tmp += VM_HIGHER_HALF; \
} \
*(volatile TYPE *)tmp = val; \
- __ASMV("" ::: "memory"); \
+ __barrier(); \
}
/*
@@ -86,7 +86,7 @@
tmp += VM_HIGHER_HALF; \
} \
\
- __ASMV("" ::: "memory"); \
+ __barrier(); \
return *(volatile TYPE *)tmp; \
}
diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h
index b724e8b..41d1e78 100644
--- a/sys/include/sys/syscall.h
+++ b/sys/include/sys/syscall.h
@@ -42,6 +42,7 @@
#define SYS_close 4
#define SYS_stat 5
#define SYS_sysctl 6
+#define SYS_write 7
#if defined(_KERNEL)
/* Syscall return value and arg type */
diff --git a/sys/include/sys/termios.h b/sys/include/sys/termios.h
new file mode 100644
index 0000000..27339f1
--- /dev/null
+++ b/sys/include/sys/termios.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 notice,
+ * this list of conditions and the following disclaimer.
+ * 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. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
+ */
+
+#ifndef _TERMIOS_H_
+#define _TERMIOS_H_
+
+/*
+ * c_iflag: Input flags
+ */
+#define ISTRIP 0x00000000
+#define ICRNL 0x00000001
+
+#define NCCS 20
+
+typedef unsigned int cc_t;
+typedef unsigned int speed_t;
+typedef unsigned int tcflag_t;
+
+struct termios {
+ tcflag_t c_iflag; /* Input flags */
+ tcflag_t c_oflag; /* Output flags */
+ tcflag_t c_cflag; /* Control flags */
+ tcflag_t c_lflag; /* Local flags */
+ cc_t c_cc[NCCS];
+};
+
+#endif /* _TERMIOS_H_ */
diff --git a/sys/include/sys/vfs.h b/sys/include/sys/vfs.h
index 61f6673..1ff722a 100644
--- a/sys/include/sys/vfs.h
+++ b/sys/include/sys/vfs.h
@@ -38,6 +38,7 @@
scret_t sys_open(struct syscall_args *scargs);
scret_t sys_close(struct syscall_args *args);
scret_t sys_read(struct syscall_args *scargs);
+scret_t sys_write(struct syscall_args *sargs);
scret_t sys_stat(struct syscall_args *scargs);
#endif /* _KERNEL */
diff --git a/sys/include/sys/vnode.h b/sys/include/sys/vnode.h
index 5cbaa15..33092f9 100644
--- a/sys/include/sys/vnode.h
+++ b/sys/include/sys/vnode.h
@@ -101,6 +101,7 @@ struct vops {
int(*lookup)(struct vop_lookup_args *args);
int(*getattr)(struct vop_getattr_args *args);
int(*read)(struct vnode *vp, struct sio_txn *sio);
+ int(*write)(struct vnode *vp, struct sio_txn *sio);
int(*reclaim)(struct vnode *vp);
};
@@ -117,6 +118,7 @@ int vfs_release_vnode(struct vnode *vp);
int vfs_vop_lookup(struct vnode *vp, struct vop_lookup_args *args);
int vfs_vop_read(struct vnode *vp, struct sio_txn *sio);
+int vfs_vop_write(struct vnode *vp, struct sio_txn *sio);
int vfs_vop_getattr(struct vnode *vp, struct vop_getattr_args *args);
#endif /* _KERNEL */
diff --git a/sys/include/vm/vm_pager.h b/sys/include/vm/vm_pager.h
index 1ba06d9..e0503e0 100644
--- a/sys/include/vm/vm_pager.h
+++ b/sys/include/vm/vm_pager.h
@@ -35,6 +35,11 @@
#include <vm/vm_obj.h>
struct vm_object;
+struct vm_pagerops;
+
+extern const struct vm_pagerops vm_vnops;
+extern const struct vm_pagerops vm_anonops;
+
/*
* Pager operations.
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 1fb3418..f3f88d7 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -83,6 +83,9 @@ main(void)
DRIVERS_INIT();
+ /* Expose the console to devfs */
+ cons_expose();
+
/* Start scheduler and bootstrap APs */
sched_init();
mp_bootstrap_aps(&g_bsp_ci);
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index d1ed044..201db3e 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -31,6 +31,7 @@
#include <sys/errno.h>
#include <sys/proc.h>
#include <sys/limits.h>
+#include <sys/fcntl.h>
#include <sys/namei.h>
#include <sys/filedesc.h>
#include <sys/systm.h>
@@ -135,15 +136,16 @@ fd_close(unsigned int fd)
}
/*
- * Read bytes from a file using a file
+ * Read/write bytes to/from a file using a file
* descriptor number.
*
* @fd: File descriptor number.
- * @buf: Buffer to read into.
+ * @buf: Buffer with data to read/write
* @count: Number of bytes to read.
+ * @write: Set to 1 for writes
*/
-int
-fd_read(unsigned int fd, void *buf, size_t count)
+static int
+fd_rw(unsigned int fd, void *buf, size_t count, uint8_t write)
{
char *kbuf = NULL;
struct filedesc *filedes;
@@ -173,13 +175,34 @@ fd_read(unsigned int fd, void *buf, size_t count)
goto done;
}
+ /* Check if this violates the file seal */
+ if (!ISSET(filedes->flags, O_ALLOW_WR) && write) {
+ return -EPERM;
+ } else if (ISSET(O_RDONLY, filedes->flags) && write) {
+ return -EPERM;
+ }
+
sio.len = count;
sio.buf = kbuf;
sio.offset = filedes->offset;
- if ((count = vfs_vop_read(filedes->vp, &sio)) < 0) {
- retval = -EIO;
- goto done;
+ if (write) {
+ /* Copy in user buffer */
+ if (copyin(buf, kbuf, count) < 0) {
+ retval = -EFAULT;
+ goto done;
+ }
+
+ /* Call VFS write hook */
+ if ((count = vfs_vop_write(filedes->vp, &sio)) < 0) {
+ retval = -EIO;
+ goto done;
+ }
+ } else {
+ if ((count = vfs_vop_read(filedes->vp, &sio)) < 0) {
+ retval = -EIO;
+ goto done;
+ }
}
if (copyout(kbuf, buf, count) < 0) {
@@ -195,6 +218,18 @@ done:
return retval;
}
+int
+fd_read(unsigned int fd, void *buf, size_t count)
+{
+ return fd_rw(fd, buf, count, 0);
+}
+
+int
+fd_write(unsigned int fd, void *buf, size_t count)
+{
+ return fd_rw(fd, buf, count, 1);
+}
+
/*
* Open a file and get a file descriptor
* number.
@@ -224,6 +259,7 @@ fd_open(const char *pathname, int flags)
}
filedes->vp = nd.vp;
+ filedes->flags = flags;
return filedes->fdno;
}
diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c
index 1d961a7..986d82a 100644
--- a/sys/kern/kern_syscall.c
+++ b/sys/kern/kern_syscall.c
@@ -41,6 +41,7 @@ scret_t(*g_sctab[])(struct syscall_args *) = {
sys_close, /* SYS_close */
sys_stat, /* SYS_stat */
sys_sysctl, /* SYS_sysctl */
+ sys_write, /* SYS_write */
};
const size_t MAX_SYSCALLS = NELEM(g_sctab);
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index f67bcfe..da0a4f9 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -167,6 +167,19 @@ vfs_vop_read(struct vnode *vp, struct sio_txn *sio)
}
int
+vfs_vop_write(struct vnode *vp, struct sio_txn *sio)
+{
+ const struct vops *vops = vp->vops;
+
+ if (vops == NULL)
+ return -EIO;
+ if (vops->write == NULL)
+ return -EIO;
+
+ return vops->write(vp, sio);
+}
+
+int
vfs_vop_getattr(struct vnode *vp, struct vop_getattr_args *args)
{
const struct vops *vops = vp->vops;
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index fa613c2..6f2d683 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -129,6 +129,18 @@ sys_read(struct syscall_args *scargs)
}
/*
+ * arg0: fd
+ * arg1: buf
+ * arg2: count
+ */
+scret_t
+sys_write(struct syscall_args *scargs)
+{
+ return fd_write(scargs->arg0, (void *)scargs->arg1,
+ scargs->arg2);
+}
+
+/*
* arg0: path
* arg1: buf
*/
diff --git a/sys/vm/vm_anon.c b/sys/vm/vm_anon.c
new file mode 100644
index 0000000..9ca8842
--- /dev/null
+++ b/sys/vm/vm_anon.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 notice,
+ * this list of conditions and the following disclaimer.
+ * 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. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/spinlock.h>
+#include <sys/syslog.h>
+#include <sys/errno.h>
+#include <sys/param.h>
+#include <vm/physmem.h>
+#include <vm/vm_pager.h>
+#include <vm/vm_page.h>
+#include <vm/vm.h>
+
+#define pr_trace(fmt, ...) kprintf("vm_anon: " fmt, ##__VA_ARGS__)
+#define pr_error(...) pr_trace(__VA_ARGS__)
+
+#define ANON_TIMEOUT_USEC 200000
+
+/*
+ * Get pages from physical memory.
+ *
+ * @obp: Object representing the backing store (in memory).
+ * @pgs: Page descriptors to be filled.
+ * @off: Offset to read from in backing store.
+ * @len: Length to read in bytes.
+ */
+static int
+anon_get(struct vm_object *obp, struct vm_page **pgs, off_t off, size_t len)
+{
+ struct vm_page *pgtmp, *pgres;
+ int retval = 0;
+ size_t j, npgs;
+
+ len = ALIGN_DOWN(len, DEFAULT_PAGESIZE);
+ if (obp == NULL || pgs == NULL) {
+ return -EINVAL;
+ }
+
+ /* Zero bytes is invalid */
+ if (len == 0) {
+ len = 4096;
+ }
+
+ spinlock_acquire(&obp->lock);
+ npgs = len >> 12;
+
+ for (int i = 0; i < npgs; ++i) {
+ j = i / DEFAULT_PAGESIZE;
+ pgtmp = vm_pagelookup(obp, i);
+ pgres = pgs[j];
+
+ /* Do we need to create our own entry? */
+ if (pgtmp == NULL) {
+ pgtmp = vm_pagealloc(obp, PALLOC_ZERO);
+ }
+
+ if (pgtmp == NULL) {
+ pr_trace("anon_get: failed to add page %d, marking invalid\n", j);
+ pgres->flags &= ~PG_VALID;
+ continue;
+ }
+
+ /*
+ * We are *just* populating `pgs' and therefore nobody
+ * should even attempt to acquire this lock... Shit
+ * happens though, so just make sure we can grab it
+ * without assuming success.
+ */
+ if (spinlock_usleep(&pgres->lock, ANON_TIMEOUT_USEC) < 0) {
+ vm_pagefree(obp, pgtmp, 0);
+ pr_error("anon_get: pgres spin timeout\n");
+ return -ETIMEDOUT;
+ }
+
+ /* Hold pgres before configuring it */
+ spinlock_acquire(&pgres->lock);
+ *pgres = *pgtmp;
+ pgres->flags |= (PG_VALID | PG_CLEAN);
+ spinlock_release(&pgres->lock);
+
+ }
+
+ spinlock_release(&obp->lock);
+ return retval;
+}
+
+const struct vm_pagerops vm_anonops = {
+ .get = anon_get
+};
diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c
index 6627865..7b0656b 100644
--- a/sys/vm/vm_map.c
+++ b/sys/vm/vm_map.c
@@ -94,8 +94,8 @@ vm_map_modify(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot, bool unmap
* @prot: Protection flags.
* @count: Count of bytes to be mapped (aligned to page granularity).
*
- * Returns 0 on success, and a less than zero errno
- * on failure.
+ * Returns 0 on success, and a less than zero errno
+ * on failure.
*/
int
vm_map(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot, size_t count)
diff --git a/sys/vm/vm_vnode.c b/sys/vm/vm_vnode.c
index 519d877..2457c97 100644
--- a/sys/vm/vm_vnode.c
+++ b/sys/vm/vm_vnode.c
@@ -50,8 +50,6 @@
#define pr_debug(...) __nothing
#endif /* PR_DEBUG */
-const struct vm_pagerops vm_vnops;
-
/*
* Perform read/write operation on vnode to/from pages.
*