diff --git a/so3/Kbuild b/so3/Kbuild index c809513d1..fcea8718a 100644 --- a/so3/Kbuild +++ b/so3/Kbuild @@ -2,15 +2,31 @@ # Kbuild for top-level directory of the kernel # This file takes care of the following: -# Generate asm-offsets.h +# Generate syscall_table.h.in and syscall_number.h + +syscall-files = include/generated/syscall_table.h.in +syscall-files += include/generated/syscall_number.h +syscall-script = scripts/syscall_gen.sh +syscall-src = syscall.tbl arch/$(SRCARCH)/syscall.h.in + +quiet_cmd_syscall_gen = GEN $@ + cmd_syscall_gen = $(syscall-script) $(syscall-src) $(syscall-files) + +$(syscall-files) &: $(syscall-script) $(syscall-src) Kbuild FORCE + $(call if_changed,syscall_gen) + +always := $(syscall-files) +targets := $(syscall-files) + +# Generate asm-offsets.h # offsets-file := include/generated/asm-offsets.h -always := $(offsets-file) -targets := $(offsets-file) +always += $(offsets-file) +targets += $(offsets-file) targets += arch/$(SRCARCH)/asm-offsets.s - + # Default sed regexp - multiline due to syntax constraints define sed-y "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}" @@ -34,10 +50,9 @@ define cmd_offsets endef # We use internal kbuild rules to avoid the "is up to date" message from make -arch/$(SRCARCH)/asm-offsets.s: $(srctree)/arch/$(SRCARCH)/asm-offsets.c FORCE +arch/$(SRCARCH)/asm-offsets.s: $(srctree)/arch/$(SRCARCH)/asm-offsets.c include/generated/syscall_number.h FORCE $(Q)mkdir -p $(dir $@) $(call if_changed_dep,cc_s_c) $(offsets-file): arch/$(SRCARCH)/asm-offsets.s Kbuild $(call cmd,offsets) - diff --git a/so3/arch/arm32/context.S b/so3/arch/arm32/context.S index 3b20ef879..5e4f3b0a6 100644 --- a/so3/arch/arm32/context.S +++ b/so3/arch/arm32/context.S @@ -272,7 +272,7 @@ ENTRY(__root_proc) mov r0, #STDOUT adr r1, .LC_welcome mov r2, #welcome_len - mov r7, #SYSCALL_WRITE + mov r7, #SYSCALL_write @ Invoke the syscall - kernel side svc 0 @@ -282,6 +282,6 @@ ENTRY(__root_proc) mov r1, #0 mov r2, #0 - mov r7, #SYSCALL_EXECVE + mov r7, #SYSCALL_execve svc 0 diff --git a/so3/arch/arm32/exception.S b/so3/arch/arm32/exception.S index 02d03537b..6f7ac347a 100644 --- a/so3/arch/arm32/exception.S +++ b/so3/arch/arm32/exception.S @@ -199,7 +199,7 @@ syscall_interrupt: add lr, sp, #OFFSET_SP_USR stmia lr, {sp, lr}^ - cmp r7, #SYSCALL_SIGRETURN + cmp r7, #SYSCALL_sigreturn beq __after_push_sp_usr ldr r0, [sp, #OFFSET_SP_USR] @@ -228,7 +228,7 @@ __after_push_sp_usr: @ Check if sigreturn has been called. In this case, we @ clean the stack frame which has been used to manage the user handler. - cmp r7, #SYSCALL_SIGRETURN + cmp r7, #SYSCALL_sigreturn bne __no_sigreturn @ Reset the stack frame by removing the one issued from sigreturn @@ -246,7 +246,7 @@ __no_sigreturn: __ret_from_fork: @ Store the return value on the stack frame - cmp r7, #SYSCALL_SIGRETURN + cmp r7, #SYSCALL_sigreturn strne r0, [sp, #OFFSET_R0] #ifdef CONFIG_IPC_SIGNAL diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h deleted file mode 100644 index 9f6552805..000000000 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2025 Clement Dieperink - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef ARCH_ARM32_SYSCALL_NUMBER_H -#define ARCH_ARM32_SYSCALL_NUMBER_H - -/* - * Syscall number definition - */ - -#define SYSCALL_EXIT 1 -#define SYSCALL_FORK 2 -#define SYSCALL_READ 3 -#define SYSCALL_WRITE 4 -#define SYSCALL_OPEN 5 -#define SYSCALL_CLOSE 6 - -#define SYSCALL_EXECVE 11 - -#define SYSCALL_LSEEK 19 -#define SYSCALL_GETPID 20 - -#define SYSCALL_PTRACE 26 - -#define SYSCALL_KILL 37 - -#define SYSCALL_DUP 41 -#define SYSCALL_PIPE 42 - -#define SYSCALL_BRK 45 - -#define SYSCALL_IOCTL 54 - -#define SYSCALL_DUP2 63 - -#define SYSCALL_GETTIMEOFDAY_TIME32 78 - -#define SYSCALL_WAIT4 114 - -#define SYSCALL_SIGRETURN 119 - -#define SYSCALL_READV 145 -#define SYSCALL_WRITEV 146 - -#define SYSCALL_NANOSLEEP 162 - -#define SYSCALL_RT_SIGRETURN 173 -#define SYSCALL_RT_SIGACTION 174 - -#define SYSCALL_MMAP2 192 - -#define SYSCALL_STAT64 195 - -#define SYSCALL_GETDENTS64 217 - -#define SYSCALL_CLOCK_GETTIME32 263 - -#define SYSCALL_SOCKET 281 -#define SYSCALL_BIND 282 -#define SYSCALL_CONNECT 283 -#define SYSCALL_LISTEN 284 -#define SYSCALL_ACCEPT 285 - -#define SYSCALL_SEND 289 -#define SYSCALL_SENDTO 290 - -#define SYSCALL_RECV 291 -#define SYSCALL_RECVFROM 292 - -#define SYSCALL_SETSOCKOPT 294 - -#define SYSCALL_OPENAT 322 - -#define SYSCALL_FSTATAT64 327 - -#define SYSCALL_DUP3 358 -#define SYSCALL_PIPE2 359 - -#define SYSCALL_CLOCK_GETTIME64 403 - -/* Following syscalls still need to be aligned */ -#define SYSCALL_THREAD_CREATE 16 -#define SYSCALL_THREAD_JOIN 17 -#define SYSCALL_THREAD_EXIT 18 -#define SYSCALL_THREAD_YIELD 43 - -#define SYSCALL_MUTEX_LOCK 60 -#define SYSCALL_MUTEX_UNLOCK 61 - -#endif /* ARCH_ARM32_SYSCALL_NUMBER_H */ diff --git a/so3/arch/arm32/syscall.h.in b/so3/arch/arm32/syscall.h.in new file mode 100644 index 000000000..54cd3b01c --- /dev/null +++ b/so3/arch/arm32/syscall.h.in @@ -0,0 +1,420 @@ +/* + * This files is copied from musl library and should not be included. + * Include generated/syscall_number.h instead. + * + * Original file from musl 1.2.5: arch/arm32/bits/syscall.h.in + */ +#define __NR_restart_syscall 0 +#define __NR_exit 1 +#define __NR_fork 2 +#define __NR_read 3 +#define __NR_write 4 +#define __NR_open 5 +#define __NR_close 6 +#define __NR_creat 8 +#define __NR_link 9 +#define __NR_unlink 10 +#define __NR_execve 11 +#define __NR_chdir 12 +#define __NR_mknod 14 +#define __NR_chmod 15 +#define __NR_lchown 16 +#define __NR_lseek 19 +#define __NR_getpid 20 +#define __NR_mount 21 +#define __NR_setuid 23 +#define __NR_getuid 24 +#define __NR_ptrace 26 +#define __NR_pause 29 +#define __NR_access 33 +#define __NR_nice 34 +#define __NR_sync 36 +#define __NR_kill 37 +#define __NR_rename 38 +#define __NR_mkdir 39 +#define __NR_rmdir 40 +#define __NR_dup 41 +#define __NR_pipe 42 +#define __NR_times 43 +#define __NR_brk 45 +#define __NR_setgid 46 +#define __NR_getgid 47 +#define __NR_geteuid 49 +#define __NR_getegid 50 +#define __NR_acct 51 +#define __NR_umount2 52 +#define __NR_ioctl 54 +#define __NR_fcntl 55 +#define __NR_setpgid 57 +#define __NR_umask 60 +#define __NR_chroot 61 +#define __NR_ustat 62 +#define __NR_dup2 63 +#define __NR_getppid 64 +#define __NR_getpgrp 65 +#define __NR_setsid 66 +#define __NR_sigaction 67 +#define __NR_setreuid 70 +#define __NR_setregid 71 +#define __NR_sigsuspend 72 +#define __NR_sigpending 73 +#define __NR_sethostname 74 +#define __NR_setrlimit 75 +#define __NR_getrusage 77 +#define __NR_gettimeofday_time32 78 +#define __NR_settimeofday_time32 79 +#define __NR_getgroups 80 +#define __NR_setgroups 81 +#define __NR_symlink 83 +#define __NR_readlink 85 +#define __NR_uselib 86 +#define __NR_swapon 87 +#define __NR_reboot 88 +#define __NR_munmap 91 +#define __NR_truncate 92 +#define __NR_ftruncate 93 +#define __NR_fchmod 94 +#define __NR_fchown 95 +#define __NR_getpriority 96 +#define __NR_setpriority 97 +#define __NR_statfs 99 +#define __NR_fstatfs 100 +#define __NR_syslog 103 +#define __NR_setitimer 104 +#define __NR_getitimer 105 +#define __NR_stat 106 +#define __NR_lstat 107 +#define __NR_fstat 108 +#define __NR_vhangup 111 +#define __NR_wait4 114 +#define __NR_swapoff 115 +#define __NR_sysinfo 116 +#define __NR_fsync 118 +#define __NR_sigreturn 119 +#define __NR_clone 120 +#define __NR_setdomainname 121 +#define __NR_uname 122 +#define __NR_adjtimex 124 +#define __NR_mprotect 125 +#define __NR_sigprocmask 126 +#define __NR_init_module 128 +#define __NR_delete_module 129 +#define __NR_quotactl 131 +#define __NR_getpgid 132 +#define __NR_fchdir 133 +#define __NR_bdflush 134 +#define __NR_sysfs 135 +#define __NR_personality 136 +#define __NR_setfsuid 138 +#define __NR_setfsgid 139 +#define __NR__llseek 140 +#define __NR_getdents 141 +#define __NR__newselect 142 +#define __NR_flock 143 +#define __NR_msync 144 +#define __NR_readv 145 +#define __NR_writev 146 +#define __NR_getsid 147 +#define __NR_fdatasync 148 +#define __NR__sysctl 149 +#define __NR_mlock 150 +#define __NR_munlock 151 +#define __NR_mlockall 152 +#define __NR_munlockall 153 +#define __NR_sched_setparam 154 +#define __NR_sched_getparam 155 +#define __NR_sched_setscheduler 156 +#define __NR_sched_getscheduler 157 +#define __NR_sched_yield 158 +#define __NR_sched_get_priority_max 159 +#define __NR_sched_get_priority_min 160 +#define __NR_sched_rr_get_interval 161 +#define __NR_nanosleep 162 +#define __NR_mremap 163 +#define __NR_setresuid 164 +#define __NR_getresuid 165 +#define __NR_poll 168 +#define __NR_nfsservctl 169 +#define __NR_setresgid 170 +#define __NR_getresgid 171 +#define __NR_prctl 172 +#define __NR_rt_sigreturn 173 +#define __NR_rt_sigaction 174 +#define __NR_rt_sigprocmask 175 +#define __NR_rt_sigpending 176 +#define __NR_rt_sigtimedwait 177 +#define __NR_rt_sigqueueinfo 178 +#define __NR_rt_sigsuspend 179 +#define __NR_pread64 180 +#define __NR_pwrite64 181 +#define __NR_chown 182 +#define __NR_getcwd 183 +#define __NR_capget 184 +#define __NR_capset 185 +#define __NR_sigaltstack 186 +#define __NR_sendfile 187 +#define __NR_vfork 190 +#define __NR_ugetrlimit 191 +#define __NR_mmap2 192 +#define __NR_truncate64 193 +#define __NR_ftruncate64 194 +#define __NR_stat64 195 +#define __NR_lstat64 196 +#define __NR_fstat64 197 +#define __NR_lchown32 198 +#define __NR_getuid32 199 +#define __NR_getgid32 200 +#define __NR_geteuid32 201 +#define __NR_getegid32 202 +#define __NR_setreuid32 203 +#define __NR_setregid32 204 +#define __NR_getgroups32 205 +#define __NR_setgroups32 206 +#define __NR_fchown32 207 +#define __NR_setresuid32 208 +#define __NR_getresuid32 209 +#define __NR_setresgid32 210 +#define __NR_getresgid32 211 +#define __NR_chown32 212 +#define __NR_setuid32 213 +#define __NR_setgid32 214 +#define __NR_setfsuid32 215 +#define __NR_setfsgid32 216 +#define __NR_getdents64 217 +#define __NR_pivot_root 218 +#define __NR_mincore 219 +#define __NR_madvise 220 +#define __NR_fcntl64 221 +#define __NR_gettid 224 +#define __NR_readahead 225 +#define __NR_setxattr 226 +#define __NR_lsetxattr 227 +#define __NR_fsetxattr 228 +#define __NR_getxattr 229 +#define __NR_lgetxattr 230 +#define __NR_fgetxattr 231 +#define __NR_listxattr 232 +#define __NR_llistxattr 233 +#define __NR_flistxattr 234 +#define __NR_removexattr 235 +#define __NR_lremovexattr 236 +#define __NR_fremovexattr 237 +#define __NR_tkill 238 +#define __NR_sendfile64 239 +#define __NR_futex 240 +#define __NR_sched_setaffinity 241 +#define __NR_sched_getaffinity 242 +#define __NR_io_setup 243 +#define __NR_io_destroy 244 +#define __NR_io_getevents 245 +#define __NR_io_submit 246 +#define __NR_io_cancel 247 +#define __NR_exit_group 248 +#define __NR_lookup_dcookie 249 +#define __NR_epoll_create 250 +#define __NR_epoll_ctl 251 +#define __NR_epoll_wait 252 +#define __NR_remap_file_pages 253 +#define __NR_set_tid_address 256 +#define __NR_timer_create 257 +#define __NR_timer_settime32 258 +#define __NR_timer_gettime32 259 +#define __NR_timer_getoverrun 260 +#define __NR_timer_delete 261 +#define __NR_clock_settime32 262 +#define __NR_clock_gettime32 263 +#define __NR_clock_getres_time32 264 +#define __NR_clock_nanosleep_time32 265 +#define __NR_statfs64 266 +#define __NR_fstatfs64 267 +#define __NR_tgkill 268 +#define __NR_utimes 269 +#define __NR_fadvise64_64 270 +#define __NR_arm_fadvise64_64 270 +#define __NR_pciconfig_iobase 271 +#define __NR_pciconfig_read 272 +#define __NR_pciconfig_write 273 +#define __NR_mq_open 274 +#define __NR_mq_unlink 275 +#define __NR_mq_timedsend 276 +#define __NR_mq_timedreceive 277 +#define __NR_mq_notify 278 +#define __NR_mq_getsetattr 279 +#define __NR_waitid 280 +#define __NR_socket 281 +#define __NR_bind 282 +#define __NR_connect 283 +#define __NR_listen 284 +#define __NR_accept 285 +#define __NR_getsockname 286 +#define __NR_getpeername 287 +#define __NR_socketpair 288 +#define __NR_send 289 +#define __NR_sendto 290 +#define __NR_recv 291 +#define __NR_recvfrom 292 +#define __NR_shutdown 293 +#define __NR_setsockopt 294 +#define __NR_getsockopt 295 +#define __NR_sendmsg 296 +#define __NR_recvmsg 297 +#define __NR_semop 298 +#define __NR_semget 299 +#define __NR_semctl 300 +#define __NR_msgsnd 301 +#define __NR_msgrcv 302 +#define __NR_msgget 303 +#define __NR_msgctl 304 +#define __NR_shmat 305 +#define __NR_shmdt 306 +#define __NR_shmget 307 +#define __NR_shmctl 308 +#define __NR_add_key 309 +#define __NR_request_key 310 +#define __NR_keyctl 311 +#define __NR_semtimedop 312 +#define __NR_vserver 313 +#define __NR_ioprio_set 314 +#define __NR_ioprio_get 315 +#define __NR_inotify_init 316 +#define __NR_inotify_add_watch 317 +#define __NR_inotify_rm_watch 318 +#define __NR_mbind 319 +#define __NR_get_mempolicy 320 +#define __NR_set_mempolicy 321 +#define __NR_openat 322 +#define __NR_mkdirat 323 +#define __NR_mknodat 324 +#define __NR_fchownat 325 +#define __NR_futimesat 326 +#define __NR_fstatat64 327 +#define __NR_unlinkat 328 +#define __NR_renameat 329 +#define __NR_linkat 330 +#define __NR_symlinkat 331 +#define __NR_readlinkat 332 +#define __NR_fchmodat 333 +#define __NR_faccessat 334 +#define __NR_pselect6 335 +#define __NR_ppoll 336 +#define __NR_unshare 337 +#define __NR_set_robust_list 338 +#define __NR_get_robust_list 339 +#define __NR_splice 340 +#define __NR_sync_file_range2 341 +#define __NR_arm_sync_file_range 341 +#define __NR_tee 342 +#define __NR_vmsplice 343 +#define __NR_move_pages 344 +#define __NR_getcpu 345 +#define __NR_epoll_pwait 346 +#define __NR_kexec_load 347 +#define __NR_utimensat 348 +#define __NR_signalfd 349 +#define __NR_timerfd_create 350 +#define __NR_eventfd 351 +#define __NR_fallocate 352 +#define __NR_timerfd_settime32 353 +#define __NR_timerfd_gettime32 354 +#define __NR_signalfd4 355 +#define __NR_eventfd2 356 +#define __NR_epoll_create1 357 +#define __NR_dup3 358 +#define __NR_pipe2 359 +#define __NR_inotify_init1 360 +#define __NR_preadv 361 +#define __NR_pwritev 362 +#define __NR_rt_tgsigqueueinfo 363 +#define __NR_perf_event_open 364 +#define __NR_recvmmsg 365 +#define __NR_accept4 366 +#define __NR_fanotify_init 367 +#define __NR_fanotify_mark 368 +#define __NR_prlimit64 369 +#define __NR_name_to_handle_at 370 +#define __NR_open_by_handle_at 371 +#define __NR_clock_adjtime 372 +#define __NR_syncfs 373 +#define __NR_sendmmsg 374 +#define __NR_setns 375 +#define __NR_process_vm_readv 376 +#define __NR_process_vm_writev 377 +#define __NR_kcmp 378 +#define __NR_finit_module 379 +#define __NR_sched_setattr 380 +#define __NR_sched_getattr 381 +#define __NR_renameat2 382 +#define __NR_seccomp 383 +#define __NR_getrandom 384 +#define __NR_memfd_create 385 +#define __NR_bpf 386 +#define __NR_execveat 387 +#define __NR_userfaultfd 388 +#define __NR_membarrier 389 +#define __NR_mlock2 390 +#define __NR_copy_file_range 391 +#define __NR_preadv2 392 +#define __NR_pwritev2 393 +#define __NR_pkey_mprotect 394 +#define __NR_pkey_alloc 395 +#define __NR_pkey_free 396 +#define __NR_statx 397 +#define __NR_rseq 398 +#define __NR_io_pgetevents 399 +#define __NR_migrate_pages 400 +#define __NR_kexec_file_load 401 +#define __NR_clock_gettime64 403 +#define __NR_clock_settime64 404 +#define __NR_clock_adjtime64 405 +#define __NR_clock_getres_time64 406 +#define __NR_clock_nanosleep_time64 407 +#define __NR_timer_gettime64 408 +#define __NR_timer_settime64 409 +#define __NR_timerfd_gettime64 410 +#define __NR_timerfd_settime64 411 +#define __NR_utimensat_time64 412 +#define __NR_pselect6_time64 413 +#define __NR_ppoll_time64 414 +#define __NR_io_pgetevents_time64 416 +#define __NR_recvmmsg_time64 417 +#define __NR_mq_timedsend_time64 418 +#define __NR_mq_timedreceive_time64 419 +#define __NR_semtimedop_time64 420 +#define __NR_rt_sigtimedwait_time64 421 +#define __NR_futex_time64 422 +#define __NR_sched_rr_get_interval_time64 423 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433 +#define __NR_pidfd_open 434 +#define __NR_clone3 435 +#define __NR_close_range 436 +#define __NR_openat2 437 +#define __NR_pidfd_getfd 438 +#define __NR_faccessat2 439 +#define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_restrict_self 446 +#define __NR_process_mrelease 448 +#define __NR_futex_waitv 449 +#define __NR_set_mempolicy_home_node 450 +#define __NR_cachestat 451 +#define __NR_fchmodat2 452 + +#define __ARM_NR_breakpoint 0x0f0001 +#define __ARM_NR_cacheflush 0x0f0002 +#define __ARM_NR_usr26 0x0f0003 +#define __ARM_NR_usr32 0x0f0004 +#define __ARM_NR_set_tls 0x0f0005 +#define __ARM_NR_get_tls 0x0f0006 + diff --git a/so3/arch/arm64/context.S b/so3/arch/arm64/context.S index 25a351731..02dadb14e 100644 --- a/so3/arch/arm64/context.S +++ b/so3/arch/arm64/context.S @@ -293,7 +293,7 @@ ENTRY(__root_proc) mov x0, #STDOUT adr x1, .LC_welcome mov x2, welcome_len - mov x8, #SYSCALL_WRITE + mov x8, #SYSCALL_write // Invoke the syscall - kernel side svc 0 @@ -306,7 +306,7 @@ ENTRY(__root_proc) mov x1, xzr mov x2, xzr - mov x8, #SYSCALL_EXECVE + mov x8, #SYSCALL_execve svc 0 @@ -315,7 +315,7 @@ ENTRY(__root_proc) mov x0, #STDOUT adr x1, .LCnoshell mov x2, noshell_len - mov x8, #SYSCALL_WRITE + mov x8, #SYSCALL_write svc 0 diff --git a/so3/arch/arm64/exception.S b/so3/arch/arm64/exception.S index cf58242bc..4d8cd4a7f 100644 --- a/so3/arch/arm64/exception.S +++ b/so3/arch/arm64/exception.S @@ -557,7 +557,7 @@ el01_sync_handler: // Check if sigreturn has been called. In this case, we // clean the stack frame which has been used to manage the user handler. - cmp x8, #SYSCALL_RT_SIGRETURN + cmp x8, #SYSCALL_rt_sigreturn bne __ret_from_fork // Reset the stack frame by removing the one issued from sigreturn diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h deleted file mode 100644 index be298b5f0..000000000 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2025 Clement Dieperink - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef ARCH_ARM64_SYSCALL_NUMBER_H -#define ARCH_ARM64_SYSCALL_NUMBER_H - -/* - * Syscall number definition - */ -#define SYSCALL_DUP 23 -#define SYSCALL_DUP3 24 - -#define SYSCALL_IOCTL 29 - -#define SYSCALL_OPENAT 56 -#define SYSCALL_CLOSE 57 - -#define SYSCALL_PIPE2 59 - -#define SYSCALL_GETDENTS64 61 -#define SYSCALL_LSEEK 62 -#define SYSCALL_READ 63 -#define SYSCALL_WRITE 64 -#define SYSCALL_READV 65 -#define SYSCALL_WRITEV 66 - -#define SYSCALL_NEWFSTATAT 79 - -#define SYSCALL_EXIT 93 - -#define SYSCALL_NANOSLEEP 101 - -#define SYSCALL_CLOCK_GETTIME 113 - -#define SYSCALL_PTRACE 117 - -#define SYSCALL_KILL 129 - -#define SYSCALL_RT_SIGACTION 134 - -#define SYSCALL_RT_SIGRETURN 139 - -#define SYSCALL_GETTIMEOFDAY 169 - -#define SYSCALL_GETPID 172 - -#define SYSCALL_SOCKET 198 - -#define SYSCALL_BIND 200 -#define SYSCALL_LISTEN 201 -#define SYSCALL_ACCEPT 202 -#define SYSCALL_CONNECT 203 - -#define SYSCALL_SENDTO 206 -#define SYSCALL_RECVFROM 207 -#define SYSCALL_SETSOCKOPT 208 - -#define SYSCALL_BRK 214 - -#define SYSCALL_EXECVE 221 -#define SYSCALL_MMAP 222 - -#define SYSCALL_WAIT4 260 - -/* Following syscalls still need to be aligned */ -#define SYSCALL_FORK 7 // => clone - -#define SYSCALL_THREAD_CREATE 16 -#define SYSCALL_THREAD_JOIN 17 -#define SYSCALL_THREAD_EXIT 18 -#define SYSCALL_THREAD_YIELD 43 - -#define SYSCALL_MUTEX_LOCK 60 -#define SYSCALL_MUTEX_UNLOCK 61 - -#endif /* ARCH_ARM64_SYSCALL_NUMBER_H */ diff --git a/so3/arch/arm64/syscall.h.in b/so3/arch/arm64/syscall.h.in new file mode 100644 index 000000000..87755c024 --- /dev/null +++ b/so3/arch/arm64/syscall.h.in @@ -0,0 +1,312 @@ +/* + * This files is copied from musl library and should not be included. + * Include generated/syscall_number.h instead. + * + * Original file from musl 1.2.5: arch/aarch64/bits/syscall.h.in + */ +#define __NR_io_setup 0 +#define __NR_io_destroy 1 +#define __NR_io_submit 2 +#define __NR_io_cancel 3 +#define __NR_io_getevents 4 +#define __NR_setxattr 5 +#define __NR_lsetxattr 6 +#define __NR_fsetxattr 7 +#define __NR_getxattr 8 +#define __NR_lgetxattr 9 +#define __NR_fgetxattr 10 +#define __NR_listxattr 11 +#define __NR_llistxattr 12 +#define __NR_flistxattr 13 +#define __NR_removexattr 14 +#define __NR_lremovexattr 15 +#define __NR_fremovexattr 16 +#define __NR_getcwd 17 +#define __NR_lookup_dcookie 18 +#define __NR_eventfd2 19 +#define __NR_epoll_create1 20 +#define __NR_epoll_ctl 21 +#define __NR_epoll_pwait 22 +#define __NR_dup 23 +#define __NR_dup3 24 +#define __NR_fcntl 25 +#define __NR_inotify_init1 26 +#define __NR_inotify_add_watch 27 +#define __NR_inotify_rm_watch 28 +#define __NR_ioctl 29 +#define __NR_ioprio_set 30 +#define __NR_ioprio_get 31 +#define __NR_flock 32 +#define __NR_mknodat 33 +#define __NR_mkdirat 34 +#define __NR_unlinkat 35 +#define __NR_symlinkat 36 +#define __NR_linkat 37 +#define __NR_renameat 38 +#define __NR_umount2 39 +#define __NR_mount 40 +#define __NR_pivot_root 41 +#define __NR_nfsservctl 42 +#define __NR_statfs 43 +#define __NR_fstatfs 44 +#define __NR_truncate 45 +#define __NR_ftruncate 46 +#define __NR_fallocate 47 +#define __NR_faccessat 48 +#define __NR_chdir 49 +#define __NR_fchdir 50 +#define __NR_chroot 51 +#define __NR_fchmod 52 +#define __NR_fchmodat 53 +#define __NR_fchownat 54 +#define __NR_fchown 55 +#define __NR_openat 56 +#define __NR_close 57 +#define __NR_vhangup 58 +#define __NR_pipe2 59 +#define __NR_quotactl 60 +#define __NR_getdents64 61 +#define __NR_lseek 62 +#define __NR_read 63 +#define __NR_write 64 +#define __NR_readv 65 +#define __NR_writev 66 +#define __NR_pread64 67 +#define __NR_pwrite64 68 +#define __NR_preadv 69 +#define __NR_pwritev 70 +#define __NR_sendfile 71 +#define __NR_pselect6 72 +#define __NR_ppoll 73 +#define __NR_signalfd4 74 +#define __NR_vmsplice 75 +#define __NR_splice 76 +#define __NR_tee 77 +#define __NR_readlinkat 78 +#define __NR_newfstatat 79 +#define __NR_fstat 80 +#define __NR_sync 81 +#define __NR_fsync 82 +#define __NR_fdatasync 83 +#define __NR_sync_file_range 84 +#define __NR_timerfd_create 85 +#define __NR_timerfd_settime 86 +#define __NR_timerfd_gettime 87 +#define __NR_utimensat 88 +#define __NR_acct 89 +#define __NR_capget 90 +#define __NR_capset 91 +#define __NR_personality 92 +#define __NR_exit 93 +#define __NR_exit_group 94 +#define __NR_waitid 95 +#define __NR_set_tid_address 96 +#define __NR_unshare 97 +#define __NR_futex 98 +#define __NR_set_robust_list 99 +#define __NR_get_robust_list 100 +#define __NR_nanosleep 101 +#define __NR_getitimer 102 +#define __NR_setitimer 103 +#define __NR_kexec_load 104 +#define __NR_init_module 105 +#define __NR_delete_module 106 +#define __NR_timer_create 107 +#define __NR_timer_gettime 108 +#define __NR_timer_getoverrun 109 +#define __NR_timer_settime 110 +#define __NR_timer_delete 111 +#define __NR_clock_settime 112 +#define __NR_clock_gettime 113 +#define __NR_clock_getres 114 +#define __NR_clock_nanosleep 115 +#define __NR_syslog 116 +#define __NR_ptrace 117 +#define __NR_sched_setparam 118 +#define __NR_sched_setscheduler 119 +#define __NR_sched_getscheduler 120 +#define __NR_sched_getparam 121 +#define __NR_sched_setaffinity 122 +#define __NR_sched_getaffinity 123 +#define __NR_sched_yield 124 +#define __NR_sched_get_priority_max 125 +#define __NR_sched_get_priority_min 126 +#define __NR_sched_rr_get_interval 127 +#define __NR_restart_syscall 128 +#define __NR_kill 129 +#define __NR_tkill 130 +#define __NR_tgkill 131 +#define __NR_sigaltstack 132 +#define __NR_rt_sigsuspend 133 +#define __NR_rt_sigaction 134 +#define __NR_rt_sigprocmask 135 +#define __NR_rt_sigpending 136 +#define __NR_rt_sigtimedwait 137 +#define __NR_rt_sigqueueinfo 138 +#define __NR_rt_sigreturn 139 +#define __NR_setpriority 140 +#define __NR_getpriority 141 +#define __NR_reboot 142 +#define __NR_setregid 143 +#define __NR_setgid 144 +#define __NR_setreuid 145 +#define __NR_setuid 146 +#define __NR_setresuid 147 +#define __NR_getresuid 148 +#define __NR_setresgid 149 +#define __NR_getresgid 150 +#define __NR_setfsuid 151 +#define __NR_setfsgid 152 +#define __NR_times 153 +#define __NR_setpgid 154 +#define __NR_getpgid 155 +#define __NR_getsid 156 +#define __NR_setsid 157 +#define __NR_getgroups 158 +#define __NR_setgroups 159 +#define __NR_uname 160 +#define __NR_sethostname 161 +#define __NR_setdomainname 162 +#define __NR_getrlimit 163 +#define __NR_setrlimit 164 +#define __NR_getrusage 165 +#define __NR_umask 166 +#define __NR_prctl 167 +#define __NR_getcpu 168 +#define __NR_gettimeofday 169 +#define __NR_settimeofday 170 +#define __NR_adjtimex 171 +#define __NR_getpid 172 +#define __NR_getppid 173 +#define __NR_getuid 174 +#define __NR_geteuid 175 +#define __NR_getgid 176 +#define __NR_getegid 177 +#define __NR_gettid 178 +#define __NR_sysinfo 179 +#define __NR_mq_open 180 +#define __NR_mq_unlink 181 +#define __NR_mq_timedsend 182 +#define __NR_mq_timedreceive 183 +#define __NR_mq_notify 184 +#define __NR_mq_getsetattr 185 +#define __NR_msgget 186 +#define __NR_msgctl 187 +#define __NR_msgrcv 188 +#define __NR_msgsnd 189 +#define __NR_semget 190 +#define __NR_semctl 191 +#define __NR_semtimedop 192 +#define __NR_semop 193 +#define __NR_shmget 194 +#define __NR_shmctl 195 +#define __NR_shmat 196 +#define __NR_shmdt 197 +#define __NR_socket 198 +#define __NR_socketpair 199 +#define __NR_bind 200 +#define __NR_listen 201 +#define __NR_accept 202 +#define __NR_connect 203 +#define __NR_getsockname 204 +#define __NR_getpeername 205 +#define __NR_sendto 206 +#define __NR_recvfrom 207 +#define __NR_setsockopt 208 +#define __NR_getsockopt 209 +#define __NR_shutdown 210 +#define __NR_sendmsg 211 +#define __NR_recvmsg 212 +#define __NR_readahead 213 +#define __NR_brk 214 +#define __NR_munmap 215 +#define __NR_mremap 216 +#define __NR_add_key 217 +#define __NR_request_key 218 +#define __NR_keyctl 219 +#define __NR_clone 220 +#define __NR_execve 221 +#define __NR_mmap 222 +#define __NR_fadvise64 223 +#define __NR_swapon 224 +#define __NR_swapoff 225 +#define __NR_mprotect 226 +#define __NR_msync 227 +#define __NR_mlock 228 +#define __NR_munlock 229 +#define __NR_mlockall 230 +#define __NR_munlockall 231 +#define __NR_mincore 232 +#define __NR_madvise 233 +#define __NR_remap_file_pages 234 +#define __NR_mbind 235 +#define __NR_get_mempolicy 236 +#define __NR_set_mempolicy 237 +#define __NR_migrate_pages 238 +#define __NR_move_pages 239 +#define __NR_rt_tgsigqueueinfo 240 +#define __NR_perf_event_open 241 +#define __NR_accept4 242 +#define __NR_recvmmsg 243 +#define __NR_wait4 260 +#define __NR_prlimit64 261 +#define __NR_fanotify_init 262 +#define __NR_fanotify_mark 263 +#define __NR_name_to_handle_at 264 +#define __NR_open_by_handle_at 265 +#define __NR_clock_adjtime 266 +#define __NR_syncfs 267 +#define __NR_setns 268 +#define __NR_sendmmsg 269 +#define __NR_process_vm_readv 270 +#define __NR_process_vm_writev 271 +#define __NR_kcmp 272 +#define __NR_finit_module 273 +#define __NR_sched_setattr 274 +#define __NR_sched_getattr 275 +#define __NR_renameat2 276 +#define __NR_seccomp 277 +#define __NR_getrandom 278 +#define __NR_memfd_create 279 +#define __NR_bpf 280 +#define __NR_execveat 281 +#define __NR_userfaultfd 282 +#define __NR_membarrier 283 +#define __NR_mlock2 284 +#define __NR_copy_file_range 285 +#define __NR_preadv2 286 +#define __NR_pwritev2 287 +#define __NR_pkey_mprotect 288 +#define __NR_pkey_alloc 289 +#define __NR_pkey_free 290 +#define __NR_statx 291 +#define __NR_io_pgetevents 292 +#define __NR_rseq 293 +#define __NR_kexec_file_load 294 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433 +#define __NR_pidfd_open 434 +#define __NR_clone3 435 +#define __NR_close_range 436 +#define __NR_openat2 437 +#define __NR_pidfd_getfd 438 +#define __NR_faccessat2 439 +#define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_restrict_self 446 +#define __NR_process_mrelease 448 +#define __NR_futex_waitv 449 +#define __NR_set_mempolicy_home_node 450 +#define __NR_cachestat 451 +#define __NR_fchmodat2 452 diff --git a/so3/include/syscall.h b/so3/include/syscall.h index 711b84145..ada2870db 100644 --- a/so3/include/syscall.h +++ b/so3/include/syscall.h @@ -21,7 +21,7 @@ #ifndef ASM_ARM_SYSCALL_H #define ASM_ARM_SYSCALL_H -#include +#include #ifndef __ASSEMBLY__ diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index d87c60098..b87cc486d 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -35,66 +35,10 @@ extern uint32_t __get_syscall_stack_arg(uint32_t nr); extern void test_malloc(int test_no); -#warning Not updated, a rework is needed to avoid having a big array because of #ifdef ... static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [0 ... NR_SYSCALLS - 1] = NULL, - /* -#ifdef CONFIG_MMU - [SYSCALL_GETPID] = __sys_getpid, - [SYSCALL_GETTIMEOFDAY] = __sys_gettimeofday, - [SYSCALL_CLOCK_GETTIME] = __sys_clock_gettime, - [SYSCALL_EXIT] = __sys_exit, - [SYSCALL_EXECVE] = __sys_execve, - [SYSCALL_FORK] = __sys_fork, - [SYSCALL_WAITPID] = __sys_waitpid, - [SYSCALL_PTRACE] = __sys_ptrace, -#endif - [SYSCALL_READ] = __sys_read, - [SYSCALL_WRITE] = __sys_write, - [SYSCALL_OPEN] = __sys_open, - [SYSCALL_CLOSE] = __sys_close, - [SYSCALL_THREAD_CREATE] = __sys_thread_create, - [SYSCALL_THREAD_JOIN] = __sys_thread_join, - [SYSCALL_THREAD_EXIT] = __sys_thread_exit, - [SYSCALL_THREAD_YIELD] = __sys_thread_yield, - [SYSCALL_READDIR] = __sys_readdir, - [SYSCALL_IOCTL] = __sys_ioctl, - [SYSCALL_FCNTL] = __sys_fcntl, - [SYSCALL_LSEEK] = __sys_lseek, - [SYSCALL_READV] = __sys_readv, - [SYSCALL_WRITEV] = __sys_writev, -#ifdef CONFIG_IPC_PIPE - [SYSCALL_PIPE] = __sys_pipe, -#endif - [SYSCALL_DUP] = __sys_dup, - [SYSCALL_DUP2] = __sys_dup2, - [SYSCALL_STAT] = __sys_stat, - [SYSCALL_MMAP] = __sys_mmap, - [SYSCALL_NANOSLEEP] = __sys_nanosleep, -#ifdef CONFIG_PROC_ENV - [SYSCALL_SBRK] = __sys_sbrk, -#endif - [SYSCALL_MUTEX_LOCK] = __sys_mutex_lock, - [SYSCALL_MUTEX_UNLOCK] = __sys_mutex_unlock, -#ifdef CONFIG_IPC_SIGNAL - [SYSCALL_SIGACTION] = __sys_sigaction, - [SYSCALL_KILL] = __sys_kill, - [SYSCALL_SIGRETURN] = __sys_sigreturn, -#endif -#ifdef CONFIG_NET - [SYSCALL_SOCKET] = __sys_socket, - [SYSCALL_BIND] = __sys_bind, - [SYSCALL_LISTEN] = __sys_listen, - [SYSCALL_ACCEPT] = __sys_accept, - [SYSCALL_CONNECT] = __sys_connect, - [SYSCALL_RECV] = __sys_recv, - [SYSCALL_SEND] = __sys_send, - [SYSCALL_SENDTO] = __sys_sendto, - [SYSCALL_SETSOCKOPT] = __sys_setsockopt, - [SYSCALL_RECVFROM] = __sys_recvfrom, -#endif - [SYSCALL_SYSINFO] = __sys_sysinfo, -*/ +/* Generated file with table element matching number to functions. */ +#include }; /* @@ -104,7 +48,6 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { long syscall_handle(syscall_args_t *syscall_args) { - long result = -1; uint32_t syscall_no; /* Get addtional args of the syscall according to the ARM & SO3 ABI */ @@ -113,11 +56,9 @@ long syscall_handle(syscall_args_t *syscall_args) if ((syscall_no >= NR_SYSCALLS) || (syscall_table[syscall_no] == NULL)) { printk("%s: unhandled syscall: %d\n", __func__, syscall_no); return -ENOSYS; - } else { - return syscall_table[syscall_no](syscall_args); } #warning do_softirq? - return result; + return syscall_table[syscall_no](syscall_args); } diff --git a/so3/scripts/syscall_gen.sh b/so3/scripts/syscall_gen.sh new file mode 100755 index 000000000..e625e152b --- /dev/null +++ b/so3/scripts/syscall_gen.sh @@ -0,0 +1,115 @@ +#!/bin/sh + +# Copyright (C) 2025 Clément Dieperink +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# +# This script generates two header for syscall number and table based on two +# inputs files. +# +# The input files are: +# +# - syscall.tbl: Declares all syscalls available on SO3 without taking into +# account the CPU arch. This also provides configuration +# requirement for a given syscall. +# - syscall.h.in: Contains all syscall number which are necessary implemented +# in SO3. This is a copy of the same file from musl library. +# +# Output files are: +# +# - syscall_number.h: Defines all available on arch SYSCALL_xxx with +# corresponding number and dependent on the configuration. +# - syscall_table.h.in: Table definition with elements of array definition to +# match syscall number to syscall functions. This file +# must be included inside a C table definition. + +set -e + +usage() { + echo >&2 "usage: $0 in_table in_number out_table out_number" >&2 + echo >&2 + echo >&2 " in_table input syscall table common for all arch" + echo >&2 " in_number input syscall number arch dependent" + echo >&2 " out_table output syscall callback table" + echo >&2 " out_number output syscall number conditional" + exit 1 +} + +file_header() { + echo "#ifndef $1" + echo "#define $1" + echo "/*" + echo " * DO NOT MODIFY." + echo " *" + echo " * This file was generated by $(realpath "$0")" + echo " */" + echo "" +} + +file_footer() { + echo "" + echo "#endif" +} + +if [ $# -ne 4 ]; then + usage +fi + +infile_table="$1" +infile_number="$2" +outfile_table="$3" +outfile_number="$4" + +declare -Ag sys_cond=() + +# Generate syscall_table.h.in file and save available syscall +# and there configuration requirement. +file_header "__SYSCALL_TABLE_H__" > "$outfile_table" + +valid_syscalls="$(grep -E "^[^#]" "$infile_table")" +while read name requirement; do + sys_cond["$name"]="$requirement" + + echo "#ifdef SYSCALL_$name" + echo -e "\t[SYSCALL_$name] = &__sys_$name," + echo "#endif" +done < <(echo "$valid_syscalls") >> "$outfile_table" + +file_footer >> "$outfile_table" + +# Generate syscall_number.h +grep -E "^#define " "$infile_number" | sed "s/^#define __NR_//" | { + file_header "__SYSCALL_NUMBER_H__" + echo "#include " + echo "" + + while read name number; do + if ! [ -v sys_cond[$name] ]; then + continue + fi + + if [ -n "${sys_cond[$name]}" ]; then + echo "#ifdef CONFIG_${sys_cond[$name]}" + fi + + echo "#define SYSCALL_$name $number" + + if [ -n "${sys_cond[$name]}" ]; then + echo "#endif" + fi + done + + file_footer +} > "$outfile_number" diff --git a/so3/syscall.tbl b/so3/syscall.tbl new file mode 100644 index 000000000..1a3921119 --- /dev/null +++ b/so3/syscall.tbl @@ -0,0 +1,66 @@ +# Copyright (C) 2025 Clément Dieperink +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# This file declare all syscalls available on SO3, without taking into account +# of CPU arch. See scripts/syscall_gen.sh for more information. +# +# Syscall name Configuration requirement +read +readv +write +writev +open +openat +close +lseek +_llseek +ioctl +dup +dup2 +dup3 +getdents64 +stat64 +fstatat64 +newfstatat +mmap +mmap2 +nanosleep +pipe IPC_PIPE +pipe2 IPC_PIPE +rt_sigaction IPC_SIGNAL +rt_kill IPC_SIGNAL +sigreturn IPC_SIGNAL +rt_sigreturn IPC_SIGNAL +getpid MMU +execve MMU +fork MMU +exit MMU +wait4 MMU +ptrace MMU +gettimeofday MMU +gettimeofday_time32 MMU +clock_gettime MMU +clock_gettime32 MMU +socket NET +connect NET +bind NET +listen NET +accept NET +recv NET +recvfrom NET +send NET +sendto NET +setsockopt NET +brk PROC_ENV