2023.11.13 TIL
Code, Image source: The Linux Programming Interface, Michael Kerrisk
Application은 system call을 통해 OS의 기능을 사용한다
fd = open("out", 1);
write(fd, "hello\n", 6);
pid = fork()
write()를 예시로
⭐ 가장 중요한 부분 → User code를 절대 kernel mode에서 실행시키면 안된다!!
tlpi-dist/fileio/copy.copen()fd는 작은 ㅑintegersys_open() → File system에서 이름 찾고 kernel data structure 수정 → User register 복구 → User mode로 전환read(), write()fd)0 → standard input1 → standard output2 → standard errortlpi-dist/procexec/fork_whos_on_first.c$ echo hellofork() system call은 새로운 process를 생성pid0tlpi-dist/procexec/t_execl.cexec([file name], [parameter]) → 호출한 현재 process를 교체tlpi-dist/pipes/simple.pipe.c$ ls | grep -nr simple*pipe() → 두개의 fd를 생성문제 발생…
구글링 아무리 해도 해결이 안된다.
gcc-multilib가 cross compiling을 도와주는건데 arm64에서 어떻게 설치하는지 모르겠다.
어떤 사람 말로는 기본적으로 gcc에 gcc-multilib가 포함돼있대서 걍 믿어보기로 한다.
일단make해서 빌드.
Linux 실행파일 format
.text → code
.rodata → read only data
.data → global C variable
readelf -a ./copyobjdump -S ./copynm ./copyfile ./copygcc -o myprogram file1.c file2.c file3.c 이렇게 하지 않고‼️ makefile 을 사용함.make : 소스 코드로 부터 실행 파일 또는 라이브러리를 생성하는 유틸리티
Makefile : make 명령어가 사용하는 스크립트 파일
$ make -f [makefile name] target
$ strace ./copy seek_io seek_io_new → copy 실행시 생기는 system call들을 출력# Makefile to build all programs in all subdirectories
#
# DIRS is a list of all subdirectories containing makefiles
# (The library directory is first so that the library gets built first)
#
DIRS =	lib \
	acl altio \
	cap cgroups \
	daemons dirs_links \
	filebuff fileio filelock files filesys getopt \
	inotify \
	loginacct \
	memalloc \
	mmap \
	pgsjc pipes pmsg \
	proc proccred procexec procpri procres \
	progconc \
	psem pshm pty \
	shlibs \
	signals sockets \
	svipc svmsg svsem svshm \
	sysinfo \
	syslim \
	threads time timers tty \
	users_groups \
	vdso \
	vmem \
	xattr
# The "namespaces" and "seccomp" directories are deliberately excluded from
# the above list because much of the code in those directories requires a
# relatively recent kernel and userspace to build. Nevertheless, each of
# those directories contains a Makefile.
BUILD_DIRS = ${DIRS}
# Dummy targets for building and clobbering everything in all subdirectories
all:
	@ echo ${BUILD_DIRS}
	@ for dir in ${BUILD_DIRS}; do (cd $${dir}; ${MAKE}) ; \
		if test $$? -ne 0; then break; fi; done
allgen:
	@ for dir in ${BUILD_DIRS}; do (cd $${dir}; ${MAKE} allgen) ; done
clean:
	@ for dir in ${BUILD_DIRS}; do (cd $${dir}; ${MAKE} clean) ; done
DIRS → 하위 directory 목록all → DIRS의 dir들 각각으로 cd $dir, make$? 가 -ne (not equal to) 0 → 마지막으로 실행된 command의 exit status가 0이 아닐 경우 (command failed), breakfi → if문의 끝을 의미allgen → DIRS의 dir들 각각으로 cd $dir, make allgenclean → DIRS의 dir들 각각으로 cd $dir, make clean# git 설치
$ sudo apt-get install git-core
$ git --version
$ git config --global user.name [내이름]
$ git config --global user.email [메일]
$ sudo git config --global color.ui "auto"
# git repository clone + connection setup
$ git clone https://github.com/glyserin/system-project.git
# 모든 file을 git stage에 추가
$ git add .
# file.txt만 git stage에 추가
$ git add file.txt
# stage 추가 된 파일 목록 보기
$ git status
# stage 추가 된 파일 commit
$ git commit -m "커밋내용"
# origin에 존재하는 branch로 push, 보통 초기에는 master branch를 사용한다.
$ git push origin main
# main에 올라간 변경사항 pull 해오기
# pull 하기 전에 내 변경사항 commit!!
$ git pull origin main