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.
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
|
* Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||||
|
* Copyright 2018, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
* Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||||
* Distributed under the terms of the NewOS License.
|
* Distributed under the terms of the NewOS License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <asm_defs.h>
|
#include <asm_defs.h>
|
||||||
@@ -19,6 +20,12 @@ FUNCTION(memcpy):
|
|||||||
movl 16(%esp),%esi /* source */
|
movl 16(%esp),%esi /* source */
|
||||||
movl 20(%esp),%ecx /* count */
|
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 */
|
/* move by words */
|
||||||
// TODO: The addresses might not be aligned!
|
// TODO: The addresses might not be aligned!
|
||||||
cld
|
cld
|
||||||
@@ -32,6 +39,7 @@ FUNCTION(memcpy):
|
|||||||
rep
|
rep
|
||||||
movsb
|
movsb
|
||||||
|
|
||||||
|
.tail:
|
||||||
popl %edi
|
popl %edi
|
||||||
popl %esi
|
popl %esi
|
||||||
ret
|
ret
|
||||||
|
|||||||
Reference in New Issue
Block a user