The Call Stack and Stack Overflows (example in C)

The Call Stack and Stack Overflows (example in C)

Jacob Sorber

3 года назад

44,372 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

A P
A P - 21.08.2023 08:30

dude wtf are you talking about? you just ramble all video. You didn't explain anything

Ответить
Aleksandar V.
Aleksandar V. - 21.07.2023 15:31

Great explanation, keep up the good work!

Ответить
Mateusz Trzeciak
Mateusz Trzeciak - 19.06.2023 23:25

I am wondering how does OS knows how much memory it must be allocated for the program. I assume that Stack Overflow occurs when Stack memory addreses intersecs with Heap memory addresses?

Ответить
Kip
Kip - 01.06.2023 00:19

So... when you're reading it normally like you would in a disassembled/hex editor or whatever the stack actually grows upwards? I get confused by everyone putting the high addresses in their examples at the top of the diagram. And with frame pointer you meant the base pointer and not the stack pointer, right?

edit: oooh yeah so the stack pointer would in this case point to the address of the "return" variable on the stack, probably? Like...

0x0 | ...
0x4 | "return" var
0x8 | old base pointer
0xC | return address
0x10 | "counter" arg
...


Frame pointer = 0x8
Stack pointer = 0x4

Ответить
Ryshask -
Ryshask - - 03.04.2023 23:05

This is the best video I found to refresh my memory on basic program execution I could find after working on higher level languages for so long. So many people put up videos that are apparent word salad with no real comprehension... As if they are trying to remember how it works while explaining it. Thank you Jacob.

Ответить
Rich
Rich - 15.02.2023 06:44

This was so good!

Ответить
AMD Readon
AMD Readon - 26.01.2023 18:48

hey jacob,
about the address from the main function when we printed : &i , __builtin_frame_address
the difference between the integer storage i and the SP was 4 bytes all seems good, but when we called myfunc() the difference between : &i , __builtin_frame_address turned to be 8 bytes
i didn't get that behavior, and could u send the link related to this video -of using these commands-.

Ответить
Taieoo
Taieoo - 08.10.2022 18:09

ALL I CAN SAY IS THANK YOUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU.

Ответить
yj c
yj c - 26.08.2022 16:05

great video!

Ответить
Smrt fašizmu
Smrt fašizmu - 01.05.2022 15:52

I did not understand how stack frames work, how stack, base and instruction pointers work until I looked at the assembly and then wrote a couple of functions in assembly myself. I was then surprised to find out that first two arguments of a function in my windows PC go into ecx and edx registers while on my Ubuntu they go to esi and edi registers. Both my Ubuntu and my windows compiler put the return value into eax register though. Ubuntu compiler doesn't decrease the stack pointer if it is a leaf function which uses less than 128 bytes (I then found out that these 128 bytes for a leaf function was called the red zone).
My Windows PC doesn't seem to have this red zone, but windows compiler sometimes puts a local variable on the other side of the base pointer (positive ofset from base pointer instead of negative offset) which never happens on my Ubuntu PC. When I write assembly I always decrease the stack pointer and put local variables in the negative offset, both when I am on Ubuntu and when I am on Windows).
Even these little things that I learned about how functions work on my Ubuntu I wouldn't know without looking at the assembly. And the reason why I learned this is because it bugged me that I didn't understand how function calls work under the hood.

Ответить
Your Linux Guy🐧
Your Linux Guy🐧 - 31.03.2022 11:53

Good, video was complicated for me, you made it easy.💕

Ответить
Asmit Pandit
Asmit Pandit - 05.03.2022 03:41

Dude ! You are an amazing instructor !! Have you already created a video where you walk the stack to find the stack trace ? If no, humbly requesting you to :)

Ответить
john smith
john smith - 01.02.2022 22:57

666 base stack memory 667 neighbor of the beast stack overflow by 1

Ответить
bretzel30000
bretzel30000 - 15.01.2022 12:44

In the illustration of the stack and the heap an so on, there is a little gap above the stack. Whats that?

Ответить
Jayo Caine
Jayo Caine - 01.10.2021 17:56

No, a stack over flow is a website where people tell you someone already asked that question

Ответить
Alex Bar
Alex Bar - 14.09.2021 01:21

How to count the number of stack frames in Stack RAM just looking at stack RAM values?

Ответить
ThatKeffordGuy
ThatKeffordGuy - 09.09.2021 21:02

I really liked seeing you using lldb, that was insightful!

Ответить
The Minds Playground
The Minds Playground - 27.08.2021 21:57

Awesome, video. Love when you matter-of-factly state the hex addresses are going up and down. Not everyone reads hex bro 😂. Still, hyper useful tutorial.

Ответить
santosh pai
santosh pai - 21.05.2021 13:39

Wow what an amazing video , super helpful channel !!

Ответить
cmdLP
cmdLP - 12.05.2021 11:02

Runtime stacktrace library please.

Ответить
Mahmoud Yasser
Mahmoud Yasser - 26.03.2021 04:10

Great video

Ответить
Carson Holloway
Carson Holloway - 08.02.2021 11:49

Do you think you could make one on setjmp.h? I recently found some code with it, and was really confused about how it worked and what it was doing. Thanks

Ответить
Jakob Fredriksson
Jakob Fredriksson - 13.01.2021 10:28

There's a difference between knowing a subject and understanding it and Jacob, even though his name isn't spelled with 'k', understands what he's talking about. That makes such big difference; that's why I've learned more about C programming watching his stuff for two days than other stuff for two months. Subscriber (since two days) !

Ответить
Sumit Bhosale
Sumit Bhosale - 12.01.2021 13:24

Can you please explain " search.h " header file in c programming.

Ответить
souptender panini
souptender panini - 07.01.2021 20:19

HE'S ALIVE!

Ответить
Jonatan Sciaky
Jonatan Sciaky - 03.01.2021 11:46

it worrying how much you look like and talk like Matthew McConaughey

Ответить
Rafal Michalski
Rafal Michalski - 30.12.2020 00:23

Hello Jacob. Very interesting material as usual. Go ahead and make material about "Calling Conventions" as it is next interesting topic in my opinion.

Ответить
potre schmotre
potre schmotre - 27.12.2020 10:05

Your channel is exceptional. Please keep up the good work!

Ответить
Alex Bar
Alex Bar - 27.12.2020 01:28

Dear Jacob,
Thanks a lot for the tutorial.

1 What happens in the process (or in firmware) before main() launches?
2 Who determines the order of initialization of global variables (in case of int g_val=foo();)?
3 What code copies the return address onto the stack frame?
4 Can a C function at runtime determine whether it has been called recursively just by exploring values in RAM stack?

Regards,
AB

Ответить
Benjamin Shinar
Benjamin Shinar - 24.12.2020 09:49

great video as always!
question: I know that there's a 'randomize memory' option for the virtual memory of the process, how does it mesh with stack addresses and stuff?

Ответить
TheCocoaDaddy
TheCocoaDaddy - 24.12.2020 01:04

Awesome video! I really like how you explain these concepts. Question: do you ever discuss how things, like stack overflows, stack 'crushing', or buffer overflows can be used for hacking purposes? I don't mean from a "here's how you do it" perspective but from a "how it can be exploited" perspective? Or maybe even that might be too close to "how to do it". lol Anyway, thanks for posting!

Ответить
vanowik
vanowik - 23.12.2020 23:40

Your videos are amazing. What kind of environment are you using for your C project?

Ответить
Ranjith Kumar
Ranjith Kumar - 23.12.2020 20:07

Hi Jacob, Why the frame address can be in the middle sometimes?

Ответить
mohammed zaid
mohammed zaid - 23.12.2020 20:03

thank you so much making videos like this and i am getting 100% fruitful from your videos!!!

Ответить
mohammed zaid
mohammed zaid - 23.12.2020 20:02

aah another thing
that you always says "that is topic for another video" or "i will talk about in future" some time you talk but most videos i anticipating are not shared

Ответить
mohammed zaid
mohammed zaid - 23.12.2020 19:56

if you can please can you make videos about in-depth usage about gdb. i mean how to use gdb more efficiently and advance feature from the beginning.

Ответить
yout ube
yout ube - 23.12.2020 19:50

I once had an actual stack overflow problem and went to try and google about it but kept finding unrelated results on Stack Overflow : (

Ответить
George B.
George B. - 23.12.2020 19:26

Very interesting. Thank you for the lesson. Thanks to you I've been writing a lot more examples in C lately, you motivated to go back and write some data structures from scratch and actually understand them better than just calling a new List<T> for literally every need.

Ответить
BBQ
BBQ - 23.12.2020 19:22

Now this is oddly convenient. I have been trying to implement a way to manually create stack frames all day. Those pesky segmentation faults and bus errors just keep on coming.

Ответить
Travis
Travis - 23.12.2020 18:57

I haven't coded in a long time. Got let go when the pandemic started then developed a movement disorder. Your videos will be nice as a quick refresher.

Ответить
A29sTech
A29sTech - 23.12.2020 18:38

I'm glad to get a tutor like you.
You are a great tutor I ever seen.
You make complex concept easy to understand.
🙏 Thank you so much 🙏

Ответить
Selim Enes Karaduman
Selim Enes Karaduman - 23.12.2020 17:25

Hello Jacob Sorber, do you think Rust will kill c/c++? Even if c/c++ used in many important software and IoT devices, I see many comments about Rust is going to replace c/c++ in the future because of its memory-safety. There are other memory-safe languages like go/java/D but they are slower than c/c++. However, It's said Rust is as fast as C/C++ and memory-safe, how is this possible? Other languages lose their speed for security but Rust doesn't, can you make a video about these topics

Ответить
Funhuninja Studio
Funhuninja Studio - 23.12.2020 17:03

It's been a long time since the last video... Happy to see another one :)

Ответить
SlowSunsetVibes
SlowSunsetVibes - 23.12.2020 17:03

Coming in clutch, jacob! I started researching the call stack in more depth recently and you just uploaded this. Thanks so much man! Wishing you a great christmas and a happy new year

Ответить