WEBVTT 1 00:00:02.820 --> 00:00:12.570 William Cheng: Okay, this is a week 13 discussion section. So I copied this from the web page. So today we're going to talk about object dump. 2 00:00:12.929 --> 00:00:21.210 William Cheng: So you understand what your application program look like. And then, of course, the goal of kernel three is to get these application program to work. 3 00:00:21.810 --> 00:00:37.530 William Cheng: So we're going to start taking a look at. Hello. So you know what to expect. And if we have extra time. We can talk about some of the kernels three FAQ. So again, Colonel three FAQ is very, very long your, you know, you should look through them. 4 00:00:38.670 --> 00:00:40.230 William Cheng: This way you can save some time. 5 00:00:41.250 --> 00:00:49.470 William Cheng: So anyways, I don't know how much of the colonel through where we will get to. But if you ask me question about them in the class school. I'll be happy to answer. Yeah. 6 00:00:49.860 --> 00:01:02.280 William Cheng: Alright, so the CO that we're going to look at is, you know, hello. So I guess we can take a look at hello hello is pretty straightforward. I so it's in user user been 7 00:01:03.510 --> 00:01:04.440 William Cheng: Hello. 8 00:01:05.520 --> 00:01:13.770 William Cheng: Hello CPP or something like that. Hello, that see. And of course, there's a hello that exact so that's, you know, where you compile it. 9 00:01:14.280 --> 00:01:24.960 William Cheng: So I'm just looking at the pristine kernel source precinct kernel source if you said you know drivers equal to one VF as equal to one, as is equal to one VM equal to one. 10 00:01:25.500 --> 00:01:38.250 William Cheng: You'll be able to compile any we generate all these executable a program for you, even though, of course, nothing works. So the hello program is very simple. You open open you right and when you return your call. Exit right 11 00:01:39.330 --> 00:01:48.300 William Cheng: You know so. So in this case you need to get the the main programs are running and that you need to make these three these two system call work right. And then in the end there's exorcism call 12 00:01:48.810 --> 00:01:54.900 William Cheng: So you basically need to understand what does it mean to you know to to to to make this call. Okay. Okay. 13 00:01:56.100 --> 00:02:06.720 William Cheng: So what else is mentioned over here. There's a service called. I see. So if we look at CES called RC user so sis called RC is in the 14 00:02:07.230 --> 00:02:20.430 William Cheng: Library and C library right live see says called I see right here. Right. So this is the one I think. I also showed this to you either the week before or two weeks ago. 15 00:02:21.090 --> 00:02:25.860 William Cheng: So this is all the system called function. So we need to get open to work as a look and look for open here. 16 00:02:26.340 --> 00:02:30.660 William Cheng: So you can see that again, these are all system called they're thin wrapper around a track machine instruction. 17 00:02:31.200 --> 00:02:41.490 William Cheng: So you set up for the trap right this is this is how you set up with a trap you invoke the trap and then you take the return value of tribe and then you return from this function and also you need to 18 00:02:42.210 --> 00:02:49.530 William Cheng: You need to, you know, set up the air number right there's an area need to have Aaron number so also going to see when when Aaron number gets set up. 19 00:02:50.250 --> 00:03:00.330 William Cheng: The other function that's call. Hello. Is get called in. Hello, is the racism call right. So again, they all look the same. Right. You know, you set up with a trap you call the trap and then you return 20 00:03:01.020 --> 00:03:10.470 William Cheng: You reach out with the value. So what is the trap system call. So if you look for it. Grab trap user sorry grip trap. 21 00:03:12.330 --> 00:03:24.240 William Cheng: User include started. Ah, it's not in there. So, so this one is a is an inline function. So I think in like almost the same thing as 22 00:03:26.070 --> 00:03:26.580 William Cheng: As 23 00:03:27.720 --> 00:03:37.260 William Cheng: As calm defined. So basically, you know, we will you use the inline function. The code of that you'll have functions copy into your into your see source so 24 00:03:38.220 --> 00:03:48.510 William Cheng: So this one user include we Nick's trap that he right kind of makes sense. It's in the winnings directory. So you can see that this code is unreadable right it's 25 00:03:49.230 --> 00:03:56.130 William Cheng: Me again assembly code, that means that it's in the hardware abstraction layer. There's only work with Intel CPU. 26 00:03:57.030 --> 00:04:00.660 William Cheng: So I mentioned before, for Intel, the way that you invoke a trap. 27 00:04:01.350 --> 00:04:15.330 William Cheng: Is to use the software interrupt instructions. Those int Raza and over here. This one is not an integer. This one is the software interrupt machine instruction and then followed by the trap interrupt string. So this one is in Cisco. 28 00:04:16.740 --> 00:04:19.080 William Cheng: So again, what is in Cisco crap. 29 00:04:20.940 --> 00:04:21.330 Read 30 00:04:23.070 --> 00:04:24.150 William Cheng: Okay, let's try it again. 31 00:04:27.240 --> 00:04:31.590 William Cheng: User include start at age is not in there. 32 00:04:32.880 --> 00:04:45.540 William Cheng: Alright, so again in this one, it says you know us what sorry interrupt you know system call is zero, x to eat. I can also look at this file user include we mix this call that age. 33 00:04:46.470 --> 00:04:53.010 William Cheng: If you look for this. It's right here. Right. So this is the most important software interrupt. There are also some other 34 00:04:54.540 --> 00:04:57.390 William Cheng: Let's see, is there some other interrupt so there's no some of the interrupt. 35 00:05:00.540 --> 00:05:07.980 William Cheng: Alright, so if we look for grip I MTR user include star start at HTC other interrupts 36 00:05:09.510 --> 00:05:22.380 William Cheng: Okay, I guess we didn't really care about some other interrupts as. Those are the only implement the system called interrupt, which is, as I mentioned before, for into its zero x two weeks or so, therefore, this one is indirect to eat and then 37 00:05:23.640 --> 00:05:31.560 William Cheng: You know, I don't really understand the assembly instruction. So somebody who knows how to read Intel assembly instruction may tell us what was, what to do. 38 00:05:32.010 --> 00:05:36.930 William Cheng: You will see that over here the track machine instruction actually consists of two 39 00:05:37.620 --> 00:05:44.970 William Cheng: You know, to, to sorry interrupt right in zero x to eat right here. And then in and also include another indirect story. 40 00:05:45.660 --> 00:05:52.110 William Cheng: So this is what I mentioned before, if you execute code at the sea level, you know, the sometimes you get confused. 41 00:05:52.530 --> 00:06:01.170 William Cheng: Because of this code. This code is in line, so therefore they get included into all the system call and what he would do is that he will actually trapped into the operating system two types. 42 00:06:01.740 --> 00:06:11.910 William Cheng: The first time over here with a trap interrupt stream over here wizards to be over here. And the second time when a trap with zero or x to you again. This time is for Aaron number 43 00:06:12.840 --> 00:06:28.410 William Cheng: Guys over here is as equal as the return value of yours, and Aaron number and then this one is a sis air number. So this is Aaron number is one of those sort of the symbol that's being used. So again, let's take a look at again. Where do we look at that. 44 00:06:33.000 --> 00:06:39.690 William Cheng: Okay, so just this call right look at number 45 over here. We saw an open open over here. 45 00:06:42.540 --> 00:06:46.500 William Cheng: Okay, so we're here at the track. So the first argument in trap is the trap code. 46 00:06:47.040 --> 00:06:55.320 William Cheng: Right. So in this case, it's an open system call you know for the ride. This one says, sis. Right, it's the right system call. So the first argument is just an integer to tell you 47 00:06:55.650 --> 00:07:00.720 William Cheng: You know, which you know we chop code. This is so what it will do is it will take this number and then 48 00:07:01.020 --> 00:07:11.520 William Cheng: It will make you will make the system call right so the the double quote with a. This one is the actual name of the system call. So first, you will use this number, right, so this will be open or right 49 00:07:11.700 --> 00:07:20.820 William Cheng: And then the second time when they're tracking the ordinances there. So this one is called sis Aaron number. So I've been is that, you know, the user space go after in return from, you know, from 50 00:07:21.150 --> 00:07:26.550 William Cheng: From a trap could be open can be right. What do you do that it will go back into the kernel and get the error number 51 00:07:27.270 --> 00:07:34.500 William Cheng: Okay, you remember what those numbers are right in Colonel to you, said the air number, right. So when open fail you will say the air number. You said the return code to be 52 00:07:35.010 --> 00:07:39.330 William Cheng: Minus something right so what happened is that that value will be copy into this global variable. 53 00:07:40.230 --> 00:07:49.380 William Cheng: Why don't know if it's a global variable or not, but instead of Colonel, there is some way to store that right that the air number value. So now when you make the system call to retrieve the air number that's that that 54 00:07:49.740 --> 00:07:52.920 William Cheng: That's where it will get it from okay so whatever you said in Colonel to 55 00:07:53.370 --> 00:07:57.990 William Cheng: So in Colonel three over here, the user space program will go down into the kernel and retrieve the air number 56 00:07:58.320 --> 00:08:04.410 William Cheng: Okay, so, so, so this again this trap you know that, you know, this one looks like a trap, but actually tap into the kernel twice. 57 00:08:05.280 --> 00:08:11.040 William Cheng: Alright, so, so make sure you understand that because you know if you assume that there's only sharp into the kernel was what, then you will be mistaken. Yeah. 58 00:08:12.030 --> 00:08:18.840 William Cheng: Alright, so again the CO is impossible to read, but we're going to see plenty of plenty of things that are impossible to read. Okay. 59 00:08:19.410 --> 00:08:26.730 William Cheng: All right, so what do we need to look at. So we started Cisco and then the next thing over here is the object dump right there's a very, very important program that you need to run 60 00:08:27.120 --> 00:08:32.790 William Cheng: So what it will do is is that I would dump the object file I mentioned before, there are two ways to look at the executable file. 61 00:08:33.210 --> 00:08:46.440 William Cheng: One is use an M. Right. So you can do, you know, man. Man and and so and MSS, you know, list the symbol for an object file. So the way I think about this is an endless the symbol table right so you can, you know, because they and them. 62 00:08:47.220 --> 00:08:54.330 William Cheng: What is it you know user user been Hello, etc. Right. So this will show you all that symbol. 63 00:08:54.960 --> 00:09:07.110 William Cheng: You know inside a hollow. So I'm doing more on it. So they will say, you know, they're all these symbols out there and, you know, there's a couple of T Laura's Ki Ki T, they're also the virtual address that they that that that that 64 00:09:07.740 --> 00:09:13.530 William Cheng: That they take off. So again, the job of the linker is to plan out the address space for every symbol you figure out what their 65 00:09:13.770 --> 00:09:23.220 William Cheng: Their addresses and then right into the the executable file. So when you run the nm program, it will go to the executable file retreat all that information and displayed on the screen. Yeah. 66 00:09:23.520 --> 00:09:30.510 William Cheng: Alright, so lots of kind of a sort of a silly functions over here so we can also do this, we can, who can who can grab for me. 67 00:09:31.890 --> 00:09:43.230 William Cheng: Okay, so you can see that main is at this virtual address this number is going to be x 08048094 okay the startup option. It's called 68 00:09:44.280 --> 00:09:53.460 William Cheng: Lip see something. I don't remember what it was. Okay, so this is lipsey static static entry there. So this is the startup options. I remember when you 69 00:09:54.120 --> 00:09:57.630 William Cheng: Know in the user's Facebook. Well, I will you try to read a user space program. 70 00:09:58.410 --> 00:10:08.280 William Cheng: So what it will do is it will first call the startup. I'm trying to start a function is the one that calls me right. So, therefore, here's the function. Let's see. Start again three it says 080480 FA 71 00:10:08.970 --> 00:10:14.610 William Cheng: So, you know, for those of you who have been trying to get hello to work, you should be very familiar with this virtual address again. 72 00:10:14.850 --> 00:10:27.300 William Cheng: Don't look at virtual address, you know, in decimal. It's totally meaningless. Look at them, you know, in hexadecimal. Right. So. So why is this number so important. Right. So if I if I, you know, whoops. 73 00:10:28.590 --> 00:10:30.810 William Cheng: If I take this number right 74 00:10:32.940 --> 00:10:34.980 William Cheng: OK. So again, this has 75 00:10:35.250 --> 00:10:47.280 William Cheng: You know, eight characters. Right. So, so what you should do is that you divide them into, you know, the first five and the last three, the first five is the virtual frame number of the virtual page number. The last three is the offset within the page. 76 00:10:47.490 --> 00:10:55.200 William Cheng: Right. So whenever you look at a virtual address, you have to look at it this way. Okay, don't think of as one number chopped into to the first one is the virtual frame number, it's 77 00:10:55.620 --> 00:11:03.090 William Cheng: Using the virtual frame number you can find out which VM area is things belong to. And then, you know, so, so, so once you find the page rain. 78 00:11:03.330 --> 00:11:10.920 William Cheng: The patient is a four kilobyte has a four kilobytes page you use the second part, rather than second part is an offset within that page, right. So once you find a page. 79 00:11:11.310 --> 00:11:20.610 William Cheng: You can use the page align address. Add the offset to it and then you have a memory location. Okay, so always look at the colonel virtual address or the user rituals or any kind of virtual address 80 00:11:21.090 --> 00:11:35.400 William Cheng: By looking at the house number and divided to five characters, followed by three characters. Yeah. Alright. So, this one says the virtual frame number is zero, x 08048 you should be very familiar with this number because people have been posting it on class Google group right 81 00:11:37.230 --> 00:11:42.960 William Cheng: All right, so, so let's so so 111 way to look at executable file. 82 00:11:43.500 --> 00:11:51.900 William Cheng: You know, I guess for Linux or the executable file is something that he sec, I don't know why the name of this way, you know, but usually the, you know, we can compile a program 83 00:11:52.230 --> 00:12:00.150 William Cheng: You know the executable file is just, you know, hello, and nothing else. Right. I mean, doesn't really matter what it's called. Because on Unix the filename extension has no meaning. 84 00:12:00.450 --> 00:12:10.470 William Cheng: So somehow the Brown University people. Does that make things this way. So, and let me show you the symbol table object done tells you everything about you know that this is this video executable. Okay. 85 00:12:10.980 --> 00:12:18.330 William Cheng: So man object dump. Right. Okay. So you can see that this one goes on forever, guys. So this is a really, really big program. 86 00:12:18.870 --> 00:12:26.910 William Cheng: It does a lot of things. So we're going to just run it ok object dump minus minus disassemble section texts away only interesting a text section. 87 00:12:27.360 --> 00:12:33.780 William Cheng: So, by the way, that's first look at what other what are all the sections inside. Hello, that yaks etc. These are, you know, 88 00:12:34.650 --> 00:12:42.840 William Cheng: These are called. These are called sections. I mean, some of them I don't know really know what they are. Okay, so let's do this and we're going to 89 00:12:43.440 --> 00:12:55.470 William Cheng: Pipe into more than studies show you that there's a text segmental remember the text right in chapter three, we saw that. Right. Do we do. There's a assembler directive called dad, something that takes that data. 90 00:12:55.920 --> 00:13:04.980 William Cheng: Here's the tech segment. Here's the data segment. Here's the BSS admin. There's a bunch of debugging segment right this is how you will be able to debug the program. Right. So typically do either. 91 00:13:05.400 --> 00:13:08.220 William Cheng: There's some comments segment. Nobody knows what they are. 92 00:13:08.940 --> 00:13:18.270 William Cheng: Our own data. Right. So this one is the read only data and somebody asked that question because Google group, the arrow data since it's read only it's put together with a tech segment. 93 00:13:18.630 --> 00:13:28.050 William Cheng: Okay. You can also see the virtual address over here the tech segment starts at this weird address 08048094 and then 94 00:13:28.650 --> 00:13:44.220 William Cheng: You know how big this is. This is the size over here and you know the ROI data over here it's it has this virtual address. So as it turns out that you know all these, you know, two segments are combined together into a text admin. 95 00:13:45.270 --> 00:13:57.930 William Cheng: Okay, so why doesn't you know when he was multiple texts admin. I have no idea, but that that's not that that's how things are done. Yeah. All right. It also show you. You know what the, the, I guess the LMA 96 00:13:59.490 --> 00:14:07.500 William Cheng: I don't even know what LM essential. So again, these addresses are very, very similar. I mean, they actually look exactly the same. So I really don't know what what you know what differences. 97 00:14:07.920 --> 00:14:17.190 William Cheng: So BMA is the version of the VM area. So again, the VM area here. Is this the the start address and remember that BMA over here, we use pages, right, so we're gonna 98 00:14:17.400 --> 00:14:23.670 William Cheng: You know page align this address right page line, meaning that you go to the offset. You said it to zero, you're going to end up with a page line address 99 00:14:23.970 --> 00:14:29.190 William Cheng: OK. So again, starting from that point we're going to start using these paste Rams to implement this memory segment that 100 00:14:29.730 --> 00:14:37.890 William Cheng: The last part over here is called the file offset. Okay, so that tells you for this particular function, where does it start inside the file is that executable file right 101 00:14:38.340 --> 00:14:42.390 William Cheng: So again, that's the idea of memory mapping you map a file into your 102 00:14:43.200 --> 00:14:52.050 William Cheng: Your map a file into your address space right over here says this is where you start mapping from the file I find offset is 00 X and it for 103 00:14:52.440 --> 00:15:02.520 William Cheng: The map into virtual you know virtual address you know 0804809 for you can see that the offset are exactly the same. So again, you should 104 00:15:02.940 --> 00:15:09.570 William Cheng: You know, get a page line address so so this way, if you take this file apps. Also you can page Eliana, you're going to get zero. 105 00:15:09.990 --> 00:15:19.560 William Cheng: Okay, so this particular page is sitting on page zero, but the first. You know, you know, the first zero x 94 bytes over here. They are not very useful. 106 00:15:19.950 --> 00:15:31.410 William Cheng: Because they are header for your executable file for starting at offset zero x 94 that's what the real text, text admin start there. So you can also do this poker your file very I'm going to do the x x 107 00:15:31.740 --> 00:15:42.720 William Cheng: The heck stamp over here because I have the wrong command over here should be access d minus g one over here. So, this way we can see one character per, per, per 108 00:15:43.800 --> 00:15:50.520 William Cheng: You know, I guess one one bite proper perhaps character. So let's take a look at what it looks like. Over here. 109 00:15:51.060 --> 00:16:00.300 William Cheng: So again, if I run this command, it will go on forever, right. So, therefore, I need to have a go to a file. I'm going to call this file z over here so I can just look at it. Right. So I look at z over here. 110 00:16:00.750 --> 00:16:09.270 William Cheng: So worse. So get this is hexadecimal. Damn right, starting up again in the fall. It says that elf. Right. So this is telling you that this file is in the elf format. 111 00:16:10.020 --> 00:16:16.110 William Cheng: Okay, so that's why the file that we use inside Colonel three is called elf 32 right because it's a 32 bit format. 112 00:16:16.440 --> 00:16:26.880 William Cheng: And then, and then that that code over there, understand, you know, the structure of this file right every executable file is just a data structure. The loader use that use that information to load them into memory. Yeah. 113 00:16:27.300 --> 00:16:39.960 William Cheng: Alright, so zero x 94 is right here. So this line is 090 so this is 090 9192 9394 so 94 over here is going to be 55 114 00:16:40.590 --> 00:16:58.380 William Cheng: Okay, so this is where your main program, they will be your main function start. Okay, well, what else have we seen over here. The other command is the headers for the tech segment over here. I guess it sort of started I saw right there, then 115 00:16:59.520 --> 00:17:09.840 William Cheng: All right. What other commands you have. So let's take a look at the, you know, the most important command over here, this is the disassemble look at the entire tech segment. So let's take a look at it. 116 00:17:11.580 --> 00:17:12.450 William Cheng: Oops. 117 00:17:16.560 --> 00:17:22.200 William Cheng: Okay, so okay I'm gonna have the output, go to a file because as far as really big, as I will look at the five x over here. 118 00:17:22.950 --> 00:17:29.010 William Cheng: X is how long has as 4677 lines long. Okay, so this is the 119 00:17:29.430 --> 00:17:38.010 William Cheng: The entire tech segment right but this one is done when I say object that is a minus minus disassemble so what it will do is that it would set this assemble the color and the show it to you. Okay. 120 00:17:38.490 --> 00:17:43.110 William Cheng: So the way that this is done over here is is that you know anything inside the angle bracket. 121 00:17:43.560 --> 00:17:52.350 William Cheng: That's the name of the function. It was a the main function started this virtual address 08048094 we just saw it, man. So that's, you know, again you you map that 122 00:17:52.620 --> 00:18:06.240 William Cheng: You know funnel this into memory starting it off. Send it for what we have on the far right. Remember, instead of ours is 55 and then followed by at 95 so if we go to the z over here and look at 955 8095 123 00:18:06.720 --> 00:18:16.530 William Cheng: Now, so you can see that starting from here. Keep going down over here. That's your main function. Right, so I can go through this every bye bye bye bye you should, you know, trust me that this actually is going to be correct. 124 00:18:18.390 --> 00:18:20.490 William Cheng: Blah, blah, blah. Right, this is your main function. Yeah. 125 00:18:21.030 --> 00:18:29.940 William Cheng: So what is your main function do right main cause, open, close, open, close, right. You can see that over here is the call machine instruction right it's a five by instruction over here. 126 00:18:30.120 --> 00:18:39.030 William Cheng: It says, Call and then this. This is the absolute address over here. OK, so again for x86 they get compiled into PC relative address over here. 127 00:18:39.510 --> 00:18:44.640 William Cheng: So you can you can see that this number and this number actually doesn't match, right. 128 00:18:45.480 --> 00:18:51.060 William Cheng: Okay, because if they match. So that means that it will call this column by the actual address the x86 we mentioned before in chapter three. 129 00:18:51.510 --> 00:19:01.980 William Cheng: They users really, really, we're way called PC relative address and you know when they show you the assembly code. They say, oh, this is the open function. Guys, where's the open function, right, we can actually look at the open ocean, this file. 130 00:19:02.850 --> 00:19:23.370 William Cheng: Slash open since I'm using bi okay so open is actually sitting right here. It's at this address you know 8048 605-804-8605 right here. Okay. So, you see that in this case this address and this address today. Sit on the same page. 131 00:19:24.300 --> 00:19:35.760 William Cheng: That's okay, you should look at the first five character right because that's a virtual frame number the virtual frame number, the first five character over here is 08048 right over here, this is 132 00:19:38.370 --> 00:19:40.020 William Cheng: So open is here, right. 133 00:19:40.260 --> 00:19:52.830 William Cheng: So unfortunately, over here, they actually print your only seven characters. So you have to add a zero in the beginning. So again, this is 08048 so exactly the same thing over here so so so you know that when you go from Maine to open. There's no more peaceful 134 00:19:53.370 --> 00:20:04.230 William Cheng: Right because open a city on the same page as open to sitting on the same page as me. Okay, so, so you call open once here and equal open ones here. And then over here, you call right okay 135 00:20:04.740 --> 00:20:13.350 William Cheng: You can see that right. It's also at the same page, man. So therefore get you only get one page fall at the beginning and then and then you know you know you're not you're not getting paid for. Yeah. 136 00:20:13.890 --> 00:20:21.600 William Cheng: All right, what about the this sort of function rather sort of function is the one that calls me if you keep going down over here you will see that here is a buncha 137 00:20:21.960 --> 00:20:36.540 William Cheng: Loop see start again tree. And this is sitting at this familiar address. You can also see that the virtual frame number over here is 0804 a city at the same you know the the same virtual frame number. And also remember in one of the colonel FAQ 138 00:20:37.440 --> 00:20:45.240 William Cheng: Let me switch to that Colonel FAQ okay because it's kind of important FAQ over here. I'm going to sort of briefly go there. 139 00:20:49.260 --> 00:20:54.750 William Cheng: Okay, so let's go to the colonel FAQ projects current. Oh. 140 00:20:56.190 --> 00:21:06.960 William Cheng: FAQ, right, so that was my PT map right so go and go to PT map over here, click on this one. Right. How do I debug to know if I call PT map with the right arguments over here. 141 00:21:07.470 --> 00:21:12.420 William Cheng: It says that when you over here. It says, you know, if you use the commander, just use over here, right. 142 00:21:12.840 --> 00:21:23.010 William Cheng: Object on this assemble tag section over here you will see that the CO look like this at three C 404 that's exactly what we saw before that and 143 00:21:23.340 --> 00:21:35.100 William Cheng: You know, if you find the right page rank. If you use, you know, ps, ps at Dr. That's the colonel virtual address for accessing page, right, so remember for every user space page there to 144 00:21:35.520 --> 00:21:43.290 William Cheng: virtual addresses one is used by the user space program. The other ones are used by the Colonel, the one used by the Colonel, you need to find the page rank first 145 00:21:43.470 --> 00:21:49.410 William Cheng: And then in the pastry and there's PF a DDR that will be a kernel virtual address that you should use for your kernel. 146 00:21:49.980 --> 00:22:05.880 William Cheng: OK. So again, it's a colonel virtual address that means that the address is bigger than or equal to 00000000 right so I'll be here when we print this out using the same address over here right FA over here should be at three f nine should be see for an F. 147 00:22:07.110 --> 00:22:15.240 William Cheng: F F OF YOU SHOULD BE 04 okay so be here. So you should see you should see this information because that information is what you need. 148 00:22:15.750 --> 00:22:25.290 William Cheng: When you copy the data from the test into memory. So we have the data from this into memory and went into a page frame and your job in handle pays for is to find that page rank. 149 00:22:26.070 --> 00:22:31.680 William Cheng: Okay, you find the wrong page frame. Well, then it's not going to work. Right, so, so, so when you finally locator page right 150 00:22:31.890 --> 00:22:39.960 William Cheng: You've got to make sure that that's the right page rank. How do you make sure it's the right page. Right, right. We look at the data inside of a strength, according to the object down 151 00:22:40.290 --> 00:22:49.590 William Cheng: Okay, this should be the pipe pattern starting and location you know offset with zero x F8. Okay. So over here, it says in offset. 152 00:22:50.130 --> 00:22:54.780 William Cheng: Zero F eight they should have the value at three. So that's why you use the offside zoom F8 over here. 153 00:22:55.320 --> 00:23:03.390 William Cheng: You should give you 83 right and also says that later on when you finish calling PT map we finished competing man, you got to make sure that 154 00:23:03.900 --> 00:23:11.130 William Cheng: The validity bit inside the page table entry is set right once you do that, then you can use the virtual address the user space virtual address now. 155 00:23:11.340 --> 00:23:21.240 William Cheng: If you choose a user space virtual address. Well, then in that case user space virtual address coming into the kernel is going to be the virtual address for the lipsey static entry. 156 00:23:21.720 --> 00:23:28.650 William Cheng: Right, so for lipsey static entry over here. So if you have a buffer that points to this address. Well, then this will be an 157 00:23:29.100 --> 00:23:45.420 William Cheng: Offset zero, right. So, here if we use VA DDR. We've had cursor to a character array and then we try to access it using offset zero, we should get a D3. If we try to go to access Officer one, which you can see for if we go to offset to we should get 04 158 00:23:46.650 --> 00:23:50.700 William Cheng: OK. So again, this is how you know how each other so Bigfoot sort of figure out what are you supposed to do. 159 00:23:51.210 --> 00:23:59.940 William Cheng: So clearly, if this particular operation works. That means that your pace table entry at least your validity bed is set correctly. Okay. And also they have the right content. 160 00:24:00.840 --> 00:24:10.200 William Cheng: Right, so somebody asked you the Costco rule you know when it goes into the user space program, they get paid for right away. Well, maybe there are other stuff you don't set properly. Right. So again, you know, look, look through the 161 00:24:11.100 --> 00:24:15.120 William Cheng: You know the kernel source code to see what else you have to set or to start a discussion in the classroom. 162 00:24:16.170 --> 00:24:21.150 William Cheng: Right, I'm going to go back to look at the Phoenix source code again over here. 163 00:24:23.190 --> 00:24:34.380 William Cheng: Alright, so we're here, right, it shows you that starting at this address, you're going to have those three bites over here. Okay, so this is. Yeah. So by looking at the object dump you know what your address basically on look like 164 00:24:35.190 --> 00:24:40.110 William Cheng: Okay, so now if we look at this co, we can actually we try to predict when are you going to get paid for. 165 00:24:40.560 --> 00:24:47.430 William Cheng: Right, so, so when you start running your program. Okay, you have no pace frames in memory, right, because we're doing on demand paging 166 00:24:47.640 --> 00:24:56.400 William Cheng: So therefore, the first time you try to go to this page you're going to get a pace for at this virtual address right we mentioned, you know, the PT map, all that kind of stuff. So this will be the first 167 00:24:56.820 --> 00:25:06.150 William Cheng: Page email address that and I mentioned in the classroom that I don't really understand it is possible that some other student might have a different virtual address 168 00:25:06.810 --> 00:25:12.480 William Cheng: Okay, I don't know. I don't understand why I you know I thought we should all have the same virtual address for all the function 169 00:25:12.960 --> 00:25:21.600 William Cheng: Because we're writing our code in the kernel and the user space code are exactly the same. So if you compile the pristine kernel source code, you should get exactly the same virtual address 170 00:25:23.190 --> 00:25:30.180 William Cheng: Alright, so, so of course if you modify your pristine kernel source going to user space co then then all bets are off. Right. But if you haven't touched it. 171 00:25:30.720 --> 00:25:32.010 William Cheng: You should get exactly the same thing. 172 00:25:32.850 --> 00:25:40.650 William Cheng: Alright, so we're here. Let's see, studying to be here. Again, this one the virtual frame number is 08048 Alrighty, and then they are the offset. 173 00:25:40.830 --> 00:25:47.070 William Cheng: So you're going to get a fast pace. While we're here, once you do once you get the pace while you brought this this page one at this into memory. 174 00:25:47.250 --> 00:25:52.500 William Cheng: There four kilobytes in here. So if you want to go anywhere inside this four kilobyte you should not get a book, another call 175 00:25:52.950 --> 00:26:01.680 William Cheng: Okay. I mean, you will get a page. Well, if we are now therefore my address space as long as we don't map that for my audio space and why, then, then, then, then you shouldn't get it, you shouldn't get another pitfall. 176 00:26:02.190 --> 00:26:10.380 William Cheng: Yeah. Alright. So where do you get an x ray. He said that this one is a add machines auction over here. So as you get a paintball well 177 00:26:10.950 --> 00:26:22.950 William Cheng: You know here is EB SP SP is a registered inside of CPU. So you go to the register is that the CPU and in this case you increment it by four. Okay, so why would you want to include ESP before I have no idea. 178 00:26:23.670 --> 00:26:31.050 William Cheng: Okay, so anyway, so this is, I mean, this is the compiler during this call. I have no control over. And then what they do is that a call this function called may 179 00:26:31.350 --> 00:26:37.380 William Cheng: May is inside the same page over here. But when you make a system called side we make a function called whatever 180 00:26:37.800 --> 00:26:45.300 William Cheng: I mean, chapter three, would go through the detailed co for making you know making a function called right so what you will do is that you will pass the function argument. 181 00:26:45.480 --> 00:26:51.450 William Cheng: You will say the return address. And then you will transfer control to the main function. The main function is right here. 182 00:26:51.990 --> 00:26:58.200 William Cheng: Okay. And the first thing in main function is push out a BP move. Well, yes. Yes. Right. And we saw this before. 183 00:26:58.830 --> 00:27:08.580 William Cheng: Okay, so this is a C functions. So we know exactly what it does, what it will do is that I will call me will do enter. And then at the end of the main function over here you will call leave it where it says leave 184 00:27:09.180 --> 00:27:13.800 William Cheng: Okay, and then he will we actually executed the return function now. 185 00:27:14.610 --> 00:27:22.320 William Cheng: Alright, so again this code is a little different from what we saw in chapter three, but you can actually look at it and can tell that they are very, very similar. Right. 186 00:27:22.500 --> 00:27:34.110 William Cheng: I mean, I don't understand why this one doesn't say push out. It says push you know but that that's what object dump does maybe I've done doesn't really do what other x86 assembly do which is which is okay. Okay. 187 00:27:34.860 --> 00:27:46.110 William Cheng: All right, so what else is here. So, so, so we will, you will you call me you're going to end up pushing data onto the stack. Did you get a paywall. Well, of course, you're gonna paste fault. 188 00:27:46.860 --> 00:27:51.720 William Cheng: Okay, so he tried to push stuff onto the stack. There is no there's no stack rain say 189 00:27:51.960 --> 00:28:01.800 William Cheng: There's no page frame for the stack. So when when the first time you try to push anything onto the stack over here, you're going to get a page Hall and more and also this particular patient is going to be a copy on write page for right 190 00:28:02.250 --> 00:28:11.250 William Cheng: Okay, because the stack is support by anonymous object. So in the beginning. Over here you can do another subject, and it's also copy on write so therefore you should, you know, again, 191 00:28:11.610 --> 00:28:15.840 William Cheng: Since we are not doing fork. You don't have to use a shadow object. 192 00:28:16.590 --> 00:28:26.310 William Cheng: Okay, so if you have an anonymous RJ you can actually set up for copy on write. So in the beginning about how to set up a copy on write, write the page table enter you make a read only. So when you try to write it for the first time. 193 00:28:26.790 --> 00:28:40.950 William Cheng: Well, so, so, so, so right now at the beginning. Over here when you try to access to the other space table entry, the validity be equal to zero. Okay, so I guess in the kernel validity x86. They don't call it the validity to bed. What do they call it. They call it the, the President 194 00:28:41.970 --> 00:28:49.110 William Cheng: OK. So again, and the beginning the entire page table, the president, they have in the user space. The President bit is equal to zero. OK, so now 195 00:28:49.440 --> 00:28:56.130 William Cheng: You know, since present billable to zero, you're gonna get a paste fall and then if you set up a copy on write what you do that, you're gonna create 196 00:28:56.490 --> 00:29:06.450 William Cheng: You're going to ask you, anonymous object to create a page where the patient is four kilobytes law in order for you to do copy or right, you can set the pace table entry over here to be present but also read only. 197 00:29:07.080 --> 00:29:13.710 William Cheng: Right, so this. Where will you go back into the user space program what he will do is it will write to that page drag and again right is incompatible with read only. 198 00:29:13.920 --> 00:29:20.550 William Cheng: You're going to come to the, you know, to have the colonel with another page for all. So again, how many pages are you do you get depends on your code. 199 00:29:21.270 --> 00:29:33.480 William Cheng: Okay. Is it okay to get to pays for at this work at the virtual address inside the stack of courses. Okay. Right. Depends on what how you do it. You can also handle this new one page fault, okay. So inside the 200 00:29:34.620 --> 00:29:48.360 William Cheng: Inside the the the stack segment right the first the first time when validity to be able to equal to zero or the president bit equal to false. You come inside of Colonel, you say, Oh, I'm supposed to do. Copyright so that we can handle the only one shot. 201 00:29:49.650 --> 00:29:52.950 William Cheng: Okay, so this way you will set the pace table entry over here to be rewrite 202 00:29:53.100 --> 00:30:04.500 William Cheng: Right. So, therefore, when you go back into the user space. You don't have to do copy on write anymore because we don't need to make copy we don't we don't need to store things that chatter object, you can write directly into the pace friend that's managed by the anonymous object. 203 00:30:06.090 --> 00:30:11.970 William Cheng: Okay, so, so, so, so why is that okay right because we're not sharing that piece right right when you make a fork system called when you 204 00:30:12.300 --> 00:30:22.350 William Cheng: When you share anything with the child process. Well, now we're going to get into trouble. Okay, with the hello program, you don't, you're not sharing your patient with anybody, so therefore it's okay not to use the chat option. 205 00:30:23.520 --> 00:30:28.470 William Cheng: Okay. And also we need to copy on write, you can just, you can just copy, you know, you don't really need to make a copy 206 00:30:29.160 --> 00:30:33.540 William Cheng: So again, you need to use either make a copy, if there's another process. 207 00:30:34.350 --> 00:30:44.490 William Cheng: Right. If you don't have another process that sharing we're sharing your page rank that you don't even have a copy. You can have everything go into the anonymous. The go into the pace ran as managed by the anonymous up yet. 208 00:30:45.750 --> 00:30:52.440 William Cheng: Okay. Similarly, if you want to write to a file again can just write to the page rain right because you're not sharing that with any process. Okay. 209 00:30:53.100 --> 00:30:59.400 William Cheng: Alright, so again, again, that's sort of the, if you think like that they should understand that we don't really need to shout object that 210 00:30:59.880 --> 00:31:18.780 William Cheng: Alright so here you can get one page where I can do page, you know, it doesn't really matter. And then you transfer control domain, right, you can actually do this co push a BP move and subtract over here, move so move out ESP this ESP plus eight months ago. What is ESP, per se. 211 00:31:19.830 --> 00:31:28.470 William Cheng: Right, yes people, you know, I guess ESP plus eight ESP is top of the stack up plus eight, maybe this is a function argument. 212 00:31:29.100 --> 00:31:44.070 William Cheng: Okay, so get main function art be an oxy I can remember we using that the user user being hello see over here. Right. I mean, we do have our Vietnam see over here, but looks like we're not using it. 213 00:31:45.000 --> 00:31:52.560 William Cheng: Okay, so this case, I don't know what it's doing over here. But anyways, they, they go to this memory location over here, they move zero into them. 214 00:31:53.370 --> 00:32:08.130 William Cheng: I guess I don't know why. And then they move this thing into ESP, and then they do they perform a call to open. Okay, so you can see that over here, they move zero into where ESP is pointing to. 215 00:32:10.890 --> 00:32:17.430 William Cheng: OK. So again, this is the same notation over here, this ESP plus zero. So you copy that into USP 216 00:32:18.660 --> 00:32:24.000 William Cheng: Why is it doing that over here. I don't know what is this address over here. 217 00:32:25.260 --> 00:32:37.830 William Cheng: Easier for be 85. So what I can do, I can search for this right copies v over here. Okay, so this is not anywhere. Oh. Oh. So, so this is the argument to the move on to remember when 218 00:32:38.430 --> 00:32:49.110 William Cheng: We when you try to call open open takes three arguments. Right. So over here, what is trying to do is that you set up the SP zero yes p plus four years free plus a is pushing argument onto the stack. Right. How can I forget that. 219 00:32:49.710 --> 00:32:57.000 William Cheng: Okay, so again the stack, should you get a page for here what ESP over here is the the the 220 00:32:57.450 --> 00:33:09.060 William Cheng: The entire stack or this page is four kilobytes. So you're doing a copy on write initially. So once you write to it for the first time. From this point on, when you try to access that particular page there should be no baseball 221 00:33:09.450 --> 00:33:20.250 William Cheng: Yeah. So again, this shouldn't cause any page for all this shouldn't cause baseball this argument over here. So again, if you look at this function over here that argument has to be slash dev site TTY zero 222 00:33:21.600 --> 00:33:28.620 William Cheng: Okay, so we're a slash deaths ICT y zero. Okay, so, so where is that 223 00:33:31.920 --> 00:33:38.850 William Cheng: OK, so maybe we should look at the hello that you see over here. So we write that whole directly into Z right here's the hex DOM. 224 00:33:39.540 --> 00:33:42.690 William Cheng: So we're gonna look for such depth. So I should E y zero. Right. It's right here. 225 00:33:43.440 --> 00:33:57.000 William Cheng: Okay, okay, this is the read only adopt our own data, you know, segment rather than we move what we put into the inside the tech side man and look at the address over here, right, is equal to 385 you know 3850 226 00:33:57.690 --> 00:34:04.530 William Cheng: So in the beginning. We started out in one page rank, right. So, so this is, you know, so, so the zero or 227 00:34:05.190 --> 00:34:19.950 William Cheng: Five zero over here is the first page. Page rank or PageRank number zero. Okay. So over here, when you get here, this will be patient. Number three. So 0123 okay over here. You can also see that the address right here. 228 00:34:22.080 --> 00:34:31.440 William Cheng: Alright, so this is a 48 right so if live just write some notes over here. So zero x 48. This one is 229 00:34:32.580 --> 00:34:42.900 William Cheng: I guess page number right so page number zero, right. So remember, remember patient on my page that misery index. So if the first one over here is page zero, then what is 230 00:34:43.350 --> 00:34:56.070 William Cheng: You know, set and then we have you know zero x 49 so that should be paged want right and then zero x five zero. So for for 231 00:34:57.150 --> 00:35:05.070 William Cheng: For a should be paid NOM NOM to right and then 232 00:35:07.980 --> 00:35:22.620 William Cheng: Zero x four be she'll be page number three. Okay, so you can see that this is a 04 be right. So, so this and the original you know address over here. They are inside the same segment. 233 00:35:22.950 --> 00:35:36.030 William Cheng: But this one is page down zero and this one is patient I'm three. Okay, so therefore we need to guess I def slushy y zero. They're sitting at page number three is over. You know what you mean that string that's what you're gonna get. We're also going to get a page for 234 00:35:37.200 --> 00:35:44.190 William Cheng: Okay, because that because right now we only brought in patient on zero is our tech segment right so that's where it may is that's where lipsey start again three years. 235 00:35:44.430 --> 00:35:49.140 William Cheng: There but this stream over here. Later on, we have to get out. You have to get a paste all because it's sitting on a different page. 236 00:35:49.560 --> 00:35:58.440 William Cheng: That's okay, this is how you figure out. And when you call open or I call but you don't get paid for it because open is sitting also a page number zero. So again, let's go to, let's go to open 237 00:36:00.210 --> 00:36:05.790 William Cheng: Okay, open is right here. Right. So, what it will do is that, you know, it will 238 00:36:06.900 --> 00:36:12.180 William Cheng: You know, over here, it will call string length, right. So what is called streamlines over here it goes through ESP 239 00:36:12.630 --> 00:36:19.980 William Cheng: So I think this is where you get the stream from right that's the first argument. So somewhere over here, they're going to access that argument. So at this point somewhere right here. 240 00:36:20.340 --> 00:36:27.090 William Cheng: Okay, I don't know exactly where but somewhere over here, you're going to get a page fall because you tried to get the string slash slash t y zero. 241 00:36:28.710 --> 00:36:44.670 William Cheng: OK. So again, you know, single, you know, look at, look at the source code over here. When you single step. And then I guess one place inside the kernel source code. They also tell you how to single step. You know, in assembly code. So let me switch to the class web page over here. 242 00:36:45.870 --> 00:36:47.520 William Cheng: single step. 243 00:36:54.780 --> 00:36:57.900 William Cheng: Alright, so I guess I should go to the top over here. 244 00:37:00.630 --> 00:37:02.220 William Cheng: What if I look for assembly. 245 00:37:08.340 --> 00:37:17.610 William Cheng: Okay, how do I debug assembly code over here. So again, this is inside Colonel three FAQ, how do I debug assembly call but here's your shows you a few important GDP command. 246 00:37:18.840 --> 00:37:25.110 William Cheng: Okay. One is si, si over here is a single, single step one line assembly code. 247 00:37:25.740 --> 00:37:36.630 William Cheng: Okay, there's there's Si. There's also an eye right and that is the next one. So if you make the function call it will actually go to the next assembly call after the function returns. Right. So there and I there's si 248 00:37:37.350 --> 00:37:44.490 William Cheng: Also this very important. You can change the layout to look at assembly code. So you said layout ASM they're 249 00:37:45.720 --> 00:37:53.760 William Cheng: Also there is something called info register, I can use info registered at these display all the CPU register. So if you want to know where the interrupters enable or not. 250 00:37:54.120 --> 00:37:58.380 William Cheng: So by looking at one of the CPU Registry will tell you. Well, with Rob's enable or disable 251 00:37:58.860 --> 00:38:06.420 William Cheng: So if they interrupt this disable then it's going to be really bad news, right, because if you are waiting for this interruption interrupts disable or then you will never get to interrupt. Yeah. 252 00:38:06.840 --> 00:38:16.080 William Cheng: Alright, some other importing your instruction over here breaks, followed by star followed by by a virtual address. You can set a breakpoint using a virtual address 253 00:38:17.010 --> 00:38:29.550 William Cheng: Okay, so if you're looking at your assembly code. And if you are looking at us and because I want to set a breakpoint on that line over here. Look at the virtual address and you can say say break, followed by at the Asterix and then followed by zero x over the with a particular address 254 00:38:30.600 --> 00:38:38.760 William Cheng: Okay, so, so when you're debugging like the the the system called there are, you know, inside the truck function. There are multiple you know 255 00:38:39.090 --> 00:38:49.290 William Cheng: You know software interrupts, or I sort of getting can set a breakpoint right after the, the, the, the end zero H E when when that line return you can actually set a breakpoint right 256 00:38:50.610 --> 00:38:58.320 William Cheng: What else is there. So I guess another important command. I didn't list over here is called layout, followed by the word next 257 00:38:59.100 --> 00:39:02.610 William Cheng: There's 11 is that there are different layouts. Oh, there's the layout ASM. 258 00:39:03.330 --> 00:39:10.500 William Cheng: There's the layer. Oh, I don't know why they are most of them are typically I just said layout next guy so so in GDP. Right. Once you have a command can keep 259 00:39:11.040 --> 00:39:18.930 William Cheng: hitting Enter key. They will repeat the previous commands or you can say layout. Next, you keep pressing enter. Do you see the layout that you want that that will be the one 260 00:39:19.710 --> 00:39:24.300 William Cheng: That you keep. Okay. Sorry. So, so be very careful. Once you in the regular 261 00:39:24.600 --> 00:39:34.470 William Cheng: GDP mode when you look at the you know what what we're not looking at any kind of a source code. It's pretty stable once you go to the other Mo, we have what, when you see the split screen. 262 00:39:34.800 --> 00:39:48.990 William Cheng: Then GD be you gotta be very careful when you copy and paste doesn't work anymore. You know, because they do all these trick with the with the cursor and stuff like that. So again sometime you rather go back to the basic mode that will be the best mode. Yeah. 263 00:39:50.700 --> 00:39:57.900 William Cheng: All right over here. You can also do this assemble. Right. So guess the other place that I usually go to inside the 264 00:39:58.500 --> 00:40:04.410 William Cheng: Colonel FAQ is to set a breakpoint in May, right over here. If you say you're here says, Be may break point in May. 265 00:40:04.890 --> 00:40:13.560 William Cheng: So you can over here. You can set a breakpoint. You may the startup function is called lipsey static entry a call, you know, cause Mang and take the return Cohen co exit on it. 266 00:40:14.100 --> 00:40:22.350 William Cheng: So you can set a breakpoint in May by doing this. Okay, so here it says at symbol file user user bit hello that you see. 267 00:40:22.890 --> 00:40:28.800 William Cheng: So this is the, you know, the first instruction in the tech segment, I don't really remember that. Okay, that's the main function. 268 00:40:29.550 --> 00:40:39.180 William Cheng: Okay, so apparently all the user space program, you know, the first memory location is always this number. Okay, and that that address always has the main function in them. 269 00:40:39.630 --> 00:40:46.290 William Cheng: Okay, so this way you can say as symbol file. Anything that you see, followed by this one. And now you know you 270 00:40:46.920 --> 00:40:54.060 William Cheng: Know you have all of a sudden. Whoa, okay, including the main symbol and now you can say be man and I can set a breakpoint in user space in the main function. 271 00:40:54.600 --> 00:41:07.830 William Cheng: OK, and now you will you do continue over here, when they execute that function user space, you'll get a break right so when you get a break point the user space. What do you do well, then they will be exactly the same as you get a break point in us a warm up warm up to 272 00:41:09.330 --> 00:41:13.020 William Cheng: Okay, so, so, so that would be the same thing over here but you gotta be careful because as soon as you 273 00:41:13.710 --> 00:41:21.540 William Cheng: You know, sort of going inside of current also, you got to be watching what you've got to be careful for single step when you single step. As it turns out that you get a page for all. Boom, you're inside of Colonel 274 00:41:22.200 --> 00:41:37.500 William Cheng: Okay, and then there's no way for you to go back into the user space program. The only way is to continue, whether you can set a breakpoint more. Okay, so what I often do is I set a breakpoint all over the place in the user space program. Yeah. Alright. So let me go back to, you know, the 275 00:41:39.480 --> 00:41:52.470 William Cheng: One to again. Okay. So for example, if I look at hello see over here, right. So in this case, you know, open over here line numbers 13 right so I say break 1314 276 00:41:55.230 --> 00:41:59.370 William Cheng: You can also set it at the end of a function break 19 over here so you can set a breakpoint everywhere. 277 00:42:00.270 --> 00:42:07.800 William Cheng: Or is it this way. If you accidentally companies out of Colonel, all you have to use the continue and you will go back to the next place that you set a breakpoint in the user space program. 278 00:42:08.370 --> 00:42:17.490 William Cheng: Okay, so. So again, what I will do is that I set a breakpoint in the user space inside me right so this case where you, you know, get a break. We'll be right here at the curly, you know, actually. 279 00:42:17.880 --> 00:42:19.530 William Cheng: At the beginning of the next line over here. 280 00:42:20.280 --> 00:42:31.140 William Cheng: Okay, so this guy again, you're ready to execute a sequel, and then I will set a breakpoint every line over here. And then in this way, you know, if I accidentally try things out a cardinal, I can do continue, I will go to the next line space. Yeah. 281 00:42:32.070 --> 00:42:44.310 William Cheng: Alright, so let's continue over here and look at the open system call we, here I am. So what can I tell about open. OK. So again, open right they set up for the trap. Okay, so, so, so 282 00:42:46.110 --> 00:42:49.950 William Cheng: VI user LIP LIP see 283 00:42:51.240 --> 00:43:03.660 William Cheng: Cisco see right opens right here. You set off with the travel over here. So again, the first argument over here is file name right, we mentioned before, the file name is sitting in page number three. 284 00:43:04.440 --> 00:43:17.670 William Cheng: Okay, so be here. Will you try to access patient on three over here. You're going to paste. Well, okay, and also string length. Where is string length. So let's take a look at a string length over here, streamline 285 00:43:18.690 --> 00:43:32.310 William Cheng: Stream. We're streaming keep looking okay so streaming is right here. The address over here is 08049 right originally with 08048 so this one is page number one. 286 00:43:32.940 --> 00:43:39.900 William Cheng: Okay, so again, will you go to page down and go to page zero, you're going to get a paintball when you go to Page Down three, you're gonna get a page where you go to page number 287 00:43:40.320 --> 00:43:49.110 William Cheng: Why are you also going to a page fall. Okay, so, so you should be expecting to get a page for this virtual address. Yeah. Alright, so let's go back to open again. 288 00:43:50.220 --> 00:43:55.380 William Cheng: Okay, so. So again, we saw the code for open right here. Right. 289 00:43:56.520 --> 00:43:58.110 William Cheng: Okay, and 290 00:43:59.340 --> 00:44:02.220 William Cheng: Open look like this right you and then at the end of the year. 291 00:44:03.000 --> 00:44:07.860 William Cheng: You you trap and then you return. Right. OK. So now that we remember what this look is setting up the thing 292 00:44:08.220 --> 00:44:14.190 William Cheng: It's pretty confusing. We don't know what it does over here and then it calls the trap or the trap code and then pass all the arguments over here. Yeah. 293 00:44:15.060 --> 00:44:28.440 William Cheng: So what we can do over here is I'm going to go through the colonel to see where it gets too. Right. So here's a sis open. There's a function, is that a kernel code says, Open Colonel API is called I see right says underscore open 294 00:44:29.490 --> 00:44:35.250 William Cheng: Okay, so, so when you make the trap system called. This is where again. Oh, where's Where's going to go 295 00:44:35.580 --> 00:44:40.470 William Cheng: Okay. So, so what we'll do, as we mentioned in lecture. Right. What do you will do is it will go through 296 00:44:40.830 --> 00:44:51.210 William Cheng: The hardware abstraction layer goes to the internal contacts when it comes to interrupt contacts, you know, go back, go into the kernel threat contacts when it goes into the kernel threat contacts, sooner or later, it needs to get here. 297 00:44:52.080 --> 00:44:56.850 William Cheng: OK. So again, we're going to assume that those part of the kernel code is perfect. When we shouldn't touch it. 298 00:44:57.300 --> 00:45:07.170 William Cheng: Okay, so therefore, as soon as you trap or right before you try to set a breakpoint right here and see if you get here. Okay. And you're supposed to get here. Right. And then there's also sis air number right 299 00:45:08.250 --> 00:45:17.370 William Cheng: Or no, whoops, we don't have it has. Okay. This is Aaron number something else. So, here it goes gods, goddesses are better. Right. What is the goal says obey 300 00:45:17.790 --> 00:45:20.280 William Cheng: The goal of this open is to reach do open 301 00:45:20.820 --> 00:45:26.760 William Cheng: Okay. The goal of this rise to go to do right the scope goal of says read is no to do read right so what it does. Over here is that 302 00:45:26.850 --> 00:45:34.260 William Cheng: You know, so, so in the user spaces and how they build a data structure, you're going to convert them into the right arguments. So you can call do open 303 00:45:35.040 --> 00:45:42.540 William Cheng: Right to Ober has two or three arguments over here, right. So what it needs to do is I need to take all these are and these arcs are user space data structure. 304 00:45:43.200 --> 00:45:49.260 William Cheng: Okay, so you need to copy it into cover the user space data structure into the kernel space data structure, right. So this is what it does. Over here. 305 00:45:49.440 --> 00:46:00.750 William Cheng: It costs copy from user. So this is the user space data structure over here, this is the kernel space data structure, right. Why is this a kernel space data structure, the current arms over here because it's a local variable right here. 306 00:46:01.770 --> 00:46:15.030 William Cheng: Right, so this is why we're already using the colonel stack. So this is a local variable here. So we're going to copy the user space argument over here into the kernel space argument. Okay, so this one is the open r s t over here is what is the open r s t 307 00:46:18.300 --> 00:46:19.140 William Cheng: To over here. 308 00:46:23.220 --> 00:46:32.760 William Cheng: Let's see. This is called a see right open. Okay, so this is open arcs to vessels are exactly the same data structure. 309 00:46:33.960 --> 00:46:42.420 William Cheng: Okay, so this data structure open arcs t. This is the user space your data structure over here, we copy them into the kernel data structure. Again, why do we copy it. 310 00:46:43.110 --> 00:46:49.500 William Cheng: Well, because we want to make sure that we only use Colonel virtual address inside the Colonel, because the user space virtual address might not be safe. 311 00:46:50.550 --> 00:46:56.430 William Cheng: Okay. So in this case, you know what, you know what, when you come inside the current over here at this time. 312 00:46:57.030 --> 00:47:06.960 William Cheng: You you make the trap system call inside the cardinal, we haven't done anything funny. Yeah. So, therefore, at this time for for very short period of time. We know that the virtual address over here in the USA, there are good. 313 00:47:07.890 --> 00:47:15.810 William Cheng: Okay, so when did. When did it become no good guys remember whenever you make a fork system call we're going to reset the 314 00:47:16.290 --> 00:47:28.050 William Cheng: Going to reset for copy on write when we used to have a copy. All right, we got on the page table with zero everything out. Okay, so when we do that, everything become invalid. So if you use the user space virtual address at that point while you're gonna get into trouble. 315 00:47:29.250 --> 00:47:37.590 William Cheng: Okay, so okay he's that are currently going to be very, very careful. We only want to use kind of virtual address when you first trapped into the kernel. At this time, we know that, you know, 316 00:47:38.220 --> 00:47:51.570 William Cheng: Or we know we will actually hope that all these arguments over here in the user space program they touch them already, so therefore they all have valid user space virtual address rise up, again, the President did or the validity of it has to be true. 317 00:47:52.230 --> 00:47:58.410 William Cheng: Okay. Otherwise, as soon as against out of Colonel, you try to copy or they ain't gonna, you're not going to pay small things that are currently if you get a paycheck, you're going to be big trouble. 318 00:47:59.280 --> 00:48:11.100 William Cheng: Okay, so again, all this isn't over here when we come inside. Over here, we know that all these user space virtual address inside this art at this moment. They're all good. So therefore, we can copy them into, you know, 319 00:48:12.660 --> 00:48:15.870 William Cheng: copy them, you know, into the kernel, the data structure. 320 00:48:16.650 --> 00:48:24.090 William Cheng: That and also be here. What I tried to do over here is that is that he will actually do a string doop. And then this is a user's reassuring do 321 00:48:24.480 --> 00:48:31.260 William Cheng: So I think this argument over here the phone and over here is going to be a user space virtual address. So what it would do that, it will actually make a copy of that string. 322 00:48:31.680 --> 00:48:36.240 William Cheng: Okay, so at this time that string. What does that straight right that's slash 323 00:48:37.200 --> 00:48:46.380 William Cheng: Slash definitely slides TTY zero right it's the first argument to open. So we're going to make a copy of it again. Why do we make a copy because we want to use the kernel space virtual address 324 00:48:46.620 --> 00:48:54.930 William Cheng: This path over here. We're going to pass it to the as the first argument to to open if we use a local user space virtual address. Well, then, to open. It's not gonna work. 325 00:48:55.800 --> 00:49:02.010 William Cheng: Okay, because they know in the middle of the do open call maybe you'll do something funny and then the bird, the bird, the virtual just become become invalid. 326 00:49:02.910 --> 00:49:06.630 William Cheng: OK. So again, instead of Colonel when you make all those system calling Colonel to 327 00:49:06.930 --> 00:49:18.750 William Cheng: You know all the argument that you ever use you always assume that they're kernel space virtual address, so therefore don't pass them user space virtual dress right over here. Yeah, this function over here, they will actually make sure that you know bathroom doesn't happen. Yeah. 328 00:49:20.190 --> 00:49:28.050 William Cheng: All right, so. So again, the goal here is go to do open. So the same thing with. Right, right. Will you make the racism call again to go over here is go to go to this go there. 329 00:49:29.100 --> 00:49:33.810 William Cheng: All right, what else that we're looking at right so we're going to open and then 330 00:49:35.760 --> 00:49:49.290 William Cheng: In zero x to eat, right. So there are two indirect to you over here. Here's one right here is the other one over here. And we know that the first indirect to he that's the open system call and the second one over here, this is the one that get the air number 331 00:49:49.800 --> 00:49:54.750 William Cheng: Okay, so they get error number over here, the code over here zero x two, seven. 332 00:49:55.260 --> 00:50:00.720 William Cheng: Okay, so remember that there's something called the SIS underscore open says under the sisters capital letter. 333 00:50:01.050 --> 00:50:13.560 William Cheng: Okay, so those symbols are, you know, tell you which system call you're making then. So I think zero x 27 that's the one that's the system called that will get you the the decimal sketchy do the air number. All right. 334 00:50:15.000 --> 00:50:22.470 William Cheng: Okay. And then what to do over here is that it makes these to stumble over here. And guess what did return over here, it's, it's basically a setup for return 335 00:50:23.160 --> 00:50:33.510 William Cheng: So we hear a pop all that kind of stuff that you saw before. In chapter three and then he will return. So in this return, he will return you know from open, right. So over here, it will return them over. 336 00:50:34.770 --> 00:50:41.820 William Cheng: So, so again, would you can do is if you look at this co this address over here will be the first location. 337 00:50:42.720 --> 00:50:53.490 William Cheng: Where you know the the open system has going to return now. So again, what you can do is that you can actually set a breakpoint right here by saying, you know, again, the syntax is be. Oops. 338 00:50:55.350 --> 00:51:06.420 William Cheng: I lost it. Okay, open is right here. Right. So if you want to make assist you want set a breakpoint over here is a bee bee space star zero x zero, x zero 339 00:51:07.050 --> 00:51:15.840 William Cheng: Right, so if you type this okay have exactly this, you will set a breakpoint right on the line. OK. So again, this is how you set a breakpoint. 340 00:51:16.350 --> 00:51:27.360 William Cheng: In assembly code. Okay, you know you you using a machine address so so when you are debugging your code right if you switch to the assembly mo by saying layout ASM. 341 00:51:27.990 --> 00:51:39.000 William Cheng: Then you're going to see, you know, all these virtual addresses right so you can actually, you know, you can copy and paste. Again, be very careful because when you copy and paste over here, you're going to end up copy and paste bunch of weird stuff because in that mode. 342 00:51:39.630 --> 00:51:45.360 William Cheng: You know where things happen. Okay, so, so sometimes you probably have to type it we type you going to make mistake over here. 343 00:51:45.930 --> 00:51:54.120 William Cheng: So I think it's okay to actually, you know, do something like this you you copy don't copy multiple line because doesn't work right can only copy, you know, within a line. 344 00:51:54.330 --> 00:52:06.810 William Cheng: And then if you're using a terminal. You can do Control, Shift see over here to copy it and they can actually paste it using control shift v. If you use other ways of copying. Some people use, you know, right click or something like that, it doesn't it doesn't work. 345 00:52:08.040 --> 00:52:13.380 William Cheng: I mean, as far as I know, it doesn't work, maybe, you know, maybe they fix it or something like that. But again, again, very that'd be very careful with it. Okay. 346 00:52:13.650 --> 00:52:24.630 William Cheng: All right, so, so this is how you you know set all these breakpoints over here. And again, sometimes very, very useful to develop this way, especially when you are doing for can wait. Were you doing for giveaway. 347 00:52:25.800 --> 00:52:32.670 William Cheng: Is very tricky, right, because you know if this one is the fourth system call. So if I look out for fourth I won't be able to actually find it over here. 348 00:52:33.060 --> 00:52:42.120 William Cheng: Okay, so if this is a fork system call right this is the first one is fork right here. Okay. And then, what it does is that after the fork. What it will do is that 349 00:52:43.110 --> 00:52:57.450 William Cheng: The parent and the child, both of them is going to return to the to to to the user space program. Okay, so, so if you set a breakpoint on this line right here right this to zero, x 489 to you actually going to break there twice. 350 00:52:58.800 --> 00:53:06.570 William Cheng: Okay, so, so you go inside the colonel was right and now both the parents how they want to return they should return to exactly the same place where should I return to 351 00:53:06.750 --> 00:53:14.640 William Cheng: They should return to the instruction right after the trap machines Joshua, which is this virtual address. Okay, so if you're if you're debugging, you know, 352 00:53:15.120 --> 00:53:22.860 William Cheng: A focused way right so you can set a breakpoint right here. You should see that it will come there twice. And again, what is the difference between user space in the kernel space program. 353 00:53:23.910 --> 00:53:31.200 William Cheng: So what is it every day. Apparently chopper where I the parents are program. They're identical. The only difference is in EAS 354 00:53:32.670 --> 00:53:38.520 William Cheng: Okay, so, so that means that if you look at all the CP register right again, there's a command called info register, look at all your CP register. 355 00:53:38.700 --> 00:53:46.440 William Cheng: What you should do is you do that. Okay, look at the parent, you know, register. Look at the Tao register. They should be exactly the same. The only difference is, yeah. 356 00:53:46.950 --> 00:53:58.590 William Cheng: For the parent process. Yeah. Actually be zero for the child child for the child process. Yeah. Actually people to zero for the program process issue have the process ID of the child, whatever that number is right, typically is going to be a very small number. 357 00:53:58.860 --> 00:54:06.390 William Cheng: So again, you know, if you said a broker over here you can immediately verify and then look at those things to know you know which one return. First is that apparently is that a child. 358 00:54:07.500 --> 00:54:16.290 William Cheng: Yeah, all right. And then what it would do is they will go to the colonel again right after I could get the error number, you know. So again, if you don't have any error while when you go to the Colonel, you should get a zero. Yeah. 359 00:54:17.670 --> 00:54:21.870 William Cheng: All right, what else do I have to tell you over here. 360 00:54:24.210 --> 00:54:28.800 William Cheng: Alright, so let's go back to the original this over here. So I guess I went over everything over here. 361 00:54:29.640 --> 00:54:46.710 William Cheng: Okay, so I guess that's all I want to talk about so so so again when you, you know, start running your hollow program. You need to know, you know, when whenever you whenever you get a page fall. Look at the virtual address. And then, you know, go go go go through this print out over here. 362 00:54:48.090 --> 00:54:56.100 William Cheng: Okay, go to this print out over here to look for that virtual dress. Okay, there's another way to do it. We want to come on over here in the in the discussion website over here. 363 00:54:56.310 --> 00:55:03.510 William Cheng: This one is almost the same as the other one, except that there's a capital minus s okay so if you if you if you run this one. 364 00:55:05.160 --> 00:55:08.280 William Cheng: Okay, and then I run this command over here. Whoops. 365 00:55:09.000 --> 00:55:20.250 William Cheng: run this command over here and I'm going to have a go into a different file called while we're here because I was too long now I go to Y can actually see that they will actually mixing together the sequel with the assembly code. 366 00:55:20.940 --> 00:55:28.860 William Cheng: Okay, so sometimes that would be very useful right when you get a good pace fall. You can look at a virtual address over here. So again, try to look for that virtual address 367 00:55:29.460 --> 00:55:39.030 William Cheng: Virtual just over here. So if I have the open system call right will be, I guess, open. I'm not going to get a paywall, which one do I get a page well 368 00:55:41.220 --> 00:55:43.020 William Cheng: Streaming streaming 369 00:55:47.310 --> 00:55:48.570 William Cheng: Okay, we don't know where it is. 370 00:55:50.220 --> 00:55:57.120 William Cheng: Oh, streamline this energy. Right, so I'd look for in string lane left ran over here. No. 371 00:56:02.640 --> 00:56:11.310 William Cheng: Right. Okay. So, so it's not it's not return engaged in size to be here. So here's a straight line function. Right. So again, it's in this address. Okay, so if you get a pastry at this address 372 00:56:11.520 --> 00:56:22.470 William Cheng: All you do is to come to this file and look for it because the, oh, it's right here. Right. This one is equal to streamline. So then, then you you and then look at the virtual the virtual page number, see if it makes sense that you're getting a pitfall. 373 00:56:23.820 --> 00:56:32.490 William Cheng: Alright, so, so, so again, don't just try to get numbers from other people will try to understand exactly what's going on. So this way you can make prediction right i mean the key to Debugging is to 374 00:56:32.760 --> 00:56:38.610 William Cheng: Make a prediction to see what's going to happen and see if it happens right if he doesn't happen either your assumption was wrong. 375 00:56:39.450 --> 00:56:48.390 William Cheng: Okay, or you know your assumption is, write your code is wrong. I mean, of course, it's possible to use something is wrong and the code is wrong. So that gives us a sort of, you need to get a different assumption. 376 00:56:48.870 --> 00:56:58.590 William Cheng: Okay, but that's how you debug stuff. Why you need to make a prediction and see if it happens. Okay. All right. So if you have any question about all this kind of stuff, feel free to send an email otherwise. 377 00:56:59.700 --> 00:57:12.450 William Cheng: You know, guess next lecture next Monday. We're going to move on and look at Chapter four finish the device driver stuff and also going to start talking about talking about virtual machines. Yeah.