{"id":287,"date":"2007-10-24T00:21:59","date_gmt":"2007-10-24T04:21:59","guid":{"rendered":"http:\/\/journal2.alanv.org\/?p=287"},"modified":"2012-10-07T22:24:21","modified_gmt":"2012-10-08T02:24:21","slug":"os-2","status":"publish","type":"post","link":"https:\/\/journal2.alanv.org\/?p=287","title":{"rendered":"OS"},"content":{"rendered":"<p>Last night I was up coding until 7 AM. A lot of the time was spent fixing compiler errors, and then tracking down a bug caused by using the wrong variable in one place, causing page table entries to get overridden&#8230; causing problems later.<\/p>\n<p>Today, it was my turn to have a huge bug in my code, and mine was a conceptual error (although, to be fair, it was one both of us missed).<br \/>\nWe decided to start the first two tasks for the kernel by writing a kernelland fork function, which works much like the user version. The user version copies over all of memory except for kernel memory, creating a new kernel stack for the child and putting only the necessary stuff on there (IRET foo and registers).<br \/>\nI did the same thing for the kernel version, except I don&#8217;t copy any memory (since there is nothing in userspace yet). I create a new kstack and copy over only the necessary values&#8230; the return address (to return to the previous calling function) and registers.<\/p>\n<p>See the problem yet?<\/p>\n<p>Turns out I forgot to take into account that execution in kernelland uses the kstack&#8230; and so maybe continuing execution in kernelland (as we do by using the same return address) would need things on the stack. As a result, we kept getting the strangest errors where memory was being overridden in various ways (since the function we return to expects certain things at esp+16, and expects ebp+4 to have arguments and such). So yeah. That bug took a good 3 hours to track down. Oops.<\/p>\n<p>I had a Google interview today. I feel like I did well at the data structures\/coding portion, but I completely bombed the algorithms part. It seriously makes me wonder how I managed to get an A in algo class. Or maybe I&#8217;ve just forgotten everything since then. Meh.<\/p>\n<p>Whee&#8230; now it&#8217;s time to debug userspace exec and fork. Fun fun fun?<\/p>\n<p><strong>Edit:<\/strong> 5:30 AM. Looks like it&#8217;s going to be another all-nighter. We really should start working more earlier in the week so we&#8217;re not stuck doing a bunch of stuff the night of the deadline.<\/p>\n<p><strong>Edit edit:<\/strong> 6 AM and fork works! Huzzah. Turns out the problem wasn&#8217;t at all in my code (which was surprisingly, given the complexity of the mapping of multiple physical pages into and out of a virtual address space, correct the first time) but rather with the TLB keeping around &#8220;stale&#8221; entries. Oops. Now let&#8217;s get exec working (and maybe bed after that).<\/p>\n<p><strong>Edit edit edit:<\/strong> 9 AM. Mission failed. We didn&#8217;t manage to get exec working (although it now does return to userland and run for a bit, albeit incorrectly, before being context-switched away and page faulting on its next run). Hopefully we&#8217;ll have it done today.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last night I was up coding until 7 AM. A lot of the time was spent fixing compiler errors, and then tracking down a bug caused by using the wrong variable in one place, causing page table entries to get &hellip; <a href=\"https:\/\/journal2.alanv.org\/?p=287\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,10],"tags":[],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-code","category-os"],"_links":{"self":[{"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/posts\/287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=287"}],"version-history":[{"count":0,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/posts\/287\/revisions"}],"wp:attachment":[{"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}