2005-05-27 01:10:39

by Blaisorblade

[permalink] [raw]
Subject: [patch 4/4] uml: make it link in tt mode against NPTL glibc


To make sure switcheroo() can execute when we remap all the executable image,
we used a trick to make it use a local copy of errno... this trick does not
work with NPTL glibc, only with LinuxThreads, so use another (simpler) one to
make it work anyway.

Might need compile testing on different host archs, since it changes
__syscall_return from <asm/unistd.h>.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <[email protected]>
---

linux-2.6.git-paolo/arch/um/kernel/tt/unmap.c | 25 +++++++++++++------------
linux-2.6.git-paolo/arch/um/kernel/uml.lds.S | 12 +-----------
2 files changed, 14 insertions(+), 23 deletions(-)

diff -puN arch/um/kernel/tt/unmap.c~uml-link-tt-mode-against-nptl arch/um/kernel/tt/unmap.c
--- linux-2.6.git/arch/um/kernel/tt/unmap.c~uml-link-tt-mode-against-nptl 2005-05-25 01:22:23.000000000 +0200
+++ linux-2.6.git-paolo/arch/um/kernel/tt/unmap.c 2005-05-25 01:22:23.000000000 +0200
@@ -1,16 +1,28 @@
/*
* Copyright (C) 2000 Jeff Dike ([email protected])
+ * Copyright (C) 2005 Paolo 'Blaisorblade' Giarrusso ([email protected])
* Licensed under the GPL
*/

#include <sys/mman.h>
+#include <linux/unistd.h>
+
+/* We can't rely on errno here! */
+#undef __syscall_return
+#define __syscall_return(type, res) \
+do { \
+ return (type) (res); \
+} while (0)
+
+static inline _syscall6(void *, mmap2, void *, start, size_t, length, int, prot, int, flags, int, fd, off_t, pgoffset)
+inline _syscall2(int, munmap, void *, start, size_t, length)

int switcheroo(int fd, int prot, void *from, void *to, int size)
{
if(munmap(to, size) < 0){
return(-1);
}
- if(mmap(to, size, prot, MAP_SHARED | MAP_FIXED, fd, 0) != to){
+ if(mmap2(to, size, prot, MAP_SHARED | MAP_FIXED, fd, 0) != to){
return(-1);
}
if(munmap(from, size) < 0){
@@ -18,14 +30,3 @@ int switcheroo(int fd, int prot, void *f
}
return(0);
}
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only. This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
diff -puN arch/um/kernel/uml.lds.S~uml-link-tt-mode-against-nptl arch/um/kernel/uml.lds.S
--- linux-2.6.git/arch/um/kernel/uml.lds.S~uml-link-tt-mode-against-nptl 2005-05-25 01:22:23.000000000 +0200
+++ linux-2.6.git-paolo/arch/um/kernel/uml.lds.S 2005-05-25 01:22:23.000000000 +0200
@@ -15,19 +15,9 @@ SECTIONS
* is remapped.*/
__binary_start = .;
#ifdef MODE_TT
- .thread_private : {
- __start_thread_private = .;
- errno = .;
- . += 4;
- arch/um/kernel/tt/unmap_fin.o (.data)
- __end_thread_private = .;
- }
- . = ALIGN(4096);
+ .remap_data: { arch/um/kernel/tt/unmap_fin.o (.data) }
.remap : { arch/um/kernel/tt/unmap_fin.o (.text) }

- /* We want it only if we are in MODE_TT. In both cases, however, when MODE_TT
- * is off the resulting binary segfaults.*/
-
. = ALIGN(4096); /* Init code and data */
#endif

_


2005-05-27 04:20:16

by Al Viro

[permalink] [raw]
Subject: Re: [patch 4/4] uml: make it link in tt mode against NPTL glibc

On Fri, May 27, 2005 at 02:40:24AM +0200, [email protected] wrote:
>
> To make sure switcheroo() can execute when we remap all the executable image,
> we used a trick to make it use a local copy of errno... this trick does not
> work with NPTL glibc, only with LinuxThreads, so use another (simpler) one to
> make it work anyway.
>
> Might need compile testing on different host archs, since it changes
> __syscall_return from <asm/unistd.h>.

For one thing, it's broken since mmap2() doesn't exist on amd64. This stuff
*is* low-level - as low-level as it gets. It's clearly per-architecture.
See ftp.linux.org.uk/pub/people/viro/UM14-unmap-RC12-rc4 for a fix...

2005-05-28 11:36:19

by Blaisorblade

[permalink] [raw]
Subject: Re: [uml-devel] Re: [patch 4/4] uml: make it link in tt mode against NPTL glibc

On Friday 27 May 2005 06:20, Al Viro wrote:
> On Fri, May 27, 2005 at 02:40:24AM +0200, [email protected] wrote:
> > To make sure switcheroo() can execute when we remap all the executable
> > image, we used a trick to make it use a local copy of errno... this trick
> > does not work with NPTL glibc, only with LinuxThreads, so use another
> > (simpler) one to make it work anyway.
> >
> > Might need compile testing on different host archs, since it changes
> > __syscall_return from <asm/unistd.h>.
>
> For one thing, it's broken since mmap2() doesn't exist on amd64. This
> stuff *is* low-level - as low-level as it gets.
> It's clearly
> per-architecture.
Yes, agreed.
> See ftp.linux.org.uk/pub/people/viro/UM14-unmap-RC12-rc4
> for a fix...
Seems reasonable except that on i386 you keep the old linker script, indeed; I
think that the linker script shouldn't be per architecture.

Also (not verified) one section is either read-write or read-only, so
merging .bss and .text does not seem good to me (I separated them on
purpose).

Good catch for using .bss instead of .data.
--
Paolo Giarrusso, aka Blaisorblade
Skype user "PaoloGiarrusso"
Linux registered user n. 292729
http://www.user-mode-linux.org/~blaisorblade





___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it