Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions arch/lkl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ LDFLAGS_vmlinux += -r
LKL_ENTRY_POINTS := lkl_start_kernel lkl_sys_halt lkl_syscall lkl_trigger_irq \
lkl_get_free_irq lkl_put_irq

SYSCALL_TBL_HDR = arch/lkl/include/generated/asm/syscall_table.h
UNISTD_HDR = arch/lkl/include/asm/unistd.h

core-y += arch/lkl/kernel/

all: lkl.o

lkl.o: vmlinux
$(OBJCOPY) -R .eh_frame -R .syscall_defs $(foreach sym,$(LKL_ENTRY_POINTS),-G$(prefix)$(sym)) vmlinux lkl.o
$(OBJCOPY) -R .eh_frame $(foreach sym,$(LKL_ENTRY_POINTS),-G$(prefix)$(sym)) vmlinux lkl.o

quiet_cmd_syscall_tbl = TBL $<
cmd_syscall_tbl = $< systbl $(UNISTD_HDR) $@

arch/lkl/include/generated/uapi/asm/syscall_defs.h: vmlinux
$(OBJCOPY) -j .syscall_defs -O binary --set-section-flags .syscall_defs=alloc $< $@
$(SYSCALL_TBL_HDR): arch/lkl/scripts/make_syscall_tbl.sh $(UNISTD_HDR)
@mkdir -p arch/lkl/include/generated/asm/
$(call cmd,syscall_tbl)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this supposed to be an underscore instead of a comma?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is intentional.


install: lkl.o __headers arch/lkl/include/generated/uapi/asm/syscall_defs.h
@echo " INSTALL $(INSTALL_PATH)/lib/lkl.o"
Expand All @@ -39,6 +46,8 @@ install: lkl.o __headers arch/lkl/include/generated/uapi/asm/syscall_defs.h
$(subst -j,-j$(NPROC),$(findstring -j,$(MAKEFLAGS))) \
$(INSTALL_PATH)/include

archheaders: $(SYSCALL_TBL_HDR)

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

Expand Down
80 changes: 80 additions & 0 deletions arch/lkl/include/asm/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,83 @@
__ASCII_MAP(x, __SC_ASCII, __VA_ARGS__) ")\\n\"\n" \
".ascii \"#endif\\n\"\n" \
".section .text\n");

/*
* Unsupported system calls due to lack of support in LKL (e.g. related to
* virtual memory, signal, user processes). We also only support 64bit version
* of system calls where we have two version to keep the same API across 32 and
* 64 bit hosts.
*/

