kernel: user safe strlen

This commit is contained in:
Matheus
2022-12-13 23:41:40 -03:00
parent 9fc62579ea
commit c17a2f4c6c
5 changed files with 55 additions and 1 deletions
+6 -1
View File
@@ -1,4 +1,4 @@
objects := $(patsubst %.c,%.o,$(wildcard *.c)) israsm.o context.o syscall.o sched.o
objects := $(patsubst %.c,%.o,$(wildcard *.c)) israsm.o context.o syscall.o sched.o ustringasm.o
subdirs=boot
OBJPATH=$(OBJDIR)/arch/${TARGET}/
export
@@ -27,3 +27,8 @@ sched.o: sched.asm
nasm -f elf64 -o $@ $<
mkdir -p $(OBJPATH)
cp $@ $(OBJPATH)/$@
ustringasm.o: ustring.asm
nasm -f elf64 -o $@ $<
mkdir -p $(OBJPATH)
cp $@ $(OBJPATH)/$@
+19
View File
@@ -0,0 +1,19 @@
section .text:
global arch_u_strlen
global arch_u_strlen_cont
arch_u_strlen:
xor rcx, rcx
.loop:
cmp byte [rdi],0
je .done
inc rcx
inc rdi
.done:
mov [rsi], rcx
xor rax, rax
ret
arch_u_strlen_cont:
mov rax, 1
ret
+2
View File
@@ -42,6 +42,8 @@ typedef struct _thread_t{
vmm_context* ctx;
pid_t tid;
int priority;
int umemoperror;
void (*umemopfailaddr)();
} thread_t;
typedef struct _proc_t{
+9
View File
@@ -0,0 +1,9 @@
#ifndef _USTRING_H_INCLUDE
#define _USTRING_H_INCLUDE
#include <stddef.h>
int u_strlen(const char* str, size_t* size);
#endif
+19
View File
@@ -0,0 +1,19 @@
#include <kernel/ustring.h>
#include <arch/cls.h>
extern void arch_u_strlen_cont();
extern int arch_u_strlen(const char* str, size_t* len);
int u_strlen(const char* str, size_t* len){
arch_getcls()->thread->umemopfailaddr = arch_u_strlen_cont;
int ret = arch_u_strlen(str, len);
arch_getcls()->thread->umemopfailaddr = NULL;
return ret == 0 ? 0 : arch_getcls()->thread->umemoperror;
}