kernel: Don't let things clear frames without holding the frame alloc lock

This commit is contained in:
K. Lange 2022-03-04 22:00:37 +09:00
parent 3852646174
commit 63fbbec928
7 changed files with 18 additions and 5 deletions

View File

@ -23,6 +23,7 @@
void mmu_frame_set(uintptr_t frame_addr);
void mmu_frame_clear(uintptr_t frame_addr);
void mmu_frame_release(uintptr_t frame_addr);
int mmu_frame_test(uintptr_t frame_addr);
uintptr_t mmu_first_n_frames(int n);
uintptr_t mmu_first_frame(void);

View File

@ -129,6 +129,12 @@ static spin_lock_t kheap_lock = { 0 };
static spin_lock_t mmio_space_lock = { 0 };
static spin_lock_t module_space_lock = { 0 };
void mmu_frame_release(uintptr_t frame_addr) {
spin_lock(frame_alloc_lock);
mmu_frame_clear(frame_addr);
spin_unlock(frame_alloc_lock);
}
uintptr_t mmu_first_n_frames(int n) {
for (uint64_t i = 0; i < nframes * PAGE_SIZE; i += PAGE_SIZE) {
int bad = 0;

View File

@ -121,6 +121,12 @@ static spin_lock_t kheap_lock = { 0 };
static spin_lock_t mmio_space_lock = { 0 };
static spin_lock_t module_space_lock = { 0 };
void mmu_frame_release(uintptr_t frame_addr) {
spin_lock(frame_alloc_lock);
mmu_frame_clear(frame_addr);
spin_unlock(frame_alloc_lock);
}
/**
* @brief Find the first range of @p n contiguous frames.
*

View File

@ -175,7 +175,7 @@ ring_buffer_t * ring_buffer_create(size_t size) {
void ring_buffer_destroy(ring_buffer_t * ring_buffer) {
if (ring_buffer->size == 4096) {
mmu_frame_clear((uintptr_t)ring_buffer->buffer & 0xFFFFFFFFF);
mmu_frame_release((uintptr_t)ring_buffer->buffer & 0xFFFFFFFFF);
} else {
free(ring_buffer->buffer);
}

View File

@ -131,7 +131,7 @@ static int release_chunk (shm_chunk_t * chunk) {
/* First, free the frames used by this chunk */
for (uint32_t i = 0; i < chunk->num_frames; i++) {
mmu_frame_clear(chunk->frames[i] << 12);
mmu_frame_release(chunk->frames[i] << 12);
}
/* Then, get rid of the damn thing */

View File

@ -82,7 +82,7 @@ static int ioctl_ramdisk(fs_node_t * node, unsigned long request, void * argp) {
node->length -= node->length % 0x1000;
}
for (uintptr_t i = node->inode; i < (node->inode + node->length); i += 0x1000) {
mmu_frame_clear(i);
mmu_frame_release(i);
}
}
/* Mark the file length as 0 */

View File

@ -131,7 +131,7 @@ static void tmpfs_file_free(struct tmpfs_file * t) {
}
spin_lock(t->lock);
for (size_t i = 0; i < t->block_count; ++i) {
mmu_frame_clear((uintptr_t)t->blocks[i] * 0x1000);
mmu_frame_release((uintptr_t)t->blocks[i] * 0x1000);
tmpfs_total_blocks--;
}
spin_unlock(t->lock);
@ -277,7 +277,7 @@ static int truncate_tmpfs(fs_node_t * node) {
struct tmpfs_file * t = (struct tmpfs_file *)(node->device);
spin_lock(t->lock);
for (size_t i = 0; i < t->block_count; ++i) {
mmu_frame_clear((uintptr_t)t->blocks[i] * 0x1000);
mmu_frame_release((uintptr_t)t->blocks[i] * 0x1000);
tmpfs_total_blocks--;
t->blocks[i] = 0;
}