diff options
author | dzwdz | 2021-09-05 18:55:32 +0200 |
---|---|---|
committer | dzwdz | 2021-09-05 18:55:32 +0200 |
commit | 0b2b263060907e8bf732c1d27c66b7358af01e9f (patch) | |
tree | 321e459503ed2694126b2556e3064f95006c0148 /src/kernel/mem/virt.c | |
parent | 838b142b7374150df63ec02b02377c114a14b314 (diff) |
make virt_iter support iterating over physical memory too
Diffstat (limited to 'src/kernel/mem/virt.c')
-rw-r--r-- | src/kernel/mem/virt.c | 22 |
1 files changed, 13 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; |