mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 22:48:21 +00:00
kernel: random fixes on syscalls and pmm
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
uintptr_t hhdmbase;
|
uintptr_t hhdmbase;
|
||||||
static size_t memorysize;
|
static size_t memorysize;
|
||||||
static size_t physicalpagecount;
|
static size_t physicalpagecount;
|
||||||
|
static size_t used;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
@@ -93,6 +94,7 @@ void *pmm_alloc(size_t size, int section) {
|
|||||||
bmset((void *)((page + j) * PAGE_SIZE), 0);
|
bmset((void *)((page + j) * PAGE_SIZE), 0);
|
||||||
|
|
||||||
spinlock_release(&bmsections[i].lock);
|
spinlock_release(&bmsections[i].lock);
|
||||||
|
__atomic_add_fetch(&used, 1, __ATOMIC_SEQ_CST);
|
||||||
return (void *)(page * PAGE_SIZE);
|
return (void *)(page * PAGE_SIZE);
|
||||||
}
|
}
|
||||||
spinlock_release(&bmsections[i].lock);
|
spinlock_release(&bmsections[i].lock);
|
||||||
@@ -114,11 +116,19 @@ void pmm_free(void *addr, size_t size) {
|
|||||||
bmset((void *)((page + j) * PAGE_SIZE), 1);
|
bmset((void *)((page + j) * PAGE_SIZE), 1);
|
||||||
|
|
||||||
spinlock_release(&bmsections[i].lock);
|
spinlock_release(&bmsections[i].lock);
|
||||||
|
__atomic_sub_fetch(&used, 1, __ATOMIC_SEQ_CST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pmm_getinfo(size_t *pages, size_t *usedpages) {
|
||||||
|
if (pages)
|
||||||
|
*pages = physicalpagecount;
|
||||||
|
if (usedpages)
|
||||||
|
*usedpages = used;
|
||||||
|
}
|
||||||
|
|
||||||
#define TOP_1MB (0x100000 / PAGE_SIZE)
|
#define TOP_1MB (0x100000 / PAGE_SIZE)
|
||||||
#define TOP_4GB ((uint64_t)0x100000000 / PAGE_SIZE)
|
#define TOP_4GB ((uint64_t)0x100000000 / PAGE_SIZE)
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,9 @@ syscallret_t syscall_read(context_t *context, int fd, void *buffer, size_t size)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO pass flags
|
|
||||||
size_t bytesread;
|
size_t bytesread;
|
||||||
uintmax_t offset = file->offset;
|
uintmax_t offset = file->offset;
|
||||||
ret.errno = vfs_read(file->vnode, kernelbuff, size, file->offset, &bytesread, 0);
|
ret.errno = vfs_read(file->vnode, kernelbuff, size, file->offset, &bytesread, fileflagstovnodeflags(file->flags));
|
||||||
|
|
||||||
if (ret.errno)
|
if (ret.errno)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|||||||
@@ -24,10 +24,9 @@ syscallret_t syscall_write(context_t *context, int fd, void *buffer, size_t size
|
|||||||
// TODO safe memcpy
|
// TODO safe memcpy
|
||||||
memcpy(kernelbuff, buffer, size);
|
memcpy(kernelbuff, buffer, size);
|
||||||
|
|
||||||
// TODO pass flags
|
|
||||||
size_t byteswritten;
|
size_t byteswritten;
|
||||||
uintmax_t offset = file->offset;
|
uintmax_t offset = file->offset;
|
||||||
ret.errno = vfs_write(file->vnode, kernelbuff, size, offset, &byteswritten, 0);
|
ret.errno = vfs_write(file->vnode, kernelbuff, size, offset, &byteswritten, fileflagstovnodeflags(file->flags));
|
||||||
|
|
||||||
if (ret.errno)
|
if (ret.errno)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|||||||
Reference in New Issue
Block a user