some vm to accomodate needing to have a region search spot be
[newos.git] / kernel / vm / vm_store_null.c
blobddab33a33d8efeb58f2c147a2023d6d524fe99d7
1 /*
2 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 #include <kernel/kernel.h>
6 #include <kernel/vm.h>
7 #include <kernel/vm_priv.h>
8 #include <kernel/heap.h>
9 #include <kernel/debug.h>
10 #include <kernel/lock.h>
11 #include <kernel/vm_store_null.h>
12 #include <kernel/vfs.h>
13 #include <newos/errors.h>
15 static void null_destroy(struct vm_store *store)
17 if(store) {
18 VERIFY_VM_STORE(store);
19 kfree(store);
23 static off_t null_commit(struct vm_store *store, off_t size)
25 VERIFY_VM_STORE(store);
26 store->committed_size = size;
27 return size;
30 static int null_has_page(struct vm_store *store, off_t offset)
32 VERIFY_VM_STORE(store);
33 return 1; // we always have the page, man
36 static ssize_t null_read(struct vm_store *store, off_t offset, iovecs *vecs)
38 VERIFY_VM_STORE(store);
39 return -1;
42 static ssize_t null_write(struct vm_store *store, off_t offset, iovecs *vecs)
44 VERIFY_VM_STORE(store);
45 return -1;
48 static int null_fault(struct vm_store *store, struct vm_address_space *aspace, off_t offset)
50 VERIFY_VM_STORE(store);
51 /* we can't fault on this region, that's pretty much the point of the null store object */
52 return ERR_VM_PF_FATAL;
55 static vm_store_ops null_ops = {
56 &null_destroy,
57 &null_commit,
58 &null_has_page,
59 &null_read,
60 &null_write,
61 &null_fault,
62 NULL,
63 NULL
66 vm_store *vm_store_create_null(void)
68 vm_store *store;
70 store = kmalloc(sizeof(vm_store));
71 if(store == NULL) {
72 return NULL;
75 store->magic = VM_STORE_MAGIC;
76 store->ops = &null_ops;
77 store->cache = NULL;
78 store->data = NULL;
79 store->committed_size = 0;
81 return store;