mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
kernel: user safe strlen
This commit is contained in:
@@ -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
|
subdirs=boot
|
||||||
OBJPATH=$(OBJDIR)/arch/${TARGET}/
|
OBJPATH=$(OBJDIR)/arch/${TARGET}/
|
||||||
export
|
export
|
||||||
@@ -27,3 +27,8 @@ sched.o: sched.asm
|
|||||||
nasm -f elf64 -o $@ $<
|
nasm -f elf64 -o $@ $<
|
||||||
mkdir -p $(OBJPATH)
|
mkdir -p $(OBJPATH)
|
||||||
cp $@ $(OBJPATH)/$@
|
cp $@ $(OBJPATH)/$@
|
||||||
|
|
||||||
|
ustringasm.o: ustring.asm
|
||||||
|
nasm -f elf64 -o $@ $<
|
||||||
|
mkdir -p $(OBJPATH)
|
||||||
|
cp $@ $(OBJPATH)/$@
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -42,6 +42,8 @@ typedef struct _thread_t{
|
|||||||
vmm_context* ctx;
|
vmm_context* ctx;
|
||||||
pid_t tid;
|
pid_t tid;
|
||||||
int priority;
|
int priority;
|
||||||
|
int umemoperror;
|
||||||
|
void (*umemopfailaddr)();
|
||||||
} thread_t;
|
} thread_t;
|
||||||
|
|
||||||
typedef struct _proc_t{
|
typedef struct _proc_t{
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user