添加系统调用实验报告_第1页
添加系统调用实验报告_第2页
添加系统调用实验报告_第3页
添加系统调用实验报告_第4页
添加系统调用实验报告_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、v1.0可编辑可修改、构建基本的实验环境基本实验环境与前提条件Windows7、Word2010、VmwareWorkstation、AdobeReaderReadHatLinux,gcc,vi将Linux内核源代码及配置文件传送给虚拟机上的RedHatLinux系统配置网络时遇到这个问题,rooig'locaUiost:-日肚EdkV.l«wTermlrulGoHlpLtooT&Ioc3LhostrootJservicenetworkrestartShuttuiEdownloopbackintertace:IUhJSettingnetworkpaLramQtQrs:

2、UKBringin-gupluupbdck.luterlacu:OKBEJdiiRjiigupIn虹f&ethiQ:Delyrrnining.IPinfoniatlunfurethO.fdjled;n.ulinkpresent.CtiEcrk匚ablt!?1FWLEDJ口心工口|百hm与t=白口七1#DeterminingIPinformationforeth0failed;nolinkpresent.Checkcable通过查找资料发现是系统的Bug,解决方法如下:至U/etc/sysconfig/network-scripts/ifcfg-eth。在文件最后一行中加入11v1.0可

3、编辑可修改check_link_down()return1;文件,则同另夕卜如果存在/etc/sysconfig/networking/profiles/default/ifcfg-eth0样在其中加入这一段东西即可,然后重启系统。23设置网络为DHCP重新启动就可以,啦,直接上图'irwi修iHiUH.thfl"buH-vdWrirvidtvsrtariiH,最后将内核代码下载到/root目录下、Linux内核编译、配置与调试内核配置与编译、解压内核源代码文件v1.0可编辑可修改33tar-zxf、解压后如下拷贝linux,命名为-rlinux 1-V ;> L J

