Use INTERNAL_SYSCALL and INLINE_SYSCALL_ERROR_RETURN_VALUE

This patch uses INTERNAL_SYSCALL and INLINE_SYSCALL_ERROR_RETURN_VALUE
to avoid reading and writing errno directly so that we don't need to
call __x86.get_pc_thunk.reg to load PC into reg in case there is an
error.

	* sysdeps/unix/sysv/linux/i386/brk.c (__brk): Use
	INLINE_SYSCALL_ERROR_RETURN_VALUE.
	* sysdeps/unix/sysv/linux/i386/fxstatat.c (__fxstatat):
	Likewise.
	* sysdeps/unix/sysv/linux/i386/setegid.c (setegid): Likewise.
	* sysdeps/unix/sysv/linux/i386/seteuid.c (seteuid): Likewise.
	* sysdeps/unix/sysv/linux/i386/fxstat.c (__fxstat): Use
	INTERNAL_SYSCALLINTERNAL_SYSCALL and
	INLINE_SYSCALL_ERROR_RETURN_VALUE.
	* sysdeps/unix/sysv/linux/i386/lockf64.c (lockf64): Likewise.
	* sysdeps/unix/sysv/linux/i386/lxstat.c (__lxstat): Likewise.
	* sysdeps/unix/sysv/linux/i386/sigaction.c (__libc_sigaction):
	Likewise.
	* sysdeps/unix/sysv/linux/i386/xstat.c (__xstat): Likewise.
This commit is contained in:
H.J. Lu 2015-10-14 03:45:32 -07:00
parent d7025badd8
commit 8f763b04a0
10 changed files with 56 additions and 47 deletions

View File

@ -1,3 +1,20 @@
2015-10-14 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/unix/sysv/linux/i386/brk.c (__brk): Use
INLINE_SYSCALL_ERROR_RETURN_VALUE.
* sysdeps/unix/sysv/linux/i386/fxstatat.c (__fxstatat):
Likewise.
* sysdeps/unix/sysv/linux/i386/setegid.c (setegid): Likewise.
* sysdeps/unix/sysv/linux/i386/seteuid.c (seteuid): Likewise.
* sysdeps/unix/sysv/linux/i386/fxstat.c (__fxstat): Use
INTERNAL_SYSCALLINTERNAL_SYSCALL and
INLINE_SYSCALL_ERROR_RETURN_VALUE.
* sysdeps/unix/sysv/linux/i386/lockf64.c (lockf64): Likewise.
* sysdeps/unix/sysv/linux/i386/lxstat.c (__lxstat): Likewise.
* sysdeps/unix/sysv/linux/i386/sigaction.c (__libc_sigaction):
Likewise.
* sysdeps/unix/sysv/linux/i386/xstat.c (__xstat): Likewise.
2015-10-13 Joseph Myers <joseph@codesourcery.com>
[BZ #19125]

View File

@ -31,19 +31,11 @@ weak_alias (__curbrk, ___brk_addr)
int
__brk (void *addr)
{
void *newbrk;
INTERNAL_SYSCALL_DECL (err);
newbrk = (void *) INTERNAL_SYSCALL (brk, err, 1, addr);
void *newbrk = (void *) INTERNAL_SYSCALL (brk, err, 1, addr);
__curbrk = newbrk;
if (newbrk < addr)
{
__set_errno (ENOMEM);
return -1;
}
return INLINE_SYSCALL_ERROR_RETURN_VALUE (ENOMEM);
return 0;
}
weak_alias (__brk, brk)

View File

@ -42,10 +42,12 @@ __fxstat (int vers, int fd, struct stat *buf)
{
struct stat64 buf64;
result = INLINE_SYSCALL (fstat64, 2, fd, &buf64);
if (result == 0)
result = __xstat32_conv (vers, &buf64, buf);
return result;
INTERNAL_SYSCALL_DECL (err);
result = INTERNAL_SYSCALL (fstat64, err, 2, fd, &buf64);
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result, err)))
return INLINE_SYSCALL_ERROR_RETURN_VALUE (-result);
else
return __xstat32_conv (vers, &buf64, buf);
}
}

View File