#define __IGNORE_restart_syscall
#define __IGNORE_exit
#define __IGNORE_fork
#define __IGNORE_execve
#define __IGNORE_ptrace
#define __IGNORE_alarm
#define __IGNORE_pause
#define __IGNORE_kill
#define __IGNORE_brk
#define __IGNORE_uselib
#define __IGNORE_swapon
#define __IGNORE_mmap
#define __IGNORE_munmap
#define __IGNORE_swapoff
#define __IGNORE_clone
#define __IGNORE_mprotect
#define __IGNORE_init_module
#define __IGNORE_quotactl
#define __IGNORE_msync
#define __IGNORE_mlock
#define __IGNORE_munlock
#define __IGNORE_mlockall
#define __IGNORE_munlockall
#define __IGNORE_mremap
#define __IGNORE_rt_sigreturn
#define __IGNORE_rt_sigaction
#define __IGNORE_rt_sigprocmask
#define __IGNORE_rt_sigpending
#define __IGNORE_rt_sigtimedwait
#define __IGNORE_rt_sigqueueinfo
#define __IGNORE_rt_sigsuspend
#define __IGNORE_sigaltstack
#define __IGNORE_vfork
#define __IGNORE_mincore
#define __IGNORE_madvise
#define __IGNORE_getdents /* we use the 64 bit counter part instead */

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"counterpart" should be just one word.
(with the space, it's easy to mis-read it as "64 bit counter")

#define __IGNORE_tkill
#define __IGNORE_exit_group
#define __IGNORE_remap_file_pages
#define __IGNORE_fstatfs /* we use the 64 bit counter part instead */
#define __IGNORE_mbind
#define __IGNORE_get_mempolicy
#define __IGNORE_set_mempolicy
#define __IGNORE_mq_open
#define __IGNORE_mq_unlink
#define __IGNORE_mq_timedsend
#define __IGNORE_mq_timedreceive
#define __IGNORE_mq_getsetattr
#define __IGNORE_kexec_load
#define __IGNORE_migrate_pages
#define __IGNORE_unshare
#define __IGNORE_set_robust_list
#define __IGNORE_get_robust_list
#define __IGNORE_sync_file_range
#define __IGNORE_vmsplice
#define __IGNORE_move_pages
#define __IGNORE_mq_notify
#define __IGNORE_delete_module
#define __IGNORE_signalfd4
#define __IGNORE_preadv /* we use the 64 bit counter part instead */
#define __IGNORE_pwritev /* we use the 64 bit counter part instead */
#define __IGNORE_rt_tgsigqueueinfo
#define __IGNORE_perf_event_open
#define __IGNORE_setns
#define __IGNORE_process_vm_readv
#define __IGNORE_process_vm_writev
#define __IGNORE_kcmp
#define __IGNORE_finit_module
#define __IGNORE_seccomp
#define __IGNORE_memfd_create
#define __IGNORE_bpf
#define __IGNORE_execveat
12 changes: 11 additions & 1 deletion arch/lkl/kernel/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
extra-y := vmlinux.lds
SYSCALL_DEFS_HDR := ../include/generated/uapi/asm/syscall_defs.h
UNISTD_HDR = arch/lkl/include/asm/unistd.h

extra-y := vmlinux.lds $(SYSCALL_DEFS_HDR)
obj-y = setup.o threads.o irq.o time.o syscalls.o misc.o mem.o console.o


quiet_cmd_syscall_def = CALL $<
cmd_syscall_def = $< sysdef $(UNISTD_HDR) arch/lkl/include/generated/uapi/asm/syscall_defs.h

arch/lkl/kernel/$(SYSCALL_DEFS_HDR): arch/lkl/scripts/make_syscall_tbl.sh $(UNISTD_HDR)
@mkdir -p arch/lkl/include/generated/uapi/asm/
$(call cmd,syscall_def)
2 changes: 2 additions & 0 deletions arch/lkl/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ typedef long (*syscall_handler_t)(long arg1, ...);
syscall_handler_t syscall_table[__NR_syscalls] = {
[0 ... __NR_syscalls - 1] = (syscall_handler_t)sys_ni_syscall,
#include <asm/unistd.h>
/* override __IGNORE-ed syscalls */
#include <asm/syscall_table.h>
};

static struct syscall_queue {
Expand Down
123 changes: 123 additions & 0 deletions arch/lkl/scripts/make_syscall_tbl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash

#set -x

# requires: bash-4.0 (hashtable), cpp, grep, sed, cat

##
## Usage: $0
## ARGV[0]: (OPT: "systbl" oe "sysdef")
## ARGV[1]: (IN: asm/unistd.h)
## ARGV[2]: (OUT: syscall_table.h(systbl) or syscall_defs.h (sysdef))
##

mode=$1
in=$2
out=$3

if [ "$mode" != "systbl" ] && [ "$mode" != "sysdef" ] ; then
echo "Usage: $0 [systbl|sysdef] (unistd.h) (output file)"
exit
fi

echo "" > $out

# obtain the blacklist of syscall
declare -A ignore_syscall

##
## step 1: create ignored syscall table entries based on
##
while read def nr ; do
name=$(echo $nr | sed "s/__IGNORE_/__NR_/")
ignore_syscall[$name]="ignored"

if [ $mode = "systbl" ] ; then
cat << EOF >> $out
#define __SYSCALL_STE_${name}(nr,sym) [nr] = (syscall_handler_t)sys_ni_syscall,
__SYSCALL_STE_${name}(${name},dummy)
EOF
fi
done < <(${CROSS_COMPILE}cpp ${LINUXINCLUDE} -dM -fdirectives-only $in | grep '__IGNORE_')

##
## stop if systbl is specified
##
if [ $mode = "systbl" ] ; then
exit
fi


##
## step 2-1: grep SYSCALL_DEFINE in whole tree with specific
## directories ($SYSCALL_DIRS)
##
SYSCALL_DIRS="block drivers/pci drivers/char fs init ipc kernel mm net"
SYSCALL_FILES=$(find ${SYSCALL_DIRS} -name \*.c | \
xargs grep -E "^SYSCALL_DEFINE[0-6]" -l)

##
## step 2-2: dump lkl syscall definitions from preprocessor's ouptut
##
set -f
for file in ${SYSCALL_FILES} ;
do
while read syscall; do
func=$(echo $syscall | sed "s/SYSCALL_DEFINE.*(\([^,]*\).*/\1/")
#echo "syscall= "$syscall
#echo "func= "$func

# 0) pull the system call name
funcname=$(echo $func | sed "s/(.*//" | sed "s/long sys_//")
#echo "funcname ="$funcname

# 1) skip if the syscall is unsupported
if [ "${ignore_syscall[__NR_$funcname]}" = "ignored" ] ; then
#echo $funcname " ignore= " "${ignore_syscall[__NR_$funcname]}"
continue
fi

# 2) count the number of argument
func_l=/$func/
IFS=','
set -- $func_l
argc=0
if [ $(echo $func | sed "s/.*(//") != "void)" ] ; then
argc=`expr $(($#-1)) + 1`
fi
#echo "argc = $argc"
IFS=' '

# 3) pull arg name template
args=$(echo $func | sed "s/.*(/(/" | sed "s/__lkl__kernel_//g"\
| sed "s/lkl_//g" | sed "s/[()]//g")
OIFS="$IFS"; IFS=','
arg=($args); IFS="$OIFS"
#echo "arg ="$arg > /dev/stdout

param=""
for i in {1..6} ; do
if [ $i -gt ${argc} ] ; then
break
fi
if [ $i -ne 1 ] ; then
param="${param}, "
fi
nparam=$(echo ${arg[$((i-1))]} | \
sed "s/\(.*\) \(.*\)$/\1, \2/")
param="${param}${nparam}"
done
#echo ${param} > /dev/stdout
IFS=' '

# 4) give a template based on funcname, args
cat << EOF >> $out

#ifdef __NR_$funcname
SYSCALL_DEFINE$argc(_$funcname, $param);
#endif /* __NR_$funcname */
EOF
done < <(${CROSS_COMPILE}cpp -P ${LINUXINCLUDE} $file 2>/dev/null \
| grep "long sys_" | sed "s/^; / /" \
| sed "s/\(.*\) __attribute.*/\1/" | grep -vE ";|,$")
done
2 changes: 0 additions & 2 deletions include/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ extern struct trace_event_functions exit_syscall_print_funcs;

#define SYSCALL_DEFINE0(sname) \
SYSCALL_METADATA(_##sname, 0); \
__SYSCALL_DEFINE_ARCH(0, _##sname); \
asmlinkage long sys_##sname(void)

#define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
Expand All @@ -193,7 +192,6 @@ extern struct trace_event_functions exit_syscall_print_funcs;

#define SYSCALL_DEFINEx(x, sname, ...) \
SYSCALL_METADATA(sname, x, __VA_ARGS__) \
__SYSCALL_DEFINE_ARCH(x, sname, __VA_ARGS__) \
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)

#define __PROTECT(...) asmlinkage_protect(__VA_ARGS__)
Expand Down
14 changes: 14 additions & 0 deletions tools/lkl/tests/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,19 @@ static int test_umount(char *str, int len)
return 0;
}

static int test_syscall(char *str, int len)
{
long ret, params[6];

ret = lkl_syscall(__lkl__NR_fork, params);

snprintf(str, len, "%ld", ret);
if (ret == -LKL_ENOSYS)
return 1;

return 0;
}

static struct cl_option *find_short_opt(char name)
{
struct cl_option *opt;
Expand Down Expand Up @@ -516,6 +529,7 @@ int main(int argc, char **argv)
TEST(opendir);
TEST(getdents64);
TEST(umount);
TEST(syscall);

lkl_sys_halt();

Expand Down