diff --git a/src/system/kernel/arch/arm/arch_cpu.cpp b/src/system/kernel/arch/arm/arch_cpu.cpp index e225f9cef8..65d4795a80 100644 --- a/src/system/kernel/arch/arm/arch_cpu.cpp +++ b/src/system/kernel/arch/arm/arch_cpu.cpp @@ -161,6 +161,8 @@ arch_cpu_user_TLB_invalidate(void) } +// TODO: all functions that use fault handlers need to be implemented +// in assembly due to problems passing in label addresses in gcc4. status_t arch_cpu_user_memcpy(void *to, const void *from, size_t size, addr_t *faultHandler) diff --git a/src/system/kernel/arch/m68k/arch_cpu.cpp b/src/system/kernel/arch/m68k/arch_cpu.cpp index 235c5aabaf..488e905c19 100644 --- a/src/system/kernel/arch/m68k/arch_cpu.cpp +++ b/src/system/kernel/arch/m68k/arch_cpu.cpp @@ -171,6 +171,8 @@ arch_cpu_user_TLB_invalidate(void) } +// TODO: all functions that use fault handlers need to be implemented +// in assembly due to problems passing in label addresses in gcc4. status_t arch_cpu_user_memcpy(void *to, const void *from, size_t size, addr_t *faultHandler) diff --git a/src/system/kernel/arch/ppc/arch_cpu.cpp b/src/system/kernel/arch/ppc/arch_cpu.cpp index 79c62967f0..80a76d4294 100644 --- a/src/system/kernel/arch/ppc/arch_cpu.cpp +++ b/src/system/kernel/arch/ppc/arch_cpu.cpp @@ -172,6 +172,9 @@ arch_cpu_user_TLB_invalidate(void) } +// TODO: all functions that use fault handlers need to be implemented +// in assembly due to problems passing in label addresses in gcc4. + status_t arch_cpu_user_memcpy(void *to, const void *from, size_t size, addr_t *faultHandler) diff --git a/src/system/kernel/arch/x86/arch_x86.S b/src/system/kernel/arch/x86/arch_x86.S index 58e20fc8cc..1ebcae0e82 100644 --- a/src/system/kernel/arch/x86/arch_x86.S +++ b/src/system/kernel/arch/x86/arch_x86.S @@ -276,32 +276,37 @@ FUNCTION(arch_cpu_user_strlcpy): /* Copy at most count - 1 bytes */ dec %ecx - /* move data by bytes */ + /* If count is now 0, skip straight to null terminating + as our loop will otherwise overflow */ + jnz .L_user_strlcpy_copy_begin + movb $0,(%edi) + jmp .L_user_strlcpy_source_count + +.L_user_strlcpy_copy_begin: cld - repnz - movsb +.L_user_strlcpy_copy_loop: + /* move data by bytes */ + lodsb + stosb + test %al,%al + jz .L_user_strlcpy_source_done + loop .L_user_strlcpy_copy_loop /* null terminate string */ movb $0,(%edi) dec %esi - /* check if we copied the entire source string */ - cmp $0,%ecx - jne .L_user_strlcpy_source_done - /* count remaining bytes in src */ .L_user_strlcpy_source_count: not %ecx - movb $0,%al + xor %al,%al repnz scasb .L_user_strlcpy_source_done: - movl %esi,%eax subl 20(%esp),%eax - subl $1,%eax - + dec %eax /* restore the old fault handler */ movl %ebx,(%edx)