WEBVTT 1 00:00:04.620 --> 00:00:15.059 William Cheng: Okay, this is week 11 discussion section. So today, we're going to, I'm going to give an introduction to Colonel three 2 00:00:16.109 --> 00:00:16.980 William Cheng: So, 3 00:00:18.090 --> 00:00:30.090 William Cheng: I guess the early submission for Colonel Tuesday next Tuesday. So the, the idea is that you should start Colonel three as early as possible because Colonel three is bigger than Colonel one and two. 4 00:00:30.780 --> 00:00:40.890 William Cheng: Combined. So in the next lecture, I guess I will give you a sort of a recommended you know timeline for, you know, for for Colonel three and that will be next Monday. 5 00:00:43.320 --> 00:00:51.630 William Cheng: Alright, so some of the new stuff in Colonel three. So number one is that, you know, incredible to have a little bit of polymorphous em, you can use a pointer. He calls up 6 00:00:52.080 --> 00:00:57.540 William Cheng: Colonel three. The polymorphous and get a little more complicated almost looked like recursive stuff. 7 00:00:58.530 --> 00:01:06.300 William Cheng: You know, but you know, I guess if you had taken some, you know, data structure algorithm class, you know that any kind of recursion can be turned into a loop. 8 00:01:06.960 --> 00:01:13.560 William Cheng: So inside Colonel don't do recursion. Okay. I mean, there are places probably is very, very difficult to avoid doing recursion. 9 00:01:14.070 --> 00:01:19.020 William Cheng: But the basic idea over here. Is that something that look like a recursive procedure, you should do it inside of a loop. 10 00:01:19.560 --> 00:01:27.360 William Cheng: Because the difference that you make recursion. If you do things using recursion, you're going to end up blow up the the colonel stack. So that will be really bad. 11 00:01:28.050 --> 00:01:33.330 William Cheng: So, therefore, you gotta watch out for kernels that guy, so therefore you can turn into a loop you should do things. Yeah. 12 00:01:34.290 --> 00:01:45.090 William Cheng: Right. So, and in the corner over here says you know where you traverse linked lists of shadow objects you will eventually reach the bottom object and the recursion must stop. 13 00:01:45.690 --> 00:01:50.700 William Cheng: So the idea here is idea of a linked list of objects over here, you follow these pointers over here. 14 00:01:51.060 --> 00:01:59.850 William Cheng: When you reach the end of the year and you don't have to make a recursive car right you can make a recursive call. So they will keep on walking down this list, or you can write your code and loop. 15 00:02:00.360 --> 00:02:12.120 William Cheng: Okay, so for Colonel three you always have to think about it. You know, if you can write things in a loop do it in a loop. Okay. Otherwise, if there's no way to get around that then then then then again you do these things sort of recursive thing. Yeah. 16 00:02:13.140 --> 00:02:19.920 William Cheng: Right, new things and Colonel too is that you have to implement an address space. So again, the colonel doesn't have an address space address spaces for you. 17 00:02:20.460 --> 00:02:25.140 William Cheng: To implement the user, you know that the user abstraction of an address space. 18 00:02:25.740 --> 00:02:31.170 William Cheng: So again, we talked about in lectures address space virtual memory map. They are the same thing, right. So basically we're going to 19 00:02:31.650 --> 00:02:41.400 William Cheng: Use this memory mapping technique inside the cardinal and we, you know, review this this process over and over again. How do you get a page ball. How do you find a page and all that kind of stuff. 20 00:02:41.910 --> 00:02:49.020 William Cheng: So that's one of the first thing that you have to do in Colonel three right it's due to the make sure that these things happen. Yeah, so that's the next thing over here handle pays for 21 00:02:49.620 --> 00:02:55.230 William Cheng: You know key by chapter seven slides in mind if you're confused, you know, go back to the lecture. 22 00:02:55.860 --> 00:02:59.820 William Cheng: Get the lecture, sort of, you know, preparing you know for for for doing kernels right now. 23 00:03:00.210 --> 00:03:10.440 William Cheng: And also in Colonel three. Now we are, you know, running user space program, the user space program actually causes them call right so we saw before. There's do readers do right 24 00:03:10.950 --> 00:03:14.640 William Cheng: Those are the kernel version of the region right you know system call 25 00:03:15.000 --> 00:03:20.970 William Cheng: But again, you going to start from the user space program and eventually you're going to reach to read and write. So again, in the user space program. 26 00:03:21.300 --> 00:03:31.350 William Cheng: The system, what's called return. Right. Okay. So you're kernels three, you're going to see exactly how you go from the read and write system call all the way come into the kernel eventually if your code is 27 00:03:31.950 --> 00:03:41.460 William Cheng: If you call it correctly, it will reach to read and do right okay if your buddies are Colonel, you will never reached over and do writers that they need to debug your kernel code and try to find out what's going on. Yeah. 28 00:03:41.970 --> 00:03:49.170 William Cheng: And also there is a Yo, you're going to end up implementing the system call rather you know that the folks is imposing the user space. So, by the way. 29 00:03:49.560 --> 00:03:54.810 William Cheng: In Colonel three all the user space program all the user space code has been written for you already. 30 00:03:55.590 --> 00:04:03.720 William Cheng: Okay, so you don't have to write a single line of users user space code. Okay. So, therefore, all the system called when I say that you have to implement it, you have to implement it inside, Colonel. 31 00:04:04.770 --> 00:04:15.300 William Cheng: Okay, so your user space all the CO written for user, you need to know single step to see where it goes. Remember the system calls a thin wrapper around the track machine instruction in Colonel three you can find out. That's exactly what it is. 32 00:04:15.600 --> 00:04:25.020 William Cheng: Okay, so when you know, eventually we are you going to invoke the Traveler you trappings that occurred, all you're gonna see where it goes. And then, you know, eventually, you need to sort of handle all the system correctly. 33 00:04:25.380 --> 00:04:31.860 William Cheng: So there's going to be a lot of system call you have to implement them to make sure that they are done correctly, or what will will will eventually get 34 00:04:32.700 --> 00:04:36.510 William Cheng: There. Alright, and debugging is going to be a lot more difficult. 35 00:04:36.720 --> 00:04:48.000 William Cheng: You may have to single step machine instruction to find bugs that so the Colonel, you know, three bugs are pretty tricky, right, because you're a user space CO and sometimes things doesn't really happen and then you got you got to end up with a kernel panic. 36 00:04:48.600 --> 00:04:56.340 William Cheng: We're going to get a kernel baseball and they use a while. What happened where I'm going to get a lot of email to say, you know, I'm you know my my Colonel crash. 37 00:04:56.640 --> 00:05:07.080 William Cheng: Tell me what happened. I have no idea what happened. Okay, so. So what do you need to do is that you need to find out you need to pinpoint and machine instruction that cause the you know the cost of fault. 38 00:05:07.680 --> 00:05:11.160 William Cheng: Okay, so there's going to be some, you know, a thought over here is not handled correctly. 39 00:05:11.370 --> 00:05:19.230 William Cheng: You need to find out exactly which machine structuring the cost of all right i mean you you're sort of prepare for it in current one and two, every time when you get a pure, good, good. 40 00:05:19.590 --> 00:05:33.840 William Cheng: Every time we get a colonel paste all I say you should read the colonel FAQ. And then, and then, you know, near the top I get the third third or fourth item tell you exactly find out which machines judgment calls the fall. Okay. That's why you have to do otherwise it's impossible to debug. 41 00:05:34.920 --> 00:05:44.250 William Cheng: Okay, so, so, so you so you end up with some bad code, you know, Colonel is going to crash. So you need to find out exactly what you know which machine instruction cars crash. 42 00:05:44.730 --> 00:05:58.440 William Cheng: So in kind of wanting to you were looking as see statement that caused the crash in Colonel three sometimes you have looked at a machine shop and why do you ever look at the machine instruction net because in one scene instruction, they might track into the kernel twice. 43 00:05:59.940 --> 00:06:03.450 William Cheng: Okay, so let me say that again. Right. One ceased, a man my end up track. 44 00:06:03.750 --> 00:06:11.790 William Cheng: You know, tapping into the internal twice. So, therefore, you know, it's very important to find out whether you crush the first time it comes to that point on. Second time because it is that a colonel right 45 00:06:11.970 --> 00:06:15.360 William Cheng: If you only debug at the sea level code, you don't really know what's going on. 46 00:06:16.080 --> 00:06:24.660 William Cheng: Okay, so sometimes one legacy code is going to you're going to end up dropping into the kernel multiple times, right. So, therefore, you know, something you have to switch to assembly code single step. The assembly call 47 00:06:25.110 --> 00:06:30.960 William Cheng: So again, look at the current FAQ, they sort of tell you all this kind of stuff you know you got you hopefully you got used to doing string search 48 00:06:31.140 --> 00:06:39.870 William Cheng: Right, so, so, you know, you know, he wants a single state machine instruction. So, so look for these words inside Colonel FAQ, and then tried to find the corresponding carnal FAQ items right 49 00:06:40.830 --> 00:06:52.920 William Cheng: Alright, so, so some of this stuff is, you know, quite involved so so in Colonel three again if you get stuck in, you know, in one day. So, so you're stuck for one day. You should ask for help. Right. So again, if you asked me, Well, 50 00:06:53.430 --> 00:06:59.130 William Cheng: Ask the question in a you know in a in a smart way. And remember that I cannot tell you what code right 51 00:07:00.060 --> 00:07:05.490 William Cheng: Okay. So, therefore, if you want your email to me to be useful. You need to ask the right questions. 52 00:07:06.300 --> 00:07:12.450 William Cheng: Okay. And also you need to provide me with you know enough information. So I can actually sort of figure out, you know, how should I help you 53 00:07:13.140 --> 00:07:20.460 William Cheng: Okay, maybe I started to maybe set a breakpoint right there and take a logo or something like that. But if you don't tell me that he's you said you just say my Colonel crash and how can I help you 54 00:07:21.300 --> 00:07:25.950 William Cheng: Okay, so you gotta be. You gotta, you gotta be very specific. Tell me you tell tell me exactly where you are. 55 00:07:26.220 --> 00:07:37.440 William Cheng: So this way you know the turnaround time is going to be much, much faster, right. So of course, I always recommend people to post some classical group because closes Glasgow, you're going to get a much quicker turnaround time. Okay. 56 00:07:39.870 --> 00:07:48.480 William Cheng: Alright, so for Colonel three. So, so again, some people are confusing. Colonel to are they they they incur one to 10 on drivers and turn off to they turn turn off drivers. 57 00:07:48.690 --> 00:07:55.410 William Cheng: Don't go back. Okay, this is, this will only going to go going one way. So when you start Colonel three, you're going to turn on all the flags. 58 00:07:55.920 --> 00:08:05.010 William Cheng: In kind of one and two, and then you continue, you know, bye bye bye bye turning the colonel through fact the the colonel three fact that the currency flags inside conflict I ok now. 59 00:08:05.550 --> 00:08:12.480 William Cheng: So over here, these are called VM ICO three is basically doing VM. You also need to turn on as five Fs s five 60 00:08:13.020 --> 00:08:18.600 William Cheng: S equals two. Why, right, because when you go to include all three. You have to switch to a different process them if you turn on. 61 00:08:18.900 --> 00:08:27.300 William Cheng: As far as equal to one and VM equals one and you say, Magnolia implement it. You got to see that there's a lot of functioning that needs to be implemented. Right. So there's one slide over here. 62 00:08:27.540 --> 00:08:34.350 William Cheng: And then I guess the next slide over here. There's a lot of functions over here. Okay, so let's take a look at, you know, all these functions that you have to implement. Yeah. 63 00:08:36.780 --> 00:08:36.900 William Cheng: The 64 00:08:38.100 --> 00:08:45.390 William Cheng: Function is in preferring Darcy right P for instance for page frame. And I mentioned before piece RAM is a very important concept in the kernel. 65 00:08:45.870 --> 00:08:56.160 William Cheng: So again, he's every page rain. There is a bunch of stuff. Right. They are the patients that data structure that keep track of some of the mapping from, you know, virtual address the physical address all these kind of stuff. 66 00:08:56.340 --> 00:09:04.290 William Cheng: Right. So again, that's very, very high level description. So when you. The first thing you have to implement when you go to Colonel three is to finish P friend Darcy. 67 00:09:04.740 --> 00:09:10.260 William Cheng: Okay, so people can now see there's lots of function and then OK. So again, it's a very complicated. You know implementation over year. 68 00:09:10.710 --> 00:09:17.700 William Cheng: So while you're while you're while you're required to do is only implement three function. Okay, what is called P frame get this one is the most you know the 69 00:09:17.940 --> 00:09:24.120 William Cheng: The, the most complicated one. Out of these three. So again, read the comment very, very carefully and try to figure out what to do that. 70 00:09:24.510 --> 00:09:37.140 William Cheng: The other two over here is called a paper and pen and paper and pen. I'm going to sort of briefly talk about that in the next lecture. Okay, so, so, so, so therefore, you know, will you know again these are actually put it, you know. 71 00:09:38.100 --> 00:09:42.720 William Cheng: Pretty simple. And the basic idea of yours that it is that the last lecture. 72 00:09:43.170 --> 00:09:51.360 William Cheng: You know lecture 22 I talk about the page on demand. So what happened is that the colonel need to play hide and seek with the page on demon 73 00:09:51.840 --> 00:10:00.000 William Cheng: OK, so the way that you hire page rain is by calling paper and pen and then all of a sudden, this patient disappear, and now the page on demon, can, can the page document can never see it. 74 00:10:00.390 --> 00:10:07.680 William Cheng: Okay. And there's some point, you need to bring it back so you copy friend I'm pin and all of a sudden that patient appear so that the page or demon can find it. 75 00:10:08.430 --> 00:10:21.000 William Cheng: OK. So again, this is really simple. So anyways, read a comment if I know what to do. P friend get I'm going to talk about it. Towards the end of today's lecture. OK. So again, that's an important function. So the idea here is that you need to, so you 76 00:10:22.020 --> 00:10:27.900 William Cheng: You need to get a PageRank. Okay, so, so go to sort of talk about, you know what, well what that means. A little later. Yeah. 77 00:10:28.650 --> 00:10:35.670 William Cheng: Alright so so so often is that at the beginning of Colonel three. The first thing you need to do is to set f5 FS equals two, one. Okay. 78 00:10:35.880 --> 00:10:45.390 William Cheng: But you should keep the me go to zero, okay, because you are not ready to implement user. The user space over here and then setting the m equals two, one, that means that you're implementing user space program. 79 00:10:46.020 --> 00:10:55.950 William Cheng: Okay, so before you get there you got to make sure you have a good implementation of the PageRank. Okay. Because if you don't have page frames, if you're patient has bugs and you start running your user process, forget it. 80 00:10:56.580 --> 00:10:59.550 William Cheng: Okay. Your user process just you know when when the, when the user president 81 00:10:59.790 --> 00:11:05.460 William Cheng: Assad run. Last time I you know I guess two lectures guys automation, what's going to happen. Right. Well, as soon as you start running a program you're going to get 82 00:11:05.640 --> 00:11:13.050 William Cheng: We're doing on demand paging you're going to get a pace fall. And now we're going to go to the disk and get your pace frame. What if your PII friend code doesn't work. 83 00:11:13.770 --> 00:11:18.930 William Cheng: Well, don't forget it. Right. There's no if we don't use Facebook had to work. So you got to have a reliable way to say whenever you need a pastry and 84 00:11:19.140 --> 00:11:26.880 William Cheng: You call your friend get, you know, whatever the right thing will happen. And then in the end going to end up with a PageRank. Then, so P for him get has to be very, very reliable. 85 00:11:27.480 --> 00:11:31.380 William Cheng: Okay. So anytime you need a Patreon you copy for and get you going to end up with a, you know, 86 00:11:31.710 --> 00:11:38.580 William Cheng: I guess there are two different functions. One is copy for him. Look up the otherwise copy from gap look up as a higher level function just like you in the system. 87 00:11:39.540 --> 00:11:49.530 William Cheng: Kernel to you're going to perform a look up on June. Okay, you try to find something. So that's a look up on June and the get is actually go go go go go go go go go. I think Peter and get will create a patriot. 88 00:11:50.910 --> 00:12:00.930 William Cheng: Or as okay you need to sort of figure out what is the difference between a look up and also again. Okay, so. So inside that we need, Colonel. They tried to name all these functions pretty consistently. 89 00:12:01.290 --> 00:12:10.140 William Cheng: Okay, so look up is looking at the side of data structure, trying to find something and get his to, in the end, I guess, I guess in Colonel to you also see these fungible. I forget. 90 00:12:10.830 --> 00:12:23.730 William Cheng: Where I sort of get f get is to create, you know, Cuckoo, cuckoo, cuckoo, create a file object and then there's the get to create a vino Rog ERS or something. Get something good. They're all creating an object of that high, so people get is to create a PageRank. 91 00:12:24.660 --> 00:12:32.430 William Cheng: Or as it again if this doesn't work. Forget about the rest of your kernel three. Okay, so this function needs to work reasonably well so that you can proceed. Okay. 92 00:12:33.210 --> 00:12:44.490 William Cheng: Right. So once you're done with that. The next thing you have to do is to implement the address space, right. So, so the way they're going to address business virtual memory map your current. Oh, Simon. This is known as VMware virtual memory map. Okay. 93 00:12:45.420 --> 00:12:48.750 William Cheng: I think inside this file, you pretty much have to implement every function. 94 00:12:49.230 --> 00:12:52.230 William Cheng: Okay, none of them has implemented for you guys. What again what is VM. 95 00:12:52.530 --> 00:13:03.000 William Cheng: You know, what is the virtual memory, Matt. Right. There's a link list of as region. We also mentioned that these are called VM area. So a virtual memory map is simply a link list of VM areas. 96 00:13:03.240 --> 00:13:14.940 William Cheng: Okay, and every VM area has a start addresses and address again these are started and virtual addresses okay that describe the segment and also they would tell you, you know, this previous segment is read only or rewrite or execute or whatever. 97 00:13:15.330 --> 00:13:18.990 William Cheng: It will also tell you that you know whether this, you know, this particular memory segment. 98 00:13:19.530 --> 00:13:25.020 William Cheng: Is private or share right if it's privately, let me say you're doing copy of it is private and rewrite that means you can copy. All right. 99 00:13:25.290 --> 00:13:33.690 William Cheng: Okay, so all that information is stored inside the linear list of VM area and the entire data structure is known as a virtual memory map. Yeah. 100 00:13:34.620 --> 00:13:42.810 William Cheng: All right, so there's a bunch of function that you have to implement. Okay. Some of them are needed by the loader in API elf 32 Darcy. 101 00:13:43.530 --> 00:13:54.630 William Cheng: There so so so often is that, you know, once you so so once you said yes. So, so let's say you finish people and get people in pen and paper and pen. Then what you do is that you said the n equals two, one as a 102 00:13:55.140 --> 00:14:03.120 William Cheng: backtrack a little. Okay, so once you get the three function to implement it to do the going to run correct correctly, you need to pass BFS test again. 103 00:14:03.960 --> 00:14:14.130 William Cheng: Okay, but now you're testing BFS with a system for file system and now with a referral system. Right. So again, the main difference businesses and above us in the referral system is that system five houses and has a disc in it. 104 00:14:15.120 --> 00:14:23.370 William Cheng: Okay. So, therefore, what you tried to access the desk for, for example, when you try to read a, you know, read, I note your current affair will fall asleep. 105 00:14:24.150 --> 00:14:29.760 William Cheng: Okay in RAM file system where you go read the I know you kind of go through it you know your cursor is I don't fall asleep because because there's no desk. 106 00:14:30.330 --> 00:14:40.020 William Cheng: Okay, so therefore you turn right away. There's no blocking. But what you have, as far as it goes, Well, we're running the code from Brown University. We don't have the source code, we only have the library file. 107 00:14:40.830 --> 00:14:45.630 William Cheng: Okay, so this case when you tried to transfer data for this into memory your current author fall asleep. 108 00:14:46.470 --> 00:14:55.050 William Cheng: Okay. So, therefore, if you have reference counting bugs. Now they're going to show up. Okay. And then you'll kernels come crashing up and rise. Okay, you need to sort of fix up your carnal to code. 109 00:14:56.190 --> 00:15:05.400 William Cheng: To make sure that you can actually work with justice system. Okay, so once you pass BFS has then you already said the N equal to one and now you're you're working on user space forward. 110 00:15:07.080 --> 00:15:13.650 William Cheng: Okay, so you're improving the user space mobile. And so what happened is that you're you're in a process right so you get the idol, particularly in the process. 111 00:15:13.830 --> 00:15:26.970 William Cheng: And now the inner process will go into user space and become a user space program. That's how you get the user space program. Okay, you, you start on inside the colonel colonel process. And now you go into user space. 112 00:15:28.170 --> 00:15:30.900 William Cheng: Or so you start running that program. What it will do is that 113 00:15:31.230 --> 00:15:40.500 William Cheng: So. So this case is almost the same thing as running an exact system call right when you run exhaust system called you can instead of Colonel you wipe all the address space you create new address there and now you go interview. 114 00:15:41.040 --> 00:15:50.160 William Cheng: You go into the user space program. And the first thing that you will do is that he will execute a startup function, right, the cell phone. She's the one that calls me and also take the return value main collected on it. 115 00:15:51.390 --> 00:16:00.690 William Cheng: Okay, so therefore you for your current or three. What happens that he's in the process. You need to go into the user space and now you're going to start using on demand page and you start going to start writing your code. 116 00:16:00.990 --> 00:16:06.960 William Cheng: Instead of sort of function right and on demand page I sort of you know i i described, but the process has to be 117 00:16:07.170 --> 00:16:14.220 William Cheng: For the tech segment for that, you know, for the data segment and also for the sex admin. Okay, so, so, so, so in that case you have to implement all that 118 00:16:14.520 --> 00:16:20.610 William Cheng: Now, all right but but before we go into the user space, you need to build the address base, who is building the address as 119 00:16:21.360 --> 00:16:30.360 William Cheng: Good. As it turns out, the loader is the one that build the address as well. What is the loader right the way I described the loader is that the loader is the one that go to the desk and unfolds. 120 00:16:30.840 --> 00:16:38.670 William Cheng: And for the program into memory. So therefore, in this case the program that you need to run. I mean, Colonel three. The first rule you need to write. It's called hello 121 00:16:39.300 --> 00:16:49.590 William Cheng: Okay, so what it will do is it will find the hollow program, you know, make sure the has everything there. And then what he will do is it will build the data you build the address base by calling some of these function right here. 122 00:16:49.830 --> 00:16:57.270 William Cheng: Okay, because all these VMware function is creating space, so it will cause some of these functions. Okay, you need to look at the code is that elf 32 Darcy. 123 00:16:57.510 --> 00:17:04.950 William Cheng: And then look for, again, usually use, you know, string search. Look for anything that start with BMI underscore, those are the function that it will 124 00:17:05.280 --> 00:17:14.490 William Cheng: They will cause again all this color written for you already. You don't have to write any code. So what it will do is that the loader will build the address space for you I calling these functions that you will you will have to implement 125 00:17:15.840 --> 00:17:27.540 William Cheng: Okay, so what you have implement enough functions over here, then the loader will be able to build the address space. Once the address space is build the load is going to return and now you're going to go into the user space program. And now I'm going to start getting paid for. 126 00:17:28.230 --> 00:17:35.010 William Cheng: In order for you to handle pace while you've got to have the address space implemented. Okay. Because otherwise, where you get a patient, you don't know what to do. 127 00:17:35.490 --> 00:17:41.280 William Cheng: Okay, so therefore, some of these functions be implemented before you're ready to go into the user space. Yeah. 128 00:17:42.150 --> 00:17:48.870 William Cheng: Alright, so as soon as you get into user space. The first thing you'll get is a baseball guy. So, therefore, you have to handle paintball 129 00:17:49.380 --> 00:17:57.660 William Cheng: There is a function called baseball Darcy inside this function. I think there's only there's only one function called handle baseball. Okay, so that's where you have to handle 130 00:17:58.260 --> 00:18:04.530 William Cheng: That, that's what you have to handle all your baseball. Okay. So you can imagine that this, this function is pretty complicated. 131 00:18:05.490 --> 00:18:07.950 William Cheng: Okay, so as soon as you get your page. All you need to find out which 132 00:18:08.220 --> 00:18:20.400 William Cheng: virtual address that you get paid for all. So the, the function. Go ahead and pay for the first argument over here is the virtual address. It's called V add are okay. So every time you see a VA DDR 133 00:18:20.820 --> 00:18:29.760 William Cheng: Sort of, again, I think winnings. They're trying to be very, very consistent. Every time you see the the you know the DVR. That means that it's a virtual address in user space. 134 00:18:30.270 --> 00:18:41.130 William Cheng: Okay, which means that this value is less than, less than zero XE 0000000 okay so we add our means it's a user space virtual dress. 135 00:18:41.670 --> 00:18:51.000 William Cheng: They also call something called K. Dr. K DVR Acadia is going to be a kernel space virtual dress and that one is going to be greater than or equal to zero XE 0000 136 00:18:52.950 --> 00:19:03.330 William Cheng: Or so, and paste over here. You start with the virtual dress. They also have another argument. Tell you what kind of pays for it, as you know, did you try to read a page, you try to write a page, you know, etc. So again, 137 00:19:03.600 --> 00:19:05.820 William Cheng: Read the comment blog over here and see what you have to implement 138 00:19:06.150 --> 00:19:16.320 William Cheng: Okay. So, this function is pretty complicated. And it's one of the earlier so so so you have to implement P frame we have implement VM and all this kind of stuff. You also need to implement I'll handle baseball 139 00:19:16.650 --> 00:19:24.120 William Cheng: Before you can run your first program. Okay, or you can start running. But in this case, you can get a pitfall. And then you have to start fixing your code right here. Okay. 140 00:19:26.250 --> 00:19:33.510 William Cheng: All right. And also, you know, in order for you to guess I'll be here. I actually, I you know I guess the top left side over here is that 141 00:19:33.990 --> 00:19:37.380 William Cheng: This one tells you what you need to do in order for you to run the hollow program. 142 00:19:38.070 --> 00:19:46.410 William Cheng: Okay, so, so again, in order for you to write Alibaba, you have to implement all these functions. So, hello, is actually pretty difficult to get it to work. Other things that the hello do. So what is 143 00:19:46.980 --> 00:19:55.680 William Cheng: Our program do so the whole program and what it will do is it will open to devices, you know, it will open, you know, slice slice TTY zero 144 00:19:56.100 --> 00:19:58.890 William Cheng: For reading and that will be your standard and it will also 145 00:19:59.190 --> 00:20:08.400 William Cheng: You know, read a chart to open sides si, si y 04 righty, that will be your standard out. So what it will do is that, you know, it will, it was set up a file descriptor zero and one. 146 00:20:08.610 --> 00:20:18.270 William Cheng: Okay, and then he will make the racism call right racism, called the first argument over here is one to call standard out and then he will write the Hello World message into the device. 147 00:20:18.720 --> 00:20:21.270 William Cheng: Okay, so therefore, in order for you to get get that to work. 148 00:20:21.450 --> 00:20:32.940 William Cheng: Again, all the user space program has been written for you the racism or the rest of the invoice has been written up for you. And now when they come inside the Colonel. The Colonel version of the read and write is actually costs. This read and sis right 149 00:20:34.320 --> 00:20:41.850 William Cheng: There. So this is the initial you know the the initial corrosion kernel version of the read and write the 150 00:20:42.210 --> 00:20:47.310 William Cheng: The kernel version of the return racism Hall. But again, they are, they're really not system, but because they're actually inside a carnal right 151 00:20:47.460 --> 00:20:57.150 William Cheng: This isn't called is what you do is I use your space. Yeah. So when they come into the kernel, they will come here and the goal for you. So if you come into sis read your goal is to reach do read 152 00:20:57.630 --> 00:21:03.840 William Cheng: Okay, if you come to justice. Right. Your goal is to go to do right if you come to assist get 153 00:21:04.080 --> 00:21:10.830 William Cheng: Get directory entries. Your goal is to go to do get directed energy or I can't remember exactly what the name is. But again, you know, 154 00:21:11.040 --> 00:21:19.410 William Cheng: In Colonel to you have dealt with this function so incredible three, you're going to start out to be in one of the system underscore function and the goal is to go to do underscore functions. 155 00:21:20.730 --> 00:21:29.190 William Cheng: Okay, so it says I've got over here. There are three functions of the implement the read and the right i don't think i think for the hello program. You don't have to 156 00:21:29.580 --> 00:21:38.310 William Cheng: You know, implement get directory entries. You also don't have to implement, you know, sis read because all you need to do is to implement. Right, right. Because you're writing the Hello World message to the 157 00:21:38.820 --> 00:21:46.620 William Cheng: Device. And remember, since you're doing to the device. This kosher, you know, once you're calling do right, eventually, it should go to special file right 158 00:21:46.920 --> 00:21:53.070 William Cheng: Right, because, you know, Colonel to you know that in special for all right. You're right into a device. So guys, okay, you need to connect the dots over here. 159 00:21:53.520 --> 00:21:54.810 William Cheng: You know, in order for you to figure out what to do. 160 00:21:55.680 --> 00:22:04.410 William Cheng: right inside API. There's a phone call access, see there are two function, you have to implement one is called the address permission and the other one is called range permission. 161 00:22:04.770 --> 00:22:11.190 William Cheng: The range of issues mission over here is that you're going to give it an address range, you want to check whether you have access right to this address range or not. 162 00:22:12.210 --> 00:22:17.850 William Cheng: Okay, so again this address range over here has a star virtual address has, you know, I think it has a length or something like that. 163 00:22:18.240 --> 00:22:27.930 William Cheng: So what you are conceptually what you have to do is that you need for every virtual address over here. You're going to call the address permission to see if a particular virtual address, you have the permission. 164 00:22:28.290 --> 00:22:36.420 William Cheng: Okay, so now the argument over here will tell you what kind of permission, you're looking for. Do you want you know re permission right permission or execute permission. I don't remember exactly what 165 00:22:36.870 --> 00:22:42.810 William Cheng: What it has. But anyways, the idea here is that you want to make sure that this range of addresses has a certain permission. 166 00:22:43.410 --> 00:22:48.480 William Cheng: Okay, and you can also use individual address over here to try to try to figure out what the permissions are 167 00:22:48.870 --> 00:22:54.750 William Cheng: So remember, you know the the protections that a kernel is one page at a time so you don't really have to check every, you know, 168 00:22:55.410 --> 00:23:03.030 William Cheng: Every virtual dresses over here. All you have to do is to check. You know, if you're at a pace boundary. All you have to do is if you check whether the first bite. 169 00:23:03.300 --> 00:23:10.290 William Cheng: The first address of the page line address has permission or not. Because if the page line that goes have permission. The entire page has the permission. 170 00:23:10.650 --> 00:23:21.360 William Cheng: And so therefore, the way you should implement the range version of yours that you need to find where the pages are and then for every one of the the page outline address you call address permission to check whether you have the permission. Permission. 171 00:23:22.110 --> 00:23:33.840 William Cheng: Yeah, so I think I guess I'm not sure whether the range permission. The beginning items over here. Does it have to be paid align. So again, you need to read the comment to find out whether it has to be paid or not. Yeah. 172 00:23:34.770 --> 00:23:41.370 William Cheng: All right. And then there's something called a memory management object over here or M n O BJ the demo BJ. 173 00:23:42.270 --> 00:23:49.230 William Cheng: Mentioned, now there's something called anonymous object. So in order for you to get hello to work, you have to implement the anonymous object. 174 00:23:49.650 --> 00:23:56.550 William Cheng: The object over here, I think, is that this file, none of the function are implemented for you so you have to implement all these function, you know, 175 00:23:57.120 --> 00:24:04.950 William Cheng: Over here. So again, read the comment if I know what you do. I'm always getting a lot of questions over here just said, I know the comment over here says anonymous Phil page 30 page. 176 00:24:05.580 --> 00:24:13.500 William Cheng: The colonel, you know, common to say they are pretty straightforward. Okay, and the student asked me, what are they supposed to do, I say, well, they're very straightforward. 177 00:24:13.890 --> 00:24:25.560 William Cheng: I, again, I think I cannot tell you what code. Right, right. So again, feel free to discuss that in the classical group to, you know, says, Okay, I mean, a lot of times, sometimes you just have to try something. Okay. If it doesn't work, you fix your code. If it works great. 178 00:24:26.970 --> 00:24:28.950 William Cheng: Okay, so again, take that as a hint. Okay. 179 00:24:30.360 --> 00:24:30.690 William Cheng: Alright. 180 00:24:31.800 --> 00:24:39.720 William Cheng: Alright, so, so also in the next lecture, the next lecture is going to be next Monday. I will give you everything that you need to know in order for you to input to finish Colonel three 181 00:24:39.960 --> 00:24:44.100 William Cheng: I'm going to sort of talk about a little more detail of you know this this memory management objects. 182 00:24:44.610 --> 00:24:51.150 William Cheng: So they're all these different kind of every on every object. So again the next lecture or you will have everything that you need to know. So here I'm going to sort of skip 183 00:24:51.750 --> 00:24:54.630 William Cheng: You know, some of these of every manager object right here. Yeah. 184 00:24:55.170 --> 00:24:55.560 William Cheng: All right. 185 00:24:55.980 --> 00:25:01.860 William Cheng: Have you ever drawn a line right above here. Okay, so these are all the function that you have to implement. So in order for you to get hello to work. 186 00:25:01.920 --> 00:25:11.550 William Cheng: You need to get all the above to work, except for sis Rita assists get them, whereas over here. This one is crossed out over here and this one is sis get directory entries over here. 187 00:25:13.290 --> 00:25:17.700 William Cheng: Okay, so, so I just want to clarify. I think this is all you need to implement 188 00:25:18.480 --> 00:25:24.900 William Cheng: Okay, so you know I'm known to make mistakes. Once in a while if I'm, if I made a mistake. You just have to tell me and 189 00:25:25.380 --> 00:25:35.070 William Cheng: I'll try to fix this slide or some people get really angry to say, oh, you told us today is not true. Okay, so I'm not making promises that this is exactly what you have to do. Right. I didn't write the code. I have no idea. 190 00:25:35.520 --> 00:25:46.710 William Cheng: Okay, I only pass you the words that I heard from other students. So my understanding is that this is all unique okay if it turns out I'm wrong, tell me that I'm wrong. Okay, and then I'll fix the slide. Okay. 191 00:25:49.800 --> 00:25:50.160 William Cheng: All right. Alright. 192 00:25:50.790 --> 00:26:01.080 William Cheng: Hello, uh, you know you. There's also something called shadow object Greg again right now. You don't know why shadow objects are the next lecture next Monday. I will tell you everything about shadow IT. I'm going to spend a lot of time. 193 00:26:01.290 --> 00:26:08.520 William Cheng: On shadow object because they are very important. Okay. Shadow obvious complicated. We only need it when you are running 194 00:26:08.790 --> 00:26:20.310 William Cheng: You know, one of the application group. So, so if you look at the grading gala and Colonel three, you're going to see that the first program yet passions. Hello. There are also other been bunch of user space program. There's a bunch of simple user space for the last simple the last 195 00:26:21.510 --> 00:26:26.730 William Cheng: Section, be of the grading guidelines. So it's actually be a winner. And the last one is called fork and way. 196 00:26:27.210 --> 00:26:36.180 William Cheng: Okay. The, the co worker ways is the first program that you saw in this class. Right. Remember the parent process for call the child processes apparent wait for the child to die. That's for can wait. 197 00:26:36.480 --> 00:26:42.840 William Cheng: Okay. So in this case, you know, this will be the first time you have the user space program will make the fork system call 198 00:26:43.710 --> 00:26:51.330 William Cheng: Okay, the fork system call you know it's not Colonel, there's a function called do for the do for is probably the most complicated function, you have to write in Colonel three 199 00:26:52.230 --> 00:26:58.020 William Cheng: I mean I'm not saying the other ones are easy. Okay, but do fog is pretty involved right because you know when you come out of Colonel, you need to, you know, 200 00:26:58.170 --> 00:27:05.130 William Cheng: Create a child process and copy everything that you have to copyright, you have to copy of a copy of the address space and all that kind of stuff you need to share 201 00:27:05.670 --> 00:27:14.370 William Cheng: You need to you need to share all the memory segment, all that kind of stuff. So again, you know, you need to find out exactly what you have to implement, you know, if we do for for for you to for yeah 202 00:27:14.640 --> 00:27:25.800 William Cheng: Alright, so again, so. So in this case you need to support all the system called like do fork over here. So, so there's a function called for Darcy inside the proc directory, you have to implement do for 203 00:27:26.580 --> 00:27:31.680 William Cheng: Insert a third I see there's a function that you didn't have to implement, you know, one is called K through a call. 204 00:27:32.910 --> 00:27:40.110 William Cheng: And I really don't know why it's there. Okay. Because, you know, the basic idea over here is that it will you will you perform a fork, you need to make copy of threats. 205 00:27:40.620 --> 00:27:48.120 William Cheng: Or ever since we're doing MTP what a zero right multiple separate process. You go to zero. Well, it only, only one, you know, we only have to copy one on thread. 206 00:27:48.630 --> 00:27:52.770 William Cheng: So you can actually do it inside do for you don't have to, you know, call K through a call. 207 00:27:53.220 --> 00:28:06.270 William Cheng: But I think the the way that the the Brown University people, you know. Organize, organize a code is that they're getting ready for multiple separate process. Right. So, therefore, they're going to sort of write a function over here so that instead of currently can actually Kona threat. 208 00:28:07.290 --> 00:28:13.140 William Cheng: Alright, so again you can you can read your code in there and they have do for call case we're calling to make a copy of the thread. 209 00:28:13.590 --> 00:28:23.790 William Cheng: Or you can do everything is I do, for I don't see any difference, guys. So anyways this is really up to you. Yeah. All right. Another version got a map right and map is the end map system call ok so again. 210 00:28:24.960 --> 00:28:37.440 William Cheng: There's a cyst em map and then assistant and not eventually she she reached do a map. The map and to do in a map or they're not implemented. So, therefore, you have to implement that guys okay this is how you map, you know, 211 00:28:38.580 --> 00:28:46.470 William Cheng: I guess we are in class. Was it sort of talk a little bit about the emphasis and call it an absolute call you're going to map part of a file into your address space. 212 00:28:47.550 --> 00:28:58.470 William Cheng: Okay. So as it turns out, the MS is imposed a little complicated. You can actually also map anonymous memory into address space. So instead of going to the dentist to get data and now you're going to ask the anonymous object for data. 213 00:28:58.980 --> 00:29:09.510 William Cheng: OK. So again, you know, for the for the stack segment for the heap segment you know right below the, the, the VM area or as region. There's a point at that point to anonymous object. 214 00:29:10.200 --> 00:29:17.940 William Cheng: Okay, so now we can also map something in Maps. I'm remembering to address space and and this memory can be anonymous memory. 215 00:29:18.900 --> 00:29:29.700 William Cheng: Or so you can either map a data from the desk on the desk or Matt, you know, data from anonymous memory. Okay, so. So again, if you're interested, you know, Do do do do a man em app. 216 00:29:31.320 --> 00:29:33.720 William Cheng: Yeah. So let's take a look at the the Linux. 217 00:29:34.020 --> 00:29:42.570 William Cheng: You know man pages for em app. So again, it's pretty complicated. We don't have to implement everything there. But again, you should read a little bit so you understand, you know what, you know, what will 218 00:29:42.810 --> 00:29:48.960 William Cheng: You understand what the function arguments you what the function arguments means ok and then later on, you know, towards 219 00:29:50.640 --> 00:29:55.200 William Cheng: Towards later Parker's otherwise you get for can wait to work. I think he you know 220 00:29:56.520 --> 00:30:00.840 William Cheng: At some point you you some point a little later. You have to, you have to get these functions to work. Yeah. 221 00:30:01.980 --> 00:30:10.440 William Cheng: All right. And then there are also something called a break. So as soon as a woman. So what is break. Alright, so. So as it turns out, that is that Colonel 222 00:30:10.740 --> 00:30:19.860 William Cheng: You know there's there's idea of what a process break is so remember your address. They look like this. You have the tech stack, may you have the data plus BSS you have the heap segment. 223 00:30:20.070 --> 00:30:30.810 William Cheng: And then you have the slack slack. We had about them over here. The he grow this way, the staff grow this way. So, so the heap actually has a current end right here. The end of the heap is known as the process break 224 00:30:32.160 --> 00:30:38.940 William Cheng: Okay, so why is that, well you Poker Stars. You are, you are allocated a certain amount of heap. So if your program called Malik, and he 225 00:30:39.360 --> 00:30:45.330 William Cheng: Inside the initialization code. What it will do is that it was set up a process break and that will be the end of your heat 226 00:30:45.900 --> 00:30:54.690 William Cheng: Okay, so there are system called called cold call. I think the they are a system called copy RK in the BPM racism call you can actually change the process break 227 00:30:55.110 --> 00:31:02.040 William Cheng: By lowering it or, or, you know, or or raising it guys. So in that case, you have to implement the duplexes call. Yeah. 228 00:31:02.730 --> 00:31:12.510 William Cheng: Anyways, so that's what later and also in the vino Darcy over here towards the end over here. There's a bunch of stuff that's called if that VM. So now you're in the EMEA implement that. 229 00:31:12.990 --> 00:31:23.310 William Cheng: Again, these are very similar to a special, special power right there call special for me map. Right. So there are some file that has the in that system calls. So therefore you're allowed to actually map that into outer space. 230 00:31:23.760 --> 00:31:39.150 William Cheng: There are also some Colombo special about feel page 30 page and clean page again these are very, very similar to the anonymous object shadow object Phil paid 30 page. You'll clean page over here. So I think you have you, you're supposed to implement them. 231 00:31:40.200 --> 00:31:45.360 William Cheng: Okay. There are also inside your kernel their function called V Phil page. 232 00:31:45.810 --> 00:31:54.420 William Cheng: The dirty page and deep clean page. Those are the one they're implemented already for you. They're actually part of your kernel to code and we never looked at them. 233 00:31:54.630 --> 00:32:03.570 William Cheng: Because you know they're useless in Colonel to remember we're doing Colonel three, you should read these function over here. Again, they're called V feel page V dirty page be clean. Clean page. 234 00:32:04.140 --> 00:32:13.920 William Cheng: So do a graph is that your current source go and look at what they're doing now over here, you have to do something very, very similar, right, except with a special file. All you need to do is find the pointer and call them directly. 235 00:32:14.400 --> 00:32:22.710 William Cheng: But then when you try to go, you know, implement the shadow Phil page shadow dirty patient have a clean page again look at those functions and see what it does. And then you need to do something similar. 236 00:32:23.640 --> 00:32:28.770 William Cheng: Guys, again, forget about shadow, you know, object at this point. So next lecture, I'll talk about shut off. Yeah. 237 00:32:31.110 --> 00:32:37.680 William Cheng: All right, in order for you to get forking way to go to the work. All you have to do is implement for you don't have to worry about em map and 238 00:32:38.070 --> 00:32:48.060 William Cheng: A map. Okay, you need to worry about Emma and our map. If you want to go to the next phase. Okay, so the next phase is to run the user space shell. 239 00:32:48.720 --> 00:32:59.190 William Cheng: Okay, so in kind of wanting to have Keisha Keisha is the kernel space show in you know in the in the user space there is a user space show. And that's a real, you know, kind of like Linux shop. 240 00:33:00.450 --> 00:33:07.470 William Cheng: Okay, so then in that case we, you know, our enterprise things that occurred on needs to go into the user space and not become the user space show 241 00:33:07.710 --> 00:33:15.390 William Cheng: And the in the beginning of getting our the user space to work. You've got to get all these functions to work. Okay, the map. The map and 242 00:33:15.870 --> 00:33:18.450 William Cheng: I don't. Not sure if you have to run to break over here. But again, 243 00:33:18.960 --> 00:33:26.820 William Cheng: You know, once you switch to run the user space for you to run into other bugs and then you got to debug the bag the bag and then you find out that oh your implementation of do a map and do a map. 244 00:33:27.150 --> 00:33:33.630 William Cheng: Map I incorrect. So again, look at the colonel three cold look for look for these days. If you want to get ahead and get ahead of everybody else. 245 00:33:33.960 --> 00:33:40.500 William Cheng: To see what kind of air that they're going to encounter. So therefore you can we should write this code you anticipate that error. Maybe you'll do a little better. 246 00:33:40.950 --> 00:33:48.780 William Cheng: Yeah. So again, you know, do we expect to to to to run into more Colonel crashes. As you start trying to get more and more user space we're going to run 247 00:33:51.300 --> 00:33:58.740 William Cheng: Oh, okay. I should over here's how you exactly what it is. So the user space show or the way that you started out as to run a spin it. 248 00:33:59.190 --> 00:34:07.590 William Cheng: Spin. And then over here, and then is a user space worldwide. So the idea here is that once you finish the forecast way program. Was it good for can wait, wait, wait. 249 00:34:08.520 --> 00:34:14.790 William Cheng: Wait around what you have to do is, I know that the kernel space in a program that is going to go into the user space. 250 00:34:14.970 --> 00:34:21.540 William Cheng: And he will become the user space in a program which kind of makes sense, right, because the you know the the you know the goal for your eventual Colonel through 251 00:34:21.750 --> 00:34:29.550 William Cheng: The destiny for your kernel in a process is to go into the user space and become the user space in in process, right, so remember what's the purpose of us being 252 00:34:29.970 --> 00:34:41.460 William Cheng: In a process is to wait for all the user space program to die when all the users are going to die. What it will do. They will also sell you. It will also self terminate when the user space in the process of determining 253 00:34:42.780 --> 00:34:47.910 William Cheng: What the kernel space and and provide also died right because they're the same thing, right, there's no user space program. There's no 254 00:34:48.630 --> 00:34:55.560 William Cheng: There's only one process, you know, either in the user space or is that a kernel. So when your user space in the program is that your kernel in 255 00:34:56.130 --> 00:35:03.090 William Cheng: Your kernel space and it provides also that when your cursor in your process dies while I bet right you wake up the idol process either process, turn off the machine. 256 00:35:04.770 --> 00:35:12.120 William Cheng: Alright, so again, your users as well as it turns out what the users fit in their process. What it will do is that it will create the user login shell. 257 00:35:12.660 --> 00:35:22.230 William Cheng: Okay, the user logs out again. Looks like the colonel show. I think the problem is a little different. It doesn't take a shower anymore. It has some kind of a user's shall prosper and now you can type Linux commands. 258 00:35:23.640 --> 00:35:29.640 William Cheng: Okay, so therefore get the user space shuttle program has written for you already. So all you have to do is run it. Right. So by by running has been in it. 259 00:35:29.760 --> 00:35:41.760 William Cheng: What it will do that. It will for cough child processes in the child processes, they will make a exact system call any exhibitionism called they will run the user space show and the user space. I was known as slash biz last sh. 260 00:35:42.150 --> 00:36:02.820 William Cheng: That the SH O stands for shout. Right. I guess you're logging show on Linux is either take a shower or TC show what this is the oldest UNIX shell is called sh. Okay. So, therefore, you know, inside. Are you know we you know we just go we run the oldest UNIX shell, which is quite as age now. 261 00:36:04.470 --> 00:36:08.640 William Cheng: Alright, so, so, so what else is here. 262 00:36:10.200 --> 00:36:16.710 William Cheng: Alright so strategy over here, you know, so, so go go go go go through the step, you must implement the patient management. 263 00:36:16.950 --> 00:36:23.190 William Cheng: You know co first. Right. So here, you said as far F is equal to one ke VI n equal to zero in conflict, I am 264 00:36:23.520 --> 00:36:31.440 William Cheng: Okay, even though this is Colonel three right so somebody was like Colonel three I need to save me go to one. No, don't do that guy because if you do that, you're gonna be in big trouble. Okay. 265 00:36:31.830 --> 00:36:38.190 William Cheng: Very difficult to get the word so ke VI n equal to zero set f5 as a reward implement all these three functions. 266 00:36:38.700 --> 00:36:46.110 William Cheng: Okay, and then you read around BFS test, right. So now again you do make clean you to remake again and now VM. So we have esters will run 267 00:36:46.380 --> 00:36:51.570 William Cheng: You know with this isn't boss. Is that right, I don't, I don't know if you actually walk through that co in Colonel to 268 00:36:51.990 --> 00:37:04.320 William Cheng: Is that Colonel to at some point they're going to mount the ramp houses them right if you read a co very carefully. It was said he would do that. If you know FSA equal to zero if F is equal to one it will mount this is above our system is that 269 00:37:05.340 --> 00:37:10.200 William Cheng: OK, so again it says. The Bible says, and there's no way for you to debug the code. You just have to trust that it's perfect. 270 00:37:10.620 --> 00:37:13.830 William Cheng: The code come from Brown University, they're implementing a binary only code. 271 00:37:14.310 --> 00:37:26.220 William Cheng: Okay. So, therefore, you know, you have, you know, use the swag bugs. Is that says. The Bible says them. I mean, some people say, oh, he crashed into pieces about was, as well as that, therefore it has to be a bug is that Brian diversity call know 272 00:37:26.550 --> 00:37:35.460 William Cheng: The bug is yours. Okay. You did something that caused you know the colonel to crash inside the system by system call and now it's going to be a little harder to debug. 273 00:37:35.820 --> 00:37:43.200 William Cheng: Right. So again, what do you need to do is that you need to imagine that the system, our system CO is just like the RAM file system called except there's a disconnect 274 00:37:44.130 --> 00:37:49.710 William Cheng: Guys, so definitely if you crash and this isn't about Marxism co most likely because it's because of rescue reference counting problem. 275 00:37:50.100 --> 00:37:53.130 William Cheng: Okay, your kernel fall asleep, and when he wakes up, everything's messed up. 276 00:37:53.880 --> 00:37:58.920 William Cheng: Okay, because when you fall asleep. Some of the reference count over here is messed up. And now you switch to another country. 277 00:37:59.340 --> 00:38:09.960 William Cheng: Another cut off their detriment the reference kind of goes to zero if we have the data structure. Well, you know, threat for your cursor wakes up later you assume that the data center is still good. Well, bad assumption because it's been freed up already. 278 00:38:10.680 --> 00:38:15.360 William Cheng: Okay, so that's one of the most common bug. You know what, what will you say if I have as an equal to one. 279 00:38:16.290 --> 00:38:25.830 William Cheng: OK. So again, you know, and people are sort of asking that question in the class Google go, how am I supposed to implement reference count. Should I incremental incremental there, that's the wrong question. 280 00:38:27.420 --> 00:38:40.230 William Cheng: That's the wrong question. Okay. So remember reference count is counting the number of pointers. You need to know where these pointers are. That's the purpose of Colonel to is to know where these pointers are right when you go to Colonel three you assume that they're the same places. 281 00:38:42.150 --> 00:38:50.010 William Cheng: Alright, so you got to know how do you go to, again, again going to learn how to debug reference counting by we can go to Colonel three at the beginning of year again going to encounter some more reference counting bug. 282 00:38:50.490 --> 00:38:54.840 William Cheng: You got to be able to figure out, you know what these bugs are and then move forward. Yeah. 283 00:38:56.520 --> 00:39:05.370 William Cheng: All right, well, you're in Colonel three don't bother with a favor. FS tests over here because favor FS tense was was designed just to run Colonel to 284 00:39:06.060 --> 00:39:11.160 William Cheng: Well guys, so therefore don't waste your time and getting a favor. FS tests around with Colonel three. Yeah. 285 00:39:11.880 --> 00:39:24.960 William Cheng: Alright, so you should get this done by the end of week 12 right then we talk next week. Right. So again, basically, you know, the idea here is that as soon as you finish one or two you should spend the next two days to get these three functions, who are 286 00:39:26.040 --> 00:39:28.200 William Cheng: Okay, then you're going to be in pretty good shape. 287 00:39:29.790 --> 00:39:30.120 William Cheng: Okay. 288 00:39:32.370 --> 00:39:38.820 William Cheng: All right, so, so if your code. If you can get, you know, the FS has to be almost working 289 00:39:39.180 --> 00:39:43.860 William Cheng: Except for one or two bugs and if you if you're if you're implemented if you implement this in a team. 290 00:39:44.160 --> 00:39:58.350 William Cheng: What I will recommend is that you know if only by the end of week 12 you only have one or two bugs over here you are, you pass mazel your BFS task which you should do so you split up your team. One person stay behind to debug that bug. Okay. The other people move forward. 291 00:39:59.730 --> 00:40:06.060 William Cheng: Okay. I mean, if you're doing it by yourself, well then you all the luck, then in that case you have to you know to to to to to get to get all these bugs fixed 292 00:40:07.260 --> 00:40:07.590 William Cheng: Okay. 293 00:40:10.230 --> 00:40:17.400 William Cheng: All right, in the first week of kernel three rather will be week 13 you should get the first user space program to run its hello 294 00:40:18.480 --> 00:40:29.490 William Cheng: Okay, so I'm not kidding. Okay, to get hello to work, you need to spend one week just to get hello to work right. Hello, you look at the code three lines open open right and then die. 295 00:40:30.540 --> 00:40:37.980 William Cheng: Okay, so these are very, very difficult to implement right because you need to you know so. So in this case, what happened right so so so inside you're in a program that you're in it. 296 00:40:38.490 --> 00:40:41.820 William Cheng: You know in your process, you need to run the hello program. 297 00:40:42.420 --> 00:40:55.140 William Cheng: Guys all saw how do you do that. Right, so, so, so is it an improper on your inside a colonel. So what you need to do is that you need to call a function called colonel. Exactly. So this is the exact system call, but it's the kernel version of it. 298 00:40:56.130 --> 00:41:07.020 William Cheng: Okay. So inside corner you can actually apply directly about corner by calling, Colonel. Exactly. So you're going to set the argument over here to say run this user space program and the users restaurant over here will be user being hello 299 00:41:07.470 --> 00:41:11.460 William Cheng: Okay, I can't remember what exactly what the function Artemis was a little guy. But the idea over here is that 300 00:41:11.640 --> 00:41:18.030 William Cheng: Your kernel you're currently in the process is going to call Colonel exactly that same thing at the exact system call 301 00:41:18.150 --> 00:41:22.500 William Cheng: You're going to wipe out the address space. Well, at this point, there's no address space. It has nothing to wipe out right 302 00:41:22.620 --> 00:41:31.230 William Cheng: And then what you do that you invoke the loader to know the hello program into memory by you know that we do on the main page. And so we don't really load any of the data into memory. 303 00:41:31.410 --> 00:41:39.720 William Cheng: What we do is to build the outer space. And then we're going to go into the user's Facebook where and when we go into the user space for what we do on the web pages. So the first thing that will happen is the page fall 304 00:41:40.680 --> 00:41:51.390 William Cheng: Okay, so we're going to come back into the kernel right away. And we're going to fix the paintball going back into the space program and now it will start running your programs. Okay, the first line of code that you execute is going to be in the startup function. 305 00:41:52.020 --> 00:41:57.960 William Cheng: Okay, so the sort of function is going to start running over here. Get a paintball you fixed baseball go back into the user space, and pretty soon. 306 00:41:58.140 --> 00:42:08.970 William Cheng: You know the Shara function will call me when he called me is going to write you going to push data onto the stack. So again, at that point going to get the second page trolley coming out of Colonel, you have to fix the picture over here and then you go back into the kernel. 307 00:42:09.390 --> 00:42:19.350 William Cheng: Maybe you'll get a patient right away because over here. We're doing copy on write you're doing something that is that A star right so again I described, all of that in detail in the previous lecture. 308 00:42:20.430 --> 00:42:28.650 William Cheng: Okay, so all those things. Things hasn't happened. And eventually what you do is that you will make system called when you make system call, you know, at the end of the system called they will set up. 309 00:42:30.240 --> 00:42:37.800 William Cheng: So one thing that you will, that they will encounter is that when you start making system call okay inside every system called they will come out of Colonel twice. 310 00:42:38.910 --> 00:42:44.190 William Cheng: Okay, the first time is that they will come into the kernel to execute the system Hall and then once you finish this isn't 311 00:42:44.430 --> 00:42:53.760 William Cheng: I mean, you did. I encourage you to write when you finish the system called if there's an error. What do you do what you said something called the air number this era numbers inside the Colonel. How do you return the air and I'm going to the user space program. 312 00:42:55.050 --> 00:42:59.040 William Cheng: While you need to make another system called comes out of kernel and grab that from the user, you know, from 313 00:42:59.580 --> 00:43:05.550 William Cheng: From the Colonel. Okay. So, therefore, every system call you're going to come inside of Colonel twice. Right. So for example, if you make the open system call 314 00:43:05.730 --> 00:43:13.050 William Cheng: You're going to come inside the Colonel, open the file is it turns out it was failure, you're going to come. He's at a quarter of the second time to get the to get the error number 315 00:43:14.700 --> 00:43:22.560 William Cheng: Okay, so therefore again he they're all these co pays all you have to handle and all these you know systems are you have to handle, you know, to get to work now. So again, the researchers 316 00:43:22.770 --> 00:43:29.640 William Cheng: The Colonel's in a process become the user space. Hello process, right, because right now. You know, I'm not running s been in it. I'm running. 317 00:43:29.880 --> 00:43:37.650 William Cheng: Running the hello program. So now when I go into the user space where where the user space program is going to have process ID number one, which is the entire process. 318 00:43:37.860 --> 00:43:44.430 William Cheng: But now the address space that it will bill is the hello address base. So therefore, the hello program is the user space in a program 319 00:43:45.210 --> 00:43:56.550 William Cheng: Okay, so what it will do is there will open file descriptor zero by the scooter one right hello to follow the script or one and then it will return for the main program. What do we do about them a program called exit you come into the current all 320 00:43:56.880 --> 00:44:04.800 William Cheng: Its to exit right you actually over here. He's gonna kill you know kill process. Number one, and they are you going to wake up process number zero and process number zero was shut down the machine. 321 00:44:06.180 --> 00:44:12.000 William Cheng: Alright, so that will be the life cycle for the hello program. There's over here. You have to be able to load the program to memory. 322 00:44:12.150 --> 00:44:21.060 William Cheng: You have to be able to build and manipulate the address basis by implement all that VMware function over here you have the be able to handle pays for us because you know when you start running a program or you're going to have a page for all 323 00:44:21.270 --> 00:44:29.070 William Cheng: You have to have some system called the work right open system called racism, called the work that's a lot of stuff to get working just to run. Hello. 324 00:44:29.910 --> 00:44:35.100 William Cheng: Okay, so, so if you read the winnings documentation. The release documentation is crazy. 325 00:44:36.060 --> 00:44:43.290 William Cheng: The winners document. He says, you know, just run as being in it. It's impossible to do that, don't go that route. I cast strongly and, you know, 326 00:44:43.620 --> 00:44:56.850 William Cheng: Recommend you not to listen to the winnings documentation, because I've been teaching this programming assemble for management here is okay so so the these these these are the steps that I recommend. And why do I recommend them because I think this will make your life easier. 327 00:44:58.020 --> 00:45:11.280 William Cheng: Okay. Some people don't believe me, they have their team members divvy up all the work, tried to get a spin in it to work. That's hopeless. Don't do that. That anyways, that's my organization. I can't force you to do whatever anyways. 328 00:45:12.390 --> 00:45:16.470 William Cheng: Okay, so it will be good to get this done by the end of week one kernel three 329 00:45:18.120 --> 00:45:27.270 William Cheng: Okay, so by the end of week, plus you get the P frame stuff to work and then you spend the entire week to get hello to work okay because Hello. Is that difficult to get it to work. 330 00:45:28.740 --> 00:45:29.130 William Cheng: All right. 331 00:45:30.780 --> 00:45:31.470 William Cheng: Now, Kitty. 332 00:45:33.420 --> 00:45:40.890 William Cheng: Alright. So in the second week of kernel three that's week number 14 of the semester. Right. You need to get all the user space whole writing section be of the grading guidelines to run 333 00:45:41.310 --> 00:45:51.150 William Cheng: Okay. So, okay, you do it exactly the same way guy from your kernel and then process over here. So what you will do is it will change it and then a proper on and then in this case you will run a different program. 334 00:45:52.110 --> 00:46:00.600 William Cheng: Okay, so some of the programs are like LS, you know, it gives you a visual LS, some of them are like echo or something like a memory. There's echoes of like that. 335 00:46:01.080 --> 00:46:08.490 William Cheng: There's a bunch of program again read the grading gotten over here. Again, Colonel through beta gamma is very different for other Colonel assignment because now you're running user space program. 336 00:46:08.790 --> 00:46:18.300 William Cheng: Yeah, so it's actually be over here at the basic idea side the kernel space in a process going to user space program just to run one program when that program called exit. You're in a process that 337 00:46:18.780 --> 00:46:28.410 William Cheng: Okay. So, therefore, you know, the idol possible got woken up and you shut off the machine. Yeah, so you're running one program at a time. So again, this is my recommendation of what you know how you should proceed. 338 00:46:29.040 --> 00:46:35.880 William Cheng: Alright, the last one over here is broken way, whereas in this case you need to get for to work is again the previous slide will show you what kind of function, you have to implement 339 00:46:36.420 --> 00:46:43.830 William Cheng: So forth. It's very difficult to work to do to get it to work. Yeah, so hopefully by the end of the weekend over here, guys. Okay. 340 00:46:44.100 --> 00:46:54.240 William Cheng: During the second week, you're going to get the first few programs to run. They are not as bad as getting hello to work right because hello. You have a lot of car hopefully all those code will work with all the other user space program. 341 00:46:55.320 --> 00:47:08.670 William Cheng: Okay, so the first thing you should be easy. And then forget where should take you a little more work. So around, you know, Friday of the second week, hopefully, you should get forgotten way to work and then by the end of the second week, you should get a spin in Toronto. 342 00:47:09.870 --> 00:47:16.680 William Cheng: There's again. It's been in it. What it will do is that this is the real colonel in the real user space in April web 343 00:47:16.920 --> 00:47:29.100 William Cheng: What it will do is is that it will fall called which are process, it will call the user space in that process and it will run your user space shop right then users may shot over here is a slash been such as ah 344 00:47:29.850 --> 00:47:39.660 William Cheng: OK, so, so, so I think if you create a three, you know, a terminal devices. What it will do is that it will actually run a user's threshold in every one of the terminals 345 00:47:40.290 --> 00:47:47.040 William Cheng: Okay. So, so far, you only see one terminal. Right. That's why you run Keisha as it turns out, there are two other ones that are hidden from you. Right. So again, 346 00:47:48.510 --> 00:47:59.250 William Cheng: I think I think they're there. Anyway, it's not it's not important in Korean three, you know, depends on how many terminals. You have you have three of them. What it will do is that it will actually create three users show each one of them running each of these 347 00:48:01.650 --> 00:48:14.160 William Cheng: These terminals that and then you can actually interact with the user. You can type ls. You can take, you know, make sure you can hide all the, all those Unix, Linux command every used to okay because over here, you're running a real user space shop. Yeah. 348 00:48:15.930 --> 00:48:16.320 William Cheng: Alright. 349 00:48:17.490 --> 00:48:24.690 William Cheng: Guys, again, the colonel colonel enterprise over here, become user space in a process over here and they will create the user level show and you know as, oh yeah. 350 00:48:25.200 --> 00:48:35.640 William Cheng: It will be good to get this done by the end of the weekend of the second week of Colonel three. Okay. So then you have one more week left the last week over here you passed all the tests. 351 00:48:37.110 --> 00:48:44.520 William Cheng: OK. So again, we really get a good thing and I will be here a gradient dissection be over here. Tell you what are the basic, you know, the simple users may point you have to run 352 00:48:44.760 --> 00:48:56.040 William Cheng: And then in Section see of the grading guidelines. He says, run the user space shall type all these commandments, or they work section D of the grading Allah says you need to get all the other five heavy duty user space program to work. 353 00:48:56.580 --> 00:49:02.520 William Cheng: OK, so the heavy duty users will include BFS test again. So now we have that says is that your user space program. 354 00:49:03.450 --> 00:49:15.390 William Cheng: Okay, so that's why we have so it looks so weird, right, because this is really tricky program. It runs in Colonel team runs and Colonel three inside the colonel with FFS equal to one and the VM go to zero. It also working be n equals one. 355 00:49:16.560 --> 00:49:24.600 William Cheng: Okay, so you to get that program run. There's also a function called mentors is going to test the heck out of, you know, your memory. So again, that's a very difficult test the past 356 00:49:25.050 --> 00:49:33.330 William Cheng: There also a program called fork bomb inside the fourth bomb and, you know, a program over here. I think they will for a few hundred time a few thousand times. 357 00:49:33.930 --> 00:49:40.290 William Cheng: So your current was gonna go crazy. There's also another one. Okay, DFS as men that test. There's another function. 358 00:49:40.770 --> 00:49:49.650 William Cheng: Pork or eat, man. I try to eat up he tried to call me up and tried to make sure that you end up implementation is correct and it will, you know, either memory or something like that, whatever that means. 359 00:49:50.130 --> 00:49:55.050 William Cheng: They're also the last one. The cause stress test inside, stretch, stretch that they run all the other stuff together. 360 00:49:56.340 --> 00:50:09.360 William Cheng: Okay, so, so, so the last week over here. There's actually a lot, you know, get more code that you have to to to to run to get it to work. Yeah. By the way, I should mention one more thing when you spin and then this will be the first time that you called Malik. 361 00:50:10.890 --> 00:50:18.780 William Cheng: Then everything before that for can weigh all the original program. They don't come a lot bigger. So, therefore, you don't have to dictate the process break stuff to work. 362 00:50:19.260 --> 00:50:29.520 William Cheng: The memory mapping doesn't really have to work perfect. You don't have to implement the end map system call once you you know Carmela then in that case, they will call you know do a map. 363 00:50:30.240 --> 00:50:36.660 William Cheng: Okay, so in that case, again, you're going to run through some bugs you had to fix those bugs. I do em map and then eventually, you can actually pass this test. 364 00:50:37.080 --> 00:50:42.270 William Cheng: Guys. Okay, look at the colonel through FAQ and try to look for all these things that I mentioned over here. 365 00:50:42.660 --> 00:50:49.950 William Cheng: So, okay, it's a really good idea when you start Colonel three to scan through the colonel three FAQ, even though they are pretty much meaningless at the beginning. It doesn't make any sense. 366 00:50:50.130 --> 00:50:58.980 William Cheng: As well. Get a scan through. So you can say, oh, I saw this and that. So later on we get stuck. You know, you can you remember what you need to search and try to you know to look for the the colonel three FAQ 367 00:51:02.760 --> 00:51:11.970 William Cheng: Alright, the last part over here is briefly go over, you know, these pre frame function over here. So people and get over here. So again in people in da see 368 00:51:12.270 --> 00:51:18.180 William Cheng: You know, first part of your kernel of importance we function P frame get p frame pen and paper and pen. 369 00:51:18.690 --> 00:51:25.050 William Cheng: paper and pen and unpaid. Again, it's very, very straightforward. You are just playing hide and seek with the with the with the page on demand. 370 00:51:25.440 --> 00:51:30.510 William Cheng: So read the code over here it tells you how to hide it. And then, you know, we hear it will tell you how 371 00:51:30.960 --> 00:51:40.440 William Cheng: How to on Hyder. So again, the way you hide it is that you remove this page frame from the place where the page argument and find the space frame and then you append that to another list. 372 00:51:41.220 --> 00:51:50.430 William Cheng: Okay, so that's all the way on high days that you go to that less and then you unlinked that from your phone or less, and then you add it to the data structure that the page or demon will scan. 373 00:51:51.030 --> 00:52:03.480 William Cheng: Guys so so again that the others. Yeah. So again, these are the paper and the the pin function, the people and get over on function, it's a little complicated. Okay, so why but is up. 374 00:52:04.560 --> 00:52:06.300 William Cheng: Every page frame has a name. 375 00:52:06.810 --> 00:52:13.890 William Cheng: Okay, the name of the Patreon page frame is which memory management object belongs to which is the first argument over here. Yeah. 376 00:52:14.100 --> 00:52:22.200 William Cheng: And the second one over here. It's going to be a page now. So I've been is that you know I mentioned before, you know, we have a memory segment over here unless it the memory segment of yours or 10 kilobytes law. 377 00:52:22.560 --> 00:52:29.790 William Cheng: Okay, the way we're going to implement that we're going to implement this four kilobytes at a time. So therefore, the way we implemented or 10 kilobytes memory segment. 378 00:52:30.000 --> 00:52:36.750 William Cheng: Is to use three pages, right. The first one over here is going to cover the force first four kilobyte the second page or a movie or a couple of the second 379 00:52:37.230 --> 00:52:42.600 William Cheng: four kilobytes. The last one over here is going to cover two k here over to Kate here, but there's no way for us. 380 00:52:42.930 --> 00:52:55.710 William Cheng: For us allocate only four kilobytes of memory without a four kilobytes at a time. Right. So therefore, the last one over here. The first two gigabytes will be useful. The last two kilobytes over here, you know, they are internal fragmentation. 381 00:52:56.790 --> 00:53:04.260 William Cheng: Okay, so therefore, when you sort of, you know, using the buddy system, you know, you can't, you know, there's no way for you to get around with internal fragmentation. So, therefore, if you want to 10 382 00:53:04.530 --> 00:53:10.800 William Cheng: You know 10 kilowatts memory segment. You have to allocate your three page right over here. And the last one over here will have internal fragmentation. 383 00:53:11.490 --> 00:53:17.190 William Cheng: OK, so the way that we're going to name these page frame is that, you know, this patient over here, implement this. 384 00:53:17.940 --> 00:53:21.630 William Cheng: Memory segment that memory segment has a memory management object. 385 00:53:22.260 --> 00:53:26.580 William Cheng: Related to memory on manga objects that we saw before, is that, you know, we saw like a fall off jag is kind of 386 00:53:26.940 --> 00:53:37.320 William Cheng: Like a memory and then image object. So remember we have a linguist VM area over here. Each one of them will point to something right I draw, you know, the picture over here. There's a diamond that are shared by the tech segment data segment. 387 00:53:37.620 --> 00:53:45.960 William Cheng: And also, if it's a memory map memory sanguine over here, again, the point to a file object and then there are these things that point to anonymous object over here for the heap segment. 388 00:53:46.140 --> 00:53:52.230 William Cheng: And also for the sock sock, man. They are anonymous object. So all these objects over here. They are called M. M. O. B gay 389 00:53:52.980 --> 00:54:02.700 William Cheng: Okay. So inside your kernel to I don't think you have noticed that you actually have to, you know, inside your Mino dog or something at the end and mobile job jack. So inside the vino there's a memo VJ 390 00:54:03.780 --> 00:54:12.180 William Cheng: Okay, and also anonymous object, the memory, memory, the object over here. So these are the one that managed the pace frame for these memories segments. 391 00:54:13.500 --> 00:54:24.390 William Cheng: Because remember, every page, you know, every memory segment is made on a page frames the page frame are managed by the memory management object. Right. That's why they're called memory management object because they manage page frames. 392 00:54:25.530 --> 00:54:34.470 William Cheng: Okay. So, therefore, if you have a memory segments, as I said, this one is the one has 10 kilobytes law. Okay, so we hear the memory management object over here. What will be the one that manages three three page way. 393 00:54:34.770 --> 00:54:44.490 William Cheng: The way that you name these pre paste RAM is that this co pays for a number zero patient number one picture. Number two, so page number over here will be equal to 01 or two. 394 00:54:45.240 --> 00:54:48.780 William Cheng: Guys, remember the in chapter seven, when I talked about the page number over here. I mentioned 395 00:54:49.530 --> 00:54:56.910 William Cheng: We're comments there that you know the colonel pace. I'm over here. They are not a virtual patient number, they're not a physical page number but it's an array index. 396 00:54:57.570 --> 00:55:08.340 William Cheng: Okay, so this is a really nice over here says that to implement this memory segment we're going to use three paceman. So the way we sort of think about them. These three pages. I like array index or a index number zero re max number one or 397 00:55:08.730 --> 00:55:12.870 William Cheng: Number two. So in order for you to net to uniquely identify identify 398 00:55:13.350 --> 00:55:27.780 William Cheng: In order for you to uniquely identify paste rate you're going to name which memory. Memory managed magical belongs to. And also, which are reading that you're supposed to use now. So by using the MO BJ and the page number right here you uniquely name a PageRank. 399 00:55:29.040 --> 00:55:39.090 William Cheng: Okay, so this function will create the patient for you. If the patient has not been created already if it turns out this patient already exists. All you have to do is to find it and you return it. 400 00:55:39.510 --> 00:55:48.810 William Cheng: Again, so he returned it again. The third argument over here. It's a return value right we saw before, you know, vino star star over here. It's a return value of year. So this one is P frame. 401 00:55:49.020 --> 00:56:03.630 William Cheng: You know, star, star. So, when this function. Find that P frame with this name he will, you know, it will return in this argument, okay, if it turns out that you know this piece that's patient doesn't exist. This function will create a page rain again return the third argument over here. 402 00:56:05.310 --> 00:56:07.380 William Cheng: There's again if you read the code in the gap. 403 00:56:08.070 --> 00:56:19.050 William Cheng: By. That's why we get this right, we get over here will try to find the vino if you find a dino your return to be know if you can find them, you know, your it will create a vino set the reference, how to go to one and then return the return of, you know, 404 00:56:19.980 --> 00:56:25.080 William Cheng: OK, so again every time when you see a good function. That's what it does, right, we try to find out if you can't find it will create it. 405 00:56:27.000 --> 00:56:37.740 William Cheng: Alright, so that's all I want to say about the introduction to Colonel three. So next Monday's lecture is very important because I'm going to give you everything that you need to know in order for you to finish curl three 406 00:56:38.070 --> 00:56:43.290 William Cheng: OK, so now you're supposed to do still being Colonel to so by next Tuesday's you'll finish Colonel to and then again. 407 00:56:43.680 --> 00:56:55.980 William Cheng: By that time, I'll finish. You're giving you all the material for Colonel three and then you know you should come back and review this discussion is actually anything you don't, you didn't understand the first time you watch it and now you should be able to do it. Okay.