Avoid calling a syscall when argument to sbrk(2) is zero.

OK by <ad>.
This commit is contained in:
rmind 2008-07-02 20:07:43 +00:00
parent b7cdc71cd2
commit 7781a976a7
2 changed files with 16 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sbrk.S,v 1.18 2007/03/09 14:30:56 ad Exp $ */
/* $NetBSD: sbrk.S,v 1.19 2008/07/02 20:07:43 rmind Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@ -36,7 +36,7 @@
#include <machine/asm.h>
#if defined(SYSLIBC_SCCS) && !defined(lint)
RCSID("$NetBSD: sbrk.S,v 1.18 2007/03/09 14:30:56 ad Exp $")
RCSID("$NetBSD: sbrk.S,v 1.19 2008/07/02 20:07:43 rmind Exp $")
#endif /* SYSLIBC_SCCS and not lint */
#include "SYS.h"
@ -59,6 +59,8 @@ ENTRY(_sbrk)
movl PIC_GOT(CURBRK),%edx
PIC_EPILOGUE
movl (%edx),%eax
test %ecx,%ecx
jz out
addl %eax,%ecx
movl %ecx,4(%esp)
OSYSTRAP(break) /* don't clobber %ecx */
@ -68,6 +70,7 @@ ENTRY(_sbrk)
PIC_EPILOGUE
movl (%edx),%eax
movl %ecx,(%edx)
out:
ret
err:
PIC_PROLOGUE
@ -77,11 +80,14 @@ err:
#else
movl 4(%esp),%ecx
movl CURBRK,%eax
test %ecx,%ecx
jz out
addl %eax,4(%esp)
OSYSTRAP(break) /* don't clobber %ecx */
jc err
movl CURBRK,%eax
addl %ecx,CURBRK
out:
ret
err:
jmp CERROR

View File

@ -1,4 +1,4 @@
/* $NetBSD: sbrk.S,v 1.2 2003/08/07 16:42:37 agc Exp $ */
/* $NetBSD: sbrk.S,v 1.3 2008/07/02 20:07:43 rmind Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@ -36,7 +36,7 @@
#include <machine/asm.h>
#if defined(SYSLIBC_SCCS) && !defined(lint)
RCSID("$NetBSD: sbrk.S,v 1.2 2003/08/07 16:42:37 agc Exp $")
RCSID("$NetBSD: sbrk.S,v 1.3 2008/07/02 20:07:43 rmind Exp $")
#endif /* SYSLIBC_SCCS and not lint */
#include "SYS.h"
@ -56,24 +56,30 @@ ENTRY(_sbrk)
#ifdef PIC
movq PIC_GOT(CURBRK),%rdx
movq (%rdx),%rax
test %rdi,%rdi
jz out
addq %rax,%rdi
SYSTRAP(break)
jc err
movq PIC_GOT(CURBRK),%rdx
movq (%rdx),%rax
movq %rdi,(%rdx)
out:
ret
err:
mov PIC_GOT(CERROR),%rdx
jmp *%rdx
#else
movq CURBRK(%rip),%rax
test %rdi,%rdi
jz out
movq %rdi,%rsi
addq %rax,%rdi
SYSTRAP(break)
jc err
movq CURBRK(%rip),%rax
addq %rsi,CURBRK(%rip)
out:
ret
err:
jmp CERROR