[#1207] warning in ruby extension eats memory — Eugene Scripnik <Eugene.Scripnik@...>

This message was posted to ruby-talk, but I didn't get responce from

22 messages 2003/07/01
[#1208] Re: warning in ruby extension eats memory — ts <decoux@...> 2003/07/01

>>>>> "E" == Eugene Scripnik <Eugene.Scripnik@itgrp.net> writes:

[#1209] Re: warning in ruby extension eats memory — Eugene Scripnik <Eugene.Scripnik@...> 2003/07/02

ts wrote:

[#1210] Re: warning in ruby extension eats memory — ts <decoux@...> 2003/07/02

>>>>> "E" == Eugene Scripnik <Eugene.Scripnik@itgrp.net> writes:

[#1211] Re: warning in ruby extension eats memory — Eugene Scripnik <Eugene.Scripnik@...> 2003/07/04

ts wrote:

[#1212] Re: warning in ruby extension eats memory — ts <decoux@...> 2003/07/04

>>>>> "E" == Eugene Scripnik <Eugene.Scripnik@itgrp.net> writes:

[#1213] Re: warning in ruby extension eats memory — Eugene Scripnik <Eugene.Scripnik@...> 2003/07/04

ts wrote:

[#1214] Re: warning in ruby extension eats memory — ts <decoux@...> 2003/07/04

>>>>> "E" == Eugene Scripnik <Eugene.Scripnik@itgrp.net> writes:

[#1215] Re: warning in ruby extension eats memory — Eugene Scripnik <Eugene.Scripnik@...> 2003/07/04

ts wrote:

[#1237] FTP.new with block — Gavin Sinclair <gsinclair@...>

Hi,

22 messages 2003/07/19
[#1238] Re: [Patch] FTP.new with block — ts <decoux@...> 2003/07/19

>>>>> "G" == Gavin Sinclair <gsinclair@soyabean.com.au> writes:

[#1240] Re: [Patch] FTP.new with block — Mathieu Bouchard <matju@...> 2003/07/19

[#1297] Fix for Bug 1058 — Markus Walser <walser@...>

Hi,

16 messages 2003/07/25

Re: stack problem

From: nobu.nokada@...
Date: 2003-07-23 00:51:06 UTC
List: ruby-core #1279
Hi,

At Wed, 23 Jul 2003 06:19:15 +0900,
Mathieu Bouchard wrote:
> This is my current cleaned-up code for finding the bottom of the stack.
> Does this make sense to you? Can you find any problems with it?

Stepping and rounding by pagesize might be better.

Just a sample.


#if defined(_WIN32) || defined(__CYGWIN__)
#include <windows.h>
void *
localize_sysstack()
{
    MEMORY_BASIC_INFORMATION m;
    memset(&m, 0, sizeof(m));
    VirtualQuery(&m, &m, sizeof(m));
    /* assume stack growing downward */
    return (char *)m.BaseAddress + m.RegionSize;
}
#else
#include <setjmp.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>

#ifndef STACK_GROW_DIRECTION
# ifdef __i386__
#   define STACK_GROW_DIRECTION -1
# endif
#endif

#ifndef LOCAL_FUNC
# ifdef __GNUC__
#   define LOCAL_FUNC 1
# else
#   define LOCAL_FUNC 0
# endif
#endif

#if LOCAL_FUNC
# define RESCUE_STACK rescue_segfault
#else
# define RESCUE_STACK *rescue_segfault
#endif
#define TRAP_STACK \
    sigjmp_buf RESCUE_STACK;\
    static void trap_segfault(int signo) {siglongjmp(RESCUE_STACK, signo);}

#if !LOCAL_FUNC
TRAP_STACK
#endif

void *
localize_sysstack()
{
#if LOCAL_FUNC
    TRAP_STACK;
#else
    sigjmp_buf sigbuf;
#endif

    volatile char *volatile bp = (volatile char *)&bp;
    void (*old)(int) = signal(SIGSEGV, trap_segfault);
    const long pagesize = getpagesize();
#if STACK_GROW_DIRECTION
    const int growup = (STACK_GROW_DIRECTION > 0);
    const long size = pagesize * STACK_GROW_DIRECTION;
#else
    const int growup = stack_growup_p() ? 1 : 0;
    const long size = growup ? pagesize : -pagesize;
#endif

#if !LOCAL_FUNC
    rescue_segfault = &sigbuf;
#endif

    if (!sigsetjmp(RESCUE_STACK, 0)) {
	while (1) {
	    volatile char *p = bp - size;
	    (void)*p;
	    bp = p;
	}
    }
    signal(SIGSEGV, old);
    return (void *)(((unsigned long)bp + (growup ? 0 : pagesize)) & ~(pagesize - 1));
}
#endif

int main()
{
    volatile char *bottom = localize_sysstack();
    printf("%p\n", bottom);
    bottom[-1];
    *bottom;
    return 0;
}


-- 
Nobu Nakada

In This Thread