diff --git a/src/kernel/core/vm/vm_store_anonymous_noswap.c b/src/kernel/core/vm/vm_store_anonymous_noswap.c index d030481880..e7309d4abb 100755 --- a/src/kernel/core/vm/vm_store_anonymous_noswap.c +++ b/src/kernel/core/vm/vm_store_anonymous_noswap.c @@ -4,20 +4,15 @@ */ -#include -#include -#include -#include -#include -#include -#include #include +#include -#ifndef TRACE_VM -# define TRACE_VM 0 -#endif -#if TRACE_VM -# define TRACE(x) dprintf(x) +#include + + +#define TRACE_VM +#ifdef TRACE_VM +# define TRACE(x) dprintf x #else # define TRACE(x) ; #endif @@ -29,39 +24,42 @@ anonymous_destroy(struct vm_store *store) free(store); } + /* anonymous_commit * As this store provides anonymous memory that is simply discarded * when finished with, we don't bother recording the changes * here, so we just return 0. */ -static off_t anonymous_commit(struct vm_store *store, off_t size) + +static off_t +anonymous_commit(struct vm_store *store, off_t size) { return 0; } -static int anonymous_has_page(struct vm_store *store, off_t offset) + +static int +anonymous_has_page(struct vm_store *store, off_t offset) { return 0; } -static ssize_t anonymous_read(struct vm_store *store, off_t offset, iovecs *vecs) + +static ssize_t +anonymous_read(struct vm_store *store, off_t offset, iovecs *vecs) { panic("anonymous_store: read called. Invalid!\n"); - return ERR_UNIMPLEMENTED; + return B_ERROR; } -static ssize_t anonymous_write(struct vm_store *store, off_t offset, iovecs *vecs) + +static ssize_t +anonymous_write(struct vm_store *store, off_t offset, iovecs *vecs) { // no place to write, this will cause the page daemon to skip this store return 0; } -/* -static int anonymous_fault(struct vm_store *backing_store, struct vm_address_space *aspace, off_t offset) -{ - // unused -} -*/ static vm_store_ops anonymous_ops = { &anonymous_destroy, @@ -74,15 +72,15 @@ static vm_store_ops anonymous_ops = { NULL }; + /* vm_store_create_anonymous * Create a new vm_store that uses anonymous noswap memory */ + vm_store * vm_store_create_anonymous_noswap() { - vm_store *store; - - store = malloc(sizeof(vm_store)); + vm_store *store = malloc(sizeof(vm_store)); if (store == NULL) return NULL; @@ -90,7 +88,6 @@ vm_store_create_anonymous_noswap() store->ops = &anonymous_ops; store->cache = NULL; - store->data = NULL; store->committed_size = 0; return store; diff --git a/src/kernel/core/vm/vm_store_device.c b/src/kernel/core/vm/vm_store_device.c index 83776bff6f..601a6b2edd 100755 --- a/src/kernel/core/vm/vm_store_device.c +++ b/src/kernel/core/vm/vm_store_device.c @@ -3,59 +3,68 @@ ** Distributed under the terms of the NewOS License. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -struct device_store_data { - addr base_addr; +#include +#include + +#include + + +struct device_store { + vm_store vm; + addr_t base_address; }; -static void device_destroy(struct vm_store *store) + +static void +device_destroy(struct vm_store *store) { - if(store) { - free(store); - } + free(store); } -static off_t device_commit(struct vm_store *store, off_t size) + +static off_t +device_commit(struct vm_store *store, off_t size) { store->committed_size = size; return size; } -static int device_has_page(struct vm_store *store, off_t offset) + +static int +device_has_page(struct vm_store *store, off_t offset) { // this should never be called return 0; } -static ssize_t device_read(struct vm_store *store, off_t offset, iovecs *vecs) + +static ssize_t +device_read(struct vm_store *store, off_t offset, iovecs *vecs) { panic("device_store: read called. Invalid!\n"); - return ERR_UNIMPLEMENTED; + return B_ERROR; } -static ssize_t device_write(struct vm_store *store, off_t offset, iovecs *vecs) + +static ssize_t +device_write(struct vm_store *store, off_t offset, iovecs *vecs) { // no place to write, this will cause the page daemon to skip this store return 0; } -// this fault handler should take over the page fault routine and map the page in -// -// setup: the cache that this store is part of has a ref being held and will be -// released after this handler is done -static int device_fault(struct vm_store *store, struct vm_address_space *aspace, off_t offset) +/** this fault handler should take over the page fault routine and map the page in + * + * setup: the cache that this store is part of has a ref being held and will be + * released after this handler is done + */ + +static int +device_fault(struct vm_store *_store, struct vm_address_space *aspace, off_t offset) { - struct device_store_data *d = (struct device_store_data *)store->data; - vm_cache_ref *cache_ref = store->cache->ref; + struct device_store *store = (struct device_store *)_store; + vm_cache_ref *cache_ref = store->vm.cache->ref; vm_region *region; // dprintf("device_fault: offset 0x%x 0x%x + base_addr 0x%x\n", offset, d->base_addr); @@ -65,15 +74,15 @@ static int device_fault(struct vm_store *store, struct vm_address_space *aspace, (*aspace->translation_map.ops->lock)(&aspace->translation_map); // cycle through all of the regions that map this cache and map the page in - for(region = cache_ref->region_list; region != NULL; region = region->cache_next) { + for (region = cache_ref->region_list; region != NULL; region = region->cache_next) { // make sure this page in the cache that was faulted on is covered in this region - if(offset >= region->cache_offset && (offset - region->cache_offset) < region->size) { + if (offset >= region->cache_offset && (offset - region->cache_offset) < region->size) { // dprintf("device_fault: mapping paddr 0x%x to vaddr 0x%x\n", // (addr)(d->base_addr + offset), // (addr)(region->base + (offset - region->cache_offset))); (*aspace->translation_map.ops->map)(&aspace->translation_map, region->base + (offset - region->cache_offset), - d->base_addr + offset, region->lock); + store->base_address + offset, region->lock); } } @@ -85,6 +94,7 @@ static int device_fault(struct vm_store *store, struct vm_address_space *aspace, return 0; } + static vm_store_ops device_ops = { &device_destroy, &device_commit, @@ -96,23 +106,20 @@ static vm_store_ops device_ops = { NULL }; -vm_store *vm_store_create_device(addr base_addr) -{ - vm_store *store; - struct device_store_data *d; - store = malloc(sizeof(vm_store) + sizeof(struct device_store_data)); - if(store == NULL) +vm_store * +vm_store_create_device(addr_t baseAddress) +{ + struct device_store *store = malloc(sizeof(struct device_store)); + if (store == NULL) return NULL; - store->ops = &device_ops; - store->cache = NULL; - store->data = (void *)((addr)store + sizeof(vm_store)); - store->committed_size = 0; + store->vm.ops = &device_ops; + store->vm.cache = NULL; + store->vm.committed_size = 0; - d = (struct device_store_data *)store->data; - d->base_addr = base_addr; + store->base_address = baseAddress; - return store; + return &store->vm; } diff --git a/src/kernel/core/vm/vm_store_null.c b/src/kernel/core/vm/vm_store_null.c index f484a46d6f..2e09a33e03 100755 --- a/src/kernel/core/vm/vm_store_null.c +++ b/src/kernel/core/vm/vm_store_null.c @@ -3,50 +3,57 @@ ** Distributed under the terms of the NewOS License. */ -#include -#include -#include -#include -#include + #include -#include -#include #include -static void null_destroy(struct vm_store *store) +#include + + +static void +null_destroy(struct vm_store *store) { - if(store) { - free(store); - } + free(store); } -static off_t null_commit(struct vm_store *store, off_t size) + +static off_t +null_commit(struct vm_store *store, off_t size) { store->committed_size = size; return size; } -static int null_has_page(struct vm_store *store, off_t offset) + +static int +null_has_page(struct vm_store *store, off_t offset) { return 1; // we always have the page, man } -static ssize_t null_read(struct vm_store *store, off_t offset, iovecs *vecs) + +static ssize_t +null_read(struct vm_store *store, off_t offset, iovecs *vecs) { return -1; } -static ssize_t null_write(struct vm_store *store, off_t offset, iovecs *vecs) + +static ssize_t +null_write(struct vm_store *store, off_t offset, iovecs *vecs) { return -1; } -static int null_fault(struct vm_store *store, struct vm_address_space *aspace, off_t offset) + +static int +null_fault(struct vm_store *store, struct vm_address_space *aspace, off_t offset) { /* we can't fault on this region, that's pretty much the point of the null store object */ return ERR_VM_PF_FATAL; } + static vm_store_ops null_ops = { &null_destroy, &null_commit, @@ -58,18 +65,18 @@ static vm_store_ops null_ops = { NULL }; -vm_store *vm_store_create_null(void) + +vm_store * +vm_store_create_null(void) { vm_store *store; store = malloc(sizeof(vm_store)); - if(store == NULL) { + if (store == NULL) return NULL; - } store->ops = &null_ops; store->cache = NULL; - store->data = NULL; store->committed_size = 0; return store;