|
From: <sv...@va...> - 2005-09-19 07:57:24
|
Author: tom
Date: 2005-09-19 08:57:20 +0100 (Mon, 19 Sep 2005)
New Revision: 4679
Log:
Make the mremap2 test a bit more portable so it builds on amd64.
Modified:
branches/ASPACEM/none/tests/mremap2.c
Modified: branches/ASPACEM/none/tests/mremap2.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/none/tests/mremap2.c 2005-09-19 00:53:52 UTC (rev 46=
78)
+++ branches/ASPACEM/none/tests/mremap2.c 2005-09-19 07:57:20 UTC (rev 46=
79)
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
=20
#include <stdio.h>
#include <sys/mman.h>
@@ -5,17 +6,17 @@
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
+#include <errno.h>
+#include <syscall.h>
=20
=20
-/* x86 linux specifics */
-#define __NR_mremap 163
-#define VKI_MREMAP_MAYMOVE 1
-#define VKI_MREMAP_FIXED 2
+#ifndef REMAP_FIXED
+#define MREMAP_FIXED 2
+#endif
=20
=20
+static int PAGE;
=20
-#define PAGE 4096
-
void mapanon_fixed ( void* start, size_t length )
{
void* r =3D mmap(start, length, PROT_NONE,=20
@@ -82,40 +83,6 @@
}
=20
=20
-int is_kerror(int r)=20
-{
- return r >=3D -4096 && r <=3D -1;
-}
-
-typedef unsigned int UWord;
-extern UWord do_syscall_WRK (
- UWord syscall_no,
- UWord a1, UWord a2, UWord a3,
- UWord a4, UWord a5, UWord a6
- );
-asm(
-"do_syscall_WRK:\n"
-" push %esi\n"
-" push %edi\n"
-" push %ebx\n"
-" push %ebp\n"
-" movl 16+ 4(%esp),%eax\n"
-" movl 16+ 8(%esp),%ebx\n"
-" movl 16+12(%esp),%ecx\n"
-" movl 16+16(%esp),%edx\n"
-" movl 16+20(%esp),%esi\n"
-" movl 16+24(%esp),%edi\n"
-" movl 16+28(%esp),%ebp\n"
-" int $0x80\n"
-" popl %ebp\n"
-" popl %ebx\n"
-" popl %edi\n"
-" popl %esi\n"
-" ret\n"
-);
-
-
-
char* dst =3D NULL;
char* src =3D NULL;
char* dst_impossible =3D NULL;
@@ -141,6 +108,8 @@
int firsttime =3D 1;
char buf[100];
=20
+ PAGE =3D sysconf(_SC_PAGESIZE);
+
for (maymove =3D 0; maymove <=3D 1 ; maymove++) {
for (fixed =3D 0; fixed <=3D 1; fixed++) {
printf("\n");
@@ -148,8 +117,8 @@
for (dstpossible =3D 0; dstpossible <=3D 1; dstpossible++) {
=20
int newsize =3D newsizes[nsi] * PAGE;
- int flags =3D (maymove ? VKI_MREMAP_MAYMOVE : 0) |
- (fixed ? VKI_MREMAP_FIXED : 0);
+ int flags =3D (maymove ? MREMAP_MAYMOVE : 0) |
+ (fixed ? MREMAP_FIXED : 0);
dst =3D dstpossible ? try_dst : dst_impossible;
src =3D setup( tidythis, tidylen );
=20
@@ -165,22 +134,21 @@
firsttime =3D 0;
}
=20
- printf("maymv %d fixed %d newsz %2d dstpo %d dst 0x%08x -> "=
,
- maymove, fixed, newsizes[nsi], dstpossible, (UWord)dst );
+ printf("maymv %d fixed %d newsz %2d dstpo %d dst %p -> ",
+ maymove, fixed, newsizes[nsi], dstpossible, dst );
r =3D (char*)
- do_syscall_WRK(__NR_mremap, (UWord)src,=20
- 20*PAGE, newsize, flags, (UWord)dst, 0 );
- if (is_kerror((int)r))
- printf("error %d\n", -(int)r);
+ syscall(__NR_mremap, src, 20*PAGE, newsize, flags, dst, 0 );
+ if (r =3D=3D MAP_FAILED)
+ printf("error %d\n", errno);
else
- printf("0x%08x (=3D=3D %s)\n", (int)r, identify(r));
+ printf("%p (=3D=3D %s)\n", r, identify(r));
=20
if (1) {
show();
printf("\n");
}
=20
- if (!is_kerror((int)r)) {
+ if (r !=3D MAP_FAILED) {
if (r !=3D src && r !=3D try_dst && r !=3D dst_impossible) {
tidythis =3D r;
tidylen =3D newsize;
|