4、*. b !U1a 4 H_ -k !S-X !M! 3. I -L ro3t(53cnlhoat root t cp rootlaccilhoBt root! anaconda-ks-cfg Lunfi-2.4.18 far MP.txt Jiislall. lug install.13g.svslog linaxrootlocalhosr rootl# mv confi£-2.4.18 for-rlinuxlinux2.4,101inus-2.4.18l.imiJL-2.L8.Ldi.gzLinuxkernelCGditiit.tk)cvwwarelodIs-a.B,z-590Z

5、12.tar.gzvimvare-TDOls-distrib、移动到根目录,替换掉.configMP.txt./linux-2.4.18/.configrooWlocalhostraotj#cdlinux-2-4.18/rooWlocalhostlinux-2.4.18IsatxhDv<uncailunii心u加kernelMakefileREADMEscriptsCOPYINGdriversinitlibmrREPORTING-BUGSCREDITSfsipcr(»tlocalho8tlinux-2.4.181#AINIAINERS11.confignetRules.makg

6、-rw-r一一r-1rootrootrnotelocalhostlinux-2B4.18#13850Ocl1321:45config、进入目录,配置和编译内核模块makeoldconfigv1.0可编辑可修改Kerneldebugging(COKF1GJ)E8UG_KERNEL)Y/n/?Debughighremarvsupport(COMFIG_PEBUG_HIGFMEM)N/y/?!Debugmemoryillacations(COMFIGDEBUG_5LAB)Y/n/?lMemorynappedI/Odebugging(CONFIGJ)EBUG_IOVIRT)N/y/?Magic卯后Rq

7、keyCCONFIG_MAGIC_SYSRQ)Y/n/?Spinlockdebugging(CONF1G_DEBUG_SEINLOCKN/y/7VerboseHUG(Jrepoiting(adds7OKJ(CONFIG_DliBUG_BUGVEREQSE)¥/n/?J*EndufLinuxkernelcunflgurdtlon.4*rCJltftkLhetup-levtilMdkefilefurddJitiotldlCUitriglU'dtlull.*Next,yaumustrunKmakedep*.makedepI « P JlK/fircl"/i;iK

8、fi/nmrfovlt-fraiQ-pointermrch-iGBSbaund3ry=? , iiFErpp.r ,i Tint Man邓rSm up Mui mcrukor pditflibf- - ''i-k prropy.c m壮看江 巾口kEl;4.18/include -wall fno-strict-allaslRi - 而cksu限.5 decietuBer.S iodelMs期1ct-protoypes -wno-trierphs ftiQ-coniTQii -pipe -mpreferred st a c k-C arrh/T3flG/Hb fristdfpm

9、ake2j ; EnterinH dirFctory "/root /1 iinux-2.4.18/archB/lib /r oot /1 iiiu 2,4.18/ ser ipi:® /-D_KERKE1_ -l/root/linu2> HdpppndLeivinr ditory '/re/Iinux-2.4.18/Brch/i3耽/lib leaving directon1 '/root/linux-2.4* 18r/root/ 1 in UK-21, 4.1 a/scripts/rikdp -D_ KFRKEL-T /ron t/1 j tiux

10、- 2.418/i.nc liide -Wh I L-strictpretijtypes1rifiraphs -02 -foqiit-fra«ie-pointer fno-strict-aliasing-fttQ-cooQJi -pipe -wreferred-slack-boundarv=2 -Mrch=ieafi - extble.c fault c init,c ioreuapBc > ,depend inalsel?1: Lpving direrrnry /roDt/liniEXmx.c oltf-checksuTi-c strstTUV a sus . c prorp

11、fis . c ptrace nemeiphare. c setup. r signal . r ismboo 5+c iwe.c trinpollne.s traps -c "l写ks_apf<c wrnse.c > .depend mmkelZl; Leavine dir c*c Tory " /ro t/I iniix - a. 4 - is/irch / i 386 /kern c 1 muke -c arch/i3B6/mr fatdep mflkeI2: Rntpring diTprtory '/r/inux-2.4,18/arch/138A

12、/mflpm工乂曾 up-date wxlverfilcmalkel: Entering diTectofry '/rrsot/liTiiux-Z,4,18*/rwt/linux-Zu 4.1 R/iiiirliid/ Hnux/miartvprsiioni-h updated 印心餐口: IiPvinR directory Vroot/liniBX-2.4.181|rrooiiDlocaho£t IIiiuk-2.4.ispud hu±L; -/H n UKt241ArocVglocaMMEL-ainl J ” nut g ka 匚/host -/&!Do

13、wnloid unri四流C Fr1 8 * 3 J: H AMmake cleanmake bzImage#v1.0可编辑可修改objeopv-0binary-R.note-Rrcomment-Scompressd/bvinliniaxcompresspd/bvmlinux.cuttools/buildbbootsectbsetupcompressed/tviilinux+ouTCURRENT>t>zImageRootdeviceis乩3)Boatsector512bytes.setupisZ52Kbytes.Systemis645kB1:Leavingdir#ctary'

14、;/root/limiK-I.4.18/arch/i386/baot1h'UULlULdlllUb1llnux'2.4.18pIsarchdriversipcMakefileREP0RT1MG-BUGSCOPYINGfskprriplmmRljp<iemakpCREDITSincludelibnetscriptsDocumentationinitlAISTAIMEftSREADMESystem.maprootlocalhostllnux-2.4.IS#vmlinuxIrooteiocaJJuostbootJffIsbboot5ectbbootsect.sb5etupbse

15、tup.scompressedMakefiletoolsbbootsect.0bootsect.sbsetup.oPhzlnagGinstall.ghsetup.svid-eo.sfr00tolacalho£tboot11bzlna,-rw-r一一r1rootroot63034oct4oo:22teLinagefe00tLocalhostbootiffl/lrgt,Unujc*2卧Q+18/ai:di,iMGe/bootKoctQlocalho£tbciotmakemodules内核安装与测试安装内核映像文件cparch/i386/boot/bzImage/boot/55-

16、_m£)f£_dir里>?*Lenrrn40口匕口lif?.4.18;声rp;trrh/i3ftfi/txHJT/yizTriagp/boot/vrlinux-?.4.1SIrnnTloralhnsTrrwiQlocalhjistboot.bchair.blinux-3.4.UIn/bnntihitr<3-2rT.2O-®Srp.IhlQtl&dk*le-illfO-2.4.2C-SrDnfig-?.4.cunfiH-2,4.2卜取叩iniird.?o-s,imgkcrneLhInT+fniir1m骷晔,anoduleinfonoduleinf

17、Q-5snipns2,.d,b3V屏twe-napSvSttuHtldp-2,4.203systeurnap-ind,2Q-65npvmlinux-2,ISvmLinuxBvmLinux-2.4.20-9supvuilinuzvmlinuzsVfflLinUZB>np拷贝和安装Linux系统映射文件,并创建其与系统映射文件之间的符号链接v1.0可编辑可修改#执行命令makemodules_install以安装可动态加载的内核模块roote oral fiost 2.4.19.* Ifb. j .moctult!5.gtneric_STringksrtielmu du 1 es-. dep

18、aoduljefl. parpartmap nodules. ua bnap nodLLLc.pcinip pencilEdu Ltd s. u np b i u bind pLrootioca Lhast 2.4rl&J# pwd/Jlb/nodulM/2.4.1Aphm Manager_LuoL!flli>CdlliGtt 2.4.18_Set .jp and nmrmrprlnfer'inciules.ieeeijyiEi添加启动项的配置利用Vi编辑器,vi查看/所在的位置,为/dev/sda3Used AvailebLe Mounted cm3G1177G4170

19、184 47% /Lfoot®iocaihostFilesystpri/deV/sdalLtuuLfilu匚alihustrootledt/IK-blocks9206944root*v1.0可编辑可修改77重新启动系统,从自己创建的内核启动系统启动后查看内核分另1J用unamer,和dmesg查看v1.0可编辑可修改FieEditV.lewGcHelp(rootPlotaliitjfitrootIffUiurti-r2.4.18rantjlhu&lrudlclnvsgLinuxversion(roojtLocaItiost,1ocaLdominJ(eccversion3.2.

20、?200302?(liedHitLinux3.7.2511*1FtiOctCXJ:21:4<ICffI2013三、Linux系统调用添加与实现在内核增加系统调用结构体structsrz_rusage可声明如下:structsrz_rusagestructtimevalru_utime;/*usertimeused*/structtimevalru_stime;/*systemtimeused*/longru_majflt;/*majorpagefaults*/longru_minflt;/*minorpagefaults*/longru_nswap;/*swaps*/;添加到下的中rru

21、ctsrz_rusagestructtimevalru_utime;stnicrtimevalru_stirne;lung;lonoru_ninfIt;ionpru.nswap;添加的系统调用名称为:intget_process_usage(pid_t,structsrz_rusage*);参考的getrusage和sys_getrusage的代码在下面分析getrusage()和sys_getrusage()的源代码1)数据Z构rusage在头文件中定义。structrusagestructtimevalru_utime;/*usertimeused*/#v1.0可编辑可修改struct t

22、imeval ru_stime;longru_maxrss;longru_ixrss;longru_idrss;longru_isrss;longru_minflt;longru_majflt;longru_nswap;longru_inblock;longru_oublock;longru_msgsnd;longru_msgrcv;longru_nsignals;longru_nvcsw;longru_nivcsw;;2)函数 getrusage()/*/ It would make sense to put struct rusage in the task_struct,* except

23、 that would make the task_struct be *really big*. After* task_struct gets moved into malloc'ed memory, it would* make sense to do this. It will make moving the rest of the information* a lot simpler! (Which we're not doing right now because we're not* measuring them yet).* This is SMP sa

24、fe. Either we are called from sys_getrusage on ourselvessystemtimeused*/*maximumresidentsetsize*/*integralsharedmemorysize*/*integralunshareddatasize*/*integralunsharedstacksize*/*pagereclaims*/*pagefaults*/*swaps*/*blockinputoperations*/*blockoutputoperations*/*messagessent*/*messagesreceived*/*sig

25、nalsreceived*/*voluntarycontextswitches*/的作用是获取系统资源使用情况。/*involuntary"*/99v1.0可编辑可修改* below(weknowwearen'tgoingtoexit/disappearandonlywechangeour* rusagecounters),orwearecalledfromwait4()onaprocesswhichis* eitherstoppedorzombied.Inthezombiedcasethetaskwon'tget* reapedtillshortlyafterthe

26、calltogetrusage(),inbothcasesthe* taskbeingexaminedisinafrozenstatesothecounterswon'tchange.* FIXME!Getthefaultcountsproperly!*/intgetrusage(structtask_struct*p,intwho,structrusage*ru)structrusager;memset(char*)&r,0,sizeof(r);switch(who)caseRUSAGE_SELF:=CT_TO_SECS(p->=CT_TO_USECS(p->=C

27、T_TO_SECS(p->=CT_TO_USECS(p->=p->min_flt;=p->maj_flt;=p->nswap;break;caseRUSAGE_CHILDREN:=CT_TO_SECS(p->=CT_TO_USECS(p->#v1.0可编辑可修改=CT_TO_SECS(p->=CT_TO_USECS(p->=p->cmin_flt;=p->cmaj_flt;=p->cnswap;break;default:=CT_TO_SECS(p->+p->=CT_TO_USECS(p->+p->

28、=CT_TO_SECS(p->+p->=CT_TO_USECS(p->+p->=p->min_flt+p->cmin_flt;=p->maj_flt+p->cmaj_flt;=p->nswap+p->cnswap;break;returncopy_to_user(ru,&r,sizeof(r)-EFAULT:0;3)sys_getrusage()只是调用了内核函数getrusage(),是内核提供给用户的接口。asmlinkagelongsysgetUSage(intwho,structrusage*ru)if(who!=RU

29、SAGE_SELF&&who!=RUSAGE_CHILDREN)return-EINVAL;returngetrusage(current,who,ru);1111v1.0可编辑可修改编写应用程序调用该系统(调用)过程在中添力口函数get_process_usage()和系统调用函数sys_get_process_usage()的代码;目录intget_process_usage(structtask_struct*p,structsrz_rusage*ru)structsrz_rusager;memset(char*)&r,0,sizeof(r);TFSO-一一曷孑J

30、define_NR_-J1.d.J二getxattr二W3229_NR_leExaECr230fgetxatcx232_NR_lisuxaEur232tdefineNR二二二six己二tr233define_NR_fliarxattr23defxne_NR_reiECvexatti:;35*define_NRIrejT.ovexattr236#detuneNRfren.ovexauur237#v1.0可编辑可修改#define._瓯.getxattr229define_NR._lgetatrr230idefine_阪_fgetxatrr231define_-listxatrr232define

31、_NR_liistKattr233考defitiw._瓯_flistxattr234_NR._rmove-xattr235define_-NR,_lremovexattr236define_皿_fremovxattr237define_NK_gei_process_usage238ongSYMBOL_NAME()的清单,该清单用来对sys_call_table口数组进行初始化,该数组包含指向内核中每个系统调用的指针。我们在清单最后添加一行:.longSYMBOL_NAME(sys_get_process_usage)sitingSYMBCL_NAME.(sys_ni_sysoall/*23Cr

32、eserved皿皿淑松I-/63。.longSYMBOL_NAME.(sysni_syscall)/*reservedfor团鼠蹑7631s.longSYHBOL_NAME(sysni.syscall)/xreservec.fdi每32.long3YM5OL_NAME(3工_3工)/*reserved£oxg33.long5YMBOL_NAME(sy3_ni_3y3call>/*zcaerQGfor34.longSYMBOL_NAME(8ys_nx_Byeeall/*23Sreserved堂口发黑驶侬猿曷黑宓:.635,IonaSYMBOL_NAME(sys_nl_vscall

33、J7*reservedfor工X觊。灵兔麻匚工”,36salong5YlaI3CLNAME(sysn±sysca.ll)/*reservedfQrf二之耳二友之及司工*二637388NR_sy3calla-ayB_call_tak;le)/A,1ongSYM30L_NAME|sys_ni_sy-callj.1口Kg.i'L一zy<_r-;_:,=(!)/*225*/.long'1b_L_NAr«u(,:._r.i_=yi.izall)产reservedforseta":tr餐,.Icing-.xT-:I.-m-(t;_r7_-y-:-:)/*

34、reservedforISPtYJtTT=$lnr-SSYWBOJNAME(qyS_ni_Ey£8:L1)/*forfHArkarir7-Ions口'1'J.-rH!)/*rFSrvclfur卜.户1lr1F*fhlungSYMSOUMMECsysj)i_syscall)/*230w.、rdfurL,Uidt11*/.long5YK30LJ4AMEsys_ni_syscall)/*reservedfOTfgetxattr*/.lar.fi5¥M3Cl_J4AME(sy_jiijyacall)/reservedforlistxdttr*/.LorKSYNBOL

35、_HMtE(bvs_Jii_syscall)/*reservedforlllstxattr*/.1岫咨SYMBOL_NAN_(sys_ni_Syscal1)Areserved±orflistxattr*/JongSYME3L_NAME(Gys_ni,syscal1)产235reservedtorrencv&xattr*ior:gS¥MBOLJ4AM£(syg_n±_gyEcall)/*reiserveciforIreTKZivexJttrInrnA'rMKIrr7U-F3111/*forTr-二旷讣*/.lung匕"I_priM

36、比,-INSERT1313v1.0可编辑可修改编译安装内核以后的启动界面出bvuL=/dwWbduJefiihlt=OCiHeOUt=lD5plashiinage-(hdo3廿l/grub/spl-ash,xprn.gztitleMIL2.4.16-etztcHjt(hdtO90)kern总1/'nllnux-2.4«18-sriiroe口口t=,d&v/xddLmtitleRedHatLinuxz.-l.Ltflabroot(hdO.O)kerne1/iti1inux-2.4.ISrorooT=/dev/sda3titleRdHatLinux(2=4.20-8snp

37、)root(hi43pCi)kernel/vi1inuz-z.a.20-roroot=lABEL=jrhdc=lde-scsiinitrdl/mitrd-2.4.20-esnp.ingtitleRedHat'LiTiux-up(2.4.20-BJroot(hdOa0)keriiel/v11Ifiuz-2_4.20-sroroot-LAHEL=/hde-ide-scsl#262-9Hot;10jmQpmg1flecgWntuipgrub,conf'126wordiprocessorfooilocajho&tHiiK-z.4J.rz/kerndQfoottocahost.h

38、oougnjbOsacOctos723PM四、编写程序调用新的系统调用程序一头文件testsyscallpid_no执行结果v1.0可编辑可修改1515Dmesg查看信息v1.0可编辑可修改#程序二testsyscallpid_nov1.0可编辑可修改£ileyiewJjermlnalgoHelpo&tQlochrfloc-jtestssceetpv_syscall2.crootlocalhostroot#./testsyscall21S05IShangRangZhuSuccessfUsertime:Oseconds:640000msecondsISystem_time:口seconds;200000msecondsMinlostpages:1102Maxlostpage:2148Changepagetines:0rooteiocalhostrootdmesg查看1717v1.0可编辑可修改1818附件:源程序一:第一种实现方法/#include</root/</root/源程序v1.0可编辑可修改/

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论