On Wed, Oct 25, 2000 at 06:23:20PM +0100, Tom Hughes wrote:
> In message <[EMAIL PROTECTED]>
>           Nicholas Clark <[EMAIL PROTECTED]> wrote:
> 
> > Specific example where you can't:
> > on ARM, the branch instructions (B and BL) are PC relative, but only have
> > a 24 bit offset field. The address space is (now) 32 bit, so there's parts
> > you can't reach without either calculating addresses (in another register)
> > and MOVing them to the PC, or loading the PC from a branch table in memory.
> 
> That is actually a word offset of course, so it can actually reach
> up to 26 bits away in bytes. Still not the full 32 though.

Good point
 
> Of course that only becomes a problem if your program is big enough
> to exceed 26 bits of address space, which is pretty unlikely. That
> or if the program occupies seriously disjoint areas of address space.

Which is likely:

nick@Bagpuss [test]$ uname -a
Linux Bagpuss.unfortu.net 2.2.17-rmk1 #5 Mon Sep 18 19:03:46 BST 2000 armv4l unknown
nick@Bagpuss [test]$ cat mmap.c
#include <unistd.h>
#include <sys/mman.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main () {
  int motd = open ("/etc/motd", O_RDONLY);
  void *mapped, *malloced, *big;

  if (motd < 0) {
    perror ("Failed to open /etc/motd");
    return 1;
  }
  mapped = mmap(NULL, 1024, PROT_EXEC | PROT_READ | PROT_WRITE , MAP_PRIVATE, motd, 0);
  malloced = malloc (1024);
  big = malloc (1024*1024*32);
  printf ("mapped = %p malloced = %p big = %p main = %p\n", mapped, malloced, big, 
&main);
  return 0;
}
nick@Bagpuss [test]$ ./mmap 
mapped = 0x40015000 malloced = 0x2008670 big = 0x40105008 main = 0x200040c

likewise x86

[nick@babyhippo nick]$ ./mmap
mapped = 0x40013000 malloced = 0x80498d0 big = 0x40109008 main = 0x80484a0
[nick@babyhippo nick]$ uname -a
Linux babyhippo.com 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686 unknown

mmap gives you memory from somewhere disjoint. And for some malloc()
implementations (glibc2.1 here, but I've compiled Doug Lea's malloc on
Solaris and HP UX) will call mmap for a large request.
(And at least one out of Solaris and HP UX also gives you pointers greater
than 0x80000000 from mmap())

Particularly likely if we're considering mmap()ing bytecode in

Nicholas Clark

Reply via email to