µ±Ç°Î»ÖãºLinux½Ì³Ì - Linux×ÛºÏ - ϵͳµ÷ÓøúÎÒѧ(1)

ϵͳµ÷ÓøúÎÒѧ(1)

¡¡¡¡±¾ÎÄÊÇLinuxϵͳµ÷ÓÃרÀ¸ÏµÁÐÎÄÕµĵÚһƪ£¬¶ÔLinuxϵͳµ÷ÓõĶ¨Òå¡¢»ù±¾Ô­Àí¡¢Ê¹Ó÷½·¨ºÍ×¢ÒâÊÂÏî´ó¸Å×÷ÁËÒ»¸ö½éÉÜ£¬ÒÔ±ã¶ÁÕ߶ÔLinuxϵͳµ÷Óý¨Á¢Ò»¸ö´óÖµÄÓ¡Ïó¡£ 1¡¢Ê²Ã´ÊÇϵͳµ÷Óã¿ LinuxÄÚºËÖÐÉèÖÃÁËÒ»×éÓÃÓÚʵÏÖ¸÷ÖÖϵͳ¹¦ÄܵÄ×Ó³ÌÐò£¬³ÆΪϵͳµ÷Óá£Óû§¿ÉÒÔͨ¹ýϵͳµ÷ÓÃÃüÁîÔÚ×Ô¼ºµÄÓ¦ÓóÌÐòÖе÷ÓÃËüÃÇ¡£´ÓijÖֽǶÈÀ´¿´£¬ÏµÍ³µ÷ÓúÍÆÕͨµÄº¯Êýµ÷Ó÷dz£ÏàËÆ¡£Çø±ð½ö½öÔÚÓÚ£¬ÏµÍ³µ÷ÓÃÓɲÙ×÷ϵͳºËÐÄÌṩ£¬ÔËÐÐÓÚºËÐÄ̬£»¶øÆÕͨµÄº¯Êýµ÷ÓÃÓɺ¯Êý¿â»òÓû§×Ô¼ºÌṩ£¬ÔËÐÐÓÚÓû§Ì¬¡£¶þÕßÔÚʹÓ÷½Ê½ÉÏÒ²ÓÐÏàËÆÖ®´¦£¬ÔÚÏÂÃ潫»áÌáµ½¡£ ËæLinuxºËÐÄ»¹ÌṩÁËһЩCÓïÑÔº¯Êý¿â£¬ÕâЩ¿â¶Ôϵͳµ÷ÓýøÐÐÁËһЩ°ü×°ºÍÀ©Õ¹£¬ÒòΪÕâЩ¿âº¯ÊýÓëϵͳµ÷ÓõĹØϵ·Ç³£½ôÃÜ£¬ËùÒÔÏ°¹ßÉÏ°ÑÕâЩº¯ÊýÒ²³ÆΪϵͳµ÷Óᣠ2¡¢LinuxÖй²ÓжàÉÙ¸öϵͳµ÷Óã¿ Õâ¸öÎÊÌâ¿É²»Ì«ºÃ»Ø´ð£¬¾ÍËãÈÃLinus Torvaldz±¾ÈËÒ²²»¼ûµÃÒ»ÏÂ×Ó¾ÍÄÜ˵Çå³þ¡£ ÔÚ2.4.4°æÄÚºËÖУ¬ÏÁÒåÉϵÄϵͳµ÷Óù²ÓÐ221¸ö£¬Äã¿ÉÒÔÔÚ<ÄÚºËÔ´ÂëĿ¼>/include/asm-i386/unistd.hÖÐÕÒµ½ËüÃǵÄÔ­±¾£¬Ò²¿ÉÒÔͨ¹ýÃüÁî"man 2 syscalls"²ì¿´ËüÃǵÄĿ¼£¨man pagesµÄ°æ±¾Ò»°ã±È½ÏÀÏ£¬¿ÉÄÜÓкܶà×îеĵ÷Óö¼Ã»Óаüº¬ÔÚÄÚ£©¡£¹ãÒåÉϵÄϵͳµ÷Óã¬Ò²¾ÍÊÇÒԿ⺯ÊýµÄÐÎʽʵÏÖµÄÄÇЩ£¬ËüÃǵĸöÊý´ÓÀ´Ã»ÓÐÈËͳ¼Æ¹ý£¬ÕâÊÇÒ»¼þ³ÔÁ¦²»ÌֺõĻÐÂÄں˲»¶ÏµØÔÚÍƳö£¬Ã¿Ò»¸öÐÂÄÚºËÖк¯ÊýÊýÄ¿µÄ±ä»¯¸ù±¾¾ÍûÓÐÈËÔÚºõ£¬ÖÁÉÙÁ¬Äں˵ÄÐÞ¸ÄÕß±¾È˶¼²»ÔÚºõ£¬ÒòΪËûÃÇ´ÓÀ´Ã»Óз¢²¼¹ýÒ»¸ö´ËÀàµÄÉùÃ÷¡£ Ëæ±¾ÎÄÒ»ÆðÓÐÒ»·Ý¾­¹ýÕûÀíµÄÁÐ±í£¬Ëü²»¿ÉÄܷdz£È«Ã棬µ«³£¼ûµÄϵͳµ÷Óûù±¾¶¼ÒѾ­°üº¬ÔÚÄÚ£¬ÄÇÀïÃæÖ»Ó⻶àµÄÒ»²¿·ÖÊÇÄãƽʱÓõõ½µÄ£¬±¾×¨À¸½«»áÓÐÑ¡ÔñµÄ¶ÔËüÃǽøÐнéÉÜ¡£ 3¡¢ÎªÊ²Ã´ÒªÓÃϵͳµ÷Óã¿ ʵ¼ÊÉÏ£¬ºÜ¶àÒѾ­±»ÎÒÃÇÏ°ÒÔΪ³£µÄCÓïÑÔ±ê×¼º¯Êý£¬ÔÚLinuxƽ̨ÉϵÄʵÏÖ¶¼ÊÇ¿¿ÏµÍ³µ÷ÓÃÍê³ÉµÄ£¬ËùÒÔÈç¹ûÏë¶Ôϵͳµ×²ãµÄÔ­Àí×÷ÉîÈëµÄÁ˽⣬ÕÆÎÕ¸÷ÖÖϵͳµ÷ÓÃÊdzõ²½µÄÒªÇó¡£½øÒ»²½£¬ÈôÏë³ÉΪһÃûLinuxϱà³Ì¸ßÊÖ£¬Ò²¾ÍÊÇÎÒÃdz£ËµµÄHacker£¬Æä±êÖ¾Ö®Ò»Ò²ÊÇÄܶԸ÷ÖÖϵͳµ÷ÓÃÓÐ͸³¹µÄÁ˽⡣ ¼´Ê¹³ýÈ¥ÉÏÃæµÄÔ­Òò£¬ÔÚƽ³£µÄ±à³ÌÖÐÄãÒ²»á·¢ÏÖ£¬ÔںܶàÇé¿öÏ£¬ÏµÍ³µ÷ÓÃÊÇʵÏÖÄãµÄÏë·¨µÄ¼ò½àÓÐЧµÄ;¾¶£¬ËùÒÔÓпÉÄܵĻ°Ó¦¸Ã¾¡Á¿¶àÕÆÎÕһЩϵͳµ÷Óã¬Õâ»á¶ÔÄãµÄ³ÌÐòÉè¼Æ¹ý³Ì´øÀ´ÒâÏë²»µ½µÄ°ïÖú¡£ 4¡¢ÏµÍ³µ÷ÓÃÊÇÔõô¹¤×÷µÄ£¿ Ò»°ãµÄ£¬½ø³ÌÊDz»ÄÜ·ÃÎÊÄں˵ġ£Ëü²»ÄÜ·ÃÎÊÄÚºËËùÕ¼ÄÚ´æ¿Õ¼äÒ²²»Äܵ÷ÓÃÄں˺¯Êý¡£CPUÓ²¼þ¾ö¶¨ÁËÕâЩ£¨Õâ¾ÍÊÇΪʲôËü±»³Æ×÷"±£»¤Ä£Ê½"£©¡£ÏµÍ³µ÷ÓÃÊÇÕâЩ¹æÔòµÄÒ»¸öÀýÍâ¡£ÆäÔ­ÀíÊǽø³ÌÏÈÓÃÊʵ±µÄÖµÌî³ä¼Ä´æÆ÷£¬È»ºóµ÷ÓÃÒ»¸öÌØÊâµÄÖ¸ÁÕâ¸öÖ¸Áî»áÌøµ½Ò»¸öÊÂÏȶ¨ÒåµÄÄÚºËÖеÄÒ»¸öλÖ㨵±È»£¬Õâ¸öλÖÃÊÇÓû§½ø³Ì¿É¶Áµ«ÊDz»¿ÉдµÄ£©¡£ÔÚIntel CPUÖУ¬Õâ¸öÓÉÖжÏ0x80ʵÏÖ¡£Ó²¼þÖªµÀÒ»µ©ÄãÌøµ½Õâ¸öλÖã¬Äã¾Í²»ÊÇÔÚÏÞÖÆģʽÏÂÔËÐеÄÓû§£¬¶øÊÇ×÷Ϊ²Ù×÷ϵͳµÄÄÚºË--ËùÒÔÄã¾Í¿ÉÒÔΪËùÓûΪ¡£ ½ø³Ì¿ÉÒÔÌøתµ½µÄÄÚºËλÖýÐ×ösysem_call¡£Õâ¸ö¹ý³Ì¼ì²éϵͳµ÷Óúţ¬Õâ¸öºÅÂë¸æËßÄں˽ø³ÌÇëÇóÄÄÖÖ·þÎñ¡£È»ºó£¬Ëü²é¿´ÏµÍ³µ÷Óñí(sys_call_table)ÕÒµ½Ëùµ÷ÓõÄÄں˺¯ÊýÈë¿ÚµØÖ·¡£½Ó×Å£¬¾Íµ÷Óú¯Êý£¬µÈ·µ»Øºó£¬×öһЩϵͳ¼ì²é£¬×îºó·µ»Øµ½½ø³Ì£¨»òµ½ÆäËû½ø³Ì£¬Èç¹ûÕâ¸ö½ø³Ìʱ¼äÓþ¡£©¡£Èç¹ûÄãÏ£Íû¶ÁÕâ¶Î´úÂ룬ËüÔÚ<ÄÚºËÔ´ÂëĿ¼>/kernel/entry.S£¬Entry(system_call)µÄÏÂÒ»ÐС£ 5¡¢ÈçºÎʹÓÃϵͳµ÷Óã¿ ÏÈÀ´¿´Ò»¸öÀý×Ó£º #include /*¶¨Òåºê_syscall1*/ #include /*¶¨ÒåÀàÐÍtime_t*/ _syscall1(time_t,time,time_t *,tloc) /*ºê£¬Õ¹¿ªºóµÃµ½time()º¯ÊýµÄÔ­ÐÍ*/ main() { time_t the_time; the_time=time((time_t *)0); /*µ÷ÓÃtimeϵͳµ÷ÓÃ*/ printf("The time is %ld\n",the_time); } ϵͳµ÷ÓÃtime·µ»Ø´Ó¸ñÁÖÄáÖÎʱ¼ä1970Äê1ÔÂ1ÈÕ0:00¿ªÊ¼µ½ÏÖÔÚµÄÃëÊý¡£ ÕâÊÇ×î±ê×¼µÄϵͳµ÷ÓõÄÐÎʽ£¬ºê_syscall1()Õ¹¿ªÀ´µÃµ½Ò»¸öº¯ÊýÔ­ÐÍ£¬ÉÔºóÎÒ»á×÷Ïêϸ½âÊÍ¡£µ«ÊÂʵÉÏ£¬Èç¹û°Ñ³ÌÐò¸Ä³ÉÏÂÃæµÄÑù×Ó£¬³ÌÐòÒ²¿ÉÒÔÔËÐеÃͬÑùµÄ½á¹û¡£ #include main() { time_t the_time; the_time=time((time_t *)0); /*µ÷ÓÃtimeϵͳµ÷ÓÃ*/ printf("The time is %ld\n",the_time); } ÕâÊÇÒòΪÔÚtime.hÖÐʵ¼ÊÉÏÒѾ­Óÿ⺯ÊýµÄÐÎʽʵÏÖÁËtimeÕâ¸öϵͳµ÷Óã¬ÌæÎÒÃÇÊ¡µôÁ˵÷ÓÃ_syscall1ºêÕ¹¿ªµÃµ½º¯ÊýÔ­ÐÍÕâÒ»²½¡£
[1] [2] [3] ÏÂÒ»Ò³ 

