[PATCH] Update: cancellation support for linux-mips
Guido Guenther
agx@sigxcpu.org
Sat Jan 25 16:19:00 GMT 2003
Hi,
I've cleaned up the syscall cancellation patch for mips a bit merging
everything into one piece (this also makes the unix/mips/sysdep.S
cleanup patch obsolete). I don't see any additional test failures with
it on mips. Can this go in? Are there any problems with the patch?
-- Guido
P.S.: The current 4 test failures on mips are at:
http://honk.physik.uni-konstanz.de/linux-mips/glibc/patches/experimental/test-failures.txt
They also show up with stock glibc 2.3.1. I'll look into them as soon as
I have a newer kernel working on my Indy since there were kernel fixes
that might help.
-------------- next part --------------
2003-01-25 Guido Guenther <agx@sigxcpu.org>
* linuxthreads/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h: New file.
* linuxthreads/sysdeps/unix/sysv/linux/mips/Makefile: New file.
* sysdeps/unix/sysv/linux/mips/pread.c: add support for
cancellation handling and handle both __NR_pread64 and __NR_pread.
* sysdeps/unix/sysv/linux/mips/pread64.c: Likewise.
* sysdeps/unix/sysv/linux/mips/pwrite.c: add support for
cancellation handling and handle both __NR_pwrite64 and __NR_pwrite.
* sysdeps/unix/sysv/linux/mips/pwrite64.c: Likewise.
* sysdeps/unix/mips/sysdep.S: don't set errno in the _LIBC_REENTRANT
case, use register names consistently.
Index: sysdeps/unix/mips/sysdep.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/mips/sysdep.S,v
retrieving revision 1.12
diff -u -u -r1.12 sysdep.S
--- sysdeps/unix/mips/sysdep.S 6 Jul 2001 04:56:11 -0000 1.12
+++ sysdeps/unix/mips/sysdep.S 25 Jan 2003 15:48:39 -0000
@@ -27,11 +27,11 @@
#ifdef __PIC__
.set noreorder
.set noat
- move $1, $31
- bltzal $0, 0f
+ move AT, ra
+ bltzal zero, 0f
nop
-0: .cpload $31
- move $31, $1
+0: .cpload ra
+ move ra, AT
.set at
.set reorder
#endif
@@ -51,9 +52,6 @@
li v0, EAGAIN
skip:
#endif
- /* Store it in the "real" variable ... */
- sw v0, errno
-
/* Find our per-thread errno address */
jal __errno_location
@@ -75,11 +73,11 @@
#ifdef __PIC__
.set noreorder
.set noat
- move $1, $31
- bltzal $0, 0f
+ move AT, ra
+ bltzal zero, 0f
nop
-0: .cpload $31
- move $31, $1
+0: .cpload ra
+ move ra, AT
.set at
.set reorder
#endif
Index: sysdeps/unix/sysv/linux/mips/pread.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/pread.c,v
retrieving revision 1.8
diff -u -u -r1.8 pread.c
--- sysdeps/unix/sysv/linux/mips/pread.c 17 Jul 2002 20:42:55 -0000 1.8
+++ sysdeps/unix/sysv/linux/mips/pread.c 25 Jan 2003 15:48:49 -0000
@@ -22,12 +22,19 @@
#include <unistd.h>
#include <endian.h>
-#include <sysdep.h>
+#include <sysdep-cancel.h>
#include <sys/syscall.h>
#include <bp-checks.h>
#include <kernel-features.h>
+#ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pread
+# error "__NR_pread and __NR_pread64 both defined???"
+# endif
+# define __NR_pread __NR_pread64
+#endif
+
#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
# if __ASSUME_PREAD_SYSCALL == 0
@@ -48,6 +55,22 @@
{
ssize_t result;
+ if (SINGLE_THREAD_P)
+ {
+ /* First try the syscall. */
+ assert (sizeof (offset) == 4);
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR (offset >> 31, offset));
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread (fd, buf, count, offset);
+# endif
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
/* First try the syscall. */
assert (sizeof (offset) == 4);
result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
@@ -57,6 +80,9 @@
/* No system call available. Use the emulation. */
result = __emulate_pread (fd, buf, count, offset);
# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
return result;
}
Index: sysdeps/unix/sysv/linux/mips/pread64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/pread64.c,v
retrieving revision 1.8
diff -u -u -r1.8 pread64.c
--- sysdeps/unix/sysv/linux/mips/pread64.c 6 Jul 2001 04:56:18 -0000 1.8
+++ sysdeps/unix/sysv/linux/mips/pread64.c 25 Jan 2003 15:48:49 -0000
@@ -21,12 +21,19 @@
#include <unistd.h>
#include <endian.h>
-#include <sysdep.h>
+#include <sysdep-cancel.h>
#include <sys/syscall.h>
#include <bp-checks.h>
#include <kernel-features.h>
+#ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pread
+# error "__NR_pread and __NR_pread64 both defined???"
+# endif
+# define __NR_pread __NR_pread64
+#endif
+
#if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
# if __ASSUME_PREAD_SYSCALL == 0
@@ -48,6 +55,23 @@
{
ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ {
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+# if __ASSUME_PREAD_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pread64 (fd, buf, count, offset);
+# endif
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
/* First try the syscall. */
result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
__LONG_LONG_PAIR ((off_t) (offset >> 32),
@@ -57,6 +81,9 @@
/* No system call available. Use the emulation. */
result = __emulate_pread64 (fd, buf, count, offset);
# endif
+
+ LIBC_CANCEL_RESET (oldtype);
+
return result;
}
Index: sysdeps/unix/sysv/linux/mips/pwrite.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/pwrite.c,v
retrieving revision 1.8
diff -u -u -r1.8 pwrite.c
--- sysdeps/unix/sysv/linux/mips/pwrite.c 17 Jul 2002 20:42:56 -0000 1.8
+++ sysdeps/unix/sysv/linux/mips/pwrite.c 25 Jan 2003 15:48:49 -0000
@@ -22,12 +22,19 @@
#include <unistd.h>
#include <endian.h>
-#include <sysdep.h>
+#include <sysdep-cancel.h>
#include <sys/syscall.h>
#include <bp-checks.h>
#include <kernel-features.h>
+#ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pwrite
+# error "__NR_pwrite and __NR_pwrite64 both defined???"
+# endif
+# define __NR_pwrite __NR_pwrite64
+#endif
+
#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
extern ssize_t __syscall_pwrite (int fd, const void *__unbounded buf, size_t count,
@@ -47,15 +54,34 @@
{
ssize_t result;
+ if (SINGLE_THREAD_P)
+ {
+ /* First try the syscall. */
+ assert (sizeof (offset) == 4);
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR (offset >> 31, offset));
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
/* First try the syscall. */
assert (sizeof (offset) == 4);
result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
- __LONG_LONG_PAIR (offset >> 31, offset));
+ __LONG_LONG_PAIR (offset >> 31, offset));
# if __ASSUME_PWRITE_SYSCALL == 0
if (result == -1 && errno == ENOSYS)
/* No system call available. Use the emulation. */
result = __emulate_pwrite (fd, buf, count, offset);
# endif
+
+ LIBC_CANCEL_RESET (oldtype);
return result;
}
Index: sysdeps/unix/sysv/linux/mips/pwrite64.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/pwrite64.c,v
retrieving revision 1.9
diff -u -u -r1.9 pwrite64.c
--- sysdeps/unix/sysv/linux/mips/pwrite64.c 3 Aug 2002 06:57:51 -0000 1.9
+++ sysdeps/unix/sysv/linux/mips/pwrite64.c 25 Jan 2003 15:48:49 -0000
@@ -21,12 +21,19 @@
#include <unistd.h>
#include <endian.h>
-#include <sysdep.h>
+#include <sysdep-cancel.h>
#include <sys/syscall.h>
#include <bp-checks.h>
#include <kernel-features.h>
+#ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
+# ifdef __NR_pwrite
+# error "__NR_pwrite and __NR_pwrite64 both defined???"
+# endif
+# define __NR_pwrite __NR_pwrite64
+#endif
+
#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
extern ssize_t __syscall_pwrite (int fd, const void *__unbounded buf, size_t count,
@@ -46,6 +53,23 @@
{
ssize_t result;
+ if (SINGLE_THREAD_P)
+ {
+ /* First try the syscall. */
+ result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
+ __LONG_LONG_PAIR ((off_t) (offset >> 32),
+ (off_t) (offset & 0xffffffff)));
+# if __ASSUME_PWRITE_SYSCALL == 0
+ if (result == -1 && errno == ENOSYS)
+ /* No system call available. Use the emulation. */
+ result = __emulate_pwrite64 (fd, buf, count, offset);
+# endif
+
+ return result;
+ }
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
/* First try the syscall. */
result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
__LONG_LONG_PAIR ((off_t) (offset >> 32),
@@ -55,6 +79,8 @@
/* No system call available. Use the emulation. */
result = __emulate_pwrite64 (fd, buf, count, offset);
# endif
+
+ LIBC_CANCEL_RESET (oldtype);
return result;
}
Index: sysdeps/unix/sysv/linux/mips/sysdep.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/sysdep.h,v
retrieving revision 1.3
diff -u -u -r1.3 sysdep.h
--- sysdeps/unix/sysv/linux/mips/sysdep.h 15 Jan 2003 01:02:03 -0000 1.3
+++ sysdeps/unix/sysv/linux/mips/sysdep.h 25 Jan 2003 15:48:49 -0000
@@ -33,7 +33,15 @@
# define SYS_ify(syscall_name) __NR_/**/syscall_name
#endif
-#ifndef __ASSEMBLER__
+#ifdef __ASSEMBLER__
+
+/* We don't want the label for the error handler to be visible in the symbol
+ table when we define it here. */
+#ifdef __PIC__
+# define SYSCALL_ERROR_LABEL 99b
+#endif
+
+#else /* ! __ASSEMBLER__ */
/* Define a macro which expands into the inline wrapper code for a system
call. */
--- /dev/null Sat Mar 16 18:32:44 2002
+++ linuxthreads/sysdeps/unix/sysv/linux/mips/Makefile Thu Jan 9 16:12:16 2003
@@ -0,0 +1,2 @@
+# pull in __syscall_error routine
+libpthread-routines += sysdep
--- /dev/null Sat Mar 16 18:32:44 2002
+++ linuxthreads/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h Fri Jan 24 19:54:46 2003
@@ -0,0 +1,145 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Guido Guenther <agx@sigxcpu.org>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#ifndef __ASSEMBLER__
+# include <linuxthreads/internals.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread
+
+#ifdef __PIC__
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .align 2; \
+ 99: la t9,__syscall_error; \
+ jr t9; \
+ ENTRY (name) \
+ .set noreorder; \
+ .cpload t9; \
+ .set reorder; \
+ SINGLE_THREAD_P(t0); \
+ bne zero, t0, Lpseudo_cancel; \
+ .set noreorder; \
+ li v0, SYS_ify(syscall_name); \
+ syscall; \
+ .set reorder; \
+ bne a3, zero, SYSCALL_ERROR_LABEL; \
+ ret; \
+ Lpseudo_cancel: \
+ SAVESTK_##args; \
+ sw ra, 28(sp); \
+ sw gp, 32(sp); \
+ PUSHARGS_##args; /* save syscall args */ \
+ CENABLE; \
+ lw gp, 32(sp); \
+ sw v0, 44(sp); /* save mask */ \
+ POPARGS_##args; /* restore syscall args */ \
+ .set noreorder; \
+ li v0, SYS_ify (syscall_name); \
+ syscall; \
+ .set reorder; \
+ sw v0, 36(sp); /* save syscall result */ \
+ sw a3, 40(sp); /* save syscall error flag */ \
+ lw a0, 44(sp); /* pass mask as arg1 */ \
+ CDISABLE; \
+ lw gp, 32(sp); \
+ lw v0, 36(sp); /* restore syscall result */ \
+ lw a3, 40(sp); /* restore syscall error flag */ \
+ lw ra, 28(sp); /* restore return address */ \
+ RESTORESTK; \
+ bne a3, zero, SYSCALL_ERROR_LABEL; \
+ Lpseudo_end:
+#endif
+
+# define PUSHARGS_0 /* nothing to do */
+# define PUSHARGS_1 PUSHARGS_0 sw a0, 0(sp);
+# define PUSHARGS_2 PUSHARGS_1 sw a1, 4(sp);
+# define PUSHARGS_3 PUSHARGS_2 sw a2, 8(sp);
+# define PUSHARGS_4 PUSHARGS_3 sw a3, 12(sp);
+# define PUSHARGS_5 PUSHARGS_4 /* handeld by SAVESTK_## */
+# define PUSHARGS_6 PUSHARGS_5
+# define PUSHARGS_7 PUSHARGS_6
+
+# define POPARGS_0 /* nothing to do */
+# define POPARGS_1 POPARGS_0 lw a0, 0(sp);
+# define POPARGS_2 POPARGS_1 lw a1, 4(sp);
+# define POPARGS_3 POPARGS_2 lw a2, 8(sp);
+# define POPARGS_4 POPARGS_3 lw a3, 12(sp);
+# define POPARGS_5 POPARGS_4 /* args already in new stackframe */
+# define POPARGS_6 POPARGS_5
+# define POPARGS_7 POPARGS_6
+
+
+# define STKSPACE 48
+# define SAVESTK_0 subu sp, STKSPACE
+# define SAVESTK_1 SAVESTK_0
+# define SAVESTK_2 SAVESTK_1
+# define SAVESTK_3 SAVESTK_2
+# define SAVESTK_4 SAVESTK_3
+# define SAVESTK_5 lw t0, 16(sp); \
+ subu sp, STKSPACE; \
+ sw t0, 16(sp)
+
+# define SAVESTK_6 lw t0, 16(sp); \
+ lw t1, 20(sp); \
+ subu sp, STKSPACE; \
+ sw t0, 16(sp); \
+ sw t1, 20(sp)
+
+# define SAVESTK_7 lw t0, 16(sp); \
+ lw t1, 20(sp); \
+ lw t2, 24(sp); \
+ subu sp, STKSPACE; \
+ sw t0, 16(sp); \
+ sw t1, 20(sp); \
+ sw t2, 24(sp)
+
+# define RESTORESTK addu sp, STKSPACE
+
+
+# ifdef IS_IN_libpthread
+# define CENABLE la t9, __pthread_enable_asynccancel; jalr t9;
+# define CDISABLE la t9, __pthread_disable_asynccancel; jalr t9;
+# define __local_multiple_threads __pthread_multiple_threads
+# else
+# define CENABLE la t9, __libc_enable_asynccancel; jalr t9;
+# define CDISABLE la t9, __libc_disable_asynccancel; jalr t9;
+# define __local_multiple_threads __libc_multiple_threads
+# endif
+
+# if !defined NOT_IN_libc
+# define __local_multiple_threads __libc_multiple_threads
+# else
+# define __local_multiple_threads __pthread_multiple_threads
+# endif
+
+# ifndef __ASSEMBLER__
+extern int __local_multiple_threads attribute_hidden;
+# define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
+# else
+# define SINGLE_THREAD_P(reg) lw reg, __local_multiple_threads
+#endif
+
+#elif !defined __ASSEMBLER__
+
+/* This code should never be used but we define it anyhow. */
+# define SINGLE_THREAD_P (1)
+
+#endif
More information about the Libc-alpha
mailing list