Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: local arrays and stack |
| Date | 2015-03-23 22:29 +0000 |
| Organization | Freie Universitaet Berlin |
| Message-ID | <cnbiemFpbilU1@mid.uni-berlin.de> (permalink) |
| References | (5 earlier) <705a5674-dbc9-460a-a72c-50bf1946be01@googlegroups.com> <c80c4036-d4a7-4a3d-9821-393b3ec9544c@googlegroups.com> <87bnjjty2r.fsf@kst-u.example.com> <56cd397c-bac6-4eac-ab5a-5548a9473140@googlegroups.com> <877fu7trzy.fsf@kst-u.example.com> |
Keith Thompson <kst-u@mib.org> wrote:
> Xcott Craver <xcottcraver@gmail.com> writes:
> > On Monday, March 23, 2015 at 1:37:23 PM UTC-4, Keith Thompson wrote:
> >> Xcott Craver <@> writes:
> >> > I can declare a 160MB array and see it on the stack. It's just a matter
> >> > of subtracting the relevant offset from the stack pointer.
> >>
> >> Using what implementation?
> >
> > 64-bit OSX:
> >
> > #define LEN 40000000
> > int main( void ) {
> > int array [LEN]; ....
> >
> > (lldb) disas --name main
> > a.out`main at tester.c:12:
> > a.out[0x100000ec0]: pushq %rbp
> > a.out[0x100000ec1]: movq %rsp, %rbp
> > a.out[0x100000ec4]: subq $0x9896820, %rsp <---- 160000032 bytes
> >
> > The ulimit command tells me that I apparently have an 8192K soft limit, and a
> > 65532K hard limit on the stack. However, I can declare gigabyte-sized arrays,
> > and dissassembly just shows the function subtracting insane amounts from the
> > stack pointer.
> I tried something similar on my system (Linux Mint, x86_64). When I
> just declared the array, the program compiled and ran without error.
> When I assigned a value to an element near the end of the array, it died
> with a segmentation fault.
For what I know that is the usual behaviour - the stack limit is
a system limit and results in the corresponding number of pages
automatically allocated for the stack at program start, but which
isn't checked for when the stack pointer is modified (would pro-
bably use quite a lot of CPU time to do that for each and every
stack pointer modification). So the stack pointer can quite easily
be modified by requesting too large a local array to point to un-
accessible memory and dereferencing it then results in a segmen-
tation fault (or worse, to memory that should be inaccessible but
isn't because the address is by chance or malicious intention some=
thing that points to mapped memory).
An interesting question is what exactly happens if you modify the
stack limit setting from within your program. Does it apply also
to he running program? Or only programs spawned from it? Never
thought about that yet;-)
Best regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-22 01:51 -0700
local arrays and stack asetofsymbols@gmail.com - 2015-03-22 02:23 -0700
Re: local arrays and stack Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-22 13:22 -0700
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-23 01:55 -0700
Re: local arrays and stack Xcott Craver <xcottcraver@gmail.com> - 2015-03-22 15:07 -0700
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-23 01:50 -0700
Re: local arrays and stack Robert Wessel <robertwessel2@yahoo.com> - 2015-03-23 04:26 -0500
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-23 06:53 -0700
Re: local arrays and stack Xcott Craver <xcottcraver@gmail.com> - 2015-03-23 07:29 -0700
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-23 08:34 -0700
Re: local arrays and stack Robert Wessel <robertwessel2@yahoo.com> - 2015-03-23 19:57 -0500
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-24 04:01 -0700
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-24 04:37 -0700
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-24 13:04 +0100
Re: local arrays and stack glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-24 17:29 +0000
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-24 20:01 +0100
Re: local arrays and stack Keith Thompson <kst-u@mib.org> - 2015-03-23 08:24 -0700
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-23 08:42 -0700
Re: local arrays and stack Bartc <bc@freeuk.com> - 2015-03-23 16:07 +0000
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-23 09:15 -0700
Re: local arrays and stack Keith Thompson <kst-u@mib.org> - 2015-03-23 09:16 -0700
Re: local arrays and stack Bartc <bc@freeuk.com> - 2015-03-23 16:34 +0000
Re: local arrays and stack Xcott Craver <xcottcraver@gmail.com> - 2015-03-23 10:12 -0700
Re: local arrays and stack Bartc <bc@freeuk.com> - 2015-03-23 17:44 +0000
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-23 11:47 -0700
Re: local arrays and stack Xcott Craver <xcottcraver@gmail.com> - 2015-03-23 12:06 -0700
Re: local arrays and stack Bartc <bc@freeuk.com> - 2015-03-23 20:25 +0000
Re: local arrays and stack Xcott Craver <xcottcraver@gmail.com> - 2015-03-23 14:10 -0700
Re: local arrays and stack Bartc <bc@freeuk.com> - 2015-03-23 22:22 +0000
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-23 23:57 -0700
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-24 10:28 +0100
Re: local arrays and stack Bartc <bc@freeuk.com> - 2015-03-24 10:44 +0000
Re: local arrays and stack Martin Shobe <martin.shobe@yahoo.com> - 2015-03-24 06:38 -0500
Re: local arrays and stack Martin Shobe <martin.shobe@yahoo.com> - 2015-03-24 09:57 -0500
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-24 13:22 +0100
Re: local arrays and stack Bartc <bc@freeuk.com> - 2015-03-25 16:07 +0000
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-25 17:42 +0100
Re: local arrays and stack Bartc <bc@freeuk.com> - 2015-03-25 19:06 +0000
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-25 12:26 -0700
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-25 13:20 -0700
Re: local arrays and stack Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-25 12:28 -0700
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-25 21:45 +0100
Re: local arrays and stack Keith Thompson <kst-u@mib.org> - 2015-03-25 12:50 -0700
Re: local arrays and stack Bartc <bc@freeuk.com> - 2015-03-25 22:33 +0000
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-25 23:57 +0100
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-25 21:42 +0100
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-25 09:55 -0700
Re: local arrays and stack Keith Thompson <kst-u@mib.org> - 2015-03-25 12:36 -0700
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-25 13:04 -0700
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-25 21:52 +0100
Re: local arrays and stack Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-25 15:18 -0700
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-26 00:02 +0100
Re: local arrays and stack Melzzzzz <mel@zzzzz.com> - 2015-03-26 00:47 +0100
Re: local arrays and stack Mel <mel@zzzzz.com> - 2015-03-24 14:58 +0100
Re: local arrays and stack Xcott Craver <xcottcraver@gmail.com> - 2015-03-24 06:58 -0700
Re: local arrays and stack Keith Thompson <kst-u@mib.org> - 2015-03-23 14:34 -0700
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-24 10:16 +0100
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-24 09:55 +0100
Re: local arrays and stack Noob <root@127.0.0.1> - 2015-03-24 10:23 +0100
Re: local arrays and stack Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-24 12:18 -0700
Re: local arrays and stack Keith Thompson <kst-u@mib.org> - 2015-03-24 13:42 -0700
Re: local arrays and stack Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-25 08:47 -0700
Re: local arrays and stack Xcott Craver <xcottcraver@gmail.com> - 2015-03-23 09:32 -0700
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-23 09:57 -0700
Re: local arrays and stack Keith Thompson <kst-u@mib.org> - 2015-03-23 10:37 -0700
Re: local arrays and stack Xcott Craver <xcottcraver@gmail.com> - 2015-03-23 10:49 -0700
Re: local arrays and stack Keith Thompson <kst-u@mib.org> - 2015-03-23 12:48 -0700
Re: local arrays and stack jt@toerring.de (Jens Thoms Toerring) - 2015-03-23 22:29 +0000
Re: local arrays and stack James Kuyper <jameskuyper@verizon.net> - 2015-03-23 19:03 -0400
Re: local arrays and stack jt@toerring.de (Jens Thoms Toerring) - 2015-03-23 23:36 +0000
Re: local arrays and stack fir <profesor.fir@gmail.com> - 2015-03-24 02:17 -0700
Re: local arrays and stack Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-23 11:56 -0700
Re: local arrays and stack Robert Wessel <robertwessel2@yahoo.com> - 2015-03-23 20:00 -0500
Re: local arrays and stack David Brown <david.brown@hesbynett.no> - 2015-03-24 10:39 +0100
csiph-web