| View previous topic :: View next topic |
| Author |
Message |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Wed Jun 16, 2010 10:43 am Post subject: |
|
|
| Burningmace wrote: | | I have always been taught from square one that recursion is a difficult beast, and that it is best to be avoided except where absolutely necessary. |
I hope this has not happened from a formal teaching of programming. If that is the case, I really question to competence of your teacher. Just because something is hard it should not be done ? Btw, you may not have come across it but in some languages, recursion is almost part of that particular paradigm. For example, functional programming languages such as Haskell or Q make it such that iterative programming is actually a lot harder than recursive programming.
| Burningmace wrote: | | The maximum stack size is not a single defined value, and thus is unpredictable. In an open source scenario, one would expect to have the code compiled on multiple architectures with multiple compilers. Whilst GCC might default to 8MB of stack space, another compiler might choose 1MB or 2MB. |
It can be set in linker options.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Wed Jun 16, 2010 11:32 am Post subject: |
|
|
Question for you Burningmace, is this topic created with the intent of actually learning or because you are doing a challenge on a site such as HackQuest and are looking for help with one of their challenges? I'm asking since this exact topic is one of their challenges, so looked familiar.
_________________
- Retired. |
|
| Back to top |
|
 |
Polynomial Grandmaster Cheater
Reputation: 5
Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
|
Posted: Thu Jun 17, 2010 12:07 pm Post subject: |
|
|
Slugsnack, actually it has been two teachers and multiple online learning references that have steered me away from recursion. I guess it's something that people avoid due to the somewhat difficult and troublesome nature of it. I know that Haskell uses it in a lot of situations, but I remember reading somewhere that the stack in Haskell is automatically expanded if it gets near the limit.
Wiccaan, it is just a learning topic. I've never heard of HackQuest, it looks interesting. I shall take a look when I have time.
_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time. |
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Thu Jun 17, 2010 12:20 pm Post subject: |
|
|
| Burningmace wrote: | | Slugsnack, actually it has been two teachers and multiple online learning references that have steered me away from recursion. I guess it's something that people avoid due to the somewhat difficult and troublesome nature of it. I know that Haskell uses it in a lot of situations, but I remember reading somewhere that the stack in Haskell is automatically expanded if it gets near the limit. |
Recurrsion is bad, mmkay?
| Code: | open System
open System.IO;
open System.Text.RegularExpressions;
let rec FilesInDirectoryMatching (regex : Regex) (dir : DirectoryInfo) =
[ yield! dir.GetFiles() |> Array.Parallel.choose (fun x -> if regex.IsMatch x.Name then Some x else None)
for subdir in dir.GetDirectories() do yield! FilesInDirectoryMatching regex subdir ]
let reg = Regex(".*")
let dir = DirectoryInfo(@"D:\Downloads")
FilesInDirectoryMatching reg dir |> List.map (fun x -> x.Name) |> printfn "%A" |
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Jun 17, 2010 3:43 pm Post subject: |
|
|
| Burningmace wrote: | | but I remember reading somewhere that the stack in Haskell is automatically expanded if it gets near the limit.. |
| Slugsnack wrote: | | A little extra info for interest. The stack is simply a block of memory that is defined by the program for specific use, ie. as the stack. Its main use is parameter passing and local variables. Now the interesting bit. The stack is actually extendable and can grow. If on a heavily recursive app, the stack commit size is exceeded, the next probe triggers a guard-page exception which causes the stack to extend and the guard page to increment to the next page. |
|
|
| Back to top |
|
 |
Polynomial Grandmaster Cheater
Reputation: 5
Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Jun 17, 2010 6:14 pm Post subject: |
|
|
| The stack being extended does not mean it can't overflow. Just means there is a large space that is reserved but it is only committed to a certain size which can then keep growing up to the reserved size.
|
|
| Back to top |
|
 |
Polynomial Grandmaster Cheater
Reputation: 5
Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
|
Posted: Thu Jun 17, 2010 8:14 pm Post subject: |
|
|
From the way I read it (it may not have been your post) it suggested that the stack would expand as much as possible, to the limit of as much memory that can be allocated by a single process. Think of it as the Stack class in the .NET framework, where the whole stack is simply an object in virtual memory and not the traditional stack pointed to by the ESP register. Each entry added allocates more memory automatically.
_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time. |
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Jun 17, 2010 8:26 pm Post subject: |
|
|
The stack must be all in contiguous memory and it can not simply be moved around to reallocate it like with realloc() or something because it would involve having to update ESP + ESP + PE headers, etc.
Each thread has a block of memory reserved for the stack. Only a proportion of that memory is committed and then the guard page will expand the committed memory. I believe the reason it's implemented like this is so you don't end up wasting tonnes of memory on unused stack memory.
|
|
| Back to top |
|
 |
Polynomial Grandmaster Cheater
Reputation: 5
Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
|
Posted: Fri Jun 18, 2010 7:22 am Post subject: |
|
|
I was talking more about a 'virtualised' system, where instructions would be translated into low level code but the higher level program stack kept in more managed conditions. I imagine this is how interpreted script languages such as PHP work.
For example, I could write code in C# that parsed a set of imitation low level instructions (including call/ret/push/pop equivilents) and modified the state of a large byte array (virtual memory) and a stack object (the virtual stack) as normal programs would do. This would create similar results to that of a native executable program (albeit with a significant performance hit) yet never directly access the real stack - the whole thing would remain managed. The managed stack in CIL is similar to this, where all CIL code is executed by the virtual machine.
But all of this is off topic. Challenges please!
_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time. |
|
| Back to top |
|
 |
Deltron Z Expert Cheater
Reputation: 1
Joined: 14 Jun 2009 Posts: 164
|
Posted: Sun Jun 20, 2010 2:58 am Post subject: |
|
|
We've already solved your challanges.
I solved the first 3 in C/C++ and Flyte gave another solution in what seems like C#, is this J#? looks cool, I didn't even know they still use it...
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Jun 20, 2010 6:09 am Post subject: |
|
|
| F#
|
|
| Back to top |
|
 |
|