kernel: Don't let things clear frames without holding the frame alloc lock
This commit is contained in:
parent
3852646174
commit
63fbbec928
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user