{"id":2019,"date":"2018-12-16T13:44:36","date_gmt":"2018-12-16T13:44:36","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=2019"},"modified":"2025-06-11T10:10:22","modified_gmt":"2025-06-11T10:10:22","slug":"architecture-and-assembly-language-basics","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=2019","title":{"rendered":"Memory Management (Basics)"},"content":{"rendered":"<h2>Process<\/h2>\n<p>Each process is running on its own virtual address space. The MMU does the necessary translation from\/to the physical address space. Every thread within a process has its own stack.<\/p>\n<h3>Address space<\/h3>\n<pre>\r\nHigh address |-------------------| 0xFFFFFFFFFFFFFFFF*\r\n             |                   |\r\n             |   Kernel space    |\r\n             |                   | 0xFFFF800000000000*\r\n             |-------------------|\r\n             |                   | 0x00007FFFFFFFFFFF*\r\n             |    User space     |\r\n             |                   |\r\nLow address  |-------------------| 0x0000000000000000*\r\n                    Process\r\n\r\n* AMD64\/x86-64 (Invalid: 0x0000800000000000 - 0xFFFF7FFFFFFFFFFF)\r\n<\/pre>\n<h3>User space<\/h3>\n<pre>\r\nHigh address |-------------------| 0x00007FFFFFFFFFFF*\r\n             | Command Line Args |\r\n             |-------------------|\r\n             | Stack (Thread 0)  |\r\n             |-------------------|\r\n             |         \u2193         |\r\n             |-------------------|\r\n             | Stack (Thread N)  |\r\n             |-------------------|\r\n             |         \u2193         |\r\n             |                   | \/|------|\r\n             |-------------------|\/ | Data |\r\n             | Shared library 0  |  |------|\r\n             |-------------------|\\ | Code |\r\n             |       ...         | \\|------|\r\n             |-------------------|\r\n             | Shared library N  |\r\n             |-------------------|\r\n             |                   |\r\n             |         \u2191         |\r\n             |-------------------|\r\n             |       Heap        |\r\n             |-------------------|\r\n             |       Data        |\r\n             |-------------------|\r\n             |       Code        |\r\nLow address  |-------------------| 0x0000000000000000*\r\n                    Process\r\n\r\n* AMD64\r\n<\/pre>\n<hr>\n<h2>Stack<\/h2>\n<p>With every function call a new stack frame gets created for the callee on the stack and as soon as it returns to the caller function that stack frame has been destructed.<\/p>\n<pre>\r\n                       (High address) \/|----------------------|\r\n                                     \/ | Caller-saved Reg [1] |\r\n                                    \/  |----------------------|\r\n                                   \/   |      Argument 1      |\r\nHigh address |---------------|    \/    |----------------------|\r\n             | Stack Frame 0 |   \/     |      Argument 0      |\r\n             |---------------|  \/      |----------------------|\r\n             | Stack Frame 1 | \/       |   Caller Ret Addr    | (Old RIP)\r\n             |---------------|\/        |----------------------|\r\n             | Stack Frame 2 |         |   Caller Base Ptr    | (Old RBP)\r\nLow address  |---------------|\\        |----------------------| <-- Base Pointer\r\n                  Stack        \\       | Callee-saved Reg [2] |        (RBP)\r\n                    \u2193           \\      |----------------------|\r\n              Grow direction     \\     |     Local Var 0      |\r\n                                  \\    |----------------------|\r\n                                   \\   |     Local Var 1      |\r\n                                    \\  |----------------------|\r\n                                     \\ |     Temp Objects     |\r\n                        (Low address) \\|----------------------| <-- Stack Pointer [3]\r\n                                            Stack Frame 2               (RSP)\r\n<\/pre>\n<p>[1] Cached by the caller if it wants the old state later on.<br \/>\n[2] Cached by the callee if it wants to use them by their own.<br \/>\n[3] Points to the top of the stack of the selected thread.<\/p>\n<p><strong>Disclaimer<\/strong><\/p>\n<ul>\n<li>The used register names are from the x86-64 Architecture.<\/li>\n<li>In a gdb backtrace the frames are in the opposite order.<\/li>\n<\/ul>\n<hr>\n<h2>Heap<\/h2>\n<p>The data on the heap isn't as moderated and strictly structured as the one on the stack. You even have to clean up by yourself, if you haven't got a garbage collector.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Process Each process is running on its own virtual address space. The MMU does the necessary translation from\/to the physical<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[28],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/2019"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2019"}],"version-history":[{"count":12,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/2019\/revisions"}],"predecessor-version":[{"id":17943,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/2019\/revisions\/17943"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2019"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}