From 7781a976a7b625af003cf96a042240caf42fe8a4 Mon Sep 17 00:00:00 2001 From: rmind Date: Wed, 2 Jul 2008 20:07:43 +0000 Subject: [PATCH] Avoid calling a syscall when argument to sbrk(2) is zero. OK by . --- lib/libc/arch/i386/sys/sbrk.S | 10 ++++++++-- lib/libc/arch/x86_64/sys/sbrk.S | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/libc/arch/i386/sys/sbrk.S b/lib/libc/arch/i386/sys/sbrk.S index 36e97bfeeb8c..359e500574db 100644 --- a/lib/libc/arch/i386/sys/sbrk.S +++ b/lib/libc/arch/i386/sys/sbrk.S @@ -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 #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 diff --git a/lib/libc/arch/x86_64/sys/sbrk.S b/lib/libc/arch/x86_64/sys/sbrk.S index b0952e8c73e7..65c33625b215 100644 --- a/lib/libc/arch/x86_64/sys/sbrk.S +++ b/lib/libc/arch/x86_64/sys/sbrk.S @@ -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 #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