WEBVTT 1 00:00:02.399 --> 00:00:12.900 William Cheng: Okay, welcome to this is like, this is the last discussion section because we don't have a discussion section on week 15 because the Colonel's Iman is due 2 00:00:13.679 --> 00:00:24.120 William Cheng: So there's really nothing left to talk about. So this will be the last one. And I'm just going to, sort of, you know, walk over some of the sort of miscellaneous code. 3 00:00:25.560 --> 00:00:29.370 William Cheng: And I guess, you know, I'm not going to look at every test. 4 00:00:30.390 --> 00:00:37.020 William Cheng: So, what you should do is that if you have questions about these, you should, you know, send email to me. Okay, so I think on the class. 5 00:00:37.800 --> 00:00:46.830 William Cheng: Website on the discussions web page. It's listed that week number four we're going to talk about, you know, things like forking wait right because you know 6 00:00:47.700 --> 00:00:54.000 William Cheng: We started out with the whole program. And then we get, you know, all the simple, you know, simple programs to work. 7 00:00:54.360 --> 00:01:10.200 William Cheng: And then finally we get to forget. Wait, so this is, you know, more complicated because you need to get the shadow object to work and also for because a little sort of convoluted. So I'm going to sort of briefly talk about, you know, a couple of. So the important 8 00:01:11.370 --> 00:01:21.300 William Cheng: things to watch out for. I can't wait. And then I guess the do for this stuff is also there are some of the items over here are the 9 00:01:21.810 --> 00:01:32.130 William Cheng: The Colonel three FAQ items. So again I briefly talked about it you know recently in the class Google group discussion. Some people, you know, 10 00:01:32.490 --> 00:01:50.400 William Cheng: Talk about some of the stuff I ended up adding new kernel three FAQ items because you know some of the question needs to be addressed. So, you know, I've been, you know, keep changing the colonel FAQ ever since 2012 so you just keep growing and growing. 11 00:01:51.540 --> 00:01:54.030 William Cheng: I don't know if you know if you ever stop but 12 00:01:54.480 --> 00:02:03.480 William Cheng: You know, anything that's sort of worthy to talk about. I will try to add it into our current FAQ right so so without the colonel FAQ. The Colonel assignment will be very difficult to do. 13 00:02:03.870 --> 00:02:10.350 William Cheng: Especially with Colonel three right because just the the winnings documentation and the spec is really, it's really not enough. 14 00:02:11.010 --> 00:02:14.580 William Cheng: Yeah, I'm gonna sort of briefly look at the code for user space shell. 15 00:02:15.120 --> 00:02:23.190 William Cheng: So, so one of the reason I'm going through all of these code over here is that you know by now you should be very familiar with the with the user space code. 16 00:02:23.820 --> 00:02:34.590 William Cheng: So if there's any issues, you should be able to, you know, debug the code in the user space in any of the user space program and try to sort of predict what's going to happen. 17 00:02:35.220 --> 00:02:43.320 William Cheng: Okay, because that's sort of the, the main thing about debugging, right, is that you know you you need to predict what's going to happen. And then you see if it happens or not. 18 00:02:43.560 --> 00:02:49.620 William Cheng: And if it doesn't happen. You need to find out you know whether your assumption is wrong or your code is bad, right. Hopefully it's not both. 19 00:02:50.460 --> 00:02:59.550 William Cheng: You know, so, so, so it's very, very important to be able to to to to to make, you know, educated guess to see what is supposed to happen right once in a while you know we made mistakes. 20 00:03:00.090 --> 00:03:08.550 William Cheng: But hopefully, you know, using everything you have learned, you know, throughout the semester, you should be able to guess well know what what's supposed to happen. Yeah. 21 00:03:09.300 --> 00:03:15.210 William Cheng: Right and and sometimes you know what's supposed to happen is it turns out it didn't happen but something else happened. 22 00:03:15.930 --> 00:03:25.890 William Cheng: You know some of the bugs are very tricky. You know, so, so, you know, because we're doing kernel code. So you shouldn't be expecting every bug to be easy to fix. 23 00:03:26.850 --> 00:03:39.420 William Cheng: All right, so, so, so let's take a look at the fork in, you know, a fork and way code, right, because this is the first time you have to get forth to work. And unfortunately, you have to get forced to work together with a copy on write. Okay. 24 00:03:40.290 --> 00:03:45.750 William Cheng: So, so let's take a look at this code over here user been for can wait. I see. 25 00:03:46.260 --> 00:03:53.220 William Cheng: So, you know, the original fork in Waco is in chapter one right over here, we add a bunch of things to mess around with the data. 26 00:03:53.670 --> 00:03:58.350 William Cheng: So, we define a global variable called data and this is intentionally set as a global variable. 27 00:03:59.070 --> 00:04:04.770 William Cheng: So this way we know that it's going to be in the data segment right the data segment. You know, we mentioned 28 00:04:05.580 --> 00:04:17.460 William Cheng: Before that, in Phoenix, the way the loader works is that originally a map that data segment from the file into the address space, right, and then they switch to a different object. This is switched to 29 00:04:18.240 --> 00:04:35.490 William Cheng: To to to anonymous object so they can do copy on write right because, you know, because we don't really want the data to go back to the disk. So, therefore, you know, so that they sort of remap it you know in inside loader. Okay, so, so, so this this piece of data is inside the 30 00:04:36.750 --> 00:04:48.480 William Cheng: Inside of data segment right so so they're subject to a copyright. Okay. All right. So in the beginning, over here, you open you open your print right and then you write and the right right and then 31 00:04:48.840 --> 00:04:53.040 William Cheng: So, so you should see some you know messages over here, all from the parent right 32 00:04:53.370 --> 00:05:01.500 William Cheng: So in the beginning over here. They actually don't say whether they're from the parent or child. So once you do fork right then. It's important that the parent will create the messages. 33 00:05:01.770 --> 00:05:04.380 William Cheng: For the parent and the child was supposed to print the messages for the child. 34 00:05:04.650 --> 00:05:14.640 William Cheng: Then, so again, read the code to understand what it's supposed to do right up. It was zero. Well, that means that all this code over here should be executed by the child. And that's why all these print up over here says Ciao Ciao Ciao. 35 00:05:15.360 --> 00:05:20.400 William Cheng: Okay, AP ID over here it goes to minus one. Well, for some reason, fork fail, you need to find out why for failed. 36 00:05:20.850 --> 00:05:29.880 William Cheng: It's in this case it was a fork failed. Otherwise, you know, everything over here, you can see that it says Parent, parent Parent, parent, right, because this thing is supposed to be printed up by the path right 37 00:05:30.720 --> 00:05:41.310 William Cheng: Alright, so again the abstraction for for is that you are the parent goes into the kernel right and then both parent colonel and both parent and the child. They were all returned from the 38 00:05:41.610 --> 00:05:49.200 William Cheng: From the kernel. And again, the abstractions that they return simultaneously. So if you have multiple CPU, there'll be able to resolve a Tennessee. 39 00:05:49.860 --> 00:05:55.860 William Cheng: So so so since that's the abstraction. You shouldn't really worry about who returned first who returned second 40 00:05:56.370 --> 00:06:00.270 William Cheng: Okay, so it depends on how you write your code, right. Some people will return from the parent first 41 00:06:00.810 --> 00:06:08.460 William Cheng: Because the parent going to Colonel using a system called right so so when you make the system call, will you return them system call. So therefore, the parents should return first 42 00:06:08.910 --> 00:06:12.240 William Cheng: Okay, what about the child. The child doesn't return from the system call 43 00:06:12.870 --> 00:06:20.430 William Cheng: Right. I mean, is this okay the system call is this, you know, to fork inside the Colonel, the child doesn't return them do for what does, what does the choco 44 00:06:21.060 --> 00:06:31.530 William Cheng: OK. So again, if you read the colonel three FAQ is sort of tells you step by step of how you supposed to implement the child. And then in the end what it, what it says is that you supposed to add the child. 45 00:06:31.950 --> 00:06:41.970 William Cheng: The the the thread inside the child process, you know, added into around you. Right. And you said, the, the, the, the instruction pointer to be user lead entry. 46 00:06:43.350 --> 00:06:52.350 William Cheng: Okay, so what are you supposed to do, is that even though the parent comes out of corn. All right, even though you're you're supposed to return simultaneously but we return us in different ways. 47 00:06:53.040 --> 00:06:58.590 William Cheng: Okay, the parent will return using the using a normal way a system calls returned, so it's okay. What is the normal way right 48 00:06:58.800 --> 00:07:11.040 William Cheng: It just, I will you make the racism call you return from be you make the races and coach them on. Right. So when you make the forces them call you should return from from fork. Okay, but the child process. We're going to make it look as if a return for 49 00:07:12.240 --> 00:07:18.720 William Cheng: Okay, so this is a question that the you know the the colonel through FAQ says that will you supposed to do, is that 50 00:07:19.110 --> 00:07:30.120 William Cheng: You just set up all these register. Right. It tells you how to set up all the register and then you know you set the IP to be user land entry as remember the user land entry is a 51 00:07:31.020 --> 00:07:37.050 William Cheng: The user land entry is a colonel function. Okay. So, therefore, when you set the sort of the, the 52 00:07:37.530 --> 00:07:50.460 William Cheng: Your IP to be usual an entry, you're still executing kernel code, right. So when it go. Go to use an entry. I don't know if you remember why is the land entry look like Colonel API. Exactly right. Exactly. Exact I see 53 00:07:51.570 --> 00:07:58.710 William Cheng: Right, so this is why use Alana Andrew look like right so the child supposed to start executing this this call next time the parent give up the CPU. 54 00:07:59.850 --> 00:08:08.580 William Cheng: Okay, why would the parent give up CPU, right, the parents give up the CPU because you know as soon as the parent return over here. What do you would do is that it will need to. So parents can execute this code, right. 55 00:08:09.390 --> 00:08:22.020 William Cheng: Okay, so this coat. When I tried to print to a device when when they try to you know make the racism call these kind of stuff, since we're in Colonel three, there are these real devices. So therefore, in this case the Colonel said we have to go to sleep. Wherefore interrupt. 56 00:08:23.250 --> 00:08:25.260 William Cheng: Okay, so that's why the parent will give up CPU. 57 00:08:26.430 --> 00:08:29.790 William Cheng: Okay, so, so therefore, again, you have your parent return first 58 00:08:30.090 --> 00:08:39.180 William Cheng: At some point, the parent will give up the CPU, because the parents are executing this call. At that point, the child to actually be woken up right because you're supposed to, you know, add the child through to the rescue. 59 00:08:39.600 --> 00:08:50.700 William Cheng: The shelter doesn't get to run until the parents were given the CPU. So the problem when the parents that you know make all these function call it will give them the CPU and now the child throughout will go to execute code in user land entry. 60 00:08:51.540 --> 00:09:04.590 William Cheng: Okay, it's okay. We'll go to this cut over here. And what is this called to write this code return to the user space. OK. So again, the way that you set up all these return i'd registered over here is that some of the return register is going to remember where to go back to 61 00:09:06.060 --> 00:09:08.190 William Cheng: What would it go back to in the user space. 62 00:09:09.300 --> 00:09:11.640 William Cheng: Okay, so, so get the idea of a system called is that 63 00:09:11.910 --> 00:09:21.960 William Cheng: You know you started in the user space, right, you make a system called you save the contacts you come inside the kernel. And when you return back into the uterus. May you need to restore the contacts. Okay, so how do you restore contacts, but 64 00:09:22.200 --> 00:09:27.240 William Cheng: This is where you restore contacts. Right. You put the register, we hear all the register, you know, for the CPU. 65 00:09:27.870 --> 00:09:38.160 William Cheng: So the idea here is that when the child returned back into the user space issue return in exactly the same values you know the the contact should be exactly the same as the parent 66 00:09:39.510 --> 00:09:47.310 William Cheng: Okay, well why is that, well, because that's the abstraction of foreground when you make a fork system call the child gets an exact copy of the 67 00:09:47.550 --> 00:09:58.050 William Cheng: That the parents address space. So as far as the parent child church are concerned, they're doing exactly the same thing. They're all in the middle of the forest system call so therefore they should return exactly the same way. 68 00:09:59.280 --> 00:10:09.450 William Cheng: Okay, so, so even though inside the Colonel. The Colonel knows better at the you can really feel the Colonel. The Colonel will see that the parents going to return back the normal way. 69 00:10:09.810 --> 00:10:18.360 William Cheng: You know, returning returning from the system call the child is going to go through these convoluted way right by going through user land entry and then as soon as they enter into the user space. 70 00:10:18.630 --> 00:10:23.190 William Cheng: Right before entry into the user space that stage should be exactly the same as the parents day 71 00:10:23.400 --> 00:10:34.590 William Cheng: The only difference is that, you know, in the contacts that are supposed to restore x will be equal to 0404 for the Chopra says yes will be equal to whatever the child's process ideas for the parent 72 00:10:37.080 --> 00:10:48.450 William Cheng: Okay, so you know where you can also you can also think about it is that as soon as I go back into the user space if I print all the CPU registers okay for the parent and for the char, they should that be exactly the same value. 73 00:10:49.740 --> 00:10:57.240 William Cheng: Okay, so that's how you should debug the code, right. So let's say that you for somebody that you're working with is that doing that the correct things right. So once a week and do over here is that 74 00:10:57.840 --> 00:11:02.130 William Cheng: So I'm going to run this command. LOOK AT THE FORECAST based system callers over here. I'm going to use object dump. 75 00:11:02.640 --> 00:11:15.210 William Cheng: Okay. So run this code over here and then you don't have the output go to x ray, so x over here. This is for can wait. Right. So I'm going to look for the trap machine shop chain. Right. So, so there's an inline function called trap. 76 00:11:15.810 --> 00:11:19.770 William Cheng: Guess if i look forward, you know, less than trap where then Colin. 77 00:11:20.040 --> 00:11:28.800 William Cheng: I'm going to see this one right. This is the one I'm looking for over here and then again inside this folder inside this function over here is going to is going to drop into the kernel twice. Right. 78 00:11:29.070 --> 00:11:42.330 William Cheng: The here is in directs to eat rice. I'm going to put a note over here. Okay, so this is going to be, you know, first time right first trap. Right. Okay. And then right here. Here is the second track. 79 00:11:43.650 --> 00:11:58.680 William Cheng: Okay. So, and this guy's again is going to tap into the kernel twice. So what I will suggest you to do is that when you know so so so when but with a parent is going to call in zero x two economies that kernel and both the parent and a child is going to execute the next instruction right 80 00:11:59.880 --> 00:12:07.380 William Cheng: Okay, because both of them will return to exactly the same, same place, what is this what is exactly the same place. It's a next machine instruction after in zero x to eat. 81 00:12:08.010 --> 00:12:15.570 William Cheng: Okay, so therefore you should set a breakpoint right here is what again look at your object. Damn it will tell you what the addresses and people are getting different addresses and that's perfectly okay 82 00:12:15.900 --> 00:12:20.580 William Cheng: There's nothing wrong with it. Okay, even though I can't explain why. But that doesn't really mean that there's anything wrong with that. 83 00:12:20.820 --> 00:12:28.710 William Cheng: You can actually get different addresses okay alright so so set a breakpoint. It will be here right so so I can say, you know, break star followed by this zero x one of the addresses. 84 00:12:29.010 --> 00:12:35.460 William Cheng: So in this case, when they return right here as soon as they return right here, what I should do is as you print out the parents registers. 85 00:12:36.420 --> 00:12:39.450 William Cheng: Okay, so if you know that the parent if he returns over here, everything will work. 86 00:12:39.780 --> 00:12:47.340 William Cheng: Properly, so therefore I will actually right here. I will say info registers, right, because that's the GDP command for look all this up register. 87 00:12:47.580 --> 00:12:56.520 William Cheng: I will take a snapshot of that put it aside and then when the child return the Chelsea returning to exactly the same instructions over here. So when I return. I need to look at the at the register. 88 00:12:56.700 --> 00:13:01.950 William Cheng: They better be exactly the same, right, because if they're not the same. Then the child is not a copy of the parent 89 00:13:03.510 --> 00:13:09.450 William Cheng: OK. So again, the only thing that can be different. Is it yes register right for the child. Yeah. Exposure should be equal to zero because that's how you 90 00:13:09.900 --> 00:13:18.990 William Cheng: How you get the return code by the return code is stored in the extra user for the parent. Yeah, x is going to contain you know whatever the number is three or four or five while you know it depends on how you run it. 91 00:13:19.800 --> 00:13:25.350 William Cheng: Okay, so they will get a different you know different value. Okay, so that's how you how 92 00:13:25.860 --> 00:13:31.530 William Cheng: You can actually verify that the chow actually was doing the right thing that it can return to the right place, with all the right register value. 93 00:13:31.950 --> 00:13:38.940 William Cheng: Okay. Because, because what if the child get get get the right here and the register value or wrong, then you're wasting your time. 94 00:13:39.360 --> 00:13:48.600 William Cheng: Okay, don't continue to volunteer because because everything doesn't make sense anymore. Right, right, because the child supposed to be a copy of the parent right so if it's not then then then then then then don't expect it to work. 95 00:13:49.830 --> 00:13:55.530 William Cheng: Okay. OK. So again, you need to sort of figure out a way how to verify what you have is correct, right. So, so again, this is the way to do it. 96 00:13:55.800 --> 00:14:03.810 William Cheng: So again, the second trouble we get, what is the second trap doing right. The second type is to get the air number. Okay, so in case the return value over here is 97 00:14:04.710 --> 00:14:10.800 William Cheng: Is less than zero rattling in that case the air number will be meaningful. So again, the second, the second system called here. 98 00:14:11.070 --> 00:14:17.670 William Cheng: That's going to get the number right so so now. So at this point, you know, if you get to the second travel we hear the parent and a child should get. They're both 99 00:14:18.360 --> 00:14:25.590 William Cheng: Okay, the parent and a child, we should we should go back to the same place where they should return to fork. Fork is just a, you know, we can actually look at the source code. 100 00:14:26.310 --> 00:14:39.570 William Cheng: For right, whereas it user LIP LIP see Cisco see right okay so fork is right here. Right. You can see the fork is very, very simple, just called trap. 101 00:14:40.320 --> 00:14:47.790 William Cheng: Okay, and it will return whatever the return value to be the return value of fork. Right. So, therefore, what it will do is that it will return back to 102 00:14:48.930 --> 00:14:49.380 William Cheng: Was it 103 00:14:50.430 --> 00:14:50.880 William Cheng: Okay, it's gonna 104 00:14:52.050 --> 00:14:59.550 William Cheng: It's gonna return from here. Alright, so another issue that you have to deal with over here is that, you know, the recommendation. 105 00:15:00.030 --> 00:15:11.400 William Cheng: You know, for implementing fork is that both, I think both the parent child parent, the child process supposed to a map the entire user, the map the entire user space page table. 106 00:15:12.060 --> 00:15:21.090 William Cheng: Okay. Is it again. What does the user space page table right the page table again our abstractions that the page table has 1 million entry. Okay, the user portion is the first three quarter. 107 00:15:21.810 --> 00:15:28.560 William Cheng: Is the first three quarter million of those entries and the Colonel entries or the bottom one quarter of the the the 1 million, geez. 108 00:15:29.430 --> 00:15:35.820 William Cheng: Okay, so we're supposed to do, is you she should call. And I guess the functional PT a map rather supposed to a map the entire user space process. 109 00:15:36.030 --> 00:15:42.420 William Cheng: So as soon as you return over here, right. So, so as soon as you return from the first trip over here. What is this supposed to happen in the next instruction. 110 00:15:44.580 --> 00:15:52.980 William Cheng: Okay. As soon as you return, since we are mapped the entire page table. That means that you know in the user space program for every page. They're going to be equal to zero. 111 00:15:54.000 --> 00:15:58.590 William Cheng: Okay, so therefore, at this point you're going back to on demand agent again for both the parent and child. 112 00:16:00.150 --> 00:16:07.860 William Cheng: Okay. And so, so, so, so this makes the boundary, a little messy, right, because you are right here, you expect that you want to do the next thing here right away. So again, 113 00:16:08.040 --> 00:16:16.920 William Cheng: First to info register, take a copy of it right so save as a leader and can come to that with a child and now you should know that the next instruction that you actually go over here, you're going to get a pay phone 114 00:16:17.700 --> 00:16:26.730 William Cheng: Right. So when you get a page. Well, you know, if you'll get a page right at you know for a 4048. So again, that's the the tech segment with page not equal to zero. 115 00:16:27.060 --> 00:16:32.670 William Cheng: Okay. So in this case, you don't have to go to the disk anymore. You should be able to find it because all we did is, to a map the pace table. 116 00:16:33.390 --> 00:16:44.700 William Cheng: Okay, again, a lecture I mentioned that the page table is a temporary data structure, you can wipe it out at any time and it's perfectly fine because because as soon as you do something, you're gonna you're gonna you're gonna 117 00:16:45.180 --> 00:16:52.650 William Cheng: You know, chopping to the Colonel. The Colonel will fix it, right, because using the colonel data structure, you can set up the in the other page table. Anyway, that 118 00:16:53.610 --> 00:17:00.150 William Cheng: Anywhere you want. OK. So again, the data structure. He's not a kernel is important. The page table entry. They're all temporary 119 00:17:00.360 --> 00:17:13.080 William Cheng: Right. So as soon as you start doing this over here, you know, this case, you're going to get a baseball bat. So what is this instruction right this instructor says move. Yes. So when you execute on instruction, you're going to get a pace fall inside the tech segment. 120 00:17:13.710 --> 00:17:27.780 William Cheng: Then, and then it says movie as a BP minus four is what is the VP might as well, right, so remember EDP supposed to point into the stock space. A Vp minus four. So, so you should get another pitfall inside the stack. He said stacks admin. 121 00:17:28.950 --> 00:17:37.320 William Cheng: Okay. So, okay, you shouldn't be surprised. Over here you you're getting to pays for for this one instruction right because the first one is equal to zero. And the second one is that 122 00:17:37.710 --> 00:17:44.160 William Cheng: You know, the second one is also be able to zero, right, because inside the stack space over here you know you you know 123 00:17:45.030 --> 00:17:58.200 William Cheng: The validity of equal to zero. So, therefore, gave an attractive girl. Right. Okay. So over here, there's two trips over here. And as it turns out, that depends on how you fix it, right, because this one you're doing copy on write, remember, at this point we have reset for copy on write 124 00:17:59.370 --> 00:18:10.950 William Cheng: OK. So again, it's very, very important when you implement for correctly. Remember for need to work together with copyright. So, therefore, you know what you're about to return from for you got to make sure that you 125 00:18:11.820 --> 00:18:23.970 William Cheng: You know you you receive a copy on write. So then what's reset for copyright right so so so the the idea of years on every page table entry in the user space should be set to read only. But we didn't even better. We said everything equal to zero. 126 00:18:24.660 --> 00:18:29.100 William Cheng: Okay, so next time when you get a pace file. You need to be able to set it back to to to to read only. Right. 127 00:18:29.340 --> 00:18:41.070 William Cheng: And if it turns out you're performing right operation like like this case where movie so EDP man is for your writing into memory. So again, you can do this using to paste are using one page follow the rule. It depends on your style. 128 00:18:41.970 --> 00:18:49.980 William Cheng: Okay. But what's important. Over here is that this, this is copy on write. Okay. So, therefore, make sure you don't write to the, sorry. 129 00:18:50.520 --> 00:18:58.200 William Cheng: I'm jumping ahead. Yeah. Alright. So. So in order for you to reset copywriter two things you have to do it. First you have to, you know, zero out of the pace table entry right make them either read only. 130 00:18:58.470 --> 00:19:08.550 William Cheng: Again, that's too difficult to do. So therefore, we just, you know, a zero, the entire user space map the entire user status page table. Okay. And then we also need to add an empty shadow object. 131 00:19:09.810 --> 00:19:12.060 William Cheng: Right. Remember, that's how we receive a copyright right 132 00:19:12.330 --> 00:19:24.330 William Cheng: You know, the first you do is what you need to do with a patient when she said everything to read only. And also you need to, you know, add a shadow object for both the parent and the child in that link list of shadow object that point, all the way to the bottom object. 133 00:19:25.080 --> 00:19:32.700 William Cheng: Okay, so make sure you do that because otherwise not going to work. Yeah. All right. And over here, over here, right, so, so, so what will you write data into the stack. 134 00:19:33.270 --> 00:19:41.790 William Cheng: You have to perform copy on write. And then in this case, you know, you're going to allocate a new page frame and the one that's managing the pace room is going to be the new shadow object in the parent 135 00:19:43.470 --> 00:19:48.210 William Cheng: Okay, and then later on when the child come here, do the same thing again. What's going to happen to the child. 136 00:19:48.420 --> 00:19:59.550 William Cheng: Exactly the same thing that I happen to the child, you're going to get one page fall for the text document one page fall for the stack segment right and then in the industry. Exactly. You got to remember to copy on write 137 00:20:01.200 --> 00:20:13.800 William Cheng: Okay, otherwise you're going to end up white otherwise over here. Right. Yeah. So here's the return value should be zero or the child process ID. And then if you if you right to the wrong place. Now, both in the parent and the child is going to end up, you know, seeing the same number. 138 00:20:14.940 --> 00:20:22.770 William Cheng: Alright, so, so that's not what you want. Right. You, you, you want both of them to see different return value over here. So again, you got to make sure that you're doing copy. Oh, yeah. 139 00:20:23.640 --> 00:20:30.060 William Cheng: All right, and then immediately what they do over here is that they will make the next system call to get the DRM right 140 00:20:31.410 --> 00:20:41.040 William Cheng: Okay, so, and let me go look at or so. So I guess that's one thing I wanted to say if we go back to 141 00:20:42.270 --> 00:20:42.930 William Cheng: The 142 00:20:43.950 --> 00:20:52.290 William Cheng: You know, the, the colonel through FAQ right there's something called to fork over here. So again, there's a long explanation of what you have to do over here. Okay, so, so 143 00:20:52.710 --> 00:21:06.540 William Cheng: I think this information was copy from the Brown University website because they're running the same you know the other the same assignment. My understanding is that this instructions over here works. 144 00:21:08.070 --> 00:21:14.790 William Cheng: Okay. Some people try to do their own it's really not recommended because because to get the fork to work. You got to follow the steps. 145 00:21:15.480 --> 00:21:23.730 William Cheng: Okay, so, so, so I strongly recommend you just follow the steps over here, you should be OK. OK, so I was told, if you just follow this then everything will work. 146 00:21:24.150 --> 00:21:34.650 William Cheng: Okay, maybe you misunderstood something right because some of these steps, not so easy to understand. Okay, so he's possibly misunderstood something but but what I was told that if you follow these steps it will work. Okay. 147 00:21:35.550 --> 00:21:42.810 William Cheng: All right, I see see people asking questions over here. I mean, over here, it says CERP set it to us or lemon tree, you should do that. 148 00:21:43.710 --> 00:21:53.550 William Cheng: Okay. Because, because the child supposed to go to usual energies child and in return the same way the parent is right because its parent made a system call and it returns the Chinese to go in a slightly different route. 149 00:21:54.780 --> 00:21:59.640 William Cheng: Okay, so, so remember the the child shouldn't execute the code into fork. Right. 150 00:22:00.750 --> 00:22:05.130 William Cheng: Okay do fork is done by the parent, the child. The child just want to return. 151 00:22:06.900 --> 00:22:13.290 William Cheng: Okay, so therefore keep that in mind. Right. So, so don't don't try to make the child goes to the do for code. Okay, so that's really not want me to go. Yeah. 152 00:22:15.150 --> 00:22:23.760 William Cheng: All right, and so anyways. You know, I guess, follow the recommendation of a year. They also something else with the do fork. 153 00:22:28.290 --> 00:22:32.760 William Cheng: Or so. So let's look for, you know, fork in our Colonel three FAQ 154 00:22:35.400 --> 00:22:37.230 William Cheng: Because there's a lot of stuff about forking here. 155 00:22:45.720 --> 00:22:54.060 William Cheng: Okay, so I'll be here here's, here's one of the common bug over here in fork and way. How come my child process returned from way P ID and not from fork. 156 00:22:54.810 --> 00:23:01.440 William Cheng: Okay, so, so how does that, right, the parents executing code if the parent doesn't you know give up the CPU, eventually they will call wait 157 00:23:02.430 --> 00:23:04.980 William Cheng: Okay, so, sooner or later, the panel will have to give up the CPU. 158 00:23:05.700 --> 00:23:13.380 William Cheng: Okay, so, uh, you know, I guess I mentioned that, you know, so again, everybody system might be a little different. Right. The parent, though, you know, the, the, the user space code that we saw. 159 00:23:13.650 --> 00:23:18.420 William Cheng: The parent, you know, returned home for a check the P IDP. It is not equal to zero, you actually the parents. 160 00:23:18.780 --> 00:23:25.860 William Cheng: The parents going to print something is going to print something to a buffer that make the racism call but eventually the power has to wait for the charger that 161 00:23:26.610 --> 00:23:34.560 William Cheng: Okay, so, so it is possible when you try to print something you don't give up CPU. Some people will, they will give us a view. So it doesn't really matter. Okay, so 162 00:23:35.220 --> 00:23:44.880 William Cheng: As long as all the parents how they execute the right code and it doesn't really matter. Right. But we know for sure that sooner or later the parent has to give up the CPU, because the CO says the parents to call wait 163 00:23:45.750 --> 00:23:54.480 William Cheng: Okay, so when they call away. They have no choice but to give up the CPU rise over here is this important, well, how come my child process returned from way P idea knife and fork or as 164 00:23:55.650 --> 00:24:09.390 William Cheng: The child. The child process and wouldn't return is supposed to return from Fort. So how come he returned from way PhD. Okay, so that doesn't make sense, right, so here again you read through this. So again, the basic problem over here. Again, I need to go back to, you know, to the 165 00:24:10.560 --> 00:24:12.120 William Cheng: To the source code over here again. 166 00:24:14.610 --> 00:24:28.950 William Cheng: OK, so again inside this trap code over here. Okay. Will you return over here again, at this point we are reset for copy on. Right. So at the beginning. Over here at the bottom of the stack over here. They are shared between the parent and the child right but we're doing copy on write 167 00:24:30.060 --> 00:24:36.780 William Cheng: Okay. So, therefore, if you have. Well, they don't do copy on write what happened is that the parents going to write to the stack over here. And if you don't have 168 00:24:37.050 --> 00:24:45.990 William Cheng: The copy on write in that case the parents going to run into the stack that's shared by the child. So therefore, when the child return over here inside the stag will be or what what's inside is that 169 00:24:46.680 --> 00:24:59.550 William Cheng: right inside the stack over here. So return address. Right. Okay. So if the child if the parent process modifying the stag, that the child also accidentally pick up well. Then the child is going to return, where the parent or the or the parent fallacy. 170 00:25:00.780 --> 00:25:07.590 William Cheng: OK. So again, the day the simple explanation over here is that, you know, if it turns out the cherry tend to the wrong place. It 171 00:25:07.860 --> 00:25:14.370 William Cheng: Again, the wrong place, meaning that it returned from the first trouble we hear perfectly right. And then over here in the end. 172 00:25:14.700 --> 00:25:24.930 William Cheng: In the end of this travel we hear whatever return over here in return to the same place as the parent fell asleep, then you know that is because you are using the wrong stack. 173 00:25:26.340 --> 00:25:38.100 William Cheng: OK. So again, the status. They are the stacks is is made of these, the amendment of these pages, right, the page over here inside the page we store those five things inside of stack rank right the return address the local variable, all that kind of stuff. 174 00:25:38.550 --> 00:25:43.350 William Cheng: Okay, so at the bottom of the stack over here right below the start for us over here you store the return address. 175 00:25:43.860 --> 00:25:48.570 William Cheng: Okay. So, therefore, if the child, pick up the parents stack, whether the child will return to where the parent pop Darcy. 176 00:25:49.470 --> 00:25:59.910 William Cheng: Guys, okay. Again, that's another thing to watch out for. So if I haven't, you should know what you have to do is to, you know, debug the copy on write immediately after the first track. Yeah. 177 00:26:00.780 --> 00:26:09.780 William Cheng: Alright, so that's that's so there's what else is here. That's for can wear it over here. So again, you know, the parent, the parent called printer. 178 00:26:10.230 --> 00:26:17.460 William Cheng: The parent call right so this one is right to the device, you know, I don't know whether you have to the parent has to give out the CPU or not. 179 00:26:18.360 --> 00:26:23.790 William Cheng: Okay. I mean, were you right to the device you're supposed to wait for the interrupt so so again. Right. Yeah. You know, so 180 00:26:24.690 --> 00:26:30.600 William Cheng: Some people see that the parent eventually will fall asleep when it Causeway PhD, right, because the parent wait for the child today. 181 00:26:30.930 --> 00:26:35.460 William Cheng: Now, so maybe you have that implementation where you don't go, you don't you don't fall asleep until we get there. 182 00:26:36.150 --> 00:26:47.520 William Cheng: Okay. And also it's possible that when the parent, you know, stuff only see you wake up the child. This child will return over here and then I will go. Go to sleep and then apparently wake up in the shower wake up and then go back and forth, back and forth. That's also a possibility. 183 00:26:48.540 --> 00:27:00.510 William Cheng: Okay, I don't know exactly what the right sequence is it doesn't really matter what rest. He goes to all the sequences are correct. Okay. As long as you execute only the, you know, only these code. Okay. If you go somewhere else. Well, then you need to find out why. 184 00:27:01.740 --> 00:27:10.770 William Cheng: Okay. All right. So that's working. Wait, so the next thing that we're going to look at is the user space shout, right, the user space. So again, user 185 00:27:11.340 --> 00:27:17.190 William Cheng: s been right as been in it that see right so that's not the user space that's user space in a program 186 00:27:17.940 --> 00:27:27.120 William Cheng: So some people was asking what this program does over here, right. So if you look at the code over here it's reading the directory entry one entry at a time. How do you knows really well enjoy your time right 187 00:27:27.330 --> 00:27:36.510 William Cheng: Over here says address of D, which is the directory entry. So we hear size of the directory entry so so so basically it makes the system calls, they give me one directory entry. 188 00:27:37.170 --> 00:27:47.850 William Cheng: Okay. So over here, what it's doing over here is to go through that directory in slash they're returning one entry at a time and try to see that entry. Start with TTY as well. Here's the street and compare 189 00:27:48.480 --> 00:27:59.730 William Cheng: The entry over here, then the component name compare with TTY string right TTY string is just TTY right so depend on how many TDI device you have you have TTY zero TT white one to two 190 00:27:59.970 --> 00:28:08.700 William Cheng: Then it will call this function three times. If you only have one device, then it will call this function once. Okay, so it doesn't really matter whether you have one or two or three two or three TTY devices over here. 191 00:28:09.270 --> 00:28:12.960 William Cheng: The slingshot over here. What it does is that it for a child process. 192 00:28:13.920 --> 00:28:20.010 William Cheng: Yeah, the parent will try to form up more child so the child process over here will close zero closed one and close to 193 00:28:20.250 --> 00:28:29.940 William Cheng: Your clothes all the terminology and then what it will do is that it will open TTY right. So in this case, I guess, open TTY is open this TTY right here. So, what it will do is it will open a device. 194 00:28:30.930 --> 00:28:37.800 William Cheng: How many times does it call open. He's gonna call open one, two, and then it's called dupe once right so here's how you can see this is what will actually happen right 195 00:28:38.040 --> 00:28:45.750 William Cheng: So since 012 they're all closed so when you call open the first time you should get zero right when you call it the second time over here is you should get one. 196 00:28:45.990 --> 00:28:51.120 William Cheng: And the third time over here where you call do what, then, in this case, I'm going to pick up a new file descriptor and the new file. 197 00:28:51.510 --> 00:28:57.840 William Cheng: Has speech, SB two. Okay, so this is how we nice share the the the file descriptor one into 198 00:28:58.230 --> 00:29:05.100 William Cheng: That because both of them is going to point to TTY and then this case we open up all right on the right. So, therefore, that standard out standard error. 199 00:29:05.580 --> 00:29:14.760 William Cheng: Okay, so this is why when you try to run your user space program. They all have fathers gripper 01 and two, they all been already okay because we're because it's done right here. Yeah. 200 00:29:15.840 --> 00:29:20.700 William Cheng: Alright so what it would do is they would change directory to the home directory. So where's home. 201 00:29:21.480 --> 00:29:33.030 William Cheng: Home directory over here is the root directory right as you see over here. And then what it will do is it does is that it will print high or something like that and then it will call it exactly eat right so exactly is the system call 202 00:29:33.630 --> 00:29:37.890 William Cheng: So, so this is the complicated system called. This will be the first time you will run into 203 00:29:39.270 --> 00:29:45.960 William Cheng: I think this is the first time you'll run into Malik. Okay. Alright, so let's take a look at exactly the year as a week out exactly over here. 204 00:29:46.830 --> 00:29:56.400 William Cheng: For the child process, it should not return right if every time you got to see this longer printer to say exactly you fail. Yeah. So again, exactly, is one of the family of exact system call 205 00:29:57.000 --> 00:30:02.040 William Cheng: So, you, you know, make a copy of the address space and, you know, then the load a new program. Right. 206 00:30:02.490 --> 00:30:18.270 William Cheng: The program over here is the shell program right the shell program is as big as sh. Right. So let's take a look at exactly user lip, lip. See, it's a system called I so exact v over here, right. This is the cook. 207 00:30:20.880 --> 00:30:29.430 William Cheng: Okay, so we're here. Right. Yeah. So this is the first time because Malik. Right. So again, major trouble time. So this is why when you go to spend an hour, you're going to get into trouble. 208 00:30:30.060 --> 00:30:36.450 William Cheng: So we had is called exactly right. So, it sets up for the other tribe over here, but it doesn't invoke the track right away. 209 00:30:37.140 --> 00:30:49.890 William Cheng: Okay, so this is actually a more complicated. You know system call. Over here, over here is going to go through all the RV over here set all the RV up. So again, try to set up the parameter before going inside the Colonel, but what it does. Over here is that Carmela 210 00:30:50.940 --> 00:31:00.150 William Cheng: Yeah. So where's Malik Malik is also here we are user lip, lip. See, I guess there's a Malik here is there is a Malagasy over here. 211 00:31:00.600 --> 00:31:08.940 William Cheng: Okay, you look at this file, this file is 1100 lines long. OK. So now you know in trouble. Okay, so, so if we look at Malik. 212 00:31:09.810 --> 00:31:23.610 William Cheng: Over here and Malik is a function as it turns out, there's a lot of Malik. There's, I am Allah, there is Malik Annette, and there's Malik this Malaga. Here's Malik. Right. And then what else do we have we have 213 00:31:27.000 --> 00:31:30.120 William Cheng: Okay, so where's Malika nick, nick 214 00:31:34.560 --> 00:31:43.440 William Cheng: Okay, there's Malik nigga. Okay, so I was looking for the wrong pattern. Okay, right. So, so there's a lot of Maliki here. Okay, so, so let's go to Malik first 215 00:31:46.140 --> 00:31:46.440 Okay. 216 00:31:47.670 --> 00:31:49.500 William Cheng: Where is it okay so here's Malik right 217 00:31:53.430 --> 00:31:58.500 William Cheng: Okay, so what it does is that it. Look at this variable called Malik started 218 00:32:00.720 --> 00:32:05.940 William Cheng: Okay, what is Malik started right so Malik started over here. It's a global variable. 219 00:32:06.960 --> 00:32:16.020 William Cheng: Okay, so this is a global variable over here, this is on initialize global variable. Okay, so for four weeks. Okay, this is not universally true i for you for four weeks. 220 00:32:16.290 --> 00:32:22.770 William Cheng: Since the way you're supposed to implement your anonymous object is that whenever you create a new page frame, you need to zero it out. 221 00:32:23.940 --> 00:32:31.290 William Cheng: Okay. So, therefore, if this one is you know if the data segment. I mean, this one is unusual is variable. So, so therefore he lives inside PSS 222 00:32:31.770 --> 00:32:36.390 William Cheng: So, since they are managed by anonymous idea, why are they are not managed by anonymous object. 223 00:32:36.780 --> 00:32:41.490 William Cheng: Right, we mentioned before, right, instead of loader. In the beginning, they were mapping to address space. So there were managed 224 00:32:41.700 --> 00:32:52.350 William Cheng: By the MO BJ that instead of vino but as soon as I finished doing that every maps it and maps it into to do to be handled by an anonymous object, right, because they they need to be set up for copy on write 225 00:32:52.680 --> 00:33:01.530 William Cheng: Okay. When that happens, the anonymous object is going to create a page full of zeros. So that's why all these initials lies variable. They should all become zero. 226 00:33:02.670 --> 00:33:09.060 William Cheng: There's again. This only works with Linux on worth was ways I think Linux also work the same way. 227 00:33:09.570 --> 00:33:17.280 William Cheng: Okay, if we have an initial as global variable and they all become initialized zero. Okay, what about I initialize local variable. 228 00:33:17.730 --> 00:33:22.920 William Cheng: What the uninitiated local variable that can become become garbage rabbit so you know when when you make a function call. 229 00:33:23.100 --> 00:33:30.270 William Cheng: You know, you're going to put stuff into the stack frame and next time when you return and you call the function again. Well, now you're going to pick on whatever garbage does. So that means that. Exactly. Okay. 230 00:33:30.480 --> 00:33:38.910 William Cheng: I mean, of course, the stack the stack segment is implement by the Anonymous. Anonymous object as well. So therefore, the first time you use the stat. Well, you should see zero 231 00:33:39.750 --> 00:33:45.540 William Cheng: Okay, but next time when you call the same function. Well then, then, then in that case that the the stack is going to be a total mess. Okay. Alright, so, so, yeah. 232 00:33:46.020 --> 00:33:51.270 William Cheng: Okay, this one should be zero. The Malik active over here should be equal to zero. So Malaga should be able to false. 233 00:33:52.020 --> 00:33:58.470 William Cheng: Okay, so that's how they play this game to make sure that you implement the anonymous object correctly otherwise going to get bad numbers over here. 234 00:33:59.190 --> 00:34:03.270 William Cheng: So this one over here is initialized. Right. So you go to say 16 years. Okay. 235 00:34:03.540 --> 00:34:14.220 William Cheng: The way that it was done. It's kind of funny right they first map in front of this into memory and then they make a copy of it and then they go to the initial question over here. And then you're supposed to set all to zero. Okay. 236 00:34:14.970 --> 00:34:25.410 William Cheng: So I think he's had a loader. What it will do is that they will ask anonymous object over here to first create the page frame and then he will copy things from the the memory segment that was allocated in the 237 00:34:26.580 --> 00:34:33.600 William Cheng: The memory seven that was allocated in the file and then what it will do is it will copy them over. Okay, so I guess I don't remember exactly what it's done. 238 00:34:34.110 --> 00:34:39.420 William Cheng: But, but what you need to make sure is that, you know, these global variable up here. They're all we said it correctly. 239 00:34:40.170 --> 00:34:51.990 William Cheng: Okay, so what you should do is you set a breakpoint. A Malik right we saw the demand function there. You set a breakpoint in Malik, it has been. It doesn't work. The first thing is just suspect is that Malik is not working properly. Okay so set a breakpoint email. 240 00:34:52.350 --> 00:34:56.010 William Cheng: As soon as you get into Malik. Alright, so let's go there again Malik. 241 00:34:56.910 --> 00:35:03.480 William Cheng: Okay, well you get here, over here. Look at these variables over here. Malik active better be zero, right. So what you do is that you 242 00:35:03.690 --> 00:35:10.320 William Cheng: Get we will you get a break one right here. Print Malik active, make sure zero if it's, if it's not equal to zero, forget your code. And I'm going to work. 243 00:35:11.220 --> 00:35:20.130 William Cheng: Okay, fix your anonymous object to make sure that you zero out the entire page. Okay. Alright, the next thing that he will do over here is look at Malik started malice started better be zero to be false. 244 00:35:20.670 --> 00:35:30.120 William Cheng: Yeah. Otherwise, again, forget it. One more. So what it will do is that is that if Malik has never been started what he would do is that it will call Malik and. NET and Malika net is what the first time you set up. 245 00:35:30.420 --> 00:35:42.330 William Cheng: You know formula you need to initialize initialize the heat. Right. Okay. So, therefore, you know, you have to, you have to call Malik in it. Okay, so, so let's take a look at my like a net over here. Right. What does it do 246 00:35:43.410 --> 00:35:56.670 William Cheng: OK, so the weird part over here is actually get caught in two different places. One is called reality and the other one is called Malik. OK, so the political Malika yeah alright so here's the trouble write the code in it and map. 247 00:35:59.040 --> 00:36:06.780 William Cheng: Them in a map it costs open and open the device slide deck slides zero. So you need to make sure. So I should have said zero is working. 248 00:36:07.290 --> 00:36:16.860 William Cheng: Right in Colonel to you're supposed to get that to work, right. So if you, you know, the code is flaky over here that it won't work. Right. So again, in this case, what he would do is that I will open slash slash zero 249 00:36:17.340 --> 00:36:22.740 William Cheng: So, so what is the episode zero do rights when you read for me. You're going to get it. You keep going to get it getting zeros. 250 00:36:23.310 --> 00:36:30.570 William Cheng: Okay, so that's why they do this right. So over here, we're gonna we're going to open it open equal to minus one that you print error message. Otherwise, everything is fine, right. 251 00:36:31.050 --> 00:36:43.380 William Cheng: Okay, so over here in EM average right here right and then extra sanity. I have no idea what it is. Go for it. Go to 123, you know, to all these kind of stuff. Nobody knows what they are. 252 00:36:43.800 --> 00:37:01.230 William Cheng: So get if it works. If it works, don't worry about it. Okay. All right. So, so why. But is that a over here. This is a common place where where we're gonna have a bad guy, the cost MF capital M map. Right. So what does couple map is over here again we can look at capital M map over here. 253 00:37:02.430 --> 00:37:08.850 William Cheng: Whereas a capital M up. Alright, so here's a couple of a map right over here. It makes the end map system call 254 00:37:10.140 --> 00:37:11.640 William Cheng: Okay, so, so it makes it so 255 00:37:12.180 --> 00:37:18.000 William Cheng: I guess some people talk about MF system called here. I saw this case, it's makes it read and write and private right so so 256 00:37:18.180 --> 00:37:30.360 William Cheng: Again, you know, forget about read everything is readable right about protection read is equal to zero. Anyway, so, so it doesn't really matter. So this one is a rewrite of memory sideman and it's private. Right. Yeah. What does that mean that means you're doing copy. All right. 257 00:37:31.590 --> 00:37:37.560 William Cheng: Okay, so, so, so over here. They use the map FD right so mad at me map. 258 00:37:38.580 --> 00:37:39.120 Whoops. 259 00:37:40.920 --> 00:37:44.670 William Cheng: Okay, so here's the file descriptor right and map FD. What does a map FD over here. 260 00:37:44.940 --> 00:37:58.080 William Cheng: Why it's called FT zero ft zero over here is like this one. So, initially is equal to zero, right. So where is it gets initialized. Okay, so to get initialize over here, will you call it a map right so you need a map, it will call OPA and then and then he will remember the file descriptor. 261 00:37:59.430 --> 00:38:09.570 William Cheng: Okay so well with the services. So this case, will you will we initialize a map. What it will do is it will open the dual device and use the file descriptor to remember what that was. 262 00:38:10.170 --> 00:38:16.410 William Cheng: Okay. And then what it will do is that it will map that i think i think what it will do is that you actually map this one into the address face. 263 00:38:17.670 --> 00:38:18.210 Whoops. 264 00:38:20.730 --> 00:38:30.600 William Cheng: Okay, so what yeah what happened is over here, it will map this fall into address me. So again, this file is def size zero, so I'll be here. Once you map into address space, everything should be zero. 265 00:38:32.190 --> 00:38:35.640 William Cheng: Okay. All right. So anyway, so here is a map right 266 00:38:39.540 --> 00:38:49.890 William Cheng: Okay, so am I was actually called a few different places. Right. So here we see that it's called one time here. What is this function. This Russia is called extend. Page der 267 00:38:51.060 --> 00:38:51.960 William Cheng: I've no idea what it does. 268 00:38:53.280 --> 00:39:00.090 William Cheng: So hopefully you don't get there. Alright. The second time is right here. So this one is in Mr Malik in it over here. Right, so 269 00:39:00.780 --> 00:39:03.570 William Cheng: So one of the common bugs over here is that we call a map. 270 00:39:04.380 --> 00:39:12.330 William Cheng: Good. What is the return is that you should return a user space virtual address some people didn't really implement a map correctly so am happy end up calling do n map. 271 00:39:12.810 --> 00:39:19.830 William Cheng: So do a map is one of the functions that you have to implement Colonel three right if you implement that incorrectly and you return a kernel space virtual address 272 00:39:20.310 --> 00:39:26.940 William Cheng: So this case you can assign that to page stir. And then what happened is that as soon as you use it. You got to get us a you're going to, you're going to get a baseball 273 00:39:27.330 --> 00:39:30.930 William Cheng: Because you can't use colonel colonel space virtual address a user space. 274 00:39:31.650 --> 00:39:36.390 William Cheng: Okay, so make sure you implement do a map correctly. Make sure the returns a user space virtual address 275 00:39:36.780 --> 00:39:48.000 William Cheng: Because those are. So again, remember the way these functional work is that he actually return the argument in the last argument and not the function return value because the financial return value is just zero or minus one. 276 00:39:48.660 --> 00:39:55.740 William Cheng: Okay, so make sure that the you know the the stuff that it's really trying to return, return to return a user space virtual address 277 00:39:56.010 --> 00:40:04.860 William Cheng: Okay, you started out with a carnal virtual address, you need to do the inverse. Look up to convert that into a user space virtual address and then that's when he could that they should return. Yeah. 278 00:40:06.600 --> 00:40:14.940 William Cheng: Alright, so again, there, you know, then I'm Allah that people have bugs and I'm Allah. So you got a hell of a lot of stuff that the bug you know inside the 279 00:40:15.330 --> 00:40:33.060 William Cheng: Sp internet. Okay. All right, so everything was successful. Okay, well then eventually you end up calling the exact the exact as in Paul you type into the kernel. And now we're going to create a child process, the child process is slash been slash so users slash Ben says sh. 280 00:40:34.380 --> 00:40:40.650 William Cheng: Okay, so this is the user level shout right and that you see that when you type help, you're going to see a bunch of different commands over here. 281 00:40:41.070 --> 00:40:47.550 William Cheng: Okay, so, so now you're running the user level shout over here. So again, the code over here is pretty long right this is even longer than 282 00:40:48.090 --> 00:40:58.140 William Cheng: Malak alright it's 15,000 1500 lines long. OK. So again, you know, you have the source code, right, the source code is a user space, you can actually, you know, debug your source code. 283 00:40:58.440 --> 00:41:07.050 William Cheng: Yeah, some people is asking the class will rule you know my logging show when I whenever I type, you know, nothing happens. What's going on, so we'll go that single, single step and find out what's going on. Yeah. 284 00:41:08.220 --> 00:41:17.490 William Cheng: All right. The other things are there's mem tests. Right. You know, test a lot of you know em map function called there's eat, ma'am. So what is eating them over here. 285 00:41:18.750 --> 00:41:30.090 William Cheng: Okay, so it's kind of a strange function over here user been tests. Eat men see over here. Okay, so this this is this program is only 157 lines long. 286 00:41:30.840 --> 00:41:35.130 William Cheng: Okay. So it's a pretty small program, even though it's very difficult to understand. Right. So again, 287 00:41:35.880 --> 00:41:41.280 William Cheng: You know the theatrics over here is that at the beginning and man over here, what it does. Over here is that it's called em map. 288 00:41:42.150 --> 00:41:48.480 William Cheng: Okay, so get all these tests. If you're a map is flaky, then it's not. It's just not going to work. OK. So again, make sure you pass me 289 00:41:49.230 --> 00:41:52.740 William Cheng: The men test because men test is going to exercise the heck out of me. 290 00:41:53.490 --> 00:42:04.590 William Cheng: And, you know, then the additional work. Yeah. So over here, it called em map and the maps. What you know 10,000 pages, pages into your address face. 291 00:42:05.190 --> 00:42:16.350 William Cheng: Okay. So this guy is going to create a large memory segment that's 10,000 pages long over here. And then what it does. Over here is that it divide these 10,000 pages into into 40 different memory segments. 292 00:42:17.400 --> 00:42:24.960 William Cheng: That. Why does it do that. I have no idea who wrote it. I think the brand new person who shared their privacy people, you know, implemented right so 293 00:42:25.500 --> 00:42:32.790 William Cheng: So, so, so what is, what it does is it takes 10,000 of them and divide into 40 of them each one of them is 25 pages long. 294 00:42:33.300 --> 00:42:39.450 William Cheng: Okay so 25 times 41,000. So in this case, you know, so he didn't map the entire 10,000 page and map. 295 00:42:39.990 --> 00:42:52.260 William Cheng: So, so it stuff on that map and then it started mapping it into smaller segment. Each one of them is a 25 pages long. Okay, so, so, so in this case, you know, each one of them is going to be 25 pages long. So the last one is still, you know, 296 00:42:53.520 --> 00:43:03.060 William Cheng: Over basically 9000 pages, not on I not 9020 to 25 pages long. OK. So again, it's weird that it's doing this or maybe in this case. 297 00:43:04.320 --> 00:43:17.340 William Cheng: It will allocate 1000 of the pages over here. So the last one over here should be 9000 pages long. Right. The left over there. That was initially created. OK. And then, what it does is a call this we're function. Caught. Caught eat. 298 00:43:18.720 --> 00:43:27.420 William Cheng: Okay, so I'll be here. It's not really eating the memory. It just trying to get a bunch of page faults guys over here. What it will try to do that, it will try to get a page for it at every page. 299 00:43:28.320 --> 00:43:43.830 William Cheng: So it's called Ed memory for some reason. And then what it will do is it'll print something out. Okay. Right. Anyways, so, so, so, so, so, so, so watch out for that. Also, there's something called tests fork. Okay, so what is it test fork over here. So anyways, that's some somewhere else. Right. 300 00:43:45.870 --> 00:43:54.270 William Cheng: All right, and then there is awesome. Let me briefly look at men test user been tests men test over here. 301 00:43:55.470 --> 00:43:56.460 William Cheng: Okay, so one of the 302 00:43:57.510 --> 00:44:06.480 William Cheng: The test over here. So the reason that this is pretty weird is that they use these, you know, pound defined over here. They caught a surf failure and a certain no fault. 303 00:44:07.140 --> 00:44:10.410 William Cheng: Okay, so you're going to see that this is all over the place, right. So if I look for. 304 00:44:11.100 --> 00:44:22.140 William Cheng: A Serb photo here you can see that there are self serve for all over the place. Okay. So all these things are so fault. Yeah. So this is pretty tricky because why because if you look at the code for us so far. What does it do 305 00:44:23.730 --> 00:44:27.030 William Cheng: Yeah. What is, what it does is it actually forks. 306 00:44:27.930 --> 00:44:42.060 William Cheng: Okay, it says, test, test, fork began test for. So again, you can graph with those core, the function over here and there in the user include you know fall somewhere. So what it does. Over here is actually for corporate our process and for the child process to execute statement. 307 00:44:43.680 --> 00:44:51.210 William Cheng: Okay, so, so, so, so again we shouldn't debug all this code is going to be very difficult, right, because, because the, you know, the men test is apparent process. 308 00:44:51.540 --> 00:45:03.960 William Cheng: Every one of this test, you will for a call for child process inside the child process, you're going to get a segmentation fault. Okay, so this way, the parents can actually receive a CO and the parent will continue to to be able to run the next test and run an exit next test. 309 00:45:05.010 --> 00:45:12.300 William Cheng: Okay, so unlike VM FS tests are you doing all the tests inside one process. This one is doing Brazilian test inside child processes. 310 00:45:12.930 --> 00:45:17.790 William Cheng: Okay, so. So again, you know, when you see these LB defines over here, you know, 311 00:45:18.630 --> 00:45:27.300 William Cheng: What happened is that you're going to see that it will fork of HR process. So if you set a breakpoint in handle paste off you're going to get a ton of you're going to actually get ton of page faults. 312 00:45:27.660 --> 00:45:30.360 William Cheng: Was again. Why are you getting a ton of baseball because you're doing a fourth 313 00:45:30.870 --> 00:45:35.400 William Cheng: Round when you do a for you create your process, the child processes will pick up from where the forecast. 314 00:45:35.610 --> 00:45:46.710 William Cheng: Is going to get many, many pages file. And eventually he want he wants to access it want to execute this rigorous, a man. Right. So again, what is the statement over here. Okay, so the statement over here will be will be will be a statement like this. 315 00:45:47.760 --> 00:46:02.640 William Cheng: Then he tried to access memory over here. So, so again, over here. What it does is that they get all the addresses over here. And inside the child process, it will eventually access this one, you know, one address and sometime over here it says a circle to assert that this will get a pitfall. 316 00:46:04.230 --> 00:46:11.670 William Cheng: Okay, so therefore, as soon as you try to access the Agile over here. You know, you get a patient and you kill the child processes that again you return back to the fact that apparent again. 317 00:46:12.810 --> 00:46:24.240 William Cheng: Okay, so. So all these things are trying to do is to make sure that you get a page fall and the child would die and the parents is going to make sure that the child died, you know, because you get a segmentation fault, okay so 318 00:46:25.560 --> 00:46:28.260 William Cheng: So let's see over here. What is this 319 00:46:31.410 --> 00:46:35.670 William Cheng: All right, I can't remember how to actually make sure that the child. The child prosecutor segmentation ball. 320 00:46:36.120 --> 00:46:51.960 William Cheng: But I think it's it's doing something like that. Okay, so again, when you get here, you, you need to be reminded that this is actually what's going on. Okay, the last one over here is for bomb right so forth bomb user user band has for bomb. 321 00:46:54.270 --> 00:47:01.200 William Cheng: OK. So again, this fall is only 53 lines long. It's very short. Right. So over here, the only has a main program. Oh no. It has a main function. 322 00:47:01.800 --> 00:47:11.310 William Cheng: The main function over here call fork. Okay. The child will execute this code. Okay, the parent over here, the parent or we're just wait for the child to die. 323 00:47:12.180 --> 00:47:15.030 William Cheng: Okay. It also try to wait for all the child process to to die. 324 00:47:15.540 --> 00:47:23.820 William Cheng: So the chart over here. What it will do is it'll go through an infinite loop and he said a little while here. What it will do is it will actually call forth again right so that's why it's called forth bomb. 325 00:47:24.060 --> 00:47:33.420 William Cheng: The chakras is gonna kick, kick, kick, kick, kick, kick, kick, kick, calling Ford. And then over here, there's a limit over here. So actually we set a limit to be like, you know, 326 00:47:34.320 --> 00:47:44.130 William Cheng: So I guess one of the RV over here is is limit. So if our the last argument over here is limit 5000 so you can run forth bomb from the users. 327 00:47:45.060 --> 00:47:57.540 William Cheng: From the user space from the user space shout, you can say for bomb followed by limit $5,000 limit 500. So in this case, what it will do is that they will for call 500 child processes or 5000 choppers is he, and he was self terminate. 328 00:47:58.710 --> 00:48:08.820 William Cheng: Alright, so the grading guy that doesn't say that. But again, if you look at this code because that oh I can actually use that to control them so that it would die after 500 or 5000 works. Yeah. So in this case, you actually remember what the limit is 329 00:48:09.750 --> 00:48:16.740 William Cheng: So if the limit is not minus one, or whatever. And then the end is greater than limit what it would do it instead of watching this message. And then eventually it will die. 330 00:48:16.980 --> 00:48:27.780 William Cheng: There. Otherwise, what it will do is that it will keep calling for over here and you can actually see that, you know, AP ID equals to fork. So what it will do is is that over, over here is that he will check 331 00:48:29.820 --> 00:48:43.830 William Cheng: You know the SP ID, where the equal to zero or not, right, zero, then it's going to go to false otherwise. This code is actually a by the parent. Okay. So, so what is the parent do over here, right. So you can see that no matter what the parent do what we had the parent always exit. 332 00:48:45.150 --> 00:48:52.350 William Cheng: Okay and and the the the chart over here. The, the, the chart over here the chart over here will continue to execute this code. 333 00:48:52.590 --> 00:49:02.400 William Cheng: Okay, so you can see that this particular co over here is that at the beginning, the parent over here, it's gonna be it's gonna fall of two processes. The original parent will wait for the charger die. 334 00:49:02.940 --> 00:49:10.980 William Cheng: The original chart over here will become the parent of the other child processes. And now what it would do that. It will call forth and the power that and the now. Now the child will run 335 00:49:11.220 --> 00:49:21.330 William Cheng: The child will run over here, he will go to the top of the while loop over here and now the, I guess this will be the grandchild, the grandchild will call fork and there's a grandchild would die and the grand, grand I will continue to run 336 00:49:22.680 --> 00:49:31.050 William Cheng: OK. And then so so the this basically it's the child process is going to keep forking a new child process and this could go on forever, right. 337 00:49:32.370 --> 00:49:42.300 William Cheng: So I think that's how it's supposed to work. So anyways, so from my understanding of the code is why if it turns out I was wrong. Please let me know, okay, because I'm reading the call. I'm trying to sort of figure out what's going on here. Okay. 338 00:49:43.380 --> 00:49:52.830 William Cheng: All right, what else is here. So I guess I sort of talked about all these code over here. The last thing over here is the Colonel three FAQ, right. So again, 339 00:49:54.540 --> 00:50:01.110 William Cheng: There's lots lots of stopping the colonel three FAQ, so I'm, you know, I guess I really can't talk about all of them over here. 340 00:50:04.200 --> 00:50:09.060 William Cheng: Okay, so you can actually see Colonel three FAQ, let me go down over here, right. 341 00:50:09.720 --> 00:50:19.110 William Cheng: There, these things. How to do GB and then talk a little bit f5 Fs. There's top entire web page table talk about page file and then the VM area or these kind of stuff. 342 00:50:19.380 --> 00:50:30.750 William Cheng: A bunch of user space program over here. So again, just like you know I mean like, for example, right. This one I just added today. Right. Some people ask that and turns out I think inside the FSS there's one common that was wrong. 343 00:50:31.590 --> 00:50:39.840 William Cheng: So again I'm just adding my my my notes over here that I think is wrong. If somebody can actually if I'm wrong, please let me know, okay, I 344 00:50:40.560 --> 00:50:51.060 William Cheng: I think is wrong. I'm not 100% sure it's wrong, right, because the Brown University people when they rice that most of the stuff is correct. Okay, so I'll be surprised that this one is wrong, but it looks like it's wrong. Yeah. 345 00:50:52.170 --> 00:50:56.700 William Cheng: Alright, so again, I mean this list, you know, once in a while, I, I will actually make them longer 346 00:50:57.810 --> 00:51:02.370 William Cheng: What else is here. Right. Talk about forking way talk about hello right all the stuff 347 00:51:03.120 --> 00:51:07.980 William Cheng: The system call, you know, be a map Reba map right, hopefully you have overcome all that already. 348 00:51:08.430 --> 00:51:13.860 William Cheng: To fork system called the fourth bomb over here. Okay, so, so one of the things people sort of asked about over here. 349 00:51:14.310 --> 00:51:21.900 William Cheng: Is about the chain or shadow objects by the shadow, they can get really, really long. So I think the only place you have to worry about it is football. 350 00:51:22.620 --> 00:51:30.810 William Cheng: Okay, so only way you're running for bomb. The, you know. Because, because, because what happened is that if you keep for HR process right we were talking about before every time when you forward. 351 00:51:31.260 --> 00:51:36.900 William Cheng: The link list for shadow objects going to get one longer right so if you fall call this 1000 time 352 00:51:37.080 --> 00:51:45.660 William Cheng: I know you're going to get up with a really big chain so Ivan. Is that where you start making recursive caught as you traverse down that link and you're going to be in trouble. You're gonna you're gonna run out of stock space. 353 00:51:46.740 --> 00:51:55.590 William Cheng: Okay, so it's almost like you know when you make a recursive call your computing Fibonacci number 4001 I forget who you are, you or are you trying to compute 354 00:51:56.130 --> 00:52:09.270 William Cheng: You know factorial of 1000, you know, and I forget it up reporting is going to die. Okay, so, so, so I guess one of my comments that I posted today was that for shadow Phil page and shadow 355 00:52:11.100 --> 00:52:20.190 William Cheng: Shadow look up page. The Brown University, but actually write it on top of those function in the comment block to say use iteration and don't use recursive call. 356 00:52:20.730 --> 00:52:29.280 William Cheng: Okay, because if you use a recursive Paul, you're going to end up running out of stock space, right. So the main question over here. Is that why don't they say the same thing about, you know, Shadow put 357 00:52:30.030 --> 00:52:37.800 William Cheng: A guide the shadow put it also, you know, if you have a long list loneliness. Right. So if you if you make a recursive call. If you call people go for it. 358 00:52:38.280 --> 00:52:42.990 William Cheng: So in that case, what if you're asked X rays that so so again if 359 00:52:43.560 --> 00:52:56.490 William Cheng: I think the only time that can happen is important bomb because for now we have a really, really long chain Raza indicated, you should read this kernel FAQ item over here right busy. Tell us over here is that there's something called a, you know, 360 00:52:57.960 --> 00:52:59.880 William Cheng: What it's called migrate or something like that. 361 00:53:00.990 --> 00:53:01.440 Let me see. 362 00:53:03.330 --> 00:53:05.580 William Cheng: Oh, sorry. I clicked on the wrong link over here. 363 00:53:07.350 --> 00:53:22.890 William Cheng: How do you make for bomb run forever. And, oh yeah, this is the one over here. Okay, so there are some note about migrating shadow objects. So the idea here is that, you know, the shadow the shadow object can get really, really long. Okay, so there's actually a trick that you can use call 364 00:53:24.360 --> 00:53:25.620 William Cheng: What is the name of the function 365 00:53:35.460 --> 00:53:50.430 William Cheng: Okay. So inside Colonel VM Chateau de over here. There's some notes over there about migrating the shadow object. I think in in via map. There's a bunch of VM map migrate. Oh, no, no. I think there's funny. 366 00:53:52.620 --> 00:53:55.410 William Cheng: All right, I need to go back to the other place. Let's take a look here. Let's go ahead 367 00:53:56.610 --> 00:54:04.710 William Cheng: So let's say that we go back to the week source code over here. Yeah, so grab my great 368 00:54:06.720 --> 00:54:13.200 William Cheng: Colonel include stars are that age over here. Ah, sorry. It's called P for a migrate so VI. 369 00:54:14.220 --> 00:54:15.150 William Cheng: Colonel 370 00:54:16.410 --> 00:54:23.490 William Cheng: Mmm, right. Mm. P frame does here. So this is one of the function in P frame that you don't have the right 371 00:54:25.590 --> 00:54:29.400 William Cheng: OK. So the code over here is to migrate a page rank up the tree. 372 00:54:29.730 --> 00:54:33.870 William Cheng: Because, again, this is the inverted tree right so if you have a patient what we hear what happens is that you have a 373 00:54:34.080 --> 00:54:37.110 William Cheng: If you have a really, really long link, link list of shadow object. 374 00:54:37.320 --> 00:54:44.640 William Cheng: What you can do is that you can take one object at the bottom over here and then move it upwards. Right. So when you move it up right at some point the shadow update become empty. 375 00:54:44.820 --> 00:54:53.430 William Cheng: When it's other object become empty, you can remove that that are out there and now the linguists of shadow is going to shrunk the live show it's going to shrink. 376 00:54:54.480 --> 00:55:06.420 William Cheng: Okay, so you have to do this very, very carefully, or you can only do this can't do the shadow migration for shadow object. I can remember, under what condition right over here. Anyways, the code over here sort of take care of it. 377 00:55:08.490 --> 00:55:10.350 William Cheng: Okay, so over here. 378 00:55:11.850 --> 00:55:16.650 William Cheng: If it's resident and it will do this right otherwise he will do something different. 379 00:55:17.670 --> 00:55:19.500 William Cheng: So over here I think it moves. 380 00:55:20.790 --> 00:55:28.200 William Cheng: moves into a different a different object, okay. So anyways, so. So let me go back to where we were before. 381 00:55:33.420 --> 00:55:40.770 William Cheng: OK. So the basic idea over here is that there's a trick for you to survive for bomb forever. Okay buddy involved doing something like this. 382 00:55:41.160 --> 00:55:43.500 William Cheng: There's also something called a shadow D the shadow demon 383 00:55:43.920 --> 00:55:52.530 William Cheng: Is not supposed to be running right but again you can he can enable the shadow demon in your current configuration by and configure okay you can say shadow deep was the one 384 00:55:52.800 --> 00:56:00.120 William Cheng: That will turn on the shadow demand, but you can you also need to make it so the channel demon. What it will do is that they will call the microwave function. 385 00:56:00.510 --> 00:56:07.650 William Cheng: Okay, so you should read the code in the shadow detail. We are the final how to migrate the page frame. So maybe you can just copy that code into your kernel. 386 00:56:08.220 --> 00:56:16.830 William Cheng: You guys were without actually invoking the, the, the shadow demon. Okay, so this way you know your lingers of chatter object is not going to grow. 387 00:56:17.640 --> 00:56:26.250 William Cheng: It is not going to grow very, very long. OK. So again, again, either the, you know, there's a lot of the sort of detail over here so you don't have to implement this. 388 00:56:26.700 --> 00:56:33.480 William Cheng: Okay. Some people really want to implement it. So if you want to implement it, you are looking for trouble. Okay, so if you have nothing better to do that, go ahead and do it. 389 00:56:34.290 --> 00:56:44.130 William Cheng: Okay. But otherwise, you know, the way we run for bomb right important note over here, you know, says please do not attempt the above setting Chateau de was one are doing all these paper migration. 390 00:56:44.370 --> 00:56:56.490 William Cheng: Unless you're completely done with Colonel two three can be done with Colonel through and you have nothing to do. You're really bored Okay, you can say, well, maybe I want to run football for 100,000 forks. Okay, if you want to do that, then you have to do this. 391 00:56:57.690 --> 00:56:59.850 William Cheng: Okay, so in that case you can you can do it. And so to sort of 392 00:57:01.980 --> 00:57:13.440 William Cheng: To do it but but if you don't, you know, again, you don't have to do this. And the reason is that if you look at the colonel three grading guidelines. When the greater test for bomb it was include print inside the BG 393 00:57:13.860 --> 00:57:25.350 William Cheng: Okay, rather debug flat right typically is equal to, you know, arrow, arrow comma test. Okay, but for debugging fork bomb and stress weapon is that inside stress. They also do something similar to for Bob 394 00:57:26.340 --> 00:57:31.800 William Cheng: OK, so the stress has is basically test everything together as also tried to make sure that your implementation is. It's pretty good. 395 00:57:32.430 --> 00:57:43.260 William Cheng: So, so those two things will will basically for Bob. Okay, but they also turn on DVD to include print. So, therefore, you know, when you're doing your conforming DVD car is going to slow everything down. 396 00:57:43.830 --> 00:57:52.050 William Cheng: Okay, so therefore your foot balm and best, you know, even though you've occur running as fast as it could. It will only run you know 240 500 forks. 397 00:57:52.560 --> 00:58:06.840 William Cheng: Okay, well, how fast your machine is there's no way for it to get to 10,000 forks okay because because also the instruction says the greatest should run for so many forks, or when the greatest way to run it for one minute, the greater will have to shut down the Colonel. 398 00:58:08.580 --> 00:58:12.780 William Cheng: Okay. So, therefore, you know. So again, if you're doing this. You're on your own. 399 00:58:13.380 --> 00:58:21.300 William Cheng: Okay, and nobody's going to help you. I mean, maybe can help each other out. Okay, but I'm not gonna help you to get this to work. Okay. Because, because there's no such requirement. All right. 400 00:58:22.080 --> 00:58:35.760 William Cheng: Okay, so I think I'm done. So again, next Friday, we don't have, you know, discussion section anymore. So this will be the last one. So, next way when I finish the rest of the textbook and then it will be the final exam time. Okay. All right.