Changes between Version 3 and Version 4 of Dev/KernelHack/COINS/worklog/201110


Ignore:
Timestamp:
Oct 26, 2011 12:47:26 PM (12 years ago)
Author:
mitty
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Dev/KernelHack/COINS/worklog/201110

    v3 v4  
    880880type = unsigned int 
    881881}}} 
     882 
     883 = 10/19 = 
     884 == add new system call (i386) == 
     885 * windell57:i386 s0711489$ vim arch/x86/include/asm/unistd_32.h 
     886 * windell57:i386 s0711489$ vim arch/x86/kernel/syscall_table_32.S 
     887 * windell57:i386 s0711489$ vim arch/x86/include/asm/new_hello.h 
     888 * windell57:i386 s0711489$ vim arch/x86/kernel/new_hello.c 
     889 
     890 = 10/21 = 
     891 == add new system call (i386) (cont) == 
     892 * windell57:i386 s0711489$ vim arch/x86/kernel/new_hello.c 
     893 * windell57:i386 s0711489$ vim arch/x86/kernel/Makefile 
     894{{{#!diff 
     895Index: arch/x86/kernel/syscall_table_32.S 
     896=================================================================== 
     897--- arch/x86/kernel/syscall_table_32.S  (revision 1352) 
     898+++ arch/x86/kernel/syscall_table_32.S  (revision 1353) 
     899@@ -337,3 +337,4 @@ 
     900        .long sys_rt_tgsigqueueinfo     /* 335 */ 
     901        .long sys_perf_event_open 
     902        .long sys_recvmmsg 
     903+       .long sys_new_hello 
     904Index: arch/x86/kernel/Makefile 
     905=================================================================== 
     906--- arch/x86/kernel/Makefile    (revision 1352) 
     907+++ arch/x86/kernel/Makefile    (revision 1353) 
     908@@ -131,3 +131,5 @@ 
     909        obj-$(CONFIG_PCI_MMCONFIG)      += mmconf-fam10h_64.o 
     910        obj-y                           += vsmp_64.o 
     911 endif 
     912+ 
     913+obj-y                          += new_hello.o 
     914Index: arch/x86/kernel/new_hello.c 
     915=================================================================== 
     916--- arch/x86/kernel/new_hello.c (revision 0) 
     917+++ arch/x86/kernel/new_hello.c (revision 1353) 
     918@@ -0,0 +1,7 @@ 
     919+#include <linux/kernel.h> 
     920+#include <linux/syscalls.h> 
     921+ 
     922+SYSCALL_DEFINE1(new_hello, int, i) { 
     923+        printk(KERN_DEBUG "new_hello() syscall with %d", i); 
     924+        return i; 
     925+} 
     926Index: arch/x86/include/asm/unistd_32.h 
     927=================================================================== 
     928--- arch/x86/include/asm/unistd_32.h    (revision 1352) 
     929+++ arch/x86/include/asm/unistd_32.h    (revision 1353) 
     930@@ -343,10 +343,11 @@ 
     931 #define __NR_rt_tgsigqueueinfo 335 
     932 #define __NR_perf_event_open   336 
     933 #define __NR_recvmmsg          337 
     934+#define __NR_new_hello         338 
     935  
     936 #ifdef __KERNEL__ 
     937  
     938-#define NR_syscalls 338 
     939+#define NR_syscalls 339 
     940  
     941 #define __ARCH_WANT_IPC_PARSE_VERSION 
     942 #define __ARCH_WANT_OLD_READDIR 
     943Index: arch/x86/include/asm/new_hello.h 
     944=================================================================== 
     945--- arch/x86/include/asm/new_hello.h    (revision 0) 
     946+++ arch/x86/include/asm/new_hello.h    (revision 1353) 
     947@@ -0,0 +1,7 @@ 
     948+#ifndef _ASM_X86_NEW_HELLO_H 
     949+#define _ASM_X86_NEW_HELLO_H 
     950+ 
     951+#include <asm/unistd.h> 
     952+#define new_hello(x) syscall(__NR_new_hello, x) 
     953+ 
     954+#endif /* _ASM_X86_NEW_HELLO_H */ 
     955}}} 
     956 
     957 * windell57:i386 s0711489$ make 
     958{{{ 
     959Kernel: arch/x86/boot/bzImage is ready  (#2) 
     960}}} 
     961 * windell57:i386 s0711489$ make modules 
     962 
     963 * s0711489@ubuntu-lucid:~$ sudo /mnt/hgfs/tools/install.sh 
     964 * s0711489@ubuntu-lucid:~$ sudo reboot 
     965{{{ 
     966Linux ubuntu-lucid 2.6.35.14 #2 SMP Fri Oct 21 14:25:51 JST 2011 i686 GNU/Linux 
     967Ubuntu 10.04.3 LTS 
     968}}} 
     969 
     970 
     971 * s0711489@ubuntu-lucid:~$ cat > new_hello.c 
     972{{{#!cc 
     973#include <unistd.h> 
     974#include <syscall.h> 
     975#include <stdio.h> 
     976 
     977int main (void) { 
     978        printf ("new_helloc(1) -> %d\n", 
     979                syscall(__NR_new_hello, 1) 
     980        ); 
     981} 
     982}}} 
     983 * s0711489@ubuntu-lucid:~$ gcc -I /lib/modules/2.6.35.14/build/arch/x86/include/ new_hello.c 
     984{{{ 
     985new_hello.c: In function ‘main’: 
     986new_hello.c:8: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’ 
     987}}} 
     988 
     989 * dmesgにしか出なかったので、KERN_DEBUGを消す 
     990 
     991 * windell57:i386 s0711489$ make 
     992{{{ 
     993Kernel: arch/x86/boot/bzImage is ready  (#3) 
     994}}} 
     995 * windell57:i386 s0711489$ make modules 
     996 
     997 * s0711489@ubuntu-lucid:~$ sudo /mnt/hgfs/tools/install.sh 
     998 * s0711489@ubuntu-lucid:~$ sudo reboot 
     999 
     1000 
     1001 * s0711489@ubuntu-lucid:~$ cat > new_hello.c 
     1002 * s0711489@ubuntu-lucid:~$ gcc -I /lib/modules/2.6.35.14/build/arch/x86/include/ new_hello.c 
     1003 * s0711489@ubuntu-lucid:~$ ./a.out 
     1004{{{ 
     1005new_helloc(1) -> 1 
     1006}}} 
     1007 
     1008 * s0711489@ubuntu-lucid:~$ dmesg | tail -n 1 
     1009{{{ 
     1010[  116.986628] new_hello() syscall with 1 
     1011}}} 
     1012 * KERN_DEBUGを消したが、結局dmesgにしか出ない 
     1013  * \nの追加 
     1014{{{#!diff 
     1015Index: arch/x86/kernel/new_hello.c 
     1016=================================================================== 
     1017--- arch/x86/kernel/new_hello.c (revision 1354) 
     1018+++ arch/x86/kernel/new_hello.c (revision 1355) 
     1019@@ -2,6 +2,6 @@ 
     1020 #include <linux/syscalls.h> 
     1021  
     1022 SYSCALL_DEFINE1(new_hello, int, i) { 
     1023-        printk(KERN_DEBUG "new_hello() syscall with %d", i); 
     1024+        printk("new_hello() syscall with %d\n", i); 
     1025         return i; 
     1026 } 
     1027}}} 
     1028 
     1029 * windell57:i386 s0711489$ make 
     1030{{{ 
     1031Kernel: arch/x86/boot/bzImage is ready  (#4) 
     1032}}} 
     1033 * windell57:i386 s0711489$ make modules 
     1034 * s0711489@ubuntu-lucid:~$ sudo /mnt/hgfs/tools/install.sh 
     1035 
     1036 
     1037 * s0711489@ubuntu-lucid:~$ cat > new_hello.c 
     1038 * s0711489@ubuntu-lucid:~$ gcc -I /lib/modules/2.6.35.14/build/arch/x86/include/ new_hello.c 
     1039 * s0711489@ubuntu-lucid:~$ ./a.out 
     1040{{{ 
     1041new_helloc(1) -> 1 
     1042}}} 
     1043 * s0711489@ubuntu-lucid:~$ ./a.out 1 
     1044{{{ 
     1045new_helloc(2) -> 2 
     1046}}} 
     1047 * s0711489@ubuntu-lucid:~$ ./a.out 2 
     1048{{{ 
     1049new_helloc(2) -> 2 
     1050}}} 
     1051 * s0711489@ubuntu-lucid:~$ ./a.out 3 
     1052{{{ 
     1053new_helloc(2) -> 2 
     1054}}} 
     1055 * s0711489@ubuntu-lucid:~$ ./a.out 1 2 3 4 5 
     1056{{{ 
     1057new_helloc(6) -> 6 
     1058}}} 
     1059 
     1060 * s0711489@ubuntu-lucid:~$ dmesg | tail 
     1061{{{ 
     1062[   62.656820] new_hello() syscall with 1 
     1063[   66.271703] new_hello() syscall with 2 
     1064[   68.411791] new_hello() syscall with 2 
     1065[   70.395934] new_hello() syscall with 2 
     1066[   77.010426] new_hello() syscall with 6 
     1067}}} 
     1068 
     1069 * /var/log/messages /var/log/kern.log /var/log/syslog にも出るようになった 
     1070{{{ 
     1071Oct 21 15:29:00 ubuntu-lucid kernel: [   62.656820] new_hello() syscall with 1 
     1072Oct 21 15:29:04 ubuntu-lucid kernel: [   66.271703] new_hello() syscall with 2 
     1073Oct 21 15:29:06 ubuntu-lucid kernel: [   68.411791] new_hello() syscall with 2 
     1074Oct 21 15:29:08 ubuntu-lucid kernel: [   70.395934] new_hello() syscall with 2 
     1075Oct 21 15:29:14 ubuntu-lucid kernel: [   77.010426] new_hello() syscall with 6 
     1076}}} 
     1077 
     1078 * KERN_DEBUGを戻す 
     1079{{{#!diff 
     1080Index: arch/x86/kernel/new_hello.c 
     1081=================================================================== 
     1082--- arch/x86/kernel/new_hello.c (revision 1356) 
     1083+++ arch/x86/kernel/new_hello.c (revision 1357) 
     1084@@ -2,6 +2,6 @@ 
     1085 #include <linux/syscalls.h> 
     1086  
     1087 SYSCALL_DEFINE1(new_hello, int, i) { 
     1088-        printk("new_hello() syscall with %d\n", i); 
     1089+        printk(KERN_DEBUG "new_hello() syscall with %d\n", i); 
     1090         return i; 
     1091 } 
     1092}}} 
     1093 
     1094 * windell57:i386 s0711489$ make 
     1095{{{ 
     1096Kernel: arch/x86/boot/bzImage is ready  (#5) 
     1097}}} 
     1098 * windell57:i386 s0711489$ make modules 
     1099 
     1100 * s0711489@ubuntu-lucid:~$ sudo /mnt/hgfs/tools/install.sh 
     1101 
     1102 
     1103 * s0711489@ubuntu-lucid:~$ ./a.out 
     1104{{{ 
     1105new_helloc(1) -> 1 
     1106}}} 
     1107 * s0711489@ubuntu-lucid:~$ ./a.out 2 
     1108{{{ 
     1109new_helloc(2) -> 2 
     1110}}} 
     1111 * s0711489@ubuntu-lucid:~$ ./a.out 2 4 
     1112{{{ 
     1113new_helloc(3) -> 3 
     1114}}} 
     1115 * s0711489@ubuntu-lucid:~$ ./a.out 2 3 4 
     1116{{{ 
     1117new_helloc(4) -> 4 
     1118}}} 
     1119 
     1120 * s0711489@ubuntu-lucid:~$ tailf /var/log/syslog 
     1121{{{ 
     1122Oct 21 15:39:29 ubuntu-lucid kernel: [   55.626892] new_hello() syscall with 1 
     1123Oct 21 15:40:18 ubuntu-lucid kernel: [  104.990720] new_hello() syscall with 2 
     1124Oct 21 15:40:20 ubuntu-lucid kernel: [  106.772709] new_hello() syscall with 3 
     1125Oct 21 15:40:23 ubuntu-lucid kernel: [  109.867051] new_hello() syscall with 4 
     1126}}} 
     1127 
     1128 * /var/log/messages には出なくなる 
     1129 
     1130 === trace sys_new_hello with GDB === 
     1131 * windell57:i386 s0711489$ gdb 
     1132{{{ 
     1133(gdb) file vmlinux 
     1134Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/vmlinux...(no debugging symbols found)...done. 
     1135(gdb) b sys_new_hello 
     1136Breakpoint 1 at 0xc101d87c: file arch/x86/kernel/new_hello.c, line 4. 
     1137(gdb) target remote localhost:8832 
     1138Remote debugging using localhost:8832 
     11390xc1007cdf in native_safe_halt () 
     1140    at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/arch/x86/include/asm/irqflags.h:49 
     114149              asm volatile("sti; hlt": : :"memory"); 
     1142(gdb) c 
     1143Continuing. 
     1144 
     1145Breakpoint 1, sys_new_hello (i=1) at arch/x86/kernel/new_hello.c:4 
     11464       SYSCALL_DEFINE1(new_hello, int, i) { 
     1147(gdb) n 
     11485               printk(KERN_DEBUG "new_hello() syscall with %d\n", i); 
     1149(gdb) l 
     11501       #include <linux/kernel.h> 
     11512       #include <linux/syscalls.h> 
     11523 
     11534       SYSCALL_DEFINE1(new_hello, int, i) { 
     11545               printk(KERN_DEBUG "new_hello() syscall with %d\n", i); 
     11556               return i; 
     11567       } 
     1157(gdb) s 
     1158printk (fmt=0xc1449502 "<7>new_hello() syscall with %d\n") 
     1159    at kernel/printk.c:614 
     1160614             va_start(args, fmt); 
     1161(gdb) l 
     1162609                     r = vkdb_printf(fmt, args); 
     1163610                     va_end(args); 
     1164611                     return r; 
     1165612             } 
     1166613     #endif 
     1167614             va_start(args, fmt); 
     1168615             r = vprintk(fmt, args); 
     1169616             va_end(args); 
     1170617 
     1171618             return r; 
     1172(gdb) n 
     1173615             r = vprintk(fmt, args); 
     1174(gdb) 
     1175614             va_start(args, fmt); 
     1176(gdb) 
     1177615             r = vprintk(fmt, args); 
     1178(gdb) 
     1179619     } 
     1180(gdb) 
     1181sys_new_hello (i=1) at arch/x86/kernel/new_hello.c:7 
     11827       } 
     1183(gdb) l 
     11842       #include <linux/syscalls.h> 
     11853 
     11864       SYSCALL_DEFINE1(new_hello, int, i) { 
     11875               printk(KERN_DEBUG "new_hello() syscall with %d\n", i); 
     11886               return i; 
     11897       } 
     1190(gdb) s 
     1191}}} 
     1192 
     1193 * s0711489@ubuntu-lucid:~$ ./a.out 
     1194{{{ 
     1195new_helloc(1) -> 1 
     1196}}} 
     1197 
     1198 === add sys_new_hello entry === 
     1199 * windell57:i386 s0711489$ vim include/linux/syscalls.h 
     1200{{{#!diff 
     1201Index: include/linux/syscalls.h 
     1202=================================================================== 
     1203--- include/linux/syscalls.h    (revision 1358) 
     1204+++ include/linux/syscalls.h    (revision 1359) 
     1205@@ -826,4 +826,6 @@ 
     1206                        unsigned long fd, unsigned long pgoff); 
     1207 asmlinkage long sys_old_mmap(struct mmap_arg_struct __user *arg); 
     1208  
     1209+asmlinkage long sys_new_hello(int i); 
     1210+ 
     1211 #endif 
     1212}}} 
     1213 
     1214 * windell57:i386 s0711489$ make 
     1215{{{ 
     1216Kernel: arch/x86/boot/bzImage is ready  (#6) 
     1217}}} 
     1218 * windell57:i386 s0711489$ make modules 
     1219 
     1220 * s0711489@ubuntu-lucid:~$ sudo /mnt/hgfs/tools/install.sh 
     1221 
     1222 * s0711489@ubuntu-lucid:~$ ./a.out 
     1223{{{ 
     1224new_helloc(1) -> 1 
     1225}}} 
     1226 * s0711489@ubuntu-lucid:~$ ./a.out 2 
     1227{{{ 
     1228new_helloc(2) -> 2 
     1229}}} 
     1230 * s0711489@ubuntu-lucid:~$ ./a.out 2 3 
     1231{{{ 
     1232new_helloc(3) -> 3 
     1233}}} 
     1234 
     1235 * s0711489@ubuntu-lucid:~$ tailf /var/log/kern.log 
     1236{{{ 
     1237Oct 21 16:16:20 ubuntu-lucid kernel: [   59.045533] new_hello() syscall with 1 
     1238Oct 21 16:16:22 ubuntu-lucid kernel: [   61.043321] new_hello() syscall with 2 
     1239Oct 21 16:16:24 ubuntu-lucid kernel: [   63.470397] new_hello() syscall with 3 
     1240}}} 
     1241 
     1242 
     1243 == add new system call (x86_64) == 
     1244 * viola04:linux-2.6.35.14 s0711489$ svn cp i386/arch/x86/include/asm/new_hello.h x86_64/arch/x86/include/asm/new_hello.h 
     1245 * viola04:linux-2.6.35.14 s0711489$ svn cp i386/arch/x86/kernel/new_hello.c x86_64/arch/x86/kernel/ 
     1246 * viola04:linux-2.6.35.14 s0711489$ svn merge i386/include/linux/syscalls.h x86_64/include/linux/syscalls.h -r 1358:1359