├── Method2 ├── Makefile └── hook.c ├── Method3 ├── Makefile └── hack_proc.c ├── linux-3.6.11 ├── hide │ ├── Makefile │ ├── hide.c │ └── unhide.c ├── arch │ └── x86 │ │ └── syscalls │ │ └── syscall_64.tbl ├── include │ └── asm-generic │ │ └── unistd.h ├── Makefile └── kernel │ └── fork.c ├── readme.md └── test.c /Method2/Makefile: -------------------------------------------------------------------------------- 1 | obj-m += hook.o -------------------------------------------------------------------------------- /Method3/Makefile: -------------------------------------------------------------------------------- 1 | obj-m += hack_proc.o -------------------------------------------------------------------------------- /linux-3.6.11/hide/Makefile: -------------------------------------------------------------------------------- 1 | obj-y +=hide.o 2 | obj-y +=unhide.o 3 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hschen0712/process-hiding/master/readme.md -------------------------------------------------------------------------------- /Method2/hook.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hschen0712/process-hiding/master/Method2/hook.c -------------------------------------------------------------------------------- /Method3/hack_proc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hschen0712/process-hiding/master/Method3/hack_proc.c -------------------------------------------------------------------------------- /linux-3.6.11/hide/hide.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | asmlinkage long sys_hide(void) 4 | { 5 | current->hide=1; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /linux-3.6.11/hide/unhide.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | asmlinkage long sys_unhide(void) 4 | { 5 | current->hide=0; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define __NR_hide 313 4 | #define __NR_unhide 314 5 | int main() 6 | { 7 | printf("Before hiding:\n"); 8 | system("ps"); 9 | syscall(__NR_hide); 10 | printf("After hiding:\n"); 11 | system("ps"); 12 | syscall(__NR_unhide); 13 | printf("After unhiding:\n"); 14 | system("ps"); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /linux-3.6.11/arch/x86/syscalls/syscall_64.tbl: -------------------------------------------------------------------------------- 1 | # 2 | # 64-bit system call numbers and entry vectors 3 | # 4 | # The format is: 5 | # 6 | # 7 | # The abi is "common", "64" or "x32" for this file. 8 | # 9 | 0 common read sys_read 10 | 1 common write sys_write 11 | 2 common open sys_open 12 | 3 common close sys_close 13 | 4 common stat sys_newstat 14 | 5 common fstat sys_newfstat 15 | 6 common lstat sys_newlstat 16 | 7 common poll sys_poll 17 | 8 common lseek sys_lseek 18 | 9 common mmap sys_mmap 19 | 10 common mprotect sys_mprotect 20 | 11 common munmap sys_munmap 21 | 12 common brk sys_brk 22 | 13 64 rt_sigaction sys_rt_sigaction 23 | 14 common rt_sigprocmask sys_rt_sigprocmask 24 | 15 64 rt_sigreturn stub_rt_sigreturn 25 | 16 64 ioctl sys_ioctl 26 | 17 common pread64 sys_pread64 27 | 18 common pwrite64 sys_pwrite64 28 | 19 64 readv sys_readv 29 | 20 64 writev sys_writev 30 | 21 common access sys_access 31 | 22 common pipe sys_pipe 32 | 23 common select sys_select 33 | 24 common sched_yield sys_sched_yield 34 | 25 common mremap sys_mremap 35 | 26 common msync sys_msync 36 | 27 common mincore sys_mincore 37 | 28 common madvise sys_madvise 38 | 29 common shmget sys_shmget 39 | 30 common shmat sys_shmat 40 | 31 common shmctl sys_shmctl 41 | 32 common dup sys_dup 42 | 33 common dup2 sys_dup2 43 | 34 common pause sys_pause 44 | 35 common nanosleep sys_nanosleep 45 | 36 common getitimer sys_getitimer 46 | 37 common alarm sys_alarm 47 | 38 common setitimer sys_setitimer 48 | 39 common getpid sys_getpid 49 | 40 common sendfile sys_sendfile64 50 | 41 common socket sys_socket 51 | 42 common connect sys_connect 52 | 43 common accept sys_accept 53 | 44 common sendto sys_sendto 54 | 45 64 recvfrom sys_recvfrom 55 | 46 64 sendmsg sys_sendmsg 56 | 47 64 recvmsg sys_recvmsg 57 | 48 common shutdown sys_shutdown 58 | 49 common bind sys_bind 59 | 50 common listen sys_listen 60 | 51 common getsockname sys_getsockname 61 | 52 common getpeername sys_getpeername 62 | 53 common socketpair sys_socketpair 63 | 54 64 setsockopt sys_setsockopt 64 | 55 64 getsockopt sys_getsockopt 65 | 56 common clone stub_clone 66 | 57 common fork stub_fork 67 | 58 common vfork stub_vfork 68 | 59 64 execve stub_execve 69 | 60 common exit sys_exit 70 | 61 common wait4 sys_wait4 71 | 62 common kill sys_kill 72 | 63 common uname sys_newuname 73 | 64 common semget sys_semget 74 | 65 common semop sys_semop 75 | 66 common semctl sys_semctl 76 | 67 common shmdt sys_shmdt 77 | 68 common msgget sys_msgget 78 | 69 common msgsnd sys_msgsnd 79 | 70 common msgrcv sys_msgrcv 80 | 71 common msgctl sys_msgctl 81 | 72 common fcntl sys_fcntl 82 | 73 common flock sys_flock 83 | 74 common fsync sys_fsync 84 | 75 common fdatasync sys_fdatasync 85 | 76 common truncate sys_truncate 86 | 77 common ftruncate sys_ftruncate 87 | 78 common getdents sys_getdents 88 | 79 common getcwd sys_getcwd 89 | 80 common chdir sys_chdir 90 | 81 common fchdir sys_fchdir 91 | 82 common rename sys_rename 92 | 83 common mkdir sys_mkdir 93 | 84 common rmdir sys_rmdir 94 | 85 common creat sys_creat 95 | 86 common link sys_link 96 | 87 common unlink sys_unlink 97 | 88 common symlink sys_symlink 98 | 89 common readlink sys_readlink 99 | 90 common chmod sys_chmod 100 | 91 common fchmod sys_fchmod 101 | 92 common chown sys_chown 102 | 93 common fchown sys_fchown 103 | 94 common lchown sys_lchown 104 | 95 common umask sys_umask 105 | 96 common gettimeofday sys_gettimeofday 106 | 97 common getrlimit sys_getrlimit 107 | 98 common getrusage sys_getrusage 108 | 99 common sysinfo sys_sysinfo 109 | 100 common times sys_times 110 | 101 64 ptrace sys_ptrace 111 | 102 common getuid sys_getuid 112 | 103 common syslog sys_syslog 113 | 104 common getgid sys_getgid 114 | 105 common setuid sys_setuid 115 | 106 common setgid sys_setgid 116 | 107 common geteuid sys_geteuid 117 | 108 common getegid sys_getegid 118 | 109 common setpgid sys_setpgid 119 | 110 common getppid sys_getppid 120 | 111 common getpgrp sys_getpgrp 121 | 112 common setsid sys_setsid 122 | 113 common setreuid sys_setreuid 123 | 114 common setregid sys_setregid 124 | 115 common getgroups sys_getgroups 125 | 116 common setgroups sys_setgroups 126 | 117 common setresuid sys_setresuid 127 | 118 common getresuid sys_getresuid 128 | 119 common setresgid sys_setresgid 129 | 120 common getresgid sys_getresgid 130 | 121 common getpgid sys_getpgid 131 | 122 common setfsuid sys_setfsuid 132 | 123 common setfsgid sys_setfsgid 133 | 124 common getsid sys_getsid 134 | 125 common capget sys_capget 135 | 126 common capset sys_capset 136 | 127 64 rt_sigpending sys_rt_sigpending 137 | 128 64 rt_sigtimedwait sys_rt_sigtimedwait 138 | 129 64 rt_sigqueueinfo sys_rt_sigqueueinfo 139 | 130 common rt_sigsuspend sys_rt_sigsuspend 140 | 131 64 sigaltstack stub_sigaltstack 141 | 132 common utime sys_utime 142 | 133 common mknod sys_mknod 143 | 134 64 uselib 144 | 135 common personality sys_personality 145 | 136 common ustat sys_ustat 146 | 137 common statfs sys_statfs 147 | 138 common fstatfs sys_fstatfs 148 | 139 common sysfs sys_sysfs 149 | 140 common getpriority sys_getpriority 150 | 141 common setpriority sys_setpriority 151 | 142 common sched_setparam sys_sched_setparam 152 | 143 common sched_getparam sys_sched_getparam 153 | 144 common sched_setscheduler sys_sched_setscheduler 154 | 145 common sched_getscheduler sys_sched_getscheduler 155 | 146 common sched_get_priority_max sys_sched_get_priority_max 156 | 147 common sched_get_priority_min sys_sched_get_priority_min 157 | 148 common sched_rr_get_interval sys_sched_rr_get_interval 158 | 149 common mlock sys_mlock 159 | 150 common munlock sys_munlock 160 | 151 common mlockall sys_mlockall 161 | 152 common munlockall sys_munlockall 162 | 153 common vhangup sys_vhangup 163 | 154 common modify_ldt sys_modify_ldt 164 | 155 common pivot_root sys_pivot_root 165 | 156 64 _sysctl sys_sysctl 166 | 157 common prctl sys_prctl 167 | 158 common arch_prctl sys_arch_prctl 168 | 159 common adjtimex sys_adjtimex 169 | 160 common setrlimit sys_setrlimit 170 | 161 common chroot sys_chroot 171 | 162 common sync sys_sync 172 | 163 common acct sys_acct 173 | 164 common settimeofday sys_settimeofday 174 | 165 common mount sys_mount 175 | 166 common umount2 sys_umount 176 | 167 common swapon sys_swapon 177 | 168 common swapoff sys_swapoff 178 | 169 common reboot sys_reboot 179 | 170 common sethostname sys_sethostname 180 | 171 common setdomainname sys_setdomainname 181 | 172 common iopl stub_iopl 182 | 173 common ioperm sys_ioperm 183 | 174 64 create_module 184 | 175 common init_module sys_init_module 185 | 176 common delete_module sys_delete_module 186 | 177 64 get_kernel_syms 187 | 178 64 query_module 188 | 179 common quotactl sys_quotactl 189 | 180 64 nfsservctl 190 | 181 common getpmsg 191 | 182 common putpmsg 192 | 183 common afs_syscall 193 | 184 common tuxcall 194 | 185 common security 195 | 186 common gettid sys_gettid 196 | 187 common readahead sys_readahead 197 | 188 common setxattr sys_setxattr 198 | 189 common lsetxattr sys_lsetxattr 199 | 190 common fsetxattr sys_fsetxattr 200 | 191 common getxattr sys_getxattr 201 | 192 common lgetxattr sys_lgetxattr 202 | 193 common fgetxattr sys_fgetxattr 203 | 194 common listxattr sys_listxattr 204 | 195 common llistxattr sys_llistxattr 205 | 196 common flistxattr sys_flistxattr 206 | 197 common removexattr sys_removexattr 207 | 198 common lremovexattr sys_lremovexattr 208 | 199 common fremovexattr sys_fremovexattr 209 | 200 common tkill sys_tkill 210 | 201 common time sys_time 211 | 202 common futex sys_futex 212 | 203 common sched_setaffinity sys_sched_setaffinity 213 | 204 common sched_getaffinity sys_sched_getaffinity 214 | 205 64 set_thread_area 215 | 206 common io_setup sys_io_setup 216 | 207 common io_destroy sys_io_destroy 217 | 208 common io_getevents sys_io_getevents 218 | 209 common io_submit sys_io_submit 219 | 210 common io_cancel sys_io_cancel 220 | 211 64 get_thread_area 221 | 212 common lookup_dcookie sys_lookup_dcookie 222 | 213 common epoll_create sys_epoll_create 223 | 214 64 epoll_ctl_old 224 | 215 64 epoll_wait_old 225 | 216 common remap_file_pages sys_remap_file_pages 226 | 217 common getdents64 sys_getdents64 227 | 218 common set_tid_address sys_set_tid_address 228 | 219 common restart_syscall sys_restart_syscall 229 | 220 common semtimedop sys_semtimedop 230 | 221 common fadvise64 sys_fadvise64 231 | 222 64 timer_create sys_timer_create 232 | 223 common timer_settime sys_timer_settime 233 | 224 common timer_gettime sys_timer_gettime 234 | 225 common timer_getoverrun sys_timer_getoverrun 235 | 226 common timer_delete sys_timer_delete 236 | 227 common clock_settime sys_clock_settime 237 | 228 common clock_gettime sys_clock_gettime 238 | 229 common clock_getres sys_clock_getres 239 | 230 common clock_nanosleep sys_clock_nanosleep 240 | 231 common exit_group sys_exit_group 241 | 232 common epoll_wait sys_epoll_wait 242 | 233 common epoll_ctl sys_epoll_ctl 243 | 234 common tgkill sys_tgkill 244 | 235 common utimes sys_utimes 245 | 236 64 vserver 246 | 237 common mbind sys_mbind 247 | 238 common set_mempolicy sys_set_mempolicy 248 | 239 common get_mempolicy sys_get_mempolicy 249 | 240 common mq_open sys_mq_open 250 | 241 common mq_unlink sys_mq_unlink 251 | 242 common mq_timedsend sys_mq_timedsend 252 | 243 common mq_timedreceive sys_mq_timedreceive 253 | 244 64 mq_notify sys_mq_notify 254 | 245 common mq_getsetattr sys_mq_getsetattr 255 | 246 64 kexec_load sys_kexec_load 256 | 247 64 waitid sys_waitid 257 | 248 common add_key sys_add_key 258 | 249 common request_key sys_request_key 259 | 250 common keyctl sys_keyctl 260 | 251 common ioprio_set sys_ioprio_set 261 | 252 common ioprio_get sys_ioprio_get 262 | 253 common inotify_init sys_inotify_init 263 | 254 common inotify_add_watch sys_inotify_add_watch 264 | 255 common inotify_rm_watch sys_inotify_rm_watch 265 | 256 common migrate_pages sys_migrate_pages 266 | 257 common openat sys_openat 267 | 258 common mkdirat sys_mkdirat 268 | 259 common mknodat sys_mknodat 269 | 260 common fchownat sys_fchownat 270 | 261 common futimesat sys_futimesat 271 | 262 common newfstatat sys_newfstatat 272 | 263 common unlinkat sys_unlinkat 273 | 264 common renameat sys_renameat 274 | 265 common linkat sys_linkat 275 | 266 common symlinkat sys_symlinkat 276 | 267 common readlinkat sys_readlinkat 277 | 268 common fchmodat sys_fchmodat 278 | 269 common faccessat sys_faccessat 279 | 270 common pselect6 sys_pselect6 280 | 271 common ppoll sys_ppoll 281 | 272 common unshare sys_unshare 282 | 273 64 set_robust_list sys_set_robust_list 283 | 274 64 get_robust_list sys_get_robust_list 284 | 275 common splice sys_splice 285 | 276 common tee sys_tee 286 | 277 common sync_file_range sys_sync_file_range 287 | 278 64 vmsplice sys_vmsplice 288 | 279 64 move_pages sys_move_pages 289 | 280 common utimensat sys_utimensat 290 | 281 common epoll_pwait sys_epoll_pwait 291 | 282 common signalfd sys_signalfd 292 | 283 common timerfd_create sys_timerfd_create 293 | 284 common eventfd sys_eventfd 294 | 285 common fallocate sys_fallocate 295 | 286 common timerfd_settime sys_timerfd_settime 296 | 287 common timerfd_gettime sys_timerfd_gettime 297 | 288 common accept4 sys_accept4 298 | 289 common signalfd4 sys_signalfd4 299 | 290 common eventfd2 sys_eventfd2 300 | 291 common epoll_create1 sys_epoll_create1 301 | 292 common dup3 sys_dup3 302 | 293 common pipe2 sys_pipe2 303 | 294 common inotify_init1 sys_inotify_init1 304 | 295 64 preadv sys_preadv 305 | 296 64 pwritev sys_pwritev 306 | 297 64 rt_tgsigqueueinfo sys_rt_tgsigqueueinfo 307 | 298 common perf_event_open sys_perf_event_open 308 | 299 64 recvmmsg sys_recvmmsg 309 | 300 common fanotify_init sys_fanotify_init 310 | 301 common fanotify_mark sys_fanotify_mark 311 | 302 common prlimit64 sys_prlimit64 312 | 303 common name_to_handle_at sys_name_to_handle_at 313 | 304 common open_by_handle_at sys_open_by_handle_at 314 | 305 common clock_adjtime sys_clock_adjtime 315 | 306 common syncfs sys_syncfs 316 | 307 64 sendmmsg sys_sendmmsg 317 | 308 common setns sys_setns 318 | 309 common getcpu sys_getcpu 319 | 310 64 process_vm_readv sys_process_vm_readv 320 | 311 64 process_vm_writev sys_process_vm_writev 321 | 312 common kcmp sys_kcmp 322 | 313 common hide sys_hide 323 | 314 common unhide sys_unhide 324 | # 325 | # x32-specific system call numbers start at 512 to avoid cache impact 326 | # for native 64-bit operation. 327 | # 328 | 512 x32 rt_sigaction sys32_rt_sigaction 329 | 513 x32 rt_sigreturn stub_x32_rt_sigreturn 330 | 514 x32 ioctl compat_sys_ioctl 331 | 515 x32 readv compat_sys_readv 332 | 516 x32 writev compat_sys_writev 333 | 517 x32 recvfrom compat_sys_recvfrom 334 | 518 x32 sendmsg compat_sys_sendmsg 335 | 519 x32 recvmsg compat_sys_recvmsg 336 | 520 x32 execve stub_x32_execve 337 | 521 x32 ptrace compat_sys_ptrace 338 | 522 x32 rt_sigpending sys32_rt_sigpending 339 | 523 x32 rt_sigtimedwait compat_sys_rt_sigtimedwait 340 | 524 x32 rt_sigqueueinfo sys32_rt_sigqueueinfo 341 | 525 x32 sigaltstack stub_x32_sigaltstack 342 | 526 x32 timer_create compat_sys_timer_create 343 | 527 x32 mq_notify compat_sys_mq_notify 344 | 528 x32 kexec_load compat_sys_kexec_load 345 | 529 x32 waitid compat_sys_waitid 346 | 530 x32 set_robust_list compat_sys_set_robust_list 347 | 531 x32 get_robust_list compat_sys_get_robust_list 348 | 532 x32 vmsplice compat_sys_vmsplice 349 | 533 x32 move_pages compat_sys_move_pages 350 | 534 x32 preadv compat_sys_preadv64 351 | 535 x32 pwritev compat_sys_pwritev64 352 | 536 x32 rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo 353 | 537 x32 recvmmsg compat_sys_recvmmsg 354 | 538 x32 sendmmsg compat_sys_sendmmsg 355 | 539 x32 process_vm_readv compat_sys_process_vm_readv 356 | 540 x32 process_vm_writev compat_sys_process_vm_writev 357 | 541 x32 setsockopt compat_sys_setsockopt 358 | 542 x32 getsockopt compat_sys_getsockopt 359 | -------------------------------------------------------------------------------- /linux-3.6.11/include/asm-generic/unistd.h: -------------------------------------------------------------------------------- 1 | #if !defined(_ASM_GENERIC_UNISTD_H) || defined(__SYSCALL) 2 | #define _ASM_GENERIC_UNISTD_H 3 | 4 | #include 5 | 6 | /* 7 | * This file contains the system call numbers, based on the 8 | * layout of the x86-64 architecture, which embeds the 9 | * pointer to the syscall in the table. 10 | * 11 | * As a basic principle, no duplication of functionality 12 | * should be added, e.g. we don't use lseek when llseek 13 | * is present. New architectures should use this file 14 | * and implement the less feature-full calls in user space. 15 | */ 16 | 17 | #ifndef __SYSCALL 18 | #define __SYSCALL(x, y) 19 | #endif 20 | 21 | #if __BITS_PER_LONG == 32 || defined(__SYSCALL_COMPAT) 22 | #define __SC_3264(_nr, _32, _64) __SYSCALL(_nr, _32) 23 | #else 24 | #define __SC_3264(_nr, _32, _64) __SYSCALL(_nr, _64) 25 | #endif 26 | 27 | #ifdef __SYSCALL_COMPAT 28 | #define __SC_COMP(_nr, _sys, _comp) __SYSCALL(_nr, _comp) 29 | #define __SC_COMP_3264(_nr, _32, _64, _comp) __SYSCALL(_nr, _comp) 30 | #else 31 | #define __SC_COMP(_nr, _sys, _comp) __SYSCALL(_nr, _sys) 32 | #define __SC_COMP_3264(_nr, _32, _64, _comp) __SC_3264(_nr, _32, _64) 33 | #endif 34 | 35 | #define __NR_io_setup 0 36 | __SC_COMP(__NR_io_setup, sys_io_setup, compat_sys_io_setup) 37 | #define __NR_io_destroy 1 38 | __SYSCALL(__NR_io_destroy, sys_io_destroy) 39 | #define __NR_io_submit 2 40 | __SC_COMP(__NR_io_submit, sys_io_submit, compat_sys_io_submit) 41 | #define __NR_io_cancel 3 42 | __SYSCALL(__NR_io_cancel, sys_io_cancel) 43 | #define __NR_io_getevents 4 44 | __SC_COMP(__NR_io_getevents, sys_io_getevents, compat_sys_io_getevents) 45 | 46 | /* fs/xattr.c */ 47 | #define __NR_setxattr 5 48 | __SYSCALL(__NR_setxattr, sys_setxattr) 49 | #define __NR_lsetxattr 6 50 | __SYSCALL(__NR_lsetxattr, sys_lsetxattr) 51 | #define __NR_fsetxattr 7 52 | __SYSCALL(__NR_fsetxattr, sys_fsetxattr) 53 | #define __NR_getxattr 8 54 | __SYSCALL(__NR_getxattr, sys_getxattr) 55 | #define __NR_lgetxattr 9 56 | __SYSCALL(__NR_lgetxattr, sys_lgetxattr) 57 | #define __NR_fgetxattr 10 58 | __SYSCALL(__NR_fgetxattr, sys_fgetxattr) 59 | #define __NR_listxattr 11 60 | __SYSCALL(__NR_listxattr, sys_listxattr) 61 | #define __NR_llistxattr 12 62 | __SYSCALL(__NR_llistxattr, sys_llistxattr) 63 | #define __NR_flistxattr 13 64 | __SYSCALL(__NR_flistxattr, sys_flistxattr) 65 | #define __NR_removexattr 14 66 | __SYSCALL(__NR_removexattr, sys_removexattr) 67 | #define __NR_lremovexattr 15 68 | __SYSCALL(__NR_lremovexattr, sys_lremovexattr) 69 | #define __NR_fremovexattr 16 70 | __SYSCALL(__NR_fremovexattr, sys_fremovexattr) 71 | 72 | /* fs/dcache.c */ 73 | #define __NR_getcwd 17 74 | __SYSCALL(__NR_getcwd, sys_getcwd) 75 | 76 | /* fs/cookies.c */ 77 | #define __NR_lookup_dcookie 18 78 | __SC_COMP(__NR_lookup_dcookie, sys_lookup_dcookie, compat_sys_lookup_dcookie) 79 | 80 | /* fs/eventfd.c */ 81 | #define __NR_eventfd2 19 82 | __SYSCALL(__NR_eventfd2, sys_eventfd2) 83 | 84 | /* fs/eventpoll.c */ 85 | #define __NR_epoll_create1 20 86 | __SYSCALL(__NR_epoll_create1, sys_epoll_create1) 87 | #define __NR_epoll_ctl 21 88 | __SYSCALL(__NR_epoll_ctl, sys_epoll_ctl) 89 | #define __NR_epoll_pwait 22 90 | __SC_COMP(__NR_epoll_pwait, sys_epoll_pwait, compat_sys_epoll_pwait) 91 | 92 | /* fs/fcntl.c */ 93 | #define __NR_dup 23 94 | __SYSCALL(__NR_dup, sys_dup) 95 | #define __NR_dup3 24 96 | __SYSCALL(__NR_dup3, sys_dup3) 97 | #define __NR3264_fcntl 25 98 | __SC_COMP_3264(__NR3264_fcntl, sys_fcntl64, sys_fcntl, compat_sys_fcntl64) 99 | 100 | /* fs/inotify_user.c */ 101 | #define __NR_inotify_init1 26 102 | __SYSCALL(__NR_inotify_init1, sys_inotify_init1) 103 | #define __NR_inotify_add_watch 27 104 | __SYSCALL(__NR_inotify_add_watch, sys_inotify_add_watch) 105 | #define __NR_inotify_rm_watch 28 106 | __SYSCALL(__NR_inotify_rm_watch, sys_inotify_rm_watch) 107 | 108 | /* fs/ioctl.c */ 109 | #define __NR_ioctl 29 110 | __SC_COMP(__NR_ioctl, sys_ioctl, compat_sys_ioctl) 111 | 112 | /* fs/ioprio.c */ 113 | #define __NR_ioprio_set 30 114 | __SYSCALL(__NR_ioprio_set, sys_ioprio_set) 115 | #define __NR_ioprio_get 31 116 | __SYSCALL(__NR_ioprio_get, sys_ioprio_get) 117 | 118 | /* fs/locks.c */ 119 | #define __NR_flock 32 120 | __SYSCALL(__NR_flock, sys_flock) 121 | 122 | /* fs/namei.c */ 123 | #define __NR_mknodat 33 124 | __SYSCALL(__NR_mknodat, sys_mknodat) 125 | #define __NR_mkdirat 34 126 | __SYSCALL(__NR_mkdirat, sys_mkdirat) 127 | #define __NR_unlinkat 35 128 | __SYSCALL(__NR_unlinkat, sys_unlinkat) 129 | #define __NR_symlinkat 36 130 | __SYSCALL(__NR_symlinkat, sys_symlinkat) 131 | #define __NR_linkat 37 132 | __SYSCALL(__NR_linkat, sys_linkat) 133 | #define __NR_renameat 38 134 | __SYSCALL(__NR_renameat, sys_renameat) 135 | 136 | /* fs/namespace.c */ 137 | #define __NR_umount2 39 138 | __SYSCALL(__NR_umount2, sys_umount) 139 | #define __NR_mount 40 140 | __SC_COMP(__NR_mount, sys_mount, compat_sys_mount) 141 | #define __NR_pivot_root 41 142 | __SYSCALL(__NR_pivot_root, sys_pivot_root) 143 | 144 | /* fs/nfsctl.c */ 145 | #define __NR_nfsservctl 42 146 | __SYSCALL(__NR_nfsservctl, sys_ni_syscall) 147 | 148 | /* fs/open.c */ 149 | #define __NR3264_statfs 43 150 | __SC_COMP_3264(__NR3264_statfs, sys_statfs64, sys_statfs, \ 151 | compat_sys_statfs64) 152 | #define __NR3264_fstatfs 44 153 | __SC_COMP_3264(__NR3264_fstatfs, sys_fstatfs64, sys_fstatfs, \ 154 | compat_sys_fstatfs64) 155 | #define __NR3264_truncate 45 156 | __SC_COMP_3264(__NR3264_truncate, sys_truncate64, sys_truncate, \ 157 | compat_sys_truncate64) 158 | #define __NR3264_ftruncate 46 159 | __SC_COMP_3264(__NR3264_ftruncate, sys_ftruncate64, sys_ftruncate, \ 160 | compat_sys_ftruncate64) 161 | 162 | #define __NR_fallocate 47 163 | __SC_COMP(__NR_fallocate, sys_fallocate, compat_sys_fallocate) 164 | #define __NR_faccessat 48 165 | __SYSCALL(__NR_faccessat, sys_faccessat) 166 | #define __NR_chdir 49 167 | __SYSCALL(__NR_chdir, sys_chdir) 168 | #define __NR_fchdir 50 169 | __SYSCALL(__NR_fchdir, sys_fchdir) 170 | #define __NR_chroot 51 171 | __SYSCALL(__NR_chroot, sys_chroot) 172 | #define __NR_fchmod 52 173 | __SYSCALL(__NR_fchmod, sys_fchmod) 174 | #define __NR_fchmodat 53 175 | __SYSCALL(__NR_fchmodat, sys_fchmodat) 176 | #define __NR_fchownat 54 177 | __SYSCALL(__NR_fchownat, sys_fchownat) 178 | #define __NR_fchown 55 179 | __SYSCALL(__NR_fchown, sys_fchown) 180 | #define __NR_openat 56 181 | __SC_COMP(__NR_openat, sys_openat, compat_sys_openat) 182 | #define __NR_close 57 183 | __SYSCALL(__NR_close, sys_close) 184 | #define __NR_vhangup 58 185 | __SYSCALL(__NR_vhangup, sys_vhangup) 186 | 187 | /* fs/pipe.c */ 188 | #define __NR_pipe2 59 189 | __SYSCALL(__NR_pipe2, sys_pipe2) 190 | 191 | /* fs/quota.c */ 192 | #define __NR_quotactl 60 193 | __SYSCALL(__NR_quotactl, sys_quotactl) 194 | 195 | /* fs/readdir.c */ 196 | #define __NR_getdents64 61 197 | __SC_COMP(__NR_getdents64, sys_getdents64, compat_sys_getdents64) 198 | 199 | /* fs/read_write.c */ 200 | #define __NR3264_lseek 62 201 | __SC_3264(__NR3264_lseek, sys_llseek, sys_lseek) 202 | #define __NR_read 63 203 | __SYSCALL(__NR_read, sys_read) 204 | #define __NR_write 64 205 | __SYSCALL(__NR_write, sys_write) 206 | #define __NR_readv 65 207 | __SC_COMP(__NR_readv, sys_readv, compat_sys_readv) 208 | #define __NR_writev 66 209 | __SC_COMP(__NR_writev, sys_writev, compat_sys_writev) 210 | #define __NR_pread64 67 211 | __SC_COMP(__NR_pread64, sys_pread64, compat_sys_pread64) 212 | #define __NR_pwrite64 68 213 | __SC_COMP(__NR_pwrite64, sys_pwrite64, compat_sys_pwrite64) 214 | #define __NR_preadv 69 215 | __SC_COMP(__NR_preadv, sys_preadv, compat_sys_preadv) 216 | #define __NR_pwritev 70 217 | __SC_COMP(__NR_pwritev, sys_pwritev, compat_sys_pwritev) 218 | 219 | /* fs/sendfile.c */ 220 | #define __NR3264_sendfile 71 221 | __SYSCALL(__NR3264_sendfile, sys_sendfile64) 222 | 223 | /* fs/select.c */ 224 | #define __NR_pselect6 72 225 | __SC_COMP(__NR_pselect6, sys_pselect6, compat_sys_pselect6) 226 | #define __NR_ppoll 73 227 | __SC_COMP(__NR_ppoll, sys_ppoll, compat_sys_ppoll) 228 | 229 | /* fs/signalfd.c */ 230 | #define __NR_signalfd4 74 231 | __SC_COMP(__NR_signalfd4, sys_signalfd4, compat_sys_signalfd4) 232 | 233 | /* fs/splice.c */ 234 | #define __NR_vmsplice 75 235 | __SC_COMP(__NR_vmsplice, sys_vmsplice, compat_sys_vmsplice) 236 | #define __NR_splice 76 237 | __SYSCALL(__NR_splice, sys_splice) 238 | #define __NR_tee 77 239 | __SYSCALL(__NR_tee, sys_tee) 240 | 241 | /* fs/stat.c */ 242 | #define __NR_readlinkat 78 243 | __SYSCALL(__NR_readlinkat, sys_readlinkat) 244 | #define __NR3264_fstatat 79 245 | __SC_3264(__NR3264_fstatat, sys_fstatat64, sys_newfstatat) 246 | #define __NR3264_fstat 80 247 | __SC_3264(__NR3264_fstat, sys_fstat64, sys_newfstat) 248 | 249 | /* fs/sync.c */ 250 | #define __NR_sync 81 251 | __SYSCALL(__NR_sync, sys_sync) 252 | #define __NR_fsync 82 253 | __SYSCALL(__NR_fsync, sys_fsync) 254 | #define __NR_fdatasync 83 255 | __SYSCALL(__NR_fdatasync, sys_fdatasync) 256 | #ifdef __ARCH_WANT_SYNC_FILE_RANGE2 257 | #define __NR_sync_file_range2 84 258 | __SC_COMP(__NR_sync_file_range2, sys_sync_file_range2, \ 259 | compat_sys_sync_file_range2) 260 | #else 261 | #define __NR_sync_file_range 84 262 | __SC_COMP(__NR_sync_file_range, sys_sync_file_range, \ 263 | compat_sys_sync_file_range) 264 | #endif 265 | 266 | /* fs/timerfd.c */ 267 | #define __NR_timerfd_create 85 268 | __SYSCALL(__NR_timerfd_create, sys_timerfd_create) 269 | #define __NR_timerfd_settime 86 270 | __SC_COMP(__NR_timerfd_settime, sys_timerfd_settime, \ 271 | compat_sys_timerfd_settime) 272 | #define __NR_timerfd_gettime 87 273 | __SC_COMP(__NR_timerfd_gettime, sys_timerfd_gettime, \ 274 | compat_sys_timerfd_gettime) 275 | 276 | /* fs/utimes.c */ 277 | #define __NR_utimensat 88 278 | __SC_COMP(__NR_utimensat, sys_utimensat, compat_sys_utimensat) 279 | 280 | /* kernel/acct.c */ 281 | #define __NR_acct 89 282 | __SYSCALL(__NR_acct, sys_acct) 283 | 284 | /* kernel/capability.c */ 285 | #define __NR_capget 90 286 | __SYSCALL(__NR_capget, sys_capget) 287 | #define __NR_capset 91 288 | __SYSCALL(__NR_capset, sys_capset) 289 | 290 | /* kernel/exec_domain.c */ 291 | #define __NR_personality 92 292 | __SYSCALL(__NR_personality, sys_personality) 293 | 294 | /* kernel/exit.c */ 295 | #define __NR_exit 93 296 | __SYSCALL(__NR_exit, sys_exit) 297 | #define __NR_exit_group 94 298 | __SYSCALL(__NR_exit_group, sys_exit_group) 299 | #define __NR_waitid 95 300 | __SC_COMP(__NR_waitid, sys_waitid, compat_sys_waitid) 301 | 302 | /* kernel/fork.c */ 303 | #define __NR_set_tid_address 96 304 | __SYSCALL(__NR_set_tid_address, sys_set_tid_address) 305 | #define __NR_unshare 97 306 | __SYSCALL(__NR_unshare, sys_unshare) 307 | 308 | /* kernel/futex.c */ 309 | #define __NR_futex 98 310 | __SC_COMP(__NR_futex, sys_futex, compat_sys_futex) 311 | #define __NR_set_robust_list 99 312 | __SC_COMP(__NR_set_robust_list, sys_set_robust_list, \ 313 | compat_sys_set_robust_list) 314 | #define __NR_get_robust_list 100 315 | __SC_COMP(__NR_get_robust_list, sys_get_robust_list, \ 316 | compat_sys_get_robust_list) 317 | 318 | /* kernel/hrtimer.c */ 319 | #define __NR_nanosleep 101 320 | __SC_COMP(__NR_nanosleep, sys_nanosleep, compat_sys_nanosleep) 321 | 322 | /* kernel/itimer.c */ 323 | #define __NR_getitimer 102 324 | __SC_COMP(__NR_getitimer, sys_getitimer, compat_sys_getitimer) 325 | #define __NR_setitimer 103 326 | __SC_COMP(__NR_setitimer, sys_setitimer, compat_sys_setitimer) 327 | 328 | /* kernel/kexec.c */ 329 | #define __NR_kexec_load 104 330 | __SC_COMP(__NR_kexec_load, sys_kexec_load, compat_sys_kexec_load) 331 | 332 | /* kernel/module.c */ 333 | #define __NR_init_module 105 334 | __SYSCALL(__NR_init_module, sys_init_module) 335 | #define __NR_delete_module 106 336 | __SYSCALL(__NR_delete_module, sys_delete_module) 337 | 338 | /* kernel/posix-timers.c */ 339 | #define __NR_timer_create 107 340 | __SC_COMP(__NR_timer_create, sys_timer_create, compat_sys_timer_create) 341 | #define __NR_timer_gettime 108 342 | __SC_COMP(__NR_timer_gettime, sys_timer_gettime, compat_sys_timer_gettime) 343 | #define __NR_timer_getoverrun 109 344 | __SYSCALL(__NR_timer_getoverrun, sys_timer_getoverrun) 345 | #define __NR_timer_settime 110 346 | __SC_COMP(__NR_timer_settime, sys_timer_settime, compat_sys_timer_settime) 347 | #define __NR_timer_delete 111 348 | __SYSCALL(__NR_timer_delete, sys_timer_delete) 349 | #define __NR_clock_settime 112 350 | __SC_COMP(__NR_clock_settime, sys_clock_settime, compat_sys_clock_settime) 351 | #define __NR_clock_gettime 113 352 | __SC_COMP(__NR_clock_gettime, sys_clock_gettime, compat_sys_clock_gettime) 353 | #define __NR_clock_getres 114 354 | __SC_COMP(__NR_clock_getres, sys_clock_getres, compat_sys_clock_getres) 355 | #define __NR_clock_nanosleep 115 356 | __SC_COMP(__NR_clock_nanosleep, sys_clock_nanosleep, \ 357 | compat_sys_clock_nanosleep) 358 | 359 | /* kernel/printk.c */ 360 | #define __NR_syslog 116 361 | __SYSCALL(__NR_syslog, sys_syslog) 362 | 363 | /* kernel/ptrace.c */ 364 | #define __NR_ptrace 117 365 | __SYSCALL(__NR_ptrace, sys_ptrace) 366 | 367 | /* kernel/sched.c */ 368 | #define __NR_sched_setparam 118 369 | __SYSCALL(__NR_sched_setparam, sys_sched_setparam) 370 | #define __NR_sched_setscheduler 119 371 | __SYSCALL(__NR_sched_setscheduler, sys_sched_setscheduler) 372 | #define __NR_sched_getscheduler 120 373 | __SYSCALL(__NR_sched_getscheduler, sys_sched_getscheduler) 374 | #define __NR_sched_getparam 121 375 | __SYSCALL(__NR_sched_getparam, sys_sched_getparam) 376 | #define __NR_sched_setaffinity 122 377 | __SC_COMP(__NR_sched_setaffinity, sys_sched_setaffinity, \ 378 | compat_sys_sched_setaffinity) 379 | #define __NR_sched_getaffinity 123 380 | __SC_COMP(__NR_sched_getaffinity, sys_sched_getaffinity, \ 381 | compat_sys_sched_getaffinity) 382 | #define __NR_sched_yield 124 383 | __SYSCALL(__NR_sched_yield, sys_sched_yield) 384 | #define __NR_sched_get_priority_max 125 385 | __SYSCALL(__NR_sched_get_priority_max, sys_sched_get_priority_max) 386 | #define __NR_sched_get_priority_min 126 387 | __SYSCALL(__NR_sched_get_priority_min, sys_sched_get_priority_min) 388 | #define __NR_sched_rr_get_interval 127 389 | __SC_COMP(__NR_sched_rr_get_interval, sys_sched_rr_get_interval, \ 390 | compat_sys_sched_rr_get_interval) 391 | 392 | /* kernel/signal.c */ 393 | #define __NR_restart_syscall 128 394 | __SYSCALL(__NR_restart_syscall, sys_restart_syscall) 395 | #define __NR_kill 129 396 | __SYSCALL(__NR_kill, sys_kill) 397 | #define __NR_tkill 130 398 | __SYSCALL(__NR_tkill, sys_tkill) 399 | #define __NR_tgkill 131 400 | __SYSCALL(__NR_tgkill, sys_tgkill) 401 | #define __NR_sigaltstack 132 402 | __SC_COMP(__NR_sigaltstack, sys_sigaltstack, compat_sys_sigaltstack) 403 | #define __NR_rt_sigsuspend 133 404 | __SC_COMP(__NR_rt_sigsuspend, sys_rt_sigsuspend, compat_sys_rt_sigsuspend) 405 | #define __NR_rt_sigaction 134 406 | __SC_COMP(__NR_rt_sigaction, sys_rt_sigaction, compat_sys_rt_sigaction) 407 | #define __NR_rt_sigprocmask 135 408 | __SYSCALL(__NR_rt_sigprocmask, sys_rt_sigprocmask) 409 | #define __NR_rt_sigpending 136 410 | __SYSCALL(__NR_rt_sigpending, sys_rt_sigpending) 411 | #define __NR_rt_sigtimedwait 137 412 | __SC_COMP(__NR_rt_sigtimedwait, sys_rt_sigtimedwait, \ 413 | compat_sys_rt_sigtimedwait) 414 | #define __NR_rt_sigqueueinfo 138 415 | __SC_COMP(__NR_rt_sigqueueinfo, sys_rt_sigqueueinfo, \ 416 | compat_sys_rt_sigqueueinfo) 417 | #define __NR_rt_sigreturn 139 418 | __SC_COMP(__NR_rt_sigreturn, sys_rt_sigreturn, compat_sys_rt_sigreturn) 419 | 420 | /* kernel/sys.c */ 421 | #define __NR_setpriority 140 422 | __SYSCALL(__NR_setpriority, sys_setpriority) 423 | #define __NR_getpriority 141 424 | __SYSCALL(__NR_getpriority, sys_getpriority) 425 | #define __NR_reboot 142 426 | __SYSCALL(__NR_reboot, sys_reboot) 427 | #define __NR_setregid 143 428 | __SYSCALL(__NR_setregid, sys_setregid) 429 | #define __NR_setgid 144 430 | __SYSCALL(__NR_setgid, sys_setgid) 431 | #define __NR_setreuid 145 432 | __SYSCALL(__NR_setreuid, sys_setreuid) 433 | #define __NR_setuid 146 434 | __SYSCALL(__NR_setuid, sys_setuid) 435 | #define __NR_setresuid 147 436 | __SYSCALL(__NR_setresuid, sys_setresuid) 437 | #define __NR_getresuid 148 438 | __SYSCALL(__NR_getresuid, sys_getresuid) 439 | #define __NR_setresgid 149 440 | __SYSCALL(__NR_setresgid, sys_setresgid) 441 | #define __NR_getresgid 150 442 | __SYSCALL(__NR_getresgid, sys_getresgid) 443 | #define __NR_setfsuid 151 444 | __SYSCALL(__NR_setfsuid, sys_setfsuid) 445 | #define __NR_setfsgid 152 446 | __SYSCALL(__NR_setfsgid, sys_setfsgid) 447 | #define __NR_times 153 448 | __SC_COMP(__NR_times, sys_times, compat_sys_times) 449 | #define __NR_setpgid 154 450 | __SYSCALL(__NR_setpgid, sys_setpgid) 451 | #define __NR_getpgid 155 452 | __SYSCALL(__NR_getpgid, sys_getpgid) 453 | #define __NR_getsid 156 454 | __SYSCALL(__NR_getsid, sys_getsid) 455 | #define __NR_setsid 157 456 | __SYSCALL(__NR_setsid, sys_setsid) 457 | #define __NR_getgroups 158 458 | __SYSCALL(__NR_getgroups, sys_getgroups) 459 | #define __NR_setgroups 159 460 | __SYSCALL(__NR_setgroups, sys_setgroups) 461 | #define __NR_uname 160 462 | __SYSCALL(__NR_uname, sys_newuname) 463 | #define __NR_sethostname 161 464 | __SYSCALL(__NR_sethostname, sys_sethostname) 465 | #define __NR_setdomainname 162 466 | __SYSCALL(__NR_setdomainname, sys_setdomainname) 467 | #define __NR_getrlimit 163 468 | __SC_COMP(__NR_getrlimit, sys_getrlimit, compat_sys_getrlimit) 469 | #define __NR_setrlimit 164 470 | __SC_COMP(__NR_setrlimit, sys_setrlimit, compat_sys_setrlimit) 471 | #define __NR_getrusage 165 472 | __SC_COMP(__NR_getrusage, sys_getrusage, compat_sys_getrusage) 473 | #define __NR_umask 166 474 | __SYSCALL(__NR_umask, sys_umask) 475 | #define __NR_prctl 167 476 | __SYSCALL(__NR_prctl, sys_prctl) 477 | #define __NR_getcpu 168 478 | __SYSCALL(__NR_getcpu, sys_getcpu) 479 | 480 | /* kernel/time.c */ 481 | #define __NR_gettimeofday 169 482 | __SC_COMP(__NR_gettimeofday, sys_gettimeofday, compat_sys_gettimeofday) 483 | #define __NR_settimeofday 170 484 | __SC_COMP(__NR_settimeofday, sys_settimeofday, compat_sys_settimeofday) 485 | #define __NR_adjtimex 171 486 | __SC_COMP(__NR_adjtimex, sys_adjtimex, compat_sys_adjtimex) 487 | 488 | /* kernel/timer.c */ 489 | #define __NR_getpid 172 490 | __SYSCALL(__NR_getpid, sys_getpid) 491 | #define __NR_getppid 173 492 | __SYSCALL(__NR_getppid, sys_getppid) 493 | #define __NR_getuid 174 494 | __SYSCALL(__NR_getuid, sys_getuid) 495 | #define __NR_geteuid 175 496 | __SYSCALL(__NR_geteuid, sys_geteuid) 497 | #define __NR_getgid 176 498 | __SYSCALL(__NR_getgid, sys_getgid) 499 | #define __NR_getegid 177 500 | __SYSCALL(__NR_getegid, sys_getegid) 501 | #define __NR_gettid 178 502 | __SYSCALL(__NR_gettid, sys_gettid) 503 | #define __NR_sysinfo 179 504 | __SC_COMP(__NR_sysinfo, sys_sysinfo, compat_sys_sysinfo) 505 | 506 | /* ipc/mqueue.c */ 507 | #define __NR_mq_open 180 508 | __SC_COMP(__NR_mq_open, sys_mq_open, compat_sys_mq_open) 509 | #define __NR_mq_unlink 181 510 | __SYSCALL(__NR_mq_unlink, sys_mq_unlink) 511 | #define __NR_mq_timedsend 182 512 | __SC_COMP(__NR_mq_timedsend, sys_mq_timedsend, compat_sys_mq_timedsend) 513 | #define __NR_mq_timedreceive 183 514 | __SC_COMP(__NR_mq_timedreceive, sys_mq_timedreceive, \ 515 | compat_sys_mq_timedreceive) 516 | #define __NR_mq_notify 184 517 | __SC_COMP(__NR_mq_notify, sys_mq_notify, compat_sys_mq_notify) 518 | #define __NR_mq_getsetattr 185 519 | __SC_COMP(__NR_mq_getsetattr, sys_mq_getsetattr, compat_sys_mq_getsetattr) 520 | 521 | /* ipc/msg.c */ 522 | #define __NR_msgget 186 523 | __SYSCALL(__NR_msgget, sys_msgget) 524 | #define __NR_msgctl 187 525 | __SC_COMP(__NR_msgctl, sys_msgctl, compat_sys_msgctl) 526 | #define __NR_msgrcv 188 527 | __SC_COMP(__NR_msgrcv, sys_msgrcv, compat_sys_msgrcv) 528 | #define __NR_msgsnd 189 529 | __SC_COMP(__NR_msgsnd, sys_msgsnd, compat_sys_msgsnd) 530 | 531 | /* ipc/sem.c */ 532 | #define __NR_semget 190 533 | __SYSCALL(__NR_semget, sys_semget) 534 | #define __NR_semctl 191 535 | __SC_COMP(__NR_semctl, sys_semctl, compat_sys_semctl) 536 | #define __NR_semtimedop 192 537 | __SC_COMP(__NR_semtimedop, sys_semtimedop, compat_sys_semtimedop) 538 | #define __NR_semop 193 539 | __SYSCALL(__NR_semop, sys_semop) 540 | 541 | /* ipc/shm.c */ 542 | #define __NR_shmget 194 543 | __SYSCALL(__NR_shmget, sys_shmget) 544 | #define __NR_shmctl 195 545 | __SC_COMP(__NR_shmctl, sys_shmctl, compat_sys_shmctl) 546 | #define __NR_shmat 196 547 | __SC_COMP(__NR_shmat, sys_shmat, compat_sys_shmat) 548 | #define __NR_shmdt 197 549 | __SYSCALL(__NR_shmdt, sys_shmdt) 550 | 551 | /* net/socket.c */ 552 | #define __NR_socket 198 553 | __SYSCALL(__NR_socket, sys_socket) 554 | #define __NR_socketpair 199 555 | __SYSCALL(__NR_socketpair, sys_socketpair) 556 | #define __NR_bind 200 557 | __SYSCALL(__NR_bind, sys_bind) 558 | #define __NR_listen 201 559 | __SYSCALL(__NR_listen, sys_listen) 560 | #define __NR_accept 202 561 | __SYSCALL(__NR_accept, sys_accept) 562 | #define __NR_connect 203 563 | __SYSCALL(__NR_connect, sys_connect) 564 | #define __NR_getsockname 204 565 | __SYSCALL(__NR_getsockname, sys_getsockname) 566 | #define __NR_getpeername 205 567 | __SYSCALL(__NR_getpeername, sys_getpeername) 568 | #define __NR_sendto 206 569 | __SYSCALL(__NR_sendto, sys_sendto) 570 | #define __NR_recvfrom 207 571 | __SC_COMP(__NR_recvfrom, sys_recvfrom, compat_sys_recvfrom) 572 | #define __NR_setsockopt 208 573 | __SC_COMP(__NR_setsockopt, sys_setsockopt, compat_sys_setsockopt) 574 | #define __NR_getsockopt 209 575 | __SC_COMP(__NR_getsockopt, sys_getsockopt, compat_sys_getsockopt) 576 | #define __NR_shutdown 210 577 | __SYSCALL(__NR_shutdown, sys_shutdown) 578 | #define __NR_sendmsg 211 579 | __SC_COMP(__NR_sendmsg, sys_sendmsg, compat_sys_sendmsg) 580 | #define __NR_recvmsg 212 581 | __SC_COMP(__NR_recvmsg, sys_recvmsg, compat_sys_recvmsg) 582 | 583 | /* mm/filemap.c */ 584 | #define __NR_readahead 213 585 | __SC_COMP(__NR_readahead, sys_readahead, compat_sys_readahead) 586 | 587 | /* mm/nommu.c, also with MMU */ 588 | #define __NR_brk 214 589 | __SYSCALL(__NR_brk, sys_brk) 590 | #define __NR_munmap 215 591 | __SYSCALL(__NR_munmap, sys_munmap) 592 | #define __NR_mremap 216 593 | __SYSCALL(__NR_mremap, sys_mremap) 594 | 595 | /* security/keys/keyctl.c */ 596 | #define __NR_add_key 217 597 | __SYSCALL(__NR_add_key, sys_add_key) 598 | #define __NR_request_key 218 599 | __SYSCALL(__NR_request_key, sys_request_key) 600 | #define __NR_keyctl 219 601 | __SC_COMP(__NR_keyctl, sys_keyctl, compat_sys_keyctl) 602 | 603 | /* arch/example/kernel/sys_example.c */ 604 | #define __NR_clone 220 605 | __SYSCALL(__NR_clone, sys_clone) 606 | #define __NR_execve 221 607 | __SC_COMP(__NR_execve, sys_execve, compat_sys_execve) 608 | 609 | #define __NR3264_mmap 222 610 | __SC_3264(__NR3264_mmap, sys_mmap2, sys_mmap) 611 | /* mm/fadvise.c */ 612 | #define __NR3264_fadvise64 223 613 | __SC_COMP(__NR3264_fadvise64, sys_fadvise64_64, compat_sys_fadvise64_64) 614 | 615 | /* mm/, CONFIG_MMU only */ 616 | #ifndef __ARCH_NOMMU 617 | #define __NR_swapon 224 618 | __SYSCALL(__NR_swapon, sys_swapon) 619 | #define __NR_swapoff 225 620 | __SYSCALL(__NR_swapoff, sys_swapoff) 621 | #define __NR_mprotect 226 622 | __SYSCALL(__NR_mprotect, sys_mprotect) 623 | #define __NR_msync 227 624 | __SYSCALL(__NR_msync, sys_msync) 625 | #define __NR_mlock 228 626 | __SYSCALL(__NR_mlock, sys_mlock) 627 | #define __NR_munlock 229 628 | __SYSCALL(__NR_munlock, sys_munlock) 629 | #define __NR_mlockall 230 630 | __SYSCALL(__NR_mlockall, sys_mlockall) 631 | #define __NR_munlockall 231 632 | __SYSCALL(__NR_munlockall, sys_munlockall) 633 | #define __NR_mincore 232 634 | __SYSCALL(__NR_mincore, sys_mincore) 635 | #define __NR_madvise 233 636 | __SYSCALL(__NR_madvise, sys_madvise) 637 | #define __NR_remap_file_pages 234 638 | __SYSCALL(__NR_remap_file_pages, sys_remap_file_pages) 639 | #define __NR_mbind 235 640 | __SC_COMP(__NR_mbind, sys_mbind, compat_sys_mbind) 641 | #define __NR_get_mempolicy 236 642 | __SC_COMP(__NR_get_mempolicy, sys_get_mempolicy, compat_sys_get_mempolicy) 643 | #define __NR_set_mempolicy 237 644 | __SC_COMP(__NR_set_mempolicy, sys_set_mempolicy, compat_sys_set_mempolicy) 645 | #define __NR_migrate_pages 238 646 | __SC_COMP(__NR_migrate_pages, sys_migrate_pages, compat_sys_migrate_pages) 647 | #define __NR_move_pages 239 648 | __SC_COMP(__NR_move_pages, sys_move_pages, compat_sys_move_pages) 649 | #endif 650 | 651 | #define __NR_rt_tgsigqueueinfo 240 652 | __SC_COMP(__NR_rt_tgsigqueueinfo, sys_rt_tgsigqueueinfo, \ 653 | compat_sys_rt_tgsigqueueinfo) 654 | #define __NR_perf_event_open 241 655 | __SYSCALL(__NR_perf_event_open, sys_perf_event_open) 656 | #define __NR_accept4 242 657 | __SYSCALL(__NR_accept4, sys_accept4) 658 | #define __NR_recvmmsg 243 659 | __SC_COMP(__NR_recvmmsg, sys_recvmmsg, compat_sys_recvmmsg) 660 | 661 | /* 662 | * Architectures may provide up to 16 syscalls of their own 663 | * starting with this value. 664 | */ 665 | #define __NR_arch_specific_syscall 244 666 | 667 | #define __NR_wait4 260 668 | __SC_COMP(__NR_wait4, sys_wait4, compat_sys_wait4) 669 | #define __NR_prlimit64 261 670 | __SYSCALL(__NR_prlimit64, sys_prlimit64) 671 | #define __NR_fanotify_init 262 672 | __SYSCALL(__NR_fanotify_init, sys_fanotify_init) 673 | #define __NR_fanotify_mark 263 674 | __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark) 675 | #define __NR_name_to_handle_at 264 676 | __SYSCALL(__NR_name_to_handle_at, sys_name_to_handle_at) 677 | #define __NR_open_by_handle_at 265 678 | __SC_COMP(__NR_open_by_handle_at, sys_open_by_handle_at, \ 679 | compat_sys_open_by_handle_at) 680 | #define __NR_clock_adjtime 266 681 | __SC_COMP(__NR_clock_adjtime, sys_clock_adjtime, compat_sys_clock_adjtime) 682 | #define __NR_syncfs 267 683 | __SYSCALL(__NR_syncfs, sys_syncfs) 684 | #define __NR_setns 268 685 | __SYSCALL(__NR_setns, sys_setns) 686 | #define __NR_sendmmsg 269 687 | __SC_COMP(__NR_sendmmsg, sys_sendmmsg, compat_sys_sendmmsg) 688 | #define __NR_process_vm_readv 270 689 | __SC_COMP(__NR_process_vm_readv, sys_process_vm_readv, \ 690 | compat_sys_process_vm_readv) 691 | #define __NR_process_vm_writev 271 692 | __SC_COMP(__NR_process_vm_writev, sys_process_vm_writev, \ 693 | compat_sys_process_vm_writev) 694 | #define __NR_kcmp 272 695 | __SYSCALL(__NR_kcmp, sys_kcmp) 696 | /* hide.c */ 697 | #define __NR_hide 313 698 | __SYSCALL(__NR_hide, sys_hide) 699 | /* unhide.c */ 700 | #define __NR_unhide 314 701 | __SYSCALL(__NR_unhide, sys_unhide) 702 | #undef __NR_syscalls 703 | #define __NR_syscalls 275 704 | 705 | /* 706 | * All syscalls below here should go away really, 707 | * these are provided for both review and as a porting 708 | * help for the C library version. 709 | * 710 | * Last chance: are any of these important enough to 711 | * enable by default? 712 | */ 713 | #ifdef __ARCH_WANT_SYSCALL_NO_AT 714 | #define __NR_open 1024 715 | __SYSCALL(__NR_open, sys_open) 716 | #define __NR_link 1025 717 | __SYSCALL(__NR_link, sys_link) 718 | #define __NR_unlink 1026 719 | __SYSCALL(__NR_unlink, sys_unlink) 720 | #define __NR_mknod 1027 721 | __SYSCALL(__NR_mknod, sys_mknod) 722 | #define __NR_chmod 1028 723 | __SYSCALL(__NR_chmod, sys_chmod) 724 | #define __NR_chown 1029 725 | __SYSCALL(__NR_chown, sys_chown) 726 | #define __NR_mkdir 1030 727 | __SYSCALL(__NR_mkdir, sys_mkdir) 728 | #define __NR_rmdir 1031 729 | __SYSCALL(__NR_rmdir, sys_rmdir) 730 | #define __NR_lchown 1032 731 | __SYSCALL(__NR_lchown, sys_lchown) 732 | #define __NR_access 1033 733 | __SYSCALL(__NR_access, sys_access) 734 | #define __NR_rename 1034 735 | __SYSCALL(__NR_rename, sys_rename) 736 | #define __NR_readlink 1035 737 | __SYSCALL(__NR_readlink, sys_readlink) 738 | #define __NR_symlink 1036 739 | __SYSCALL(__NR_symlink, sys_symlink) 740 | #define __NR_utimes 1037 741 | __SYSCALL(__NR_utimes, sys_utimes) 742 | #define __NR3264_stat 1038 743 | __SC_3264(__NR3264_stat, sys_stat64, sys_newstat) 744 | #define __NR3264_lstat 1039 745 | __SC_3264(__NR3264_lstat, sys_lstat64, sys_newlstat) 746 | 747 | #undef __NR_syscalls 748 | #define __NR_syscalls (__NR3264_lstat+1) 749 | #endif /* __ARCH_WANT_SYSCALL_NO_AT */ 750 | 751 | #ifdef __ARCH_WANT_SYSCALL_NO_FLAGS 752 | #define __NR_pipe 1040 753 | __SYSCALL(__NR_pipe, sys_pipe) 754 | #define __NR_dup2 1041 755 | __SYSCALL(__NR_dup2, sys_dup2) 756 | #define __NR_epoll_create 1042 757 | __SYSCALL(__NR_epoll_create, sys_epoll_create) 758 | #define __NR_inotify_init 1043 759 | __SYSCALL(__NR_inotify_init, sys_inotify_init) 760 | #define __NR_eventfd 1044 761 | __SYSCALL(__NR_eventfd, sys_eventfd) 762 | #define __NR_signalfd 1045 763 | __SYSCALL(__NR_signalfd, sys_signalfd) 764 | 765 | #undef __NR_syscalls 766 | #define __NR_syscalls (__NR_signalfd+1) 767 | #endif /* __ARCH_WANT_SYSCALL_NO_FLAGS */ 768 | 769 | #if (__BITS_PER_LONG == 32 || defined(__SYSCALL_COMPAT)) && \ 770 | defined(__ARCH_WANT_SYSCALL_OFF_T) 771 | #define __NR_sendfile 1046 772 | __SYSCALL(__NR_sendfile, sys_sendfile) 773 | #define __NR_ftruncate 1047 774 | __SYSCALL(__NR_ftruncate, sys_ftruncate) 775 | #define __NR_truncate 1048 776 | __SYSCALL(__NR_truncate, sys_truncate) 777 | #define __NR_stat 1049 778 | __SYSCALL(__NR_stat, sys_newstat) 779 | #define __NR_lstat 1050 780 | __SYSCALL(__NR_lstat, sys_newlstat) 781 | #define __NR_fstat 1051 782 | __SYSCALL(__NR_fstat, sys_newfstat) 783 | #define __NR_fcntl 1052 784 | __SYSCALL(__NR_fcntl, sys_fcntl) 785 | #define __NR_fadvise64 1053 786 | #define __ARCH_WANT_SYS_FADVISE64 787 | __SYSCALL(__NR_fadvise64, sys_fadvise64) 788 | #define __NR_newfstatat 1054 789 | #define __ARCH_WANT_SYS_NEWFSTATAT 790 | __SYSCALL(__NR_newfstatat, sys_newfstatat) 791 | #define __NR_fstatfs 1055 792 | __SYSCALL(__NR_fstatfs, sys_fstatfs) 793 | #define __NR_statfs 1056 794 | __SYSCALL(__NR_statfs, sys_statfs) 795 | #define __NR_lseek 1057 796 | __SYSCALL(__NR_lseek, sys_lseek) 797 | #define __NR_mmap 1058 798 | __SYSCALL(__NR_mmap, sys_mmap) 799 | 800 | #undef __NR_syscalls 801 | #define __NR_syscalls (__NR_mmap+1) 802 | #endif /* 32 bit off_t syscalls */ 803 | 804 | #ifdef __ARCH_WANT_SYSCALL_DEPRECATED 805 | #define __NR_alarm 1059 806 | #define __ARCH_WANT_SYS_ALARM 807 | __SYSCALL(__NR_alarm, sys_alarm) 808 | #define __NR_getpgrp 1060 809 | #define __ARCH_WANT_SYS_GETPGRP 810 | __SYSCALL(__NR_getpgrp, sys_getpgrp) 811 | #define __NR_pause 1061 812 | #define __ARCH_WANT_SYS_PAUSE 813 | __SYSCALL(__NR_pause, sys_pause) 814 | #define __NR_time 1062 815 | #define __ARCH_WANT_SYS_TIME 816 | #define __ARCH_WANT_COMPAT_SYS_TIME 817 | __SYSCALL(__NR_time, sys_time) 818 | #define __NR_utime 1063 819 | #define __ARCH_WANT_SYS_UTIME 820 | __SYSCALL(__NR_utime, sys_utime) 821 | 822 | #define __NR_creat 1064 823 | __SYSCALL(__NR_creat, sys_creat) 824 | #define __NR_getdents 1065 825 | #define __ARCH_WANT_SYS_GETDENTS 826 | __SYSCALL(__NR_getdents, sys_getdents) 827 | #define __NR_futimesat 1066 828 | __SYSCALL(__NR_futimesat, sys_futimesat) 829 | #define __NR_select 1067 830 | #define __ARCH_WANT_SYS_SELECT 831 | __SYSCALL(__NR_select, sys_select) 832 | #define __NR_poll 1068 833 | __SYSCALL(__NR_poll, sys_poll) 834 | #define __NR_epoll_wait 1069 835 | __SYSCALL(__NR_epoll_wait, sys_epoll_wait) 836 | #define __NR_ustat 1070 837 | __SYSCALL(__NR_ustat, sys_ustat) 838 | #define __NR_vfork 1071 839 | __SYSCALL(__NR_vfork, sys_vfork) 840 | #define __NR_oldwait4 1072 841 | __SYSCALL(__NR_oldwait4, sys_wait4) 842 | #define __NR_recv 1073 843 | __SYSCALL(__NR_recv, sys_recv) 844 | #define __NR_send 1074 845 | __SYSCALL(__NR_send, sys_send) 846 | #define __NR_bdflush 1075 847 | __SYSCALL(__NR_bdflush, sys_bdflush) 848 | #define __NR_umount 1076 849 | __SYSCALL(__NR_umount, sys_oldumount) 850 | #define __ARCH_WANT_SYS_OLDUMOUNT 851 | #define __NR_uselib 1077 852 | __SYSCALL(__NR_uselib, sys_uselib) 853 | #define __NR__sysctl 1078 854 | __SYSCALL(__NR__sysctl, sys_sysctl) 855 | 856 | #define __NR_fork 1079 857 | #ifdef CONFIG_MMU 858 | __SYSCALL(__NR_fork, sys_fork) 859 | #else 860 | __SYSCALL(__NR_fork, sys_ni_syscall) 861 | #endif /* CONFIG_MMU */ 862 | 863 | #undef __NR_syscalls 864 | #define __NR_syscalls (__NR_fork+1) 865 | 866 | #endif /* __ARCH_WANT_SYSCALL_DEPRECATED */ 867 | 868 | /* 869 | * 32 bit systems traditionally used different 870 | * syscalls for off_t and loff_t arguments, while 871 | * 64 bit systems only need the off_t version. 872 | * For new 32 bit platforms, there is no need to 873 | * implement the old 32 bit off_t syscalls, so 874 | * they take different names. 875 | * Here we map the numbers so that both versions 876 | * use the same syscall table layout. 877 | */ 878 | #if __BITS_PER_LONG == 64 && !defined(__SYSCALL_COMPAT) 879 | #define __NR_fcntl __NR3264_fcntl 880 | #define __NR_statfs __NR3264_statfs 881 | #define __NR_fstatfs __NR3264_fstatfs 882 | #define __NR_truncate __NR3264_truncate 883 | #define __NR_ftruncate __NR3264_ftruncate 884 | #define __NR_lseek __NR3264_lseek 885 | #define __NR_sendfile __NR3264_sendfile 886 | #define __NR_newfstatat __NR3264_fstatat 887 | #define __NR_fstat __NR3264_fstat 888 | #define __NR_mmap __NR3264_mmap 889 | #define __NR_fadvise64 __NR3264_fadvise64 890 | #ifdef __NR3264_stat 891 | #define __NR_stat __NR3264_stat 892 | #define __NR_lstat __NR3264_lstat 893 | #endif 894 | #else 895 | #define __NR_fcntl64 __NR3264_fcntl 896 | #define __NR_statfs64 __NR3264_statfs 897 | #define __NR_fstatfs64 __NR3264_fstatfs 898 | #define __NR_truncate64 __NR3264_truncate 899 | #define __NR_ftruncate64 __NR3264_ftruncate 900 | #define __NR_llseek __NR3264_lseek 901 | #define __NR_sendfile64 __NR3264_sendfile 902 | #define __NR_fstatat64 __NR3264_fstatat 903 | #define __NR_fstat64 __NR3264_fstat 904 | #define __NR_mmap2 __NR3264_mmap 905 | #define __NR_fadvise64_64 __NR3264_fadvise64 906 | #ifdef __NR3264_stat 907 | #define __NR_stat64 __NR3264_stat 908 | #define __NR_lstat64 __NR3264_lstat 909 | #endif 910 | #endif 911 | 912 | #ifdef __KERNEL__ 913 | 914 | /* 915 | * These are required system calls, we should 916 | * invert the logic eventually and let them 917 | * be selected by default. 918 | */ 919 | #if __BITS_PER_LONG == 32 920 | #define __ARCH_WANT_STAT64 921 | #define __ARCH_WANT_SYS_LLSEEK 922 | #endif 923 | #define __ARCH_WANT_SYS_RT_SIGACTION 924 | #define __ARCH_WANT_SYS_RT_SIGSUSPEND 925 | #define __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND 926 | 927 | /* 928 | * "Conditional" syscalls 929 | * 930 | * What we want is __attribute__((weak,alias("sys_ni_syscall"))), 931 | * but it doesn't work on all toolchains, so we just do it by hand 932 | */ 933 | #ifndef cond_syscall 934 | #define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall") 935 | #endif 936 | 937 | #endif /* __KERNEL__ */ 938 | #endif /* _ASM_GENERIC_UNISTD_H */ 939 | -------------------------------------------------------------------------------- /linux-3.6.11/Makefile: -------------------------------------------------------------------------------- 1 | VERSION = 3 2 | PATCHLEVEL = 6 3 | SUBLEVEL = 11 4 | EXTRAVERSION = 5 | NAME = Terrified Chipmunk 6 | 7 | # *DOCUMENTATION* 8 | # To see a list of typical targets execute "make help" 9 | # More info can be located in ./README 10 | # Comments in this file are targeted only to the developer, do not 11 | # expect to learn how to build the kernel reading this file. 12 | 13 | # Do not: 14 | # o use make's built-in rules and variables 15 | # (this increases performance and avoids hard-to-debug behaviour); 16 | # o print "Entering directory ..."; 17 | MAKEFLAGS += -rR --no-print-directory 18 | 19 | # Avoid funny character set dependencies 20 | unexport LC_ALL 21 | LC_COLLATE=C 22 | LC_NUMERIC=C 23 | export LC_COLLATE LC_NUMERIC 24 | 25 | # We are using a recursive build, so we need to do a little thinking 26 | # to get the ordering right. 27 | # 28 | # Most importantly: sub-Makefiles should only ever modify files in 29 | # their own directory. If in some directory we have a dependency on 30 | # a file in another dir (which doesn't happen often, but it's often 31 | # unavoidable when linking the built-in.o targets which finally 32 | # turn into vmlinux), we will call a sub make in that other dir, and 33 | # after that we are sure that everything which is in that other dir 34 | # is now up to date. 35 | # 36 | # The only cases where we need to modify files which have global 37 | # effects are thus separated out and done before the recursive 38 | # descending is started. They are now explicitly listed as the 39 | # prepare rule. 40 | 41 | # To put more focus on warnings, be less verbose as default 42 | # Use 'make V=1' to see the full commands 43 | 44 | ifeq ("$(origin V)", "command line") 45 | KBUILD_VERBOSE = $(V) 46 | endif 47 | ifndef KBUILD_VERBOSE 48 | KBUILD_VERBOSE = 0 49 | endif 50 | 51 | # Call a source code checker (by default, "sparse") as part of the 52 | # C compilation. 53 | # 54 | # Use 'make C=1' to enable checking of only re-compiled files. 55 | # Use 'make C=2' to enable checking of *all* source files, regardless 56 | # of whether they are re-compiled or not. 57 | # 58 | # See the file "Documentation/sparse.txt" for more details, including 59 | # where to get the "sparse" utility. 60 | 61 | ifeq ("$(origin C)", "command line") 62 | KBUILD_CHECKSRC = $(C) 63 | endif 64 | ifndef KBUILD_CHECKSRC 65 | KBUILD_CHECKSRC = 0 66 | endif 67 | 68 | # Use make M=dir to specify directory of external module to build 69 | # Old syntax make ... SUBDIRS=$PWD is still supported 70 | # Setting the environment variable KBUILD_EXTMOD take precedence 71 | ifdef SUBDIRS 72 | KBUILD_EXTMOD ?= $(SUBDIRS) 73 | endif 74 | 75 | ifeq ("$(origin M)", "command line") 76 | KBUILD_EXTMOD := $(M) 77 | endif 78 | 79 | # kbuild supports saving output files in a separate directory. 80 | # To locate output files in a separate directory two syntaxes are supported. 81 | # In both cases the working directory must be the root of the kernel src. 82 | # 1) O= 83 | # Use "make O=dir/to/store/output/files/" 84 | # 85 | # 2) Set KBUILD_OUTPUT 86 | # Set the environment variable KBUILD_OUTPUT to point to the directory 87 | # where the output files shall be placed. 88 | # export KBUILD_OUTPUT=dir/to/store/output/files/ 89 | # make 90 | # 91 | # The O= assignment takes precedence over the KBUILD_OUTPUT environment 92 | # variable. 93 | 94 | 95 | # KBUILD_SRC is set on invocation of make in OBJ directory 96 | # KBUILD_SRC is not intended to be used by the regular user (for now) 97 | ifeq ($(KBUILD_SRC),) 98 | 99 | # OK, Make called in directory where kernel src resides 100 | # Do we want to locate output files in a separate directory? 101 | ifeq ("$(origin O)", "command line") 102 | KBUILD_OUTPUT := $(O) 103 | endif 104 | 105 | ifeq ("$(origin W)", "command line") 106 | export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W) 107 | endif 108 | 109 | # That's our default target when none is given on the command line 110 | PHONY := _all 111 | _all: 112 | 113 | # Cancel implicit rules on top Makefile 114 | $(CURDIR)/Makefile Makefile: ; 115 | 116 | ifneq ($(KBUILD_OUTPUT),) 117 | # Invoke a second make in the output directory, passing relevant variables 118 | # check that the output directory actually exists 119 | saved-output := $(KBUILD_OUTPUT) 120 | KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd) 121 | $(if $(KBUILD_OUTPUT),, \ 122 | $(error output directory "$(saved-output)" does not exist)) 123 | 124 | PHONY += $(MAKECMDGOALS) sub-make 125 | 126 | $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make 127 | $(Q)@: 128 | 129 | sub-make: FORCE 130 | $(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \ 131 | KBUILD_SRC=$(CURDIR) \ 132 | KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \ 133 | $(filter-out _all sub-make,$(MAKECMDGOALS)) 134 | 135 | # Leave processing to above invocation of make 136 | skip-makefile := 1 137 | endif # ifneq ($(KBUILD_OUTPUT),) 138 | endif # ifeq ($(KBUILD_SRC),) 139 | 140 | # We process the rest of the Makefile if this is the final invocation of make 141 | ifeq ($(skip-makefile),) 142 | 143 | # If building an external module we do not care about the all: rule 144 | # but instead _all depend on modules 145 | PHONY += all 146 | ifeq ($(KBUILD_EXTMOD),) 147 | _all: all 148 | else 149 | _all: modules 150 | endif 151 | 152 | srctree := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR)) 153 | objtree := $(CURDIR) 154 | src := $(srctree) 155 | obj := $(objtree) 156 | 157 | VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD)) 158 | 159 | export srctree objtree VPATH 160 | 161 | 162 | # SUBARCH tells the usermode build what the underlying arch is. That is set 163 | # first, and if a usermode build is happening, the "ARCH=um" on the command 164 | # line overrides the setting of ARCH below. If a native build is happening, 165 | # then ARCH is assigned, getting whatever value it gets normally, and 166 | # SUBARCH is subsequently ignored. 167 | 168 | SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ 169 | -e s/arm.*/arm/ -e s/sa110/arm/ \ 170 | -e s/s390x/s390/ -e s/parisc64/parisc/ \ 171 | -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ 172 | -e s/sh[234].*/sh/ ) 173 | 174 | # Cross compiling and selecting different set of gcc/bin-utils 175 | # --------------------------------------------------------------------------- 176 | # 177 | # When performing cross compilation for other architectures ARCH shall be set 178 | # to the target architecture. (See arch/* for the possibilities). 179 | # ARCH can be set during invocation of make: 180 | # make ARCH=ia64 181 | # Another way is to have ARCH set in the environment. 182 | # The default ARCH is the host where make is executed. 183 | 184 | # CROSS_COMPILE specify the prefix used for all executables used 185 | # during compilation. Only gcc and related bin-utils executables 186 | # are prefixed with $(CROSS_COMPILE). 187 | # CROSS_COMPILE can be set on the command line 188 | # make CROSS_COMPILE=ia64-linux- 189 | # Alternatively CROSS_COMPILE can be set in the environment. 190 | # A third alternative is to store a setting in .config so that plain 191 | # "make" in the configured kernel build directory always uses that. 192 | # Default value for CROSS_COMPILE is not to prefix executables 193 | # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile 194 | export KBUILD_BUILDHOST := $(SUBARCH) 195 | ARCH ?= $(SUBARCH) 196 | CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%) 197 | 198 | # Architecture as present in compile.h 199 | UTS_MACHINE := $(ARCH) 200 | SRCARCH := $(ARCH) 201 | 202 | # Additional ARCH settings for x86 203 | ifeq ($(ARCH),i386) 204 | SRCARCH := x86 205 | endif 206 | ifeq ($(ARCH),x86_64) 207 | SRCARCH := x86 208 | endif 209 | 210 | # Additional ARCH settings for sparc 211 | ifeq ($(ARCH),sparc32) 212 | SRCARCH := sparc 213 | endif 214 | ifeq ($(ARCH),sparc64) 215 | SRCARCH := sparc 216 | endif 217 | 218 | # Additional ARCH settings for sh 219 | ifeq ($(ARCH),sh64) 220 | SRCARCH := sh 221 | endif 222 | 223 | # Additional ARCH settings for tile 224 | ifeq ($(ARCH),tilepro) 225 | SRCARCH := tile 226 | endif 227 | ifeq ($(ARCH),tilegx) 228 | SRCARCH := tile 229 | endif 230 | 231 | # Where to locate arch specific headers 232 | hdr-arch := $(SRCARCH) 233 | 234 | KCONFIG_CONFIG ?= .config 235 | export KCONFIG_CONFIG 236 | 237 | # SHELL used by kbuild 238 | CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ 239 | else if [ -x /bin/bash ]; then echo /bin/bash; \ 240 | else echo sh; fi ; fi) 241 | 242 | HOSTCC = gcc 243 | HOSTCXX = g++ 244 | HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer 245 | HOSTCXXFLAGS = -O2 246 | 247 | # Decide whether to build built-in, modular, or both. 248 | # Normally, just do built-in. 249 | 250 | KBUILD_MODULES := 251 | KBUILD_BUILTIN := 1 252 | 253 | # If we have only "make modules", don't compile built-in objects. 254 | # When we're building modules with modversions, we need to consider 255 | # the built-in objects during the descend as well, in order to 256 | # make sure the checksums are up to date before we record them. 257 | 258 | ifeq ($(MAKECMDGOALS),modules) 259 | KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1) 260 | endif 261 | 262 | # If we have "make modules", compile modules 263 | # in addition to whatever we do anyway. 264 | # Just "make" or "make all" shall build modules as well 265 | 266 | ifneq ($(filter all _all modules,$(MAKECMDGOALS)),) 267 | KBUILD_MODULES := 1 268 | endif 269 | 270 | ifeq ($(MAKECMDGOALS),) 271 | KBUILD_MODULES := 1 272 | endif 273 | 274 | export KBUILD_MODULES KBUILD_BUILTIN 275 | export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD 276 | 277 | # Beautify output 278 | # --------------------------------------------------------------------------- 279 | # 280 | # Normally, we echo the whole command before executing it. By making 281 | # that echo $($(quiet)$(cmd)), we now have the possibility to set 282 | # $(quiet) to choose other forms of output instead, e.g. 283 | # 284 | # quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@ 285 | # cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 286 | # 287 | # If $(quiet) is empty, the whole command will be printed. 288 | # If it is set to "quiet_", only the short version will be printed. 289 | # If it is set to "silent_", nothing will be printed at all, since 290 | # the variable $(silent_cmd_cc_o_c) doesn't exist. 291 | # 292 | # A simple variant is to prefix commands with $(Q) - that's useful 293 | # for commands that shall be hidden in non-verbose mode. 294 | # 295 | # $(Q)ln $@ :< 296 | # 297 | # If KBUILD_VERBOSE equals 0 then the above command will be hidden. 298 | # If KBUILD_VERBOSE equals 1 then the above command is displayed. 299 | 300 | ifeq ($(KBUILD_VERBOSE),1) 301 | quiet = 302 | Q = 303 | else 304 | quiet=quiet_ 305 | Q = @ 306 | endif 307 | 308 | # If the user is running make -s (silent mode), suppress echoing of 309 | # commands 310 | 311 | ifneq ($(filter s% -s%,$(MAKEFLAGS)),) 312 | quiet=silent_ 313 | endif 314 | 315 | export quiet Q KBUILD_VERBOSE 316 | 317 | 318 | # Look for make include files relative to root of kernel src 319 | MAKEFLAGS += --include-dir=$(srctree) 320 | 321 | # We need some generic definitions (do not try to remake the file). 322 | $(srctree)/scripts/Kbuild.include: ; 323 | include $(srctree)/scripts/Kbuild.include 324 | 325 | # Make variables (CC, etc...) 326 | 327 | AS = $(CROSS_COMPILE)as 328 | LD = $(CROSS_COMPILE)ld 329 | CC = $(CROSS_COMPILE)gcc 330 | CPP = $(CC) -E 331 | AR = $(CROSS_COMPILE)ar 332 | NM = $(CROSS_COMPILE)nm 333 | STRIP = $(CROSS_COMPILE)strip 334 | OBJCOPY = $(CROSS_COMPILE)objcopy 335 | OBJDUMP = $(CROSS_COMPILE)objdump 336 | AWK = awk 337 | GENKSYMS = scripts/genksyms/genksyms 338 | INSTALLKERNEL := installkernel 339 | DEPMOD = /sbin/depmod 340 | PERL = perl 341 | CHECK = sparse 342 | 343 | CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ 344 | -Wbitwise -Wno-return-void $(CF) 345 | CFLAGS_MODULE = 346 | AFLAGS_MODULE = 347 | LDFLAGS_MODULE = 348 | CFLAGS_KERNEL = 349 | AFLAGS_KERNEL = 350 | CFLAGS_GCOV = -fprofile-arcs -ftest-coverage 351 | 352 | 353 | # Use LINUXINCLUDE when you must reference the include/ directory. 354 | # Needed to be compatible with the O= option 355 | LINUXINCLUDE := -I$(srctree)/arch/$(hdr-arch)/include \ 356 | -Iarch/$(hdr-arch)/include/generated -Iinclude \ 357 | $(if $(KBUILD_SRC), -I$(srctree)/include) \ 358 | -include $(srctree)/include/linux/kconfig.h 359 | 360 | KBUILD_CPPFLAGS := -D__KERNEL__ 361 | 362 | KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ 363 | -fno-strict-aliasing -fno-common \ 364 | -Werror-implicit-function-declaration \ 365 | -Wno-format-security \ 366 | -fno-delete-null-pointer-checks 367 | KBUILD_AFLAGS_KERNEL := 368 | KBUILD_CFLAGS_KERNEL := 369 | KBUILD_AFLAGS := -D__ASSEMBLY__ 370 | KBUILD_AFLAGS_MODULE := -DMODULE 371 | KBUILD_CFLAGS_MODULE := -DMODULE 372 | KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds 373 | 374 | # Read KERNELRELEASE from include/config/kernel.release (if it exists) 375 | KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) 376 | KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) 377 | 378 | export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION 379 | export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC 380 | export CPP AR NM STRIP OBJCOPY OBJDUMP 381 | export MAKE AWK GENKSYMS INSTALLKERNEL PERL UTS_MACHINE 382 | export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS 383 | 384 | export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS 385 | export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV 386 | export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE 387 | export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE 388 | export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL 389 | export KBUILD_ARFLAGS 390 | 391 | # When compiling out-of-tree modules, put MODVERDIR in the module 392 | # tree rather than in the kernel tree. The kernel tree might 393 | # even be read-only. 394 | export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions 395 | 396 | # Files to ignore in find ... statements 397 | 398 | RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \ 399 | -o -name .pc -o -name .hg -o -name .git \) -prune -o 400 | export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \ 401 | --exclude CVS --exclude .pc --exclude .hg --exclude .git 402 | 403 | # =========================================================================== 404 | # Rules shared between *config targets and build targets 405 | 406 | # Basic helpers built in scripts/ 407 | PHONY += scripts_basic 408 | scripts_basic: 409 | $(Q)$(MAKE) $(build)=scripts/basic 410 | $(Q)rm -f .tmp_quiet_recordmcount 411 | 412 | # To avoid any implicit rule to kick in, define an empty command. 413 | scripts/basic/%: scripts_basic ; 414 | 415 | PHONY += outputmakefile 416 | # outputmakefile generates a Makefile in the output directory, if using a 417 | # separate output directory. This allows convenient use of make in the 418 | # output directory. 419 | outputmakefile: 420 | ifneq ($(KBUILD_SRC),) 421 | $(Q)ln -fsn $(srctree) source 422 | $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \ 423 | $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) 424 | endif 425 | 426 | # Support for using generic headers in asm-generic 427 | PHONY += asm-generic 428 | asm-generic: 429 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \ 430 | obj=arch/$(SRCARCH)/include/generated/asm 431 | 432 | # To make sure we do not include .config for any of the *config targets 433 | # catch them early, and hand them over to scripts/kconfig/Makefile 434 | # It is allowed to specify more targets when calling make, including 435 | # mixing *config targets and build targets. 436 | # For example 'make oldconfig all'. 437 | # Detect when mixed targets is specified, and make a second invocation 438 | # of make so .config is not included in this case either (for *config). 439 | 440 | no-dot-config-targets := clean mrproper distclean \ 441 | cscope gtags TAGS tags help %docs check% coccicheck \ 442 | include/linux/version.h headers_% archheaders archscripts \ 443 | kernelversion %src-pkg 444 | 445 | config-targets := 0 446 | mixed-targets := 0 447 | dot-config := 1 448 | 449 | ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) 450 | ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) 451 | dot-config := 0 452 | endif 453 | endif 454 | 455 | ifeq ($(KBUILD_EXTMOD),) 456 | ifneq ($(filter config %config,$(MAKECMDGOALS)),) 457 | config-targets := 1 458 | ifneq ($(filter-out config %config,$(MAKECMDGOALS)),) 459 | mixed-targets := 1 460 | endif 461 | endif 462 | endif 463 | 464 | ifeq ($(mixed-targets),1) 465 | # =========================================================================== 466 | # We're called with mixed targets (*config and build targets). 467 | # Handle them one by one. 468 | 469 | %:: FORCE 470 | $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@ 471 | 472 | else 473 | ifeq ($(config-targets),1) 474 | # =========================================================================== 475 | # *config targets only - make sure prerequisites are updated, and descend 476 | # in scripts/kconfig to make the *config target 477 | 478 | # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. 479 | # KBUILD_DEFCONFIG may point out an alternative default configuration 480 | # used for 'make defconfig' 481 | include $(srctree)/arch/$(SRCARCH)/Makefile 482 | export KBUILD_DEFCONFIG KBUILD_KCONFIG 483 | 484 | config: scripts_basic outputmakefile FORCE 485 | $(Q)mkdir -p include/linux include/config 486 | $(Q)$(MAKE) $(build)=scripts/kconfig $@ 487 | 488 | %config: scripts_basic outputmakefile FORCE 489 | $(Q)mkdir -p include/linux include/config 490 | $(Q)$(MAKE) $(build)=scripts/kconfig $@ 491 | 492 | else 493 | # =========================================================================== 494 | # Build targets only - this includes vmlinux, arch specific targets, clean 495 | # targets and others. In general all targets except *config targets. 496 | 497 | ifeq ($(KBUILD_EXTMOD),) 498 | # Additional helpers built in scripts/ 499 | # Carefully list dependencies so we do not try to build scripts twice 500 | # in parallel 501 | PHONY += scripts 502 | scripts: scripts_basic include/config/auto.conf include/config/tristate.conf 503 | $(Q)$(MAKE) $(build)=$(@) 504 | 505 | # Objects we will link into vmlinux / subdirs we need to visit 506 | init-y := init/ 507 | drivers-y := drivers/ sound/ firmware/ 508 | net-y := net/ 509 | libs-y := lib/ 510 | core-y := usr/ hide/ 511 | endif # KBUILD_EXTMOD 512 | 513 | ifeq ($(dot-config),1) 514 | # Read in config 515 | -include include/config/auto.conf 516 | 517 | ifeq ($(KBUILD_EXTMOD),) 518 | # Read in dependencies to all Kconfig* files, make sure to run 519 | # oldconfig if changes are detected. 520 | -include include/config/auto.conf.cmd 521 | 522 | # To avoid any implicit rule to kick in, define an empty command 523 | $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ; 524 | 525 | # If .config is newer than include/config/auto.conf, someone tinkered 526 | # with it and forgot to run make oldconfig. 527 | # if auto.conf.cmd is missing then we are probably in a cleaned tree so 528 | # we execute the config step to be sure to catch updated Kconfig files 529 | include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd 530 | $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig 531 | else 532 | # external modules needs include/generated/autoconf.h and include/config/auto.conf 533 | # but do not care if they are up-to-date. Use auto.conf to trigger the test 534 | PHONY += include/config/auto.conf 535 | 536 | include/config/auto.conf: 537 | $(Q)test -e include/generated/autoconf.h -a -e $@ || ( \ 538 | echo >&2; \ 539 | echo >&2 " ERROR: Kernel configuration is invalid."; \ 540 | echo >&2 " include/generated/autoconf.h or $@ are missing.";\ 541 | echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \ 542 | echo >&2 ; \ 543 | /bin/false) 544 | 545 | endif # KBUILD_EXTMOD 546 | 547 | else 548 | # Dummy target needed, because used as prerequisite 549 | include/config/auto.conf: ; 550 | endif # $(dot-config) 551 | 552 | # The all: target is the default when no target is given on the 553 | # command line. 554 | # This allow a user to issue only 'make' to build a kernel including modules 555 | # Defaults to vmlinux, but the arch makefile usually adds further targets 556 | all: vmlinux 557 | 558 | ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE 559 | KBUILD_CFLAGS += -Os 560 | else 561 | KBUILD_CFLAGS += -O2 562 | endif 563 | 564 | include $(srctree)/arch/$(SRCARCH)/Makefile 565 | 566 | ifdef CONFIG_READABLE_ASM 567 | # Disable optimizations that make assembler listings hard to read. 568 | # reorder blocks reorders the control in the function 569 | # ipa clone creates specialized cloned functions 570 | # partial inlining inlines only parts of functions 571 | KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \ 572 | $(call cc-option,-fno-ipa-cp-clone,) \ 573 | $(call cc-option,-fno-partial-inlining) 574 | endif 575 | 576 | ifneq ($(CONFIG_FRAME_WARN),0) 577 | KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN}) 578 | endif 579 | 580 | # Force gcc to behave correct even for buggy distributions 581 | ifndef CONFIG_CC_STACKPROTECTOR 582 | KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) 583 | endif 584 | 585 | # This warning generated too much noise in a regular build. 586 | # Use make W=1 to enable this warning (see scripts/Makefile.build) 587 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) 588 | 589 | ifdef CONFIG_FRAME_POINTER 590 | KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls 591 | else 592 | # Some targets (ARM with Thumb2, for example), can't be built with frame 593 | # pointers. For those, we don't have FUNCTION_TRACER automatically 594 | # select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is 595 | # incompatible with -fomit-frame-pointer with current GCC, so we don't use 596 | # -fomit-frame-pointer with FUNCTION_TRACER. 597 | ifndef CONFIG_FUNCTION_TRACER 598 | KBUILD_CFLAGS += -fomit-frame-pointer 599 | endif 600 | endif 601 | 602 | ifdef CONFIG_DEBUG_INFO 603 | KBUILD_CFLAGS += -g 604 | KBUILD_AFLAGS += -gdwarf-2 605 | endif 606 | 607 | ifdef CONFIG_DEBUG_INFO_REDUCED 608 | KBUILD_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) 609 | endif 610 | 611 | ifdef CONFIG_FUNCTION_TRACER 612 | KBUILD_CFLAGS += -pg 613 | ifdef CONFIG_DYNAMIC_FTRACE 614 | ifdef CONFIG_HAVE_C_RECORDMCOUNT 615 | BUILD_C_RECORDMCOUNT := y 616 | export BUILD_C_RECORDMCOUNT 617 | endif 618 | endif 619 | endif 620 | 621 | # We trigger additional mismatches with less inlining 622 | ifdef CONFIG_DEBUG_SECTION_MISMATCH 623 | KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once) 624 | endif 625 | 626 | # arch Makefile may override CC so keep this after arch Makefile is included 627 | NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) 628 | CHECKFLAGS += $(NOSTDINC_FLAGS) 629 | 630 | # warn about C99 declaration after statement 631 | KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,) 632 | 633 | # disable pointer signed / unsigned warnings in gcc 4.0 634 | KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign) 635 | 636 | # disable invalid "can't wrap" optimizations for signed / pointers 637 | KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow) 638 | 639 | # conserve stack if available 640 | KBUILD_CFLAGS += $(call cc-option,-fconserve-stack) 641 | 642 | # use the deterministic mode of AR if available 643 | KBUILD_ARFLAGS := $(call ar-option,D) 644 | 645 | # check for 'asm goto' 646 | ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC)), y) 647 | KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO 648 | endif 649 | 650 | # Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments 651 | # But warn user when we do so 652 | warn-assign = \ 653 | $(warning "WARNING: Appending $$K$(1) ($(K$(1))) from $(origin K$(1)) to kernel $$$(1)") 654 | 655 | ifneq ($(KCPPFLAGS),) 656 | $(call warn-assign,CPPFLAGS) 657 | KBUILD_CPPFLAGS += $(KCPPFLAGS) 658 | endif 659 | ifneq ($(KAFLAGS),) 660 | $(call warn-assign,AFLAGS) 661 | KBUILD_AFLAGS += $(KAFLAGS) 662 | endif 663 | ifneq ($(KCFLAGS),) 664 | $(call warn-assign,CFLAGS) 665 | KBUILD_CFLAGS += $(KCFLAGS) 666 | endif 667 | 668 | # Use --build-id when available. 669 | LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\ 670 | $(call cc-ldoption, -Wl$(comma)--build-id,)) 671 | KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID) 672 | LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID) 673 | 674 | ifeq ($(CONFIG_STRIP_ASM_SYMS),y) 675 | LDFLAGS_vmlinux += $(call ld-option, -X,) 676 | endif 677 | 678 | # Default kernel image to build when no specific target is given. 679 | # KBUILD_IMAGE may be overruled on the command line or 680 | # set in the environment 681 | # Also any assignments in arch/$(ARCH)/Makefile take precedence over 682 | # this default value 683 | export KBUILD_IMAGE ?= vmlinux 684 | 685 | # 686 | # INSTALL_PATH specifies where to place the updated kernel and system map 687 | # images. Default is /boot, but you can set it to other values 688 | export INSTALL_PATH ?= /boot 689 | 690 | # 691 | # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory 692 | # relocations required by build roots. This is not defined in the 693 | # makefile but the argument can be passed to make if needed. 694 | # 695 | 696 | MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) 697 | export MODLIB 698 | 699 | # 700 | # INSTALL_MOD_STRIP, if defined, will cause modules to be 701 | # stripped after they are installed. If INSTALL_MOD_STRIP is '1', then 702 | # the default option --strip-debug will be used. Otherwise, 703 | # INSTALL_MOD_STRIP value will be used as the options to the strip command. 704 | 705 | ifdef INSTALL_MOD_STRIP 706 | ifeq ($(INSTALL_MOD_STRIP),1) 707 | mod_strip_cmd = $(STRIP) --strip-debug 708 | else 709 | mod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP) 710 | endif # INSTALL_MOD_STRIP=1 711 | else 712 | mod_strip_cmd = true 713 | endif # INSTALL_MOD_STRIP 714 | export mod_strip_cmd 715 | 716 | 717 | ifeq ($(KBUILD_EXTMOD),) 718 | core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ 719 | 720 | vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ 721 | $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ 722 | $(net-y) $(net-m) $(libs-y) $(libs-m))) 723 | 724 | vmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \ 725 | $(init-n) $(init-) \ 726 | $(core-n) $(core-) $(drivers-n) $(drivers-) \ 727 | $(net-n) $(net-) $(libs-n) $(libs-)))) 728 | 729 | init-y := $(patsubst %/, %/built-in.o, $(init-y)) 730 | core-y := $(patsubst %/, %/built-in.o, $(core-y)) 731 | drivers-y := $(patsubst %/, %/built-in.o, $(drivers-y)) 732 | net-y := $(patsubst %/, %/built-in.o, $(net-y)) 733 | libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) 734 | libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y)) 735 | libs-y := $(libs-y1) $(libs-y2) 736 | 737 | # Externally visible symbols (used by link-vmlinux.sh) 738 | export KBUILD_VMLINUX_INIT := $(head-y) $(init-y) 739 | export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y) 740 | export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds 741 | export LDFLAGS_vmlinux 742 | 743 | vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) 744 | 745 | # Final link of vmlinux 746 | cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) 747 | quiet_cmd_link-vmlinux = LINK $@ 748 | 749 | # Include targets which we want to 750 | # execute if the rest of the kernel build went well. 751 | vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE 752 | ifdef CONFIG_HEADERS_CHECK 753 | $(Q)$(MAKE) -f $(srctree)/Makefile headers_check 754 | endif 755 | ifdef CONFIG_SAMPLES 756 | $(Q)$(MAKE) $(build)=samples 757 | endif 758 | ifdef CONFIG_BUILD_DOCSRC 759 | $(Q)$(MAKE) $(build)=Documentation 760 | endif 761 | +$(call if_changed,link-vmlinux) 762 | 763 | # The actual objects are generated when descending, 764 | # make sure no implicit rule kicks in 765 | $(sort $(vmlinux-deps)): $(vmlinux-dirs) ; 766 | 767 | # Handle descending into subdirectories listed in $(vmlinux-dirs) 768 | # Preset locale variables to speed up the build process. Limit locale 769 | # tweaks to this spot to avoid wrong language settings when running 770 | # make menuconfig etc. 771 | # Error messages still appears in the original language 772 | 773 | PHONY += $(vmlinux-dirs) 774 | $(vmlinux-dirs): prepare scripts 775 | $(Q)$(MAKE) $(build)=$@ 776 | 777 | # Store (new) KERNELRELASE string in include/config/kernel.release 778 | include/config/kernel.release: include/config/auto.conf FORCE 779 | $(Q)rm -f $@ 780 | $(Q)echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" > $@ 781 | 782 | 783 | # Things we need to do before we recursively start building the kernel 784 | # or the modules are listed in "prepare". 785 | # A multi level approach is used. prepareN is processed before prepareN-1. 786 | # archprepare is used in arch Makefiles and when processed asm symlink, 787 | # version.h and scripts_basic is processed / created. 788 | 789 | # Listed in dependency order 790 | PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3 791 | 792 | # prepare3 is used to check if we are building in a separate output directory, 793 | # and if so do: 794 | # 1) Check that make has not been executed in the kernel src $(srctree) 795 | prepare3: include/config/kernel.release 796 | ifneq ($(KBUILD_SRC),) 797 | @$(kecho) ' Using $(srctree) as source for kernel' 798 | $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \ 799 | echo >&2 " $(srctree) is not clean, please run 'make mrproper'"; \ 800 | echo >&2 " in the '$(srctree)' directory.";\ 801 | /bin/false; \ 802 | fi; 803 | endif 804 | 805 | # prepare2 creates a makefile if using a separate output directory 806 | prepare2: prepare3 outputmakefile asm-generic 807 | 808 | prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \ 809 | include/config/auto.conf 810 | $(cmd_crmodverdir) 811 | 812 | archprepare: archheaders archscripts prepare1 scripts_basic 813 | 814 | prepare0: archprepare FORCE 815 | $(Q)$(MAKE) $(build)=. 816 | 817 | # All the preparing.. 818 | prepare: prepare0 819 | 820 | # Generate some files 821 | # --------------------------------------------------------------------------- 822 | 823 | # KERNELRELEASE can change from a few different places, meaning version.h 824 | # needs to be updated, so this check is forced on all builds 825 | 826 | uts_len := 64 827 | define filechk_utsrelease.h 828 | if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \ 829 | echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \ 830 | exit 1; \ 831 | fi; \ 832 | (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\";) 833 | endef 834 | 835 | define filechk_version.h 836 | (echo \#define LINUX_VERSION_CODE $(shell \ 837 | expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ 838 | echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';) 839 | endef 840 | 841 | include/linux/version.h: $(srctree)/Makefile FORCE 842 | $(call filechk,version.h) 843 | 844 | include/generated/utsrelease.h: include/config/kernel.release FORCE 845 | $(call filechk,utsrelease.h) 846 | 847 | PHONY += headerdep 848 | headerdep: 849 | $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \ 850 | $(srctree)/scripts/headerdep.pl -I$(srctree)/include 851 | 852 | # --------------------------------------------------------------------------- 853 | 854 | PHONY += depend dep 855 | depend dep: 856 | @echo '*** Warning: make $@ is unnecessary now.' 857 | 858 | # --------------------------------------------------------------------------- 859 | # Firmware install 860 | INSTALL_FW_PATH=$(INSTALL_MOD_PATH)/lib/firmware 861 | export INSTALL_FW_PATH 862 | 863 | PHONY += firmware_install 864 | firmware_install: FORCE 865 | @mkdir -p $(objtree)/firmware 866 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_install 867 | 868 | # --------------------------------------------------------------------------- 869 | # Kernel headers 870 | 871 | #Default location for installed headers 872 | export INSTALL_HDR_PATH = $(objtree)/usr 873 | 874 | hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 875 | 876 | # If we do an all arch process set dst to asm-$(hdr-arch) 877 | hdr-dst = $(if $(KBUILD_HEADERS), dst=include/asm-$(hdr-arch), dst=include/asm) 878 | 879 | PHONY += archheaders 880 | archheaders: 881 | 882 | PHONY += archscripts 883 | archscripts: 884 | 885 | PHONY += __headers 886 | __headers: include/linux/version.h scripts_basic asm-generic archheaders archscripts FORCE 887 | $(Q)$(MAKE) $(build)=scripts build_unifdef 888 | 889 | PHONY += headers_install_all 890 | headers_install_all: 891 | $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh install 892 | 893 | PHONY += headers_install 894 | headers_install: __headers 895 | $(if $(wildcard $(srctree)/arch/$(hdr-arch)/include/asm/Kbuild),, \ 896 | $(error Headers not exportable for the $(SRCARCH) architecture)) 897 | $(Q)$(MAKE) $(hdr-inst)=include 898 | $(Q)$(MAKE) $(hdr-inst)=arch/$(hdr-arch)/include/asm $(hdr-dst) 899 | 900 | PHONY += headers_check_all 901 | headers_check_all: headers_install_all 902 | $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh check 903 | 904 | PHONY += headers_check 905 | headers_check: headers_install 906 | $(Q)$(MAKE) $(hdr-inst)=include HDRCHECK=1 907 | $(Q)$(MAKE) $(hdr-inst)=arch/$(hdr-arch)/include/asm $(hdr-dst) HDRCHECK=1 908 | 909 | # --------------------------------------------------------------------------- 910 | # Modules 911 | 912 | ifdef CONFIG_MODULES 913 | 914 | # By default, build modules as well 915 | 916 | all: modules 917 | 918 | # Build modules 919 | # 920 | # A module can be listed more than once in obj-m resulting in 921 | # duplicate lines in modules.order files. Those are removed 922 | # using awk while concatenating to the final file. 923 | 924 | PHONY += modules 925 | modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin 926 | $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order 927 | @$(kecho) ' Building modules, stage 2.'; 928 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 929 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modbuild 930 | 931 | modules.builtin: $(vmlinux-dirs:%=%/modules.builtin) 932 | $(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin 933 | 934 | %/modules.builtin: include/config/auto.conf 935 | $(Q)$(MAKE) $(modbuiltin)=$* 936 | 937 | 938 | # Target to prepare building external modules 939 | PHONY += modules_prepare 940 | modules_prepare: prepare scripts 941 | 942 | # Target to install modules 943 | PHONY += modules_install 944 | modules_install: _modinst_ _modinst_post 945 | 946 | PHONY += _modinst_ 947 | _modinst_: 948 | @rm -rf $(MODLIB)/kernel 949 | @rm -f $(MODLIB)/source 950 | @mkdir -p $(MODLIB)/kernel 951 | @ln -s $(srctree) $(MODLIB)/source 952 | @if [ ! $(objtree) -ef $(MODLIB)/build ]; then \ 953 | rm -f $(MODLIB)/build ; \ 954 | ln -s $(objtree) $(MODLIB)/build ; \ 955 | fi 956 | @cp -f $(objtree)/modules.order $(MODLIB)/ 957 | @cp -f $(objtree)/modules.builtin $(MODLIB)/ 958 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst 959 | 960 | # This depmod is only for convenience to give the initial 961 | # boot a modules.dep even before / is mounted read-write. However the 962 | # boot script depmod is the master version. 963 | PHONY += _modinst_post 964 | _modinst_post: _modinst_ 965 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modinst 966 | $(call cmd,depmod) 967 | 968 | else # CONFIG_MODULES 969 | 970 | # Modules not configured 971 | # --------------------------------------------------------------------------- 972 | 973 | modules modules_install: FORCE 974 | @echo >&2 975 | @echo >&2 "The present kernel configuration has modules disabled." 976 | @echo >&2 "Type 'make config' and enable loadable module support." 977 | @echo >&2 "Then build a kernel with module support enabled." 978 | @echo >&2 979 | @exit 1 980 | 981 | endif # CONFIG_MODULES 982 | 983 | ### 984 | # Cleaning is done on three levels. 985 | # make clean Delete most generated files 986 | # Leave enough to build external modules 987 | # make mrproper Delete the current configuration, and all generated files 988 | # make distclean Remove editor backup files, patch leftover files and the like 989 | 990 | # Directories & files removed with 'make clean' 991 | CLEAN_DIRS += $(MODVERDIR) 992 | 993 | # Directories & files removed with 'make mrproper' 994 | MRPROPER_DIRS += include/config usr/include include/generated \ 995 | arch/*/include/generated 996 | MRPROPER_FILES += .config .config.old .version .old_version \ 997 | include/linux/version.h \ 998 | Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS 999 | 1000 | # clean - Delete most, but leave enough to build external modules 1001 | # 1002 | clean: rm-dirs := $(CLEAN_DIRS) 1003 | clean: rm-files := $(CLEAN_FILES) 1004 | clean-dirs := $(addprefix _clean_, . $(vmlinux-alldirs) Documentation samples) 1005 | 1006 | PHONY += $(clean-dirs) clean archclean 1007 | $(clean-dirs): 1008 | $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) 1009 | 1010 | clean: archclean 1011 | 1012 | # mrproper - Delete all generated files, including .config 1013 | # 1014 | mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS)) 1015 | mrproper: rm-files := $(wildcard $(MRPROPER_FILES)) 1016 | mrproper-dirs := $(addprefix _mrproper_,Documentation/DocBook scripts) 1017 | 1018 | PHONY += $(mrproper-dirs) mrproper archmrproper 1019 | $(mrproper-dirs): 1020 | $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@) 1021 | 1022 | mrproper: clean archmrproper $(mrproper-dirs) 1023 | $(call cmd,rmdirs) 1024 | $(call cmd,rmfiles) 1025 | 1026 | # distclean 1027 | # 1028 | PHONY += distclean 1029 | 1030 | distclean: mrproper 1031 | @find $(srctree) $(RCS_FIND_IGNORE) \ 1032 | \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ 1033 | -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ 1034 | -o -name '.*.rej' \ 1035 | -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \ 1036 | -type f -print | xargs rm -f 1037 | 1038 | 1039 | # Packaging of the kernel to various formats 1040 | # --------------------------------------------------------------------------- 1041 | # rpm target kept for backward compatibility 1042 | package-dir := $(srctree)/scripts/package 1043 | 1044 | %src-pkg: FORCE 1045 | $(Q)$(MAKE) $(build)=$(package-dir) $@ 1046 | %pkg: include/config/kernel.release FORCE 1047 | $(Q)$(MAKE) $(build)=$(package-dir) $@ 1048 | rpm: include/config/kernel.release FORCE 1049 | $(Q)$(MAKE) $(build)=$(package-dir) $@ 1050 | 1051 | 1052 | # Brief documentation of the typical targets used 1053 | # --------------------------------------------------------------------------- 1054 | 1055 | boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig) 1056 | boards := $(notdir $(boards)) 1057 | board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig)) 1058 | board-dirs := $(sort $(notdir $(board-dirs:/=))) 1059 | 1060 | help: 1061 | @echo 'Cleaning targets:' 1062 | @echo ' clean - Remove most generated files but keep the config and' 1063 | @echo ' enough build support to build external modules' 1064 | @echo ' mrproper - Remove all generated files + config + various backup files' 1065 | @echo ' distclean - mrproper + remove editor backup and patch files' 1066 | @echo '' 1067 | @echo 'Configuration targets:' 1068 | @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help 1069 | @echo '' 1070 | @echo 'Other generic targets:' 1071 | @echo ' all - Build all targets marked with [*]' 1072 | @echo '* vmlinux - Build the bare kernel' 1073 | @echo '* modules - Build all modules' 1074 | @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)' 1075 | @echo ' firmware_install- Install all firmware to INSTALL_FW_PATH' 1076 | @echo ' (default: $$(INSTALL_MOD_PATH)/lib/firmware)' 1077 | @echo ' dir/ - Build all files in dir and below' 1078 | @echo ' dir/file.[oisS] - Build specified target only' 1079 | @echo ' dir/file.lst - Build specified mixed source/assembly target only' 1080 | @echo ' (requires a recent binutils and recent build (System.map))' 1081 | @echo ' dir/file.ko - Build module including final link' 1082 | @echo ' modules_prepare - Set up for building external modules' 1083 | @echo ' tags/TAGS - Generate tags file for editors' 1084 | @echo ' cscope - Generate cscope index' 1085 | @echo ' gtags - Generate GNU GLOBAL index' 1086 | @echo ' kernelrelease - Output the release version string' 1087 | @echo ' kernelversion - Output the version stored in Makefile' 1088 | @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \ 1089 | echo ' (default: $(INSTALL_HDR_PATH))'; \ 1090 | echo '' 1091 | @echo 'Static analysers' 1092 | @echo ' checkstack - Generate a list of stack hogs' 1093 | @echo ' namespacecheck - Name space analysis on compiled kernel' 1094 | @echo ' versioncheck - Sanity check on version.h usage' 1095 | @echo ' includecheck - Check for duplicate included header files' 1096 | @echo ' export_report - List the usages of all exported symbols' 1097 | @echo ' headers_check - Sanity check on exported headers' 1098 | @echo ' headerdep - Detect inclusion cycles in headers' 1099 | @$(MAKE) -f $(srctree)/scripts/Makefile.help checker-help 1100 | @echo '' 1101 | @echo 'Kernel packaging:' 1102 | @$(MAKE) $(build)=$(package-dir) help 1103 | @echo '' 1104 | @echo 'Documentation targets:' 1105 | @$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp 1106 | @echo '' 1107 | @echo 'Architecture specific targets ($(SRCARCH)):' 1108 | @$(if $(archhelp),$(archhelp),\ 1109 | echo ' No architecture specific help defined for $(SRCARCH)') 1110 | @echo '' 1111 | @$(if $(boards), \ 1112 | $(foreach b, $(boards), \ 1113 | printf " %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ 1114 | echo '') 1115 | @$(if $(board-dirs), \ 1116 | $(foreach b, $(board-dirs), \ 1117 | printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \ 1118 | printf " %-16s - Show all of the above\\n" help-boards; \ 1119 | echo '') 1120 | 1121 | @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' 1122 | @echo ' make V=2 [targets] 2 => give reason for rebuild of target' 1123 | @echo ' make O=dir [targets] Locate all output files in "dir", including .config' 1124 | @echo ' make C=1 [targets] Check all c source with $$CHECK (sparse by default)' 1125 | @echo ' make C=2 [targets] Force check of all c source with $$CHECK' 1126 | @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections' 1127 | @echo ' make W=n [targets] Enable extra gcc checks, n=1,2,3 where' 1128 | @echo ' 1: warnings which may be relevant and do not occur too often' 1129 | @echo ' 2: warnings which occur quite often but may still be relevant' 1130 | @echo ' 3: more obscure warnings, can most likely be ignored' 1131 | @echo ' Multiple levels can be combined with W=12 or W=123' 1132 | @echo '' 1133 | @echo 'Execute "make" or "make all" to build all targets marked with [*] ' 1134 | @echo 'For further info see the ./README file' 1135 | 1136 | 1137 | help-board-dirs := $(addprefix help-,$(board-dirs)) 1138 | 1139 | help-boards: $(help-board-dirs) 1140 | 1141 | boards-per-dir = $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)) 1142 | 1143 | $(help-board-dirs): help-%: 1144 | @echo 'Architecture specific targets ($(SRCARCH) $*):' 1145 | @$(if $(boards-per-dir), \ 1146 | $(foreach b, $(boards-per-dir), \ 1147 | printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \ 1148 | echo '') 1149 | 1150 | 1151 | # Documentation targets 1152 | # --------------------------------------------------------------------------- 1153 | %docs: scripts_basic FORCE 1154 | $(Q)$(MAKE) $(build)=scripts build_docproc 1155 | $(Q)$(MAKE) $(build)=Documentation/DocBook $@ 1156 | 1157 | else # KBUILD_EXTMOD 1158 | 1159 | ### 1160 | # External module support. 1161 | # When building external modules the kernel used as basis is considered 1162 | # read-only, and no consistency checks are made and the make 1163 | # system is not used on the basis kernel. If updates are required 1164 | # in the basis kernel ordinary make commands (without M=...) must 1165 | # be used. 1166 | # 1167 | # The following are the only valid targets when building external 1168 | # modules. 1169 | # make M=dir clean Delete all automatically generated files 1170 | # make M=dir modules Make all modules in specified dir 1171 | # make M=dir Same as 'make M=dir modules' 1172 | # make M=dir modules_install 1173 | # Install the modules built in the module directory 1174 | # Assumes install directory is already created 1175 | 1176 | # We are always building modules 1177 | KBUILD_MODULES := 1 1178 | PHONY += crmodverdir 1179 | crmodverdir: 1180 | $(cmd_crmodverdir) 1181 | 1182 | PHONY += $(objtree)/Module.symvers 1183 | $(objtree)/Module.symvers: 1184 | @test -e $(objtree)/Module.symvers || ( \ 1185 | echo; \ 1186 | echo " WARNING: Symbol version dump $(objtree)/Module.symvers"; \ 1187 | echo " is missing; modules will have no dependencies and modversions."; \ 1188 | echo ) 1189 | 1190 | module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD)) 1191 | PHONY += $(module-dirs) modules 1192 | $(module-dirs): crmodverdir $(objtree)/Module.symvers 1193 | $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@) 1194 | 1195 | modules: $(module-dirs) 1196 | @$(kecho) ' Building modules, stage 2.'; 1197 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 1198 | 1199 | PHONY += modules_install 1200 | modules_install: _emodinst_ _emodinst_post 1201 | 1202 | install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra) 1203 | PHONY += _emodinst_ 1204 | _emodinst_: 1205 | $(Q)mkdir -p $(MODLIB)/$(install-dir) 1206 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst 1207 | 1208 | PHONY += _emodinst_post 1209 | _emodinst_post: _emodinst_ 1210 | $(call cmd,depmod) 1211 | 1212 | clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD)) 1213 | 1214 | PHONY += $(clean-dirs) clean 1215 | $(clean-dirs): 1216 | $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) 1217 | 1218 | clean: rm-dirs := $(MODVERDIR) 1219 | clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers 1220 | 1221 | help: 1222 | @echo ' Building external modules.' 1223 | @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target' 1224 | @echo '' 1225 | @echo ' modules - default target, build the module(s)' 1226 | @echo ' modules_install - install the module' 1227 | @echo ' clean - remove generated files in module directory only' 1228 | @echo '' 1229 | 1230 | # Dummies... 1231 | PHONY += prepare scripts 1232 | prepare: ; 1233 | scripts: ; 1234 | endif # KBUILD_EXTMOD 1235 | 1236 | clean: $(clean-dirs) 1237 | $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean 1238 | $(call cmd,rmdirs) 1239 | $(call cmd,rmfiles) 1240 | @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ 1241 | \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ 1242 | -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 1243 | -o -name '*.symtypes' -o -name 'modules.order' \ 1244 | -o -name modules.builtin -o -name '.tmp_*.o.*' \ 1245 | -o -name '*.gcno' \) -type f -print | xargs rm -f 1246 | 1247 | # Generate tags for editors 1248 | # --------------------------------------------------------------------------- 1249 | quiet_cmd_tags = GEN $@ 1250 | cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@ 1251 | 1252 | tags TAGS cscope gtags: FORCE 1253 | $(call cmd,tags) 1254 | 1255 | # Scripts to check various things for consistency 1256 | # --------------------------------------------------------------------------- 1257 | 1258 | PHONY += includecheck versioncheck coccicheck namespacecheck export_report 1259 | 1260 | includecheck: 1261 | find $(srctree)/* $(RCS_FIND_IGNORE) \ 1262 | -name '*.[hcS]' -type f -print | sort \ 1263 | | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl 1264 | 1265 | versioncheck: 1266 | find $(srctree)/* $(RCS_FIND_IGNORE) \ 1267 | -name '*.[hcS]' -type f -print | sort \ 1268 | | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl 1269 | 1270 | coccicheck: 1271 | $(Q)$(CONFIG_SHELL) $(srctree)/scripts/$@ 1272 | 1273 | namespacecheck: 1274 | $(PERL) $(srctree)/scripts/namespace.pl 1275 | 1276 | export_report: 1277 | $(PERL) $(srctree)/scripts/export_report.pl 1278 | 1279 | endif #ifeq ($(config-targets),1) 1280 | endif #ifeq ($(mixed-targets),1) 1281 | 1282 | PHONY += checkstack kernelrelease kernelversion 1283 | 1284 | # UML needs a little special treatment here. It wants to use the host 1285 | # toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone 1286 | # else wants $(ARCH), including people doing cross-builds, which means 1287 | # that $(SUBARCH) doesn't work here. 1288 | ifeq ($(ARCH), um) 1289 | CHECKSTACK_ARCH := $(SUBARCH) 1290 | else 1291 | CHECKSTACK_ARCH := $(ARCH) 1292 | endif 1293 | checkstack: 1294 | $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \ 1295 | $(PERL) $(src)/scripts/checkstack.pl $(CHECKSTACK_ARCH) 1296 | 1297 | kernelrelease: 1298 | @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" 1299 | 1300 | kernelversion: 1301 | @echo $(KERNELVERSION) 1302 | 1303 | # Clear a bunch of variables before executing the submake 1304 | tools/: FORCE 1305 | $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/ 1306 | 1307 | tools/%: FORCE 1308 | $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/ $* 1309 | 1310 | # Single targets 1311 | # --------------------------------------------------------------------------- 1312 | # Single targets are compatible with: 1313 | # - build with mixed source and output 1314 | # - build with separate output dir 'make O=...' 1315 | # - external modules 1316 | # 1317 | # target-dir => where to store outputfile 1318 | # build-dir => directory in kernel source tree to use 1319 | 1320 | ifeq ($(KBUILD_EXTMOD),) 1321 | build-dir = $(patsubst %/,%,$(dir $@)) 1322 | target-dir = $(dir $@) 1323 | else 1324 | zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@))) 1325 | build-dir = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash)) 1326 | target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@)) 1327 | endif 1328 | 1329 | %.s: %.c prepare scripts FORCE 1330 | $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1331 | %.i: %.c prepare scripts FORCE 1332 | $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1333 | %.o: %.c prepare scripts FORCE 1334 | $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1335 | %.lst: %.c prepare scripts FORCE 1336 | $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1337 | %.s: %.S prepare scripts FORCE 1338 | $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1339 | %.o: %.S prepare scripts FORCE 1340 | $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1341 | %.symtypes: %.c prepare scripts FORCE 1342 | $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1343 | 1344 | # Modules 1345 | /: prepare scripts FORCE 1346 | $(cmd_crmodverdir) 1347 | $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ 1348 | $(build)=$(build-dir) 1349 | %/: prepare scripts FORCE 1350 | $(cmd_crmodverdir) 1351 | $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ 1352 | $(build)=$(build-dir) 1353 | %.ko: prepare scripts FORCE 1354 | $(cmd_crmodverdir) 1355 | $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ 1356 | $(build)=$(build-dir) $(@:.ko=.o) 1357 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 1358 | 1359 | # FIXME Should go into a make.lib or something 1360 | # =========================================================================== 1361 | 1362 | quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs))) 1363 | cmd_rmdirs = rm -rf $(rm-dirs) 1364 | 1365 | quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) 1366 | cmd_rmfiles = rm -f $(rm-files) 1367 | 1368 | # Run depmod only if we have System.map and depmod is executable 1369 | quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) 1370 | cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ 1371 | $(KERNELRELEASE) 1372 | 1373 | # Create temporary dir for module support files 1374 | # clean it up only when building all modules 1375 | cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \ 1376 | $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*) 1377 | 1378 | # read all saved command lines 1379 | 1380 | targets := $(wildcard $(sort $(targets))) 1381 | cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1382 | 1383 | ifneq ($(cmd_files),) 1384 | $(cmd_files): ; # Do not try to update included dependency files 1385 | include $(cmd_files) 1386 | endif 1387 | 1388 | # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir 1389 | # Usage: 1390 | # $(Q)$(MAKE) $(clean)=dir 1391 | clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj 1392 | 1393 | endif # skip-makefile 1394 | 1395 | PHONY += FORCE 1396 | FORCE: 1397 | 1398 | # Declare the contents of the .PHONY variable as phony. We keep that 1399 | # information in a variable so we can use it in if_changed and friends. 1400 | .PHONY: $(PHONY) 1401 | -------------------------------------------------------------------------------- /linux-3.6.11/kernel/fork.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/fork.c 3 | * 4 | * Copyright (C) 1991, 1992 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * 'fork.c' contains the help-routines for the 'fork' system call 9 | * (see also entry.S and others). 10 | * Fork is rather simple, once you get the hang of it, but the memory 11 | * management can be a bitch. See 'mm/memory.c': 'copy_page_range()' 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | 81 | #include 82 | 83 | #define CREATE_TRACE_POINTS 84 | #include 85 | 86 | /* 87 | * Protected counters by write_lock_irq(&tasklist_lock) 88 | */ 89 | unsigned long total_forks; /* Handle normal Linux uptimes. */ 90 | int nr_threads; /* The idle threads do not count.. */ 91 | 92 | int max_threads; /* tunable limit on nr_threads */ 93 | 94 | DEFINE_PER_CPU(unsigned long, process_counts) = 0; 95 | 96 | __cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */ 97 | 98 | #ifdef CONFIG_PROVE_RCU 99 | int lockdep_tasklist_lock_is_held(void) 100 | { 101 | return lockdep_is_held(&tasklist_lock); 102 | } 103 | EXPORT_SYMBOL_GPL(lockdep_tasklist_lock_is_held); 104 | #endif /* #ifdef CONFIG_PROVE_RCU */ 105 | 106 | int nr_processes(void) 107 | { 108 | int cpu; 109 | int total = 0; 110 | 111 | for_each_possible_cpu(cpu) 112 | total += per_cpu(process_counts, cpu); 113 | 114 | return total; 115 | } 116 | 117 | void __weak arch_release_task_struct(struct task_struct *tsk) 118 | { 119 | } 120 | 121 | #ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR 122 | static struct kmem_cache *task_struct_cachep; 123 | 124 | static inline struct task_struct *alloc_task_struct_node(int node) 125 | { 126 | return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node); 127 | } 128 | 129 | static inline void free_task_struct(struct task_struct *tsk) 130 | { 131 | kmem_cache_free(task_struct_cachep, tsk); 132 | } 133 | #endif 134 | 135 | void __weak arch_release_thread_info(struct thread_info *ti) 136 | { 137 | } 138 | 139 | #ifndef CONFIG_ARCH_THREAD_INFO_ALLOCATOR 140 | 141 | /* 142 | * Allocate pages if THREAD_SIZE is >= PAGE_SIZE, otherwise use a 143 | * kmemcache based allocator. 144 | */ 145 | # if THREAD_SIZE >= PAGE_SIZE 146 | static struct thread_info *alloc_thread_info_node(struct task_struct *tsk, 147 | int node) 148 | { 149 | struct page *page = alloc_pages_node(node, THREADINFO_GFP, 150 | THREAD_SIZE_ORDER); 151 | 152 | return page ? page_address(page) : NULL; 153 | } 154 | 155 | static inline void free_thread_info(struct thread_info *ti) 156 | { 157 | free_pages((unsigned long)ti, THREAD_SIZE_ORDER); 158 | } 159 | # else 160 | static struct kmem_cache *thread_info_cache; 161 | 162 | static struct thread_info *alloc_thread_info_node(struct task_struct *tsk, 163 | int node) 164 | { 165 | return kmem_cache_alloc_node(thread_info_cache, THREADINFO_GFP, node); 166 | } 167 | 168 | static void free_thread_info(struct thread_info *ti) 169 | { 170 | kmem_cache_free(thread_info_cache, ti); 171 | } 172 | 173 | void thread_info_cache_init(void) 174 | { 175 | thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE, 176 | THREAD_SIZE, 0, NULL); 177 | BUG_ON(thread_info_cache == NULL); 178 | } 179 | # endif 180 | #endif 181 | 182 | /* SLAB cache for signal_struct structures (tsk->signal) */ 183 | static struct kmem_cache *signal_cachep; 184 | 185 | /* SLAB cache for sighand_struct structures (tsk->sighand) */ 186 | struct kmem_cache *sighand_cachep; 187 | 188 | /* SLAB cache for files_struct structures (tsk->files) */ 189 | struct kmem_cache *files_cachep; 190 | 191 | /* SLAB cache for fs_struct structures (tsk->fs) */ 192 | struct kmem_cache *fs_cachep; 193 | 194 | /* SLAB cache for vm_area_struct structures */ 195 | struct kmem_cache *vm_area_cachep; 196 | 197 | /* SLAB cache for mm_struct structures (tsk->mm) */ 198 | static struct kmem_cache *mm_cachep; 199 | 200 | static void account_kernel_stack(struct thread_info *ti, int account) 201 | { 202 | struct zone *zone = page_zone(virt_to_page(ti)); 203 | 204 | mod_zone_page_state(zone, NR_KERNEL_STACK, account); 205 | } 206 | 207 | void free_task(struct task_struct *tsk) 208 | { 209 | account_kernel_stack(tsk->stack, -1); 210 | arch_release_thread_info(tsk->stack); 211 | free_thread_info(tsk->stack); 212 | rt_mutex_debug_task_free(tsk); 213 | ftrace_graph_exit_task(tsk); 214 | put_seccomp_filter(tsk); 215 | arch_release_task_struct(tsk); 216 | free_task_struct(tsk); 217 | } 218 | EXPORT_SYMBOL(free_task); 219 | 220 | static inline void free_signal_struct(struct signal_struct *sig) 221 | { 222 | taskstats_tgid_free(sig); 223 | sched_autogroup_exit(sig); 224 | kmem_cache_free(signal_cachep, sig); 225 | } 226 | 227 | static inline void put_signal_struct(struct signal_struct *sig) 228 | { 229 | if (atomic_dec_and_test(&sig->sigcnt)) 230 | free_signal_struct(sig); 231 | } 232 | 233 | void __put_task_struct(struct task_struct *tsk) 234 | { 235 | WARN_ON(!tsk->exit_state); 236 | WARN_ON(atomic_read(&tsk->usage)); 237 | WARN_ON(tsk == current); 238 | 239 | security_task_free(tsk); 240 | exit_creds(tsk); 241 | delayacct_tsk_free(tsk); 242 | put_signal_struct(tsk->signal); 243 | 244 | if (!profile_handoff_task(tsk)) 245 | free_task(tsk); 246 | } 247 | EXPORT_SYMBOL_GPL(__put_task_struct); 248 | 249 | void __init __weak arch_task_cache_init(void) { } 250 | 251 | void __init fork_init(unsigned long mempages) 252 | { 253 | #ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR 254 | #ifndef ARCH_MIN_TASKALIGN 255 | #define ARCH_MIN_TASKALIGN L1_CACHE_BYTES 256 | #endif 257 | /* create a slab on which task_structs can be allocated */ 258 | task_struct_cachep = 259 | kmem_cache_create("task_struct", sizeof(struct task_struct), 260 | ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL); 261 | #endif 262 | 263 | /* do the arch specific task caches init */ 264 | arch_task_cache_init(); 265 | 266 | /* 267 | * The default maximum number of threads is set to a safe 268 | * value: the thread structures can take up at most half 269 | * of memory. 270 | */ 271 | max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE); 272 | 273 | /* 274 | * we need to allow at least 20 threads to boot a system 275 | */ 276 | if (max_threads < 20) 277 | max_threads = 20; 278 | 279 | init_task.signal->rlim[RLIMIT_NPROC].rlim_cur = max_threads/2; 280 | init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2; 281 | init_task.signal->rlim[RLIMIT_SIGPENDING] = 282 | init_task.signal->rlim[RLIMIT_NPROC]; 283 | } 284 | 285 | int __attribute__((weak)) arch_dup_task_struct(struct task_struct *dst, 286 | struct task_struct *src) 287 | { 288 | *dst = *src; 289 | return 0; 290 | } 291 | 292 | static struct task_struct *dup_task_struct(struct task_struct *orig) 293 | { 294 | struct task_struct *tsk; 295 | struct thread_info *ti; 296 | unsigned long *stackend; 297 | int node = tsk_fork_get_node(orig); 298 | int err; 299 | 300 | tsk = alloc_task_struct_node(node); 301 | if (!tsk) 302 | return NULL; 303 | 304 | ti = alloc_thread_info_node(tsk, node); 305 | if (!ti) 306 | goto free_tsk; 307 | 308 | err = arch_dup_task_struct(tsk, orig); 309 | if (err) 310 | goto free_ti; 311 | 312 | tsk->stack = ti; 313 | 314 | setup_thread_stack(tsk, orig); 315 | clear_user_return_notifier(tsk); 316 | clear_tsk_need_resched(tsk); 317 | stackend = end_of_stack(tsk); 318 | *stackend = STACK_END_MAGIC; /* for overflow detection */ 319 | 320 | #ifdef CONFIG_CC_STACKPROTECTOR 321 | tsk->stack_canary = get_random_int(); 322 | #endif 323 | 324 | /* 325 | * One for us, one for whoever does the "release_task()" (usually 326 | * parent) 327 | */ 328 | atomic_set(&tsk->usage, 2); 329 | #ifdef CONFIG_BLK_DEV_IO_TRACE 330 | tsk->btrace_seq = 0; 331 | #endif 332 | tsk->splice_pipe = NULL; 333 | 334 | account_kernel_stack(ti, 1); 335 | 336 | return tsk; 337 | 338 | free_ti: 339 | free_thread_info(ti); 340 | free_tsk: 341 | free_task_struct(tsk); 342 | return NULL; 343 | } 344 | 345 | #ifdef CONFIG_MMU 346 | static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) 347 | { 348 | struct vm_area_struct *mpnt, *tmp, *prev, **pprev; 349 | struct rb_node **rb_link, *rb_parent; 350 | int retval; 351 | unsigned long charge; 352 | struct mempolicy *pol; 353 | 354 | down_write(&oldmm->mmap_sem); 355 | flush_cache_dup_mm(oldmm); 356 | /* 357 | * Not linked in yet - no deadlock potential: 358 | */ 359 | down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING); 360 | 361 | mm->locked_vm = 0; 362 | mm->mmap = NULL; 363 | mm->mmap_cache = NULL; 364 | mm->free_area_cache = oldmm->mmap_base; 365 | mm->cached_hole_size = ~0UL; 366 | mm->map_count = 0; 367 | cpumask_clear(mm_cpumask(mm)); 368 | mm->mm_rb = RB_ROOT; 369 | rb_link = &mm->mm_rb.rb_node; 370 | rb_parent = NULL; 371 | pprev = &mm->mmap; 372 | retval = ksm_fork(mm, oldmm); 373 | if (retval) 374 | goto out; 375 | retval = khugepaged_fork(mm, oldmm); 376 | if (retval) 377 | goto out; 378 | 379 | prev = NULL; 380 | for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) { 381 | struct file *file; 382 | 383 | if (mpnt->vm_flags & VM_DONTCOPY) { 384 | vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file, 385 | -vma_pages(mpnt)); 386 | continue; 387 | } 388 | charge = 0; 389 | if (mpnt->vm_flags & VM_ACCOUNT) { 390 | unsigned long len = vma_pages(mpnt); 391 | 392 | if (security_vm_enough_memory_mm(oldmm, len)) /* sic */ 393 | goto fail_nomem; 394 | charge = len; 395 | } 396 | tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); 397 | if (!tmp) 398 | goto fail_nomem; 399 | *tmp = *mpnt; 400 | INIT_LIST_HEAD(&tmp->anon_vma_chain); 401 | pol = mpol_dup(vma_policy(mpnt)); 402 | retval = PTR_ERR(pol); 403 | if (IS_ERR(pol)) 404 | goto fail_nomem_policy; 405 | vma_set_policy(tmp, pol); 406 | tmp->vm_mm = mm; 407 | if (anon_vma_fork(tmp, mpnt)) 408 | goto fail_nomem_anon_vma_fork; 409 | tmp->vm_flags &= ~VM_LOCKED; 410 | tmp->vm_next = tmp->vm_prev = NULL; 411 | file = tmp->vm_file; 412 | if (file) { 413 | struct inode *inode = file->f_path.dentry->d_inode; 414 | struct address_space *mapping = file->f_mapping; 415 | 416 | get_file(file); 417 | if (tmp->vm_flags & VM_DENYWRITE) 418 | atomic_dec(&inode->i_writecount); 419 | mutex_lock(&mapping->i_mmap_mutex); 420 | if (tmp->vm_flags & VM_SHARED) 421 | mapping->i_mmap_writable++; 422 | flush_dcache_mmap_lock(mapping); 423 | /* insert tmp into the share list, just after mpnt */ 424 | vma_prio_tree_add(tmp, mpnt); 425 | flush_dcache_mmap_unlock(mapping); 426 | mutex_unlock(&mapping->i_mmap_mutex); 427 | } 428 | 429 | /* 430 | * Clear hugetlb-related page reserves for children. This only 431 | * affects MAP_PRIVATE mappings. Faults generated by the child 432 | * are not guaranteed to succeed, even if read-only 433 | */ 434 | if (is_vm_hugetlb_page(tmp)) 435 | reset_vma_resv_huge_pages(tmp); 436 | 437 | /* 438 | * Link in the new vma and copy the page table entries. 439 | */ 440 | *pprev = tmp; 441 | pprev = &tmp->vm_next; 442 | tmp->vm_prev = prev; 443 | prev = tmp; 444 | 445 | __vma_link_rb(mm, tmp, rb_link, rb_parent); 446 | rb_link = &tmp->vm_rb.rb_right; 447 | rb_parent = &tmp->vm_rb; 448 | 449 | mm->map_count++; 450 | retval = copy_page_range(mm, oldmm, mpnt); 451 | 452 | if (tmp->vm_ops && tmp->vm_ops->open) 453 | tmp->vm_ops->open(tmp); 454 | 455 | if (retval) 456 | goto out; 457 | 458 | if (file) 459 | uprobe_mmap(tmp); 460 | } 461 | /* a new mm has just been created */ 462 | arch_dup_mmap(oldmm, mm); 463 | retval = 0; 464 | out: 465 | up_write(&mm->mmap_sem); 466 | flush_tlb_mm(oldmm); 467 | up_write(&oldmm->mmap_sem); 468 | return retval; 469 | fail_nomem_anon_vma_fork: 470 | mpol_put(pol); 471 | fail_nomem_policy: 472 | kmem_cache_free(vm_area_cachep, tmp); 473 | fail_nomem: 474 | retval = -ENOMEM; 475 | vm_unacct_memory(charge); 476 | goto out; 477 | } 478 | 479 | static inline int mm_alloc_pgd(struct mm_struct *mm) 480 | { 481 | mm->pgd = pgd_alloc(mm); 482 | if (unlikely(!mm->pgd)) 483 | return -ENOMEM; 484 | return 0; 485 | } 486 | 487 | static inline void mm_free_pgd(struct mm_struct *mm) 488 | { 489 | pgd_free(mm, mm->pgd); 490 | } 491 | #else 492 | #define dup_mmap(mm, oldmm) (0) 493 | #define mm_alloc_pgd(mm) (0) 494 | #define mm_free_pgd(mm) 495 | #endif /* CONFIG_MMU */ 496 | 497 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(mmlist_lock); 498 | 499 | #define allocate_mm() (kmem_cache_alloc(mm_cachep, GFP_KERNEL)) 500 | #define free_mm(mm) (kmem_cache_free(mm_cachep, (mm))) 501 | 502 | static unsigned long default_dump_filter = MMF_DUMP_FILTER_DEFAULT; 503 | 504 | static int __init coredump_filter_setup(char *s) 505 | { 506 | default_dump_filter = 507 | (simple_strtoul(s, NULL, 0) << MMF_DUMP_FILTER_SHIFT) & 508 | MMF_DUMP_FILTER_MASK; 509 | return 1; 510 | } 511 | 512 | __setup("coredump_filter=", coredump_filter_setup); 513 | 514 | #include 515 | 516 | static void mm_init_aio(struct mm_struct *mm) 517 | { 518 | #ifdef CONFIG_AIO 519 | spin_lock_init(&mm->ioctx_lock); 520 | INIT_HLIST_HEAD(&mm->ioctx_list); 521 | #endif 522 | } 523 | 524 | static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p) 525 | { 526 | atomic_set(&mm->mm_users, 1); 527 | atomic_set(&mm->mm_count, 1); 528 | init_rwsem(&mm->mmap_sem); 529 | INIT_LIST_HEAD(&mm->mmlist); 530 | mm->flags = (current->mm) ? 531 | (current->mm->flags & MMF_INIT_MASK) : default_dump_filter; 532 | mm->core_state = NULL; 533 | mm->nr_ptes = 0; 534 | memset(&mm->rss_stat, 0, sizeof(mm->rss_stat)); 535 | spin_lock_init(&mm->page_table_lock); 536 | mm->free_area_cache = TASK_UNMAPPED_BASE; 537 | mm->cached_hole_size = ~0UL; 538 | mm_init_aio(mm); 539 | mm_init_owner(mm, p); 540 | 541 | if (likely(!mm_alloc_pgd(mm))) { 542 | mm->def_flags = 0; 543 | mmu_notifier_mm_init(mm); 544 | return mm; 545 | } 546 | 547 | free_mm(mm); 548 | return NULL; 549 | } 550 | 551 | static void check_mm(struct mm_struct *mm) 552 | { 553 | int i; 554 | 555 | for (i = 0; i < NR_MM_COUNTERS; i++) { 556 | long x = atomic_long_read(&mm->rss_stat.count[i]); 557 | 558 | if (unlikely(x)) 559 | printk(KERN_ALERT "BUG: Bad rss-counter state " 560 | "mm:%p idx:%d val:%ld\n", mm, i, x); 561 | } 562 | 563 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE 564 | VM_BUG_ON(mm->pmd_huge_pte); 565 | #endif 566 | } 567 | 568 | /* 569 | * Allocate and initialize an mm_struct. 570 | */ 571 | struct mm_struct *mm_alloc(void) 572 | { 573 | struct mm_struct *mm; 574 | 575 | mm = allocate_mm(); 576 | if (!mm) 577 | return NULL; 578 | 579 | memset(mm, 0, sizeof(*mm)); 580 | mm_init_cpumask(mm); 581 | return mm_init(mm, current); 582 | } 583 | 584 | /* 585 | * Called when the last reference to the mm 586 | * is dropped: either by a lazy thread or by 587 | * mmput. Free the page directory and the mm. 588 | */ 589 | void __mmdrop(struct mm_struct *mm) 590 | { 591 | BUG_ON(mm == &init_mm); 592 | mm_free_pgd(mm); 593 | destroy_context(mm); 594 | mmu_notifier_mm_destroy(mm); 595 | check_mm(mm); 596 | free_mm(mm); 597 | } 598 | EXPORT_SYMBOL_GPL(__mmdrop); 599 | 600 | /* 601 | * Decrement the use count and release all resources for an mm. 602 | */ 603 | void mmput(struct mm_struct *mm) 604 | { 605 | might_sleep(); 606 | 607 | if (atomic_dec_and_test(&mm->mm_users)) { 608 | uprobe_clear_state(mm); 609 | exit_aio(mm); 610 | ksm_exit(mm); 611 | khugepaged_exit(mm); /* must run before exit_mmap */ 612 | exit_mmap(mm); 613 | set_mm_exe_file(mm, NULL); 614 | if (!list_empty(&mm->mmlist)) { 615 | spin_lock(&mmlist_lock); 616 | list_del(&mm->mmlist); 617 | spin_unlock(&mmlist_lock); 618 | } 619 | if (mm->binfmt) 620 | module_put(mm->binfmt->module); 621 | mmdrop(mm); 622 | } 623 | } 624 | EXPORT_SYMBOL_GPL(mmput); 625 | 626 | /* 627 | * We added or removed a vma mapping the executable. The vmas are only mapped 628 | * during exec and are not mapped with the mmap system call. 629 | * Callers must hold down_write() on the mm's mmap_sem for these 630 | */ 631 | void added_exe_file_vma(struct mm_struct *mm) 632 | { 633 | mm->num_exe_file_vmas++; 634 | } 635 | 636 | void removed_exe_file_vma(struct mm_struct *mm) 637 | { 638 | mm->num_exe_file_vmas--; 639 | if ((mm->num_exe_file_vmas == 0) && mm->exe_file) { 640 | fput(mm->exe_file); 641 | mm->exe_file = NULL; 642 | } 643 | 644 | } 645 | 646 | void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) 647 | { 648 | if (new_exe_file) 649 | get_file(new_exe_file); 650 | if (mm->exe_file) 651 | fput(mm->exe_file); 652 | mm->exe_file = new_exe_file; 653 | mm->num_exe_file_vmas = 0; 654 | } 655 | 656 | struct file *get_mm_exe_file(struct mm_struct *mm) 657 | { 658 | struct file *exe_file; 659 | 660 | /* We need mmap_sem to protect against races with removal of 661 | * VM_EXECUTABLE vmas */ 662 | down_read(&mm->mmap_sem); 663 | exe_file = mm->exe_file; 664 | if (exe_file) 665 | get_file(exe_file); 666 | up_read(&mm->mmap_sem); 667 | return exe_file; 668 | } 669 | 670 | static void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm) 671 | { 672 | /* It's safe to write the exe_file pointer without exe_file_lock because 673 | * this is called during fork when the task is not yet in /proc */ 674 | newmm->exe_file = get_mm_exe_file(oldmm); 675 | } 676 | 677 | /** 678 | * get_task_mm - acquire a reference to the task's mm 679 | * 680 | * Returns %NULL if the task has no mm. Checks PF_KTHREAD (meaning 681 | * this kernel workthread has transiently adopted a user mm with use_mm, 682 | * to do its AIO) is not set and if so returns a reference to it, after 683 | * bumping up the use count. User must release the mm via mmput() 684 | * after use. Typically used by /proc and ptrace. 685 | */ 686 | struct mm_struct *get_task_mm(struct task_struct *task) 687 | { 688 | struct mm_struct *mm; 689 | 690 | task_lock(task); 691 | mm = task->mm; 692 | if (mm) { 693 | if (task->flags & PF_KTHREAD) 694 | mm = NULL; 695 | else 696 | atomic_inc(&mm->mm_users); 697 | } 698 | task_unlock(task); 699 | return mm; 700 | } 701 | EXPORT_SYMBOL_GPL(get_task_mm); 702 | 703 | struct mm_struct *mm_access(struct task_struct *task, unsigned int mode) 704 | { 705 | struct mm_struct *mm; 706 | int err; 707 | 708 | err = mutex_lock_killable(&task->signal->cred_guard_mutex); 709 | if (err) 710 | return ERR_PTR(err); 711 | 712 | mm = get_task_mm(task); 713 | if (mm && mm != current->mm && 714 | !ptrace_may_access(task, mode)) { 715 | mmput(mm); 716 | mm = ERR_PTR(-EACCES); 717 | } 718 | mutex_unlock(&task->signal->cred_guard_mutex); 719 | 720 | return mm; 721 | } 722 | 723 | static void complete_vfork_done(struct task_struct *tsk) 724 | { 725 | struct completion *vfork; 726 | 727 | task_lock(tsk); 728 | vfork = tsk->vfork_done; 729 | if (likely(vfork)) { 730 | tsk->vfork_done = NULL; 731 | complete(vfork); 732 | } 733 | task_unlock(tsk); 734 | } 735 | 736 | static int wait_for_vfork_done(struct task_struct *child, 737 | struct completion *vfork) 738 | { 739 | int killed; 740 | 741 | freezer_do_not_count(); 742 | killed = wait_for_completion_killable(vfork); 743 | freezer_count(); 744 | 745 | if (killed) { 746 | task_lock(child); 747 | child->vfork_done = NULL; 748 | task_unlock(child); 749 | } 750 | 751 | put_task_struct(child); 752 | return killed; 753 | } 754 | 755 | /* Please note the differences between mmput and mm_release. 756 | * mmput is called whenever we stop holding onto a mm_struct, 757 | * error success whatever. 758 | * 759 | * mm_release is called after a mm_struct has been removed 760 | * from the current process. 761 | * 762 | * This difference is important for error handling, when we 763 | * only half set up a mm_struct for a new process and need to restore 764 | * the old one. Because we mmput the new mm_struct before 765 | * restoring the old one. . . 766 | * Eric Biederman 10 January 1998 767 | */ 768 | void mm_release(struct task_struct *tsk, struct mm_struct *mm) 769 | { 770 | /* Get rid of any futexes when releasing the mm */ 771 | #ifdef CONFIG_FUTEX 772 | if (unlikely(tsk->robust_list)) { 773 | exit_robust_list(tsk); 774 | tsk->robust_list = NULL; 775 | } 776 | #ifdef CONFIG_COMPAT 777 | if (unlikely(tsk->compat_robust_list)) { 778 | compat_exit_robust_list(tsk); 779 | tsk->compat_robust_list = NULL; 780 | } 781 | #endif 782 | if (unlikely(!list_empty(&tsk->pi_state_list))) 783 | exit_pi_state_list(tsk); 784 | #endif 785 | 786 | uprobe_free_utask(tsk); 787 | 788 | /* Get rid of any cached register state */ 789 | deactivate_mm(tsk, mm); 790 | 791 | /* 792 | * If we're exiting normally, clear a user-space tid field if 793 | * requested. We leave this alone when dying by signal, to leave 794 | * the value intact in a core dump, and to save the unnecessary 795 | * trouble, say, a killed vfork parent shouldn't touch this mm. 796 | * Userland only wants this done for a sys_exit. 797 | */ 798 | if (tsk->clear_child_tid) { 799 | if (!(tsk->flags & PF_SIGNALED) && 800 | atomic_read(&mm->mm_users) > 1) { 801 | /* 802 | * We don't check the error code - if userspace has 803 | * not set up a proper pointer then tough luck. 804 | */ 805 | put_user(0, tsk->clear_child_tid); 806 | sys_futex(tsk->clear_child_tid, FUTEX_WAKE, 807 | 1, NULL, NULL, 0); 808 | } 809 | tsk->clear_child_tid = NULL; 810 | } 811 | 812 | /* 813 | * All done, finally we can wake up parent and return this mm to him. 814 | * Also kthread_stop() uses this completion for synchronization. 815 | */ 816 | if (tsk->vfork_done) 817 | complete_vfork_done(tsk); 818 | } 819 | 820 | /* 821 | * Allocate a new mm structure and copy contents from the 822 | * mm structure of the passed in task structure. 823 | */ 824 | struct mm_struct *dup_mm(struct task_struct *tsk) 825 | { 826 | struct mm_struct *mm, *oldmm = current->mm; 827 | int err; 828 | 829 | if (!oldmm) 830 | return NULL; 831 | 832 | mm = allocate_mm(); 833 | if (!mm) 834 | goto fail_nomem; 835 | 836 | memcpy(mm, oldmm, sizeof(*mm)); 837 | mm_init_cpumask(mm); 838 | 839 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE 840 | mm->pmd_huge_pte = NULL; 841 | #endif 842 | uprobe_reset_state(mm); 843 | 844 | if (!mm_init(mm, tsk)) 845 | goto fail_nomem; 846 | 847 | if (init_new_context(tsk, mm)) 848 | goto fail_nocontext; 849 | 850 | dup_mm_exe_file(oldmm, mm); 851 | 852 | err = dup_mmap(mm, oldmm); 853 | if (err) 854 | goto free_pt; 855 | 856 | mm->hiwater_rss = get_mm_rss(mm); 857 | mm->hiwater_vm = mm->total_vm; 858 | 859 | if (mm->binfmt && !try_module_get(mm->binfmt->module)) 860 | goto free_pt; 861 | 862 | return mm; 863 | 864 | free_pt: 865 | /* don't put binfmt in mmput, we haven't got module yet */ 866 | mm->binfmt = NULL; 867 | mmput(mm); 868 | 869 | fail_nomem: 870 | return NULL; 871 | 872 | fail_nocontext: 873 | /* 874 | * If init_new_context() failed, we cannot use mmput() to free the mm 875 | * because it calls destroy_context() 876 | */ 877 | mm_free_pgd(mm); 878 | free_mm(mm); 879 | return NULL; 880 | } 881 | 882 | static int copy_mm(unsigned long clone_flags, struct task_struct *tsk) 883 | { 884 | struct mm_struct *mm, *oldmm; 885 | int retval; 886 | 887 | tsk->min_flt = tsk->maj_flt = 0; 888 | tsk->nvcsw = tsk->nivcsw = 0; 889 | #ifdef CONFIG_DETECT_HUNG_TASK 890 | tsk->last_switch_count = tsk->nvcsw + tsk->nivcsw; 891 | #endif 892 | 893 | tsk->mm = NULL; 894 | tsk->active_mm = NULL; 895 | 896 | /* 897 | * Are we cloning a kernel thread? 898 | * 899 | * We need to steal a active VM for that.. 900 | */ 901 | oldmm = current->mm; 902 | if (!oldmm) 903 | return 0; 904 | 905 | if (clone_flags & CLONE_VM) { 906 | atomic_inc(&oldmm->mm_users); 907 | mm = oldmm; 908 | goto good_mm; 909 | } 910 | 911 | retval = -ENOMEM; 912 | mm = dup_mm(tsk); 913 | if (!mm) 914 | goto fail_nomem; 915 | 916 | good_mm: 917 | tsk->mm = mm; 918 | tsk->active_mm = mm; 919 | return 0; 920 | 921 | fail_nomem: 922 | return retval; 923 | } 924 | 925 | static int copy_fs(unsigned long clone_flags, struct task_struct *tsk) 926 | { 927 | struct fs_struct *fs = current->fs; 928 | if (clone_flags & CLONE_FS) { 929 | /* tsk->fs is already what we want */ 930 | spin_lock(&fs->lock); 931 | if (fs->in_exec) { 932 | spin_unlock(&fs->lock); 933 | return -EAGAIN; 934 | } 935 | fs->users++; 936 | spin_unlock(&fs->lock); 937 | return 0; 938 | } 939 | tsk->fs = copy_fs_struct(fs); 940 | if (!tsk->fs) 941 | return -ENOMEM; 942 | return 0; 943 | } 944 | 945 | static int copy_files(unsigned long clone_flags, struct task_struct *tsk) 946 | { 947 | struct files_struct *oldf, *newf; 948 | int error = 0; 949 | 950 | /* 951 | * A background process may not have any files ... 952 | */ 953 | oldf = current->files; 954 | if (!oldf) 955 | goto out; 956 | 957 | if (clone_flags & CLONE_FILES) { 958 | atomic_inc(&oldf->count); 959 | goto out; 960 | } 961 | 962 | newf = dup_fd(oldf, &error); 963 | if (!newf) 964 | goto out; 965 | 966 | tsk->files = newf; 967 | error = 0; 968 | out: 969 | return error; 970 | } 971 | 972 | static int copy_io(unsigned long clone_flags, struct task_struct *tsk) 973 | { 974 | #ifdef CONFIG_BLOCK 975 | struct io_context *ioc = current->io_context; 976 | struct io_context *new_ioc; 977 | 978 | if (!ioc) 979 | return 0; 980 | /* 981 | * Share io context with parent, if CLONE_IO is set 982 | */ 983 | if (clone_flags & CLONE_IO) { 984 | ioc_task_link(ioc); 985 | tsk->io_context = ioc; 986 | } else if (ioprio_valid(ioc->ioprio)) { 987 | new_ioc = get_task_io_context(tsk, GFP_KERNEL, NUMA_NO_NODE); 988 | if (unlikely(!new_ioc)) 989 | return -ENOMEM; 990 | 991 | new_ioc->ioprio = ioc->ioprio; 992 | put_io_context(new_ioc); 993 | } 994 | #endif 995 | return 0; 996 | } 997 | 998 | static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk) 999 | { 1000 | struct sighand_struct *sig; 1001 | 1002 | if (clone_flags & CLONE_SIGHAND) { 1003 | atomic_inc(¤t->sighand->count); 1004 | return 0; 1005 | } 1006 | sig = kmem_cache_alloc(sighand_cachep, GFP_KERNEL); 1007 | rcu_assign_pointer(tsk->sighand, sig); 1008 | if (!sig) 1009 | return -ENOMEM; 1010 | atomic_set(&sig->count, 1); 1011 | memcpy(sig->action, current->sighand->action, sizeof(sig->action)); 1012 | return 0; 1013 | } 1014 | 1015 | void __cleanup_sighand(struct sighand_struct *sighand) 1016 | { 1017 | if (atomic_dec_and_test(&sighand->count)) { 1018 | signalfd_cleanup(sighand); 1019 | kmem_cache_free(sighand_cachep, sighand); 1020 | } 1021 | } 1022 | 1023 | 1024 | /* 1025 | * Initialize POSIX timer handling for a thread group. 1026 | */ 1027 | static void posix_cpu_timers_init_group(struct signal_struct *sig) 1028 | { 1029 | unsigned long cpu_limit; 1030 | 1031 | /* Thread group counters. */ 1032 | thread_group_cputime_init(sig); 1033 | 1034 | cpu_limit = ACCESS_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur); 1035 | if (cpu_limit != RLIM_INFINITY) { 1036 | sig->cputime_expires.prof_exp = secs_to_cputime(cpu_limit); 1037 | sig->cputimer.running = 1; 1038 | } 1039 | 1040 | /* The timer lists. */ 1041 | INIT_LIST_HEAD(&sig->cpu_timers[0]); 1042 | INIT_LIST_HEAD(&sig->cpu_timers[1]); 1043 | INIT_LIST_HEAD(&sig->cpu_timers[2]); 1044 | } 1045 | 1046 | static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) 1047 | { 1048 | struct signal_struct *sig; 1049 | 1050 | if (clone_flags & CLONE_THREAD) 1051 | return 0; 1052 | 1053 | sig = kmem_cache_zalloc(signal_cachep, GFP_KERNEL); 1054 | tsk->signal = sig; 1055 | if (!sig) 1056 | return -ENOMEM; 1057 | 1058 | sig->nr_threads = 1; 1059 | atomic_set(&sig->live, 1); 1060 | atomic_set(&sig->sigcnt, 1); 1061 | init_waitqueue_head(&sig->wait_chldexit); 1062 | if (clone_flags & CLONE_NEWPID) 1063 | sig->flags |= SIGNAL_UNKILLABLE; 1064 | sig->curr_target = tsk; 1065 | init_sigpending(&sig->shared_pending); 1066 | INIT_LIST_HEAD(&sig->posix_timers); 1067 | 1068 | hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 1069 | sig->real_timer.function = it_real_fn; 1070 | 1071 | task_lock(current->group_leader); 1072 | memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim); 1073 | task_unlock(current->group_leader); 1074 | 1075 | posix_cpu_timers_init_group(sig); 1076 | 1077 | tty_audit_fork(sig); 1078 | sched_autogroup_fork(sig); 1079 | 1080 | #ifdef CONFIG_CGROUPS 1081 | init_rwsem(&sig->group_rwsem); 1082 | #endif 1083 | 1084 | sig->oom_adj = current->signal->oom_adj; 1085 | sig->oom_score_adj = current->signal->oom_score_adj; 1086 | sig->oom_score_adj_min = current->signal->oom_score_adj_min; 1087 | 1088 | sig->has_child_subreaper = current->signal->has_child_subreaper || 1089 | current->signal->is_child_subreaper; 1090 | 1091 | mutex_init(&sig->cred_guard_mutex); 1092 | 1093 | return 0; 1094 | } 1095 | 1096 | static void copy_flags(unsigned long clone_flags, struct task_struct *p) 1097 | { 1098 | unsigned long new_flags = p->flags; 1099 | 1100 | new_flags &= ~(PF_SUPERPRIV | PF_WQ_WORKER); 1101 | new_flags |= PF_FORKNOEXEC; 1102 | p->flags = new_flags; 1103 | } 1104 | 1105 | SYSCALL_DEFINE1(set_tid_address, int __user *, tidptr) 1106 | { 1107 | current->clear_child_tid = tidptr; 1108 | 1109 | return task_pid_vnr(current); 1110 | } 1111 | 1112 | static void rt_mutex_init_task(struct task_struct *p) 1113 | { 1114 | raw_spin_lock_init(&p->pi_lock); 1115 | #ifdef CONFIG_RT_MUTEXES 1116 | plist_head_init(&p->pi_waiters); 1117 | p->pi_blocked_on = NULL; 1118 | #endif 1119 | } 1120 | 1121 | #ifdef CONFIG_MM_OWNER 1122 | void mm_init_owner(struct mm_struct *mm, struct task_struct *p) 1123 | { 1124 | mm->owner = p; 1125 | } 1126 | #endif /* CONFIG_MM_OWNER */ 1127 | 1128 | /* 1129 | * Initialize POSIX timer handling for a single task. 1130 | */ 1131 | static void posix_cpu_timers_init(struct task_struct *tsk) 1132 | { 1133 | tsk->cputime_expires.prof_exp = 0; 1134 | tsk->cputime_expires.virt_exp = 0; 1135 | tsk->cputime_expires.sched_exp = 0; 1136 | INIT_LIST_HEAD(&tsk->cpu_timers[0]); 1137 | INIT_LIST_HEAD(&tsk->cpu_timers[1]); 1138 | INIT_LIST_HEAD(&tsk->cpu_timers[2]); 1139 | } 1140 | 1141 | /* 1142 | * This creates a new process as a copy of the old one, 1143 | * but does not actually start it yet. 1144 | * 1145 | * It copies the registers, and all the appropriate 1146 | * parts of the process environment (as per the clone 1147 | * flags). The actual kick-off is left to the caller. 1148 | */ 1149 | static struct task_struct *copy_process(unsigned long clone_flags, 1150 | unsigned long stack_start, 1151 | struct pt_regs *regs, 1152 | unsigned long stack_size, 1153 | int __user *child_tidptr, 1154 | struct pid *pid, 1155 | int trace) 1156 | { 1157 | int retval; 1158 | struct task_struct *p; 1159 | int cgroup_callbacks_done = 0; 1160 | 1161 | if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS)) 1162 | return ERR_PTR(-EINVAL); 1163 | 1164 | /* 1165 | * Thread groups must share signals as well, and detached threads 1166 | * can only be started up within the thread group. 1167 | */ 1168 | if ((clone_flags & CLONE_THREAD) && !(clone_flags & CLONE_SIGHAND)) 1169 | return ERR_PTR(-EINVAL); 1170 | 1171 | /* 1172 | * Shared signal handlers imply shared VM. By way of the above, 1173 | * thread groups also imply shared VM. Blocking this case allows 1174 | * for various simplifications in other code. 1175 | */ 1176 | if ((clone_flags & CLONE_SIGHAND) && !(clone_flags & CLONE_VM)) 1177 | return ERR_PTR(-EINVAL); 1178 | 1179 | /* 1180 | * Siblings of global init remain as zombies on exit since they are 1181 | * not reaped by their parent (swapper). To solve this and to avoid 1182 | * multi-rooted process trees, prevent global and container-inits 1183 | * from creating siblings. 1184 | */ 1185 | if ((clone_flags & CLONE_PARENT) && 1186 | current->signal->flags & SIGNAL_UNKILLABLE) 1187 | return ERR_PTR(-EINVAL); 1188 | 1189 | retval = security_task_create(clone_flags); 1190 | if (retval) 1191 | goto fork_out; 1192 | 1193 | retval = -ENOMEM; 1194 | p = dup_task_struct(current); 1195 | if (!p) 1196 | goto fork_out; 1197 | 1198 | ftrace_graph_init_task(p); 1199 | get_seccomp_filter(p); 1200 | /* Initialize hide to be 0 which denotes unhiding this process */ 1201 | p->hide = 0; 1202 | rt_mutex_init_task(p); 1203 | 1204 | #ifdef CONFIG_PROVE_LOCKING 1205 | DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled); 1206 | DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled); 1207 | #endif 1208 | retval = -EAGAIN; 1209 | if (atomic_read(&p->real_cred->user->processes) >= 1210 | task_rlimit(p, RLIMIT_NPROC)) { 1211 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && 1212 | p->real_cred->user != INIT_USER) 1213 | goto bad_fork_free; 1214 | } 1215 | current->flags &= ~PF_NPROC_EXCEEDED; 1216 | 1217 | retval = copy_creds(p, clone_flags); 1218 | if (retval < 0) 1219 | goto bad_fork_free; 1220 | 1221 | /* 1222 | * If multiple threads are within copy_process(), then this check 1223 | * triggers too late. This doesn't hurt, the check is only there 1224 | * to stop root fork bombs. 1225 | */ 1226 | retval = -EAGAIN; 1227 | if (nr_threads >= max_threads) 1228 | goto bad_fork_cleanup_count; 1229 | 1230 | if (!try_module_get(task_thread_info(p)->exec_domain->module)) 1231 | goto bad_fork_cleanup_count; 1232 | 1233 | p->did_exec = 0; 1234 | delayacct_tsk_init(p); /* Must remain after dup_task_struct() */ 1235 | copy_flags(clone_flags, p); 1236 | INIT_LIST_HEAD(&p->children); 1237 | INIT_LIST_HEAD(&p->sibling); 1238 | rcu_copy_process(p); 1239 | p->vfork_done = NULL; 1240 | spin_lock_init(&p->alloc_lock); 1241 | 1242 | init_sigpending(&p->pending); 1243 | 1244 | p->utime = p->stime = p->gtime = 0; 1245 | p->utimescaled = p->stimescaled = 0; 1246 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING 1247 | p->prev_utime = p->prev_stime = 0; 1248 | #endif 1249 | #if defined(SPLIT_RSS_COUNTING) 1250 | memset(&p->rss_stat, 0, sizeof(p->rss_stat)); 1251 | #endif 1252 | 1253 | p->default_timer_slack_ns = current->timer_slack_ns; 1254 | 1255 | task_io_accounting_init(&p->ioac); 1256 | acct_clear_integrals(p); 1257 | 1258 | posix_cpu_timers_init(p); 1259 | 1260 | do_posix_clock_monotonic_gettime(&p->start_time); 1261 | p->real_start_time = p->start_time; 1262 | monotonic_to_bootbased(&p->real_start_time); 1263 | p->io_context = NULL; 1264 | p->audit_context = NULL; 1265 | if (clone_flags & CLONE_THREAD) 1266 | threadgroup_change_begin(current); 1267 | cgroup_fork(p); 1268 | #ifdef CONFIG_NUMA 1269 | p->mempolicy = mpol_dup(p->mempolicy); 1270 | if (IS_ERR(p->mempolicy)) { 1271 | retval = PTR_ERR(p->mempolicy); 1272 | p->mempolicy = NULL; 1273 | goto bad_fork_cleanup_cgroup; 1274 | } 1275 | mpol_fix_fork_child_flag(p); 1276 | #endif 1277 | #ifdef CONFIG_CPUSETS 1278 | p->cpuset_mem_spread_rotor = NUMA_NO_NODE; 1279 | p->cpuset_slab_spread_rotor = NUMA_NO_NODE; 1280 | seqcount_init(&p->mems_allowed_seq); 1281 | #endif 1282 | #ifdef CONFIG_TRACE_IRQFLAGS 1283 | p->irq_events = 0; 1284 | #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW 1285 | p->hardirqs_enabled = 1; 1286 | #else 1287 | p->hardirqs_enabled = 0; 1288 | #endif 1289 | p->hardirq_enable_ip = 0; 1290 | p->hardirq_enable_event = 0; 1291 | p->hardirq_disable_ip = _THIS_IP_; 1292 | p->hardirq_disable_event = 0; 1293 | p->softirqs_enabled = 1; 1294 | p->softirq_enable_ip = _THIS_IP_; 1295 | p->softirq_enable_event = 0; 1296 | p->softirq_disable_ip = 0; 1297 | p->softirq_disable_event = 0; 1298 | p->hardirq_context = 0; 1299 | p->softirq_context = 0; 1300 | #endif 1301 | #ifdef CONFIG_LOCKDEP 1302 | p->lockdep_depth = 0; /* no locks held yet */ 1303 | p->curr_chain_key = 0; 1304 | p->lockdep_recursion = 0; 1305 | #endif 1306 | 1307 | #ifdef CONFIG_DEBUG_MUTEXES 1308 | p->blocked_on = NULL; /* not blocked yet */ 1309 | #endif 1310 | #ifdef CONFIG_MEMCG 1311 | p->memcg_batch.do_batch = 0; 1312 | p->memcg_batch.memcg = NULL; 1313 | #endif 1314 | 1315 | /* Perform scheduler related setup. Assign this task to a CPU. */ 1316 | sched_fork(p); 1317 | 1318 | retval = perf_event_init_task(p); 1319 | if (retval) 1320 | goto bad_fork_cleanup_policy; 1321 | retval = audit_alloc(p); 1322 | if (retval) 1323 | goto bad_fork_cleanup_policy; 1324 | /* copy all the process information */ 1325 | retval = copy_semundo(clone_flags, p); 1326 | if (retval) 1327 | goto bad_fork_cleanup_audit; 1328 | retval = copy_files(clone_flags, p); 1329 | if (retval) 1330 | goto bad_fork_cleanup_semundo; 1331 | retval = copy_fs(clone_flags, p); 1332 | if (retval) 1333 | goto bad_fork_cleanup_files; 1334 | retval = copy_sighand(clone_flags, p); 1335 | if (retval) 1336 | goto bad_fork_cleanup_fs; 1337 | retval = copy_signal(clone_flags, p); 1338 | if (retval) 1339 | goto bad_fork_cleanup_sighand; 1340 | retval = copy_mm(clone_flags, p); 1341 | if (retval) 1342 | goto bad_fork_cleanup_signal; 1343 | retval = copy_namespaces(clone_flags, p); 1344 | if (retval) 1345 | goto bad_fork_cleanup_mm; 1346 | retval = copy_io(clone_flags, p); 1347 | if (retval) 1348 | goto bad_fork_cleanup_namespaces; 1349 | retval = copy_thread(clone_flags, stack_start, stack_size, p, regs); 1350 | if (retval) 1351 | goto bad_fork_cleanup_io; 1352 | 1353 | if (pid != &init_struct_pid) { 1354 | retval = -ENOMEM; 1355 | pid = alloc_pid(p->nsproxy->pid_ns); 1356 | if (!pid) 1357 | goto bad_fork_cleanup_io; 1358 | } 1359 | 1360 | p->pid = pid_nr(pid); 1361 | p->tgid = p->pid; 1362 | if (clone_flags & CLONE_THREAD) 1363 | p->tgid = current->tgid; 1364 | 1365 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; 1366 | /* 1367 | * Clear TID on mm_release()? 1368 | */ 1369 | p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr : NULL; 1370 | #ifdef CONFIG_BLOCK 1371 | p->plug = NULL; 1372 | #endif 1373 | #ifdef CONFIG_FUTEX 1374 | p->robust_list = NULL; 1375 | #ifdef CONFIG_COMPAT 1376 | p->compat_robust_list = NULL; 1377 | #endif 1378 | INIT_LIST_HEAD(&p->pi_state_list); 1379 | p->pi_state_cache = NULL; 1380 | #endif 1381 | uprobe_copy_process(p); 1382 | /* 1383 | * sigaltstack should be cleared when sharing the same VM 1384 | */ 1385 | if ((clone_flags & (CLONE_VM|CLONE_VFORK)) == CLONE_VM) 1386 | p->sas_ss_sp = p->sas_ss_size = 0; 1387 | 1388 | /* 1389 | * Syscall tracing and stepping should be turned off in the 1390 | * child regardless of CLONE_PTRACE. 1391 | */ 1392 | user_disable_single_step(p); 1393 | clear_tsk_thread_flag(p, TIF_SYSCALL_TRACE); 1394 | #ifdef TIF_SYSCALL_EMU 1395 | clear_tsk_thread_flag(p, TIF_SYSCALL_EMU); 1396 | #endif 1397 | clear_all_latency_tracing(p); 1398 | 1399 | /* ok, now we should be set up.. */ 1400 | if (clone_flags & CLONE_THREAD) 1401 | p->exit_signal = -1; 1402 | else if (clone_flags & CLONE_PARENT) 1403 | p->exit_signal = current->group_leader->exit_signal; 1404 | else 1405 | p->exit_signal = (clone_flags & CSIGNAL); 1406 | 1407 | p->pdeath_signal = 0; 1408 | p->exit_state = 0; 1409 | 1410 | p->nr_dirtied = 0; 1411 | p->nr_dirtied_pause = 128 >> (PAGE_SHIFT - 10); 1412 | p->dirty_paused_when = 0; 1413 | 1414 | /* 1415 | * Ok, make it visible to the rest of the system. 1416 | * We dont wake it up yet. 1417 | */ 1418 | p->group_leader = p; 1419 | INIT_LIST_HEAD(&p->thread_group); 1420 | p->task_works = NULL; 1421 | 1422 | /* Now that the task is set up, run cgroup callbacks if 1423 | * necessary. We need to run them before the task is visible 1424 | * on the tasklist. */ 1425 | cgroup_fork_callbacks(p); 1426 | cgroup_callbacks_done = 1; 1427 | 1428 | /* Need tasklist lock for parent etc handling! */ 1429 | write_lock_irq(&tasklist_lock); 1430 | 1431 | /* CLONE_PARENT re-uses the old parent */ 1432 | if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) { 1433 | p->real_parent = current->real_parent; 1434 | p->parent_exec_id = current->parent_exec_id; 1435 | } else { 1436 | p->real_parent = current; 1437 | p->parent_exec_id = current->self_exec_id; 1438 | } 1439 | 1440 | spin_lock(¤t->sighand->siglock); 1441 | 1442 | /* 1443 | * Process group and session signals need to be delivered to just the 1444 | * parent before the fork or both the parent and the child after the 1445 | * fork. Restart if a signal comes in before we add the new process to 1446 | * it's process group. 1447 | * A fatal signal pending means that current will exit, so the new 1448 | * thread can't slip out of an OOM kill (or normal SIGKILL). 1449 | */ 1450 | recalc_sigpending(); 1451 | if (signal_pending(current)) { 1452 | spin_unlock(¤t->sighand->siglock); 1453 | write_unlock_irq(&tasklist_lock); 1454 | retval = -ERESTARTNOINTR; 1455 | goto bad_fork_free_pid; 1456 | } 1457 | 1458 | if (clone_flags & CLONE_THREAD) { 1459 | current->signal->nr_threads++; 1460 | atomic_inc(¤t->signal->live); 1461 | atomic_inc(¤t->signal->sigcnt); 1462 | p->group_leader = current->group_leader; 1463 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); 1464 | } 1465 | 1466 | if (likely(p->pid)) { 1467 | ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace); 1468 | 1469 | if (thread_group_leader(p)) { 1470 | if (is_child_reaper(pid)) 1471 | p->nsproxy->pid_ns->child_reaper = p; 1472 | 1473 | p->signal->leader_pid = pid; 1474 | p->signal->tty = tty_kref_get(current->signal->tty); 1475 | attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); 1476 | attach_pid(p, PIDTYPE_SID, task_session(current)); 1477 | list_add_tail(&p->sibling, &p->real_parent->children); 1478 | list_add_tail_rcu(&p->tasks, &init_task.tasks); 1479 | __this_cpu_inc(process_counts); 1480 | } 1481 | attach_pid(p, PIDTYPE_PID, pid); 1482 | nr_threads++; 1483 | } 1484 | 1485 | total_forks++; 1486 | spin_unlock(¤t->sighand->siglock); 1487 | write_unlock_irq(&tasklist_lock); 1488 | proc_fork_connector(p); 1489 | cgroup_post_fork(p); 1490 | if (clone_flags & CLONE_THREAD) 1491 | threadgroup_change_end(current); 1492 | perf_event_fork(p); 1493 | 1494 | trace_task_newtask(p, clone_flags); 1495 | 1496 | return p; 1497 | 1498 | bad_fork_free_pid: 1499 | if (pid != &init_struct_pid) 1500 | free_pid(pid); 1501 | bad_fork_cleanup_io: 1502 | if (p->io_context) 1503 | exit_io_context(p); 1504 | bad_fork_cleanup_namespaces: 1505 | if (unlikely(clone_flags & CLONE_NEWPID)) 1506 | pid_ns_release_proc(p->nsproxy->pid_ns); 1507 | exit_task_namespaces(p); 1508 | bad_fork_cleanup_mm: 1509 | if (p->mm) 1510 | mmput(p->mm); 1511 | bad_fork_cleanup_signal: 1512 | if (!(clone_flags & CLONE_THREAD)) 1513 | free_signal_struct(p->signal); 1514 | bad_fork_cleanup_sighand: 1515 | __cleanup_sighand(p->sighand); 1516 | bad_fork_cleanup_fs: 1517 | exit_fs(p); /* blocking */ 1518 | bad_fork_cleanup_files: 1519 | exit_files(p); /* blocking */ 1520 | bad_fork_cleanup_semundo: 1521 | exit_sem(p); 1522 | bad_fork_cleanup_audit: 1523 | audit_free(p); 1524 | bad_fork_cleanup_policy: 1525 | perf_event_free_task(p); 1526 | #ifdef CONFIG_NUMA 1527 | mpol_put(p->mempolicy); 1528 | bad_fork_cleanup_cgroup: 1529 | #endif 1530 | if (clone_flags & CLONE_THREAD) 1531 | threadgroup_change_end(current); 1532 | cgroup_exit(p, cgroup_callbacks_done); 1533 | delayacct_tsk_free(p); 1534 | module_put(task_thread_info(p)->exec_domain->module); 1535 | bad_fork_cleanup_count: 1536 | atomic_dec(&p->cred->user->processes); 1537 | exit_creds(p); 1538 | bad_fork_free: 1539 | free_task(p); 1540 | fork_out: 1541 | return ERR_PTR(retval); 1542 | } 1543 | 1544 | noinline struct pt_regs * __cpuinit __attribute__((weak)) idle_regs(struct pt_regs *regs) 1545 | { 1546 | memset(regs, 0, sizeof(struct pt_regs)); 1547 | return regs; 1548 | } 1549 | 1550 | static inline void init_idle_pids(struct pid_link *links) 1551 | { 1552 | enum pid_type type; 1553 | 1554 | for (type = PIDTYPE_PID; type < PIDTYPE_MAX; ++type) { 1555 | INIT_HLIST_NODE(&links[type].node); /* not really needed */ 1556 | links[type].pid = &init_struct_pid; 1557 | } 1558 | } 1559 | 1560 | struct task_struct * __cpuinit fork_idle(int cpu) 1561 | { 1562 | struct task_struct *task; 1563 | struct pt_regs regs; 1564 | 1565 | task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, 1566 | &init_struct_pid, 0); 1567 | if (!IS_ERR(task)) { 1568 | init_idle_pids(task->pids); 1569 | init_idle(task, cpu); 1570 | } 1571 | 1572 | return task; 1573 | } 1574 | 1575 | /* 1576 | * Ok, this is the main fork-routine. 1577 | * 1578 | * It copies the process, and if successful kick-starts 1579 | * it and waits for it to finish using the VM if required. 1580 | */ 1581 | long do_fork(unsigned long clone_flags, 1582 | unsigned long stack_start, 1583 | struct pt_regs *regs, 1584 | unsigned long stack_size, 1585 | int __user *parent_tidptr, 1586 | int __user *child_tidptr) 1587 | { 1588 | struct task_struct *p; 1589 | int trace = 0; 1590 | long nr; 1591 | 1592 | /* 1593 | * Do some preliminary argument and permissions checking before we 1594 | * actually start allocating stuff 1595 | */ 1596 | if (clone_flags & CLONE_NEWUSER) { 1597 | if (clone_flags & CLONE_THREAD) 1598 | return -EINVAL; 1599 | /* hopefully this check will go away when userns support is 1600 | * complete 1601 | */ 1602 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) || 1603 | !capable(CAP_SETGID)) 1604 | return -EPERM; 1605 | } 1606 | 1607 | /* 1608 | * Determine whether and which event to report to ptracer. When 1609 | * called from kernel_thread or CLONE_UNTRACED is explicitly 1610 | * requested, no event is reported; otherwise, report if the event 1611 | * for the type of forking is enabled. 1612 | */ 1613 | if (likely(user_mode(regs)) && !(clone_flags & CLONE_UNTRACED)) { 1614 | if (clone_flags & CLONE_VFORK) 1615 | trace = PTRACE_EVENT_VFORK; 1616 | else if ((clone_flags & CSIGNAL) != SIGCHLD) 1617 | trace = PTRACE_EVENT_CLONE; 1618 | else 1619 | trace = PTRACE_EVENT_FORK; 1620 | 1621 | if (likely(!ptrace_event_enabled(current, trace))) 1622 | trace = 0; 1623 | } 1624 | 1625 | p = copy_process(clone_flags, stack_start, regs, stack_size, 1626 | child_tidptr, NULL, trace); 1627 | /* 1628 | * Do this prior waking up the new thread - the thread pointer 1629 | * might get invalid after that point, if the thread exits quickly. 1630 | */ 1631 | if (!IS_ERR(p)) { 1632 | struct completion vfork; 1633 | 1634 | trace_sched_process_fork(current, p); 1635 | 1636 | nr = task_pid_vnr(p); 1637 | 1638 | if (clone_flags & CLONE_PARENT_SETTID) 1639 | put_user(nr, parent_tidptr); 1640 | 1641 | if (clone_flags & CLONE_VFORK) { 1642 | p->vfork_done = &vfork; 1643 | init_completion(&vfork); 1644 | get_task_struct(p); 1645 | } 1646 | 1647 | wake_up_new_task(p); 1648 | 1649 | /* forking complete and child started to run, tell ptracer */ 1650 | if (unlikely(trace)) 1651 | ptrace_event(trace, nr); 1652 | 1653 | if (clone_flags & CLONE_VFORK) { 1654 | if (!wait_for_vfork_done(p, &vfork)) 1655 | ptrace_event(PTRACE_EVENT_VFORK_DONE, nr); 1656 | } 1657 | } else { 1658 | nr = PTR_ERR(p); 1659 | } 1660 | return nr; 1661 | } 1662 | 1663 | #ifndef ARCH_MIN_MMSTRUCT_ALIGN 1664 | #define ARCH_MIN_MMSTRUCT_ALIGN 0 1665 | #endif 1666 | 1667 | static void sighand_ctor(void *data) 1668 | { 1669 | struct sighand_struct *sighand = data; 1670 | 1671 | spin_lock_init(&sighand->siglock); 1672 | init_waitqueue_head(&sighand->signalfd_wqh); 1673 | } 1674 | 1675 | void __init proc_caches_init(void) 1676 | { 1677 | sighand_cachep = kmem_cache_create("sighand_cache", 1678 | sizeof(struct sighand_struct), 0, 1679 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_DESTROY_BY_RCU| 1680 | SLAB_NOTRACK, sighand_ctor); 1681 | signal_cachep = kmem_cache_create("signal_cache", 1682 | sizeof(struct signal_struct), 0, 1683 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL); 1684 | files_cachep = kmem_cache_create("files_cache", 1685 | sizeof(struct files_struct), 0, 1686 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL); 1687 | fs_cachep = kmem_cache_create("fs_cache", 1688 | sizeof(struct fs_struct), 0, 1689 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL); 1690 | /* 1691 | * FIXME! The "sizeof(struct mm_struct)" currently includes the 1692 | * whole struct cpumask for the OFFSTACK case. We could change 1693 | * this to *only* allocate as much of it as required by the 1694 | * maximum number of CPU's we can ever have. The cpumask_allocation 1695 | * is at the end of the structure, exactly for that reason. 1696 | */ 1697 | mm_cachep = kmem_cache_create("mm_struct", 1698 | sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN, 1699 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL); 1700 | vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC); 1701 | mmap_init(); 1702 | nsproxy_cache_init(); 1703 | } 1704 | 1705 | /* 1706 | * Check constraints on flags passed to the unshare system call. 1707 | */ 1708 | static int check_unshare_flags(unsigned long unshare_flags) 1709 | { 1710 | if (unshare_flags & ~(CLONE_THREAD|CLONE_FS|CLONE_NEWNS|CLONE_SIGHAND| 1711 | CLONE_VM|CLONE_FILES|CLONE_SYSVSEM| 1712 | CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET)) 1713 | return -EINVAL; 1714 | /* 1715 | * Not implemented, but pretend it works if there is nothing to 1716 | * unshare. Note that unsharing CLONE_THREAD or CLONE_SIGHAND 1717 | * needs to unshare vm. 1718 | */ 1719 | if (unshare_flags & (CLONE_THREAD | CLONE_SIGHAND | CLONE_VM)) { 1720 | /* FIXME: get_task_mm() increments ->mm_users */ 1721 | if (atomic_read(¤t->mm->mm_users) > 1) 1722 | return -EINVAL; 1723 | } 1724 | 1725 | return 0; 1726 | } 1727 | 1728 | /* 1729 | * Unshare the filesystem structure if it is being shared 1730 | */ 1731 | static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp) 1732 | { 1733 | struct fs_struct *fs = current->fs; 1734 | 1735 | if (!(unshare_flags & CLONE_FS) || !fs) 1736 | return 0; 1737 | 1738 | /* don't need lock here; in the worst case we'll do useless copy */ 1739 | if (fs->users == 1) 1740 | return 0; 1741 | 1742 | *new_fsp = copy_fs_struct(fs); 1743 | if (!*new_fsp) 1744 | return -ENOMEM; 1745 | 1746 | return 0; 1747 | } 1748 | 1749 | /* 1750 | * Unshare file descriptor table if it is being shared 1751 | */ 1752 | static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp) 1753 | { 1754 | struct files_struct *fd = current->files; 1755 | int error = 0; 1756 | 1757 | if ((unshare_flags & CLONE_FILES) && 1758 | (fd && atomic_read(&fd->count) > 1)) { 1759 | *new_fdp = dup_fd(fd, &error); 1760 | if (!*new_fdp) 1761 | return error; 1762 | } 1763 | 1764 | return 0; 1765 | } 1766 | 1767 | /* 1768 | * unshare allows a process to 'unshare' part of the process 1769 | * context which was originally shared using clone. copy_* 1770 | * functions used by do_fork() cannot be used here directly 1771 | * because they modify an inactive task_struct that is being 1772 | * constructed. Here we are modifying the current, active, 1773 | * task_struct. 1774 | */ 1775 | SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags) 1776 | { 1777 | struct fs_struct *fs, *new_fs = NULL; 1778 | struct files_struct *fd, *new_fd = NULL; 1779 | struct nsproxy *new_nsproxy = NULL; 1780 | int do_sysvsem = 0; 1781 | int err; 1782 | 1783 | err = check_unshare_flags(unshare_flags); 1784 | if (err) 1785 | goto bad_unshare_out; 1786 | 1787 | /* 1788 | * If unsharing namespace, must also unshare filesystem information. 1789 | */ 1790 | if (unshare_flags & CLONE_NEWNS) 1791 | unshare_flags |= CLONE_FS; 1792 | /* 1793 | * CLONE_NEWIPC must also detach from the undolist: after switching 1794 | * to a new ipc namespace, the semaphore arrays from the old 1795 | * namespace are unreachable. 1796 | */ 1797 | if (unshare_flags & (CLONE_NEWIPC|CLONE_SYSVSEM)) 1798 | do_sysvsem = 1; 1799 | err = unshare_fs(unshare_flags, &new_fs); 1800 | if (err) 1801 | goto bad_unshare_out; 1802 | err = unshare_fd(unshare_flags, &new_fd); 1803 | if (err) 1804 | goto bad_unshare_cleanup_fs; 1805 | err = unshare_nsproxy_namespaces(unshare_flags, &new_nsproxy, new_fs); 1806 | if (err) 1807 | goto bad_unshare_cleanup_fd; 1808 | 1809 | if (new_fs || new_fd || do_sysvsem || new_nsproxy) { 1810 | if (do_sysvsem) { 1811 | /* 1812 | * CLONE_SYSVSEM is equivalent to sys_exit(). 1813 | */ 1814 | exit_sem(current); 1815 | } 1816 | 1817 | if (new_nsproxy) { 1818 | switch_task_namespaces(current, new_nsproxy); 1819 | new_nsproxy = NULL; 1820 | } 1821 | 1822 | task_lock(current); 1823 | 1824 | if (new_fs) { 1825 | fs = current->fs; 1826 | spin_lock(&fs->lock); 1827 | current->fs = new_fs; 1828 | if (--fs->users) 1829 | new_fs = NULL; 1830 | else 1831 | new_fs = fs; 1832 | spin_unlock(&fs->lock); 1833 | } 1834 | 1835 | if (new_fd) { 1836 | fd = current->files; 1837 | current->files = new_fd; 1838 | new_fd = fd; 1839 | } 1840 | 1841 | task_unlock(current); 1842 | } 1843 | 1844 | if (new_nsproxy) 1845 | put_nsproxy(new_nsproxy); 1846 | 1847 | bad_unshare_cleanup_fd: 1848 | if (new_fd) 1849 | put_files_struct(new_fd); 1850 | 1851 | bad_unshare_cleanup_fs: 1852 | if (new_fs) 1853 | free_fs_struct(new_fs); 1854 | 1855 | bad_unshare_out: 1856 | return err; 1857 | } 1858 | 1859 | /* 1860 | * Helper to unshare the files of the current task. 1861 | * We don't want to expose copy_files internals to 1862 | * the exec layer of the kernel. 1863 | */ 1864 | 1865 | int unshare_files(struct files_struct **displaced) 1866 | { 1867 | struct task_struct *task = current; 1868 | struct files_struct *copy = NULL; 1869 | int error; 1870 | 1871 | error = unshare_fd(CLONE_FILES, ©); 1872 | if (error || !copy) { 1873 | *displaced = NULL; 1874 | return error; 1875 | } 1876 | *displaced = task->files; 1877 | task_lock(task); 1878 | task->files = copy; 1879 | task_unlock(task); 1880 | return 0; 1881 | } 1882 | --------------------------------------------------------------------------------