summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2013-06-15 09:45:37 +0200
committerRichard Braun <rbraun@sceen.net>2013-07-06 19:02:09 +0200
commit577fb05e6d92e38bb94994ef88d09dfda137fb83 (patch)
treec3e40037a9f79b8c759b7e832a5432e6671c2014
parent38dad0326a0c22676e64d757223df6f97f19eac0 (diff)
Initial object implementation
-rw-r--r--Makefrag.am1
-rw-r--r--vm/vm_object.h66
2 files changed, 67 insertions, 0 deletions
diff --git a/Makefrag.am b/Makefrag.am
index d32c02a3..3dcb507f 100644
--- a/Makefrag.am
+++ b/Makefrag.am
@@ -60,6 +60,7 @@ x15_SOURCES += \
vm/vm_kmem.h \
vm/vm_map.c \
vm/vm_map.h \
+ vm/vm_object.h \
vm/vm_page.h \
vm/vm_phys.c \
vm/vm_phys.h \
diff --git a/vm/vm_object.h b/vm/vm_object.h
new file mode 100644
index 00000000..5de636ab
--- /dev/null
+++ b/vm/vm_object.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * Virtual memory object.
+ *
+ * VM objects are the primary interface between a VM map and a pager. They
+ * can be entered in a VM map ("mapped") and, on page fault, the VM system
+ * requests the actual data from the the backing store pager. The physical
+ * pages used to store those data are then inserted into the appropriate
+ * object.
+ */
+
+#ifndef _VM_VM_OBJECT_H
+#define _VM_VM_OBJECT_H
+
+#include <kern/list.h>
+#include <kern/mutex.h>
+#include <kern/rdxtree.h>
+#include <kern/stdint.h>
+
+struct vm_object_pager;
+
+/*
+ * Memory object.
+ */
+struct vm_object {
+ struct mutex lock;
+ struct rdxtree pages;
+ unsigned long nr_pages;
+ struct vm_object_pager *pager;
+};
+
+/*
+ * Pager operations on an object.
+ */
+struct vm_object_pager {
+ void (*ref)(struct vm_object *object);
+ void (*unref)(struct vm_object *object);
+ int (*get)(struct vm_object *object, uint64_t offset, struct list *pages,
+ int access_prot, int advice);
+};
+
+static inline void
+vm_object_init(struct vm_object *object, struct vm_object_pager *pager)
+{
+ mutex_init(&object->lock);
+ rdxtree_init(&object->pages);
+ object->nr_pages = 0;
+ object->pager = pager;
+}
+
+#endif /* _VM_VM_OBJECT_H */