Skip to content

Commit

Permalink
Add linux submodule, build it from meson
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Jun 27, 2021
1 parent c0ae5e5 commit 071b4e6
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 101 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build-linux:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
cc: [clang, gcc]
kernel: [ish, linux]
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -22,15 +22,19 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install ninja-build libarchive-dev
pip3 install meson
sudo apt-get install libarchive-dev
pip3 install meson ninja
- name: Clone Linux
if: matrix.kernel == 'linux'
run: deps/clone-linux.sh
- name: Build
run: |
meson build -Dengine=jit
meson build -Dengine=jit -Dkernel=${{matrix.kernel}}
ninja -C build
env:
CC: ${{matrix.cc}}
- name: Test
if: matrix.kernel == 'ish'
run: ninja -C build test

build-mac:
Expand Down
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
[submodule "deps/libarchive"]
path = deps/libarchive
url = https://github.com/libarchive/libarchive
[submodule "deps/linux"]
path = deps/linux
url = https://github.com/ish-app/linux
update = none
shallow = true
8 changes: 8 additions & 0 deletions deps/clone-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh -e
repo_root="$(realpath "$(dirname $0)/..")"
sub_path=deps/linux
sub_repo="$repo_root/$sub_path"
git submodule init "$sub_path"
git clone "$(git config submodule.$sub_path.url)" --depth=1 --sparse --filter=blob:none "$sub_repo"
git -C "$sub_repo" sparse-checkout set --stdin < "$sub_repo/../linux-sparse.txt"
git config --local submodule.$sub_path.update checkout
1 change: 1 addition & 0 deletions deps/linux
Submodule linux added at 3f78b0
23 changes: 23 additions & 0 deletions deps/linux-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -e
output="$1"
srctree="$2"
objtree="$3"
depfile="$4"
export ISH_CFLAGS="$5"
export LIB_ISH_EMU="$6"
export ARCH=ish

mkdir -p "$objtree"
export ISH_MESON_VARS="$(realpath "$objtree/meson_vars.mk")"
cat >"$ISH_MESON_VARS" <<END
export ISH_CFLAGS = $ISH_CFLAGS
export LIB_ISH_EMU = $LIB_ISH_EMU
END

defconfig=app_defconfig
if [[ "$srctree/arch/ish/configs/$defconfig" -nt "$objtree/.config" ]]; then
make -C "$srctree" O="$(realpath "$objtree")" "$defconfig"
fi

make -C "$objtree" -j "$(nproc)" --debug=v | "$srctree/../makefilter.py" "$depfile" "$output"
cp "$objtree/vmlinux" "$output"
88 changes: 88 additions & 0 deletions deps/linux-sparse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Makefile
Kbuild
Kconfig*

!/arch/
/arch/ish/
/arch/x86/include/asm/
/arch/x86/include/uapi/
/arch/x86/entry/syscalls/
/arch/x86/kernel/sys_ia32.c
/arch/um/scripts/Makefile.rules

!/drivers/
/drivers/block/
/drivers/char/
/drivers/tty/
!/drivers/tty/serial
/drivers/base/
/drivers/net/Space.c
/drivers/net/loopback.c
/drivers/net/veth.c

!/fs/*/
/fs/xfs/xfs_sysctl.h
/fs/squashfs/squashfs_fs.h
/fs/iomap/
/fs/kernfs/
/fs/proc/
/fs/sysfs/
/fs/devpts/
/fs/notify/
/fs/ext4/
/fs/jbd2/
/fs/ramfs/
/fs/overlayfs/
/fs/hostfs/
/fs/exportfs/

!/net/*/
/net/core/
/net/llc/
/net/ethernet/
/net/802/
/net/sched/
/net/netlink/
/net/ethtool/
/net/netfilter/
/net/ipv4/
/net/unix/
/net/ipv6/
/net/packet/
/net/bridge/

!/include/linux/*/
/include/linux/sched/
/include/linux/device/
/include/linux/byteorder/
/include/linux/netfilter/
/include/linux/decompress/
/include/linux/gpio/
/include/linux/sunrpc/
/include/linux/unaligned/
/include/linux/pinctrl/
/include/linux/raid/
/include/linux/clk/
/include/linux/netfilter_ipv4/
/include/linux/platform_data/dsa.h
!/include/dt-bindings
!/include/sound

!/sound
!/tools
!/Documentation

!/include/uapi/linux/netfilter/xt_connmark.h
!/include/uapi/linux/netfilter/xt_dscp.h
!/include/uapi/linux/netfilter/xt_MARK.h
!/include/uapi/linux/netfilter/xt_tcpmss.h
!/include/uapi/linux/netfilter/xt_rateest.h
!/include/uapi/linux/netfilter_ipv4/ipt_ecn.h
!/include/uapi/linux/netfilter_ipv4/ipt_ttl.h
!/include/uapi/linux/netfilter_ipv6/ip6t_hl.h
!/net/netfilter/xt_dscp.c
!/net/netfilter/xt_hl.c
!/net/netfilter/xt_rateest.c
!/net/netfilter/xt_tcpmss.c
!/tools/memory-model/litmus-tests/Z6.0+pooncelock+pooncelock+pombonce.litmus
21 changes: 21 additions & 0 deletions deps/makefilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
import sys
import re
import os
line_re = re.compile(r'^ [A-Z]+\s+')
dep_re = re.compile(r'\s+Prerequisite `([^\']*)\' is older than target')
deps = set()
for line in sys.stdin:
if line.endswith('\n'):
line = line[:-1]
if line_re.match(line):
print(line)
m = dep_re.match(line)
if m:
deps.add(m.group(1))
deps = [os.path.realpath(dep) for dep in sorted(deps)]
deps = [dep for dep in deps if os.path.exists(dep)]
with open(sys.argv[1], 'w') as f:
print(f'{sys.argv[2]}: \\', file=f)
for dep in deps:
print(f'{dep} \\', file=f)
43 changes: 43 additions & 0 deletions deps/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
if get_option('kernel') == 'linux'
build_linux = custom_target('linux',
command: [
find_program('linux-build.sh'),
'@OUTPUT0@',
'@SOURCE_ROOT@/deps/linux',
'@OUTPUT1@',
'@DEPFILE@',

# hack to find the right directories because meson is bad
'-I'+meson.project_source_root(), # ISH_CFLAGS
meson.project_build_root() + '/libish_emu.a', # LIB_ISH_EMU
],
depend_files: ['makefilter.py'],
depends: [libish_emu],
console: true,
depfile: 'linux.d',
output: ['liblinux.a', 'linux'])

# Create empty include directories so the liblinux declaration doesn't throw File Not Found
run_command('mkdir', [
'-p',
meson.current_build_dir()+'/linux/include/generated/uapi',
meson.current_build_dir()+'/linux/arch/ish/include/generated/uapi'])

liblinux = declare_dependency(
link_with: [libish_emu],
link_whole: [build_linux[0]],
link_args: [
'-sectalign', '__DATA', '__percpu_first', '1000',
'-sectalign', '__DATA', '__tracepoints', '20',
],
compile_args: ['-include', 'linux/compiler_attributes.h', '-U__weak'],
include_directories: include_directories(
'linux/arch/ish/include',
'linux/arch/ish/include/generated',
'linux/include',
'linux/arch/ish/include/uapi',
'linux/arch/ish/include/generated/uapi',
'linux/include/uapi',
'linux/include/generated/uapi',
))
endif
2 changes: 1 addition & 1 deletion emu/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static_assert(CPU_OFFSET(esp) == CPU_OFFSET(regs[4]), "register order");
static_assert(CPU_OFFSET(ebp) == CPU_OFFSET(regs[5]), "register order");
static_assert(CPU_OFFSET(esi) == CPU_OFFSET(regs[6]), "register order");
static_assert(CPU_OFFSET(edi) == CPU_OFFSET(regs[7]), "register order");
static_assert(sizeof(struct cpu_state) < UINT16_MAX, "cpu struct is too big for vector gadgets");
static_assert(sizeof(struct cpu_state) < 0xffff, "cpu struct is too big for vector gadgets");

// flags
#define ZF (cpu->zf_res ? cpu->res == 0 : cpu->zf)
Expand Down
17 changes: 17 additions & 0 deletions linux/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <linux/compiler_attributes.h>
#include <linux/start_kernel.h>
#include <string.h>

extern void run_kernel(void);

int main(int argc, const char *argv[])
{
int i;
for (i = 1; i < argc; i++) {
if (i > 1)
strcat(boot_command_line, " ");
strcat(boot_command_line, argv[i]);
}
run_kernel();
return 0;
}
Loading

0 comments on commit 071b4e6

Please sign in to comment.