summaryrefslogtreecommitdiff
path: root/src/kernel/mem
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/mem')
-rw-r--r--src/kernel/mem/virt.c22
-rw-r--r--src/kernel/mem/virt.h1
2 files changed, 14 insertions, 9 deletions
diff --git a/src/kernel/mem/virt.c b/src/kernel/mem/virt.c
index 2990668..beeb54f 100644
--- a/src/kernel/mem/virt.c
+++ b/src/kernel/mem/virt.c
@@ -23,21 +23,25 @@ bool virt_iter_next(struct virt_iter *iter) {
* virtual and physical memory, which might not always be the case.
* TODO test this */
- user_ptr virt = iter->_virt;
size_t partial = iter->_remaining;
iter->prior += iter->frag_len;
if (partial <= 0) return false;
- // don't read past the page
- if ((virt & PAGE_MASK) + partial > PAGE_SIZE)
- partial = PAGE_SIZE - (virt & PAGE_MASK);
+ if (iter->_pages) { // if iterating over virtual memory
+ // don't read past the page
+ if ((iter->_virt & PAGE_MASK) + partial > PAGE_SIZE)
+ partial = PAGE_SIZE - (iter->_virt & PAGE_MASK);
- iter->frag = pagedir_virt2phys(iter->_pages,
- iter->_virt, iter->_user, iter->_writeable);
+ iter->frag = pagedir_virt2phys(iter->_pages,
+ iter->_virt, iter->_user, iter->_writeable);
- if (iter->frag == 0) {
- iter->error = true;
- return false;
+ if (iter->frag == 0) {
+ iter->error = true;
+ return false;
+ }
+ } else {
+ // "iterate" over physical memory
+ iter->frag = iter->_virt;
}
iter->frag_len = partial;
diff --git a/src/kernel/mem/virt.h b/src/kernel/mem/virt.h
index 98a7a16..e87a9fe 100644
--- a/src/kernel/mem/virt.h
+++ b/src/kernel/mem/virt.h
@@ -17,6 +17,7 @@ struct virt_iter {
bool _writeable;
};
+/* if pages == NULL, create an iterator over physical memory. */
void virt_iter_new(
struct virt_iter *iter, user_ptr virt, size_t length,
struct pagedir *pages, bool user, bool writeable);