|
From: <sv...@va...> - 2005-08-09 18:00:08
|
Author: sewardj
Date: 2005-08-09 18:59:26 +0100 (Tue, 09 Aug 2005)
New Revision: 4354
Log:
Get rid of most of the glibc dependencies from m_ume.c. Not there
yet, but moving in the right direction.
Modified:
branches/ASPACEM/coregrind/m_libcfile.c
branches/ASPACEM/coregrind/m_libcproc.c
branches/ASPACEM/coregrind/m_main.c
branches/ASPACEM/coregrind/m_ume.c
branches/ASPACEM/coregrind/pub_core_libcfile.h
branches/ASPACEM/coregrind/pub_core_ume.h
branches/ASPACEM/include/pub_tool_libcfile.h
branches/ASPACEM/include/pub_tool_libcproc.h
Modified: branches/ASPACEM/coregrind/m_libcfile.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/coregrind/m_libcfile.c 2005-08-09 12:30:07 UTC (rev =
4353)
+++ branches/ASPACEM/coregrind/m_libcfile.c 2005-08-09 17:59:26 UTC (rev =
4354)
@@ -113,10 +113,12 @@
return res.isError ? -1 : 0;
}
=20
-OffT VG_(lseek) ( Int fd, OffT offset, Int whence)
+OffT VG_(lseek) ( Int fd, OffT offset, Int whence )
{
SysRes res =3D VG_(do_syscall3)(__NR_lseek, fd, offset, whence);
return res.isError ? (-1) : 0;
+ /* if you change the error-reporting conventions of this, also
+ change VG_(pread) and all other usage points. */
}
=20
SysRes VG_(stat) ( Char* file_name, struct vki_stat* buf )
@@ -201,6 +203,14 @@
#endif
}
=20
+SSizeT VG_(pread) ( Int fd, void* buf, Int count, Int offset )
+{
+ OffT off =3D VG_(lseek)( fd, (OffT)offset, VKI_SEEK_SET);
+ if (off !=3D 0)
+ return (SSizeT)(-1);
+ SysRes res =3D VG_(do_syscall3)(__NR_read, fd, (UWord)buf, count );
+ return (SSizeT)( res.isError ? -1 : res.val);
+}
=20
/* ---------------------------------------------------------------------
Socket-related stuff. This is very Linux-kernel specific.
Modified: branches/ASPACEM/coregrind/m_libcproc.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/coregrind/m_libcproc.c 2005-08-09 12:30:07 UTC (rev =
4353)
+++ branches/ASPACEM/coregrind/m_libcproc.c 2005-08-09 17:59:26 UTC (rev =
4354)
@@ -388,12 +388,19 @@
return VG_(do_syscall0)(__NR_getppid) . val;
}
=20
-Int VG_(setpgid) ( Int pid, Int pgrp )
+Int VG_(geteuid) ( void )
{
/* ASSUMES SYSCALL ALWAYS SUCCEEDS */
- return VG_(do_syscall2)(__NR_setpgid, pid, pgrp) . val;
+ return VG_(do_syscall0)(__NR_geteuid) . val;
}
=20
+Int VG_(getegid) ( void )
+{
+ /* ASSUMES SYSCALL ALWAYS SUCCEEDS */
+ return VG_(do_syscall0)(__NR_getegid) . val;
+}
+
+
/* ---------------------------------------------------------------------
Timing stuff
------------------------------------------------------------------ */
Modified: branches/ASPACEM/coregrind/m_main.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/coregrind/m_main.c 2005-08-09 12:30:07 UTC (rev 4353=
)
+++ branches/ASPACEM/coregrind/m_main.c 2005-08-09 17:59:26 UTC (rev 4354=
)
@@ -124,17 +124,17 @@
// HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK A
// temporary bootstrapping allocator, for use until such time as we
// can get rid of the circularites in allocator dependencies at
-// startup.
+// startup. There is also a copy of this in m_ume.c.
#define N_HACK_BYTES 10000
static Int hack_bytes_used =3D 0;
static HChar hack_bytes[N_HACK_BYTES];
=20
static void* hack_malloc ( Int n )
{
- VG_(debugLog)(1, "main", " FIXME: hack_malloc(%d)\n", n);
+ VG_(debugLog)(1, "main", " FIXME: hack_malloc(m_main)(%d)\n", n);
while (n % 16) n++;
if (hack_bytes_used + n > N_HACK_BYTES) {
- VG_(printf)("valgrind: N_HACK_BYTES too low. Sorry.\n");
+ VG_(printf)("valgrind: N_HACK_BYTES(m_main) too low. Sorry.\n");
VG_(exit)(0);
}
hack_bytes_used +=3D n;
Modified: branches/ASPACEM/coregrind/m_ume.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/coregrind/m_ume.c 2005-08-09 12:30:07 UTC (rev 4353)
+++ branches/ASPACEM/coregrind/m_ume.c 2005-08-09 17:59:26 UTC (rev 4354)
@@ -38,19 +38,59 @@
// included ahead of the glibc ones. This fix is a kludge; the right
// solution is to entirely remove the glibc dependency.
#include "pub_core_basics.h"
+#include "pub_core_debuglog.h"
#include "pub_core_libcbase.h"
#include "pub_core_machine.h"
+#include "pub_core_libcprint.h"
+#include "pub_core_libcfile.h" // VG_(close) et al
+#include "pub_core_libcproc.h" // VG_(geteuid), VG_(getegid)
+#include "pub_core_libcassert.h" // VG_(exit), vg_assert
+#include "pub_core_syscall.h" // VG_(strerror)
+#include "pub_core_mallocfree.h" // VG_(malloc), VG_(free)
+
+#include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr.h :(
+#include "pub_core_aspacemgr.h" // VG_(mmap_native)
+#include "vki_unistd.h" // mmap-related constants
+
#include "pub_core_ume.h"
=20
-#include <sys/mman.h>
+//#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <assert.h>
=20
+//#include <string.h>
+//#include <stdlib.h>
+//#include <unistd.h>
+//#include <assert.h>
+
+
+// HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK A
+// temporary bootstrapping allocator, for use until such time as we
+// can get rid of the circularites in allocator dependencies at
+// startup. There is also a copy of this in m_main.c.
+#define N_HACK_BYTES 10000
+static Int hack_bytes_used =3D 0;
+static HChar hack_bytes[N_HACK_BYTES];
+
+static void* hack_malloc ( Int n )
+{
+ VG_(debugLog)(1, "ume", " FIXME: hack_malloc(m_ume)(%d)\n", n);
+ while (n % 16) n++;
+ if (hack_bytes_used + n > N_HACK_BYTES) {
+ VG_(printf)("valgrind: N_HACK_BYTES(m_ume) too low. Sorry.\n");
+ VG_(exit)(0);
+ }
+ hack_bytes_used +=3D n;
+ return (void*) &hack_bytes[hack_bytes_used - n];
+}
+
+static HChar* hack_strdup ( HChar* str )
+{
+ HChar* p =3D hack_malloc( 1 + VG_(strlen)(str) );
+ VG_(strcpy)(p, str);
+ return p;
+}
+
#if VG_WORDSIZE =3D=3D 8
#define ESZ(x) Elf64_##x
#elif VG_WORDSIZE =3D=3D 4
@@ -66,174 +106,174 @@
int fd;
};
=20
-static void check_mmap(void* res, void* base, int len)
+static void check_mmap(SysRes res, void* base, int len)
{
- if ((void*)-1 =3D=3D res) {
- fprintf(stderr, "valgrind: mmap(%p, %d) failed in UME.\n", base, l=
en);
- exit(1);
+ if (res.isError) {
+ VG_(printf)("valgrind: mmap(%p, %d) failed in UME.\n", base, len);
+ VG_(exit)(1);
}
}
=20
-// 'extra' allows the caller to pass in extra args to 'fn', like free
-// variables to a closure.
-void VG_(foreach_map)(int (*fn)(char *start, char *end,
- const char *perm, off_t offset,
- int maj, int min, int ino, void* extra),
- void* extra)
-{
- static char buf[10240];
- char *bufptr =3D buf;
- int ret, fd;
+//zz // 'extra' allows the caller to pass in extra args to 'fn', like fr=
ee
+//zz // variables to a closure.
+//zz void VG_(foreach_map)(int (*fn)(char *start, char *end,
+//zz const char *perm, off_t offset,
+//zz int maj, int min, int ino, void* ex=
tra),
+//zz void* extra)
+//zz {
+//zz static char buf[10240];
+//zz char *bufptr =3D buf;
+//zz int ret, fd;
+//zz=20
+//zz fd =3D open("/proc/self/maps", O_RDONLY);
+//zz=20
+//zz if (fd =3D=3D -1) {
+//zz perror("open /proc/self/maps");
+//zz return;
+//zz }
+//zz=20
+//zz ret =3D read(fd, buf, sizeof(buf));
+//zz=20
+//zz if (ret =3D=3D -1) {
+//zz perror("read /proc/self/maps");
+//zz close(fd);
+//zz return;
+//zz }
+//zz close(fd);
+//zz=20
+//zz if (ret =3D=3D sizeof(buf)) {
+//zz VG_(printf)("coregrind/m_ume.c: buf too small\n");
+//zz return;
+//zz }
+//zz=20
+//zz while(bufptr && bufptr < buf+ret) {
+//zz char perm[5];
+//zz ULong offset;
+//zz int maj, min;
+//zz int ino;
+//zz void *segstart, *segend;
+//zz=20
+//zz sscanf(bufptr, "%p-%p %s %llx %x:%x %d",
+//zz &segstart, &segend, perm, &offset, &maj, &min, &ino);
+//zz bufptr =3D strchr(bufptr, '\n');
+//zz if (bufptr !=3D NULL)
+//zz bufptr++; /* skip \n */
+//zz=20
+//zz if (!(*fn)(segstart, segend, perm, offset, maj, min, ino, ext=
ra))
+//zz break;
+//zz }
+//zz }
+//zz=20
+//zz /*------------------------------------------------------------*/
+//zz /*--- Stack switching ---*/
+//zz /*------------------------------------------------------------*/
+//zz=20
+//zz // __attribute__((noreturn))
+//zz // void VG_(jump_and_switch_stacks) ( Addr stack, Addr dst );
+//zz #if defined(VGA_x86)
+//zz // 4(%esp) =3D=3D stack
+//zz // 8(%esp) =3D=3D dst
+//zz asm(
+//zz ".global vgPlain_jump_and_switch_stacks\n"
+//zz "vgPlain_jump_and_switch_stacks:\n"
+//zz " movl %esp, %esi\n" // remember old stack pointer
+//zz " movl 4(%esi), %esp\n" // set stack
+//zz " pushl 8(%esi)\n" // dst to stack
+//zz " movl $0, %eax\n" // zero all GP regs
+//zz " movl $0, %ebx\n"
+//zz " movl $0, %ecx\n"
+//zz " movl $0, %edx\n"
+//zz " movl $0, %esi\n"
+//zz " movl $0, %edi\n"
+//zz " movl $0, %ebp\n"
+//zz " ret\n" // jump to dst
+//zz " ud2\n" // should never get here
+//zz );
+//zz #elif defined(VGA_amd64)
+//zz // %rdi =3D=3D stack
+//zz // %rsi =3D=3D dst
+//zz asm(
+//zz ".global vgPlain_jump_and_switch_stacks\n"
+//zz "vgPlain_jump_and_switch_stacks:\n"
+//zz " movq %rdi, %rsp\n" // set stack
+//zz " pushq %rsi\n" // dst to stack
+//zz " movq $0, %rax\n" // zero all GP regs
+//zz " movq $0, %rbx\n"
+//zz " movq $0, %rcx\n"
+//zz " movq $0, %rdx\n"
+//zz " movq $0, %rsi\n"
+//zz " movq $0, %rdi\n"
+//zz " movq $0, %rbp\n"
+//zz " movq $0, %r8\n"
+//zz " movq $0, %r9\n"
+//zz " movq $0, %r10\n"
+//zz " movq $0, %r11\n"
+//zz " movq $0, %r12\n"
+//zz " movq $0, %r13\n"
+//zz " movq $0, %r14\n"
+//zz " movq $0, %r15\n"
+//zz " ret\n" // jump to dst
+//zz " ud2\n" // should never get here
+//zz );
+//zz=20
+//zz #elif defined(VGA_ppc32)
+//zz /* Jump to 'dst', but first set the stack pointer to 'stack'. Also=
,
+//zz clear all the integer registers before entering 'dst'. It's
+//zz important that the stack pointer is set to exactly 'stack' and n=
ot
+//zz (eg) stack - apparently_harmless_looking_small_offset. Basicall=
y
+//zz because the code at 'dst' might be wanting to scan the area abov=
e
+//zz 'stack' (viz, the auxv array), and putting spurious words on the
+//zz stack confuses it.
+//zz */
+//zz // %r3 =3D=3D stack
+//zz // %r4 =3D=3D dst
+//zz asm(
+//zz ".global vgPlain_jump_and_switch_stacks\n"
+//zz "vgPlain_jump_and_switch_stacks:\n"
+//zz " mtctr %r4\n\t" // dst to %ctr
+//zz " mr %r1,%r3\n\t" // stack to %sp
+//zz " li 0,0\n\t" // zero all GP regs
+//zz " li 3,0\n\t"
+//zz " li 4,0\n\t"
+//zz " li 5,0\n\t"
+//zz " li 6,0\n\t"
+//zz " li 7,0\n\t"
+//zz " li 8,0\n\t"
+//zz " li 9,0\n\t"
+//zz " li 10,0\n\t"
+//zz " li 11,0\n\t"
+//zz " li 12,0\n\t"
+//zz " li 13,0\n\t" // CAB: This right? r13 =3D small data a=
rea ptr
+//zz " li 14,0\n\t"
+//zz " li 15,0\n\t"
+//zz " li 16,0\n\t"
+//zz " li 17,0\n\t"
+//zz " li 18,0\n\t"
+//zz " li 19,0\n\t"
+//zz " li 20,0\n\t"
+//zz " li 21,0\n\t"
+//zz " li 22,0\n\t"
+//zz " li 23,0\n\t"
+//zz " li 24,0\n\t"
+//zz " li 25,0\n\t"
+//zz " li 26,0\n\t"
+//zz " li 27,0\n\t"
+//zz " li 28,0\n\t"
+//zz " li 29,0\n\t"
+//zz " li 30,0\n\t"
+//zz " li 31,0\n\t"
+//zz " mtxer 0\n\t"
+//zz " mtcr 0\n\t"
+//zz " mtlr %r0\n\t"
+//zz " bctr\n\t" // jump to dst
+//zz " trap\n" // should never get here
+//zz );
+//zz=20
+//zz #else
+//zz # error Unknown architecture
+//zz #endif
=20
- fd =3D open("/proc/self/maps", O_RDONLY);
-
- if (fd =3D=3D -1) {
- perror("open /proc/self/maps");
- return;
- }
-
- ret =3D read(fd, buf, sizeof(buf));
-
- if (ret =3D=3D -1) {
- perror("read /proc/self/maps");
- close(fd);
- return;
- }
- close(fd);
-
- if (ret =3D=3D sizeof(buf)) {
- fprintf(stderr, "buf too small\n");
- return;
- }
-
- while(bufptr && bufptr < buf+ret) {
- char perm[5];
- ULong offset;
- int maj, min;
- int ino;
- void *segstart, *segend;
-
- sscanf(bufptr, "%p-%p %s %llx %x:%x %d",
- &segstart, &segend, perm, &offset, &maj, &min, &ino);
- bufptr =3D strchr(bufptr, '\n');
- if (bufptr !=3D NULL)
- bufptr++; /* skip \n */
-
- if (!(*fn)(segstart, segend, perm, offset, maj, min, ino, extra))
- break;
- }
-}
-
/*------------------------------------------------------------*/
-/*--- Stack switching ---*/
-/*------------------------------------------------------------*/
-
-// __attribute__((noreturn))
-// void VG_(jump_and_switch_stacks) ( Addr stack, Addr dst );
-#if defined(VGA_x86)
-// 4(%esp) =3D=3D stack
-// 8(%esp) =3D=3D dst
-asm(
-".global vgPlain_jump_and_switch_stacks\n"
-"vgPlain_jump_and_switch_stacks:\n"
-" movl %esp, %esi\n" // remember old stack pointer
-" movl 4(%esi), %esp\n" // set stack
-" pushl 8(%esi)\n" // dst to stack
-" movl $0, %eax\n" // zero all GP regs
-" movl $0, %ebx\n"
-" movl $0, %ecx\n"
-" movl $0, %edx\n"
-" movl $0, %esi\n"
-" movl $0, %edi\n"
-" movl $0, %ebp\n"
-" ret\n" // jump to dst
-" ud2\n" // should never get here
-);
-#elif defined(VGA_amd64)
-// %rdi =3D=3D stack
-// %rsi =3D=3D dst
-asm(
-".global vgPlain_jump_and_switch_stacks\n"
-"vgPlain_jump_and_switch_stacks:\n"
-" movq %rdi, %rsp\n" // set stack
-" pushq %rsi\n" // dst to stack
-" movq $0, %rax\n" // zero all GP regs
-" movq $0, %rbx\n"
-" movq $0, %rcx\n"
-" movq $0, %rdx\n"
-" movq $0, %rsi\n"
-" movq $0, %rdi\n"
-" movq $0, %rbp\n"
-" movq $0, %r8\n"\
-" movq $0, %r9\n"\
-" movq $0, %r10\n"
-" movq $0, %r11\n"
-" movq $0, %r12\n"
-" movq $0, %r13\n"
-" movq $0, %r14\n"
-" movq $0, %r15\n"
-" ret\n" // jump to dst
-" ud2\n" // should never get here
-);
-
-#elif defined(VGA_ppc32)
-/* Jump to 'dst', but first set the stack pointer to 'stack'. Also,
- clear all the integer registers before entering 'dst'. It's
- important that the stack pointer is set to exactly 'stack' and not
- (eg) stack - apparently_harmless_looking_small_offset. Basically
- because the code at 'dst' might be wanting to scan the area above
- 'stack' (viz, the auxv array), and putting spurious words on the
- stack confuses it.
-*/
-// %r3 =3D=3D stack
-// %r4 =3D=3D dst
-asm(
-".global vgPlain_jump_and_switch_stacks\n"
-"vgPlain_jump_and_switch_stacks:\n"
-" mtctr %r4\n\t" // dst to %ctr
-" mr %r1,%r3\n\t" // stack to %sp
-" li 0,0\n\t" // zero all GP regs
-" li 3,0\n\t"
-" li 4,0\n\t"
-" li 5,0\n\t"
-" li 6,0\n\t"
-" li 7,0\n\t"
-" li 8,0\n\t"
-" li 9,0\n\t"
-" li 10,0\n\t"
-" li 11,0\n\t"
-" li 12,0\n\t"
-" li 13,0\n\t" // CAB: This right? r13 =3D small data area p=
tr
-" li 14,0\n\t"
-" li 15,0\n\t"
-" li 16,0\n\t"
-" li 17,0\n\t"
-" li 18,0\n\t"
-" li 19,0\n\t"
-" li 20,0\n\t"
-" li 21,0\n\t"
-" li 22,0\n\t"
-" li 23,0\n\t"
-" li 24,0\n\t"
-" li 25,0\n\t"
-" li 26,0\n\t"
-" li 27,0\n\t"
-" li 28,0\n\t"
-" li 29,0\n\t"
-" li 30,0\n\t"
-" li 31,0\n\t"
-" mtxer 0\n\t"
-" mtcr 0\n\t"
-" mtlr %r0\n\t"
-" bctr\n\t" // jump to dst
-" trap\n" // should never get here
-);
-
-#else
-# error Unknown architecture
-#endif
-
-/*------------------------------------------------------------*/
/*--- Finding auxv on the stack ---*/
/*------------------------------------------------------------*/
=20
@@ -266,62 +306,62 @@
static=20
struct elfinfo *readelf(int fd, const char *filename)
{
- struct elfinfo *e =3D malloc(sizeof(*e));
+ struct elfinfo *e =3D hack_malloc(sizeof(*e));
int phsz;
=20
- assert(e);
+ vg_assert(e);
e->fd =3D fd;
=20
- if (pread(fd, &e->e, sizeof(e->e), 0) !=3D sizeof(e->e)) {
- fprintf(stderr, "valgrind: %s: can't read ELF header: %s\n",=20
- filename, strerror(errno));
+ if (VG_(pread)(fd, &e->e, sizeof(e->e), 0) !=3D sizeof(e->e)) {
+ VG_(printf)("valgrind: %s: can't read ELF header: %s\n",=20
+ filename, VG_(strerror)(errno));
goto bad;
}
=20
- if (memcmp(&e->e.e_ident[0], ELFMAG, SELFMAG) !=3D 0) {
- fprintf(stderr, "valgrind: %s: bad ELF magic number\n", filename);
+ if (VG_(memcmp)(&e->e.e_ident[0], ELFMAG, SELFMAG) !=3D 0) {
+ VG_(printf)("valgrind: %s: bad ELF magic number\n", filename);
goto bad;
}
if (e->e.e_ident[EI_CLASS] !=3D VG_ELF_CLASS) {
- fprintf(stderr,=20
- "valgrind: wrong ELF executable class "
- "(eg. 32-bit instead of 64-bit)\n");
+ VG_(printf)("valgrind: wrong ELF executable class "
+ "(eg. 32-bit instead of 64-bit)\n");
goto bad;
}
if (e->e.e_ident[EI_DATA] !=3D VG_ELF_DATA2XXX) {
- fprintf(stderr, "valgrind: executable has wrong endian-ness\n");
+ VG_(printf)("valgrind: executable has wrong endian-ness\n");
goto bad;
}
if (!(e->e.e_type =3D=3D ET_EXEC || e->e.e_type =3D=3D ET_DYN)) {
- fprintf(stderr, "valgrind: this is not an executable\n");
+ VG_(printf)("valgrind: this is not an executable\n");
goto bad;
}
=20
if (e->e.e_machine !=3D VG_ELF_MACHINE) {
- fprintf(stderr, "valgrind: executable is not for "
- "this architecture\n");
+ VG_(printf)("valgrind: executable is not for "
+ "this architecture\n");
goto bad;
}
=20
if (e->e.e_phentsize !=3D sizeof(ESZ(Phdr))) {
- fprintf(stderr, "valgrind: sizeof ELF Phdr wrong\n");
+ VG_(printf)("valgrind: sizeof ELF Phdr wrong\n");
goto bad;
}
=20
phsz =3D sizeof(ESZ(Phdr)) * e->e.e_phnum;
- e->p =3D malloc(phsz);
- assert(e->p);
+ e->p =3D hack_malloc(phsz);
+ vg_assert(e->p);
=20
- if (pread(fd, e->p, phsz, e->e.e_phoff) !=3D phsz) {
- fprintf(stderr, "valgrind: can't read phdr: %s\n", strerror(errno)=
);
- free(e->p);
+ if (VG_(pread)(fd, e->p, phsz, e->e.e_phoff) !=3D phsz) {
+ VG_(printf)("valgrind: can't read phdr: %s\n",=20
+ VG_(strerror)(errno));
+ //FIXME VG_(free)(e->p);
goto bad;
}
=20
return e;
=20
bad:
- free(e);
+ //FIXME VG_(free)(e);
return NULL;
}
=20
@@ -329,8 +369,8 @@
static
ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base)
{
- int i;
- void* res;
+ Int i;
+ SysRes res;
ESZ(Addr) elfbrk =3D 0;
=20
for(i =3D 0; i < e->e.e_phnum; i++) {
@@ -360,9 +400,9 @@
if (ph->p_type !=3D PT_LOAD)
continue;
=20
- if (ph->p_flags & PF_X) prot |=3D PROT_EXEC;
- if (ph->p_flags & PF_W) prot |=3D PROT_WRITE;
- if (ph->p_flags & PF_R) prot |=3D PROT_READ;
+ if (ph->p_flags & PF_X) prot |=3D VKI_PROT_EXEC;
+ if (ph->p_flags & PF_W) prot |=3D VKI_PROT_WRITE;
+ if (ph->p_flags & PF_R) prot |=3D VKI_PROT_READ;
=20
addr =3D ph->p_vaddr+base;
off =3D ph->p_offset;
@@ -378,9 +418,12 @@
//
// The condition handles the case of a zero-length segment.
if (VG_PGROUNDUP(bss)-VG_PGROUNDDN(addr) > 0) {
- res =3D mmap((char *)VG_PGROUNDDN(addr),
+ res =3D VG_(mmap_native)
+ ((char *)VG_PGROUNDDN(addr),
VG_PGROUNDUP(bss)-VG_PGROUNDDN(addr),
- prot, MAP_FIXED|MAP_PRIVATE, e->fd, VG_PGROUNDDN(off=
));
+ prot, VKI_MAP_FIXED|VKI_MAP_PRIVATE,=20
+ e->fd, VG_PGROUNDDN(off)
+ );
check_mmap(res, (char*)VG_PGROUNDDN(addr),
VG_PGROUNDUP(bss)-VG_PGROUNDDN(addr));
}
@@ -391,17 +434,20 @@
=20
bytes =3D VG_PGROUNDUP(brkaddr)-VG_PGROUNDUP(bss);
if (bytes > 0) {
- res =3D mmap((char *)VG_PGROUNDUP(bss), bytes,
- prot, MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+ res =3D VG_(mmap_native)(
+ (Char *)VG_PGROUNDUP(bss), bytes,
+ prot, VKI_MAP_FIXED|VKI_MAP_ANONYMOUS|VKI_MAP_PRIVATE,=20
+ -1, 0
+ );
check_mmap(res, (char*)VG_PGROUNDUP(bss), bytes);
}
=20
bytes =3D bss & (VKI_PAGE_SIZE - 1);
=20
// The 'prot' condition allows for a read-only bss
- if ((prot & PROT_WRITE) && (bytes > 0)) {
+ if ((prot & VKI_PROT_WRITE) && (bytes > 0)) {
bytes =3D VKI_PAGE_SIZE - bytes;
- memset((char *)bss, 0, bytes);
+ VG_(memset)((char *)bss, 0, bytes);
}
}
}
@@ -415,7 +461,7 @@
static int match_ELF(const char *hdr, int len)
{
ESZ(Ehdr) *e =3D (ESZ(Ehdr) *)hdr;
- return (len > sizeof(*e)) && memcmp(&e->e_ident[0], ELFMAG, SELFMAG) =
=3D=3D 0;
+ return (len > sizeof(*e)) && VG_(memcmp)(&e->e_ident[0], ELFMAG, SELF=
MAG) =3D=3D 0;
}
=20
static int load_ELF(char *hdr, int len, int fd, const char *name,
@@ -467,27 +513,27 @@
break;
=09
case PT_INTERP: {
- char *buf =3D malloc(ph->p_filesz+1);
+ char *buf =3D hack_malloc(ph->p_filesz+1);
int j;
int intfd;
int baseaddr_set;
=20
- assert(buf);
- pread(fd, buf, ph->p_filesz, ph->p_offset);
+ vg_assert(buf);
+ VG_(pread)(fd, buf, ph->p_filesz, ph->p_offset);
buf[ph->p_filesz] =3D '\0';
=20
intfd =3D open(buf, O_RDONLY);
if (intfd =3D=3D -1) {
- perror("open interp");
- exit(1);
+ VG_(printf)("valgrind: m_ume.c: can't open interpreter\n");
+ VG_(exit)(1);
}
=20
interp =3D readelf(intfd, buf);
if (interp =3D=3D NULL) {
- fprintf(stderr, "Can't read interpreter\n");
+ VG_(printf)("valgrind: m_ume.c: can't read interpreter\n");
return 1;
}
- free(buf);
+ //FIXME VG_(free)(buf);
=20
baseaddr_set =3D 0;
for(j =3D 0; j < interp->e.e_phnum; j++) {
@@ -525,10 +571,10 @@
if (minaddr >=3D maxaddr ||
(minaddr + ebase < info->exe_base ||
maxaddr + ebase > info->exe_end)) {
- fprintf(stderr, "Executable range %p-%p is outside the\n"
- "acceptable range %p-%p\n",
- (void *)minaddr + ebase, (void *)maxaddr + ebase,
- (void *)info->exe_base, (void *)info->exe_end);
+ VG_(printf)("Executable range %p-%p is outside the\n"
+ "acceptable range %p-%p\n",
+ (void *)minaddr + ebase, (void *)maxaddr + ebase,
+ (void *)info->exe_base, (void *)info->exe_end);
return ENOMEM;
}
}
@@ -540,31 +586,32 @@
=20
if (interp !=3D NULL) {
/* reserve a chunk of address space for interpreter */
- void* res;
- char* base =3D (char *)info->exe_base;
- char* baseoff;
- int flags =3D MAP_PRIVATE|MAP_ANONYMOUS;
+ SysRes res;
+ Char* base =3D (Char *)info->exe_base;
+ Char* baseoff;
+ Int flags =3D VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS;
=20
if (info->map_base !=3D 0) {
base =3D (char *)VG_ROUNDUP(info->map_base, interp_align);
- flags |=3D MAP_FIXED;
+ flags |=3D VKI_MAP_FIXED;
}
=20
- res =3D mmap(base, interp_size, PROT_NONE, flags, -1, 0);
+ res =3D VG_(mmap_native)(base, interp_size, VKI_PROT_NONE, flags, =
-1, 0);
check_mmap(res, base, interp_size);
- base =3D res;
+ vg_assert(!res.isError);
+ base =3D (Char*)res.val;
=20
baseoff =3D base - interp_addr;
=20
mapelf(interp, (ESZ(Addr))baseoff);
=20
- close(interp->fd);
+ VG_(close)(interp->fd);
=20
entry =3D baseoff + interp->e.e_entry;
info->interp_base =3D (ESZ(Addr))base;
=20
- free(interp->p);
- free(interp);
+ //FIXME VG_(free)(interp->p);
+ //FIXME VG_(free)(interp);
} else
entry =3D (void *)(ebase + e->e.e_entry);
=20
@@ -573,8 +620,8 @@
=20
info->init_eip =3D (Addr)entry;
=20
- free(e->p);
- free(e);
+ //FIXME VG_(free)(e->p);
+ //FIXME VG_(free)(e);
=20
return 0;
}
@@ -582,7 +629,7 @@
=20
static int match_script(const char *hdr, Int len)
{
- return (len > 2) && memcmp(hdr, "#!", 2) =3D=3D 0;
+ return (len > 2) && VG_(memcmp)(hdr, "#!", 2) =3D=3D 0;
}
=20
static int load_script(char *hdr, int len, int fd, const char *name,
@@ -621,19 +668,19 @@
*cp =3D '\0';
}
=20
- info->interp_name =3D strdup(interp);
- assert(NULL !=3D info->interp_name);
+ info->interp_name =3D hack_strdup(interp);
+ vg_assert(NULL !=3D info->interp_name);
if (arg !=3D NULL && *arg !=3D '\0') {
- info->interp_args =3D strdup(arg);
- assert(NULL !=3D info->interp_args);
+ info->interp_args =3D hack_strdup(arg);
+ vg_assert(NULL !=3D info->interp_args);
}
=20
if (info->argv && info->argv[0] !=3D NULL)
info->argv[0] =3D (char *)name;
=20
if (0)
- printf("#! script: interp_name=3D\"%s\" interp_args=3D\"%s\"\n",
- info->interp_name, info->interp_args);
+ VG_(printf)("#! script: interp_name=3D\"%s\" interp_args=3D\"%s\"\=
n",
+ info->interp_name, info->interp_args);
=20
return do_exec_inner(interp, info);
}
@@ -657,17 +704,17 @@
return errno;
=20
if (st.st_mode & (S_ISUID | S_ISGID)) {
- //fprintf(stderr, "Can't execute suid/sgid executable %s\n", exe);
+ //VG_(printf)("Can't execute suid/sgid executable %s\n", exe);
return EACCES;
}
=20
- if (geteuid() =3D=3D st.st_uid) {
+ if (VG_(geteuid)() =3D=3D st.st_uid) {
if (!(st.st_mode & S_IXUSR))
return EACCES;
} else {
int grpmatch =3D 0;
=20
- if (getegid() =3D=3D st.st_gid)
+ if (VG_(getegid)() =3D=3D st.st_gid)
grpmatch =3D 1;
else {
gid_t groups[32];
@@ -711,22 +758,22 @@
fd =3D open(exe, O_RDONLY);
if (fd =3D=3D -1) {
if (0)
- fprintf(stderr, "Can't open executable %s: %s\n",
- exe, strerror(errno));
+ VG_(printf)("Can't open executable %s: %s\n",
+ exe, VG_(strerror)(errno));
return errno;
}
=20
err =3D check_perms(fd);
if (err !=3D 0) {
- close(fd);
+ VG_(close)(fd);
return err;
}
=20
- bufsz =3D pread(fd, buf, sizeof(buf), 0);
+ bufsz =3D VG_(pread)(fd, buf, sizeof(buf), 0);
if (bufsz < 0) {
- fprintf(stderr, "Can't read executable header: %s\n",
- strerror(errno));
- close(fd);
+ VG_(printf)("Can't read executable header: %s\n",
+ VG_(strerror)(errno));
+ VG_(close)(fd);
return errno;
}
=20
@@ -738,7 +785,7 @@
}
}
=20
- close(fd);
+ VG_(close)(fd);
=20
return ret;
}
Modified: branches/ASPACEM/coregrind/pub_core_libcfile.h
=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/coregrind/pub_core_libcfile.h 2005-08-09 12:30:07 UT=
C (rev 4353)
+++ branches/ASPACEM/coregrind/pub_core_libcfile.h 2005-08-09 17:59:26 UT=
C (rev 4354)
@@ -62,6 +62,8 @@
=20
extern Int VG_(access) ( HChar* path, Bool irusr, Bool iwusr, Bool ixusr=
);
=20
+extern SSizeT VG_(pread) ( Int fd, void* buf, Int count, Int offset );
+
#endif // __PUB_CORE_LIBCFILE_H
=20
/*--------------------------------------------------------------------*/
Modified: branches/ASPACEM/coregrind/pub_core_ume.h
=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/coregrind/pub_core_ume.h 2005-08-09 12:30:07 UTC (re=
v 4353)
+++ branches/ASPACEM/coregrind/pub_core_ume.h 2005-08-09 17:59:26 UTC (re=
v 4354)
@@ -44,27 +44,30 @@
/*------------------------------------------------------------*/
=20
/* This is only here so it can be shared between stage1 and stage2 */
-extern
-void VG_(foreach_map)(int (*fn)(char *start, char *end,
- const char *perm, off_t offset,
- int maj, int min, int ino, void* extra),
- void* extra);
=20
-/* Jump to 'dst', but first set the stack pointer to 'stack'. Also,
- clear all the integer registers before entering 'dst'. It's
- important that the stack pointer is set to exactly 'stack' and not
- (eg) stack - apparently_harmless_looking_small_offset. Basically
- because the code at 'dst' might be wanting to scan the area above
- 'stack' (viz, the auxv array), and putting spurious words on the
- stack confuses it.
+/* JRS 9 Aug 05: both of these are apparently unused, except by
+ memcheck/tests/vgtest_ume.c. */
+//zz extern
+//zz void VG_(foreach_map)(int (*fn)(char *start, char *end,
+//zz const char *perm, off_t offset,
+//zz int maj, int min, int ino, void* extra),
+//zz void* extra);
+//zz=20
+//zz /* Jump to 'dst', but first set the stack pointer to 'stack'. Also=
,
+//zz clear all the integer registers before entering 'dst'. It's
+//zz important that the stack pointer is set to exactly 'stack' and n=
ot
+//zz (eg) stack - apparently_harmless_looking_small_offset. Basicall=
y
+//zz because the code at 'dst' might be wanting to scan the area abov=
e
+//zz 'stack' (viz, the auxv array), and putting spurious words on the
+//zz stack confuses it.
+//zz=20
+//zz This is only exported so that vgtest_ume.c can use it.
+//zz */
+//zz extern
+//zz __attribute__((noreturn))
+//zz void VG_(jump_and_switch_stacks) ( Addr stack, Addr dst );
=20
- This is only exported so that vgtest_ume.c can use it.
-*/
-extern
-__attribute__((noreturn))
-void VG_(jump_and_switch_stacks) ( Addr stack, Addr dst );
=20
-
/*------------------------------------------------------------*/
/*--- Loading ELF files ---*/
/*------------------------------------------------------------*/
Modified: branches/ASPACEM/include/pub_tool_libcfile.h
=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/include/pub_tool_libcfile.h 2005-08-09 12:30:07 UTC =
(rev 4353)
+++ branches/ASPACEM/include/pub_tool_libcfile.h 2005-08-09 17:59:26 UTC =
(rev 4354)
@@ -40,7 +40,7 @@
extern Int VG_(read) ( Int fd, void* buf, Int count);
extern Int VG_(write) ( Int fd, const void* buf, Int count);
extern Int VG_(pipe) ( Int fd[2] );
-extern OffT VG_(lseek) ( Int fd, OffT offset, Int whence);
+extern OffT VG_(lseek) ( Int fd, OffT offset, Int whence );
=20
extern SysRes VG_(stat) ( Char* file_name, struct vki_stat* buf );
extern Int VG_(fstat) ( Int fd, struct vki_stat* buf );
@@ -49,10 +49,10 @@
extern Int VG_(unlink) ( Char* file_name );
=20
// Returns False on failure (eg. if the buffer isn't big enough).
-extern Bool VG_(getcwd) ( Char* buf, SizeT size );
+extern Bool VG_(getcwd) ( Char* buf, SizeT size );
=20
-extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize );
-extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt count =
);
+extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize );
+extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt coun=
t );
=20
#endif // __PUB_TOOL_LIBCFILE_H
=20
Modified: branches/ASPACEM/include/pub_tool_libcproc.h
=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/include/pub_tool_libcproc.h 2005-08-09 12:30:07 UTC =
(rev 4353)
+++ branches/ASPACEM/include/pub_tool_libcproc.h 2005-08-09 17:59:26 UTC =
(rev 4354)
@@ -64,11 +64,12 @@
pids, etc
------------------------------------------------------------------ */
=20
-extern Int VG_(gettid) ( void );
+extern Int VG_(gettid) ( void );
extern Int VG_(getpid) ( void );
extern Int VG_(getppid) ( void );
extern Int VG_(getpgrp) ( void );
-extern Int VG_(setpgid) ( Int pid, Int pgrp );
+extern Int VG_(geteuid) ( void );
+extern Int VG_(getegid) ( void );
=20
/* ---------------------------------------------------------------------
Timing
|