This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v5] [BZ #21956] MIPS/o32: Fix internal_syscall5/6/7


On 2017-08-24 14:26, Maciej W. Rozycki wrote:
> From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> 
> Fix a commit cc25c8b4c119 ("New pthread rwlock that is more scalable.") 
> regression and prevent uncontrolled stack space usage from happening 
> when a 5-, 6- or 7-argument syscall wrapper is placed in a loop.
> 
> The cause of the problem is the use of `alloca' in regular MIPS/Linux 
> wrappers to force the use of the frame pointer register in any function 
> using one or more of these wrappers.  Using the frame pointer register 
> is required so as not to break frame unwinding as the the stack pointer 
> is lowered within the inline asm used by these wrappers to make room for 
> the stack arguments, which 5-, 6- and 7-argument syscalls use with the 
> o32 ABI.
> 
> The regular MIPS/Linux wrappers are macros however, expanded inline, and 
> stack allocations made with `alloca' are not discarded until the return 
> of the function they are made in.  Consequently if called in a loop, 
> then virtual memory is wasted, and if the loop goes through enough 
> iterations, then ultimately available memory can get exhausted causing 
> the program to crash.
> 
> Address the issue by replacing the inline code with standalone assembly 
> functions, which rely on the compiler arranging syscall arguments 
> according to the o32 function calling convention, which MIPS/Linux 
> syscalls also use, except for the syscall number passed and the error 
> flag returned.  This way there is no need to fiddle with the stack 
> pointer anymore and all that has to be handled in the new standalone 
> functions is the special handling of the syscall number and the error 
> flag.
> 
> Redirect 5-, 6- or 7-argument MIPS16/Linux syscall wrappers to these new 
> functions as well, so as to avoid an unnecessary double call the 
> existing wrappers would cause with the new arrangement.
> 
> 2017-08-24  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
> 	    Aurelien Jarno  <aurelien@aurel32.net>
> 	    Maciej W. Rozycki  <macro@imgtec.com>
> 
> 	[BZ #21956]
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/Makefile
> 	[subdir = misc] (sysdep_routines): Remove `mips16-syscall5',
> 	`mips16-syscall6' and `mips16-syscall7'.
> 	(CFLAGS-mips16-syscall5.c, CFLAGS-mips16-syscall6.c)
> 	(CFLAGS-mips16-syscall7.c): Remove.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/Versions (libc):
> 	Remove `__mips16_syscall5', `__mips16_syscall6' and 
> 	`__mips16_syscall7'.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/mips16-syscall0.c
> 	(__mips16_syscall0): Rename `__mips16_syscall_return' to 
> 	`__mips_syscall_return'.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/mips16-syscall1.c
> 	(__mips16_syscall1): Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/mips16-syscall2.c
> 	(__mips16_syscall2): Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/mips16-syscall3.c
> 	(__mips16_syscall3): Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/mips16-syscall4.c
> 	(__mips16_syscall4): Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/mips16-syscall5.c:
> 	Remove.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/mips16-syscall6.c:
> 	Remove.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/mips16-syscall7.c:
> 	Remove.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips16/mips16-syscall.h
> 	(__mips16_syscall5): Expand to `__mips_syscall5' rather than 
> 	`__mips16_syscall5'.  Remove prototype.
> 	(__mips16_syscall6): Expand to `__mips_syscall6' rather than
> 	`__mips16_syscall6'.  Remove prototype.
> 	(__mips16_syscall7): Expand to `__mips_syscall7' rather than
> 	`__mips16_syscall7'.  Remove prototype.
> 	(__nomips16, __mips16_syscall_return): Move to...
> 	* sysdeps/unix/sysv/linux/mips/mips32/sysdep.h 
> 	(__nomips16, __mips_syscall_return): ... here.
> 	[__mips16] (INTERNAL_SYSCALL_NCS): Rename 
> 	`__mips16_syscall_return' to `__mips_syscall_return'.
> 	[__mips16] (INTERNAL_SYSCALL_MIPS16): Pass `number' to
> 	`internal_syscall##nr'.
> 	[!__mips16] (INTERNAL_SYSCALL): Pass `SYS_ify (name)' to
> 	`internal_syscall##nr'.
> 	(FORCE_FRAME_POINTER): Remove.
> 	(__mips_syscall5): New prototype.
> 	(internal_syscall5): Rewrite to call `__mips_syscall5'.
> 	(__mips_syscall6): New prototype.
> 	(internal_syscall6): Rewrite to call `__mips_syscall6'.
> 	(__mips_syscall7): New prototype.
> 	(internal_syscall7): Rewrite to call `__mips_syscall7'.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips-syscall5.S: New file.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips-syscall6.S: New file.
> 	* sysdeps/unix/sysv/linux/mips/mips32/mips-syscall7.S: New file.
> 	* sysdeps/unix/sysv/linux/mips/mips32/Makefile [subdir = misc]
> 	(sysdep_routines): Add libc-do-syscall.
> 	* sysdeps/unix/sysv/linux/mips/mips32/Versions (libc): Add
> 	`__mips_syscall5', `__mips_syscall6' and `__mips_syscall7'.
> 
> ---

Thanks for this new version, it looks good to me.

Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]