‫Hello and welcome, everybody, and in this lecture, we are going to implement free, so you will notice
‫in the last lecture we implemented the labor free function, but it doesn't do anything.
‫Well, unless lecture, we're going to make a purchase free function and we're also going to make the
‫colonel command for free.
‫So we'll start with the colonel command, go to keep see and we're just going to go void ISI d.H Command
‫five free struct intraplate, OK?
‫And it's going to accept appointed a free ride.
‫So we're going to go right point to free equals tasks.
‫Get stack idam tasks current zero.
‫OK, and now we're just going to go return zero here and we're going to go process free pointed to free
‫and we haven't created that yet and we're just going to go test current process.
‫So there we are.
‫So that's how that should look.
‫OK, and we're going to create the process free function shortly.
‫Now just go to ISI to start Hajj and we're going to create a new system command system command five
‫three.
‫We're going to go to ISI to start see and we're going to go ISI, the Hajj Register Command System Command
‫five free ISI, Hajj, Command five.
‫Free, OK?
‫And we just need to put that in the header file as well, guys, a copy and paste society hageman free
‫into a heap page.
‫OK, so that sets up the command.
‫We now need to create the actual process free function.
‫So to set up the process free function, lets go to task and process.
‫Start just in the process.
‫Mallak, we're going to go avoid process free struct process process void's pointer.
‫OK, and this is the point of the free so we can't just go free on the pointer because the pointer might
‫not belong to us.
‫It might have been some other memory that created that, OK, some of the process or something.
‫And for security reasons we can't just free that.
‫It could even be a kernel pointer, one that doesn't belong to us.
‫So because of this, we're going to actually create a function that will check if we can access that
‫pointer or not.
‫Static bool.
‫Process is our pintor.
‫Or is this point to, I should say?
‫Process is a process pointer to process process, void pointer, and all of this does is it'll go through
‫all of the allocations, OK?
‫And it will essentially say if the process allocation is equal to pointer, then return true, otherwise
‫will return false down here.
‫OK, and we're going to have to scroll up and include SAGD Ball as well, guys.
‫So just by here, we're going to go include acidy ball dot org and we should probably put that in the
‫header file actually.
‫So just copy and paste that and we're going to put that in post to start here and we'll just pasted
‫here.
‫And if I'm going to wait for you, just pause the video guys to catch up.
‫You don't have to go at my pace.
‫I'm just trying to cover this for everybody at a reasonable pace.
‫So if we scroll down here
‫to where is it now?
‫Search for OK, our processes process pointer.
‫OK, so yeah, we can now check if this is our pointer or not and then we'll know if we can continue.
‫So all we're going to say is if process is process pointer process pointer.
‫OK, we're going to put an asterisk there, non asterisk exclamation mark.
‫I mean we're basically saying if the process pointer is not part, it's not for this process, then
‫we can't do anything.
‫That's basically what we're saying here.
‫OK, so what we're now going to say is, is just return.
‫We can't do anything because it's not our pointer.
‫OK, so that that that solves that problem.
‫We now need to loop through the applications and basically free it.
‫OK, so what we can do is we can make another function here, a static void process, mark as mark allocation.
‫Then we can say enjoin allocation or allocation and join.
‫Sounds much better.
‫Right.
‫And we're going to pass the process here.
‫We're going to pass the void pointer and I will join it from the actual allocations table.
‫So we're going to loop through them again.
‫And we're going to say if the process allocations is equal to appointer, then process allocation is
‫equal to now.
‫So we basically enjoin it from the allocation so it no longer associates the allocation with that process.
‫So when I was going to say process allocation and join a process pointer.
‫And then finally free the memory.
‫OK, and it's as simple as that, and that does the job, so just copy and paste process free here now
‫and we're going to put that in process to the Hajj just under the process Malac.
‫OK, and we're ready to now build this and see if that works.
‫So we're just going to go make clean build that, S.H..
‫I can see that Bill's perfectly fine.
‫OK, so we now have come on five free.
‫OK, so now let's go to our use of land labor and we're going to write a routine for this.
‫So go to WDM and we're just going to say Peatross free and we're going to push the base point to move
‫the base and move the stack point to the base.
‫Point up, we're going to Select Command five.
‫We're going to push.
‫The point is a free.
‫We're going to call the colonel.
‫We're going to adjust the stack pointer by four bytes to restore the stack pointer, and I pop the base
‫point and return from the routine analysis just to comment to say what it is.
‫Void Peatross free void pointer.
‫OK, now let's just scroll up and we're going to export this global picture as free and that's a function.
‫Scroll back down, copy and paste this comment that we made and we're going to put that as the prototype
‫and features like that.
‫And there we go.
‫Now we have PTW Malcolm Peatross, free pause the video if you need.
‫That's how the assembly code should look for Peatross free.
‫OK, that's how it should look just like that.
‫So that's one thing I will say impetuousness.
‫DSM, we're not using the same section here.
‫We probably should be.
‫So we're not going to do anything for now, but we might have to set section to ask them later on if
‫these become unaligned.
‫But for now it'll be OK.
‫You know what?
‫Actually, let's try and set that to S.A.M. just to see if everything works is expected once we do that.
‫So just do that and rebuild that and we're just going to run that again.
‫Ah, we can see it still works, OK?
‫Yes, no problem.
‫So just use S.A.M. because there is a there can be alignment issues, as I've already explained before.
‫So just use section that SMPTE lsm.
‫OK, I will be ready to continue to ask Philip, see.
‫And we're just going to go purchase free and we're going to pass in the pointer, OK.
‫And now if you go to Planktos C, we should be able to now say free pointer and it should work like
‫that without any problems.
‫So let's just make clean and build that S.H..
‫And we're going to run that stop typing and yeah, we can see that the program didn't crash or anything,
‫I'm pretty sure free and mallock work perfectly now, OK.
‫So, yeah, thanks for watching this lecture.
‫We have now implemented both Free and Mallak.
‫Have a great day.