zsh-workers
 help / color / mirror / code / Atom feed
* Re: Segmentation Fault on Stack Overflow
       [not found]       ` <20140105175831.4640d8a5@pws-pc.ntlworld.com>
@ 2014-01-05 21:33         ` Peter Stephenson
  2014-01-05 22:12           ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2014-01-05 21:33 UTC (permalink / raw)
  To: Zsh Hackers' List

On Sun, 5 Jan 2014 17:58:31 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> It might be possible to do a little better by querying some of the
> memory-related limits (I would guess available stack space is the key
> one, but some investigation will be necessary) to see if one of the
> limits is getting short and aborting function calls in a handlable
> fashion at that level.  Unhelpfully, limits (from getrlimit()) and
> current usage (from getrusage()) don't seem to map cleanly onto one
> another, and this is all rather system-specific, so this doesn't look
> like a trivial project.

What's more, on Linux the resources useful here aren't actually reported by
getrusage() at the moment.  The best I've found with a bit of poking
around locally (I might do better online, but I might as well ask here
first) is /proc/$$/status.  This is obviously completely system specific
and quite possible specific to certain kernel versions.  The code below
does seem to do roughly what I want (at the moment it reports the limits
and usage rather than checking the values) but I can't help thinking I'm
missing something.  It's going to be hard to get something of general
use out of this sort of thing.

    {
	struct rlimit rlimit;
	int found = 0;
	long usage, limit;
	char buffer[256];		
	FILE *sfile;
	sprintf(buffer, "/proc/%d/status", getpid());
	sfile = fopen(buffer, "r");
	if (sfile) {
	    while (fgets(buffer, 256, sfile)) {
		if (!strncmp(buffer, "VmStk:", 6) &&
		    getrlimit(RLIMIT_STACK, &rlimit) == 0) {
		    const char *ptr = buffer + 6;
		    while (!isdigit(*ptr))
			ptr++;
		    usage = atol(ptr);
		    limit = rlimit.rlim_cur == (rlim_t)-1 ?
			rlimit.rlim_max : rlimit.rlim_cur;
		    fprintf(stderr, "stack: limit = %ld, usage = %ld\n",
			    limit, usage * 1024);
		    found++;
		} else if (!strncmp(buffer, "VmData:", 7) &&
			   getrlimit(RLIMIT_DATA, &rlimit) == 0) {
		    const char *ptr = buffer + 7;
		    while (!isdigit(*ptr))
			ptr++;
		    usage = atol(ptr);
		    limit = rlimit.rlim_cur == (rlim_t)-1 ?
			rlimit.rlim_max : rlimit.rlim_cur;
		    fprintf(stderr, "stack: limit = %ld, usage = %ld\n",
			    limit, usage * 1024);
		    found++;
		}
		if (found == 2)
		    break;
	    }
	    fflush(stderr);
	    fclose(sfile);
	}
    }

pws


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Segmentation Fault on Stack Overflow
  2014-01-05 21:33         ` Segmentation Fault on Stack Overflow Peter Stephenson
@ 2014-01-05 22:12           ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2014-01-05 22:12 UTC (permalink / raw)
  To: Zsh Hackers' List

On Jan 5,  9:33pm, Peter Stephenson wrote:
} Subject: Re: Segmentation Fault on Stack Overflow
}
} On Sun, 5 Jan 2014 17:58:31 +0000
} Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
} > It might be possible to do a little better by querying some of the
} > memory-related limits [...]
} 
} What's more, on Linux the resources useful here aren't actually reported by
} getrusage() at the moment.

We discussed this a bit back when we made --disable-max-function-depth.
It's just not the shell's responsibility to manage resources in this
much detail.  Zsh is hardly alone in this:

schaefer[543] bash
schaefer@burner:~$ inf() { inf; }; inf
zsh: segmentation fault (core dumped)  bash


The most I'd suggest is that we experiment with a MAX_FUNCTION_DEPTH
parameter that users could adjust when they have restrictive soft limits
or a small-memory host, etc.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-05 22:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <3540501074823477909@gmail297201516>
     [not found] ` <87d2k8y6wn.fsf@ft.bewatermyfriend.org>
     [not found]   ` <AF114D5A-7797-4E3F-A34A-A03A0B7E9167@macports.org>
     [not found]     ` <878uuwy0vk.fsf@ft.bewatermyfriend.org>
     [not found]       ` <20140105175831.4640d8a5@pws-pc.ntlworld.com>
2014-01-05 21:33         ` Segmentation Fault on Stack Overflow Peter Stephenson
2014-01-05 22:12           ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).