@ -42,13 +42,10 @@ __fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
struct stat64 st64;
result = INTERNAL_SYSCALL (fstatat64, err, 4, fd, file, &st64, flag);
if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1))
return __xstat32_conv (vers, &st64, st);
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result, err)))
return INLINE_SYSCALL_ERROR_RETURN_VALUE (-result);
else
{
__set_errno (INTERNAL_SYSCALL_ERRNO (result, err));
return -1;
}
return __xstat32_conv (vers, &st64, st);
}
libc_hidden_def (__fxstatat)
#ifdef XSTAT_IS_XSTAT64

View File

@ -29,6 +29,7 @@ lockf64 (int fd, int cmd, off64_t len64)
{
struct flock64 fl64;
int cmd64;
int result;
memset ((char *) &fl64, '\0', sizeof (fl64));
fl64.l_whence = SEEK_CUR;
@ -41,12 +42,13 @@ lockf64 (int fd, int cmd, off64_t len64)
/* Test the lock: return 0 if FD is unlocked or locked by this process;
return -1, set errno to EACCES, if another process holds the lock. */
fl64.l_type = F_RDLCK;
if (INLINE_SYSCALL (fcntl64, 3, fd, F_GETLK64, &fl64) < 0)
return -1;
INTERNAL_SYSCALL_DECL (err);
result = INTERNAL_SYSCALL (fcntl64, err, 3, fd, F_GETLK64, &fl64);
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result, err)))
return INLINE_SYSCALL_ERROR_RETURN_VALUE (-result);
if (fl64.l_type == F_UNLCK || fl64.l_pid == __getpid ())
return 0;
__set_errno (EACCES);
return -1;
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EACCES);
case F_ULOCK:
fl64.l_type = F_UNLCK;
cmd64 = F_SETLK64;
@ -61,8 +63,7 @@ lockf64 (int fd, int cmd, off64_t len64)
break;
default:
__set_errno (EINVAL);
return -1;
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
}
return INLINE_SYSCALL (fcntl64, 3, fd, cmd64, &fl64);
}

View File

@ -43,10 +43,12 @@ __lxstat (int vers, const char *name, struct stat *buf)
{
struct stat64 buf64;
result = INLINE_SYSCALL (lstat64, 2, name, &buf64);
if (result == 0)
result = __xstat32_conv (vers, &buf64, buf);
return result;
INTERNAL_SYSCALL_DECL (err);
result = INTERNAL_SYSCALL (lstat64, err, 2, name, &buf64);
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result, err)))
return INLINE_SYSCALL_ERROR_RETURN_VALUE (-result);
else
return __xstat32_conv (vers, &buf64, buf);
}
}

View File

@ -27,10 +27,7 @@ setegid (gid)
int result;
if (gid == (gid_t) ~0)
{
__set_errno (EINVAL);
return -1;
}
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1);

View File

@ -26,10 +26,7 @@ seteuid (uid_t uid)
int result;
if (uid == (uid_t) ~0)
{
__set_errno (EINVAL);
return -1;
}
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
result = INLINE_SETXID_SYSCALL (setresuid32, 3, -1, uid, -1);

View File

@ -69,11 +69,13 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
/* XXX The size argument hopefully will have to be changed to the
real size of the user-level sigset_t. */
result = INLINE_SYSCALL (rt_sigaction, 4,
sig, act ? &kact : NULL,
oact ? &koact : NULL, _NSIG / 8);
if (oact && result >= 0)
INTERNAL_SYSCALL_DECL (err);
result = INTERNAL_SYSCALL (rt_sigaction, err, 4,
sig, act ? &kact : NULL,
oact ? &koact : NULL, _NSIG / 8);
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result, err)))
return INLINE_SYSCALL_ERROR_RETURN_VALUE (-result);
else if (oact && result >= 0)
{
oact->sa_handler = koact.k_sa_handler;
memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));

View File

@ -43,10 +43,12 @@ __xstat (int vers, const char *name, struct stat *buf)
{
struct stat64 buf64;
result = INLINE_SYSCALL (stat64, 2, name, &buf64);
if (result == 0)
result = __xstat32_conv (vers, &buf64, buf);
return result;
INTERNAL_SYSCALL_DECL (err);
result = INTERNAL_SYSCALL (stat64, err, 2, name, &buf64);
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result, err)))
return INLINE_SYSCALL_ERROR_RETURN_VALUE (-result);
else
return __xstat32_conv (vers, &buf64, buf);
}
}
hidden_def (__xstat)