´ó¶àÊýϵͳµ÷Óö¼ÔÚ¸÷ÖÖCÓïÑÔº¯Êý¿âÖÐÓÐËùʵÏÖ£¬ËùÒÔÔÚÒ»°ãÇé¿öÏ£¬ÎÒÃǶ¼¿ÉÒÔÏñµ÷ÓÃÆÕͨµÄ¿âº¯ÊýÄÇÑùµ÷ÓÃϵͳµ÷Óã¬Ö»ÔÚ¼«¸ö±ðµÄÇé¿öÏ£¬ÎÒÃDzÅÓлú»áÓõ½_syscall*()Õ⼸¸öºê¡£ 6¡¢_syscall*()ÊÇʲô£¿ ÔÚunistd.hÀﶨÒåÁË7¸öºê£¬·Ö±ðÊÇ _syscall0(type,name) _syscall1(type,name,type1,arg1) _syscall2(type,name,type1,arg1,type2,arg2) _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) ËüÃÇ¿´ÆðÀ´Ëƺõ²»Ì«Ïñºê£¬µ«ÆäʵÖÊºÍ #define MAXSIZE 100 ÀïÃæµÄMAXSIZEûÓÐÈκÎÇø±ð¡£ ËüÃǵÄ×÷ÓÃÊÇÐγÉÏàÓ¦µÄϵͳµ÷Óú¯ÊýÔ­ÐÍ£¬¹©ÎÒÃÇÔÚ³ÌÐòÖе÷Óá£ÎÒÃǺÜÈÝÒ×¾ÍÄÜ·¢ÏÖ¹æÂÉ£¬_syscallºóÃæµÄÊý×ÖºÍtypeN,argNµÄÊýÄ¿Ò»Ñù¶à¡£ÊÂʵÉÏ£¬_syscallºóÃæ¸úµÄÊý×ÖÖ¸Ã÷ÁËÕ¹¿ªºóÐγɺ¯ÊýµÄ²ÎÊýµÄ¸öÊý£¬ÈÃÎÒÃÇ¿´Ò»¸öʵÀý£¬¾ÍÊǸոÕÓùýµÄtimeϵͳµ÷Ó㺠_syscall1(time_t,time,time_t *,tloc) Õ¹¿ªºóµÄÇéÐÎÊÇÕâÑù£º time_t time(time_t * tloc) { long __res; __asm__ volatile("int $0x80" : "=a" (__res) : "0" (13),"b" ((long)(tloc))); do { if ((unsigned long)(__res) >= (unsigned long)(-125)) { errno = -(__res); __res = -1; } return (time_t) (__res); } while (0) ; } ¿ÉÒÔ¿´³ö£¬_syscall1(time_t,time,time_t *,tloc)Õ¹¿ª³ÉÒ»¸öÃûΪtimeµÄº¯Êý£¬Ô­²ÎÊýtime_t¾ÍÊǺ¯ÊýµÄ·µ»ØÀàÐÍ£¬Ô­²ÎÊýtime_t *ºÍtloc·Ö±ð¹¹³Éк¯ÊýµÄ²ÎÊý¡£ÊÂʵÉÏ£¬³ÌÐòÖÐÓõ½µÄtimeº¯ÊýµÄÔ­Ð;ÍÊÇËü¡£ 7¡¢errnoÊÇʲô£¿ Ϊ·ÀÖ¹ºÍÕý³£µÄ·µ»ØÖµ»ìÏý£¬ÏµÍ³µ÷Óò¢²»Ö±½Ó·µ»Ø´íÎóÂ룬¶øÊǽ«´íÎóÂë·ÅÈëÒ»¸öÃûΪerrnoµÄÈ«¾Ö±äÁ¿ÖС£Èç¹ûÒ»¸öϵͳµ÷ÓÃʧ°Ü£¬Äã¿ÉÒÔ¶Á³öerrnoµÄÖµÀ´È·¶¨ÎÊÌâËùÔÚ¡£ errno²»Í¬ÊýÖµËù´ú±íµÄ´íÎóÏûÏ¢¶¨ÒåÔÚerrno.hÖУ¬ÄãÒ²¿ÉÒÔͨ¹ýÃüÁî"man 3 errno"À´²ì¿´ËüÃÇ¡£ ÐèҪעÒâµÄÊÇ£¬errnoµÄÖµÖ»ÔÚº¯Êý·¢Éú´íÎóʱÉèÖã¬Èç¹ûº¯Êý²»·¢Éú´íÎó£¬errnoµÄÖµ¾ÍÎÞ¶¨Ò壬²¢²»»á±»ÖÃΪ0¡£ÁíÍ⣬ÔÚ´¦ÀíerrnoÇ°×îºÃÏÈ°ÑËüµÄÖµ´æÈëÁíÒ»¸ö±äÁ¿£¬ÒòΪÔÚ´íÎó´¦Àí¹ý³ÌÖУ¬¼´Ê¹Ïñprintf()ÕâÑùµÄº¯Êý³ö´íʱҲ»á¸Ä±äerrnoµÄÖµ¡£ 8¡¢ÏµÍ³µ÷ÓüæÈÝÐÔºÃÂ𣿠ºÜÒź¶£¬´ð°¸ÊÇ--²»ºÃ¡£µ«Õâ¾ö²»Òâζ×ÅÄãµÄ³ÌÐò»áÈýÌìÁ½Í·µÄµ¼ÖÂϵͳ±ÀÀ££¬ÒòΪϵͳµ÷ÓÃÊÇLinuxµÄÄÚºËÌṩµÄ£¬ËùÒÔËüÃǹ¤×÷ÆðÀ´·Ç³£Îȶ¨£¬¶ÔÓڴ˵ãÎÞÐèË¿ºÁ»³ÒÉ£¬ÔÚ¾ø´ó¶àÊýµÄÇé¿öÏ£¬ÏµÍ³µ÷ÓÃÒª±ÈÄã×Ô¼º±àдµÄ´úÂë¿É¿¿¶ø¸ßЧµÄ¶à¡£ µ«ÊÇ£¬ÔÚLinuxµÄ¸÷°æ±¾ÄÚºËÖ®¼ä£¬ÏµÍ³µ÷ÓõļæÈÝÐÔ±íÏֵò¢²»ÏñÏëÏóÄÇôºÃ£¬ÕâÊÇÓÉLinux±¾ÉíµÄÐÔÖʾö¶¨µÄ¡£LinuxÊÇһȺ³ÌÐòÉè¼Æ¸ßÊÖÀûÓÃÒµÓàʱ¼ä¿ª·¢³öÀ´µÄ£¬ËûÃÇÖмäµÄ´ó²¿·ÖÈËûÓаÑLinuxµ±³ÉÒ»¸öÑÏËàµÄÉÌÒµÈí¼þ£¬£¨ÏÖÔÚµÄÇé¿öÓÐЩ²»Í¬ÁË£¬Ëæ×ÅLinuxÉÌÒµ¹«Ë¾ºÍÒÔLinuxΪÉúµÄÈ˵ÄÔö³¤£¬²»ÉÙÈ˵ÄÄԽÉúÁ˱仯¡££©½á¹û¾ÍÊÇ£¬Èç¹ûеķ½°¸ÔÚЧÂʺͼæÈÝÐÔÉÏ·¢ÉúÁËì¶Ü£¬ËûÃÇÍùÍùÉáÆú¼æÈÝÐÔ¶ø×·ÇóЧÂÊ£¬¾ÍÕâÑù£¬Èç¹ûËûÃÇÈÏΪij¸öϵͳµ÷ÓÃʵÏֵıȽÏÔã¸â£¬ËûÃǾͻáºÁ²»ÓÌÔ¥µÄ×÷³öÐ޸ģ¬ÓÐЩʱºòÉõÖÁÁ¬½Ó¿ÚÒ²Ò»Æð¸ÄµôÁË£¬¸ü¿ÉŵÄÊÇ£¬ºÜ¶àʱºò£¬ËûÃǶÔ×Ô¼ºµÄÐÞ¸ÄÁ¬¸öÕкôÒ²²»´ò£¬ÔÚÈκÎÎĵµÀﶼÕÒ²»µ½¹ØÓÚÐ޸ĵÄÌáʾ¡£ÕâÑù£¬Ã¿µ±ÐÂÄÚºËÍƳöµÄʱºò£¬ºÜ¿ÉÄܶ¼»áÇÄÇĵĸüÐÂһЩϵͳµ÷Óã¬Óû§±àÖƵÄÓ¦ÓóÌÐòÒ²»á¸ú×ųö´í¡£ ˵µ½ÕâÀÄãÊDz»ÊǸоõǰ;һƬ»è°µÄØ£¿ºÇºÇ£¬²»ÓÃÌ«½ôÕÅ£¬ÈçÇ°ÃæËù˵£¬Ëæ×ÅÔ½À´Ô½¶àµÄÈË°ÑLinuxµ±³É×Ô¼ºµÄ·¹Í룬²»¼æÈݵÄÇé¿öÒ²Ô½À´Ô½º±¼û¡£´Ó2.2°æ±¾ÒÔºóµÄLinuxÄÚºËÒѾ­·Ç³£Îȶ¨ÁË£¬²»¹ý¾¡¹ÜÈç´Ë£¬Ä㻹ÊÇÓбØÒªÔÚÿ¸öÐÂÄÚºËÍƳöÖ®ºó£¬¶Ô×Ô¼ºµÄÓ¦ÓóÌÐò½øÐмæÈÝÐÔ²âÊÔ£¬ÒÔ·ÀÖ¹ÒâÍâµÄ·¢Éú¡£ 9¡¢¸ÃÈçºÎѧϰʹÓÃLinuxϵͳµ÷ÓÃÄØ£¿ Äã¿ÉÒÔÓÃ"man 2 ϵͳµ÷ÓÃÃû³Æ"µÄÃüÁîÀ´²é¿´¸÷Ìõϵͳµ÷ÓõĽéÉÜ£¬µ«ÕâÊ×ÏÈÒªÇóÄãÒªÓв»´íµÄÓ¢Óï»ù´¡£¬Æä´Î»¹µÃÓÐÒ»¶¨µÄ³ÌÐòÉè¼ÆºÍϵͳ±à³ÌµÄ¹¦µ×£¬man pages²»»áÉæ¼°Ì«¶àµÄÓ¦ÓÃϸ½Ú£¬ÒòΪËüÖ»ÊÇÒ»¸öÊÖ²á¶ø·Ç½Ì³Ì¡£Èç¹ûman pagesËùÌṩµÄ¶«Î÷²»ÄÜʹÄã¸Ðµ½·Ç³£ÂúÒ⣬ÄǾ͸úÎÒÀ´°É£¬±¾×¨À¸½«ÏòÄãչʾLinuxϵͳµ÷Óñà³ÌµÄÎÞÇî÷ÈÁ¦¡£ <
ÉÏÒ»Ò³ [1] [2] [3] ÏÂÒ»Ò³ 

£¨³ö´¦£ºhttp://www.sheup.com£©


ÉÏÒ»Ò³ [1] [2] [3]