Okay.
Good morning, everyone. I'm so assignment one was do last night, you had until a few minutes ago. To finish up.
So what I. So I've now posted the solutions.
So we can talk about them. Now while it's still fresh.
Before I start going through, so if you now if you want to follow along you go to the bottom of the assignment page and you'll see me there is a link now to assign one solutions.
So, let's start going through this year. So first question. There are three functions defined a 3000 menu. See, which lines through them implement each of those functions.
So, so here the lines but the basic idea is that the one where the label for the function is, is the start of the code, but really you want to also include the data.
So for example, if we go to
know what I want to do. I want to go back, I want to download these
here I want to go to.
Yeah.
So if you look at the code here.
So we're talking about the functions like run program. Oh that's very stupid.
So here's the thousand menu so here's the scene.
And then let's bring up the
This.
So, what we're talking about here with.
So it's saying that.
I'll show you.
So we look at run program right here.
You see void run program here and then we see the strings here running there. How does that show up in assembly so we have the run program here. That's certainly the start of the code for it.
But you see up here, there's the string here running, which is right here, this running string. So, this is clearly part of the run program assembly code as well.
So that has to be included. And so really you can see here we just go up here and there's this section, you know, you'll notice that there's this pattern the section so really you could say it starts at this line here but, you know, I kind of say it starts
starts right here because this is where it is defining it, and this LC zero is actually the label for the string so really should include, you know we should start here this lc 04 started that one.
And then it goes here we have run program run program on down. Here's the end of the function where returns.
But you know for for life that's one return. And then there's the executive, he here.
There's another call here.
And then, but this right here is the end of run program.
line three to 60 lc zeros line for yes LC zero is on line for, but the label before it is a section.
And so really, each of these the function really starts with this section declaration.
But that's how that's how the assembler, keep section keeps functions apart, is they all start with a section, and the section has a size and that goes till this size one program and you know what's next is a section.
And the section here and then we see are we have all the consonants that are defined the next function LC one lC lC three things, the things that are grinder.
And then we have here and then, and then choose program and then choose program goes up until
the saw. You know, this right here. And then main, there's main doesn't have any strings or anything embedded in it so the start is just right here at global main we defined that variable so that, you know, can be accessed from outside of this a file,
and then, you know, it goes until this oh sorry it goes until
until the size thing.
So you don't, I'm going to leave it up to the TA is I mean I'm certainly going to give some flexibility on how I'm aware of what you say.
I, the main thing.
So this is a little bit of a judgment call I was I didn't specifically talk sections, but I was hoping for you to look at it and see the pattern, like why are these lines there.
You certainly will be giving out, you know, you weren't really supposed to give up, you know, I'm definitely give out partial marks. Now,
what I was expecting you to do is now again, I expect yourself to get marks for this, but look at the pattern.
CFIN proc. So if you look at CFIN proc that's certainly a reasonable place to stop.
You know, like, and in fact that gets you everything here.
So,
what the size directive on the size directive is basically how it's calculating this, so each section has to have a size.
And so what this notation is basically saying, from the starter run program to the end of I think this probably means the end of the CFP and I'd have to look that up again.
I haven't looked I don't program and assembly, I don't, you know, know all the details all these declarations but just looking at the patterns you can see that oh, here's another section.
This is our read only data. You know that starts here.
And this is, you know, here's a section that starts read only data.
And this read only data goes here now, this, the CFA start proc n conch.
That is certainly regional The only problem is is you left out the data, this string is clearly part of this code.
So it's like you cut it off.
Sir, I think that we can differentiate between what was used by the code and what's part of the code, so like when we were reading the documentation he gave us, he gave us no indicator that you would want it that included the documentation states the
end in the beginning, from the sci fi. If you read if you read things you've linked, which is all we had to go on.
And I know in previous compiling courses I've taken. They talked about how the compilers extract out static elements which don't change, and give it their own section and text and it can be referred to by not one but multiple functions so I I did not
see that is uniquely belonging to that function, it certainly uses it, but it could have this function could have been at the bottom, and using something on the top right.
So, exactly.
Exactly. And again, the point. The point is, the way we're going to give marks for this is not based on the exact lines that you give, it's going to be based on your reasoning about it.
And your reasoning that you just described is perfectly is reasonable.
And you're correct about that.
So, you know, again we're not I'm not trying to teach you the ins and outs of assembly code.
That's not the point of this. The point of this is actually to look at something that you don't completely understand, compared to something that you should completely understand what I expect you to understand see and kind of go like, Hmm, what does
this look like.
And the point of the assignment is more to go through the exercise going, What is the connection between these two, and then state your reasoning, and so as long as you give a reasonable reasoning, and then you and then you get the numbers, I don't, the
precise numbers is not the point.
The point is, did you try and do the correct if you made a reasonable inference will give you the full marks.
But, but I do want but if you're going to be bleeding out clearly what's, you know, I see running is right here. And then I see running it's over here and you say that's not part of the thing but like I would want some reasoning about it.
I was saying that the compiler extracted out, but it's like okay fine but without that it's like, but that's part of the code.
So, so that's why I'm looking for is.
And that's why I have all these things of like saying, how do you how do you know these are the correct lines.
I want you to go through the, the answer, ultimately, for most of this class is not the point. It's how you get there.
How you're thinking about these things. Because what I am throwing you throwing in you here is an environment where you don't understand everything.
Yeah. So, yeah, this is the same for like, you're not going to understand everything that's going on.
Yeah, so, state your assumptions. Exactly. And if your assumptions are reasonable assumptions will have to give you marks, because sometimes the questions are ambiguous in ways that I sometimes have deliberately ambiguous.
Sometimes our biggest some ways I didn't mean to. And so, I'm looking for you to explain your reasoning.
Because some of these things are debatable.
And I'm not saying, I've got the ground truth because I don't. Again, we're talking about. So, in the back of your head.
One of my fundamental learning objectives, I want you to have for this class that I have in this class is dealing with complex software systems.
And when you start getting into complex software systems.
You're not going to understand how everything works and in fact you're mostly not going to understand how things work, operating systems is really the first time in the curriculum where you're really dealing with such a complex software system and you
know what alternative way of teaching operating systems is to give you a simplified operating system.
And have you see how all the parts work but
that's not what you're going to live with.
That's not the environments, you'll be programming every day your program complex systems.
And part of that means living with the fact that you don't know what's going on for a lot of things and how do I navigate so you understand well enough to be able to do what you need to do.
So that's the point of doing the assembly is not that you understand all the assembly, but get used to like, let me learn enough to do what I need to do.
So going on.
So I guess I was expecting some variation in this, and will be certainly flexible about that and if you know you feel that he has been you know unfair same but I will, you know, the nice thing is the same ta will be grading each question.
So because that's what the whole point of the, of the validation of the code and of your assignment stuff so I can read through a script split up by question.
Great, all of question one all the question to say.
The.
So,
when you talk about so there's natural breaks.
You talk about a C program.
There's natural ways you chunk it up.
You've got functions, that's the basic unit of functions.
You have struck.
And you can say a race.
But that's, that's how it is and maybe you have some of the other but really that's how you divide divide things up so in assembly.
Doesn't have natural divisions like that. It's just bites after bites after bites and the interpretation of those bites, but you may have an actual interpretation that you intend, but the process is going to go along bite after bite after bite and make
its own interpretation.
So keeping sane.
That's all it is. I mean, now of course you can say section look at 10 segments.
And if you say look at elf, oftentimes these things get translated a different section becomes a separate thing for the elf binary.
So that, you know, okay here is something that you're going to load in the loader will load those separately.
Cool stuff.
Interesting learn about, way beyond the scope of this class.
But
so what line 3000 men you define the menu array of characters. So again just sort of looking looking at your reasoning. The thing I looked at here was good oh here it is, you know, so we're after main now so the beginning of me here with the graph domain.
And then we've got this global declaration for quit.
And then we got you know quit no quit.
So this is the number quit, which has the value three so critical. And then there's the global menu and so that's that's the thing we're talking about here.
And here we've got a bunch of strings defined.
And here we've got a bunch of strings defined right there with their references there. And then we have this, this is the actual menu object that we size and it's 40 bytes, because it's eight times five is 40, and a pointer in 64 bit land is eight bytes
because he bites at 64 bits. And so we have a pointer point our point our pointer and no pointer zero.
So you could say the data so really the data structure menu really starts here.
You know you say starts here, this is metadata for it. So you can see it starts here it starts there and it goes from here and it goes through this quad.
But then the data for it is just above it.
So, but he calls to say the global menu, kind of, is also there so you can just say it's all there so I want you to talk something about it the constant data is here, the pointers are right here.
We will be generous barley will see like how you compare to your peers.
So, again, don't.
The way I structured this course is that things are practice for the next thing is the tutorials or practice for the assignments assignments or practice for the midterm, You know, and the final.
So, you see the same things over and over again in different forms. And I'm training you how to answer these questions. So, if you, If you do well on the assignment that can potentially help.
No. Do you well but if you know for the rest of things but if you don't do well and you do better on the midterm and final your grades will be raised by those I do grading schemes where you are, where you show competence.
That's where I can give you your marks.
I'm so that's it so three now what what lines that 3000 men you define the menu array of characters, why that's why that was me. I didn't I skipped to my apologies.
So why is environment reference not the final 3000 menu.
Well, note that environment is declared as an expert expert is necessary because if I just said character environment here.
That would mean that I'm declaring storage for it right here.
And someone else can't define it so enough to find it then there's overlap here I'm saying someone else defined environment, we're just using it here in assembly.
If someone else to find it and we're just using it here, we just use it. And we don't define it.
That's all.
So that's that's the nice thing about, um,
but the external, you know thing, XXR and basically just turns in some sense you and assembly there isn't all these checks of like is that in scope is that out of scope, like scope, doesn't mean much in assembly except maybe outside the file inside the
file. That's about it.
Yeah.
Yeah, exactly.
Your environment comes from the standard. Yeah, the Unix standard library. Exactly. That's where environment comes from. It's from outside of it and that's what you didn't even have to know about that you just know it's declared external.
What does external mean.
So it's not so much declared in there. It could be in the header.
It doesn't actually have to be in the header headers are for see.
Remember, headers are never compiled by themselves, they are just things that are included in C files, and then they're compiled as part of it, they don't really have a life on the road the compiler never compiles a header file on its own, it's always
included. And so, and in fact, we actually wouldn't want a defined environment a header because we included multiple things by having the extra declaration here, where you had it in the header you declare it as external, but some other ops what this really
says some other object file declares environment, as a global variable.
And because it's declared as a global variable in a another library basic in another c file.
We can access that global variable, we just have to say it's somewhere else to find externally, this is what extranet in see.
And that manifests in assembly as just being, we just use it without defining it.
And what the linker does. That's the whole job of the linker is to define these undefined references between object files you a bunch of object files they all have a bunch of references that are internal to the object file but it is something else, the
linker says oh I these two occupies this one The first was wrong and this one, this one for this one okay we can put them together and resolve those references into actual addresses and combine the code together.
And if it finds, oh I don't know where that is. Then you get a link error and your link fails.
You don't tend to see link or errors, commonly because you normally are working in a language that would make such undefined references an error at the source compilation level.
By the time you get to the linker everything should work. But if you start putting in external declarations for variables, and you don't actually declare it as a global and some other file, and then you try to compile it, you'll get link or errors.
So.
So question for you.
to 14, to 20 this is all.
This is all putting. So what is this actually doing this is putting identifiers in about the version of the GCC that's in there.
Me. It's just an identifier it's not part of the.
That's the compiler, that's really the compiler saying, Hey I made this.
Okay so, um,
how does it so far identify labels, I'm
so, so, so files, the names are all there if you'd like, look at object dump and Nm you can see all the names that are not referenced, or that can be referenced like.
So this.
Yeah, that they're all in there.
Again, I don't want to go into full detail of how all name resolution and stuff works in this because it gets quite complex. I just want you to know.
This is the kind of thing happening at this level.
Why windows requires those extra macros for DLL in the header. I'm.
I'm not sure. I mean basically they're just dynamically like libraries.
But I not that I'm not that much windows programming. So we'll have to see them but.
So, how does extra know which file to grab is associated very often, extra does it extra and just says it's someone else in the link or basically looks at everything you're incorporating the binary and any of them could define it.
Does it sound like it could get a little complicated yes linking complex programs can take a while to resolve all the symbol references.
Anyway, okay so let's move on to four, which lines of 3000 menu correspond to line 72 cents Submit. So here.
So, let's let's let's line this up here so.
So we're looking at one one line 171.
So,
so we're talking about 74 to 76.
Right.
So, 74 to 7672 to 76 I guess it starts. So here what I'm looking for is, it's we call a function, the return value the function is assigned to a variable we check the variable for a value and if it.
And depending on it we potentially returned from the function with the W zero.
So that's what's happening.
So, in here.
We know we're in Maine, so we know that's there.
And then we look for the call to choose program.
So, call the Choose program that's right there so that corresponds to calling the function, so we're good. Notice we don't have an assignment.
We don't have assignment for the return variable so the return value of cheese program was returned in in in a register.
And then we have, if program equals quit.
So if you looked up the, so we call and then we compare long, the value of EA. Yeah. So that's a register which presumably is where choose program, put its return value.
And then, and then compare it to the value at quit which will be three but that's a global variable so we're comparing those two.
And then what this instruction je jump equal to LUL 22, so I'll 22 is down here. So this is it saying if these two are equal.
We jumped here and then we. Here we go. Move this to their change the stack and return.
So,
that's it.
That's the code.
Here's the return zero because he moves zero in there and TX and then we hit return. So that's, returning zero from the function.
And then, this was the, you know, this was choose. She's program, and we got to run the inside of the if statement by because we checked if it was zero and then we jumped to this label and if we didn't jump, then we're actually can falling through and
that's the code for the if the program does not equal minus one.
And that's that comparison.
And then we jumped to em and then, and then this is the loop. If it's equal.
You know it's there. Now you know this means we're going back to the top of the loop, which is the J 19, otherwise it calls run program.
So, the point of this was really for you to try to read a little bit of assembly.
So what's going on here. So,
exactly, Jason you're exactly right that extra is just basically, I wouldn't quite call it syntactic sugar syntactic sugar doesn't change the semantics, it's but it is a declaration saying yeah someone else's do this don't consider it not being declared
an error, it's fine.
So why do you have all these offset directives.
So, the offsets are basically saying where things are, remember we're laying out things in binary and so sometimes we're padding things out to makes me and a nice even boundary because things get annoying if they're not on like, like boundaries to blessing
for machine. There's other boundaries that you care for cash alignment but
you're having to figure out things pattern.
Okay, good. So that's what I want you to read this much assembly.
That was really the assembly I wanted you to read and if you look up these instructions.
No, it's not complicated.
You know, it's just telling me it's literally, here is a jump. Here's a comparison. And here's a movie here's a call.
Like, that's it.
So you can just showing you, like, if say what's really cool about doing this as you realize that when you code and see.
It can translate. See, maps, very cleanly to assembly, it really can be thought of as a high level assembly language.
And it's just not,
you know, it's really compact, like you do this. Um, so yeah so that was a little puzzle for you guys to go through and I didn't think I thought this code was pretty straightforward.
And then if you if you understand this, you will have a little understanding of assembly.
So that's for let's go to.
So, We're back.
Five.
Yes, the call to get line a life is an implicit Malakal requiring a free does this result additional system calls.
It does not result a distance as an accomplice, and the way you can see this if you didn't ask trace, let's let's walk through this year, whereas the gala.
So what we do is we first do we do a printout of your choice.
And we do a get line. And then presumably you know we'd run the command, you know, run the command. So here, you look here, if you look at the screen, you'll see your choice.
You'll see or read.
And then you'll see a right of what it's running, and in between there, there was a gap, you know, there's the get line here.
The get line clearly did the read the line before clearly did the right.
And then the next system call is the right that came from running here, which was you know this is run program and run program happens right after you choose the menu option here.
Your choice.
What I actually like it gets in main because we get choose program and then we run the program so this is all the system calls, there's no memory allocation in there.
So, that's it didn't happen.
Yeah, well, literally all cuz it well.
If you go to a higher level so this question here is,
you're going to start Yeah, many languages you go from that language to see to assembly to binary Yeah, but you have a lot of language but some languages go straight to assembly and then binary So, a lot of them.
Not all languages go through a seaside stage. Some do.
And some of them have complex run times, which run, which interpret things like you name it, they can even turn by currently.
There's a lot of way things get implemented, but see is very close to assembly. And in fact, when you are experiencing see programmer can envision how a given construct will compile to assembly and in fact, when people are programming Linux, the really
advanced folks, they will sometimes look at the C program and then look at the assembly and go like, is that really the quite the assembly or Could I get better assembly and they'll tweak their see to get better assembly out.
So, um, yeah right is the library function right is no right is a system called that print f does.
So remember, it's not a library called these are system called this is what s trace outputs. Now suddenly there is a right, like there's a right library called in the C library that wraps it, because we will get to that in a minute but that is a system.
And so, so yeah so and that's what I'm saying is there's no additional system calls in between.
So, if you just walk through the system call you know trace. So what was the purpose of me doing this was I wanted you to see that you can see where system calls line up in your code, and you can see how the execution is just by seeing what the simple
things like that system call that has to come from this product code that's in the car to come from this product code I mean the strings are right there.
that in more depth seen a little, you should have covered that in 24 one,
to some degree, it's all talk about file descriptors.
So why there is it. So the reason why there aren't additional system calls, is because Matlock has an initial allocation it.
Now look at this is something that you should have seen in tutorial to if you played with Malik, you do small allocations, it just doesn't break, and there's already some amount of storage already there so it doesn't have to keep changing it.
If it's just a small location but for big ones will have to grow the stock but then if you do really large ones.
It just doesn't end map, and we'll, we'll talk about what a map is later but it does this map and they get you a big chunk of memory
and but s break is used and it's not called every time you do an allocation is just to do larger allocations because system calls are expensive, so you don't necessarily want I want 10 bites I want 15 by do want those smaller allocations are always required
system call.
So Malik only gets a pool and then splits it up.
So, you're empirically seeing this this this fact of memory allocation that you ask for big chunks of memory from the colonel.
Small allocations you don't go to the colonel, you get a bigger allocation and you slice it up in your program itself that's how you do efficient memory allocation.
If you ask the kernel for every little small allocation kills performance.
Six, if we replace like 27 a filament with P equals zero was behavior the program change, why now we're starting with the assembly stuff and just trying to understand what this code does.
So line 27.
So basically this is saying, we're not gonna make a call to fork.
We're gonna say zero. This means that we no longer have two processes here at this point, normally after a fork we have to process running, and what the to process of doing is distinguished by the two causes of testing of the P i p zero, the child gets
the parent gets the P idea of the child.
So, if we say zero, we're only running the child code, and so we do this.
So the behavior change you see is you do, is you run you select an option for the menu.
It runs, and then the program terminates, and it terminates, because we didn't exactly eat but we didn't do an executive in a child process, which is exactly in our main process, and so we throw away all our code.
And so, instead of running the command and so when that exit there was nothing else to return to.
That's why, so this is just me again why probably there's you understand the dynamic between fork and exactly, and why we why shells do a fork and then executive.
Oh yeah that that's painful.
So, um, so question five.
If you only state the first part, there's no sizzle call center, not mentioned small increments of security that enough. So for question five.
I'm just a question five do these results and district calls result in additional system calls How do you know, in order to get full credit for this. you just have to explain your observations that you look to the system calls you look at the code and
said there's nothing there so clearly there's no sizzle call from our now why that's the case I did not ask that if you put that in there. Great. And that case but that was not required for full credit,
it's now going to cool says,
Ah,
I'm not going to talk about stack overflows right now, except to realize
when you're talking about the stock growing so stock or flows when the stock was too big and get an error with that.
Just because the compiler says something doesn't mean you actually have more memory allocated you'd have to add in system calls to ask the colonel for more memory.
To avoid a Stack Overflow.
Because ranges of memory that have been allocated part, which is why your program if it goes too far off into unallocated memory ranges. Get segmentation violations.
Okay, so back to so we did five.
Alex we depend on how you are you wrote your answer. I mean, I was really looking for you to do is like I was looking for you to do the test.
I was looking for you to check to see what the program does.
Because if you didn't check to see what the program does. I'm not sure if you knew how you would know for sure. I would have to check can be sure, because it might do a system call.
It could mean, depending on the C library. It could do this first allocation know every it can do a system call for every allocation of your bad C library but it could.
So, I was expecting you to do an empirical test.
And if you didn't, you'd have to have a very good high level answer.
Oh, so okay so this is six to seven, if we replace one of the string pointers that, you know, so we may you know so what is going on here with this thing.
What is this.
This is a little hack.
This is a little hack to get me the correct command line options for executives they get the right things for exactly specifically to make this one work.
But I have to look at your answer. If your answers have been explanation outs and potentially fine but we'll have to see.
But here, so what so what is, let's look at a man.
Yeah, exactly. So we're looking at exactly what does it take it takes the arguments path name argument list environment variables. So half name.
That's the choice menu choice. And so our choices a number menu is a bunch of full path names.
So half name is easy. First arguments actually done, third argument to exactly. We're just including our environment variables, we're just passing them on.
So that's easy to done.
The second one, we need to make an argument list. So what is an argument list. It's an array of string pointers, with the last element of the with the last string pointer being No, that's how you don't give the colonel.
A number thing how many, how long are the is you just have an array of strings and the last one is, it's no terminated. It's a array of pointers that's no terminated.
I could have made my own thing but I realized my menu.
wasn't was already the same kind of thing.
So I just need to. I if I just give a pointer to the first element here like I give a pointer to this one. And then I make sure the next pointer is no.
I'm done.
So that's all I'm doing is I'm overriding here, I'm saying, you know, menu bracket choice is is my choice, and the next element in the array I make it No, and then I make sure I just pass a pointer to that choice so I just start the array there.
So it's quite hacking, but it works up because I have no command line arguments I'm passing on to the commands, I wanted to include a command line arguments then I'd really have to construct my own right but here I'm just using it raises their.
Now, the other part of this question is, why did I mess up things like because if I did this in the past, if I did this normally I think why messed up the menu I overrode a choice in the menu.
But you did it in the child and the child process as a copy of everything.
So if you're the child how it changes memory does not affect the parent, so this is perfectly safe.
So that's what I was really testing here is whether, in order to understand this you'd have to have a conceptual model, understanding. That's what's happening with it.
Oh yeah, Martin, the whole thing about clobbering data and stuff like that that that's, we will talk some more about that.
When you get a site one grades, I'm going to give it up to the TA is and no, You should get it before the midterm.
I'll say that we were the goal is you should have grades for a site one for the midterm assignment to you'll get the, you'll get the solutions for it but it won't be graded before the midterm, but you'll at least have the solutions, but you'll have a
sign of one grades before the midterm.
So that explain that so seven.
So I thought that's what this.
What change in the menu so explain that. So eight. Does, does well how does the the menus behavior change if you delete line 34 the call to wait.
So here I'm just getting to understand that Wait, because we're calling wait on, you know, on this. We're waiting until the child finishes, and if there's no child that has things that yet but there is a child that's running.
This will cause the process to block it because that that's why it's called weight.
And so here we're not waiting for the child execution will continue next, next, with the menu. So again, this is the same behavior as the shells we've seen with this foreground versus background processing so that's why this should have been very straightforward
if you play with those
GDP is the next thing I want to talk about after I'm finished with this.
And then we're on tonight.
So nine.
I will talk about.
I will talk about that. Right now we're still in a process level view.
That'll be across talking about how the system works.
The young chosen but I'm
replacing replace line. So replace line 29 in manga dot s
warning the line, line 29 so leave this call. So what is this line doing this is calling the fork library function.
That's what this is doing.
And I'm saying, replace this with this move 57 yaks and Cisco.
So what I done by replacing this with this is, I am instead of calling it library function. I am making a system called right here. That's how do you make a system call you load the system called number in here and then you make a system called into the
EAX red shirt and then you make a system call. And, you know, Cisco instruction, because this will call.
Now, how do I know how did I know it was number 57.
I looked that up.
xoo what was the past.
I'm.
Thank you.
include XIXH, that was, that was ok x86 sm. and then
you just did 64.
So here is the file, which is user include x86 64 Linux new ASM, not a file you should normally be looking at.
But this has the 64 on a 64 bit Linux x86 system, the system called numbering and if you go down to 57.
You'll see it's for
you.
So yeah, you would not be I for Ricky you cannot just use a random register, there's a specific assign meaning to registers, when you do system calls, and even when you do function calls, that's, It's a calling.
It's called calling conventions, so you can't just put things at random registers certain registers have certain meetings, it's typically by convention, but that doesn't make it any less real certainly when you're making system called you better put the
the things in the right registers only things will not work.
They aren't just random, they're not just variables there are places for things.
So what I was expecting you to see.
When you do this, first of all, it's dark side player dynamic link well I told you, dynamically linked you when you compile it.
Because that's the default. And then what you should have seen is when you ran this.
When you read the original one, this call to for should have actually produced a clone system call.
But when you change the assembly, you would set see a fork system called and no library called a fork. If you the original made a library called a fork buddy system call to clone.
That was always expecting you to see. Now, why is it use clone
clone is this creative child process. It's a more general version of four, it's got lots of things going on, more precise control what piece of execution context of share between calling processing the child process.
It's a fancier fork. And so the C library. The library decides instead of using for system call it uses calm,
Cool xa said call a calling convention with you.
Thank you, Martin.
Okay, so
I think that's all.
Oh yeah so that's what that's why it differs is because, you know, first clone and then the last thing is
the, well I mean,
I was trying to say. You can't do this.
You can't go around, adding.
You can't put there's no way to state and see, I want to have a Cisco instruction. Now there's a library call, where you can do we can do the equivalent of this.
But if you look at it at an assembly language level.
It wouldn't be this.
It would be a called
Excel.
The number of system calls.
Depends on what the fork system calls doing it should be the same I haven't checked that
there are multiple unit states should make sure you look in x86 64.
Things like so there's a couple of units did, if you look. Let me show you.
See,
those are the United States, but actually you want, that's not actually what you want. You want fine.
That's after the fall you one is unisex underscore 64 dot age. That's the one of the system call numbers.
Um, but yeah, but for just last one.
If you had evidence that you said, I haven't actually checked what Cisco compiled into it, it's possible it might just jump directly generate the assembly and the code.
I don't know, I haven't checked that. But if it does, then fine, but otherwise normally you are calling a library function not directly generating that assembly you're calling a library that has that assembly
is is very close to you.
You can use in line assembly for see but that's not standard see
no no call says call it PLT is not a sis call instruction.
Yeah. No, you can't. Yeah, That's a nobody was possible thin line assemble Yes, perfect, Jason that's perfect. Steve, your answer is not correct. Because you notice the call to Cisco, that is not the same as this call.
That is calling a function named Cisco, not executing a Cisco instruction.
Do you see the difference. Steve,
a visually similar. It's visually yes it's visually similar but it's semantically completely different.
It looks, it doesn't look a lot. Yeah, it looks very similar, but no, this, this bit, I was looking for, could you get that system called instruction in there this this this call instruction assembly.
Wasn't
the naming naming of things could be better I'm not gonna argue with about that.
But let's let's switch now let's go to.
So now I'm going to Let's go now and let's start using a debugger,
new language lessons length and lessons learned languages like see. That is very true. They are see his old sees from the 70s. So,
Well, out in a dash g bugging and
browsing shower. last, so we're good.
GDP.
So I can run so I can do. So let me show you how to do GDP properly here.
Alright,
so now, so you got a terminal here. And we've got a regular shell here so what I'm going to do here is I'm.
So I'm going to run thousand show.
what.
Oh, right.
I can't do that here.
I can do that here.
You don't have pipe support in 3000 show.
So that's 16441 so what I really want to do is GDP.
Okay, so I want to now, I want to say attach.
What was the process ID was
16441.
That says could not attach to program.
So, what you have to do is I have to on my system, I have to
manifest this call. Yeah.
So if you put put nuts two bolts you could see right the actual bits of anything correct, a naughty, smart and you can't actually do it directly from see you can only do it if you use using inline assembler you can do anything.
Using see you can't
This error is not true. So this error is not about talking about compiler with dash gi did compiler gosh gene. That's not the issue here, if I want to debug this process. I need to actually do.
I mean up separate shelves becoming root and the command I'm running is I echoing.
A one, two, rock, Sis, Colonel Yama ping trace.
So I'll just show you I did.
This is literally what I just didn't want to do it in Emacs but it might have shown my wife things but this is what I typed.
So, since I've done that now I should be able to
work.
Echo zero.
No. Now,
there we go. You have to echo zero or two that
make this echo zero
router yeah sorry I was honestly I was typing it into one so now I have this.
Yeah, sorry I was obviously I was typing it into one so now I have this. I have GDP here. Now one cool thing I can do now is I can do.
So notice, I'm going to say now if I type something in here and I type in LS.
It's not doing anything because it's actually frozen, so I've just had to continue here.
Actually no, I want to say.
So if I, if I say continue the program will keep running, but I needed to break on something.
So
let's break I we've already there let's break on
run program.
So we're going to say, right.
Run program.
So now I've got a break but I run program, and I can say continue.
And now we'll break.
So now I process some data here.
Now let's.
So now I can actually watch the program as it runs.
What is to try text user interface.
So this is saying GDP has Emacs actually has a very nice, also interface. And so now you can go through things like this, there we go so I'm making it one window.
So this is why I say login into two things and run it separately in one, you can run this and now you can actually walk through it.
And then
where is my cheat sheet. I want to go to.
Let's go. I'm working on another window right now bring up my tutorial, three, I gave myself some quick start.
I have none of our professors told me about this.
Oh yeah and then you can also do catch this call.
And then we can say continue.
So now it's it's catching on Cisco and you say continue. Okay wait for catch on right
back trace.
Say.
Very good.
Next statements.
Oh.
Remember how to you absolutely can get it to walk through the assembly code.
I'm forgetting how to do that.
Okay.
What is a modern it you have extra
modern ideas have definitely.
That's what we want.
It's waiting on this.
Okay, there we go.
So it stop there for read.
Oh, we're so you notice right here we're saying no source available.
Let's break on.
We're not getting a very good look at how this thing is running.
So we want to let's break
broke loose.
personally personal orgs prompt on that.
There we go.
That's a little more, that's a little nicer, and we can say,
go here we can step through it line by line, and we can actually examine
yeah there's there's all kinds of things here, I'll show you a more detailed
GDP is definitely the OpenStack instance.
So,
where the blue and black and dress. So, the blue is an actual address.
That's in memory where it is and this is the value in memory so x is an argument so
Argh subzero.
As you can see what that is, let's see let's check what's another variable that would be actually useful.
Hi has been optimized out.
Okay, so you can't do a do that in syntax for.
Oh,
Wait a second. Oh, that's why I haven't actually.
Okay.
That's what I want to print. That's command.
Brent.
So it's been optimized out.
Well, That's no.
So.
Oh, thank you. That's where I was, oh,
that was a command.
I need to put that I need to add that to my cheat sheet. Because now you can actually do
you actually step and walk through the assembly
layout source
next year.
What's the way to get back to the source, yeah.
Sorry, in tutorial for Do we have to use the remote server thing we set up at the beginning, or other user operation still work on any other it.
A
ou you really will effort for tutorial for you really want to have some terminal level access.
You got us. Yes.
Thank you.
There we go.
Continue. It's a run program and notice it gives you the light, what all the arguments were to the program it tells you this, this is that
a.
You really don't want to be using virtual box.
You want to be using the VM I supplied on OpenStack. And the reason why is, it's got some fun things in it, in particular. So up until the midterm.
You can probably get away without it.
But once passed the midterm.
You really don't.
And part of the reason why I don't give out an OpenStack and the Virtual Box images because I want you to learn how to use cloud resources. This is how you do things if you're working on AWS, or you're working on Azure or something, it's a very similar
kind of workflow. So, I want you to play with that so you should use your VM that you created an OpenStack.
And also, I've configured it very specially so it's not a standard Ubuntu image, there's some things starting after the midterm that you will, that will be there and if you install it on a regular machine it's a bit of a pain.
That's what yeah when you use sh that that that is true. That is very true when you if you're using sh always work on someone else's computer, or at least a different computer.
I don't expect what I did here with with GDP to be very clear, using something like GDP is,
the more you use it like I was rusty I was forgetting commands and stuff.
Look it up. There's a lot of things on how to use TTP and stuff but I'm saying there's cool stuff here you can walk through the source by the way you want the dash g option so you can see the source, that's what allows it to do this.
Otherwise if you don't have Dasha can't follow you along like this.
Um, I don't have a lot more time left I have about 10 more minutes. Oh.
Yeah, exactly.
Yes.
Let's kill that kill the terminal.
Um, I want to do is go back to back the web browser here.
Um, so we're right now on.
Technically I should have already finished covering tutorial three and I have covered with enough, and not really covered file descriptors, so
let's talk about file descriptors, And then I'll end up for that got a little behind here. And then on Tuesday, we'll start talking about new ideas and gi demons and all that stuff.
So when you're looking at a
when you when you're talking about a program here that does print off printout goes to.
think we're lecture seven
word one solutions.
So there's this concept and C of standard in standard out standard error.
That's what the, that's what you do print.
So you look at print fuc that printouts when you do f print up, it takes, actually, a file stream. That's the data structure it takes this is a see concept.
This is cross platform so it works on different platforms, you know, different things. But what is that in a file stream is not a concept from.
on Unix we have file descriptors, which are.
So these are small numbers associated with open files.
So if you look at like the open functions. These are the system calls for open, they return it.
that they return is a file descriptor.
And then if you look at.
And then if we look at.
If you look at read the Read and Write system calls, take an integer, of a file descriptor. So you do an open the open returns a small number, and that number is what you then use for beating right.
And then if you do
the closed system call again takes a file descriptor. To close.
So what I mean by file pointer.
If you look here at math print FF print out takes a file pointer.
As an argument.
That's what I'm referring to.
So that's, that's pretty tough. That's tough pretty tough, but you.
So, we are so.
So, alright so.
So these are.
So, when you're working in with with when you're writing a program and Unix you standard and standard standard error, you're using these file descriptors, the convention is is that those have been opened.
So before you do it exactly often after the fork, you set up the standard in standard out standard error to point to where you want. Now, if you don't do anything.
This is a weird little thing about Unix, is that when you do it exactly memory gets PR, everything's thrown away, except what's included in the executive, a statement that you know environment variables and the command line arguments.
But open files stay open.
You could think of a system where everything was closed when you, when you do an executive, but no by convention they all stay open. So, the program has access to all of those things.
But is there a maximum there.
So, so, so what does it mean when people say everything in Linux is a file descriptor.
We'll continue talking about this on Tuesday, but it means that you access most things even.
So this is concept of device files TTY know, etc.
Special files.
You are exactly so redirecting output to a file means putting standard out to a specific file. That's exactly it, you just are opening that file on that file descriptor.
And so you.
So there's this dude to call if you look it up that you are basically you open it on another call script and move it.
We're out of time.
A character files are type of special file.
So it's definitely relevant.
Anyway, I will stop here, and good luck with the tutorial three and tutorial for and assignment to will be posted with next day I already have the code for it I just have to finish making up the questions.
Have a good day.