[0/1] Only pass the minimum number of syscall arguments (RISC-V)

Message ID 20200210201958.352384-1-mail@gms.tf
Headers show
Series
  • Only pass the minimum number of syscall arguments (RISC-V)
Related show

Message

Georg Sauthoff Feb. 10, 2020, 8:19 p.m.
As is, the RISC-V syscall code unconditionally sets all possible syscall
arguments even if the syscall requires fewer.

For example, the instruction sequence for a exit syscall looked like
this:

    li    a0, 1   # in ther caller of exit()
    # ...         # in newlib:
    li    a1, 0   # unused arguments
    li    a2, 0
    li    a3, 0
    li    a4, 0
    li    a5, 0
    li    a7, 93  # exit syscall number

(i.e. the binary contains then 5 superfluous instructions for this
one argument syscall)

This patch changes the RISC-V syscall code such that only the required
syscall argument registers are set.

Georg Sauthoff (1):
  Only pass the minimum number of syscall arguments

 libgloss/riscv/internal_syscall.h | 41 ++++++++++++++++++++++---------
 libgloss/riscv/sys_access.c       |  2 +-
 libgloss/riscv/sys_close.c        |  2 +-
 libgloss/riscv/sys_exit.c         |  2 +-
 libgloss/riscv/sys_faccessat.c    |  2 +-
 libgloss/riscv/sys_fstat.c        |  2 +-
 libgloss/riscv/sys_fstatat.c      |  2 +-
 libgloss/riscv/sys_gettimeofday.c |  2 +-
 libgloss/riscv/sys_link.c         |  2 +-
 libgloss/riscv/sys_lseek.c        |  2 +-
 libgloss/riscv/sys_lstat.c        |  2 +-
 libgloss/riscv/sys_open.c         |  2 +-
 libgloss/riscv/sys_openat.c       |  2 +-
 libgloss/riscv/sys_read.c         |  2 +-
 libgloss/riscv/sys_sbrk.c         |  4 +--
 libgloss/riscv/sys_stat.c         |  2 +-
 libgloss/riscv/sys_unlink.c       |  2 +-
 libgloss/riscv/sys_write.c        |  2 +-
 18 files changed, 48 insertions(+), 29 deletions(-)

-- 
2.24.1

Comments

Corinna Vinschen Feb. 11, 2020, 8:42 a.m. | #1
On Feb 10 21:19, Georg Sauthoff wrote:
> As is, the RISC-V syscall code unconditionally sets all possible syscall

> arguments even if the syscall requires fewer.

> 

> For example, the instruction sequence for a exit syscall looked like

> this:

> 

>     li    a0, 1   # in ther caller of exit()

>     # ...         # in newlib:

>     li    a1, 0   # unused arguments

>     li    a2, 0

>     li    a3, 0

>     li    a4, 0

>     li    a5, 0

>     li    a7, 93  # exit syscall number

> 

> (i.e. the binary contains then 5 superfluous instructions for this

> one argument syscall)

> 

> This patch changes the RISC-V syscall code such that only the required

> syscall argument registers are set.

> 

> Georg Sauthoff (1):

>   Only pass the minimum number of syscall arguments

> 

>  libgloss/riscv/internal_syscall.h | 41 ++++++++++++++++++++++---------

>  libgloss/riscv/sys_access.c       |  2 +-

>  libgloss/riscv/sys_close.c        |  2 +-

>  libgloss/riscv/sys_exit.c         |  2 +-

>  libgloss/riscv/sys_faccessat.c    |  2 +-

>  libgloss/riscv/sys_fstat.c        |  2 +-

>  libgloss/riscv/sys_fstatat.c      |  2 +-

>  libgloss/riscv/sys_gettimeofday.c |  2 +-

>  libgloss/riscv/sys_link.c         |  2 +-

>  libgloss/riscv/sys_lseek.c        |  2 +-

>  libgloss/riscv/sys_lstat.c        |  2 +-

>  libgloss/riscv/sys_open.c         |  2 +-

>  libgloss/riscv/sys_openat.c       |  2 +-

>  libgloss/riscv/sys_read.c         |  2 +-

>  libgloss/riscv/sys_sbrk.c         |  4 +--

>  libgloss/riscv/sys_stat.c         |  2 +-

>  libgloss/riscv/sys_unlink.c       |  2 +-

>  libgloss/riscv/sys_write.c        |  2 +-

>  18 files changed, 48 insertions(+), 29 deletions(-)

> 

> -- 

> 2.24.1


Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat