WEBVTT 1 00:00:02.220 --> 00:00:15.540 William Cheng: Welcome to Week 10 discussion section. So if you go to the web page. We're going to sort of talk about a bunch of stuff. So last time. Last time we 2 00:00:16.350 --> 00:00:22.530 William Cheng: Gave you a introduction to Colonel three and also look at some of the code in elf 30 to see 3 00:00:23.250 --> 00:00:30.450 William Cheng: Those code called those VM app functions and also we look at access that see which look at the 4 00:00:30.960 --> 00:00:39.360 William Cheng: Permission. You know functions and also there are those functions that are important like copy from user copy to user, so. So this time we're not going to 5 00:00:39.870 --> 00:00:47.430 William Cheng: Talk about those anymore I copied this over here to a text file here so we can just have easy access to that. 6 00:00:48.090 --> 00:00:55.110 William Cheng: And so I guess you know so. So this is from last time. Right, we talked about P frame stuff so I can, you know, get rid of them. We don't need them anymore. 7 00:00:55.710 --> 00:01:00.510 William Cheng: We also talk about the address space implementation. I mean, even though I didn't go through any detail. 8 00:01:00.930 --> 00:01:06.540 William Cheng: About exactly, you know how to implement all these functions. So we got you should look at the comment blog. 9 00:01:07.140 --> 00:01:13.590 William Cheng: The important thing is to make the connection between this code and also the code in the in the loader, which is an elf 32 10 00:01:14.070 --> 00:01:23.040 William Cheng: Okay, so you do have 32 when they call this function, they are creating the address space. So the first thing that a loader will do is to read the 11 00:01:23.790 --> 00:01:31.590 William Cheng: The, the executable file and then parse incredible power and try to sort of figure out how to build the address space and so get all these called are written for you already. 12 00:01:31.800 --> 00:01:42.060 William Cheng: All they have to do is to make all these function call over here. So you have to implement this function to build that link list of VM area right so VM area. Every VM area represent a 13 00:01:42.780 --> 00:01:48.930 William Cheng: Memory segments or there's to be text that memory attacks admin. This could be data plus BSS there's a stack segment. 14 00:01:49.890 --> 00:01:58.350 William Cheng: You won't get a heap segment until you do Malik right so in the beginning, the first year program. They don't demand. So therefore, in that case is you only end up with three memory segments again. So again, 15 00:01:59.250 --> 00:02:05.550 William Cheng: I mentioned before, when you get your first legitimate page fall, you should print out your address space and then post it into the classroom grow grew 16 00:02:06.090 --> 00:02:12.330 William Cheng: tell other people what you get and see whether you're getting the same thing. Yeah. Alright, so I'm going to also get rid of this. 17 00:02:13.050 --> 00:02:24.270 William Cheng: So last time we also talked about access dicey right range permission range permission. The for hello to work. We don't need sis re. We don't need system right 18 00:02:24.900 --> 00:02:27.840 William Cheng: So today we're basically then probably you know some of these other functions. 19 00:02:28.410 --> 00:02:37.590 William Cheng: A little more on handle page ball a little ball on the SIS right function and then they're all these anonymous object. So let's first talk about the anonymous object over here. 20 00:02:38.160 --> 00:02:45.810 William Cheng: So remember the Anonymous. Anonymous object. It's probably multi object, right, because there are three types of anonymous object we have to handle internal three 21 00:02:46.230 --> 00:02:53.400 William Cheng: The anonymous object, the shadow object and also the the MO VJ than that inside of vino 22 00:02:53.880 --> 00:03:03.720 William Cheng: Okay, so, so all these three, you know, you know, all these three objects. They're all memory management object. So one thing that you should do is to look at the header for the memory management object. 23 00:03:04.320 --> 00:03:15.390 William Cheng: So that's in colonel. Mm hmm. Or VJ sorry Colonel include. Mm hmm LBJ ah so here is the memory management object. 24 00:03:16.350 --> 00:03:22.020 William Cheng: So the memory management, our deck is the one that has a reference count. Right. So I think last time I sort of mentioned it as 25 00:03:22.980 --> 00:03:25.350 William Cheng: I mentioned that the PageRank doesn't really have a reference count. 26 00:03:25.830 --> 00:03:37.260 William Cheng: So, therefore, is it turns out it's the memory management object as a reference count. Okay. So, this way we can actually have multiple user processes share the same memory management object and the memory management is the one that managed page brain. 27 00:03:37.800 --> 00:03:43.770 William Cheng: Cells. So this case all these different process, he will be able to share the same page right now. So I'll get the ref count is actually right here. 28 00:03:44.370 --> 00:03:59.970 William Cheng: There's a, you know, M. M. O. P. S. Or again anytime you see underscore PS. That's the real function pointers over here. Alright, so, so again, there's a real function pointer. There's number or resident pages and we mentioned before, you know, when a 29 00:04:01.170 --> 00:04:09.360 William Cheng: You know, when it, when a memory management object, you know, try to manage some with some of the pain. Some of them a memory resident and some of them not memorize, then 30 00:04:09.810 --> 00:04:15.900 William Cheng: If you are the bottom object of the button object know how to create those objects chatter object and only two copies. Right. Yeah. 31 00:04:16.440 --> 00:04:27.060 William Cheng: So over here. Mmm. Oh, and read pages that's keeping track of the number of Resident pages over here. And then there's a list of all these registered and roses and pages and then 32 00:04:27.720 --> 00:04:36.930 William Cheng: There's a union over here. So, so if you are not familiar with. See the Union data structure, meaning that it's a data source that can hold to dip and you know you can get a hold two different things. 33 00:04:37.290 --> 00:04:43.410 William Cheng: You, it's either either one of them, or the other thing, whereas over here. The first thing is less. And the second one is a pointer. 34 00:04:43.920 --> 00:04:55.920 William Cheng: So, so this data structure can hold either one of them. So you need other part of the data structure in order for us to try to figure out exactly, you know, are you using are you using this feel as either MMR VM as or the 35 00:04:56.400 --> 00:05:04.590 William Cheng: Bottom objects. Okay, so get over here. There's some explanation of what this you know what this particular point is okay. 36 00:05:05.430 --> 00:05:11.460 William Cheng: All right. And finally, there's a shadow that has appointed the point of the next mmm will be gay. So this is the next point or 37 00:05:11.940 --> 00:05:22.350 William Cheng: In the linguists. Okay. So over here, for some reason, they decided not to use a double living circular list because this is a single event. So therefore, all you need to do is to have a next point or another object. 38 00:05:23.190 --> 00:05:34.560 William Cheng: Or so this is the mmm LBJ and then here is the real function pointer. Right. There's the ref assumption module. So you can implement the reference cow on the shadow on the anonymous or on the enemy will be 39 00:05:34.920 --> 00:05:45.780 William Cheng: Inside inside of me know you can document the reference count. There's a function called look up page, whereas it again. You know, so look at page is the one that you you try to find a page frame object. 40 00:05:46.230 --> 00:05:52.830 William Cheng: So you can see that the last argument over here. It struck page rank, star, star by now you should be very familiar with, you know, 41 00:05:53.100 --> 00:05:59.370 William Cheng: With with a call that looks like two stars. Typically I mean not guarantee. But typically, that's a return value. 42 00:05:59.970 --> 00:06:11.700 William Cheng: Okay. So this guy's again, this function is going to return a page spread. So given the given the memo BJ and the page DOM. So I think in the last discussion section I went over, you know, 43 00:06:13.950 --> 00:06:24.570 William Cheng: All those slides about you know the the page. Now, maybe I'm LBJ again this is the function, they will you are used to look up a particular page were given an MMA LBJ and given a page. Now, you know, return a page, right. 44 00:06:25.620 --> 00:06:35.460 William Cheng: Now, so this is known as a look up on Sriracha, the function is like a lookup table, given a key you tried to look for value. So in this case, the key has two parts. One is the MO BJ and the other ones as 45 00:06:35.970 --> 00:06:44.490 William Cheng: Well, as it turns out that, you know, depends on whether you're doing reading or writing, you know, you're going to get a different different page rank, because remember that when 46 00:06:45.360 --> 00:06:52.350 William Cheng: We perform reading, we need to follow the algorithm go down the list of shadow objects in that case what we try to look up a pretty good Facebook page, right. 47 00:06:52.770 --> 00:07:01.110 William Cheng: When you're looking things up for righty, well you know you feel memory segment is private then whenever you try to write, you always right into the first 48 00:07:01.830 --> 00:07:09.030 William Cheng: You always writing to the first you know shadow object, right, because everything below the first object. They're all consider read only. 49 00:07:09.900 --> 00:07:15.000 William Cheng: OK. So again, this for right over here, you know, makes difference. Yeah. And then there are these three function. 50 00:07:15.750 --> 00:07:20.790 William Cheng: Is what Caulfield page, so, so, so, so, given a you know a 51 00:07:21.240 --> 00:07:28.830 William Cheng: Do that mmm ob gyn and also keeping pace. Right. So inside a page rank and also have a self identifying information to say that this page rain. 52 00:07:29.070 --> 00:07:36.300 William Cheng: What is the key to get to this page rain. Right. But again, the key will be mo BJ followed by page now that. So in this case, we're going to throw 53 00:07:37.140 --> 00:07:41.160 William Cheng: In this case, we're going to ask this mm LBJ to fill this page rank. 54 00:07:42.150 --> 00:07:51.690 William Cheng: Whereas, what does the Philippines frame, right. So, again, for you know for for for anonymous object you create a page rank you fill it with zero for the 55 00:07:52.110 --> 00:07:57.780 William Cheng: The one that's inside the vino why that case you don't know how to do it right. So, therefore, you need to ask the lower level of the process them. 56 00:07:58.140 --> 00:08:01.470 William Cheng: To fill that page. So in this case, I think it's going to reach the 57 00:08:02.130 --> 00:08:10.320 William Cheng: Either the device driver or reach some kind of a block device interface or something. That's okay. It's a lower level of the deposit Sam will know how to fill a page, right. 58 00:08:11.010 --> 00:08:18.870 William Cheng: So again, the idea of building a page rank for the vino is to go to the desk. Get that paid from the business and then copy of a copy. That means to the page way. Okay. 59 00:08:19.500 --> 00:08:32.130 William Cheng: So, so, so, so of course our code doesn't know how to do it because that involves device driver and also the, the, the, the, the, the, I guess it's called IO management or something where I basically the lower level, the load of these data file system. 60 00:08:33.750 --> 00:08:44.280 William Cheng: Philippines can also be done by the shadow object, the object will be doing copy on write right because the way you sort of fill a page is that you find the why you need to copy from and then you fill it. I'm making a copy of that. 61 00:08:45.120 --> 00:08:57.360 William Cheng: 30 page is to make a page dirty. So again, you know, read this girl, you know, the comment over here so happens that you know when you modify a patient, you want to say that this page right now is different from what's on 62 00:08:58.320 --> 00:09:04.050 William Cheng: What's on this. So, therefore, you need to dirty this piece right okay we mentioned before about the 63 00:09:05.400 --> 00:09:10.620 William Cheng: The, the, the page on demand. When the page. I did find a page frame that's not recently used 64 00:09:10.890 --> 00:09:21.300 William Cheng: It will, it will need to check to see if the patient is dirty in the page them is not dirty wanting that case that patient has exactly the same data as well as on this. So in that case, you can just bring it up and return it to the buddy system. 65 00:09:21.750 --> 00:09:26.580 William Cheng: Okay. Otherwise, you need to write it out to the desert. So, therefore, you know, the dirty page over here, you know, 66 00:09:27.420 --> 00:09:34.440 William Cheng: Will will actually made a piece frame object pajamas dirty. So this way you know the page on demon will know what to do. Yeah. 67 00:09:35.010 --> 00:09:46.680 William Cheng: I don't need to keep clean page. So this one you can paste function, make the page clean. How do you make the page clean. Right. So in this data, this page right it's different from what's on the desk, one in a clean pages that you write it out to a desk. 68 00:09:47.880 --> 00:09:55.290 William Cheng: That. So for the, the three top of Ma ma BJ. As it turns out that you're one of them has already implemented for you. 69 00:09:55.770 --> 00:10:03.630 William Cheng: So that will be the one that's the enema, we did that, is that have enough, right, you have to write all the code for the anonymous object and also for the shadow on 70 00:10:04.170 --> 00:10:14.730 William Cheng: There but luckily the wind in the veto is in Colonel FS vino mm LBJ LPS. Okay, so this is the one that has all those functions. 71 00:10:15.030 --> 00:10:25.740 William Cheng: That has the implementation. So if you open this one so I guess I'll be here. I also mentioned that right will be here. The colonel. This is the father. You need to look at this is the code for Mo, mo BJ that's inside the vino 72 00:10:26.820 --> 00:10:31.800 William Cheng: Now, so let's take a look at it. Right. These are all the function that we mentioned before, there's a ref 73 00:10:32.550 --> 00:10:43.020 William Cheng: There is the unwrapped so we're here, you can see that, you know, so again, this is the polymorphous ref Matt since this is the one that's inside of vino as simply use JIRA right use the Venus function. 74 00:10:43.230 --> 00:10:54.450 William Cheng: At the increment the reference cow or if you have a detrimental reference combine these guys, you know, you use the Dinos you know people function there. So this is how it's done. How do you look up a page. Okay, it's over here at first. 75 00:10:56.280 --> 00:11:06.900 William Cheng: He tried to make sure that the page now is valid. If the page down is invalid one and this function. He will return and negative Aaron number just like all your kernel to 76 00:11:08.490 --> 00:11:14.280 William Cheng: The Colonel to function right you return zero means success return minus air number, meaning that there's a failure. 77 00:11:14.700 --> 00:11:18.300 William Cheng: Guys, in this case, and one of the arguments over here is invalid. For example, 78 00:11:18.690 --> 00:11:26.760 William Cheng: If your page down is wrong. So again, typically the page numbers, a small integer. If you appease them use a virtual page number or physical page I'm reading that will be gigantic 79 00:11:27.030 --> 00:11:35.580 William Cheng: So in that case, easily, you will fail this test and you will return Ii Ii Ii minus E and valid that so remember 80 00:11:36.390 --> 00:11:45.570 William Cheng: Last week, no discussion section. So to talk about what you know the the menial page and also inside a kernel fact again search for the stream page them. 81 00:11:46.350 --> 00:11:49.830 William Cheng: And then they'll the concept of a zombies. Very, very important. Yeah. 82 00:11:50.550 --> 00:11:57.690 William Cheng: Alright, so, so the turns out it's not all arranged, then what it will do is that it will call P frame get and this is the one that you implement it. 83 00:11:58.110 --> 00:12:03.180 William Cheng: You know, at the beginning of Colonel three right that's first one you have a black people and get people in pen, paper and pen. 84 00:12:03.660 --> 00:12:10.110 William Cheng: So looking up a particular page over here. Once you pass the sanity check right here. Then would you do that you simply copy for and get 85 00:12:10.800 --> 00:12:18.570 William Cheng: Because remember people and get is like the get right. What is trying to do. So I tried to return a page frame there so so so 86 00:12:19.530 --> 00:12:23.280 William Cheng: So in that case in the pace rain. So what it will do is it will see if the patient. 87 00:12:24.030 --> 00:12:39.210 William Cheng: exists already if it exists already what it would do is that you need to wait for it to be a busy and then in that case we will return it. When this function returns this page friend is not busy. Okay. You cannot return a patient that that's busy, because that's really not about. Yeah. 88 00:12:40.560 --> 00:12:49.260 William Cheng: So this case it will return a PageRank. Again, just like we get if it turns out at this pace friend doesn't exist when this case, you have to ask the bottom object to create a page where 89 00:12:50.040 --> 00:12:58.650 William Cheng: They are so good you by now you should have people and get working already and you should be passing BFS test with f5 by bicycle one. Yeah. 90 00:12:59.550 --> 00:13:05.970 William Cheng: So you can see that, you know, when you call look our page, it actually ignore for right doesn't really matter. So you simply copy. Yeah, yeah. 91 00:13:06.540 --> 00:13:16.290 William Cheng: I read page over here again at the vino over here. The vino it's in the virtual buses and he has no idea how do we get up on the desk. So in this case, again, they call this function called 92 00:13:16.650 --> 00:13:25.410 William Cheng: So I don't really understand why in the winners, Colonel. They call this function read, page one in the in the MO VJ. It's called Phil. Phil page. 93 00:13:26.250 --> 00:13:36.840 William Cheng: Okay, so for some reason it's called is read page. But the real name. Apple does parliamentary budget is still page. So what it will do is is that you will find the vino it's still paste function and then it will call it 94 00:13:37.770 --> 00:13:47.340 William Cheng: Okay, so I think this particular function over here actually belong to the bite device or the block device, whatever the the devices. 95 00:13:47.850 --> 00:13:54.150 William Cheng: So again, what you should do is that you can set a breakpoint right here set a breakpoint as we read page where you get here inside GDP, you 96 00:13:54.420 --> 00:14:08.550 William Cheng: Say print the right arrow VI, N, O, P. S. And he would actually tell you, you know, so why don't we do that, it will show you. This is the polymorphous pointer and he will tell you what kind of, you know, what kind of, do you know what what kind of ponder this 97 00:14:09.660 --> 00:14:22.410 William Cheng: Okay, so, so, so make sure you set a breakpoint right here. And when you get here, you know, after you know you you you just set a breakpoint on the last line and be repaid. And when you get there, print the right arrow VN OBS 98 00:14:23.460 --> 00:14:31.410 William Cheng: Okay. You can also do Pinterest RV and they will actually print out all the fields. So this way you can actually tell you know what kind of polymorphous pointer is 99 00:14:32.130 --> 00:14:41.310 William Cheng: OK. So again, it's very, very important to understand, you know, what kind of work with partners. So I think you just set a breakpoint right here you will see that this object this object. It's another kind of 100 00:14:42.150 --> 00:14:45.150 William Cheng: It's not shadow object. It's not anonymous object. 101 00:14:45.390 --> 00:14:54.630 William Cheng: It's not the one in the Beano because it's already here. So it's not a recursive function call, it's actually different kinds of animal VJ and those kinds of stuff that has been implemented already for you. 102 00:14:54.840 --> 00:15:09.540 William Cheng: You know, inside the pristine kernel source of source code and then or maybe it's written in the device driver CO or this isn't bypasses I think most likely it's either already implemented for you or it's in the solution that we got from Brown University for your device driver. 103 00:15:10.740 --> 00:15:20.940 William Cheng: Guys, again, if it's if it's if it's co written by the Brown University people in the device driver. There's no way for you to single step into so therefore you can do is just set a breakpoint on the next slide. 104 00:15:21.150 --> 00:15:30.330 William Cheng: And you can continue or you can just do a next what it will do is they'll go to next time well as what again it's useful to look at exactly what kind of pointed this this now. 105 00:15:31.080 --> 00:15:40.560 William Cheng: Right now, finally, the dirty page over here again you know virtual POS system doesn't know how to do it. So what he would do is that it will call the 30 page bump shooting you know inside the 106 00:15:41.250 --> 00:15:47.790 William Cheng: You know the wallet whatever this pointer pointing to. OK. So again, this is the same pointer, as in the Phil page. Okay. 107 00:15:48.270 --> 00:15:58.740 William Cheng: Over here, according to the the header file, you need to first check whether it's dirty or not. If it's 31 then the other. If the patient is dirty. What then you will call the dirty page. 108 00:15:59.160 --> 00:16:07.710 William Cheng: Otherwise, that you wouldn't do anything. Okay. So some of these functions over here. Sometimes you don't have to do anything. All you need to make sure is that you return the right value. Yeah. 109 00:16:09.060 --> 00:16:17.430 William Cheng: All right, I'll clean page over here. So again, I just like the other the other function. This is in the vino vino doesn't know how to do this or they will get it rely on this probably more three pointer. 110 00:16:17.670 --> 00:16:21.300 William Cheng: I guess set a breakpoint right here and look at, take a look at what kind of point during this. Yeah. 111 00:16:25.800 --> 00:16:31.920 William Cheng: Alright, so, so we covered this one right the N, M, M. O. B. J. O. P. S. This is the Copa de 112 00:16:32.430 --> 00:16:42.930 William Cheng: vino and also that will give you a hint. So by by understanding the code inside of vino you can actually see that for anonymous object over here. They all have exactly the same function because we're doing 113 00:16:43.860 --> 00:16:53.700 William Cheng: It is a polymorphous pointer. So all the animal VJ they all have to have all these funky, even though it might not make sense to have them for a particular object type. 114 00:16:54.630 --> 00:17:01.980 William Cheng: Okay then. And that's sort of the nature of polymorphous that all the function needs to be there, even when it doesn't make sense. You know, for for football for pretty large. 115 00:17:02.490 --> 00:17:08.070 William Cheng: Okay, alright. So, you will see that, you know, instead of kernel source code. There are places where it says, you know, this is really 116 00:17:08.550 --> 00:17:18.900 William Cheng: really straightforward. Okay, maybe because these functions doesn't really make sense for you know for function like anonymous object. Right. So remember, was the anonymous IDs. Right. Those are the one that created a piece frame out of thin air. 117 00:17:19.710 --> 00:17:22.980 William Cheng: OK. So again, you know, think about how you would implement all these kind of stuff. Yeah. 118 00:17:24.330 --> 00:17:33.600 William Cheng: Alright, so I'm going to delete all this kind of stuff. Since we just finished covering it. So next thing we're going to look at is object dumb guy. So in order for you to run so so so yeah 119 00:17:34.440 --> 00:17:42.510 William Cheng: What, what we need to do is to to get a loader to work in that case you have to implement all the function and be a map right so what it will do is that at the end. 120 00:17:43.350 --> 00:17:52.230 William Cheng: It will actually call a function to go into user space. So let's take a look at the code for the loader. The Colonel API exact 121 00:17:52.860 --> 00:18:01.560 William Cheng: Darcy right so so inside exact I see there is Colonel exact be so there's the function that you're supposed to call inside the 122 00:18:02.280 --> 00:18:09.240 William Cheng: Inner talk right now. So he's like no you're supposed to call this function to go into user space, right. So over here, what it does is at the beginning. 123 00:18:09.570 --> 00:18:22.560 William Cheng: It called been FMT low so that invoking the loader. Right. That's where all the VM app launch is going to call eventually when everything is done and what it does. Over here, as I said, it says all these kind of thing that set up CPU register. 124 00:18:24.180 --> 00:18:36.450 William Cheng: Okay, so good. We just assume that this code works. We don't know why we're going to soon. Soon works, guys, so you know all the coding exact I see over here. We also see that there are eight zero that means that this code is not included. 125 00:18:37.080 --> 00:18:45.300 William Cheng: But you know, it's doing something with assembly call and then what he will do is that it was said he flies 00202 whatever that is. 126 00:18:45.510 --> 00:18:56.730 William Cheng: And then finally, is called a function called user lead entry with the word is going to go into the user space. Okay, so where is user land entry. It's the same function over here. So this is how you go into the user space. 127 00:18:57.300 --> 00:19:02.520 William Cheng: Okay, so, so, yeah, we are inside any any processes that kernel. And now we're going to go into the user space. 128 00:19:02.730 --> 00:19:11.730 William Cheng: Is still the same processor is going to be in a process in the user's name but we just use the loader to low hello program. So what we're going to the user space will be running the whole program now. 129 00:19:12.510 --> 00:19:22.740 William Cheng: So what does this code do over here, right at disable to interrupt guy because when we just ran out what we need to do is that we need to go through the hallway abstraction layer. So we stopped before right you know 130 00:19:23.070 --> 00:19:30.030 William Cheng: The, the way go into the user space and you disable you know off. And then over here, you said IPI equals slow and then 131 00:19:30.330 --> 00:19:39.180 William Cheng: You execute this one. So what's important. Over the years that you bet. The only way to get into the user space program is the FAQ that I returned machine structure, right. I mentioned that in class. 132 00:19:39.510 --> 00:19:47.730 William Cheng: I return is as a x86 way for returning to users as well. So this is a return. Right. You know, so I'm going to pretend that we're actually all companies that are kind of using the interim 133 00:19:47.910 --> 00:19:56.670 William Cheng: And now we need to return back to the user space, right. That's how we get into the user space we're going to pretend that we are in the corner because I mean interrupt and now we're going to return on the internet. Yeah. 134 00:19:57.150 --> 00:20:07.680 William Cheng: Alright, so it's all the speaking is done at the no vacancy. The last instructional because I return that once we execute I return boom wearing where user space. Okay. 135 00:20:08.460 --> 00:20:15.840 William Cheng: Over here, it does a bunch of stuff. So again, these are assembly code. We just assume that they're perfect. We don't know what it does. I was just gonna assume they're perfect. Yeah. 136 00:20:17.610 --> 00:20:31.380 William Cheng: Alright, so once you get into the US over here, since we are doing on demand paging right. The first thing that we're going to get is that we're going to get a baseball. Okay, so what is going to be the pace for address. Okay, so in this case the hello I see over here. 137 00:20:32.640 --> 00:20:45.450 William Cheng: So, so what's the first function that is going to execute is going to be the startup. I'm sure the startup function is the function that calls me. Okay. So, therefore, how do we look at our code over here. Okay, so let's take a look at hello Darcy right 138 00:20:46.500 --> 00:20:50.100 William Cheng: Does the user space user been hello Darcy. 139 00:20:50.700 --> 00:21:01.890 William Cheng: Then this is the hello program. Right. So again, it's very, very important to, to, to understand exactly what it does. I'll be here. So the open slash slash TTY for read only. So you should return file descriptor zero 140 00:21:02.550 --> 00:21:13.920 William Cheng: Then you call openness is definitely TTY 04 right on. He returned about the script one and then you write the script or number one over here. So you guaranteed to write to slash their city y zero. 141 00:21:14.250 --> 00:21:20.910 William Cheng: There and then you read the string hello well and then the string length of visit support team as you can actually count the number of characters over here. 142 00:21:22.020 --> 00:21:35.190 William Cheng: 14 is so so you know that the including the backslash so passion is only one character. So in this case, you know that that's a stream lane at the last character, his backside zero so 14 does not include back backside zero. Yeah. 143 00:21:36.390 --> 00:21:41.730 William Cheng: So they open it open and make the racism called when they return and make the exorcism call right so so 144 00:21:42.030 --> 00:21:49.470 William Cheng: But, but, again, when you try to run your hello program, you don't execute sequel, you actually execute assembly code. Okay, so we need to take a look at the assembly call 145 00:21:49.830 --> 00:21:59.910 William Cheng: The way to do this is using object dump. Right. So here are some of the useful command over here. The first one over here. It's called object dumb. So again, all these things are from the colonel FAQ 146 00:22:00.360 --> 00:22:08.250 William Cheng: That. So let's take a look at the first command over here it says I wanted this assemble the tech segment user user being hello that 147 00:22:09.180 --> 00:22:20.250 William Cheng: The SEC right so if I execute this command, you'll see that I just go over that crazy, right. So what we're gonna do is, I'm going to run this command. We're going to output to the first outbred right so this one I'm going to call a wine. 148 00:22:20.790 --> 00:22:34.500 William Cheng: The second I'm gonna, we're gonna have a go to two. So I'm just going to modify this file over here, right arrow one right arrow to the right arrow three right arrow for alright so this will be just run that like this all in one shot. 149 00:22:37.770 --> 00:22:44.370 William Cheng: Okay, so in one we're going to have the the output and the two over here, there's an extra command line arguments minus s 150 00:22:44.880 --> 00:22:50.640 William Cheng: So what it will do is that it will list the source code together with assembly code that's that's pretty useful. Now, 151 00:22:51.360 --> 00:22:59.130 William Cheng: So we can take a look at one and two. I saw one look like this. Okay, just assembly code right that we saw this in chapter three already right shouldn't be very surprising. 152 00:22:59.520 --> 00:23:02.580 William Cheng: If we look at to over here. That's the one with the source code. 153 00:23:02.940 --> 00:23:08.010 William Cheng: Okay, so what do we do is it will actually put in all these CO, this is the source code open is right here. Right. 154 00:23:08.250 --> 00:23:19.290 William Cheng: Open right and then you also show you when you combine two. So again, this is sort of the preamble enter and stuff like that. And then you're ready to execute see co at the C code is open. Right. And this, etc. 155 00:23:19.530 --> 00:23:27.750 William Cheng: And then when you're finished writing or we hear that there's leave right which is the end over here. Then there's also a function called lipsey static entry. 156 00:23:28.860 --> 00:23:45.210 William Cheng: There. So this code is pretty much impossible to read over here. So what's important over here. Here is the code for lipsey static entry. What it does is that execute some instruction. First is to add for TSP, whereas for us is to 157 00:23:45.780 --> 00:23:52.050 William Cheng: You know, increment ESP by four and then it calls the function may. Okay. So remember, you know, 158 00:23:53.970 --> 00:24:00.480 William Cheng: What do you do it what we call the function right in chapter three, we saw that, what you do is that you push the 159 00:24:01.920 --> 00:24:09.180 William Cheng: I guess what you call you you you create space for the for the local variable. 160 00:24:11.670 --> 00:24:20.490 William Cheng: Sorry, so, so, so you so you push the function argumentative that yeah sorry you push the budget argument onto the stack over here. So for some reason they only increment by four and then you call the main function. 161 00:24:21.030 --> 00:24:27.960 William Cheng: Okay, so what happened is that, you know, inside the main function, I guess there's a bunch of stuff on the stack already. So when you go when you go into the main function. 162 00:24:28.350 --> 00:24:30.360 William Cheng: Their stuff they're set it, set up for you already. 163 00:24:30.720 --> 00:24:39.450 William Cheng: There so you call the main function over here. And then when main function in return. You take the return value. We just started. Yes. And then you call exit on it. Right. So it's exactly what will 164 00:24:39.780 --> 00:24:50.220 William Cheng: What will always that in class, the you know the purpose of this function here is to, you know, set up the stack, called the main function and then take the return code. The main function and call excellent net 165 00:24:51.030 --> 00:24:57.690 William Cheng: Price okay you know for program to edit to to self terminate the correct things to do is to call the accesses the call. 166 00:24:59.580 --> 00:25:09.660 William Cheng: Alright, so, so let's take a look at this thing. So, so, you know, when you start running your program. You know, so, so I guess you know inside 167 00:25:11.820 --> 00:25:18.450 William Cheng: Inside the process inside of Colonel, you're going to call Colonel exactly the loader is going to finish build out the address space. 168 00:25:18.690 --> 00:25:33.720 William Cheng: And then you call us or when entry and boom, you're in the user space. So the first thing that you will do is to execute this line of code that. So this line of code is a virtual address so we do an object or the executable file the executable file, since we are doing 169 00:25:34.770 --> 00:25:46.710 William Cheng: Since we're doing static Lincoln and loading the executable file has all the virtual addresses determine already because that's the job the linker to to sort of figure out to perform relocation so that every symbol has an address. 170 00:25:47.070 --> 00:25:57.030 William Cheng: Guys so this case, the symbol for lipsey static entry is this address. We can also see the global Director of IT SHOULD BE all familiar with this. What about the main function. 171 00:25:57.480 --> 00:26:09.420 William Cheng: Okay, the main function over here. Guess it started out at this address as zero x A's so everything's gonna be has a 048094 okay so be careful. There are only seven 172 00:26:09.990 --> 00:26:17.610 William Cheng: Hexadecimal here, right. So, so actually this is if you want to make it into a hack hack stager the leading character over here, there are zero. 173 00:26:18.750 --> 00:26:27.600 William Cheng: Well as over the end the tech segment is that low memory address. So, therefore, you started at 08008048 there and if all about 094 174 00:26:27.840 --> 00:26:39.330 William Cheng: Whenever we look at a virtual address, we need to look at any hacks because the first 20 bits or five hex character is the virtual page number and the last three character or the last hobbits is the offset. 175 00:26:40.080 --> 00:26:46.200 William Cheng: All right, we have to look at it this way because then address translation, everything will make sense, right, don't look at the decimal number. Yeah. 176 00:26:47.100 --> 00:26:53.160 William Cheng: Right. So if we look at the live see stay static entries over here, right. The first line over here is this address 177 00:26:53.700 --> 00:27:07.050 William Cheng: You will see that in the the sort of the, the, the, the weenies document Asia and the Colonel FAQ Q AMP. A i'll tell you that you know the hello program started running at this address. Okay, so this will be the main function. 178 00:27:07.560 --> 00:27:16.980 William Cheng: Okay 809 for a while this lip is the statue over here is going to be a 0480 fa. Okay, which means that 179 00:27:17.430 --> 00:27:27.120 William Cheng: So, so remember when you go into the user space. The first thing that we would that we have done is that we're going to zero out the entire page table. So the first thing that happened in the user space for visa is that you're going to get a peaceful 180 00:27:27.330 --> 00:27:34.980 William Cheng: And the page fall address has to be this address. Okay, so your very first page or has to be zero, x 804808 181 00:27:36.060 --> 00:27:43.590 William Cheng: Or so once you get a patient all of your, what are you supposed to do, right. So again, this case you need to go to the colonel FAQ handle the first page Hall. 182 00:27:44.310 --> 00:27:46.350 William Cheng: Guys, okay, this is very, very important. Whenever you 183 00:27:46.800 --> 00:27:54.960 William Cheng: Know. So, so what is it you're going to the user space. And this is where the on demand page and boom, you're inside a colonel you're inside this function call handle peaceful 184 00:27:55.170 --> 00:28:06.120 William Cheng: And that's where you need to handle your first page fall if your first spacewalk is not handled properly, you're going to return to the user space even come back and we're currently going up and down, up and down forever because you didn't fix your pace fall 185 00:28:07.230 --> 00:28:10.440 William Cheng: Okay. So inside handle pays well you have to fix a page for all 186 00:28:10.860 --> 00:28:19.140 William Cheng: In class always mentioned that, you know, right before you return back to the user space. You've got to make sure that all the colonel data structure is consistent and also you need to fix up 187 00:28:19.590 --> 00:28:29.130 William Cheng: The page table entry inside your entire page table, right, because if you don't fix that up. Well then, next time you provide your transition, you know, again, equal to zero, you're going to come back inside of Colonel 188 00:28:30.090 --> 00:28:38.940 William Cheng: Okay, so at the end of handling the first page for you need to set up a page table n g. So, this way when you go into the user space, you are not going to get a taste fall right away. 189 00:28:40.290 --> 00:28:46.710 William Cheng: Okay. Alright, so let's take a look at handling the third person pays off inside the colonel three FAQ 190 00:28:47.670 --> 00:29:04.530 William Cheng: Okay, so what does that look like. So this one is pretty long over here. Okay, is how do I debug and know if I call PT mob where the right arguments over here, there, so, so, so what you do is, that way you handle your first page. Let's go back to this code over here. 191 00:29:07.020 --> 00:29:10.620 William Cheng: Guys. So if we look at the code for handling pays for Colonel 192 00:29:11.760 --> 00:29:12.480 William Cheng: VM. 193 00:29:14.400 --> 00:29:29.520 William Cheng: Handle peaceful peaceful Darcy there there's only one function in here. It's called handle page for that. So whenever you get a paste all this will be the first argument is called VAD Dr. That will be the user space page called address 194 00:29:29.970 --> 00:29:42.900 William Cheng: Okay. The example I always give a zero x 12345678 that address is less than zero XE 000000 so therefore the user space virtual address that. So yeah, this address over here, very important is to look at it as a 195 00:29:44.550 --> 00:29:52.110 William Cheng: As a heads. It doesn't want number. Take the first few character as the virtual page number and the last three character as the offset within the page. 196 00:29:52.500 --> 00:30:02.850 William Cheng: Okay. So use the virtual papers number you walk down your linear with a VM area, try to sort of find out which one it belongs to. And why is it funnel which wanted to also then you look at all the information you know 197 00:30:03.480 --> 00:30:07.710 William Cheng: The VM area and then you decide what to do that. So that's the, that's how you 198 00:30:08.340 --> 00:30:16.680 William Cheng: That's how you, how you handle 100 page. I'll take the virtual address over here. Find out which VM area belongs to. And it is that a VM area. What do you have 199 00:30:17.190 --> 00:30:26.460 William Cheng: Whereas, they'll get a VMware is a memory segment instead of VMware right you have the MO VJ and the demo video or the link list of mo BJ. Those are the places you need to find the pace. Right. 200 00:30:27.630 --> 00:30:37.920 William Cheng: OK. So the purpose of handling pays for is to find the pace rain and then map. The map. The map page rain into your page table. 201 00:30:39.180 --> 00:30:42.930 William Cheng: Okay, why did you find the painting right. Is that a patient over here, there is a 202 00:30:43.200 --> 00:30:48.090 William Cheng: virtual address for the colonel and then for the virtual address of the Colonel, you can actually convert them to a physical address 203 00:30:48.270 --> 00:30:56.940 William Cheng: Because in the end, you need to set up a page table entry instead of a stable energy, the physical page number. So if you can find the page where you can find the physical page number 204 00:30:57.570 --> 00:31:03.270 William Cheng: OK, so again this is done in directly. But again, once you find the page friend, you'll be able to find the, you know, 205 00:31:03.840 --> 00:31:09.960 William Cheng: You, you, you, you'll be able to find as the physical page number, right. What about the other stuff inside the page table entry. 206 00:31:10.500 --> 00:31:20.460 William Cheng: OK, so again for Intel the x86 CPU the page table entry is a little different from what we talked about in class. So again, you should look at you click on the current FAQ 207 00:31:21.510 --> 00:31:27.120 William Cheng: So let me say, where's that I could as you look for programmer. 208 00:31:28.530 --> 00:31:35.190 William Cheng: Okay, here's the programmers reference manual over here, it will tell you you know what the you know what the patient when you look like 209 00:31:36.000 --> 00:31:47.700 William Cheng: Okay, so, so let's go back to what we work before I think I lost that I have on page over here. There. So we're here trying to explain why you have to do over here, right. So once you you know 210 00:31:48.660 --> 00:31:53.580 William Cheng: You know, find the VM area, find the pace, right, you got to make sure that the patient has the right data. 211 00:31:54.690 --> 00:32:02.790 William Cheng: Okay, so, so when you get the first page of the page. The first page file is actually on the first page of the you know the tech segment over here. 212 00:32:06.450 --> 00:32:11.700 William Cheng: Okay, over here, this is, you know, this is the beginning of your holiday etc file. 213 00:32:12.060 --> 00:32:22.920 William Cheng: So I think the virtual or just over here. They're all sorted linearly. So, therefore, this is the smallest address over here. So, this will be paid zero so page zero has a virtual page number of this wise but again. 214 00:32:23.160 --> 00:32:25.710 William Cheng: The first five character. Watch out for the space. 215 00:32:26.010 --> 00:32:34.890 William Cheng: Okay, it's going to be the virtual frame number of the virtual patient number. So in this case, it will be 08048 and the last three characters over here is the offset within the page for that again. 216 00:32:35.160 --> 00:32:39.480 William Cheng: Every character is for bears four times to equal to 12. So that's the page offset that. 217 00:32:40.200 --> 00:32:48.840 William Cheng: Alright, so you need to bring this page. And that's all we bring this page, and we need to verify that this page is the right page, right. So how do we make sure that it's the right page. OK. So again, 218 00:32:49.200 --> 00:32:58.200 William Cheng: The first page right over here is the lip see static entry over here. So, so we need to verify that the patient that we found has these three bites in there. 219 00:33:00.900 --> 00:33:04.380 William Cheng: Okay, so we just did object DOM. We know that you know for the tech stack, man. 220 00:33:04.710 --> 00:33:18.540 William Cheng: And virtual address 080480 F eight has that these three buys right so again this is going to be inside of page, friend, is that a Patreon, we're gonna have a page line address and if you add the offset to her, you're going to get a three see for 221 00:33:19.560 --> 00:33:35.820 William Cheng: See four and 004 so what the current FAQ page telling us that that's the pattern that you need to look for right over here, it says lipsey start again. She looks like this, you know, the first is a three see 404 so therefore, when you get a page for a you need to look at all set. Fa 222 00:33:37.530 --> 00:33:45.450 William Cheng: Fa at night and an FA those three buys to see if they're equal to zero, x at three zero XE four and 00 for 223 00:33:46.080 --> 00:33:52.170 William Cheng: Rapid if those three bites are wrong, you have loaded the wrong you have loaded the wrong page rank. 224 00:33:53.010 --> 00:33:59.580 William Cheng: Okay, if you know the wrong page, I can guarantee you, when you go into the user space, you don't come right back and and then this case, you will never get it right. 225 00:34:00.300 --> 00:34:14.070 William Cheng: Okay, so you got to make sure that when you handle the first page fall, you're going to be able to find the right page friend and then again asked the other, the DMO BJ instead of Dino to say, hey, you know, give me to, you know, give me the tech stack, man. So this way I could use it. 226 00:34:15.150 --> 00:34:15.420 William Cheng: Now, 227 00:34:16.470 --> 00:34:25.320 William Cheng: Alright, so once you verify this right. What you would do is that you will call the PT map PT mob is the function that you will use instead of page table dot c file. 228 00:34:25.980 --> 00:34:31.440 William Cheng: Let's look at page table without see Colonel mmm page table. I see. 229 00:34:32.070 --> 00:34:41.280 William Cheng: Okay. So, okay, this is the one that implemented page, Dave. All right. This is the one that implement a two level abstraction for the multi level page. They've also got this is very complicated. 230 00:34:41.550 --> 00:34:50.670 William Cheng: Don't spend time trying to understand it just pay pay pay attention to see what kind of function that they have to use their. So one of the function that you have to use over here is called PT map. 231 00:34:51.570 --> 00:35:03.990 William Cheng: Gradually, one is called PT. The other one is called PT a map, which is the next function over here. So this is PT on map right. You want a map a page table entry from the address space. And then over here, it's called PT map. 232 00:35:05.130 --> 00:35:11.280 William Cheng: Okay, so this one again. The first argument is a pace directory, because we are doing in town. So therefore, the customer pays directory 233 00:35:11.550 --> 00:35:20.940 William Cheng: And then keep on a particular you know virtual address over here, we need to find the corresponding page table entry and then we need to set set it into all the, all these three arguments over here. 234 00:35:21.180 --> 00:35:27.840 William Cheng: Now the first argument is the physical address. So if you're getting the physical address this function will actually, you know, take the leading 235 00:35:28.050 --> 00:35:33.960 William Cheng: 20 beers over here that will be the physical page number and it will put it into the page that might be, again, you don't have to worry about how it's done. 236 00:35:34.230 --> 00:35:41.850 William Cheng: You just need to make sure that you give it the right address there. And then there are these flags for the page directory and also for the page table. 237 00:35:42.030 --> 00:35:49.470 William Cheng: Because we're doing multi level a page table. So therefore, we need to specify what are the flies that go into the page directory entry and also what are they 238 00:35:50.610 --> 00:36:00.750 William Cheng: Enter the information I go into the page table entry. Now, if you read the colonel colonel FAQ, it will tell you that PD PD flag and PD, for they must be exactly the same value. 239 00:36:01.740 --> 00:36:07.860 William Cheng: Okay, so therefore, when you call this function. Right. You know what the DDR you have, you know, what is the page directory. So the other thing you need to figure out 240 00:36:07.980 --> 00:36:19.770 William Cheng: Is what is the physical address and also what flag. So you. So these are the one that you that you say instead of patient branch. Right. So again, read the Intel's programmers manual. The extra the entire three 386 the pope has manual 241 00:36:19.950 --> 00:36:25.530 William Cheng: And find out what the flags are are some of their so one of their, their the validity Bay. I think for Intel they call the present bed. 242 00:36:25.950 --> 00:36:31.320 William Cheng: There also the permission bids over there. So again, all the stuff we talked about in class. Look at them and try to sort of figure out what you have to do. 243 00:36:33.330 --> 00:36:39.480 William Cheng: Is ok if you asked me what you should put there. I cannot tell you what Coach right now. Alright, so again this is important function over here. 244 00:36:39.900 --> 00:36:53.790 William Cheng: So that's the PT malfunction over here. So once you copy the map, you know. So in that case, once you set up the pace table entry. Now the validity be equal to one and you have to read permission. You should be able to use the virtual address now. 245 00:36:54.840 --> 00:37:05.880 William Cheng: Well that's all we hear the PRP of add that's a kernel space virtual address and now if you use VA DDR. So remember VAD Dr. At the beginning of handle baseball. That's the address that you have a pitfall. 246 00:37:06.450 --> 00:37:09.600 William Cheng: Okay, so therefore you cannot use it because if you use it, you're gonna end up with the Colonel. 247 00:37:10.440 --> 00:37:14.580 William Cheng: Colonel pitfall. And then in that case, you know, you're going to get a kernel panic. 248 00:37:14.880 --> 00:37:31.350 William Cheng: Okay, but once you map this paste over entry by calling PT mobile via then then in that case, you can use a DDR. So if you go VAD Dr have zero, you should see at three very because if you go to VAD the art of one is to see you again. CC for me to go via DVR to it's just easier for 249 00:37:32.760 --> 00:37:43.440 William Cheng: Okay, so these two you know this this prince a monopoly is using crypto virtual address and this print server over here is using user space virtual address and he can see exactly the same data and the data are correct. 250 00:37:43.710 --> 00:37:54.450 William Cheng: Chances out where you go back into the user space now not now there's a there's a pretty good chance that you will be successful. You can also fail if you, you know, if you didn't set up all the other arguments correctly. 251 00:37:55.110 --> 00:38:04.920 William Cheng: Okay, but if you set out for the validity be correctly and also the re permission correctly. So this way when you go back to the user space, you will be able to execute the next few instructions. So what did they experienced actually look like. 252 00:38:05.550 --> 00:38:14.310 William Cheng: That. So once this instruction is successful, what do you would do is it will actually do the next instruction. So this one is going to be the call machines. Talk to you again. 253 00:38:14.520 --> 00:38:21.300 William Cheng: It's a five by instruction and the first one says, Call and then followed by, you know, some kind of a PC relative address or something like that. 254 00:38:22.470 --> 00:38:34.620 William Cheng: Base or this is the actual address. I can't remember what the what this one is. So it's anyways. They will call this address, you know, nine for F, F, F, F, F, F, F, F. So I think this is a PC relative address 255 00:38:35.670 --> 00:38:43.050 William Cheng: So, so again, this will be the instruction pointer and he was subtract you add this number. This is a negative number. So this case will end up calling me 256 00:38:43.500 --> 00:38:52.290 William Cheng: Okay, so when you call the main function over here. That's where you need to say the return address onto the stack, since we're doing on the main page. And when you set the return address on 257 00:38:52.590 --> 00:38:57.180 William Cheng: What you push the return address on the onto the stack. That's what you're supposed to get the second page fall 258 00:38:57.930 --> 00:39:08.730 William Cheng: Guy. So again, the first page fall was when you fetch the instructions over here. A three see 404 that will be the first page fall and the second page FALL YOU'RE GOING TO BE end up pushing the the the return 259 00:39:09.180 --> 00:39:20.130 William Cheng: Return latches onto the stack, then you will get the second page Hall. So again, you come into the kernel with hundred page while you walk down that list of a VM area, find out which one it is. And this one is, since this one is in the stomach area. 260 00:39:21.390 --> 00:39:24.540 William Cheng: Stuck segment. You are supposed to set off on copy on write 261 00:39:25.590 --> 00:39:30.930 William Cheng: OK. So again, you know, he's I have a page. Well, that's also that's also where you need to set up a copy of the right 262 00:39:31.140 --> 00:39:39.150 William Cheng: How do you know that you're doing copyright, because if you go to that memory segue. You will see that this memory segment is rewrite and private so therefore you need to set up a copy. All right. 263 00:39:40.170 --> 00:39:51.750 William Cheng: All right. Well, so, by the way, just to be clear, this is the regular copy on write, not the copy on write with, you know, with a fork system call because the copyright with forces and Paul uni shadow object. 264 00:39:52.230 --> 00:39:59.400 William Cheng: Okay, so in the hello program, you still need to get copy on write down correctly because you need to push that data onto the stack. 265 00:39:59.880 --> 00:40:11.220 William Cheng: But in this case, you don't need to shout object, okay. It's okay, your team can decide whether you want to implement that object. At this time, or do it when you try to implement the we try to get the foreign away program to work. Yeah. 266 00:40:12.780 --> 00:40:20.070 William Cheng: So, wow. So once you can successfully pushed it onto the onto the stack. So again, the second, the second tab is going to handle page are you to have them correctly. 267 00:40:20.280 --> 00:40:27.960 William Cheng: And then you will be able to go to me right so what the main do over here, right. The first two insertion, we see many, many times is the enter 268 00:40:28.680 --> 00:40:34.650 William Cheng: Is the intercall push, you know, push. I guess they're not showing push L over here in class was that push out a VP. 269 00:40:35.160 --> 00:40:48.720 William Cheng: Move. Oh yes, P BP and then it does a bunch of stuff and then he will make the open system call. So where's the open system call right over here. It says, Call open. So if you look at the object, the object down, you can actually look for open 270 00:40:49.860 --> 00:40:52.860 William Cheng: There's no strings surgeon open and here's open right 271 00:40:53.190 --> 00:41:02.430 William Cheng: Open is that this virtual address. So this one is still in the same virtual page number. So, therefore, we call open, you shouldn't get another page while because it's in the same page. 272 00:41:02.760 --> 00:41:06.990 William Cheng: Okay, the offset is different. The opposite, it's okay. You know, let's go back to the beginning. Over here. 273 00:41:07.200 --> 00:41:14.190 William Cheng: This one is right here. Right, we're going to, I'm going to copy that line compare against that. So, so, so the first line over here. 274 00:41:14.430 --> 00:41:24.360 William Cheng: The one right here. This is the one from the main function. Right. So again, can see that the first five character, including this space. They're all the same 08048. So that's the virtual 275 00:41:24.870 --> 00:41:29.520 William Cheng: The virtual frame number the offset over here is different. Right. So yeah, the co for open 276 00:41:30.360 --> 00:41:36.180 William Cheng: In the same page as me. So therefore, when the main called open virgin, you shouldn't get another page for that. 277 00:41:36.720 --> 00:41:42.540 William Cheng: Alright, so in this case the code will continue to execute over here and then it will call another function over here. Again, it's in the same 278 00:41:43.470 --> 00:41:47.790 William Cheng: In the same virtual page number so therefore nothing bad is going to happen. 279 00:41:48.780 --> 00:42:01.800 William Cheng: Yeah. Alright, so let's go back to the open over here, the code over here also to move out 0804 BS again and this guy's got there only seven characters. So you need to add a leading zero over here, a powder was zero. 280 00:42:02.250 --> 00:42:08.760 William Cheng: In this case, the virtual page number is 0804 be again. That will be a new page friends or this case, you could paste fall 281 00:42:09.210 --> 00:42:19.950 William Cheng: So in this case, this will be right. So, this you know if the first patient what we hear is the one with page number zero because his paint is the first page rank instead of file, right, so remember the pace rain. 282 00:42:20.340 --> 00:42:29.430 William Cheng: Give you the file offset. You know what, what will you map a file into your address face. OK. So again, where's that file right so let's take a look at that fall over here. 283 00:42:29.910 --> 00:42:43.860 William Cheng: So in this case, user been hello over here. One of the headsets textile mill that file. And this is the one we we have a go to for. So now we can actually take a look at four, so four is the output of upside for over here is the output of the heck, stop. 284 00:42:45.330 --> 00:42:48.420 William Cheng: Okay, so this is the hex down what is 285 00:42:49.530 --> 00:43:03.780 William Cheng: Okay, what is going to be the first page or is OK. You look at the virtual address over here. The first five characters over here are the virtual page number so it will go all the way to, you know, I guess, over here, there's a lot of stuff over here. 286 00:43:06.030 --> 00:43:08.580 William Cheng: Okay, so this line, it will go to page number two. 287 00:43:10.350 --> 00:43:24.180 William Cheng: Okay, so everything above it or they're all inside, page one. So again, page one over here is 4090 and 96 buys over here. There's a lot of stuff in it. Right. So again, by looking at the next time you can actually see what's you know what's actually inside the object, then 288 00:43:25.890 --> 00:43:34.230 William Cheng: All right, where are we over here. Right, so, so, so again you know you need to analyze this code to sort of figure out when are you going to get a pitfall. Yeah. 289 00:43:34.800 --> 00:43:44.220 William Cheng: Alright so this address over here you know we're here, so. So again, what is this address over here. So remember when you make the make a function call, you're going to push the argument from right to left. 290 00:43:44.760 --> 00:43:55.110 William Cheng: So we here. We move zero and move some read only. And then that ke y zero over here. So I think this particular string over here is actually slash dev site TTY zero 291 00:43:55.890 --> 00:44:03.240 William Cheng: Okay, so in this case in class. We said that you know the stream constant. They are inside that they're inside the other instead of data segment. 292 00:44:03.840 --> 00:44:11.820 William Cheng: For we mix. I think they're a little different. So one of the commands over here is through his three over here, we look at the headers of the holiday, etc. 293 00:44:12.360 --> 00:44:19.290 William Cheng: So this one can look at the the header. So if we look at three over here, it will show you all the memory segment is that hold on a sec. 294 00:44:19.860 --> 00:44:25.920 William Cheng: Okay, you can see that there's a lot of segment over here, right, even though you mentioned that there's text. I mean, there's data segment plus BSS 295 00:44:26.190 --> 00:44:35.550 William Cheng: There's a heap. Second, we're just. Next up is what are all these other segment right you can I see that a lot of sevens over here, we are related to debugging. So therefore, when you set things up for debugging. There's these extra SEC man. 296 00:44:36.060 --> 00:44:42.810 William Cheng: There's a tech segment over here. There's the data. There's BSS. There's also a segment called read only data. 297 00:44:43.650 --> 00:44:51.000 William Cheng: Okay, so, so I think what we need says is that they combine the tech segment a read only did I, since they're all read only. They will combine them into one segment. 298 00:44:51.480 --> 00:45:05.130 William Cheng: Okay, so the read only data over here starts at, you know, the virtual address over here 0804 be a five zero. So we can actually look into that. Okay. To see where that is. So over here, we cannot find it. 299 00:45:07.620 --> 00:45:16.440 William Cheng: Okay, so what can we can do is that we can actually go to the next town over here, we can look for us slash dev slash TTY zero 300 00:45:16.980 --> 00:45:29.130 William Cheng: Okay, we're good at, you're going to see right here the string. I just copy over here, right. You can actually see the last three characters over here exactly the same over here. So this is on page three, and page zero is that 301 00:45:29.670 --> 00:45:44.130 William Cheng: You know, a zero, you know, sort of 48 right so 49 is page one for at page two, and Page three over here is for be so you can add you to see that this one is actually a page number zero. That's what Wi Fi slash deaths ice y zero. 302 00:45:45.990 --> 00:45:50.490 William Cheng: Okay, so I know I'm going pretty fast over here and I'm switching between these two are these different bars again. 303 00:45:50.700 --> 00:45:59.100 William Cheng: You should do the same thing. And look at all these four files 123 and four and try to make the connection of where this data is OK. And then again, when you try to access data over here, you should 304 00:45:59.460 --> 00:46:05.730 William Cheng: Expect to get a pace fall because we have access this one yet. Right. So in this case, again, we get a baseball. You try. 305 00:46:06.150 --> 00:46:13.350 William Cheng: To go to handle page while you need to find it. If you can't find it again look at page down a lot of the bugs are there because people computer right 306 00:46:13.830 --> 00:46:19.890 William Cheng: Computer on page now. Okay, so sorry, at the beginning, the page down should be a small offset because it's 307 00:46:20.190 --> 00:46:29.520 William Cheng: The beginning of the executable file. So please down to be 012345 and things like that. Okay, so if you use the virtual page number which is zero, x 08048 308 00:46:29.790 --> 00:46:33.660 William Cheng: That's a huge number. If you use that to try to get a paste. On. You're going to get garbage. 309 00:46:34.080 --> 00:46:38.310 William Cheng: Okay, once you get garbage. Why, in that case, you had a patient will be incorrect. And then when you start to 310 00:46:38.520 --> 00:46:47.070 William Cheng: Follow the instruction inside the, the current FAQ, you will not see those strings that. So again, where you are cannot to see those strings, chances are, because you use the wrong page now. 311 00:46:47.670 --> 00:46:55.830 William Cheng: There's also there's other possibilities, they address space representation is wrong. So again, that's why the first time, will you get to handle paste all you should use that GDP command. 312 00:46:56.760 --> 00:47:02.640 William Cheng: Guys, what does that GDP command over here as a GDP command over here is this command right Colonel info VM M. 313 00:47:02.880 --> 00:47:10.950 William Cheng: Mapping info over here. So, this one will print out the address space again post that into the class Google Groups that will, this is what I get. Is everybody getting the same thing. 314 00:47:11.280 --> 00:47:18.360 William Cheng: Okay, so some people all the addresses is not sorta it needs to be. Sorta. Some people have, you know, empty, empty memory segment and all kinds of weird stuff. 315 00:47:18.870 --> 00:47:31.980 William Cheng: Okay. That's because one of the VM malfunction you implemented was incorrect as well, you can end up with the wrong address. Yeah. I also want to show you inside a VM malfunction Colonel VM VM malfunction. 316 00:47:32.940 --> 00:47:48.810 William Cheng: There. So let's say you're implement VM map malfunction over here, I see is a function over here. The first argument over here is the VM map and that will be the same, that you know that that actually isn't the same data type as current proc P VM MVP. 317 00:47:49.950 --> 00:47:59.130 William Cheng: Okay, so what you're doing over here is that you actually, you pull the you build a virtual memory map. When you finish putting the virtual memory, Matt, you, you. 318 00:47:59.670 --> 00:48:10.080 William Cheng: Inside the current prod you use the pointer to point to the data server, they are building. Okay. So, therefore, in this case, the first argument over here eventually is going to become current projects VM IMAP 319 00:48:10.980 --> 00:48:21.750 William Cheng: Okay, so therefore you can actually we are building this data center over here, you can use the same command over here. He says, Colonel info VMware mapping for here. And the last argument will be at the argument right here using the map. 320 00:48:22.530 --> 00:48:27.900 William Cheng: Okay, so you should do that at the beginning of VM at the beginning of this function as over here, what I would do is that 321 00:48:28.290 --> 00:48:37.410 William Cheng: When I when I get to the beginning part over here, I will execute this command in GDP or so I'm copy and paste over here, of course, you can't put the code there but you can sort of run the 322 00:48:38.460 --> 00:48:43.920 William Cheng: The, the GDP to type this command. Okay. Over here. The first argument will be map. 323 00:48:44.910 --> 00:48:55.770 William Cheng: Okay, because the map over here is compatible with current problem AP and then in the end, when the function is about to return. I also do the same thing. So this way I can see that whether I have to the new memory segment. 324 00:48:56.940 --> 00:49:05.070 William Cheng: Right, because we are map, map, map over here is to create a new memory segment. So at the beginning, over here, as you have one less memory segment. At the end of the I'm gonna do one more. 325 00:49:05.670 --> 00:49:09.600 William Cheng: Right, so you can actually use easy GDP command to make sure that the are these things are built there. 326 00:49:09.840 --> 00:49:14.970 William Cheng: Also, you can do the same thing. There are also other VM app. Over here, over here says want to remove a memory segment. 327 00:49:15.180 --> 00:49:24.060 William Cheng: Again, you put it at the beginning you put at the end over here. Okay, and now put it at the end, you need to set a breakpoint of the beginning breakpoint idea and they use the GDP GDP compared to see it's actually 328 00:49:24.390 --> 00:49:33.690 William Cheng: The, the kind of changes that you want to have it hasn't happened yet. Okay. If it didn't happen. Well, then in that case you need to devalue so all these functions will be here. 329 00:49:34.170 --> 00:49:43.890 William Cheng: Is rain GMT, the, I guess they don't really manipulate the map VM AP RE. RE from the address paste copy paste from the address space and via map right you know copy 330 00:49:45.420 --> 00:49:54.540 William Cheng: Copy copy data into the address space. So they are unrelated to building address map since I did a memory map. 331 00:49:55.020 --> 00:50:07.680 William Cheng: VM map. Look up. So this want to try to look up a function find range over here is using the first fifth memory alligator VM have inserted. Right. So again, you can sort of put the same thing before and after I have to make sure that we try to insert a 332 00:50:08.550 --> 00:50:14.250 William Cheng: Memory segment right before you have less memory segment. Once you finish in certain Asia. So again, print this one correctly. 333 00:50:15.090 --> 00:50:25.050 William Cheng: We are not create when you finish create. So I would think that this function should work. You're going to end up with an empty map, you should, at the end of this VM or Korea function, you should see you know what will. 334 00:50:25.860 --> 00:50:38.580 William Cheng: What the map supposed to look like the map destroy you can also put it at the beginning. Over here right before destroy you can sort of take a look at what it sees the way it looks. I can make sure they look they look they look reasonable. Yeah. 335 00:50:40.410 --> 00:50:43.440 William Cheng: All right, what else is here. Um, 336 00:50:45.030 --> 00:50:52.290 William Cheng: Okay. And also, you know, meaning a page number of years again. So again, you know, you should definitely read as a try to understand that and then 337 00:50:52.830 --> 00:50:59.490 William Cheng: The meaning of page down, right. So again, this one I keep explaining it over and over and over again in lecture in the discussion slide and then 338 00:51:00.300 --> 00:51:10.950 William Cheng: In Week three discussion section. Again, this picture is very, very important. I just, well some people asked me, you know, whether the first first pray the patient I'm zero be here PF one OB. 339 00:51:11.760 --> 00:51:23.580 William Cheng: Doesn't have to exist or not, please understand that I didn't draw this picture. Okay, so, so, you know, thanks to, you know, some students in for 2013 the student draw this picture. I mean, again, I didn't 340 00:51:24.060 --> 00:51:30.570 William Cheng: Die, you know i i i didn't invent we need. I didn't design when x. So some of the stuff I don't really know for sure. 341 00:51:31.590 --> 00:51:38.670 William Cheng: Okay. So, for example, like the VI de de de over here. So, so this video is not the same one as the one in in handle pays for 342 00:51:39.150 --> 00:51:45.210 William Cheng: This is the one that's the beginning of a memory segment very so again in Week nine I mentioned that the DVR 343 00:51:45.420 --> 00:51:55.380 William Cheng: At the beginning of every segment, I think it's, it's, it's always page alive. But then again, I'm not 100%. Sure. So don't print this page. And this picture, we are. I did enjoy it to be paid July. 344 00:51:56.610 --> 00:52:01.620 William Cheng: Okay, so if you if it turns out it's always page, let me know guys, or maybe I can update you know 345 00:52:02.520 --> 00:52:10.590 William Cheng: I can actually update the current FAQ. Okay. And also, if you have seen that the beginning of a memory segment. It's not page line to get also let me know. So this way I can 346 00:52:10.800 --> 00:52:18.630 William Cheng: Confirm that this picture is actually accurate because sometimes the DDR doesn't have to be the beginning of my memory segment doesn't have to be patient. 347 00:52:19.500 --> 00:52:28.380 William Cheng: Okay. But again, it's kind of makes sense. At the beginning of the memory segment is always page a lot, right. But again, I, I didn't run the code. So therefore, I'm not 100% sure 348 00:52:30.150 --> 00:52:40.920 William Cheng: Oh, I also went over all this. And also, you know, again, you need to use GDP or you need to be able to set a breakpoint in the user space program. So you can. So again, these are all in the kernel FAQ right so you need to 349 00:52:41.430 --> 00:52:51.060 William Cheng: You know, I guess you could go to the colonel FAQ, if you just look for. Hello. Right. And you can actually go all over the place. Look at all the places where there have hello and as you see everything that related to hello 350 00:52:51.540 --> 00:52:57.720 William Cheng: Okay. And also, you know, you can set a breakpoint on lipsey static entry. You set a breakpoint in May. So once you 351 00:52:58.320 --> 00:53:04.170 William Cheng: Enter the symbol file command okay you adding the user space program into GB 352 00:53:04.830 --> 00:53:13.260 William Cheng: You know the into GDP and now GDP can actually say breakpoint in the user space program right before you do the all these commands over here you will not be able to set 353 00:53:13.680 --> 00:53:18.180 William Cheng: A breakpoint user space, but that's okay. You can say break man is a little break at the beginning of the main function. 354 00:53:18.630 --> 00:53:24.930 William Cheng: You can also set a breakpoint at a virtual address. Right. So again, my favorite virtual resurrect 12345678 355 00:53:25.170 --> 00:53:34.320 William Cheng: Okay, so for example if you see a line that look like this. So this addresses is like this. Right, so therefore I can actually say, if I want to set set a 356 00:53:34.770 --> 00:53:44.490 William Cheng: breakpoint there. I can say be star and then pay is the virtual address over here. I guess I have to say zero x that because otherwise. 357 00:53:44.940 --> 00:53:59.340 William Cheng: GDP is going to get confused because you know you need to stay where they're using a hex or not. Right. So if you want to break an any you know assembly code. If you have a you know a virtual address, you can actually break star followed by zero x all by the virtual dress. 358 00:54:00.180 --> 00:54:06.450 William Cheng: Well, you can change the layout of your GDP to be in the assembly mouth. So this way when you try to do a single step. 359 00:54:06.810 --> 00:54:19.140 William Cheng: You can use the SI command. So, so instead of using S S is single step in psycho si a single step in machine judging or you can also use the next instruction to do a next in the sequel. You can also use an eye. 360 00:54:19.800 --> 00:54:27.720 William Cheng: For the next instruction in some in the assembly code there once you get into the ASM over here. It's very difficult to get back 361 00:54:28.440 --> 00:54:30.330 William Cheng: Okay. And also, you got to be very careful with cut 362 00:54:30.570 --> 00:54:40.770 William Cheng: Copy and paste. Once you go into these different kind of layout, you know, GDP is little we're going to end up with. But sometimes, sometimes, will you when things get so bad. You just have to press Control C. 363 00:54:40.980 --> 00:54:47.730 William Cheng: And then, and then and then because you're going to start debugging Linux from the beginning again. Okay, so, so again, remember GDP is not perfect. 364 00:54:48.270 --> 00:54:56.850 William Cheng: Sometimes we can into a best day. Right. So one thing that we use that I will use layout next guy. So this way I can actually keep a cycle through different kinds of layout. Some of them are 365 00:54:57.240 --> 00:55:03.300 William Cheng: Not very useful. So again, keep using the layout. Next, and in GDP. If you keep pressing enter it will repeat a previous commands. 366 00:55:03.570 --> 00:55:14.250 William Cheng: Because once you do it early on, he can keep pressing enter it will cycle through all different kinds of layout even stopped at where you are. But again, when you try to copy style be very, very careful when you try to copy stuff on the top. Sometimes it doesn't work. 367 00:55:14.610 --> 00:55:20.910 William Cheng: Guys will get don't send me email to say, hey, this doesn't work, you know, there's no way to get around that. That just sort of bugged inside GDP. 368 00:55:21.870 --> 00:55:32.670 William Cheng: That if you want to see the register value over here, you can use info register. So again, look at you know yes P BP and all that kind of stuff. And also, if you want to see where the interrupters enable or not. 369 00:55:33.660 --> 00:55:43.440 William Cheng: So again, if you look at this one I enter rub in then enable over here, right, if you say info register you know he flies will be. There's the flood register. 370 00:55:43.860 --> 00:55:55.230 William Cheng: There's, you know, there's a Flacco if telling you where the interrupters that enable or not. Okay. I think election we call IE, right. So we're in it for the entire terminology, like I should call this is where 371 00:55:56.400 --> 00:56:07.770 William Cheng: Oh I so I think that's pretty much everything I want to cover. I guess they're slightly over here called Cisco Darcy. So let's take a look at Cisco. See, so that's the user space or as a user 372 00:56:08.790 --> 00:56:13.410 William Cheng: Lip. Lip see saga. This is the in the C library that's fine you can lift. 373 00:56:16.170 --> 00:56:18.750 William Cheng: Cisco Darcy. This is different from BMS 374 00:56:19.590 --> 00:56:30.780 William Cheng: For the VM FS as this call, because those calls inside of Colonel, right. So this is the user space function over here so we can look at the reef function over here. So this is the racism call right. So yeah, what is it racism Hall. 375 00:56:31.020 --> 00:56:42.720 William Cheng: Right. It's a thin wrapper around a trap machine structure over here it cause a function called trap. So what is trapped. Right. So Greg trap user include star star. He will be here. 376 00:56:43.350 --> 00:56:48.420 William Cheng: So it's in Phoenix user include we next trap that ah yeah 377 00:56:49.320 --> 00:56:57.600 William Cheng: So this is the trap machine instructions. Right. So as it turns out, if you look at this very, very carefully again assembly code. We don't know how to read some people really, really, I should learn assembly call 378 00:56:57.900 --> 00:57:08.280 William Cheng: I still don't know how to read this call. Okay, so, so if you asked me to read as what is equal a I've no idea what I will tell you what the code is doing right what's important. Over here is that you can actually look at the assembly code over here. 379 00:57:09.810 --> 00:57:10.830 William Cheng: Okay, so let's see. 380 00:57:11.940 --> 00:57:14.160 William Cheng: So if we go go back there. 381 00:57:19.980 --> 00:57:24.540 William Cheng: Okay, we can look at the trap machine instruction over here, right. So, here the tribe instruction. OK. 382 00:57:28.740 --> 00:57:32.880 William Cheng: OK, so I guess this is the code out that this is this is this is the code that we just saw. 383 00:57:34.080 --> 00:57:38.130 William Cheng: Okay, so what's important is to understand that this is at the time machine instructions. 384 00:57:38.580 --> 00:57:47.730 William Cheng: Okay in zero x t i mentioned before, is there actually is a software interrupt so for intel is directs to either yourself or interrupt to implement the trap machine structure. 385 00:57:48.150 --> 00:57:58.320 William Cheng: There. So what's funny about this code is that inside this trap function right even though it looks like a function inside of me actually called a chart machines RJ yeah I should call it twice. 386 00:57:59.490 --> 00:58:08.280 William Cheng: Okay. So inside the read function you call this function. So, really, is going to try. These are the corner over here. The first time when it turns out a corner. This will be tracking your 387 00:58:08.610 --> 00:58:23.970 William Cheng: Tribe and for the REE REE function, it will go inside of Colonel, you end up going to sister and sister. You need to go to do read you know and do all that kind of stuff where it says read Greg says we need Colonel started started to see 388 00:58:25.020 --> 00:58:29.790 William Cheng: Okay, so this internal API's is called I see right says read 389 00:58:30.960 --> 00:58:33.570 William Cheng: That. So this will be the function that you have to implement 390 00:58:34.110 --> 00:58:37.170 William Cheng: You know, so again in the user space re is going to 391 00:58:37.380 --> 00:58:47.820 William Cheng: Reach US history. So again, read the comment over here to see what you have to do. And the goal over here is the eventually called do read, write and do it you're very familiar with you've been doing that in your kernel to rise over here. 392 00:58:48.090 --> 00:58:54.210 William Cheng: You know, the user space we reach the kernel version of the religious this read and eventually cause to read there. 393 00:58:55.050 --> 00:58:58.740 William Cheng: Alright, so in the user space called over here again the call call this one. So the call. 394 00:58:59.250 --> 00:59:12.720 William Cheng: It trying to the corner twice. So the first time is actually you know the the the trap the second time over here. Rob is that, remember that you're doing when you're done is I do we you set out the air number 395 00:59:13.140 --> 00:59:18.330 William Cheng: How do you return the air number into the user space. Well, as it turns out, the way you do that you make another system call 396 00:59:19.110 --> 00:59:24.330 William Cheng: Okay. So over here, there are two troubleshooting section. The first one over here, it depends on, you know, which 397 00:59:24.570 --> 00:59:31.800 William Cheng: You know system called calls that that will set up the trap and the second one over here, this one, this one, the code over here 027 398 00:59:32.100 --> 00:59:36.810 William Cheng: That's the one you know that that's a trap machine instruction that will go into the kernel to get the error number 399 00:59:37.800 --> 00:59:46.680 William Cheng: So when this one finished over here. What it will do is that it will copy the return value which is into insight. Yes. And he will copy into this address over here zero x 400 00:59:48.360 --> 00:59:54.060 William Cheng: That's the address for the global variable inside the BSS like then that's know as Aaron number 401 00:59:55.410 --> 00:59:59.730 William Cheng: OK. So again, the second one over here. So, again, not, not now. You know, the mystery of all these you know trap. 402 01:00:00.360 --> 01:00:12.120 William Cheng: trap trap function call over here. So again, this is the trap call over here. The first one is, is the real trap the second one over here, copy the air number and then put it into the global variable here. Okay. 403 01:00:13.080 --> 01:00:29.910 William Cheng: All right, so I guess that's, you know, I guess that's all I wanted to talk about today. So, so again, you know, if you're stuck in getting hello to work, you know, don't wait too long, send me email pose a question to the past, Google group come to office are all these kind of stuff. Yeah. 404 01:00:31.290 --> 01:00:35.250 William Cheng: All right. Okay, I'm gonna end this now.