This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'linux-syscall/' from commit '5a63d3bcf701f3c676b0f9d72aa9fd748d5…
- Loading branch information
Showing
11 changed files
with
2,169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Execute files | ||
mycalculator | ||
|
||
# Temporary files | ||
.dependency | ||
*.sh | ||
*.txt | ||
|
||
# Prerequisites | ||
*.d | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
*.obj | ||
*.elf | ||
|
||
# Linker output | ||
*.ilk | ||
*.map | ||
*.exp | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*.idb | ||
*.pdb | ||
|
||
# Kernel Module Compile Results | ||
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
dkms.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
all: mycalculator | ||
CC=gcc | ||
mycalculator: mycalculator.c | ||
$(CC) -o $@ $< | ||
clean: | ||
rm mycalculator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Calculation System Call | ||
|
||
4가지 연산 기능을 (덧셈(+), 뺄셈(-), 곱셈(*), 나머지(%)) 제공하는 신규 시스템 콜을 각각 추가하고, 추가된 시스템 콜을 호출하는 테스트 프로그램 구현 | ||
|
||
## 0. Quick start | ||
|
||
``` bash | ||
git clone https://github.com/codejune/c-linux-syscall.git | ||
cd c-linux-syscall | ||
|
||
# 시스템 콜 추가 | ||
cp sys_* {linux_kernel_dir}/kernel/ | ||
cp kernel_Makefile {linux_kernel_dir}/kernel/Makefile | ||
cp syscalls.h {linux_kernel_dir}/include/linux/ | ||
cp syscall_64.tbl {linux_kernel_dir}/arch/x86/entry/syscalls/ | ||
# Do kernel build and reboot your system | ||
|
||
# 테스트 프로그램 빌드 및 실행 | ||
make | ||
./mycalculator | ||
``` | ||
|
||
## 1. Environment | ||
|
||
### Software | ||
|
||
- Ubuntu 20.04.3 LTS (x86_64) | ||
- Linux Kernel 5.11.22 | ||
|
||
### Hardware | ||
|
||
- VM Instance | ||
- 4 Core 8 Thread | ||
- 8 GB RAM | ||
- 60 GB Storage | ||
|
||
## 2. Requirement | ||
|
||
### 조건 | ||
|
||
- 4가지 이항 연산을 (덧셈(+), 뺄셈(-), 곱셈(*), 나머지(%)) 제공하는 새로운 시스템 콜 함수 4개를 커널에 등록 | ||
- 테스트 프로그램을 (4가지 연산만을 수행하는 이항 계산기 프로그램) 작성하여 새롭게 등록된 시스템 콜 호출 확인 | ||
|
||
### 출력 | ||
|
||
- 테스트 프로그램 | ||
|
||
``` bash | ||
$ ./mycalculator | ||
>> 1+2 | ||
3 | ||
>> 3+5 | ||
8 | ||
>> 4+2 | ||
6 | ||
``` | ||
|
||
- 커널 로그 | ||
|
||
``` bash | ||
$ dmesg | ||
... | ||
[260376.527302] TCP: request_sock_TCP: Possible SYN flooding on port 22. Sending cookies. Check SNMP counters. | ||
[435056.713901] sys_my_add: a=1, b=2, result=3 | ||
[435059.119871] sys_my_add: a=3, b=5, result=8 | ||
[435061.672088] sys_my_add: a=4, b=2, result=6 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
# | ||
# Makefile for the linux kernel. | ||
# | ||
|
||
obj-y = fork.o exec_domain.o panic.o \ | ||
cpu.o exit.o softirq.o resource.o \ | ||
sysctl.o capability.o ptrace.o user.o \ | ||
signal.o sys.o umh.o workqueue.o pid.o task_work.o \ | ||
extable.o params.o \ | ||
kthread.o sys_ni.o nsproxy.o \ | ||
notifier.o ksysfs.o cred.o reboot.o \ | ||
async.o range.o smpboot.o ucount.o regset.o \ | ||
sys_print_hello.o sys_my_add.o sys_my_subtract.o sys_my_multiply.o sys_my_modular.o | ||
|
||
obj-$(CONFIG_USERMODE_DRIVER) += usermode_driver.o | ||
obj-$(CONFIG_MODULES) += kmod.o | ||
obj-$(CONFIG_MULTIUSER) += groups.o | ||
|
||
ifdef CONFIG_FUNCTION_TRACER | ||
# Do not trace internal ftrace files | ||
CFLAGS_REMOVE_irq_work.o = $(CC_FLAGS_FTRACE) | ||
endif | ||
|
||
# Prevents flicker of uninteresting __do_softirq()/__local_bh_disable_ip() | ||
# in coverage traces. | ||
KCOV_INSTRUMENT_softirq.o := n | ||
# Avoid KCSAN instrumentation in softirq ("No shared variables, all the data | ||
# are CPU local" => assume no data races), to reduce overhead in interrupts. | ||
KCSAN_SANITIZE_softirq.o = n | ||
# These are called from save_stack_trace() on slub debug path, | ||
# and produce insane amounts of uninteresting coverage. | ||
KCOV_INSTRUMENT_module.o := n | ||
KCOV_INSTRUMENT_extable.o := n | ||
KCOV_INSTRUMENT_stacktrace.o := n | ||
# Don't self-instrument. | ||
KCOV_INSTRUMENT_kcov.o := n | ||
# If sanitizers detect any issues in kcov, it may lead to recursion | ||
# via printk, etc. | ||
KASAN_SANITIZE_kcov.o := n | ||
KCSAN_SANITIZE_kcov.o := n | ||
UBSAN_SANITIZE_kcov.o := n | ||
CFLAGS_kcov.o := $(call cc-option, -fno-conserve-stack) -fno-stack-protector | ||
|
||
obj-y += sched/ | ||
obj-y += locking/ | ||
obj-y += power/ | ||
obj-y += printk/ | ||
obj-y += irq/ | ||
obj-y += rcu/ | ||
obj-y += livepatch/ | ||
obj-y += dma/ | ||
obj-y += entry/ | ||
|
||
obj-$(CONFIG_KCMP) += kcmp.o | ||
obj-$(CONFIG_FREEZER) += freezer.o | ||
obj-$(CONFIG_PROFILING) += profile.o | ||
obj-$(CONFIG_STACKTRACE) += stacktrace.o | ||
obj-y += time/ | ||
obj-$(CONFIG_FUTEX) += futex.o | ||
obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o | ||
obj-$(CONFIG_SMP) += smp.o | ||
ifneq ($(CONFIG_SMP),y) | ||
obj-y += up.o | ||
endif | ||
obj-$(CONFIG_UID16) += uid16.o | ||
obj-$(CONFIG_MODULES) += module.o | ||
obj-$(CONFIG_MODULE_SIG) += module_signing.o | ||
obj-$(CONFIG_MODULE_SIG_FORMAT) += module_signature.o | ||
obj-$(CONFIG_KALLSYMS) += kallsyms.o | ||
obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o | ||
obj-$(CONFIG_CRASH_CORE) += crash_core.o | ||
obj-$(CONFIG_KEXEC_CORE) += kexec_core.o | ||
obj-$(CONFIG_KEXEC) += kexec.o | ||
obj-$(CONFIG_KEXEC_FILE) += kexec_file.o | ||
obj-$(CONFIG_KEXEC_ELF) += kexec_elf.o | ||
obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o | ||
obj-$(CONFIG_COMPAT) += compat.o | ||
obj-$(CONFIG_CGROUPS) += cgroup/ | ||
obj-$(CONFIG_UTS_NS) += utsname.o | ||
obj-$(CONFIG_USER_NS) += user_namespace.o | ||
obj-$(CONFIG_PID_NS) += pid_namespace.o | ||
obj-$(CONFIG_IKCONFIG) += configs.o | ||
obj-$(CONFIG_IKHEADERS) += kheaders.o | ||
obj-$(CONFIG_SMP) += stop_machine.o | ||
obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o | ||
obj-$(CONFIG_AUDIT) += audit.o auditfilter.o | ||
obj-$(CONFIG_AUDITSYSCALL) += auditsc.o audit_watch.o audit_fsnotify.o audit_tree.o | ||
obj-$(CONFIG_GCOV_KERNEL) += gcov/ | ||
obj-$(CONFIG_KCOV) += kcov.o | ||
obj-$(CONFIG_KPROBES) += kprobes.o | ||
obj-$(CONFIG_FAIL_FUNCTION) += fail_function.o | ||
obj-$(CONFIG_KGDB) += debug/ | ||
obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o | ||
obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o | ||
obj-$(CONFIG_HARDLOCKUP_DETECTOR_PERF) += watchdog_hld.o | ||
obj-$(CONFIG_SECCOMP) += seccomp.o | ||
obj-$(CONFIG_RELAY) += relay.o | ||
obj-$(CONFIG_SYSCTL) += utsname_sysctl.o | ||
obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o | ||
obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o | ||
obj-$(CONFIG_TRACEPOINTS) += tracepoint.o | ||
obj-$(CONFIG_LATENCYTOP) += latencytop.o | ||
obj-$(CONFIG_FUNCTION_TRACER) += trace/ | ||
obj-$(CONFIG_TRACING) += trace/ | ||
obj-$(CONFIG_TRACE_CLOCK) += trace/ | ||
obj-$(CONFIG_RING_BUFFER) += trace/ | ||
obj-$(CONFIG_TRACEPOINTS) += trace/ | ||
obj-$(CONFIG_IRQ_WORK) += irq_work.o | ||
obj-$(CONFIG_CPU_PM) += cpu_pm.o | ||
obj-$(CONFIG_BPF) += bpf/ | ||
obj-$(CONFIG_KCSAN) += kcsan/ | ||
obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o | ||
obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call.o | ||
|
||
obj-$(CONFIG_PERF_EVENTS) += events/ | ||
|
||
obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o | ||
obj-$(CONFIG_PADATA) += padata.o | ||
obj-$(CONFIG_CRASH_DUMP) += crash_dump.o | ||
obj-$(CONFIG_JUMP_LABEL) += jump_label.o | ||
obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o | ||
obj-$(CONFIG_TORTURE_TEST) += torture.o | ||
|
||
obj-$(CONFIG_HAS_IOMEM) += iomem.o | ||
obj-$(CONFIG_RSEQ) += rseq.o | ||
obj-$(CONFIG_WATCH_QUEUE) += watch_queue.o | ||
|
||
obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o | ||
obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o | ||
|
||
CFLAGS_stackleak.o += $(DISABLE_STACKLEAK_PLUGIN) | ||
obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o | ||
KASAN_SANITIZE_stackleak.o := n | ||
KCSAN_SANITIZE_stackleak.o := n | ||
KCOV_INSTRUMENT_stackleak.o := n | ||
|
||
obj-$(CONFIG_SCF_TORTURE_TEST) += scftorture.o | ||
|
||
$(obj)/configs.o: $(obj)/config_data.gz | ||
|
||
targets += config_data config_data.gz | ||
$(obj)/config_data.gz: $(obj)/config_data FORCE | ||
$(call if_changed,gzip) | ||
|
||
filechk_cat = cat $< | ||
|
||
$(obj)/config_data: $(KCONFIG_CONFIG) FORCE | ||
$(call filechk,cat) | ||
|
||
$(obj)/kheaders.o: $(obj)/kheaders_data.tar.xz | ||
|
||
quiet_cmd_genikh = CHK $(obj)/kheaders_data.tar.xz | ||
cmd_genikh = $(CONFIG_SHELL) $(srctree)/kernel/gen_kheaders.sh $@ | ||
$(obj)/kheaders_data.tar.xz: FORCE | ||
$(call cmd,genikh) | ||
|
||
clean-files := kheaders_data.tar.xz kheaders.md5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <linux/kernel.h> | ||
#include <sys/syscall.h> | ||
#include <unistd.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
#define BUFFER_SIZE 256 | ||
#define SYS_MY_ADD 443 | ||
#define SYS_MY_SUBTRACT 444 | ||
#define SYS_MY_MULTIPLY 445 | ||
#define SYS_MY_MODULAR 446 | ||
int main(void) | ||
{ | ||
char op; | ||
char a[BUFFER_SIZE], b[BUFFER_SIZE]; | ||
|
||
while(true) | ||
{ | ||
printf(">> "); | ||
scanf("%[^+-*%]%c%[^\n]", a, &op, b); | ||
getchar(); | ||
switch(op) | ||
{ | ||
case '+': | ||
printf("%ld\n", syscall(SYS_MY_ADD, atoi(a), atoi(b))); | ||
break; | ||
case '-': | ||
printf("%ld\n", syscall(SYS_MY_SUBTRACT, atoi(a), atoi(b))); | ||
break; | ||
case '*': | ||
printf("%ld\n", syscall(SYS_MY_MULTIPLY, atoi(a), atoi(b))); | ||
break; | ||
case '%': | ||
printf("%ld\n", syscall(SYS_MY_MODULAR, atoi(a), atoi(b))); | ||
break; | ||
} | ||
} | ||
exit(EXIT_SUCCESS); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <linux/kernel.h> | ||
#include <linux/syscalls.h> | ||
asmlinkage long sys_my_add(long a, long b){ | ||
printk("sys_my_add: a=%ld, b=%ld, result=%ld\n", a, b, a+b); | ||
return a + b; | ||
} | ||
|
||
SYSCALL_DEFINE2(my_add, long, a, long, b) | ||
{ | ||
return sys_my_add(a, b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <linux/kernel.h> | ||
#include <linux/syscalls.h> | ||
asmlinkage long sys_my_modular(long a, long b) | ||
{ | ||
printk("sys_my_modular: a=%ld, b=%ld, result=%ld\n", a, b, a%b); | ||
return a % b; | ||
} | ||
SYSCALL_DEFINE2(my_modular, long, a, long, b) | ||
{ | ||
return sys_my_modular(a, b); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <linux/kernel.h> | ||
#include <linux/syscalls.h> | ||
asmlinkage long sys_my_multiply(long a, long b) | ||
{ | ||
printk("sys_my_multiply: a=%ld, b=%ld, result=%ld\n", a, b, a*b); | ||
return a * b; | ||
} | ||
|
||
SYSCALL_DEFINE2(my_multiply, long, a, long, b) | ||
{ | ||
return sys_my_multiply(a, b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <linux/kernel.h> | ||
#include <linux/syscalls.h> | ||
asmlinkage long sys_my_subtract(long a, long b) | ||
{ | ||
printk("sys_my_subtract: a=%ld, b=%ld, result=%ld\n", a, b, a-b); | ||
return a - b; | ||
} | ||
SYSCALL_DEFINE2(my_subtract, long, a, long, b) | ||
{ | ||
return sys_my_subtract(a, b); | ||
} | ||
|
Oops, something went wrong.