{"action":"created","issue":{"url":"https://api.github.com/repos/phil-opp/blog_os/issues/126","labels_url":"https://api.github.com/repos/phil-opp/blog_os/issues/126/labels{/name}","comments_url":"https://api.github.com/repos/phil-opp/blog_os/issues/126/comments","events_url":"https://api.github.com/repos/phil-opp/blog_os/issues/126/events","html_url":"https://github.com/phil-opp/blog_os/issues/126","id":129527242,"number":126,"title":"AreaFrameAllocator no longer safe to use after remapping the kernel","user":{"login":"mmalone","id":6750,"avatar_url":"https://avatars.githubusercontent.com/u/6750?v=3","gravatar_id":"","url":"https://api.github.com/users/mmalone","html_url":"https://github.com/mmalone","followers_url":"https://api.github.com/users/mmalone/followers","following_url":"https://api.github.com/users/mmalone/following{/other_user}","gists_url":"https://api.github.com/users/mmalone/gists{/gist_id}","starred_url":"https://api.github.com/users/mmalone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmalone/subscriptions","organizations_url":"https://api.github.com/users/mmalone/orgs","repos_url":"https://api.github.com/users/mmalone/repos","events_url":"https://api.github.com/users/mmalone/events{/privacy}","received_events_url":"https://api.github.com/users/mmalone/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-01-28T18:00:47Z","updated_at":"2016-02-01T18:08:29Z","closed_at":null,"body":"The `AreaFrameAllocator` is unsafe to use after kernel remapping because it references the multiboot information structure, which is not remapped. I'm not sure what your next steps are (it's possible this is by design) but this took me a hot second to debug once I got through your last post and started off on my own adventures. If other people are having similar problems you have a couple choices:\r\n- Stop using the AreaFrameAllocator and us some other FrameAllocator after the kernel remap\r\n- Remap the multiboot header in `remap_the_kernel`, like you did the VGA buffer\r\n\r\nYou already have a reference to the `boot_info` object in remap_the_kernel, so you can use that for the remap. It's a bit ghetto, but here's a quick implementation of the latter option:\r\n\r\n```rust\r\nlet boot_info_frame = Frame::containing_address(boot_info as *const _ as usize);\r\nmapper.identity_map(boot_info_frame, PRESENT, allocator);\r\n```\r\n "},"comment":{"url":"https://api.github.com/repos/phil-opp/blog_os/issues/comments/178103578","html_url":"https://github.com/phil-opp/blog_os/issues/126#issuecomment-178103578","issue_url":"https://api.github.com/repos/phil-opp/blog_os/issues/126","id":178103578,"user":{"login":"phil-opp","id":1131315,"avatar_url":"https://avatars.githubusercontent.com/u/1131315?v=3","gravatar_id":"","url":"https://api.github.com/users/phil-opp","html_url":"https://github.com/phil-opp","followers_url":"https://api.github.com/users/phil-opp/followers","following_url":"https://api.github.com/users/phil-opp/following{/other_user}","gists_url":"https://api.github.com/users/phil-opp/gists{/gist_id}","starred_url":"https://api.github.com/users/phil-opp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phil-opp/subscriptions","organizations_url":"https://api.github.com/users/phil-opp/orgs","repos_url":"https://api.github.com/users/phil-opp/repos","events_url":"https://api.github.com/users/phil-opp/events{/privacy}","received_events_url":"https://api.github.com/users/phil-opp/received_events","type":"User","site_admin":false},"created_at":"2016-02-01T18:08:29Z","updated_at":"2016-02-01T18:08:29Z","body":"Another thought: Maybe the other alternative is easier after all:\r\n\r\n>Stop using the AreaFrameAllocator and use some other FrameAllocator after the kernel remap\r\n\r\nWe could just add a new `FrameAllocator` such as the following:\r\n\r\n```rust\r\nuse core::ops::Range;\r\n\r\nstruct RangeFrameAllocator {\r\n    free_areas: [Option<Range<Frame>>; 10],\r\n}\r\n\r\nimpl FrameAllocator for RangeFrameAllocator {\r\n    fn allocate_frame(&mut self) -> Option<Frame> {\r\n        for area_option in &mut self.free_areas {\r\n            if let Some(Range{start: Frame {number: start}, end: Frame {number: end}}) = *area_option {\r\n                if start == end {\r\n                    *area_option = None;\r\n                }\r\n            }\r\n            if let Some(ref mut area) = *area_option {\r\n                let frame = area.start.clone();\r\n                area.start.number += 1;\r\n                return Some(frame);\r\n            }\r\n        }\r\n        None\r\n    }\r\n}\r\n```\r\n\r\nIt has room for 10 memory areas which should be more that needed for most (all?) systems. We could take the old frame allocator by value in `remap_the_kernel` and return the new one, which we create just before switching tables."}}