From d1f8f8301cf0273f0f88abb613712044c6e7194b Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 29 Oct 2018 22:44:01 -0400 Subject: [PATCH] kernel: Tolerate "count" argument to memcpy being 0. It seems GCC2 occasionally will inline a call to memcpy with a count of 0, which this function did not previously expect and would result in a "Divide Error Exception." Hopefully fixes #14613. --- src/system/kernel/lib/arch/x86/arch_string.S | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/system/kernel/lib/arch/x86/arch_string.S b/src/system/kernel/lib/arch/x86/arch_string.S index 7a3480b2c5..a5fe6b51ce 100644 --- a/src/system/kernel/lib/arch/x86/arch_string.S +++ b/src/system/kernel/lib/arch/x86/arch_string.S @@ -1,10 +1,11 @@ /* * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2018, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Copyright 2001, Travis Geiselbrecht. All rights reserved. * Distributed under the terms of the NewOS License. -*/ + */ #include @@ -19,6 +20,12 @@ FUNCTION(memcpy): movl 16(%esp),%esi /* source */ movl 20(%esp),%ecx /* count */ + /* (count == 0 || dest == src) -> quick way out */ + testl %ecx, %ecx + je .tail + cmpl %edi, %esi + je .tail + /* move by words */ // TODO: The addresses might not be aligned! cld @@ -32,6 +39,7 @@ FUNCTION(memcpy): rep movsb +.tail: popl %edi popl %esi ret