Information Technology Reference
In-Depth Information
intKernelStub_Open(){
char*localCopy[MaxFileNameSize+1];
//checkthatstackpointerisvalidandthatargumentsarestoredatvalidaddresses
if(!validUserAddressRange(userStackPointer,userStackPointer+sizeofargumentsonstack))
returnerror_code;
//fetchpointertofilenamefromuserstack,andconverttoakernelpointer
filename=VirtualToKernel(userStackPointer);
//makealocalcopyofthefilename,insidetheOS
//thispreventstheapplicationfromchangingthename
//surreptitiously,afterthecheck,butbeforetheread!
//thestringcopyneedstocheckeachaddressinthestringbeforeuse
//tomakesureeveryaddressinthestringisvalid
//thestringcopyterminatesafteritcopiesMaxFileNameSize
//toensurewedon'toverwriteourinternalbuffer
if(!VirtualToKernelStringCopy(filename,localCopy,MaxFileNameSize))
returnerror_code;
//let'smakesureourlocalcopyisnullterminated
localCopy[MaxFileNameSize]=0;
//wecannowcheckiftheuserispermittedtoaccessthisfile
if(!UserFileAccessPermitted(localCopy,current_process)
returnerror_code;
//finallywecancalltheactualroutinetoopenthefile
//thisreturnsafilehandleonsuccess,oranerror_codeonfailure
returnKernel_Open(localCopy);
}
Figure2.14: Stub routine for the open system call inside the kernel
start(arg1,arg2){
main(arg1,arg2); //calluser'smain
exit();
//ifmainreturns,callexit
}
Search WWH ::




Custom Search