Professional Web Applications Themes

Allocating memory starting at 0x00000000 - Mac Programming

I want to allocate a bunch of memory starting from address 0x00000000 using mmap() or vm_allocate() on OS X 10.2. By default apps don't allow this to protect against NULL pointer mischief - how do I change things so that I can map this memory? So far I've discovered it is the linker that is stopping me - it inserts a no access block called __PAGEZERO in the zeroth page and other stuff such as a __TEXT block and the actual executable code follows shortly thereafter. I figured out how to link the program so that it loaded itself in ...

  1. #1

    Default Allocating memory starting at 0x00000000

    I want to allocate a bunch of memory starting from address 0x00000000
    using mmap() or vm_allocate() on OS X 10.2. By default apps don't allow
    this to protect against NULL pointer mischief - how do I change things
    so that I can map this memory?

    So far I've discovered it is the linker that is stopping me - it inserts
    a no access block called __PAGEZERO in the zeroth page and other stuff
    such as a __TEXT block and the actual executable code follows shortly
    thereafter. I figured out how to link the program so that it loaded
    itself in at 0x10000000 instead using -seg1addr but it still puts in
    __PAGEZERO.

    Even then I can't seem to map any memory below about 0x000A4000. I was
    expecting to be able to start from 0x00001000 with just __PAGEZERO in
    the low pages. What's else is stopping me?

    So in short what else (if anything) apart from __PAGEZERO is thwarting
    me and if anyone does know how to map in a block of memory starting at
    0x00000000 please tell me the secret!

    Cheers

    James
    James Weatherley Guest

  2. #2

    Default Re: Allocating memory starting at 0x00000000

    In article <MPG.19aad44f6fc09d2e98968fNews.Individual.NET> ,
    James Weatherley <newsweatherley.net> wrote:
    > I want to allocate a bunch of memory starting from address 0x00000000
    > using mmap() or vm_allocate() on OS X 10.2. By default apps don't allow
    > this to protect against NULL pointer mischief - how do I change things
    > so that I can map this memory?
    Open a terminal window and read up on "ld" (% man ld). You can map a
    read-write segment at location 0 in your "ld" command line, if you want
    to, using gcc.
    David Phillip Oster Guest

  3. #3

    Default Re: Allocating memory starting at 0x00000000

    In <oster-CF1A45.22573018082003news.sf.sbcglobal.net> David Phillip
    Oster wrote:
    > In article <MPG.19aad44f6fc09d2e98968fNews.Individual.NET> ,
    > James Weatherley <newsweatherley.net> wrote:
    >
    >> I want to allocate a bunch of memory starting from address 0x00000000
    >> using mmap() or vm_allocate() on OS X 10.2. By default apps don't
    >> allow this to protect against NULL pointer mischief - how do I
    >> change things so that I can map this memory?
    >
    > Open a terminal window and read up on "ld" (% man ld). You can map a
    > read-write segment at location 0 in your "ld" command line, if you
    > want to, using gcc.
    >
    Yes, I've been looking at the ld man pages - that's where I found out
    about __PAGEZERO. I still can't work out what flags I need. '-segs_read_
    write_addr addr and '-segs_read_only_addr addr' seemed hopeful but they
    only apply if you are using the '-dylib' option but I want an executable.
    JamesW Guest

  4. #4

    Default Re: Allocating memory starting at 0x00000000

    In article <3F487055.1334A9C6nospam.idiom.com>, [email]jcrnospam.idiom.com[/email]
    says...
    > James Weatherley wrote:
    > >
    > > I want to allocate a bunch of memory starting from address 0x00000000
    > > using mmap() or vm_allocate() on OS X 10.2. By default apps don't allow
    > > this to protect against NULL pointer mischief - how do I change things
    > > so that I can map this memory?
    >
    > Why do you need to do this?
    >
    > -jcr
    >
    I'm porting a Sinclair QL emulator uQLx to OS X - [url]http://www.dokos-[/url]
    gr.net/ql/uqlxmac.html. As you can see I can get it running but the
    original version has some performance enhancements that would be nice to
    have in the Mac version. One of these is basing the emulated machine's
    memory at 0x00000000 to save some pointer arithmetic every time the
    emulated machine needs to access memory (ie all the time!). The author
    claims a 20-30% speed boost on UNICES that allow this.

    James
    James Weatherley Guest

  5. #5

    Default Re: Allocating memory starting at 0x00000000

    In article <MPG.19b534bd54bd7402989690News.Individual.NET> ,
    James Weatherley <newsweatherley.net> wrote:
    > In article <3F487055.1334A9C6nospam.idiom.com>, [email]jcrnospam.idiom.com[/email]
    > says...
    > > James Weatherley wrote:
    > > >
    > > > I want to allocate a bunch of memory starting from address 0x00000000
    > > > using mmap() or vm_allocate() on OS X 10.2. By default apps don't allow
    > > > this to protect against NULL pointer mischief - how do I change things
    > > > so that I can map this memory?
    > >
    > > Why do you need to do this?
    > I'm porting a Sinclair QL emulator uQLx to OS X - [url]http://www.dokos-[/url]
    > gr.net/ql/uqlxmac.html. As you can see I can get it running but the
    > original version has some performance enhancements that would be nice to
    > have in the Mac version. One of these is basing the emulated machine's
    > memory at 0x00000000 to save some pointer arithmetic every time the
    > emulated machine needs to access memory (ie all the time!). The author
    > claims a 20-30% speed boost on UNICES that allow this.
    Without reading anything about it, the degree of that speed boost sounds
    very odd. You save one or two instructions per memory access, but
    that's more than dwarfed by the high cost of accessing memory. I can't
    see how that'd lead to a 20-30% performance improvement.

    -Eric

    --
    Eric Albert [email]ejalbertstanford.edu[/email]
    [url]http://rescomp.stanford.edu/~ejalbert/[/url]
    Eric Albert Guest

Similar Threads

  1. #39438 [NEW]: Memory leak PHP Fatal error: Out of memory
    By nikolas dot hagelstein at gmail dot com in forum PHP Bugs
    Replies: 11
    Last Post: December 1st, 08:08 PM
  2. Flash Player 8 huge memory using during drag (all memory gone in few minutes) !!!
    By LSopko@1024Informatica.com in forum Macromedia Flash Player
    Replies: 0
    Last Post: June 13th, 09:42 AM
  3. Allocating memory
    By Tristanbully in forum Adobe Illustrator Macintosh
    Replies: 5
    Last Post: May 21st, 03:08 PM
  4. Memory consumption of Ruby/mod_ruby combo on Apache [memory leak]
    By David Heinemeier Hansson in forum Ruby
    Replies: 4
    Last Post: September 10th, 01:58 AM
  5. Replies: 1
    Last Post: June 26th, 04:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139