# FreeBSD Introduction - Trace Code ## 1 - Reading: sys/*.h Please write a one-line summary for the following header files, some outdate header file are not included. The first few lines are examples. * acct.h - accounting structure * acl.h - access-control list (ACL) definitions * aio.h - asynchronous I/O definitions * alq.h - asynchronous-logging queue definitions * bio.h - description of an I/O operation in the kernel * bitstring.h * blist.h * buf.h * bufobj.h * bus.h * bus_dma.h * callout.h * clist.h * clock.h * condvar.h * conf.h * cons.h * consio.h * cpu.h * ctype.h * device_port.h * devicestat.h * dir.h * dirent.h * disk.h * disklabel.h * diskmbr.h * domain.h * dvdio.h * elf32.h * elf64.h * elf_common.h * elf_generic.h * endian.h * errno.h * event.h * eventhandler.h * eventvar.h * exec.h * extattr.h * fbio.h * fcntl.h * fdcio.h * file.h * filedesc.h * fnv_hash.h * gmon.h * gpt.h * imgact.h * imgact_elf.h * inflate.h * interrupt.h * _iovec.h * ipc.h * jail.h * kbio.h * kdb.h * kernel.h * kerneldump.h * kobj.h * kse.h * kthread.h * ktr.h * ktrace.h * _label.h * libkern.h * limits.h * linedisc.h * link_elf.h * linker.h * linker_set.h * _lock.h * lock.h * lockf.h * lockmgr.h * mac.h * mac_policy.h * malloc.h * mbpool.h * mbuf.h * mchain.h * md5.h * mdioctl.h * mman.h * module.h * mount.h * mouse.h * msg.h * msgbuf.h * mutex.h * _mutex.h * namei.h * _null.h * param.h * pciio.h * pcpu.h * pipe.h * pmckern.h * pmclog.h * poll.h * power.h * priority.h * proc.h * procfs.h * protosw.h * _pthreadtypes.h * _sigset.h * ptrace.h * queue.h * random.h * reboot.h * resource.h * resourcevar.h * rman.h * rtprio.h * runq.h * sbuf.h * sched.h * select.h * selinfo.h * sem.h * sema.h * sf_buf.h * shm.h * sigio.h * signal.h * signalvar.h * sleepqueue.h * smp.h * snoop.h * socket.h * socketvar.h * sockio.h * stat.h * statvfs.h * sx.h * sysctl.h * sysent.h * syslimits.h * syslog.h * systm.h * _task.h * taskqueue.h * termios.h * thr.h * time.h * timepps.h * times.h * _timespec.h * timespec.h * timetc.h * _timeval.h * timex.h * tree.h * tty.h * ttychars.h * ttydefaults.h * turnstile.h * _types.h * types.h * ucontext.h * ucred.h * uio.h * umtx.h * un.h * unistd.h * unpcb.h * user.h * uuid.h * vmmeter.h * vnode.h * wait.h * watchdog.h ## 2 - Understand how a system boot up. - I don't know how to trace the code ;( ## 3 - Understand how a syscall occurs, and be handled. - You may have to read the following files: - [sys/riscv/riscv/exception.S](https://github.com/freebsd/freebsd-src/blob/main/sys/riscv/riscv/exception.S) - read function: cpu_exception_handler_user - know how the program pass the parameter from assembly to c - [sys/riscv/riscv/trap.c](https://github.com/freebsd/freebsd-src/blob/main/sys/riscv/riscv/trap.c) - read functions: do_trap_user, ecall_handler - [sys/riscv/riscv/elf_machdep.c](https://github.com/freebsd/freebsd-src/blob/main/sys/riscv/riscv/elf_machdep.c) - read struct: static struct sysentvec - [sys/sys/proc.h](https://github.com/freebsd/freebsd-src/blob/main/sys/sys/proc.h#L733) - read struct: `proc` - As for now, you can assume proc->p_sysent=elf64_freebsd_sysvec. - [sys/kern/subr_syscall.c](https://github.com/freebsd/freebsd-src/blob/main/sys/kern/subr_syscall.c#L53) - read functions: syscallenter, syscallret - [sys/kern/subr_trap.c](https://github.com/freebsd/freebsd-src/blob/main/sys/kern/subr_trap.c) - read functions: userret - You don't have to understand the code, but you have to read the remarks. - [System Calls Table](https://alfonsosiciliano.gitlab.io/posts/2021-01-02-freebsd-system-calls-table.html) ## 4 - Understand how a process launchs and executes an arbituary program and finally exit. - You may have to read the following files: - sys/kern/kern_*.c - sys/kern/imgact_*.c - Closely read the following files/functions: - sys/kern/kern_fork.c: sys_fork, fork1 - sys/kern/kern_exec.c: sys_execve, kern_execve, do_execve, - sys/kern/imgact_shell.c: exec_shell_imgact
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up