| 1247 | |
| 1248 | = 10/26 = |
| 1249 | == add new system call (x86_64) (cont) == |
| 1250 | * viola06:x86_64 s0711489$ svn revert include/linux/syscalls.h arch/x86/kernel/new_hello.c arch/x86/include/asm/new_hello.h |
| 1251 | * viola06:x86_64 s0711489$ rm arch/x86/kernel/new_hello.c arch/x86/include/asm/new_hello.h |
| 1252 | |
| 1253 | * viola06:linux-2.6.35.14 s0711489$ svn merge i386/arch/ x86_64/arch/ -r1352:1359 |
| 1254 | * viola06:linux-2.6.35.14 s0711489$ svn merge i386/include/ x86_64/include/ -r1358:1359 |
| 1255 | * viola04:x86_64 s0711489$ vim arch/x86/include/asm/unistd_64.h |
| 1256 | {{{ |
| 1257 | Index: include/linux/syscalls.h |
| 1258 | =================================================================== |
| 1259 | --- include/linux/syscalls.h (revision 1367) |
| 1260 | +++ include/linux/syscalls.h (revision 1368) |
| 1261 | @@ -826,4 +826,6 @@ |
| 1262 | unsigned long fd, unsigned long pgoff); |
| 1263 | asmlinkage long sys_old_mmap(struct mmap_arg_struct __user *arg); |
| 1264 | |
| 1265 | +asmlinkage long sys_new_hello(int i); |
| 1266 | + |
| 1267 | #endif |
| 1268 | Index: include |
| 1269 | =================================================================== |
| 1270 | --- include (revision 1367) |
| 1271 | +++ include (revision 1368) |
| 1272 | |
| 1273 | Property changes on: include |
| 1274 | ___________________________________________________________________ |
| 1275 | Added: svn:mergeinfo |
| 1276 | Merged /trunk/coursework/KernelHack/linux-2.6.35.14/i386/include:r1359 |
| 1277 | Index: arch/x86/kernel/syscall_table_32.S |
| 1278 | =================================================================== |
| 1279 | --- arch/x86/kernel/syscall_table_32.S (revision 1367) |
| 1280 | +++ arch/x86/kernel/syscall_table_32.S (revision 1368) |
| 1281 | @@ -337,3 +337,4 @@ |
| 1282 | .long sys_rt_tgsigqueueinfo /* 335 */ |
| 1283 | .long sys_perf_event_open |
| 1284 | .long sys_recvmmsg |
| 1285 | + .long sys_new_hello |
| 1286 | Index: arch/x86/kernel/Makefile |
| 1287 | =================================================================== |
| 1288 | --- arch/x86/kernel/Makefile (revision 1367) |
| 1289 | +++ arch/x86/kernel/Makefile (revision 1368) |
| 1290 | @@ -131,3 +131,5 @@ |
| 1291 | obj-$(CONFIG_PCI_MMCONFIG) += mmconf-fam10h_64.o |
| 1292 | obj-y += vsmp_64.o |
| 1293 | endif |
| 1294 | + |
| 1295 | +obj-y += new_hello.o |
| 1296 | Index: arch/x86/kernel/new_hello.c |
| 1297 | =================================================================== |
| 1298 | --- arch/x86/kernel/new_hello.c (revision 0) |
| 1299 | +++ arch/x86/kernel/new_hello.c (revision 1368) |
| 1300 | @@ -0,0 +1,7 @@ |
| 1301 | +#include <linux/kernel.h> |
| 1302 | +#include <linux/syscalls.h> |
| 1303 | + |
| 1304 | +SYSCALL_DEFINE1(new_hello, int, i) { |
| 1305 | + printk(KERN_DEBUG "new_hello() syscall with %d\n", i); |
| 1306 | + return i; |
| 1307 | +} |
| 1308 | Index: arch/x86/include/asm/unistd_32.h |
| 1309 | =================================================================== |
| 1310 | --- arch/x86/include/asm/unistd_32.h (revision 1367) |
| 1311 | +++ arch/x86/include/asm/unistd_32.h (revision 1368) |
| 1312 | @@ -343,10 +343,11 @@ |
| 1313 | #define __NR_rt_tgsigqueueinfo 335 |
| 1314 | #define __NR_perf_event_open 336 |
| 1315 | #define __NR_recvmmsg 337 |
| 1316 | +#define __NR_new_hello 338 |
| 1317 | |
| 1318 | #ifdef __KERNEL__ |
| 1319 | |
| 1320 | -#define NR_syscalls 338 |
| 1321 | +#define NR_syscalls 339 |
| 1322 | |
| 1323 | #define __ARCH_WANT_IPC_PARSE_VERSION |
| 1324 | #define __ARCH_WANT_OLD_READDIR |
| 1325 | Index: arch/x86/include/asm/new_hello.h |
| 1326 | =================================================================== |
| 1327 | --- arch/x86/include/asm/new_hello.h (revision 0) |
| 1328 | +++ arch/x86/include/asm/new_hello.h (revision 1368) |
| 1329 | @@ -0,0 +1,7 @@ |
| 1330 | +#ifndef _ASM_X86_NEW_HELLO_H |
| 1331 | +#define _ASM_X86_NEW_HELLO_H |
| 1332 | + |
| 1333 | +#include <asm/unistd.h> |
| 1334 | +#define new_hello(x) syscall(__NR_new_hello, x) |
| 1335 | + |
| 1336 | +#endif /* _ASM_X86_NEW_HELLO_H */ |
| 1337 | Index: arch/x86/include/asm/unistd_64.h |
| 1338 | =================================================================== |
| 1339 | --- arch/x86/include/asm/unistd_64.h (revision 1367) |
| 1340 | +++ arch/x86/include/asm/unistd_64.h (revision 1368) |
| 1341 | @@ -663,6 +663,8 @@ |
| 1342 | __SYSCALL(__NR_perf_event_open, sys_perf_event_open) |
| 1343 | #define __NR_recvmmsg 299 |
| 1344 | __SYSCALL(__NR_recvmmsg, sys_recvmmsg) |
| 1345 | +#define __NR_new_hello 300 |
| 1346 | +__SYSCALL(__NR_new_hello, sys_new_hello) |
| 1347 | |
| 1348 | #ifndef __NO_STUBS |
| 1349 | #define __ARCH_WANT_OLD_READDIR |
| 1350 | Index: arch |
| 1351 | =================================================================== |
| 1352 | --- arch (revision 1367) |
| 1353 | +++ arch (revision 1368) |
| 1354 | |
| 1355 | Property changes on: arch |
| 1356 | ___________________________________________________________________ |
| 1357 | Added: svn:mergeinfo |
| 1358 | Merged /trunk/coursework/KernelHack/linux-2.6.35.14/i386/arch:r1353-1359 |
| 1359 | }}} |
| 1360 | |
| 1361 | * viola06:x86_64 s0711489$ make -j 16 |
| 1362 | {{{ |
| 1363 | Kernel: arch/x86/boot/bzImage is ready (#2) |
| 1364 | }}} |
| 1365 | * viola06:x86_64 s0711489$ make modules |
| 1366 | |
| 1367 | |
| 1368 | * s0711489@ubuntu-lucid64:~$ sudo /mnt/hgfs/tools/install.sh |
| 1369 | |
| 1370 | * s0711489@ubuntu-lucid64:~/KernelHack/03$ uname -a |
| 1371 | {{{ |
| 1372 | Linux ubuntu-lucid64 2.6.32-33-generic #72-Ubuntu SMP Fri Jul 29 21:07:13 UTC 2011 x86_64 GNU/Linux |
| 1373 | }}} |
| 1374 | * s0711489@ubuntu-lucid64:~/KernelHack/03$ gcc -I /lib/modules/2.6.35.14/build/arch/x86/include/ new_hello.c |
| 1375 | {{{ |
| 1376 | new_hello.c: In function ‘main’: |
| 1377 | new_hello.c:9: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ |
| 1378 | }}} |
| 1379 | * s0711489@ubuntu-lucid64:~/KernelHack/03$ ./a.out |
| 1380 | {{{ |
| 1381 | new_hello(1) -> -1 |
| 1382 | }}} |
| 1383 | * reboot 前はsyscallが存在しない |
| 1384 | |
| 1385 | * s0711489@ubuntu-lucid64:~$ sudo reboot |
| 1386 | |
| 1387 | * s0711489@ubuntu-lucid64:~$ uname -a |
| 1388 | {{{ |
| 1389 | Linux ubuntu-lucid64 2.6.35.14 #2 SMP Wed Oct 26 13:06:41 JST 2011 x86_64 GNU/Linux |
| 1390 | }}} |
| 1391 | * s0711489@ubuntu-lucid64:~/KernelHack/03$ ./a.out |
| 1392 | {{{ |
| 1393 | new_hello(1) -> 1 |
| 1394 | }}} |
| 1395 | * s0711489@ubuntu-lucid64:~/KernelHack/03$ ./a.out 2 |
| 1396 | {{{ |
| 1397 | new_hello(2) -> 2 |
| 1398 | }}} |
| 1399 | * s0711489@ubuntu-lucid64:~/KernelHack/03$ ./a.out 2 3 |
| 1400 | {{{ |
| 1401 | new_hello(3) -> 3 |
| 1402 | }}} |
| 1403 | * s0711489@ubuntu-lucid64:~/KernelHack/03$ ./a.out 2 3 4 |
| 1404 | {{{ |
| 1405 | new_hello(4) -> 4 |
| 1406 | }}} |
| 1407 | * s0711489@ubuntu-lucid64:~/KernelHack/03$ tail /var/log/kern.log |
| 1408 | {{{ |
| 1409 | Oct 26 13:12:40 ubuntu-lucid64 kernel: [ 40.542158] new_hello() syscall with 1 |
| 1410 | Oct 26 13:12:42 ubuntu-lucid64 kernel: [ 42.668465] new_hello() syscall with 2 |
| 1411 | Oct 26 13:12:43 ubuntu-lucid64 kernel: [ 43.908292] new_hello() syscall with 3 |
| 1412 | Oct 26 13:12:45 ubuntu-lucid64 kernel: [ 45.645548] new_hello() syscall with 4 |
| 1413 | }}} |