public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paweł Sikora" <pluto@agmk.net>
To: libc-help@sourceware.org
Cc: Mike Frysinger <vapier@gentoo.org>, linux-kernel@vger.kernel.org
Subject: Re: mprotect() failed: Cannot allocate memory
Date: Wed, 21 Apr 2010 01:44:18 +0200	[thread overview]
Message-ID: <201004210144.18954.pluto@agmk.net> (raw)
In-Reply-To: <201004201917.23286.vapier@gentoo.org>

On Wednesday 21 April 2010 01:17:22 Mike Frysinger wrote:
> On Tuesday 20 April 2010 19:05:20 Paweł Sikora wrote:
> > i'm trying to debug an ugly application with ElectricFence.
> 
> electricfence does a lot of ugly memory tricks to do its thing, including,
> but not limited to, overriding memory related symbols.  best to seek help
> from the electricfence authors.

so, let's avoid EF and run following test:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

void* my_alloc( size_t n )
{
        size_t ps = getpagesize();
        printf( "request for %Zd bytes => ", n );
        /* alloc PAGE_SIZE + n */
        char* p = mmap( 0, ps + n, PROT_READ | PROT_WRITE, MAP_SHARED | 
MAP_ANONYMOUS, -1, 0 );
        if ( p == MAP_FAILED )
                __builtin_abort();
        /* block guard page */
        int rc = mprotect( p, ps, PROT_NONE );
        if ( rc != 0 )
                __builtin_abort();
        char* q = p + ps;
        printf( "guard page @ %p, allocated region @ %p\n", p, q );
        return q;
}

int main()
{
        #define N 100  
        size_t NN = 4*100*100;
        size_t kmax = 100;
        int i;

        double **bm = (double **)my_alloc( NN * sizeof( double* ) );
        for( i = 0; i < NN; ++i )
        {
                bm[ i ] = (double*)my_alloc( kmax * sizeof( double ) );
        }
        // leak...
        return 0;
}

and the result is...

(...)
mmap(NULL, 4896, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0) = 
0x7f5fd97df000
mprotect(0x7f5fd97df000, 4096, PROT_NONE) = -1 ENOMEM (Cannot allocate memory)

  reply	other threads:[~2010-04-20 23:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-20 23:05 mprotect() failed: Cannot allocate memory Paweł Sikora
2010-04-20 23:17 ` Mike Frysinger
2010-04-20 23:44   ` Paweł Sikora [this message]
2010-04-21  2:23     ` Mike Frysinger
2010-04-21  8:22     ` Yann Droneaud
2010-04-21  7:33       ` Paweł Sikora
2010-04-21  7:42       ` Paweł Sikora
2010-04-21 10:16 ` Peter Zijlstra
2010-04-21  9:42   ` Paweł Sikora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201004210144.18954.pluto@agmk.net \
    --to=pluto@agmk.net \
    --cc=libc-help@sourceware.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vapier@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox