Тёмный

Your Computer is Lying To You (Virtual Memory) 

Jacob Sorber
Подписаться 165 тыс.
Просмотров 17 тыс.
50% 1

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 33   
@umpoucosobreconhecimentos
@umpoucosobreconhecimentos 2 года назад
I am learning a lot with your low level code explanation videos. It is very useful to me. Thank you very much
@JacobSorber
@JacobSorber 2 года назад
You are welcome! Glad I could help.
@olegfare4625
@olegfare4625 2 года назад
you are hands down the best youtuber when it comes to explaining C coding , memory and computer science overall for beginners like me! the clearest explanation possible! huge thanks from Russia
@tranqilo6453
@tranqilo6453 2 года назад
Best Comp Sci professor I have never paid for, thanks for sharing your knowledge sir.
@KangJangkrik
@KangJangkrik 2 года назад
You paid him with ads, by the way
@georgecop9538
@georgecop9538 2 года назад
Yeah, OSes provide a lot of abstractions *eg. device drivers* from the core functions like inb(),outb() or memset()
@Gauthamphongalkar
@Gauthamphongalkar Год назад
Hi Jacob, Big fan of you! I have question if address are virtual then why we bothering about memmove of address overlapping.. it will be translated by MMU right?
@raghavsrivastava2910
@raghavsrivastava2910 2 года назад
How are you running macOS and Linux together, are you using a remote machine? Also why the compiler chooses address for x so big, it can even choose something like 0x1 or 0x2 or whatever (I know choosing such big addresses doesn’t make the os allocate tonnes of memory [learned from one of your video]). Thanks in advance, amazing video.
@LFSDK
@LFSDK 2 года назад
A program’s memory is divided into segments which have pretty standard placememts in virtual memory. To make sure null pointers cause segfaults the area around zero (small addresses) is left unallocated. And you lose nothing by using big addresses rather than small addresses since virtual memory mapping (stored in tables in memory managed by the OS) also divides the address space (both virtual and physical) into pages that make small and high addresses the same. So, using bigger numbers is really just a convention that we stick to.
@JacobSorber
@JacobSorber 2 года назад
What LFalch said. And, I'm running macOS natively, and Linux on a virtual machine, using vagrant/virtualbox.
@raghavsrivastava2910
@raghavsrivastava2910 2 года назад
Thank you @LFalch , @Jacob Sorber ❤️
@funkykong9001
@funkykong9001 2 года назад
What Linux distro are you using? On my Ubuntu 21.10, the address of x does change every run. However, if I build with "-Wl,--no-pie", then yes, it's a static address each run, so I think your results are highly dependent on what default compiler/linker options your Linux distro is using.
@JacobSorber
@JacobSorber 2 года назад
I was using Ubuntu 20.04.3. But, yes, good point. It's not a Linux/macOS thing as much as an OS/compiler/linker thing. Those were just the two environments that I had handy.
@foadsf
@foadsf 2 года назад
do you got Twitter? I tried searching for you with no avail. just wanted to let you know that you are awesome man. I love your C videos. please keep up the good work. 🖖
@tanchienhao
@tanchienhao Год назад
Awesome video
@hakimcherfi217
@hakimcherfi217 2 года назад
Awesome video !
@JusticeNDOU
@JusticeNDOU 2 года назад
source code available during office hours at , that was what came to mind when listening to this, i cant seem to figure out why , can someone help ?
@krumpy8259
@krumpy8259 2 года назад
This is so low level that I missed bad paintings for better understanding
@XenoTravis
@XenoTravis 2 года назад
Jokes on it, I manipulate the crap out of it everyday! We have a very abusive relationship
@monad_tcp
@monad_tcp 2 года назад
4:22 mostly, the system tries to do that, the hardware MMU helps a bit, but it eventually fail, and the machine can crash, although rarely
@mr.mirror1213
@mr.mirror1213 2 года назад
Iirc, the operating system dispatches page tables unique to a process and when ever you access a memory, the mmu walks the page table to give you the data
@smrtfasizmu6161
@smrtfasizmu6161 2 года назад
I didn't notice that compiler always puts variables on the same addresses so I always wondered how buffer overflow attacks are done. I have watched some video about it and I never understood how you know with what number to overwrite the place on the stack where the previous instruction pointer is.
@mehregankbi
@mehregankbi 2 года назад
my question is, why doesn't realloc always return the same pointer? so let's say we need 2MB of memory but there is not a chunk available on our physical memory, so our data is moved further. but all that needs to be changed is the virtual address to physical address map. similarly, this could be done for the variables in stack too. right?
@wumi2419
@wumi2419 2 года назад
I'd assume virtual to physical address maps are using page addresses or even bigger blocks, so it's basically impossible to move small memory blocks. I also don't know much about structure of processor and/or memory, which i will hopefully learn more about later.
@ohwow2074
@ohwow2074 2 года назад
Yes. Now my question too. Why doesn't OS return the same address to the program every time realloc is called??
@DaNinjasDen
@DaNinjasDen 2 года назад
Likely because it couldn't fit in the virtual address space. If you have an allocation at 0x4 of size 2 and an allocation at 0x6 of size 2, then if you realloc the 0x4 alloc to a size of say 10 it would be overlapping with the other alloc if it used the same base address,so it returns a different address
@mehregankbi
@mehregankbi 2 года назад
@@DaNinjasDen oh thx for the explanation. it makes sense now. since pointer arithmetics are done on the virtual address, you have to change the virtual address too.
@ohwow2074
@ohwow2074 2 года назад
@@DaNinjasDen let's assume that there is no data in 0x6. Then if we want to extend the block that starts at 0x4 by another 2 bytes (total size will be 4) then will the OS decide to keep the original block in its place and add the required 2 bytes to it by allocating 0x6 and 0x7 to the original block??
@arrahul316
@arrahul316 2 года назад
Great!!!!!!!!!!!!!!!!
@dwaynestgeorge2558
@dwaynestgeorge2558 Год назад
Thanks
@xrafter
@xrafter 2 года назад
Fing OSs lying to us all the time🤬
@starc0w
@starc0w 2 года назад
Top! Thanks!