Merge branch 'master' of postpeta.pccluster.org:mckernel
This commit is contained in:
@@ -82,6 +82,7 @@ void x86_init_perfctr(void);
|
|||||||
int gettime_local_support = 0;
|
int gettime_local_support = 0;
|
||||||
|
|
||||||
extern int kprintf(const char *format, ...);
|
extern int kprintf(const char *format, ...);
|
||||||
|
extern int interrupt_from_user(void *);
|
||||||
|
|
||||||
static struct idt_entry{
|
static struct idt_entry{
|
||||||
uint32_t desc[4];
|
uint32_t desc[4];
|
||||||
@@ -786,6 +787,8 @@ void handle_interrupt(int vector, struct x86_user_context *regs)
|
|||||||
lapic_ack();
|
lapic_ack();
|
||||||
++v->in_interrupt;
|
++v->in_interrupt;
|
||||||
|
|
||||||
|
set_cputime(interrupt_from_user(regs)? 1: 2);
|
||||||
|
|
||||||
dkprintf("CPU[%d] got interrupt, vector: %d, RIP: 0x%lX\n",
|
dkprintf("CPU[%d] got interrupt, vector: %d, RIP: 0x%lX\n",
|
||||||
ihk_mc_get_processor_id(), vector, regs->gpr.rip);
|
ihk_mc_get_processor_id(), vector, regs->gpr.rip);
|
||||||
|
|
||||||
@@ -862,12 +865,14 @@ void handle_interrupt(int vector, struct x86_user_context *regs)
|
|||||||
|
|
||||||
check_signal(0, regs, 0);
|
check_signal(0, regs, 0);
|
||||||
check_need_resched();
|
check_need_resched();
|
||||||
|
set_cputime(0);
|
||||||
|
|
||||||
--v->in_interrupt;
|
--v->in_interrupt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpe_handler(struct x86_user_context *regs)
|
void gpe_handler(struct x86_user_context *regs)
|
||||||
{
|
{
|
||||||
|
set_cputime(interrupt_from_user(regs)? 1: 2);
|
||||||
kprintf("General protection fault (err: %lx, %lx:%lx)\n",
|
kprintf("General protection fault (err: %lx, %lx:%lx)\n",
|
||||||
regs->gpr.error, regs->gpr.cs, regs->gpr.rip);
|
regs->gpr.error, regs->gpr.cs, regs->gpr.rip);
|
||||||
arch_show_interrupt_context(regs);
|
arch_show_interrupt_context(regs);
|
||||||
@@ -877,6 +882,7 @@ void gpe_handler(struct x86_user_context *regs)
|
|||||||
set_signal(SIGSEGV, regs, NULL);
|
set_signal(SIGSEGV, regs, NULL);
|
||||||
check_signal(0, regs, 0);
|
check_signal(0, regs, 0);
|
||||||
check_need_resched();
|
check_need_resched();
|
||||||
|
set_cputime(0);
|
||||||
// panic("GPF");
|
// panic("GPF");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -886,6 +892,7 @@ void debug_handler(struct x86_user_context *regs)
|
|||||||
int si_code = 0;
|
int si_code = 0;
|
||||||
struct siginfo info;
|
struct siginfo info;
|
||||||
|
|
||||||
|
set_cputime(interrupt_from_user(regs)? 1: 2);
|
||||||
#ifdef DEBUG_PRINT_CPU
|
#ifdef DEBUG_PRINT_CPU
|
||||||
kprintf("debug exception (err: %lx, %lx:%lx)\n",
|
kprintf("debug exception (err: %lx, %lx:%lx)\n",
|
||||||
regs->gpr.error, regs->gpr.cs, regs->gpr.rip);
|
regs->gpr.error, regs->gpr.cs, regs->gpr.rip);
|
||||||
@@ -905,12 +912,14 @@ void debug_handler(struct x86_user_context *regs)
|
|||||||
set_signal(SIGTRAP, regs, &info);
|
set_signal(SIGTRAP, regs, &info);
|
||||||
check_signal(0, regs, 0);
|
check_signal(0, regs, 0);
|
||||||
check_need_resched();
|
check_need_resched();
|
||||||
|
set_cputime(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void int3_handler(struct x86_user_context *regs)
|
void int3_handler(struct x86_user_context *regs)
|
||||||
{
|
{
|
||||||
struct siginfo info;
|
struct siginfo info;
|
||||||
|
|
||||||
|
set_cputime(interrupt_from_user(regs)? 1: 2);
|
||||||
#ifdef DEBUG_PRINT_CPU
|
#ifdef DEBUG_PRINT_CPU
|
||||||
kprintf("int3 exception (err: %lx, %lx:%lx)\n",
|
kprintf("int3 exception (err: %lx, %lx:%lx)\n",
|
||||||
regs->gpr.error, regs->gpr.cs, regs->gpr.rip);
|
regs->gpr.error, regs->gpr.cs, regs->gpr.rip);
|
||||||
@@ -922,6 +931,7 @@ void int3_handler(struct x86_user_context *regs)
|
|||||||
set_signal(SIGTRAP, regs, &info);
|
set_signal(SIGTRAP, regs, &info);
|
||||||
check_signal(0, regs, 0);
|
check_signal(0, regs, 0);
|
||||||
check_need_resched();
|
check_need_resched();
|
||||||
|
set_cputime(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
* syscall_name[] only, no handler exists.
|
* syscall_name[] only, no handler exists.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SYSCALL_DELEGATED(0, read)
|
SYSCALL_HANDLED(0, read)
|
||||||
SYSCALL_DELEGATED(1, write)
|
SYSCALL_DELEGATED(1, write)
|
||||||
SYSCALL_DELEGATED(2, open)
|
SYSCALL_DELEGATED(2, open)
|
||||||
SYSCALL_HANDLED(3, close)
|
SYSCALL_HANDLED(3, close)
|
||||||
@@ -35,7 +35,7 @@ SYSCALL_HANDLED(12, brk)
|
|||||||
SYSCALL_HANDLED(13, rt_sigaction)
|
SYSCALL_HANDLED(13, rt_sigaction)
|
||||||
SYSCALL_HANDLED(14, rt_sigprocmask)
|
SYSCALL_HANDLED(14, rt_sigprocmask)
|
||||||
SYSCALL_HANDLED(15, rt_sigreturn)
|
SYSCALL_HANDLED(15, rt_sigreturn)
|
||||||
SYSCALL_DELEGATED(16, ioctl)
|
SYSCALL_HANDLED(16, ioctl)
|
||||||
SYSCALL_DELEGATED(17, pread64)
|
SYSCALL_DELEGATED(17, pread64)
|
||||||
SYSCALL_DELEGATED(18, pwrite64)
|
SYSCALL_DELEGATED(18, pwrite64)
|
||||||
SYSCALL_DELEGATED(20, writev)
|
SYSCALL_DELEGATED(20, writev)
|
||||||
@@ -51,6 +51,8 @@ SYSCALL_HANDLED(30, shmat)
|
|||||||
SYSCALL_HANDLED(31, shmctl)
|
SYSCALL_HANDLED(31, shmctl)
|
||||||
SYSCALL_HANDLED(34, pause)
|
SYSCALL_HANDLED(34, pause)
|
||||||
SYSCALL_HANDLED(35, nanosleep)
|
SYSCALL_HANDLED(35, nanosleep)
|
||||||
|
SYSCALL_HANDLED(36, getitimer)
|
||||||
|
SYSCALL_HANDLED(38, setitimer)
|
||||||
SYSCALL_HANDLED(39, getpid)
|
SYSCALL_HANDLED(39, getpid)
|
||||||
SYSCALL_HANDLED(56, clone)
|
SYSCALL_HANDLED(56, clone)
|
||||||
SYSCALL_DELEGATED(57, fork)
|
SYSCALL_DELEGATED(57, fork)
|
||||||
@@ -69,6 +71,7 @@ SYSCALL_DELEGATED(79, getcwd)
|
|||||||
SYSCALL_DELEGATED(89, readlink)
|
SYSCALL_DELEGATED(89, readlink)
|
||||||
SYSCALL_HANDLED(96, gettimeofday)
|
SYSCALL_HANDLED(96, gettimeofday)
|
||||||
SYSCALL_HANDLED(97, getrlimit)
|
SYSCALL_HANDLED(97, getrlimit)
|
||||||
|
SYSCALL_HANDLED(100, times)
|
||||||
SYSCALL_HANDLED(101, ptrace)
|
SYSCALL_HANDLED(101, ptrace)
|
||||||
SYSCALL_HANDLED(102, getuid)
|
SYSCALL_HANDLED(102, getuid)
|
||||||
SYSCALL_HANDLED(104, getgid)
|
SYSCALL_HANDLED(104, getgid)
|
||||||
@@ -107,6 +110,7 @@ SYSCALL_HANDLED(158, arch_prctl)
|
|||||||
SYSCALL_HANDLED(160, setrlimit)
|
SYSCALL_HANDLED(160, setrlimit)
|
||||||
SYSCALL_HANDLED(164, settimeofday)
|
SYSCALL_HANDLED(164, settimeofday)
|
||||||
SYSCALL_HANDLED(186, gettid)
|
SYSCALL_HANDLED(186, gettid)
|
||||||
|
SYSCALL_HANDLED(200, tkill)
|
||||||
SYSCALL_DELEGATED(201, time)
|
SYSCALL_DELEGATED(201, time)
|
||||||
SYSCALL_HANDLED(202, futex)
|
SYSCALL_HANDLED(202, futex)
|
||||||
SYSCALL_HANDLED(203, sched_setaffinity)
|
SYSCALL_HANDLED(203, sched_setaffinity)
|
||||||
@@ -133,6 +137,7 @@ SYSCALL_HANDLED(279, move_pages)
|
|||||||
SYSCALL_DELEGATED(281, epoll_pwait)
|
SYSCALL_DELEGATED(281, epoll_pwait)
|
||||||
SYSCALL_HANDLED(282, signalfd)
|
SYSCALL_HANDLED(282, signalfd)
|
||||||
SYSCALL_HANDLED(289, signalfd4)
|
SYSCALL_HANDLED(289, signalfd4)
|
||||||
|
SYSCALL_HANDLED(298, perf_event_open)
|
||||||
#ifdef DCFA_KMOD
|
#ifdef DCFA_KMOD
|
||||||
SYSCALL_HANDLED(303, mod_call)
|
SYSCALL_HANDLED(303, mod_call)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -209,7 +209,9 @@ enter_user_mode:
|
|||||||
callq release_runq_lock
|
callq release_runq_lock
|
||||||
movq $0, %rdi
|
movq $0, %rdi
|
||||||
movq %rsp, %rsi
|
movq %rsp, %rsi
|
||||||
call check_signal
|
call check_signal
|
||||||
|
movq $0, %rdi
|
||||||
|
call set_cputime
|
||||||
POP_ALL_REGS
|
POP_ALL_REGS
|
||||||
addq $8, %rsp
|
addq $8, %rsp
|
||||||
iretq
|
iretq
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ int write_process_vm(struct process_vm *vm, void *dst, const void *src, size_t s
|
|||||||
long do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact);
|
long do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact);
|
||||||
long syscall(int num, ihk_mc_user_context_t *ctx);
|
long syscall(int num, ihk_mc_user_context_t *ctx);
|
||||||
extern void save_fp_regs(struct thread *proc);
|
extern void save_fp_regs(struct thread *proc);
|
||||||
|
void set_signal(int sig, void *regs0, siginfo_t *info);
|
||||||
|
void check_signal(unsigned long rc, void *regs0, int num);
|
||||||
|
|
||||||
//#define DEBUG_PRINT_SC
|
//#define DEBUG_PRINT_SC
|
||||||
|
|
||||||
@@ -178,6 +180,17 @@ SYSCALL_DECLARE(rt_sigreturn)
|
|||||||
if(sigsp->restart){
|
if(sigsp->restart){
|
||||||
return syscall(sigsp->num, (ihk_mc_user_context_t *)regs);
|
return syscall(sigsp->num, (ihk_mc_user_context_t *)regs);
|
||||||
}
|
}
|
||||||
|
if(regs->gpr.rflags & RFLAGS_TF){
|
||||||
|
struct siginfo info;
|
||||||
|
|
||||||
|
regs->gpr.rax = sigsp->sigrc;
|
||||||
|
memset(&info, '\0', sizeof info);
|
||||||
|
regs->gpr.rflags &= ~RFLAGS_TF;
|
||||||
|
info.si_code = TRAP_TRACE;
|
||||||
|
set_signal(SIGTRAP, regs, &info);
|
||||||
|
check_signal(0, regs, 0);
|
||||||
|
check_need_resched();
|
||||||
|
}
|
||||||
return sigsp->sigrc;
|
return sigsp->sigrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,6 +608,16 @@ do_signal(unsigned long rc, void *regs0, struct thread *thread, struct sig_pendi
|
|||||||
thread->sigmask.__val[0] |= pending->sigmask.__val[0];
|
thread->sigmask.__val[0] |= pending->sigmask.__val[0];
|
||||||
kfree(pending);
|
kfree(pending);
|
||||||
ihk_mc_spinlock_unlock(&thread->sigcommon->lock, irqstate);
|
ihk_mc_spinlock_unlock(&thread->sigcommon->lock, irqstate);
|
||||||
|
if(regs->gpr.rflags & RFLAGS_TF){
|
||||||
|
struct siginfo info;
|
||||||
|
|
||||||
|
memset(&info, '\0', sizeof info);
|
||||||
|
regs->gpr.rflags &= ~RFLAGS_TF;
|
||||||
|
info.si_code = TRAP_TRACE;
|
||||||
|
set_signal(SIGTRAP, regs, &info);
|
||||||
|
check_signal(0, regs, 0);
|
||||||
|
check_need_resched();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int coredumped = 0;
|
int coredumped = 0;
|
||||||
@@ -756,6 +779,14 @@ hassigpending(struct thread *thread)
|
|||||||
return getsigpending(thread, 0);
|
return getsigpending(thread, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
interrupt_from_user(void *regs0)
|
||||||
|
{
|
||||||
|
struct x86_user_context *regs = regs0;
|
||||||
|
|
||||||
|
return !(regs->gpr.rsp & 0x8000000000000000);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
check_signal(unsigned long rc, void *regs0, int num)
|
check_signal(unsigned long rc, void *regs0, int num)
|
||||||
{
|
{
|
||||||
@@ -785,7 +816,7 @@ check_signal(unsigned long rc, void *regs0, int num)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(regs != NULL && (regs->gpr.rsp & 0x8000000000000000)) {
|
if(regs != NULL && !interrupt_from_user(regs)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ fi
|
|||||||
# Remove mcoverlay if loaded
|
# Remove mcoverlay if loaded
|
||||||
if [ "$enable_mcoverlay" != "" ]; then
|
if [ "$enable_mcoverlay" != "" ]; then
|
||||||
if [ "`lsmod | grep mcoverlay`" != "" ]; then
|
if [ "`lsmod | grep mcoverlay`" != "" ]; then
|
||||||
|
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_sys`" != "" ]; then umount -l /tmp/mcos/mcos0_sys; fi
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_proc`" != "" ]; then umount -l /tmp/mcos/mcos0_proc; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_proc`" != "" ]; then umount -l /tmp/mcos/mcos0_proc; fi
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos`" != "" ]; then umount -l /tmp/mcos; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos`" != "" ]; then umount -l /tmp/mcos; fi
|
||||||
if [ -e /tmp/mcos ]; then rm -rf /tmp/mcos; fi
|
if [ -e /tmp/mcos ]; then rm -rf /tmp/mcos; fi
|
||||||
@@ -159,6 +160,25 @@ if [ "$enable_mcoverlay" != "" ]; then
|
|||||||
if [ ! -e /tmp/mcos/mcos0_proc_work ]; then mkdir -p /tmp/mcos/mcos0_proc_work; fi
|
if [ ! -e /tmp/mcos/mcos0_proc_work ]; then mkdir -p /tmp/mcos/mcos0_proc_work; fi
|
||||||
if ! mount -t mcoverlay mcoverlay -o lowerdir=/proc/mcos0:/proc,upperdir=/tmp/mcos/mcos0_proc_upper,workdir=/tmp/mcos/mcos0_proc_work,nocopyupw,nofscheck /tmp/mcos/mcos0_proc; then echo "error: mount /tmp/mcos/mcos0_proc"; exit; fi
|
if ! mount -t mcoverlay mcoverlay -o lowerdir=/proc/mcos0:/proc,upperdir=/tmp/mcos/mcos0_proc_upper,workdir=/tmp/mcos/mcos0_proc_work,nocopyupw,nofscheck /tmp/mcos/mcos0_proc; then echo "error: mount /tmp/mcos/mcos0_proc"; exit; fi
|
||||||
mount --make-rprivate /proc
|
mount --make-rprivate /proc
|
||||||
|
while [ ! -e /sys/devices/virtual/mcos/mcos0/sys ]
|
||||||
|
do
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
if [ ! -e /tmp/mcos/mcos0_sys ]; then mkdir -p /tmp/mcos/mcos0_sys; fi
|
||||||
|
if [ ! -e /tmp/mcos/mcos0_sys_upper ]; then mkdir -p /tmp/mcos/mcos0_sys_upper; fi
|
||||||
|
if [ ! -e /tmp/mcos/mcos0_sys_work ]; then mkdir -p /tmp/mcos/mcos0_sys_work; fi
|
||||||
|
if ! mount -t mcoverlay mcoverlay -o lowerdir=/sys/devices/virtual/mcos/mcos0/sys:/sys,upperdir=/tmp/mcos/mcos0_sys_upper,workdir=/tmp/mcos/mcos0_sys_work,nocopyupw,nofscheck /tmp/mcos/mcos0_sys; then echo "error: mount /tmp/mcos/mcos0_sys"; exit; fi
|
||||||
|
mount --make-rprivate /sys
|
||||||
|
for cpuid in `find /sys/devices/system/cpu/* -maxdepth 0 -name "cpu[0123456789]*" -printf "%f "`; do
|
||||||
|
if [ ! -e "/sys/devices/virtual/mcos/mcos0/sys/devices/system/cpu/$cpuid" ]; then
|
||||||
|
rm -rf /tmp/mcos/mcos0_sys/devices/system/cpu/$cpuid
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
for cpuid in `find /sys/bus/cpu/devices/* -maxdepth 0 -name "cpu[0123456789]*" -printf "%f "`; do
|
||||||
|
if [ ! -e "/sys/devices/virtual/mcos/mcos0/sys/bus/cpu/devices/$cpuid" ]; then
|
||||||
|
rm -rf /tmp/mcos/mcos0_sys/bus/cpu/devices/$cpuid
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
if [ ${LOGMODE} -ne 0 ]
|
if [ ${LOGMODE} -ne 0 ]
|
||||||
then
|
then
|
||||||
|
|||||||
303
configure
vendored
303
configure
vendored
@@ -649,6 +649,7 @@ ac_user_opts='
|
|||||||
enable_option_checking
|
enable_option_checking
|
||||||
with_kernelsrc
|
with_kernelsrc
|
||||||
with_target
|
with_target
|
||||||
|
with_system_map
|
||||||
enable_dcfa
|
enable_dcfa
|
||||||
'
|
'
|
||||||
ac_precious_vars='build_alias
|
ac_precious_vars='build_alias
|
||||||
@@ -1277,6 +1278,8 @@ Optional Packages:
|
|||||||
/lib/modules/uname_r/build
|
/lib/modules/uname_r/build
|
||||||
--with-target={attached-mic | builtin-mic | builtin-x86 | smp-x86}
|
--with-target={attached-mic | builtin-mic | builtin-x86 | smp-x86}
|
||||||
target, default is attached-mic
|
target, default is attached-mic
|
||||||
|
--with-system_map=path Path to 'System.map file', default is
|
||||||
|
/boot/System.map-uname_r
|
||||||
|
|
||||||
Some influential environment variables:
|
Some influential environment variables:
|
||||||
CC C compiler command
|
CC C compiler command
|
||||||
@@ -1784,6 +1787,15 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Check whether --with-system_map was given.
|
||||||
|
if test "${with_system_map+set}" = set; then :
|
||||||
|
withval=$with_system_map; WITH_SYSTEM_MAP=$withval
|
||||||
|
else
|
||||||
|
WITH_SYSTEM_MAP=yes
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Check whether --enable-dcfa was given.
|
# Check whether --enable-dcfa was given.
|
||||||
if test "${enable_dcfa+set}" = set; then :
|
if test "${enable_dcfa+set}" = set; then :
|
||||||
enableval=$enable_dcfa;
|
enableval=$enable_dcfa;
|
||||||
@@ -3798,6 +3810,96 @@ esac
|
|||||||
KDIR="$WITH_KERNELSRC"
|
KDIR="$WITH_KERNELSRC"
|
||||||
TARGET="$WITH_TARGET"
|
TARGET="$WITH_TARGET"
|
||||||
|
|
||||||
|
MCCTRL_LINUX_SYMTAB=""
|
||||||
|
case "X$WITH_SYSTEM_MAP" in
|
||||||
|
Xyes | Xno | X)
|
||||||
|
MCCTRL_LINUX_SYMTAB=""
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
MCCTRL_LINUX_SYMTAB="$WITH_SYSTEM_MAP"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for System.map" >&5
|
||||||
|
$as_echo_n "checking for System.map... " >&6; }
|
||||||
|
if test -f "$MCCTRL_LINUX_SYMTAB"; then
|
||||||
|
MCCTRL_LINUX_SYMTAB="$MCCTRL_LINUX_SYMTAB"
|
||||||
|
elif test -f "/boot/System.map-`uname -r`"; then
|
||||||
|
MCCTRL_LINUX_SYMTAB="/boot/System.map-`uname -r`"
|
||||||
|
elif test -f "$KDIR/System.map"; then
|
||||||
|
MCCTRL_LINUX_SYMTAB="$KDIR/System.map"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$MCCTRL_LINUX_SYMTAB" == ""; then
|
||||||
|
as_fn_error $? "could not find" "$LINENO" 5
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "`eval cat $MCCTRL_LINUX_SYMTAB`"; then
|
||||||
|
as_fn_error $? "could not read System.map file, no read permission?" "$LINENO" 5
|
||||||
|
fi
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MCCTRL_LINUX_SYMTAB" >&5
|
||||||
|
$as_echo "$MCCTRL_LINUX_SYMTAB" >&6; }
|
||||||
|
|
||||||
|
MCCTRL_LINUX_SYMTAB_CMD="cat $MCCTRL_LINUX_SYMTAB"
|
||||||
|
|
||||||
|
# MCCTRL_FIND_KSYM(SYMBOL)
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Search System.map for address of the given symbol and
|
||||||
|
# do one of three things in config.h:
|
||||||
|
# If not found, leave MCCTRL_KSYM_foo undefined
|
||||||
|
# If found to be exported, "#define MCCTRL_KSYM_foo 0"
|
||||||
|
# If found not to be exported, "#define MCCTRL_KSYM_foo 0x<value>"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking System.map for symbol sys_mount" >&5
|
||||||
|
$as_echo_n "checking System.map for symbol sys_mount... " >&6; }
|
||||||
|
mcctrl_addr=`eval $MCCTRL_LINUX_SYMTAB_CMD | grep " sys_mount\$" | cut -d\ -f1`
|
||||||
|
if test -z $mcctrl_addr; then
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
|
||||||
|
$as_echo "not found" >&6; }
|
||||||
|
else
|
||||||
|
mcctrl_result=$mcctrl_addr
|
||||||
|
mcctrl_addr="0x$mcctrl_addr"
|
||||||
|
|
||||||
|
if `eval $MCCTRL_LINUX_SYMTAB_CMD | grep " __ksymtab_sys_mount\$" >/dev/null`; then
|
||||||
|
mcctrl_result="exported"
|
||||||
|
mcctrl_addr="0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $mcctrl_result" >&5
|
||||||
|
$as_echo "$mcctrl_result" >&6; }
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define MCCTRL_KSYM_sys_mount $mcctrl_addr
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking System.map for symbol sys_unshare" >&5
|
||||||
|
$as_echo_n "checking System.map for symbol sys_unshare... " >&6; }
|
||||||
|
mcctrl_addr=`eval $MCCTRL_LINUX_SYMTAB_CMD | grep " sys_unshare\$" | cut -d\ -f1`
|
||||||
|
if test -z $mcctrl_addr; then
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
|
||||||
|
$as_echo "not found" >&6; }
|
||||||
|
else
|
||||||
|
mcctrl_result=$mcctrl_addr
|
||||||
|
mcctrl_addr="0x$mcctrl_addr"
|
||||||
|
|
||||||
|
if `eval $MCCTRL_LINUX_SYMTAB_CMD | grep " __ksymtab_sys_unshare\$" >/dev/null`; then
|
||||||
|
mcctrl_result="exported"
|
||||||
|
mcctrl_addr="0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $mcctrl_result" >&5
|
||||||
|
$as_echo "$mcctrl_result" >&6; }
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define MCCTRL_KSYM_sys_unshare $mcctrl_addr
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -3816,6 +3918,10 @@ TARGET="$WITH_TARGET"
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ac_config_headers="$ac_config_headers executer/kernel/mcctrl/config.h"
|
||||||
|
|
||||||
ac_config_files="$ac_config_files Makefile executer/user/Makefile executer/kernel/mcctrl/Makefile executer/kernel/mcoverlayfs/Makefile kernel/Makefile kernel/Makefile.build arch/x86/tools/mcreboot-attached-mic.sh arch/x86/tools/mcshutdown-attached-mic.sh arch/x86/tools/mcreboot-builtin-x86.sh arch/x86/tools/mcreboot-smp-x86.sh arch/x86/tools/mcstop+release-smp-x86.sh arch/x86/tools/mcshutdown-builtin-x86.sh arch/x86/tools/mcreboot.1:arch/x86/tools/mcreboot.1in"
|
ac_config_files="$ac_config_files Makefile executer/user/Makefile executer/kernel/mcctrl/Makefile executer/kernel/mcoverlayfs/Makefile kernel/Makefile kernel/Makefile.build arch/x86/tools/mcreboot-attached-mic.sh arch/x86/tools/mcshutdown-attached-mic.sh arch/x86/tools/mcreboot-builtin-x86.sh arch/x86/tools/mcreboot-smp-x86.sh arch/x86/tools/mcstop+release-smp-x86.sh arch/x86/tools/mcshutdown-builtin-x86.sh arch/x86/tools/mcreboot.1:arch/x86/tools/mcreboot.1in"
|
||||||
|
|
||||||
|
|
||||||
@@ -3915,43 +4021,7 @@ test "x$prefix" = xNONE && prefix=$ac_default_prefix
|
|||||||
# Let make expand exec_prefix.
|
# Let make expand exec_prefix.
|
||||||
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
|
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
|
||||||
|
|
||||||
# Transform confdefs.h into DEFS.
|
DEFS=-DHAVE_CONFIG_H
|
||||||
# Protect against shell expansion while executing Makefile rules.
|
|
||||||
# Protect against Makefile macro expansion.
|
|
||||||
#
|
|
||||||
# If the first sed substitution is executed (which looks for macros that
|
|
||||||
# take arguments), then branch to the quote section. Otherwise,
|
|
||||||
# look for a macro that doesn't take arguments.
|
|
||||||
ac_script='
|
|
||||||
:mline
|
|
||||||
/\\$/{
|
|
||||||
N
|
|
||||||
s,\\\n,,
|
|
||||||
b mline
|
|
||||||
}
|
|
||||||
t clear
|
|
||||||
:clear
|
|
||||||
s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g
|
|
||||||
t quote
|
|
||||||
s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g
|
|
||||||
t quote
|
|
||||||
b any
|
|
||||||
:quote
|
|
||||||
s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g
|
|
||||||
s/\[/\\&/g
|
|
||||||
s/\]/\\&/g
|
|
||||||
s/\$/$$/g
|
|
||||||
H
|
|
||||||
:any
|
|
||||||
${
|
|
||||||
g
|
|
||||||
s/^\n//
|
|
||||||
s/\n/ /g
|
|
||||||
p
|
|
||||||
}
|
|
||||||
'
|
|
||||||
DEFS=`sed -n "$ac_script" confdefs.h`
|
|
||||||
|
|
||||||
|
|
||||||
ac_libobjs=
|
ac_libobjs=
|
||||||
ac_ltlibobjs=
|
ac_ltlibobjs=
|
||||||
@@ -4385,11 +4455,15 @@ case $ac_config_files in *"
|
|||||||
"*) set x $ac_config_files; shift; ac_config_files=$*;;
|
"*) set x $ac_config_files; shift; ac_config_files=$*;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
case $ac_config_headers in *"
|
||||||
|
"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||||
# Files that config.status was made for.
|
# Files that config.status was made for.
|
||||||
config_files="$ac_config_files"
|
config_files="$ac_config_files"
|
||||||
|
config_headers="$ac_config_headers"
|
||||||
|
|
||||||
_ACEOF
|
_ACEOF
|
||||||
|
|
||||||
@@ -4410,10 +4484,15 @@ Usage: $0 [OPTION]... [TAG]...
|
|||||||
--recheck update $as_me by reconfiguring in the same conditions
|
--recheck update $as_me by reconfiguring in the same conditions
|
||||||
--file=FILE[:TEMPLATE]
|
--file=FILE[:TEMPLATE]
|
||||||
instantiate the configuration file FILE
|
instantiate the configuration file FILE
|
||||||
|
--header=FILE[:TEMPLATE]
|
||||||
|
instantiate the configuration header FILE
|
||||||
|
|
||||||
Configuration files:
|
Configuration files:
|
||||||
$config_files
|
$config_files
|
||||||
|
|
||||||
|
Configuration headers:
|
||||||
|
$config_headers
|
||||||
|
|
||||||
Report bugs to the package provider."
|
Report bugs to the package provider."
|
||||||
|
|
||||||
_ACEOF
|
_ACEOF
|
||||||
@@ -4474,7 +4553,18 @@ do
|
|||||||
esac
|
esac
|
||||||
as_fn_append CONFIG_FILES " '$ac_optarg'"
|
as_fn_append CONFIG_FILES " '$ac_optarg'"
|
||||||
ac_need_defaults=false;;
|
ac_need_defaults=false;;
|
||||||
--he | --h | --help | --hel | -h )
|
--header | --heade | --head | --hea )
|
||||||
|
$ac_shift
|
||||||
|
case $ac_optarg in
|
||||||
|
*\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
|
||||||
|
esac
|
||||||
|
as_fn_append CONFIG_HEADERS " '$ac_optarg'"
|
||||||
|
ac_need_defaults=false;;
|
||||||
|
--he | --h)
|
||||||
|
# Conflict between --help and --header
|
||||||
|
as_fn_error $? "ambiguous option: \`$1'
|
||||||
|
Try \`$0 --help' for more information.";;
|
||||||
|
--help | --hel | -h )
|
||||||
$as_echo "$ac_cs_usage"; exit ;;
|
$as_echo "$ac_cs_usage"; exit ;;
|
||||||
-q | -quiet | --quiet | --quie | --qui | --qu | --q \
|
-q | -quiet | --quiet | --quie | --qui | --qu | --q \
|
||||||
| -silent | --silent | --silen | --sile | --sil | --si | --s)
|
| -silent | --silent | --silen | --sile | --sil | --si | --s)
|
||||||
@@ -4530,6 +4620,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
|||||||
for ac_config_target in $ac_config_targets
|
for ac_config_target in $ac_config_targets
|
||||||
do
|
do
|
||||||
case $ac_config_target in
|
case $ac_config_target in
|
||||||
|
"executer/kernel/mcctrl/config.h") CONFIG_HEADERS="$CONFIG_HEADERS executer/kernel/mcctrl/config.h" ;;
|
||||||
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
||||||
"executer/user/Makefile") CONFIG_FILES="$CONFIG_FILES executer/user/Makefile" ;;
|
"executer/user/Makefile") CONFIG_FILES="$CONFIG_FILES executer/user/Makefile" ;;
|
||||||
"executer/kernel/mcctrl/Makefile") CONFIG_FILES="$CONFIG_FILES executer/kernel/mcctrl/Makefile" ;;
|
"executer/kernel/mcctrl/Makefile") CONFIG_FILES="$CONFIG_FILES executer/kernel/mcctrl/Makefile" ;;
|
||||||
@@ -4556,6 +4647,7 @@ done
|
|||||||
# bizarre bug on SunOS 4.1.3.
|
# bizarre bug on SunOS 4.1.3.
|
||||||
if $ac_need_defaults; then
|
if $ac_need_defaults; then
|
||||||
test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
|
test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
|
||||||
|
test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Have a temporary directory for convenience. Make it in the build tree
|
# Have a temporary directory for convenience. Make it in the build tree
|
||||||
@@ -4743,8 +4835,116 @@ fi
|
|||||||
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||||
fi # test -n "$CONFIG_FILES"
|
fi # test -n "$CONFIG_FILES"
|
||||||
|
|
||||||
|
# Set up the scripts for CONFIG_HEADERS section.
|
||||||
|
# No need to generate them if there are no CONFIG_HEADERS.
|
||||||
|
# This happens for instance with `./config.status Makefile'.
|
||||||
|
if test -n "$CONFIG_HEADERS"; then
|
||||||
|
cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
|
||||||
|
BEGIN {
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
eval set X " :F $CONFIG_FILES "
|
# Transform confdefs.h into an awk script `defines.awk', embedded as
|
||||||
|
# here-document in config.status, that substitutes the proper values into
|
||||||
|
# config.h.in to produce config.h.
|
||||||
|
|
||||||
|
# Create a delimiter string that does not exist in confdefs.h, to ease
|
||||||
|
# handling of long lines.
|
||||||
|
ac_delim='%!_!# '
|
||||||
|
for ac_last_try in false false :; do
|
||||||
|
ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
|
||||||
|
if test -z "$ac_tt"; then
|
||||||
|
break
|
||||||
|
elif $ac_last_try; then
|
||||||
|
as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
|
||||||
|
else
|
||||||
|
ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# For the awk script, D is an array of macro values keyed by name,
|
||||||
|
# likewise P contains macro parameters if any. Preserve backslash
|
||||||
|
# newline sequences.
|
||||||
|
|
||||||
|
ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
|
||||||
|
sed -n '
|
||||||
|
s/.\{148\}/&'"$ac_delim"'/g
|
||||||
|
t rset
|
||||||
|
:rset
|
||||||
|
s/^[ ]*#[ ]*define[ ][ ]*/ /
|
||||||
|
t def
|
||||||
|
d
|
||||||
|
:def
|
||||||
|
s/\\$//
|
||||||
|
t bsnl
|
||||||
|
s/["\\]/\\&/g
|
||||||
|
s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
|
||||||
|
D["\1"]=" \3"/p
|
||||||
|
s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p
|
||||||
|
d
|
||||||
|
:bsnl
|
||||||
|
s/["\\]/\\&/g
|
||||||
|
s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
|
||||||
|
D["\1"]=" \3\\\\\\n"\\/p
|
||||||
|
t cont
|
||||||
|
s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
|
||||||
|
t cont
|
||||||
|
d
|
||||||
|
:cont
|
||||||
|
n
|
||||||
|
s/.\{148\}/&'"$ac_delim"'/g
|
||||||
|
t clear
|
||||||
|
:clear
|
||||||
|
s/\\$//
|
||||||
|
t bsnlc
|
||||||
|
s/["\\]/\\&/g; s/^/"/; s/$/"/p
|
||||||
|
d
|
||||||
|
:bsnlc
|
||||||
|
s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
|
||||||
|
b cont
|
||||||
|
' <confdefs.h | sed '
|
||||||
|
s/'"$ac_delim"'/"\\\
|
||||||
|
"/g' >>$CONFIG_STATUS || ac_write_fail=1
|
||||||
|
|
||||||
|
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||||
|
for (key in D) D_is_set[key] = 1
|
||||||
|
FS = ""
|
||||||
|
}
|
||||||
|
/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
|
||||||
|
line = \$ 0
|
||||||
|
split(line, arg, " ")
|
||||||
|
if (arg[1] == "#") {
|
||||||
|
defundef = arg[2]
|
||||||
|
mac1 = arg[3]
|
||||||
|
} else {
|
||||||
|
defundef = substr(arg[1], 2)
|
||||||
|
mac1 = arg[2]
|
||||||
|
}
|
||||||
|
split(mac1, mac2, "(") #)
|
||||||
|
macro = mac2[1]
|
||||||
|
prefix = substr(line, 1, index(line, defundef) - 1)
|
||||||
|
if (D_is_set[macro]) {
|
||||||
|
# Preserve the white space surrounding the "#".
|
||||||
|
print prefix "define", macro P[macro] D[macro]
|
||||||
|
next
|
||||||
|
} else {
|
||||||
|
# Replace #undef with comments. This is necessary, for example,
|
||||||
|
# in the case of _POSIX_SOURCE, which is predefined and required
|
||||||
|
# on some systems where configure will not decide to define it.
|
||||||
|
if (defundef == "undef") {
|
||||||
|
print "/*", prefix defundef, macro, "*/"
|
||||||
|
next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{ print }
|
||||||
|
_ACAWK
|
||||||
|
_ACEOF
|
||||||
|
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||||
|
as_fn_error $? "could not setup config headers machinery" "$LINENO" 5
|
||||||
|
fi # test -n "$CONFIG_HEADERS"
|
||||||
|
|
||||||
|
|
||||||
|
eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS "
|
||||||
shift
|
shift
|
||||||
for ac_tag
|
for ac_tag
|
||||||
do
|
do
|
||||||
@@ -4952,7 +5152,30 @@ which seems to be undefined. Please make sure it is defined" >&2;}
|
|||||||
esac \
|
esac \
|
||||||
|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
|
|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
|
||||||
;;
|
;;
|
||||||
|
:H)
|
||||||
|
#
|
||||||
|
# CONFIG_HEADER
|
||||||
|
#
|
||||||
|
if test x"$ac_file" != x-; then
|
||||||
|
{
|
||||||
|
$as_echo "/* $configure_input */" \
|
||||||
|
&& eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
|
||||||
|
} >"$ac_tmp/config.h" \
|
||||||
|
|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
|
||||||
|
if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
|
||||||
|
$as_echo "$as_me: $ac_file is unchanged" >&6;}
|
||||||
|
else
|
||||||
|
rm -f "$ac_file"
|
||||||
|
mv "$ac_tmp/config.h" "$ac_file" \
|
||||||
|
|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
$as_echo "/* $configure_input */" \
|
||||||
|
&& eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
|
||||||
|
|| as_fn_error $? "could not create -" "$LINENO" 5
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|||||||
65
configure.ac
65
configure.ac
@@ -27,6 +27,11 @@ AC_ARG_WITH([target],
|
|||||||
[--with-target={attached-mic | builtin-mic | builtin-x86 | smp-x86}],[target, default is attached-mic]),
|
[--with-target={attached-mic | builtin-mic | builtin-x86 | smp-x86}],[target, default is attached-mic]),
|
||||||
[WITH_TARGET=$withval],[WITH_TARGET=yes])
|
[WITH_TARGET=$withval],[WITH_TARGET=yes])
|
||||||
|
|
||||||
|
AC_ARG_WITH([system_map],
|
||||||
|
AS_HELP_STRING(
|
||||||
|
[--with-system_map=path],[Path to 'System.map file', default is /boot/System.map-uname_r]),
|
||||||
|
[WITH_SYSTEM_MAP=$withval],[WITH_SYSTEM_MAP=yes])
|
||||||
|
|
||||||
AC_ARG_ENABLE([dcfa],
|
AC_ARG_ENABLE([dcfa],
|
||||||
[AS_HELP_STRING(
|
[AS_HELP_STRING(
|
||||||
[--enable-dcfa],[Enable DCFA modules])],[],[enable_dcfa=no])
|
[--enable-dcfa],[Enable DCFA modules])],[],[enable_dcfa=no])
|
||||||
@@ -139,6 +144,65 @@ esac
|
|||||||
KDIR="$WITH_KERNELSRC"
|
KDIR="$WITH_KERNELSRC"
|
||||||
TARGET="$WITH_TARGET"
|
TARGET="$WITH_TARGET"
|
||||||
|
|
||||||
|
MCCTRL_LINUX_SYMTAB=""
|
||||||
|
case "X$WITH_SYSTEM_MAP" in
|
||||||
|
Xyes | Xno | X)
|
||||||
|
MCCTRL_LINUX_SYMTAB=""
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
MCCTRL_LINUX_SYMTAB="$WITH_SYSTEM_MAP"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([[for System.map]])
|
||||||
|
if test -f "$MCCTRL_LINUX_SYMTAB"; then
|
||||||
|
MCCTRL_LINUX_SYMTAB="$MCCTRL_LINUX_SYMTAB"
|
||||||
|
elif test -f "/boot/System.map-`uname -r`"; then
|
||||||
|
MCCTRL_LINUX_SYMTAB="/boot/System.map-`uname -r`"
|
||||||
|
elif test -f "$KDIR/System.map"; then
|
||||||
|
MCCTRL_LINUX_SYMTAB="$KDIR/System.map"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$MCCTRL_LINUX_SYMTAB" == ""; then
|
||||||
|
AC_MSG_ERROR([could not find])
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "`eval cat $MCCTRL_LINUX_SYMTAB`"; then
|
||||||
|
AC_MSG_ERROR([could not read System.map file, no read permission?])
|
||||||
|
fi
|
||||||
|
AC_MSG_RESULT([$MCCTRL_LINUX_SYMTAB])
|
||||||
|
|
||||||
|
MCCTRL_LINUX_SYMTAB_CMD="cat $MCCTRL_LINUX_SYMTAB"
|
||||||
|
|
||||||
|
# MCCTRL_FIND_KSYM(SYMBOL)
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Search System.map for address of the given symbol and
|
||||||
|
# do one of three things in config.h:
|
||||||
|
# If not found, leave MCCTRL_KSYM_foo undefined
|
||||||
|
# If found to be exported, "#define MCCTRL_KSYM_foo 0"
|
||||||
|
# If found not to be exported, "#define MCCTRL_KSYM_foo 0x<value>"
|
||||||
|
AC_DEFUN([MCCTRL_FIND_KSYM],[
|
||||||
|
AC_MSG_CHECKING([[System.map for symbol $1]])
|
||||||
|
mcctrl_addr=`eval $MCCTRL_LINUX_SYMTAB_CMD | grep " $1\$" | cut -d\ -f1`
|
||||||
|
if test -z $mcctrl_addr; then
|
||||||
|
AC_MSG_RESULT([not found])
|
||||||
|
else
|
||||||
|
mcctrl_result=$mcctrl_addr
|
||||||
|
mcctrl_addr="0x$mcctrl_addr"
|
||||||
|
m4_ifval([$2],[],[
|
||||||
|
if `eval $MCCTRL_LINUX_SYMTAB_CMD | grep " __ksymtab_$1\$" >/dev/null`; then
|
||||||
|
mcctrl_result="exported"
|
||||||
|
mcctrl_addr="0"
|
||||||
|
fi
|
||||||
|
])
|
||||||
|
AC_MSG_RESULT([$mcctrl_result])
|
||||||
|
AC_DEFINE_UNQUOTED(MCCTRL_KSYM_[]$1,$mcctrl_addr,[Define to address of kernel symbol $1, or 0 if exported])
|
||||||
|
fi
|
||||||
|
])
|
||||||
|
|
||||||
|
MCCTRL_FIND_KSYM([sys_mount])
|
||||||
|
MCCTRL_FIND_KSYM([sys_unshare])
|
||||||
|
|
||||||
AC_SUBST(CC)
|
AC_SUBST(CC)
|
||||||
AC_SUBST(XCC)
|
AC_SUBST(XCC)
|
||||||
AC_SUBST(ARCH)
|
AC_SUBST(ARCH)
|
||||||
@@ -157,6 +221,7 @@ AC_SUBST(IHK_RELEASE_DATE)
|
|||||||
AC_SUBST(MCKERNEL_RELEASE_DATE)
|
AC_SUBST(MCKERNEL_RELEASE_DATE)
|
||||||
AC_SUBST(DCFA_RESEASE_DATE)
|
AC_SUBST(DCFA_RESEASE_DATE)
|
||||||
|
|
||||||
|
AC_CONFIG_HEADERS([executer/kernel/mcctrl/config.h])
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
executer/user/Makefile
|
executer/user/Makefile
|
||||||
|
|||||||
@@ -48,6 +48,9 @@
|
|||||||
#define MCEXEC_UP_OPEN_EXEC 0x30a02912
|
#define MCEXEC_UP_OPEN_EXEC 0x30a02912
|
||||||
#define MCEXEC_UP_CLOSE_EXEC 0x30a02913
|
#define MCEXEC_UP_CLOSE_EXEC 0x30a02913
|
||||||
|
|
||||||
|
#define MCEXEC_UP_SYS_MOUNT 0x30a02914
|
||||||
|
#define MCEXEC_UP_SYS_UNSHARE 0x30a02915
|
||||||
|
|
||||||
#define MCEXEC_UP_DEBUG_LOG 0x40000000
|
#define MCEXEC_UP_DEBUG_LOG 0x40000000
|
||||||
|
|
||||||
#define MCEXEC_UP_TRANSFER_TO_REMOTE 0
|
#define MCEXEC_UP_TRANSFER_TO_REMOTE 0
|
||||||
@@ -167,4 +170,16 @@ struct newprocess_desc {
|
|||||||
int pid;
|
int pid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct sys_mount_desc {
|
||||||
|
char *dev_name;
|
||||||
|
char *dir_name;
|
||||||
|
char *type;
|
||||||
|
unsigned long flags;
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sys_unshare_desc {
|
||||||
|
unsigned long unshare_flags;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ IHK_BASE=$(src)/../../../../ihk
|
|||||||
|
|
||||||
obj-m += mcctrl.o
|
obj-m += mcctrl.o
|
||||||
|
|
||||||
ccflags-y := -I$(IHK_BASE)/linux/include -I$(IHK_BASE)/ikc/include -I$(IHK_BASE)/include -I$(src)/../../include -mcmodel=kernel -mno-red-zone -DMCEXEC_PATH=\"$(BINDIR)/mcexec\"
|
ccflags-y := -I$(IHK_BASE)/linux/include -I$(IHK_BASE)/ikc/include -I$(IHK_BASE)/include -I$(src)/../../include -mcmodel=kernel -mno-red-zone -DMCEXEC_PATH=\"$(BINDIR)/mcexec\" -I@abs_builddir@
|
||||||
|
|
||||||
mcctrl-y := driver.o control.o ikc.o syscall.o procfs.o binfmt_mcexec.o
|
mcctrl-y := driver.o control.o ikc.o syscall.o procfs.o binfmt_mcexec.o
|
||||||
mcctrl-y += sysfs.o sysfs_files.o
|
mcctrl-y += sysfs.o sysfs_files.o
|
||||||
|
|||||||
25
executer/kernel/mcctrl/config.h.in
Normal file
25
executer/kernel/mcctrl/config.h.in
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/* executer/kernel/mcctrl/config.h.in. Generated from configure.ac by autoheader. */
|
||||||
|
|
||||||
|
/* Define to address of kernel symbol sys_mount, or 0 if exported */
|
||||||
|
#undef MCCTRL_KSYM_sys_mount
|
||||||
|
|
||||||
|
/* Define to address of kernel symbol sys_unshare, or 0 if exported */
|
||||||
|
#undef MCCTRL_KSYM_sys_unshare
|
||||||
|
|
||||||
|
/* Define to the address where bug reports for this package should be sent. */
|
||||||
|
#undef PACKAGE_BUGREPORT
|
||||||
|
|
||||||
|
/* Define to the full name of this package. */
|
||||||
|
#undef PACKAGE_NAME
|
||||||
|
|
||||||
|
/* Define to the full name and version of this package. */
|
||||||
|
#undef PACKAGE_STRING
|
||||||
|
|
||||||
|
/* Define to the one symbol short name of this package. */
|
||||||
|
#undef PACKAGE_TARNAME
|
||||||
|
|
||||||
|
/* Define to the home page for this package. */
|
||||||
|
#undef PACKAGE_URL
|
||||||
|
|
||||||
|
/* Define to the version of this package. */
|
||||||
|
#undef PACKAGE_VERSION
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
#include <asm/delay.h>
|
#include <asm/delay.h>
|
||||||
#include <asm/msr.h>
|
#include <asm/msr.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
|
#include "config.h"
|
||||||
#include "mcctrl.h"
|
#include "mcctrl.h"
|
||||||
|
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
@@ -46,12 +47,31 @@
|
|||||||
#define dprintk(...)
|
#define dprintk(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MCCTRL_KSYM_sys_unshare
|
||||||
|
#if MCCTRL_KSYM_sys_unshare
|
||||||
|
typedef int (*int_star_fn_ulong_t)(unsigned long);
|
||||||
|
int (*mcctrl_sys_unshare)(unsigned long unshare_flags) =
|
||||||
|
(int_star_fn_ulong_t)
|
||||||
|
MCCTRL_KSYM_sys_unshare;
|
||||||
|
#else // exported
|
||||||
|
int (*mcctrl_sys_unshare)(unsigned long unshare_flags) = NULL;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MCCTRL_KSYM_sys_mount
|
||||||
|
#if MCCTRL_KSYM_sys_mount
|
||||||
|
typedef int (*int_star_fn_char_char_char_ulong_void_t)(char *, char *, char *, unsigned long, void *);
|
||||||
|
int (*mcctrl_sys_mount)(char *dev_name,char *dir_name, char *type, unsigned long flags, void *data) =
|
||||||
|
(int_star_fn_char_char_char_ulong_void_t)
|
||||||
|
MCCTRL_KSYM_sys_mount;
|
||||||
|
#else // exported
|
||||||
|
int (*mcctrl_sys_mount)(char *dev_name,char *dir_name, char *type, unsigned long flags, void *data) = NULL;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
//static DECLARE_WAIT_QUEUE_HEAD(wq_prepare);
|
//static DECLARE_WAIT_QUEUE_HEAD(wq_prepare);
|
||||||
//extern struct mcctrl_channel *channels;
|
//extern struct mcctrl_channel *channels;
|
||||||
int mcctrl_ikc_set_recv_cpu(ihk_os_t os, int cpu);
|
int mcctrl_ikc_set_recv_cpu(ihk_os_t os, int cpu);
|
||||||
extern int procfs_create_entry(void *os, int ref, int osnum, int pid, char *name,
|
|
||||||
int mode, void *opaque);
|
|
||||||
extern void procfs_delete_entry(void *os, int osnum, char *fname);
|
|
||||||
|
|
||||||
static long mcexec_prepare_image(ihk_os_t os,
|
static long mcexec_prepare_image(ihk_os_t os,
|
||||||
struct program_load_desc * __user udesc)
|
struct program_load_desc * __user udesc)
|
||||||
@@ -105,10 +125,10 @@ static long mcexec_prepare_image(ihk_os_t os,
|
|||||||
|
|
||||||
pdesc->args = (void*)virt_to_phys(args);
|
pdesc->args = (void*)virt_to_phys(args);
|
||||||
printk("args: 0x%lX\n", (unsigned long)pdesc->args);
|
printk("args: 0x%lX\n", (unsigned long)pdesc->args);
|
||||||
printk("argc: %d\n", *(int*)args);
|
printk("argc: %ld\n", *(long *)args);
|
||||||
pdesc->envs = (void*)virt_to_phys(envs);
|
pdesc->envs = (void*)virt_to_phys(envs);
|
||||||
printk("envs: 0x%lX\n", (unsigned long)pdesc->envs);
|
printk("envs: 0x%lX\n", (unsigned long)pdesc->envs);
|
||||||
printk("envc: %d\n", *(int*)envs);
|
printk("envc: %ld\n", *(long *)envs);
|
||||||
|
|
||||||
isp.msg = SCD_MSG_PREPARE_PROCESS;
|
isp.msg = SCD_MSG_PREPARE_PROCESS;
|
||||||
isp.ref = pdesc->cpu;
|
isp.ref = pdesc->cpu;
|
||||||
@@ -267,12 +287,15 @@ static void release_handler(ihk_os_t os, void *param)
|
|||||||
{
|
{
|
||||||
struct handlerinfo *info = param;
|
struct handlerinfo *info = param;
|
||||||
struct ikc_scd_packet isp;
|
struct ikc_scd_packet isp;
|
||||||
|
int os_ind = ihk_host_os_get_index(os);
|
||||||
|
|
||||||
memset(&isp, '\0', sizeof isp);
|
memset(&isp, '\0', sizeof isp);
|
||||||
isp.msg = SCD_MSG_CLEANUP_PROCESS;
|
isp.msg = SCD_MSG_CLEANUP_PROCESS;
|
||||||
isp.pid = info->pid;
|
isp.pid = info->pid;
|
||||||
|
|
||||||
mcctrl_ikc_send(os, 0, &isp);
|
mcctrl_ikc_send(os, 0, &isp);
|
||||||
|
if(os_ind >= 0)
|
||||||
|
delete_pid_entry(os_ind, info->pid);
|
||||||
kfree(param);
|
kfree(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -838,7 +861,7 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
|
|||||||
struct mckernel_exec_file *mcef_iter;
|
struct mckernel_exec_file *mcef_iter;
|
||||||
int retval;
|
int retval;
|
||||||
int os_ind = ihk_host_os_get_index(os);
|
int os_ind = ihk_host_os_get_index(os);
|
||||||
char *proc_name, *pathbuf, *fullpath;
|
char *pathbuf, *fullpath;
|
||||||
|
|
||||||
if (os_ind < 0) {
|
if (os_ind < 0) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@@ -849,12 +872,6 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
|
|||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
proc_name = kmalloc(PATH_MAX, GFP_TEMPORARY);
|
|
||||||
if (!proc_name) {
|
|
||||||
retval = ENOMEM;
|
|
||||||
goto out_error_free_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
file = open_exec(filename);
|
file = open_exec(filename);
|
||||||
retval = PTR_ERR(file);
|
retval = PTR_ERR(file);
|
||||||
if (IS_ERR(file)) {
|
if (IS_ERR(file)) {
|
||||||
@@ -873,8 +890,6 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
|
|||||||
goto out_put_file;
|
goto out_put_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(proc_name, 1024, "mcos%d/%d/exe", os_ind, current->tgid);
|
|
||||||
|
|
||||||
spin_lock_irq(&mckernel_exec_file_lock);
|
spin_lock_irq(&mckernel_exec_file_lock);
|
||||||
/* Find previous file (if exists) and drop it */
|
/* Find previous file (if exists) and drop it */
|
||||||
list_for_each_entry(mcef_iter, &mckernel_exec_files, list) {
|
list_for_each_entry(mcef_iter, &mckernel_exec_files, list) {
|
||||||
@@ -883,9 +898,6 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
|
|||||||
fput(mcef_iter->fp);
|
fput(mcef_iter->fp);
|
||||||
list_del(&mcef_iter->list);
|
list_del(&mcef_iter->list);
|
||||||
kfree(mcef_iter);
|
kfree(mcef_iter);
|
||||||
/* Drop old /proc/self/exe */
|
|
||||||
procfs_delete_entry(os, os_ind, proc_name);
|
|
||||||
dprintk("%d open_exec dropped previous executable \n", (int)current->tgid);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -897,15 +909,12 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
|
|||||||
list_add_tail(&mcef->list, &mckernel_exec_files);
|
list_add_tail(&mcef->list, &mckernel_exec_files);
|
||||||
|
|
||||||
/* Create /proc/self/exe entry */
|
/* Create /proc/self/exe entry */
|
||||||
if (procfs_create_entry(os, 0, os_ind, current->tgid, proc_name,
|
add_pid_entry(os_ind, current->tgid);
|
||||||
S_IFLNK, fullpath) != 0) {
|
proc_exe_link(os_ind, current->tgid, fullpath);
|
||||||
printk("ERROR: could not create a procfs entry for %s.\n", proc_name);
|
|
||||||
}
|
|
||||||
spin_unlock(&mckernel_exec_file_lock);
|
spin_unlock(&mckernel_exec_file_lock);
|
||||||
|
|
||||||
dprintk("%d open_exec and holding file: %s\n", (int)current->tgid, filename);
|
dprintk("%d open_exec and holding file: %s\n", (int)current->tgid, filename);
|
||||||
|
|
||||||
kfree(proc_name);
|
|
||||||
kfree(pathbuf);
|
kfree(pathbuf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -914,9 +923,6 @@ out_put_file:
|
|||||||
fput(file);
|
fput(file);
|
||||||
|
|
||||||
out_error_free:
|
out_error_free:
|
||||||
kfree(proc_name);
|
|
||||||
|
|
||||||
out_error_free_path:
|
|
||||||
kfree(pathbuf);
|
kfree(pathbuf);
|
||||||
return -retval;
|
return -retval;
|
||||||
}
|
}
|
||||||
@@ -927,7 +933,6 @@ int mcexec_close_exec(ihk_os_t os)
|
|||||||
struct mckernel_exec_file *mcef = NULL;
|
struct mckernel_exec_file *mcef = NULL;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
int os_ind = ihk_host_os_get_index(os);
|
int os_ind = ihk_host_os_get_index(os);
|
||||||
char proc_name[1024];
|
|
||||||
|
|
||||||
if (os_ind < 0) {
|
if (os_ind < 0) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@@ -946,14 +951,6 @@ int mcexec_close_exec(ihk_os_t os)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove /proc/self/exe and /proc/self directory
|
|
||||||
* TODO: instead of removing directory explicitly, detect in procfs_delete_entry()
|
|
||||||
* when a directory becomes empty and remove it automatically */
|
|
||||||
snprintf(proc_name, 1024, "mcos%d/%d/exe", os_ind, current->tgid);
|
|
||||||
procfs_delete_entry(os, os_ind, proc_name);
|
|
||||||
snprintf(proc_name, 1024, "mcos%d/%d", os_ind, current->tgid);
|
|
||||||
procfs_delete_entry(os, os_ind, proc_name);
|
|
||||||
|
|
||||||
spin_unlock(&mckernel_exec_file_lock);
|
spin_unlock(&mckernel_exec_file_lock);
|
||||||
|
|
||||||
return (found ? 0 : EINVAL);
|
return (found ? 0 : EINVAL);
|
||||||
@@ -1011,6 +1008,67 @@ long mcexec_strncpy_from_user(ihk_os_t os, struct strncpy_from_user_desc * __use
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long mcexec_sys_mount(struct sys_mount_desc *__user arg)
|
||||||
|
{
|
||||||
|
struct sys_mount_desc desc;
|
||||||
|
struct cred *promoted;
|
||||||
|
const struct cred *original;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (copy_from_user(&desc, arg, sizeof(desc))) {
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
promoted = prepare_creds();
|
||||||
|
if (!promoted) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
cap_raise(promoted->cap_effective, CAP_SYS_ADMIN);
|
||||||
|
original = override_creds(promoted);
|
||||||
|
|
||||||
|
#if MCCTRL_KSYM_sys_mount
|
||||||
|
ret = mcctrl_sys_mount(desc.dev_name, desc.dir_name, desc.type,
|
||||||
|
desc.flags, desc.data);
|
||||||
|
#else
|
||||||
|
ret = -EFAULT;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
revert_creds(original);
|
||||||
|
put_cred(promoted);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
long mcexec_sys_unshare(struct sys_unshare_desc *__user arg)
|
||||||
|
{
|
||||||
|
struct sys_unshare_desc desc;
|
||||||
|
struct cred *promoted;
|
||||||
|
const struct cred *original;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (copy_from_user(&desc, arg, sizeof(desc))) {
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
promoted = prepare_creds();
|
||||||
|
if (!promoted) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
cap_raise(promoted->cap_effective, CAP_SYS_ADMIN);
|
||||||
|
original = override_creds(promoted);
|
||||||
|
|
||||||
|
#if MCCTRL_KSYM_sys_unshare
|
||||||
|
ret = mcctrl_sys_unshare(desc.unshare_flags);
|
||||||
|
#else
|
||||||
|
ret = -EFAULT;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
revert_creds(original);
|
||||||
|
put_cred(promoted);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
long __mcctrl_control(ihk_os_t os, unsigned int req, unsigned long arg,
|
long __mcctrl_control(ihk_os_t os, unsigned int req, unsigned long arg,
|
||||||
struct file *file)
|
struct file *file)
|
||||||
{
|
{
|
||||||
@@ -1065,6 +1123,12 @@ long __mcctrl_control(ihk_os_t os, unsigned int req, unsigned long arg,
|
|||||||
case MCEXEC_UP_GET_CREDV:
|
case MCEXEC_UP_GET_CREDV:
|
||||||
return mcexec_getcredv((int *)arg);
|
return mcexec_getcredv((int *)arg);
|
||||||
|
|
||||||
|
case MCEXEC_UP_SYS_MOUNT:
|
||||||
|
return mcexec_sys_mount((struct sys_mount_desc *)arg);
|
||||||
|
|
||||||
|
case MCEXEC_UP_SYS_UNSHARE:
|
||||||
|
return mcexec_sys_unshare((struct sys_unshare_desc *)arg);
|
||||||
|
|
||||||
case MCEXEC_UP_DEBUG_LOG:
|
case MCEXEC_UP_DEBUG_LOG:
|
||||||
return mcexec_debug_log(os, arg);
|
return mcexec_debug_log(os, arg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ static struct ihk_os_user_call_handler mcctrl_uchs[] = {
|
|||||||
{ .request = MCEXEC_UP_CLOSE_EXEC, .func = mcctrl_ioctl },
|
{ .request = MCEXEC_UP_CLOSE_EXEC, .func = mcctrl_ioctl },
|
||||||
{ .request = MCEXEC_UP_GET_CRED, .func = mcctrl_ioctl },
|
{ .request = MCEXEC_UP_GET_CRED, .func = mcctrl_ioctl },
|
||||||
{ .request = MCEXEC_UP_GET_CREDV, .func = mcctrl_ioctl },
|
{ .request = MCEXEC_UP_GET_CREDV, .func = mcctrl_ioctl },
|
||||||
|
{ .request = MCEXEC_UP_SYS_MOUNT, .func = mcctrl_ioctl },
|
||||||
|
{ .request = MCEXEC_UP_SYS_UNSHARE, .func = mcctrl_ioctl },
|
||||||
{ .request = MCEXEC_UP_DEBUG_LOG, .func = mcctrl_ioctl },
|
{ .request = MCEXEC_UP_DEBUG_LOG, .func = mcctrl_ioctl },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,6 +82,12 @@ static struct ihk_os_user_call mcctrl_uc[OS_MAX_MINOR];
|
|||||||
|
|
||||||
static ihk_os_t os[OS_MAX_MINOR];
|
static ihk_os_t os[OS_MAX_MINOR];
|
||||||
|
|
||||||
|
ihk_os_t
|
||||||
|
osnum_to_os(int n)
|
||||||
|
{
|
||||||
|
return os[n];
|
||||||
|
}
|
||||||
|
|
||||||
static int __init mcctrl_init(void)
|
static int __init mcctrl_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@@ -41,9 +41,6 @@
|
|||||||
void mcexec_prepare_ack(ihk_os_t os, unsigned long arg, int err);
|
void mcexec_prepare_ack(ihk_os_t os, unsigned long arg, int err);
|
||||||
static void mcctrl_ikc_init(ihk_os_t os, int cpu, unsigned long rphys, struct ihk_ikc_channel_desc *c);
|
static void mcctrl_ikc_init(ihk_os_t os, int cpu, unsigned long rphys, struct ihk_ikc_channel_desc *c);
|
||||||
int mcexec_syscall(struct mcctrl_channel *c, int pid, unsigned long arg);
|
int mcexec_syscall(struct mcctrl_channel *c, int pid, unsigned long arg);
|
||||||
void procfs_create(void *__os, int ref, int osnum, int pid, unsigned long arg);
|
|
||||||
void procfs_delete(void *__os, int osnum, unsigned long arg);
|
|
||||||
void procfs_answer(unsigned long arg, int err);
|
|
||||||
void sig_done(unsigned long arg, int err);
|
void sig_done(unsigned long arg, int err);
|
||||||
|
|
||||||
static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||||
@@ -69,14 +66,6 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
|||||||
mcexec_syscall(usrdata->channels + pisp->ref, pisp->pid, pisp->arg);
|
mcexec_syscall(usrdata->channels + pisp->ref, pisp->pid, pisp->arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCD_MSG_PROCFS_CREATE:
|
|
||||||
procfs_create(__os, pisp->ref, pisp->osnum, pisp->pid, pisp->arg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCD_MSG_PROCFS_DELETE:
|
|
||||||
procfs_delete(__os, pisp->osnum, pisp->arg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCD_MSG_PROCFS_ANSWER:
|
case SCD_MSG_PROCFS_ANSWER:
|
||||||
procfs_answer(pisp->arg, pisp->err);
|
procfs_answer(pisp->arg, pisp->err);
|
||||||
break;
|
break;
|
||||||
@@ -98,6 +87,14 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
|||||||
pisp->sysfs_arg1, pisp->sysfs_arg2);
|
pisp->sysfs_arg1, pisp->sysfs_arg2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SCD_MSG_PROCFS_TID_CREATE:
|
||||||
|
add_tid_entry(ihk_host_os_get_index(__os), pisp->pid, pisp->arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCD_MSG_PROCFS_TID_DELETE:
|
||||||
|
delete_tid_entry(ihk_host_os_get_index(__os), pisp->pid, pisp->arg);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printk(KERN_ERR "mcctrl:syscall_packet_handler:"
|
printk(KERN_ERR "mcctrl:syscall_packet_handler:"
|
||||||
"unknown message (%d.%d.%d.%d.%d.%#lx)\n",
|
"unknown message (%d.%d.%d.%d.%d.%#lx)\n",
|
||||||
|
|||||||
@@ -81,6 +81,8 @@
|
|||||||
#define SCD_MSG_SYSFS_RESP_SETUP 0x41
|
#define SCD_MSG_SYSFS_RESP_SETUP 0x41
|
||||||
/* #define SCD_MSG_SYSFS_REQ_CLEANUP 0x42 */
|
/* #define SCD_MSG_SYSFS_REQ_CLEANUP 0x42 */
|
||||||
/* #define SCD_MSG_SYSFS_RESP_CLEANUP 0x43 */
|
/* #define SCD_MSG_SYSFS_RESP_CLEANUP 0x43 */
|
||||||
|
#define SCD_MSG_PROCFS_TID_CREATE 0x44
|
||||||
|
#define SCD_MSG_PROCFS_TID_DELETE 0x45
|
||||||
|
|
||||||
#define DMA_PIN_SHIFT 21
|
#define DMA_PIN_SHIFT 21
|
||||||
|
|
||||||
@@ -226,6 +228,8 @@ int mcctrl_ikc_is_valid_thread(ihk_os_t os, int cpu);
|
|||||||
int reserve_user_space(struct mcctrl_usrdata *usrdata, unsigned long *startp,
|
int reserve_user_space(struct mcctrl_usrdata *usrdata, unsigned long *startp,
|
||||||
unsigned long *endp);
|
unsigned long *endp);
|
||||||
|
|
||||||
|
ihk_os_t osnum_to_os(int n);
|
||||||
|
|
||||||
/* syscall.c */
|
/* syscall.c */
|
||||||
int init_peer_channel_registry(struct mcctrl_usrdata *ud);
|
int init_peer_channel_registry(struct mcctrl_usrdata *ud);
|
||||||
void destroy_peer_channel_registry(struct mcctrl_usrdata *ud);
|
void destroy_peer_channel_registry(struct mcctrl_usrdata *ud);
|
||||||
@@ -244,6 +248,7 @@ struct procfs_read {
|
|||||||
int ret; /* read bytes (answer) */
|
int ret; /* read bytes (answer) */
|
||||||
int status; /* non-zero if done (answer) */
|
int status; /* non-zero if done (answer) */
|
||||||
int newcpu; /* migrated new cpu (answer) */
|
int newcpu; /* migrated new cpu (answer) */
|
||||||
|
int readwrite; /* 0:read, 1:write */
|
||||||
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -253,6 +258,15 @@ struct procfs_file {
|
|||||||
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void procfs_answer(unsigned int arg, int err);
|
||||||
|
void add_tid_entry(int osnum, int pid, int tid);
|
||||||
|
void add_pid_entry(int osnum, int pid);
|
||||||
|
void delete_tid_entry(int osnum, int pid, int tid);
|
||||||
|
void delete_pid_entry(int osnum, int pid);
|
||||||
|
void proc_exe_link(int osnum, int pid, const char *path);
|
||||||
|
void procfs_init(int osnum);
|
||||||
|
void procfs_exit(int osnum);
|
||||||
|
|
||||||
/* sysfs_files.c */
|
/* sysfs_files.c */
|
||||||
void setup_sysfs_files(ihk_os_t os);
|
void setup_sysfs_files(ihk_os_t os);
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
|||||||
CC=@CC@
|
CC=@CC@
|
||||||
BINDIR=@BINDIR@
|
BINDIR=@BINDIR@
|
||||||
|
KDIR ?= @KDIR@
|
||||||
CFLAGS=-Wall -O -fPIE -pie
|
CFLAGS=-Wall -O -fPIE -pie
|
||||||
VPATH=@abs_srcdir@
|
VPATH=@abs_srcdir@
|
||||||
TARGET=mcexec
|
TARGET=mcexec
|
||||||
@@ -7,7 +8,7 @@ TARGET=mcexec
|
|||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
mcexec: mcexec.c
|
mcexec: mcexec.c
|
||||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -pthread -o $@ $^ $(EXTRA_OBJS)
|
$(CC) -I${KDIR} $(CFLAGS) $(EXTRA_CFLAGS) -pthread -o $@ $^ $(EXTRA_OBJS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(TARGET) *.o
|
$(RM) $(TARGET) *.o
|
||||||
@@ -16,5 +17,5 @@ clean:
|
|||||||
|
|
||||||
install:
|
install:
|
||||||
mkdir -p -m 755 $(BINDIR)
|
mkdir -p -m 755 $(BINDIR)
|
||||||
install -o root -m 4755 mcexec $(BINDIR)
|
install -m 755 mcexec $(BINDIR)
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <linux/version.h>
|
#include <include/generated/uapi/linux/version.h>
|
||||||
#include "../include/uprotocol.h"
|
#include "../include/uprotocol.h"
|
||||||
|
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
@@ -185,7 +185,8 @@ struct program_load_desc *load_elf(FILE *fp, char **interp_pathp)
|
|||||||
|
|
||||||
desc = malloc(sizeof(struct program_load_desc)
|
desc = malloc(sizeof(struct program_load_desc)
|
||||||
+ sizeof(struct program_image_section) * nhdrs);
|
+ sizeof(struct program_image_section) * nhdrs);
|
||||||
memset(desc, '\0', sizeof(struct program_load_desc));
|
memset(desc, '\0', sizeof(struct program_load_desc)
|
||||||
|
+ sizeof(struct program_image_section) * nhdrs);
|
||||||
desc->shell_path[0] = '\0';
|
desc->shell_path[0] = '\0';
|
||||||
fseek(fp, hdr.e_phoff, SEEK_SET);
|
fseek(fp, hdr.e_phoff, SEEK_SET);
|
||||||
j = 0;
|
j = 0;
|
||||||
@@ -673,6 +674,7 @@ void transfer_image(int fd, struct program_load_desc *desc)
|
|||||||
desc->sections[i].offset, flen);
|
desc->sections[i].offset, flen);
|
||||||
|
|
||||||
while (s < e) {
|
while (s < e) {
|
||||||
|
memset(&pt, '\0', sizeof pt);
|
||||||
pt.rphys = rpa;
|
pt.rphys = rpa;
|
||||||
pt.userp = dma_buf;
|
pt.userp = dma_buf;
|
||||||
pt.size = PAGE_SIZE;
|
pt.size = PAGE_SIZE;
|
||||||
@@ -776,7 +778,7 @@ int flatten_strings(int nr_strings, char *first, char **strings, char **flat)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Count full length */
|
/* Count full length */
|
||||||
full_len = sizeof(int) + sizeof(char *); // Counter and terminating NULL
|
full_len = sizeof(long) + sizeof(char *); // Counter and terminating NULL
|
||||||
if (first) {
|
if (first) {
|
||||||
full_len += sizeof(char *) + strlen(first) + 1;
|
full_len += sizeof(char *) + strlen(first) + 1;
|
||||||
}
|
}
|
||||||
@@ -786,6 +788,8 @@ int flatten_strings(int nr_strings, char *first, char **strings, char **flat)
|
|||||||
full_len += sizeof(char *) + strlen(strings[string_i]) + 1;
|
full_len += sizeof(char *) + strlen(strings[string_i]) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
full_len = (full_len + sizeof(long) - 1) & ~(sizeof(long) - 1);
|
||||||
|
|
||||||
_flat = (char *)malloc(full_len);
|
_flat = (char *)malloc(full_len);
|
||||||
if (!_flat) {
|
if (!_flat) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -794,14 +798,14 @@ int flatten_strings(int nr_strings, char *first, char **strings, char **flat)
|
|||||||
memset(_flat, 0, full_len);
|
memset(_flat, 0, full_len);
|
||||||
|
|
||||||
/* Number of strings */
|
/* Number of strings */
|
||||||
*((int*)_flat) = nr_strings + (first ? 1 : 0);
|
*((long *)_flat) = nr_strings + (first ? 1 : 0);
|
||||||
|
|
||||||
// Actual offset
|
// Actual offset
|
||||||
flat_offset = sizeof(int) + sizeof(char *) * (nr_strings + 1 +
|
flat_offset = sizeof(long) + sizeof(char *) * (nr_strings + 1 +
|
||||||
(first ? 1 : 0));
|
(first ? 1 : 0));
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
*((char **)(_flat + sizeof(int))) = (void *)flat_offset;
|
*((char **)(_flat + sizeof(long))) = (void *)flat_offset;
|
||||||
memcpy(_flat + flat_offset, first, strlen(first) + 1);
|
memcpy(_flat + flat_offset, first, strlen(first) + 1);
|
||||||
flat_offset += strlen(first) + 1;
|
flat_offset += strlen(first) + 1;
|
||||||
}
|
}
|
||||||
@@ -809,7 +813,7 @@ int flatten_strings(int nr_strings, char *first, char **strings, char **flat)
|
|||||||
for (string_i = 0; string_i < nr_strings; ++string_i) {
|
for (string_i = 0; string_i < nr_strings; ++string_i) {
|
||||||
|
|
||||||
/* Fabricate the string */
|
/* Fabricate the string */
|
||||||
*((char **)(_flat + sizeof(int) + (string_i + (first ? 1 : 0))
|
*((char **)(_flat + sizeof(long) + (string_i + (first ? 1 : 0))
|
||||||
* sizeof(char *))) = (void *)flat_offset;
|
* sizeof(char *))) = (void *)flat_offset;
|
||||||
memcpy(_flat + flat_offset, strings[string_i], strlen(strings[string_i]) + 1);
|
memcpy(_flat + flat_offset, strings[string_i], strlen(strings[string_i]) + 1);
|
||||||
flat_offset += strlen(strings[string_i]) + 1;
|
flat_offset += strlen(strings[string_i]) + 1;
|
||||||
@@ -892,6 +896,7 @@ sendsig(int sig, siginfo_t *siginfo, void *context)
|
|||||||
remote_tid = -1;
|
remote_tid = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(&sigdesc, '\0', sizeof sigdesc);
|
||||||
sigdesc.cpu = cpu;
|
sigdesc.cpu = cpu;
|
||||||
sigdesc.pid = (int)pid;
|
sigdesc.pid = (int)pid;
|
||||||
sigdesc.tid = remote_tid;
|
sigdesc.tid = remote_tid;
|
||||||
@@ -918,6 +923,7 @@ act_signalfd4(struct syscall_wait_desc *w)
|
|||||||
switch(mode){
|
switch(mode){
|
||||||
case 0: /* new signalfd */
|
case 0: /* new signalfd */
|
||||||
sfd = malloc(sizeof(struct sigfd));
|
sfd = malloc(sizeof(struct sigfd));
|
||||||
|
memset(sfd, '\0', sizeof(struct sigfd));
|
||||||
tmp = w->sr.args[1];
|
tmp = w->sr.args[1];
|
||||||
flags = 0;
|
flags = 0;
|
||||||
if(tmp & SFD_NONBLOCK)
|
if(tmp & SFD_NONBLOCK)
|
||||||
@@ -1301,39 +1307,6 @@ int main(int argc, char **argv)
|
|||||||
++optind;
|
++optind;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0)
|
|
||||||
__dprintf("mcoverlay enable\n");
|
|
||||||
char mcos_procdir[PATH_MAX];
|
|
||||||
|
|
||||||
error = isunshare();
|
|
||||||
if (error == 0) {
|
|
||||||
if (unshare(CLONE_NEWNS)) {
|
|
||||||
fprintf(stderr, "Error: Failed to unshare. (%s)\n",
|
|
||||||
strerror(errno));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(mcos_procdir, "/tmp/mcos/mcos%d_proc", mcosid);
|
|
||||||
if (mount(mcos_procdir, "/proc", NULL, MS_BIND, NULL)) {
|
|
||||||
fprintf(stderr, "Error: Failed to mount. (%s)\n",
|
|
||||||
strerror(errno));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} else if (error == -1) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
__dprintf("mcoverlay disable\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
__dprintf("before seteuid(): uid=%d, euid=%d\n", getuid(), geteuid());
|
|
||||||
if (seteuid(getuid())) {
|
|
||||||
fprintf(stderr, "Error: Failed to seteuid. (%s)\n",
|
|
||||||
strerror(errno));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
__dprintf("after seteuid(): uid=%d, euid=%d\n", getuid(), geteuid());
|
|
||||||
|
|
||||||
sprintf(dev, "/dev/mcos%d", mcosid);
|
sprintf(dev, "/dev/mcos%d", mcosid);
|
||||||
|
|
||||||
/* No more arguments? */
|
/* No more arguments? */
|
||||||
@@ -1355,6 +1328,58 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0)
|
||||||
|
__dprintf("mcoverlay enable\n");
|
||||||
|
char mcos_procdir[PATH_MAX];
|
||||||
|
char mcos_sysdir[PATH_MAX];
|
||||||
|
|
||||||
|
error = isunshare();
|
||||||
|
if (error == 0) {
|
||||||
|
struct sys_unshare_desc unshare_desc;
|
||||||
|
struct sys_mount_desc mount_desc;
|
||||||
|
|
||||||
|
memset(&unshare_desc, '\0', sizeof unshare_desc);
|
||||||
|
memset(&mount_desc, '\0', sizeof mount_desc);
|
||||||
|
unshare_desc.unshare_flags = CLONE_NEWNS;
|
||||||
|
if (ioctl(fd, MCEXEC_UP_SYS_UNSHARE,
|
||||||
|
(unsigned long)&unshare_desc) != 0) {
|
||||||
|
fprintf(stderr, "Error: Failed to unshare. (%s)\n",
|
||||||
|
strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(mcos_procdir, "/tmp/mcos/mcos%d_proc", mcosid);
|
||||||
|
mount_desc.dev_name = mcos_procdir;
|
||||||
|
mount_desc.dir_name = "/proc";
|
||||||
|
mount_desc.type = NULL;
|
||||||
|
mount_desc.flags = MS_BIND;
|
||||||
|
mount_desc.data = NULL;
|
||||||
|
if (ioctl(fd, MCEXEC_UP_SYS_MOUNT,
|
||||||
|
(unsigned long)&mount_desc) != 0) {
|
||||||
|
fprintf(stderr, "Error: Failed to mount /proc. (%s)\n",
|
||||||
|
strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(mcos_sysdir, "/tmp/mcos/mcos%d_sys", mcosid);
|
||||||
|
mount_desc.dev_name = mcos_sysdir;
|
||||||
|
mount_desc.dir_name = "/sys";
|
||||||
|
mount_desc.type = NULL;
|
||||||
|
mount_desc.flags = MS_BIND;
|
||||||
|
mount_desc.data = NULL;
|
||||||
|
if (ioctl(fd, MCEXEC_UP_SYS_MOUNT,
|
||||||
|
(unsigned long)&mount_desc) != 0) {
|
||||||
|
fprintf(stderr, "Error: Failed to mount /sys. (%s)\n",
|
||||||
|
strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else if (error == -1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
__dprintf("mcoverlay disable\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (lookup_exec_path(argv[optind], path, sizeof(path)) != 0) {
|
if (lookup_exec_path(argv[optind], path, sizeof(path)) != 0) {
|
||||||
fprintf(stderr, "error: finding file: %s\n", argv[optind]);
|
fprintf(stderr, "error: finding file: %s\n", argv[optind]);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -1522,6 +1547,7 @@ void do_syscall_return(int fd, int cpu,
|
|||||||
{
|
{
|
||||||
struct syscall_ret_desc desc;
|
struct syscall_ret_desc desc;
|
||||||
|
|
||||||
|
memset(&desc, '\0', sizeof desc);
|
||||||
desc.cpu = cpu;
|
desc.cpu = cpu;
|
||||||
desc.ret = ret;
|
desc.ret = ret;
|
||||||
desc.src = src;
|
desc.src = src;
|
||||||
@@ -1538,6 +1564,7 @@ void do_syscall_load(int fd, int cpu, unsigned long dest, unsigned long src,
|
|||||||
{
|
{
|
||||||
struct syscall_load_desc desc;
|
struct syscall_load_desc desc;
|
||||||
|
|
||||||
|
memset(&desc, '\0', sizeof desc);
|
||||||
desc.cpu = cpu;
|
desc.cpu = cpu;
|
||||||
desc.src = src;
|
desc.src = src;
|
||||||
desc.dest = dest;
|
desc.dest = dest;
|
||||||
@@ -1587,6 +1614,7 @@ static long do_strncpy_from_user(int fd, void *dest, void *src, unsigned long n)
|
|||||||
struct strncpy_from_user_desc desc;
|
struct strncpy_from_user_desc desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
memset(&desc, '\0', sizeof desc);
|
||||||
desc.dest = dest;
|
desc.dest = dest;
|
||||||
desc.src = src;
|
desc.src = src;
|
||||||
desc.n = n;
|
desc.n = n;
|
||||||
@@ -1718,6 +1746,7 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
|
|||||||
char pathbuf[PATH_MAX];
|
char pathbuf[PATH_MAX];
|
||||||
char tmpbuf[PATH_MAX];
|
char tmpbuf[PATH_MAX];
|
||||||
|
|
||||||
|
memset(&w, '\0', sizeof w);
|
||||||
w.cpu = cpu;
|
w.cpu = cpu;
|
||||||
w.pid = getpid();
|
w.pid = getpid();
|
||||||
|
|
||||||
@@ -2140,6 +2169,7 @@ return_execve1:
|
|||||||
fprintf(stderr, "execve(): error allocating desc\n");
|
fprintf(stderr, "execve(): error allocating desc\n");
|
||||||
goto return_execve2;
|
goto return_execve2;
|
||||||
}
|
}
|
||||||
|
memset(desc, '\0', w.sr.args[2]);
|
||||||
|
|
||||||
/* Copy descriptor from co-kernel side */
|
/* Copy descriptor from co-kernel side */
|
||||||
trans.userp = (void*)desc;
|
trans.userp = (void*)desc;
|
||||||
@@ -2182,6 +2212,11 @@ return_execve2:
|
|||||||
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case __NR_perf_event_open:
|
||||||
|
ret = open("/dev/null", O_RDONLY);
|
||||||
|
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
case __NR_rt_sigaction:
|
case __NR_rt_sigaction:
|
||||||
act_sigaction(&w);
|
act_sigaction(&w);
|
||||||
do_syscall_return(fd, cpu, 0, 0, 0, 0, 0);
|
do_syscall_return(fd, cpu, 0, 0, 0, 0, 0);
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ int prepare_process_ranges_args_envs(struct thread *thread,
|
|||||||
p->args_len = args_len;
|
p->args_len = args_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
dkprintf("args copy, nr: %d\n", *((int*)args_envs_r));
|
dkprintf("args copy, nr: %d\n", *((long *)args_envs_r));
|
||||||
|
|
||||||
memcpy_long(args_envs, args_envs_r, p->args_len + sizeof(long) - 1);
|
memcpy_long(args_envs, args_envs_r, p->args_len + sizeof(long) - 1);
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ int prepare_process_ranges_args_envs(struct thread *thread,
|
|||||||
p->envs_len = envs_len;
|
p->envs_len = envs_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
dkprintf("envs copy, nr: %d\n", *((int*)args_envs_r));
|
dkprintf("envs copy, nr: %d\n", *((long *)args_envs_r));
|
||||||
|
|
||||||
memcpy_long(args_envs + p->args_len, args_envs_r, p->envs_len + sizeof(long) - 1);
|
memcpy_long(args_envs + p->args_len, args_envs_r, p->envs_len + sizeof(long) - 1);
|
||||||
|
|
||||||
@@ -289,10 +289,10 @@ int prepare_process_ranges_args_envs(struct thread *thread,
|
|||||||
flush_tlb();
|
flush_tlb();
|
||||||
|
|
||||||
// Update variables
|
// Update variables
|
||||||
argc = *((int*)(args_envs));
|
argc = *((long *)(args_envs));
|
||||||
dkprintf("argc: %d\n", argc);
|
dkprintf("argc: %d\n", argc);
|
||||||
|
|
||||||
argv = (char **)(args_envs + (sizeof(int)));
|
argv = (char **)(args_envs + (sizeof(long)));
|
||||||
if(proc->saved_cmdline){
|
if(proc->saved_cmdline){
|
||||||
kfree(proc->saved_cmdline);
|
kfree(proc->saved_cmdline);
|
||||||
proc->saved_cmdline_len = 0;
|
proc->saved_cmdline_len = 0;
|
||||||
@@ -309,17 +309,17 @@ int prepare_process_ranges_args_envs(struct thread *thread,
|
|||||||
*a = (char *)addr + (unsigned long)*a; // Process' address space!
|
*a = (char *)addr + (unsigned long)*a; // Process' address space!
|
||||||
}
|
}
|
||||||
|
|
||||||
envc = *((int*)(args_envs + p->args_len));
|
envc = *((long *)(args_envs + p->args_len));
|
||||||
dkprintf("envc: %d\n", envc);
|
dkprintf("envc: %d\n", envc);
|
||||||
|
|
||||||
env = (char **)(args_envs + p->args_len + sizeof(int));
|
env = (char **)(args_envs + p->args_len + sizeof(long));
|
||||||
while (*env) {
|
while (*env) {
|
||||||
char **_env = env;
|
char **_env = env;
|
||||||
//dkprintf("%s\n", args_envs + p->args_len + (unsigned long)*env);
|
//dkprintf("%s\n", args_envs + p->args_len + (unsigned long)*env);
|
||||||
*env = (char *)addr + p->args_len + (unsigned long)*env;
|
*env = (char *)addr + p->args_len + (unsigned long)*env;
|
||||||
env = ++_env;
|
env = ++_env;
|
||||||
}
|
}
|
||||||
env = (char **)(args_envs + p->args_len + sizeof(int));
|
env = (char **)(args_envs + p->args_len + sizeof(long));
|
||||||
|
|
||||||
dkprintf("env OK\n");
|
dkprintf("env OK\n");
|
||||||
|
|
||||||
@@ -449,7 +449,7 @@ static void process_msg_init(struct ikc_scd_init_param *pcp, struct syscall_para
|
|||||||
|
|
||||||
static void process_msg_init_acked(struct ihk_ikc_channel_desc *c, unsigned long pphys)
|
static void process_msg_init_acked(struct ihk_ikc_channel_desc *c, unsigned long pphys)
|
||||||
{
|
{
|
||||||
struct ikc_scd_init_param *param = (void *)pphys;
|
struct ikc_scd_init_param *param = phys_to_virt(pphys);
|
||||||
struct syscall_params *lparam;
|
struct syscall_params *lparam;
|
||||||
enum ihk_mc_pt_attribute attr;
|
enum ihk_mc_pt_attribute attr;
|
||||||
|
|
||||||
|
|||||||
@@ -312,18 +312,22 @@ struct vm_regions {
|
|||||||
|
|
||||||
struct process_vm;
|
struct process_vm;
|
||||||
|
|
||||||
struct sigfd {
|
struct mckfd {
|
||||||
struct sigfd *next;
|
struct mckfd *next;
|
||||||
int fd;
|
int fd;
|
||||||
__sigset_t mask;
|
long data;
|
||||||
|
void *opt;
|
||||||
|
long (*read_cb)(struct mckfd *, ihk_mc_user_context_t *);
|
||||||
|
int (*ioctl_cb)(struct mckfd *, ihk_mc_user_context_t *);
|
||||||
|
int (*close_cb)(struct mckfd *, ihk_mc_user_context_t *);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SFD_CLOEXEC 02000000
|
#define SFD_CLOEXEC 02000000
|
||||||
#define SFD_NONBLOCK 04000
|
#define SFD_NONBLOCK 04000
|
||||||
|
|
||||||
struct sig_common {
|
struct sig_common {
|
||||||
ihk_spinlock_t lock;
|
ihk_spinlock_t lock;
|
||||||
ihk_atomic_t use;
|
ihk_atomic_t use;
|
||||||
struct sigfd *sigfd;
|
|
||||||
struct k_sigaction action[_NSIG];
|
struct k_sigaction action[_NSIG];
|
||||||
struct list_head sigpending;
|
struct list_head sigpending;
|
||||||
};
|
};
|
||||||
@@ -343,7 +347,7 @@ typedef void pgio_func_t(void *arg);
|
|||||||
* special "init" process */
|
* special "init" process */
|
||||||
struct process {
|
struct process {
|
||||||
struct list_head hash_list;
|
struct list_head hash_list;
|
||||||
mcs_rwlock_lock_t update_lock; // lock for parent, status, ...?
|
mcs_rwlock_lock_t update_lock; // lock for parent, status, cpu time...
|
||||||
|
|
||||||
// process vm
|
// process vm
|
||||||
struct process_vm *vm;
|
struct process_vm *vm;
|
||||||
@@ -425,6 +429,16 @@ struct process {
|
|||||||
/* Store signal sent to parent when the process terminates. */
|
/* Store signal sent to parent when the process terminates. */
|
||||||
int termsig;
|
int termsig;
|
||||||
|
|
||||||
|
ihk_spinlock_t mckfd_lock;
|
||||||
|
struct mckfd *mckfd;
|
||||||
|
|
||||||
|
// cpu time (summary)
|
||||||
|
struct timespec stime;
|
||||||
|
struct timespec utime;
|
||||||
|
|
||||||
|
// cpu time (children)
|
||||||
|
struct timespec stime_children;
|
||||||
|
struct timespec utime_children;
|
||||||
};
|
};
|
||||||
|
|
||||||
void hold_thread(struct thread *ftn);
|
void hold_thread(struct thread *ftn);
|
||||||
@@ -512,6 +526,20 @@ struct thread {
|
|||||||
unsigned long *ptrace_debugreg; /* debug registers for ptrace */
|
unsigned long *ptrace_debugreg; /* debug registers for ptrace */
|
||||||
struct sig_pending *ptrace_recvsig;
|
struct sig_pending *ptrace_recvsig;
|
||||||
struct sig_pending *ptrace_sendsig;
|
struct sig_pending *ptrace_sendsig;
|
||||||
|
|
||||||
|
// cpu time
|
||||||
|
struct timespec stime;
|
||||||
|
struct timespec utime;
|
||||||
|
struct timespec btime;
|
||||||
|
int times_update;
|
||||||
|
int in_kernel;
|
||||||
|
|
||||||
|
// interval timers
|
||||||
|
int itimer_enabled;
|
||||||
|
struct itimerval itimer_virtual;
|
||||||
|
struct itimerval itimer_prof;
|
||||||
|
struct timespec itimer_virtual_value;
|
||||||
|
struct timespec itimer_prof_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct process_vm {
|
struct process_vm {
|
||||||
@@ -615,5 +643,6 @@ void process_unlock(struct process *proc, struct mcs_rwlock_node_irqsave *lock);
|
|||||||
void chain_process(struct process *);
|
void chain_process(struct process *);
|
||||||
void chain_thread(struct thread *);
|
void chain_thread(struct thread *);
|
||||||
void proc_init();
|
void proc_init();
|
||||||
|
void set_timer();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -66,6 +66,8 @@
|
|||||||
#define SCD_MSG_SYSFS_RESP_SETUP 0x41
|
#define SCD_MSG_SYSFS_RESP_SETUP 0x41
|
||||||
/* #define SCD_MSG_SYSFS_REQ_CLEANUP 0x42 */
|
/* #define SCD_MSG_SYSFS_REQ_CLEANUP 0x42 */
|
||||||
/* #define SCD_MSG_SYSFS_RESP_CLEANUP 0x43 */
|
/* #define SCD_MSG_SYSFS_RESP_CLEANUP 0x43 */
|
||||||
|
#define SCD_MSG_PROCFS_TID_CREATE 0x44
|
||||||
|
#define SCD_MSG_PROCFS_TID_DELETE 0x45
|
||||||
|
|
||||||
#define ARCH_SET_GS 0x1001
|
#define ARCH_SET_GS 0x1001
|
||||||
#define ARCH_SET_FS 0x1002
|
#define ARCH_SET_FS 0x1002
|
||||||
@@ -314,6 +316,7 @@ struct procfs_read {
|
|||||||
int ret; /* read bytes (answer) */
|
int ret; /* read bytes (answer) */
|
||||||
int status; /* non-zero if done (answer) */
|
int status; /* non-zero if done (answer) */
|
||||||
int newcpu; /* migrated new cpu (answer) */
|
int newcpu; /* migrated new cpu (answer) */
|
||||||
|
int readwrite; /* 0:read, 1:write */
|
||||||
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -334,4 +337,7 @@ struct tod_data_s {
|
|||||||
};
|
};
|
||||||
extern struct tod_data_s tod_data; /* residing in arch-dependent file */
|
extern struct tod_data_s tod_data; /* residing in arch-dependent file */
|
||||||
|
|
||||||
|
void reset_cputime();
|
||||||
|
void set_cputime(int mode);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -53,5 +53,72 @@ struct timezone
|
|||||||
int tz_dsttime; /* Nonzero if DST is ever in effect. */
|
int tz_dsttime; /* Nonzero if DST is ever in effect. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define ITIMER_REAL 0
|
||||||
|
#define ITIMER_VIRTUAL 1
|
||||||
|
#define ITIMER_PROF 2
|
||||||
|
|
||||||
|
struct itimerval {
|
||||||
|
struct timeval it_interval;
|
||||||
|
struct timeval it_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ts_add(struct timespec *ats, const struct timespec *bts)
|
||||||
|
{
|
||||||
|
ats->tv_sec += bts->tv_sec;
|
||||||
|
ats->tv_nsec += bts->tv_nsec;
|
||||||
|
while(ats->tv_nsec >= 1000000000){
|
||||||
|
ats->tv_sec++;
|
||||||
|
ats->tv_nsec -= 1000000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ts_sub(struct timespec *ats, const struct timespec *bts)
|
||||||
|
{
|
||||||
|
ats->tv_sec -= bts->tv_sec;
|
||||||
|
ats->tv_nsec -= bts->tv_nsec;
|
||||||
|
while(ats->tv_nsec < 0){
|
||||||
|
ats->tv_sec--;
|
||||||
|
ats->tv_nsec += 1000000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
tv_add(struct timeval *ats, const struct timeval *bts)
|
||||||
|
{
|
||||||
|
ats->tv_sec += bts->tv_sec;
|
||||||
|
ats->tv_usec += bts->tv_usec;
|
||||||
|
while(ats->tv_usec >= 1000000){
|
||||||
|
ats->tv_sec++;
|
||||||
|
ats->tv_usec -= 1000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
tv_sub(struct timeval *ats, const struct timeval *bts)
|
||||||
|
{
|
||||||
|
ats->tv_sec -= bts->tv_sec;
|
||||||
|
ats->tv_usec -= bts->tv_usec;
|
||||||
|
while(ats->tv_usec < 0){
|
||||||
|
ats->tv_sec--;
|
||||||
|
ats->tv_usec += 1000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
tv_to_ts(struct timespec *ats, const struct timeval *bts)
|
||||||
|
{
|
||||||
|
ats->tv_sec = bts->tv_sec;
|
||||||
|
ats->tv_nsec = bts->tv_usec * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ts_to_tv(struct timeval *ats, const struct timespec *bts)
|
||||||
|
{
|
||||||
|
ats->tv_sec = bts->tv_sec;
|
||||||
|
ats->tv_usec = bts->tv_nsec / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // __TIME_H
|
#endif // __TIME_H
|
||||||
|
|
||||||
|
|||||||
@@ -283,7 +283,6 @@ static void post_init(void)
|
|||||||
zero_tsc();
|
zero_tsc();
|
||||||
ap_start();
|
ap_start();
|
||||||
|
|
||||||
create_os_procfs_files();
|
|
||||||
sysfs_init();
|
sysfs_init();
|
||||||
populate_sysfs();
|
populate_sysfs();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ static unsigned long pa_start, pa_end;
|
|||||||
static struct page *pa_pages;
|
static struct page *pa_pages;
|
||||||
|
|
||||||
extern int ihk_mc_pt_print_pte(struct page_table *pt, void *virt);
|
extern int ihk_mc_pt_print_pte(struct page_table *pt, void *virt);
|
||||||
|
extern int interrupt_from_user(void *);
|
||||||
|
|
||||||
struct tlb_flush_entry tlb_flush_vector[IHK_TLB_FLUSH_IRQ_VECTOR_SIZE];
|
struct tlb_flush_entry tlb_flush_vector[IHK_TLB_FLUSH_IRQ_VECTOR_SIZE];
|
||||||
|
|
||||||
@@ -369,6 +370,7 @@ static void page_fault_handler(void *fault_addr, uint64_t reason, void *regs)
|
|||||||
struct thread *thread = cpu_local_var(current);
|
struct thread *thread = cpu_local_var(current);
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
set_cputime(interrupt_from_user(regs)? 1: 2);
|
||||||
dkprintf("[%d]page_fault_handler(%p,%lx,%p)\n",
|
dkprintf("[%d]page_fault_handler(%p,%lx,%p)\n",
|
||||||
ihk_mc_get_processor_id(), fault_addr, reason, regs);
|
ihk_mc_get_processor_id(), fault_addr, reason, regs);
|
||||||
|
|
||||||
@@ -427,6 +429,7 @@ out:
|
|||||||
ihk_mc_get_processor_id(), fault_addr, reason,
|
ihk_mc_get_processor_id(), fault_addr, reason,
|
||||||
regs, error);
|
regs, error);
|
||||||
check_need_resched();
|
check_need_resched();
|
||||||
|
set_cputime(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ extern int num_processors;
|
|||||||
extern ihk_spinlock_t cpuid_head_lock;
|
extern ihk_spinlock_t cpuid_head_lock;
|
||||||
int ptrace_detach(int pid, int data);
|
int ptrace_detach(int pid, int data);
|
||||||
extern unsigned long do_kill(struct thread *, int pid, int tid, int sig, struct siginfo *info, int ptracecont);
|
extern unsigned long do_kill(struct thread *, int pid, int tid, int sig, struct siginfo *info, int ptracecont);
|
||||||
|
extern void procfs_create_thread(struct thread *);
|
||||||
|
extern void procfs_delete_thread(struct thread *);
|
||||||
|
|
||||||
struct list_head resource_set_list;
|
struct list_head resource_set_list;
|
||||||
mcs_rwlock_lock_t resource_set_lock;
|
mcs_rwlock_lock_t resource_set_lock;
|
||||||
@@ -96,6 +98,7 @@ init_process(struct process *proc, struct process *parent)
|
|||||||
INIT_LIST_HEAD(&proc->ptraced_children_list);
|
INIT_LIST_HEAD(&proc->ptraced_children_list);
|
||||||
mcs_rwlock_init(&proc->threads_lock);
|
mcs_rwlock_init(&proc->threads_lock);
|
||||||
mcs_rwlock_init(&proc->children_lock);
|
mcs_rwlock_init(&proc->children_lock);
|
||||||
|
ihk_mc_spinlock_init(&proc->mckfd_lock);
|
||||||
waitq_init(&proc->waitpid_q);
|
waitq_init(&proc->waitpid_q);
|
||||||
ihk_atomic_set(&proc->refcount, 2);
|
ihk_atomic_set(&proc->refcount, 2);
|
||||||
}
|
}
|
||||||
@@ -2158,13 +2161,20 @@ void destroy_thread(struct thread *thread)
|
|||||||
void release_thread(struct thread *thread)
|
void release_thread(struct thread *thread)
|
||||||
{
|
{
|
||||||
struct process_vm *vm;
|
struct process_vm *vm;
|
||||||
|
struct mcs_rwlock_node lock;
|
||||||
|
|
||||||
if (!ihk_atomic_dec_and_test(&thread->refcount)) {
|
if (!ihk_atomic_dec_and_test(&thread->refcount)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mcs_rwlock_writer_lock_noirq(&thread->proc->update_lock, &lock);
|
||||||
|
ts_add(&thread->proc->stime, &thread->stime);
|
||||||
|
ts_add(&thread->proc->utime, &thread->utime);
|
||||||
|
mcs_rwlock_writer_unlock_noirq(&thread->proc->update_lock, &lock);
|
||||||
|
|
||||||
vm = thread->vm;
|
vm = thread->vm;
|
||||||
|
|
||||||
|
procfs_delete_thread(thread);
|
||||||
destroy_thread(thread);
|
destroy_thread(thread);
|
||||||
|
|
||||||
release_process_vm(vm);
|
release_process_vm(vm);
|
||||||
@@ -2468,6 +2478,26 @@ ack:
|
|||||||
ihk_mc_spinlock_unlock(&cur_v->migq_lock, irqstate);
|
ihk_mc_spinlock_unlock(&cur_v->migq_lock, irqstate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
set_timer()
|
||||||
|
{
|
||||||
|
struct cpu_local_var *v = get_this_cpu_local_var();
|
||||||
|
|
||||||
|
/* Toggle timesharing if CPU core is oversubscribed */
|
||||||
|
if (v->runq_len > 1 || v->current->itimer_enabled) {
|
||||||
|
if (!cpu_local_var(timer_enabled)) {
|
||||||
|
lapic_timer_enable(10000000);
|
||||||
|
cpu_local_var(timer_enabled) = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (cpu_local_var(timer_enabled)) {
|
||||||
|
lapic_timer_disable();
|
||||||
|
cpu_local_var(timer_enabled) = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void schedule(void)
|
void schedule(void)
|
||||||
{
|
{
|
||||||
struct cpu_local_var *v;
|
struct cpu_local_var *v;
|
||||||
@@ -2506,20 +2536,6 @@ redo:
|
|||||||
list_add_tail(&prev->sched_list, &(v->runq));
|
list_add_tail(&prev->sched_list, &(v->runq));
|
||||||
++v->runq_len;
|
++v->runq_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Toggle timesharing if CPU core is oversubscribed */
|
|
||||||
if (v->runq_len > 1) {
|
|
||||||
if (!cpu_local_var(timer_enabled)) {
|
|
||||||
lapic_timer_enable(10000000);
|
|
||||||
cpu_local_var(timer_enabled) = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (cpu_local_var(timer_enabled)) {
|
|
||||||
lapic_timer_disable();
|
|
||||||
cpu_local_var(timer_enabled) = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->flags & CPU_FLAG_NEED_MIGRATE) {
|
if (v->flags & CPU_FLAG_NEED_MIGRATE) {
|
||||||
@@ -2543,8 +2559,11 @@ redo:
|
|||||||
if (prev != next) {
|
if (prev != next) {
|
||||||
switch_ctx = 1;
|
switch_ctx = 1;
|
||||||
v->current = next;
|
v->current = next;
|
||||||
|
reset_cputime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_timer();
|
||||||
|
|
||||||
if (switch_ctx) {
|
if (switch_ctx) {
|
||||||
dkprintf("schedule: %d => %d \n",
|
dkprintf("schedule: %d => %d \n",
|
||||||
prev ? prev->tid : 0, next ? next->tid : 0);
|
prev ? prev->tid : 0, next ? next->tid : 0);
|
||||||
@@ -2752,7 +2771,7 @@ void runq_add_thread(struct thread *thread, int cpu_id)
|
|||||||
__runq_add_thread(thread, cpu_id);
|
__runq_add_thread(thread, cpu_id);
|
||||||
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
|
ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate);
|
||||||
|
|
||||||
create_proc_procfs_files(thread->proc->pid, cpu_id);
|
procfs_create_thread(thread);
|
||||||
|
|
||||||
/* Kick scheduler */
|
/* Kick scheduler */
|
||||||
if (cpu_id != ihk_mc_get_processor_id())
|
if (cpu_id != ihk_mc_get_processor_id())
|
||||||
|
|||||||
571
kernel/procfs.c
571
kernel/procfs.c
@@ -38,212 +38,37 @@ extern int sscanf(const char * buf, const char * fmt, ...);
|
|||||||
|
|
||||||
extern int osnum;
|
extern int osnum;
|
||||||
|
|
||||||
void create_proc_procfs_files(int pid, int cpuid);
|
|
||||||
void delete_proc_procfs_files(int pid);
|
|
||||||
void create_os_procfs_files(void);
|
|
||||||
void delete_os_procfs_files(void);
|
|
||||||
|
|
||||||
static void create_proc_procfs_file(int pid, char *fname, int mode, int cpuid);
|
|
||||||
static void delete_proc_procfs_file(int pid, char *fname);
|
|
||||||
static void operate_proc_procfs_file(int pid, char *fname, int msg, int mode, int cpuid);
|
|
||||||
|
|
||||||
int copy_from_user(void *dst, const void *src, size_t siz);
|
int copy_from_user(void *dst, const void *src, size_t siz);
|
||||||
int copy_to_user(void *dst, const void *src, size_t siz);
|
int copy_to_user(void *dst, const void *src, size_t siz);
|
||||||
|
|
||||||
/**
|
static void
|
||||||
* \brief Create all procfs files for process.
|
procfs_thread_ctl(struct thread *thread, int msg)
|
||||||
*
|
|
||||||
* \param pid pid of the process
|
|
||||||
* \param cpuid cpuid of the process
|
|
||||||
*/
|
|
||||||
|
|
||||||
void create_proc_procfs_files(int pid, int cpuid)
|
|
||||||
{
|
|
||||||
char fname[PROCFS_NAME_MAX];
|
|
||||||
|
|
||||||
dprintf("create procfs files:\n");
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/auxv", osnum, pid);
|
|
||||||
create_proc_procfs_file(pid, fname, 0400, cpuid);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/cmdline", osnum, pid);
|
|
||||||
create_proc_procfs_file(pid, fname, 0444, cpuid);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/mem", osnum, pid);
|
|
||||||
create_proc_procfs_file(pid, fname, 0400, cpuid);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/maps", osnum, pid);
|
|
||||||
create_proc_procfs_file(pid, fname, 0444, cpuid);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/pagemap", osnum, pid);
|
|
||||||
create_proc_procfs_file(pid, fname, 0444, cpuid);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/status", osnum, pid);
|
|
||||||
create_proc_procfs_file(pid, fname, 0444, cpuid);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/task/%d/mem", osnum, pid, pid);
|
|
||||||
create_proc_procfs_file(pid, fname, 0400, cpuid);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/task/%d/stat", osnum, pid, pid);
|
|
||||||
create_proc_procfs_file(pid, fname, 0444, cpuid);
|
|
||||||
|
|
||||||
dprintf("create procfs files: done\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Create a procfs file for process.
|
|
||||||
*
|
|
||||||
* \param pid pid of the process
|
|
||||||
* \param fname file name of the procfs file
|
|
||||||
* \param mode file mode
|
|
||||||
* \param cpuid cpuid of the process
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void create_proc_procfs_file(int pid, char *fname, int mode, int cpuid)
|
|
||||||
{
|
|
||||||
dprintf("create procfs file: %s, mode: %o, cpuid: %d\n", fname, mode, cpuid);
|
|
||||||
operate_proc_procfs_file(pid, fname, SCD_MSG_PROCFS_CREATE, mode, cpuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Delete all procfs files for process.
|
|
||||||
*
|
|
||||||
* \param pid pid of the process
|
|
||||||
*/
|
|
||||||
|
|
||||||
void delete_proc_procfs_files(int pid)
|
|
||||||
{
|
|
||||||
char fname[PROCFS_NAME_MAX];
|
|
||||||
|
|
||||||
dprintf("delete procfs files for pid %d.\n", pid);
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/task/%d/mem", osnum, pid, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/task/%d/stat", osnum, pid, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/task/%d", osnum, pid, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/task", osnum, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/mem", osnum, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/maps", osnum, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/status", osnum, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/pagemap", osnum, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/cmdline", osnum, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
snprintf(fname, PROCFS_NAME_MAX, "mcos%d/%d/auxv", osnum, pid);
|
|
||||||
delete_proc_procfs_file(pid, fname);
|
|
||||||
|
|
||||||
/* NOTE: Directory is removed on the host when mcexec drops the executable */
|
|
||||||
dprintf("delete procfs files for pid %d: done\n", pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Delete a procfs file for process.
|
|
||||||
*
|
|
||||||
* \param pid pid of the process
|
|
||||||
* \param fname file name of the procfs file
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void delete_proc_procfs_file(int pid, char *fname)
|
|
||||||
{
|
|
||||||
dprintf("delete procfs file: %s\n", fname);
|
|
||||||
operate_proc_procfs_file(pid, fname, SCD_MSG_PROCFS_DELETE, 0, 0);
|
|
||||||
dprintf("delete procfs file: %s done\n", fname);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief create a procfs file for this operating system
|
|
||||||
* \param fname relative path name from "host:/proc".
|
|
||||||
* \param mode permissions of the file to be created
|
|
||||||
*
|
|
||||||
* Though operate_proc_procfs_file() is intended to create a process
|
|
||||||
* specific file, it is reused to create a OS specific file by
|
|
||||||
* specifying -1 as the pid parameter.
|
|
||||||
*/
|
|
||||||
static void create_os_procfs_file(char *fname, int mode)
|
|
||||||
{
|
|
||||||
const pid_t pid = -1;
|
|
||||||
const int msg = SCD_MSG_PROCFS_CREATE;
|
|
||||||
const int cpuid = ihk_mc_get_processor_id(); /* i.e. BSP */
|
|
||||||
|
|
||||||
operate_proc_procfs_file(pid, fname, msg, mode, cpuid);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief create all procfs files for this operating system
|
|
||||||
*/
|
|
||||||
void create_os_procfs_files(void)
|
|
||||||
{
|
|
||||||
char *fname = NULL;
|
|
||||||
size_t n;
|
|
||||||
|
|
||||||
fname = kmalloc(PROCFS_NAME_MAX, IHK_MC_AP_CRITICAL);
|
|
||||||
|
|
||||||
n = snprintf(fname, PROCFS_NAME_MAX, "mcos%d/stat", osnum);
|
|
||||||
if (n >= PROCFS_NAME_MAX) panic("/proc/stat");
|
|
||||||
create_os_procfs_file(fname, 0444);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Create/delete a procfs file for process.
|
|
||||||
*
|
|
||||||
* \param pid pid of the process
|
|
||||||
* \param fname file name of the procfs file
|
|
||||||
* \param msg message (create/delete)
|
|
||||||
* \param mode file mode
|
|
||||||
* \param cpuid cpuid of the process
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void operate_proc_procfs_file(int pid, char *fname, int msg, int mode, int cpuid)
|
|
||||||
{
|
{
|
||||||
struct ihk_ikc_channel_desc *syscall_channel;
|
struct ihk_ikc_channel_desc *syscall_channel;
|
||||||
struct ikc_scd_packet pckt;
|
struct ikc_scd_packet packet;
|
||||||
struct procfs_file *f;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
syscall_channel = cpu_local_var(syscall_channel);
|
syscall_channel = cpu_local_var(syscall_channel);
|
||||||
|
memset(&packet, '\0', sizeof packet);
|
||||||
|
packet.arg = thread->tid;
|
||||||
|
packet.msg = msg;
|
||||||
|
packet.osnum = osnum;
|
||||||
|
packet.ref = thread->cpu_id;
|
||||||
|
packet.pid = thread->proc->pid;
|
||||||
|
packet.err = 0;
|
||||||
|
|
||||||
f = kmalloc(sizeof(struct procfs_file), IHK_MC_AP_NOWAIT);
|
ihk_ikc_send(syscall_channel, &packet, 0);
|
||||||
if (!f) {
|
}
|
||||||
kprintf("ERROR: not enough memory for dealing procfs file %s!",
|
|
||||||
fname);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
f->status = 0;
|
|
||||||
f->mode = mode;
|
|
||||||
strncpy(f->fname, fname, PROCFS_NAME_MAX);
|
|
||||||
pckt.arg = virt_to_phys(f);
|
|
||||||
pckt.msg = msg;
|
|
||||||
pckt.osnum = osnum;
|
|
||||||
pckt.ref = cpuid;
|
|
||||||
pckt.pid = pid;
|
|
||||||
pckt.err = 0;
|
|
||||||
|
|
||||||
ret = ihk_ikc_send(syscall_channel, &pckt, 0);
|
void
|
||||||
if (ret < 0) {
|
procfs_create_thread(struct thread *thread)
|
||||||
kprintf("ERROR: sending IKC msg, ret: %d\n", ret);
|
{
|
||||||
}
|
procfs_thread_ctl(thread, SCD_MSG_PROCFS_TID_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
while (f->status != 1) {
|
void
|
||||||
cpu_pause();
|
procfs_delete_thread(struct thread *thread)
|
||||||
}
|
{
|
||||||
kfree(f);
|
procfs_thread_ctl(thread, SCD_MSG_PROCFS_TID_DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -251,12 +76,13 @@ static void operate_proc_procfs_file(int pid, char *fname, int msg, int mode, in
|
|||||||
*
|
*
|
||||||
* \param rarg returned argument
|
* \param rarg returned argument
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
void process_procfs_request(unsigned long rarg)
|
process_procfs_request(unsigned long rarg)
|
||||||
{
|
{
|
||||||
unsigned long parg, pbuf;
|
unsigned long parg, pbuf;
|
||||||
struct thread *thread = cpu_local_var(current);
|
struct thread *thread = NULL;
|
||||||
struct process *proc = thread->proc;
|
struct process *proc = NULL;
|
||||||
|
struct process_vm *vm = NULL;
|
||||||
struct procfs_read *r;
|
struct procfs_read *r;
|
||||||
struct ikc_scd_packet packet;
|
struct ikc_scd_packet packet;
|
||||||
int rosnum, ret, pid, tid, ans = -EIO, eof = 0;
|
int rosnum, ret, pid, tid, ans = -EIO, eof = 0;
|
||||||
@@ -266,7 +92,7 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
int count;
|
int count;
|
||||||
int npages;
|
int npages;
|
||||||
int is_current = 1; /* is 'proc' same as 'current'? */
|
int readwrite = 0;
|
||||||
|
|
||||||
dprintf("process_procfs_request: invoked.\n");
|
dprintf("process_procfs_request: invoked.\n");
|
||||||
|
|
||||||
@@ -296,6 +122,7 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
goto bufunavail;
|
goto bufunavail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readwrite = r->readwrite;
|
||||||
count = r->count;
|
count = r->count;
|
||||||
offset = r->offset;
|
offset = r->offset;
|
||||||
dprintf("fname: %s, offset: %lx, count:%d.\n", r->fname, r->offset, r->count);
|
dprintf("fname: %s, offset: %lx, count:%d.\n", r->fname, r->offset, r->count);
|
||||||
@@ -334,32 +161,47 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
*/
|
*/
|
||||||
ret = sscanf(p, "%d/", &pid);
|
ret = sscanf(p, "%d/", &pid);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
if (pid != cpu_local_var(current)->proc->pid) {
|
struct mcs_rwlock_node tlock;
|
||||||
/* We are not located in the proper cpu for some reason. */
|
int tids;
|
||||||
|
struct thread *thread1 = NULL;
|
||||||
|
|
||||||
dprintf("mismatched pid. We are %d, but requested pid is %d.\n",
|
proc = find_process(pid, &lock);
|
||||||
pid, cpu_local_var(current)->pid);
|
if(proc == NULL){
|
||||||
tid = pid; /* main thread */
|
kprintf("process_procfs_request: no such pid %d\n", pid);
|
||||||
thread = find_thread(pid, tid, &lock);
|
goto end;
|
||||||
if (!thread) {
|
|
||||||
dprintf("We cannot find the proper cpu for requested pid.\n");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
else if (thread->cpu_id != ihk_mc_get_processor_id()) {
|
|
||||||
/* The target process has gone by migration. */
|
|
||||||
r->newcpu = thread->cpu_id;
|
|
||||||
dprintf("expected cpu id is %d.\n", thread->cpu_id);
|
|
||||||
thread_unlock(thread, &lock);
|
|
||||||
ans = 0;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
thread_unlock(thread, &lock);
|
|
||||||
/* 'proc' is not 'current' */
|
|
||||||
is_current = 0;
|
|
||||||
}
|
|
||||||
proc = thread->proc;
|
|
||||||
}
|
}
|
||||||
|
p = strchr(p, '/') + 1;
|
||||||
|
if((tids = sscanf(p, "task/%d/", &tid)) == 1){
|
||||||
|
p = strchr(p, '/') + 1;
|
||||||
|
p = strchr(p, '/') + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tid = pid;
|
||||||
|
|
||||||
|
mcs_rwlock_reader_lock_noirq(&proc->threads_lock, &tlock);
|
||||||
|
list_for_each_entry(thread, &proc->threads_list, siblings_list){
|
||||||
|
if(thread->tid == tid)
|
||||||
|
break;
|
||||||
|
if(!thread1)
|
||||||
|
thread1 = thread;
|
||||||
|
}
|
||||||
|
if(thread == NULL){
|
||||||
|
kprintf("process_procfs_request: no such tid %d-%d\n", pid, tid);
|
||||||
|
if(tids){
|
||||||
|
process_unlock(proc, &lock);
|
||||||
|
mcs_rwlock_reader_unlock_noirq(&proc->threads_lock, &tlock);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
thread = thread1;
|
||||||
|
}
|
||||||
|
if(thread)
|
||||||
|
hold_thread(thread);
|
||||||
|
mcs_rwlock_reader_unlock_noirq(&proc->threads_lock, &tlock);
|
||||||
|
hold_process(proc);
|
||||||
|
vm = proc->vm;
|
||||||
|
if(vm)
|
||||||
|
hold_process_vm(vm);
|
||||||
|
process_unlock(proc, &lock);
|
||||||
}
|
}
|
||||||
else if (!strcmp(p, "stat")) { /* "/proc/stat" */
|
else if (!strcmp(p, "stat")) { /* "/proc/stat" */
|
||||||
extern int num_processors; /* kernel/ap.c */
|
extern int num_processors; /* kernel/ap.c */
|
||||||
@@ -390,10 +232,9 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
kprintf("unsupported procfs entry: %s\n", p);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
dprintf("matched PID: %d.\n", pid);
|
|
||||||
p = strchr(p, '/') + 1;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mcos%d/PID/mem
|
* mcos%d/PID/mem
|
||||||
@@ -402,74 +243,55 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
* of the process. The count is the length of the area.
|
* of the process. The count is the length of the area.
|
||||||
*/
|
*/
|
||||||
if (strcmp(p, "mem") == 0) {
|
if (strcmp(p, "mem") == 0) {
|
||||||
struct vm_range *range;
|
uint64_t reason = PF_POPULATE | PF_WRITE | PF_USER;
|
||||||
struct process_vm *vm = proc->vm;
|
unsigned long offset = r->offset;
|
||||||
|
unsigned long left = r->count;
|
||||||
|
int ret;
|
||||||
|
struct page_table *pt = vm->address_space->page_table;
|
||||||
|
|
||||||
if (!is_current) {
|
ans = 0;
|
||||||
uint64_t reason = PF_POPULATE | PF_WRITE | PF_USER;
|
if(left == 0)
|
||||||
unsigned long offset = r->offset;
|
goto end;
|
||||||
unsigned long left = r->count;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ans = 0;
|
#if 0
|
||||||
if(left == 0)
|
if(!(proc->ptrace & PT_TRACED) ||
|
||||||
goto end;
|
!(proc->status & (PS_STOPPED | PS_TRACED))){
|
||||||
|
ans = -EIO;
|
||||||
while(left){
|
goto end;
|
||||||
unsigned long pa;
|
|
||||||
char *va;
|
|
||||||
int pos = offset & (PAGE_SIZE - 1);
|
|
||||||
int size = PAGE_SIZE - pos;
|
|
||||||
|
|
||||||
if(size > left)
|
|
||||||
size = left;
|
|
||||||
ret = page_fault_process_vm(proc->vm,
|
|
||||||
(void *)offset, reason);
|
|
||||||
if(ret){
|
|
||||||
if(ans == 0)
|
|
||||||
ans = -EIO;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
ret = ihk_mc_pt_virt_to_phys(vm->address_space->page_table,
|
|
||||||
(void *)offset, &pa);
|
|
||||||
if(ret){
|
|
||||||
if(ans == 0)
|
|
||||||
ans = -EIO;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
va = phys_to_virt(pa);
|
|
||||||
memcpy(buf + ans, va, size);
|
|
||||||
offset += size;
|
|
||||||
left -= size;
|
|
||||||
ans += size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
#endif
|
||||||
unsigned long offset = r->offset;
|
|
||||||
unsigned long left = r->count;
|
if(readwrite == 0)
|
||||||
unsigned long pos;
|
reason = PF_POPULATE | PF_USER;
|
||||||
unsigned long l;
|
|
||||||
ans = 0;
|
while(left){
|
||||||
list_for_each_entry(range, &vm->vm_range_list, list) {
|
unsigned long pa;
|
||||||
dprintf("range: %lx - %lx\n", range->start, range->end);
|
char *va;
|
||||||
while (left &&
|
int pos = offset & (PAGE_SIZE - 1);
|
||||||
(range->start <= offset) &&
|
int size = PAGE_SIZE - pos;
|
||||||
(offset < range->end)) {
|
|
||||||
pos = offset & (PAGE_SIZE - 1);
|
if(size > left)
|
||||||
l = PAGE_SIZE - pos;
|
size = left;
|
||||||
if(l > left)
|
ret = page_fault_process_vm(vm, (void *)offset, reason);
|
||||||
l = left;
|
if(ret){
|
||||||
if(copy_from_user(buf, (void *)offset, l)){
|
if(ans == 0)
|
||||||
if(ans == 0)
|
ans = -EIO;
|
||||||
ans = -EIO;
|
goto end;
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
buf += l;
|
|
||||||
ans += l;
|
|
||||||
offset += l;
|
|
||||||
left -= l;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
ret = ihk_mc_pt_virt_to_phys(pt, (void *)offset, &pa);
|
||||||
|
if(ret){
|
||||||
|
if(ans == 0)
|
||||||
|
ans = -EIO;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
va = phys_to_virt(pa);
|
||||||
|
if(readwrite)
|
||||||
|
memcpy(va, buf + ans, size);
|
||||||
|
else
|
||||||
|
memcpy(buf + ans, va, size);
|
||||||
|
offset += size;
|
||||||
|
left -= size;
|
||||||
|
ans += size;
|
||||||
}
|
}
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@@ -479,7 +301,6 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
*/
|
*/
|
||||||
if (strcmp(p, "maps") == 0) {
|
if (strcmp(p, "maps") == 0) {
|
||||||
struct vm_range *range;
|
struct vm_range *range;
|
||||||
struct process_vm *vm = proc->vm;
|
|
||||||
int left = r->count - 1; /* extra 1 for terminating NULL */
|
int left = r->count - 1; /* extra 1 for terminating NULL */
|
||||||
int written = 0;
|
int written = 0;
|
||||||
char *_buf = buf;
|
char *_buf = buf;
|
||||||
@@ -537,7 +358,6 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
* mcos%d/PID/pagemap
|
* mcos%d/PID/pagemap
|
||||||
*/
|
*/
|
||||||
if (strcmp(p, "pagemap") == 0) {
|
if (strcmp(p, "pagemap") == 0) {
|
||||||
struct process_vm *vm = proc->vm;
|
|
||||||
uint64_t *_buf = (uint64_t *)buf;
|
uint64_t *_buf = (uint64_t *)buf;
|
||||||
uint64_t start, end;
|
uint64_t start, end;
|
||||||
|
|
||||||
@@ -620,7 +440,7 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
* mcos%d/PID/auxv
|
* mcos%d/PID/auxv
|
||||||
*/
|
*/
|
||||||
if (strcmp(p, "auxv") == 0) {
|
if (strcmp(p, "auxv") == 0) {
|
||||||
unsigned int limit = AUXV_LEN * sizeof(int);
|
unsigned int limit = AUXV_LEN * sizeof(unsigned long);
|
||||||
unsigned int len = r->count;
|
unsigned int len = r->count;
|
||||||
if (r->offset < limit) {
|
if (r->offset < limit) {
|
||||||
if (limit < r->offset + r->count) {
|
if (limit < r->offset + r->count) {
|
||||||
@@ -673,112 +493,71 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
* The offset is treated as the beginning of the virtual address area
|
* The offset is treated as the beginning of the virtual address area
|
||||||
* of the process. The count is the length of the area.
|
* of the process. The count is the length of the area.
|
||||||
*/
|
*/
|
||||||
tid = pid;
|
|
||||||
ret = sscanf(p, "task/%d/", &tid);
|
|
||||||
if (ret == 1) {
|
|
||||||
p = strchr(p, '/') + 1;
|
|
||||||
p = strchr(p, '/') + 1;
|
|
||||||
|
|
||||||
if (!strcmp(p, "mem")){
|
if (!strcmp(p, "stat")) {
|
||||||
struct vm_range *range;
|
char tmp[1024];
|
||||||
struct process_vm *vm = proc->vm;
|
int len;
|
||||||
|
|
||||||
if (!is_current) {
|
/*
|
||||||
goto end;
|
* pid (comm) state ppid
|
||||||
|
* pgrp session tty_nr tpgid
|
||||||
|
* flags minflt cminflt majflt
|
||||||
|
* cmajflt utime stime cutime
|
||||||
|
* cstime priority nice num_threads
|
||||||
|
* itrealvalue starttime vsize rss
|
||||||
|
* rsslim startcode endcode startstack
|
||||||
|
* kstkesp kstkeip signal blocked
|
||||||
|
* sigignore sigcatch wchan nswap
|
||||||
|
* cnswap exit_signal processor rt_priority
|
||||||
|
* policy delayacct_blkio_ticks guest_time cguest_time
|
||||||
|
*/
|
||||||
|
ans = sprintf(tmp,
|
||||||
|
"%d (%s) %c %d " // pid...
|
||||||
|
"%d %d %d %d " // pgrp...
|
||||||
|
"%u %lu %lu %lu " // flags...
|
||||||
|
"%lu %lu %lu %ld " // cmajflt...
|
||||||
|
"%ld %ld %ld %ld " // cstime...
|
||||||
|
"%ld %llu %lu %ld " // itrealvalue...
|
||||||
|
"%lu %lu %lu %lu " // rsslim...
|
||||||
|
"%lu %lu %lu %lu " // kstkesp...
|
||||||
|
"%lu %lu %lu %lu " // sigignore...
|
||||||
|
"%lu %d %d %u " // cnswap...
|
||||||
|
"%u %llu %lu %ld\n", // policy...
|
||||||
|
0, "exe", 'R', 0, // pid...
|
||||||
|
0, 0, 0, 0, // pgrp...
|
||||||
|
0, 0L, 0L, 0L, // flags...
|
||||||
|
0L, 0L, 0L, 0L, // cmajflt...
|
||||||
|
0L, 0L, 0L, 0L, // cstime...
|
||||||
|
0L, 0LL, 0L, 0L, // itrealvalue...
|
||||||
|
0L, 0L, 0L, 0L, // rsslim...
|
||||||
|
0L, 0L, 0L, 0L, // kstkesp...
|
||||||
|
0L, 0L, 0L, 0L, // sigignore...
|
||||||
|
0L, 0, thread->cpu_id, 0, // cnswap...
|
||||||
|
0, 0LL, 0L, 0L // policy...
|
||||||
|
);
|
||||||
|
dprintf("tmp=%s\n", tmp);
|
||||||
|
|
||||||
|
len = strlen(tmp);
|
||||||
|
if (r->offset < len) {
|
||||||
|
if (r->offset + r->count < len) {
|
||||||
|
ans = r->count;
|
||||||
|
} else {
|
||||||
|
eof = 1;
|
||||||
|
ans = len;
|
||||||
}
|
}
|
||||||
if (pid != tid) {
|
strncpy(buf, tmp + r->offset, ans);
|
||||||
/* We are not multithreaded yet. */
|
} else if (r->offset == len) {
|
||||||
goto end;
|
ans = 0;
|
||||||
}
|
eof = 1;
|
||||||
list_for_each_entry(range, &vm->vm_range_list, list) {
|
|
||||||
dprintf("range: %lx - %lx\n", range->start, range->end);
|
|
||||||
if ((range->start <= r->offset) &&
|
|
||||||
(r->offset < range->end)) {
|
|
||||||
unsigned int len = r->count;
|
|
||||||
if (range->end < r->offset + r->count) {
|
|
||||||
len = range->end - r->offset;
|
|
||||||
}
|
|
||||||
memcpy((void *)buf, (void *)range->start, len);
|
|
||||||
ans = len;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(p, "stat")) {
|
|
||||||
char tmp[1024];
|
|
||||||
int len;
|
|
||||||
|
|
||||||
if ((thread = find_thread(pid, tid, &lock))){
|
|
||||||
dprintf("thread found! pid=%d tid=%d\n", pid, tid);
|
|
||||||
/*
|
|
||||||
* pid (comm) state ppid
|
|
||||||
* pgrp session tty_nr tpgid
|
|
||||||
* flags minflt cminflt majflt
|
|
||||||
* cmajflt utime stime cutime
|
|
||||||
* cstime priority nice num_threads
|
|
||||||
* itrealvalue starttime vsize rss
|
|
||||||
* rsslim startcode endcode startstack
|
|
||||||
* kstkesp kstkeip signal blocked
|
|
||||||
* sigignore sigcatch wchan nswap
|
|
||||||
* cnswap exit_signal processor rt_priority
|
|
||||||
* policy delayacct_blkio_ticks guest_time cguest_time
|
|
||||||
*/
|
|
||||||
ans = sprintf(tmp,
|
|
||||||
"%d (%s) %c %d " // pid...
|
|
||||||
"%d %d %d %d " // pgrp...
|
|
||||||
"%u %lu %lu %lu " // flags...
|
|
||||||
"%lu %lu %lu %ld " // cmajflt...
|
|
||||||
"%ld %ld %ld %ld " // cstime...
|
|
||||||
"%ld %llu %lu %ld " // itrealvalue...
|
|
||||||
"%lu %lu %lu %lu " // rsslim...
|
|
||||||
"%lu %lu %lu %lu " // kstkesp...
|
|
||||||
"%lu %lu %lu %lu " // sigignore...
|
|
||||||
"%lu %d %d %u " // cnswap...
|
|
||||||
"%u %llu %lu %ld\n", // policy...
|
|
||||||
0, "exe", 'R', 0, // pid...
|
|
||||||
0, 0, 0, 0, // pgrp...
|
|
||||||
0, 0L, 0L, 0L, // flags...
|
|
||||||
0L, 0L, 0L, 0L, // cmajflt...
|
|
||||||
0L, 0L, 0L, 0L, // cstime...
|
|
||||||
0L, 0LL, 0L, 0L, // itrealvalue...
|
|
||||||
0L, 0L, 0L, 0L, // rsslim...
|
|
||||||
0L, 0L, 0L, 0L, // kstkesp...
|
|
||||||
0L, 0L, 0L, 0L, // sigignore...
|
|
||||||
0L, 0, thread->cpu_id, 0, // cnswap...
|
|
||||||
0, 0LL, 0L, 0L // policy...
|
|
||||||
);
|
|
||||||
thread_unlock(thread, &lock);
|
|
||||||
dprintf("tmp=%s\n", tmp);
|
|
||||||
|
|
||||||
len = strlen(tmp);
|
|
||||||
if (r->offset < len) {
|
|
||||||
if (r->offset + r->count < len) {
|
|
||||||
ans = r->count;
|
|
||||||
} else {
|
|
||||||
eof = 1;
|
|
||||||
ans = len;
|
|
||||||
}
|
|
||||||
strncpy(buf, tmp + r->offset, ans);
|
|
||||||
} else if (r->offset == len) {
|
|
||||||
ans = 0;
|
|
||||||
eof = 1;
|
|
||||||
}
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
dprintf("no thread found pid=%d tid=%d\n", pid, tid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dprintf("could not find a matching entry for task/%d/%s.\n", tid, p);
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if(thread)
|
||||||
* Processing for pattern "mcos%d/PID/xxx" files should be here.
|
kprintf("unsupported procfs entry: %d/task/%d/%s\n", pid, tid, p);
|
||||||
*/
|
else
|
||||||
dprintf("could not find a matching entry for %s.\n", p);
|
kprintf("unsupported procfs entry: %d/%s\n", pid, p);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
ihk_mc_unmap_virtual(buf, npages, 0);
|
ihk_mc_unmap_virtual(buf, npages, 0);
|
||||||
dprintf("ret: %d, eof: %d\n", ans, eof);
|
dprintf("ret: %d, eof: %d\n", ans, eof);
|
||||||
@@ -799,6 +578,12 @@ dataunavail:
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
kprintf("ERROR: sending IKC msg, ret: %d\n", ret);
|
kprintf("ERROR: sending IKC msg, ret: %d\n", ret);
|
||||||
}
|
}
|
||||||
|
if(proc)
|
||||||
|
release_process(proc);
|
||||||
|
if(thread)
|
||||||
|
release_thread(thread);
|
||||||
|
if(vm)
|
||||||
|
release_process_vm(vm);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
507
kernel/syscall.c
507
kernel/syscall.c
@@ -113,6 +113,7 @@ extern unsigned long ihk_mc_get_ns_per_tsc(void);
|
|||||||
extern int ptrace_detach(int pid, int data);
|
extern int ptrace_detach(int pid, int data);
|
||||||
extern void debug_log(unsigned long);
|
extern void debug_log(unsigned long);
|
||||||
extern void free_all_process_memory_range(struct process_vm *vm);
|
extern void free_all_process_memory_range(struct process_vm *vm);
|
||||||
|
extern struct cpu_local_var *clv;
|
||||||
|
|
||||||
int prepare_process_ranges_args_envs(struct thread *thread,
|
int prepare_process_ranges_args_envs(struct thread *thread,
|
||||||
struct program_load_desc *pn,
|
struct program_load_desc *pn,
|
||||||
@@ -401,6 +402,12 @@ do_wait(int pid, int *status, int options, void *rusage)
|
|||||||
ret = wait_zombie(thread, child, status, options);
|
ret = wait_zombie(thread, child, status, options);
|
||||||
mcs_rwlock_writer_unlock_noirq(&thread->proc->children_lock, &lock);
|
mcs_rwlock_writer_unlock_noirq(&thread->proc->children_lock, &lock);
|
||||||
if(!(options & WNOWAIT)){
|
if(!(options & WNOWAIT)){
|
||||||
|
mcs_rwlock_writer_lock_noirq(&proc->update_lock, &lock);
|
||||||
|
ts_add(&proc->stime_children, &child->stime);
|
||||||
|
ts_add(&proc->utime_children, &child->utime);
|
||||||
|
ts_add(&proc->stime_children, &child->stime_children);
|
||||||
|
ts_add(&proc->utime_children, &child->utime_children);
|
||||||
|
mcs_rwlock_writer_unlock_noirq(&proc->update_lock, &lock);
|
||||||
release_process(child);
|
release_process(child);
|
||||||
}
|
}
|
||||||
goto out_found;
|
goto out_found;
|
||||||
@@ -632,8 +639,6 @@ terminate(int rc, int sig)
|
|||||||
list_add_tail(&mythread->siblings_list, &proc->threads_list);
|
list_add_tail(&mythread->siblings_list, &proc->threads_list);
|
||||||
mcs_rwlock_writer_unlock(&proc->threads_lock, &lock);
|
mcs_rwlock_writer_unlock(&proc->threads_lock, &lock);
|
||||||
|
|
||||||
delete_proc_procfs_files(proc->pid);
|
|
||||||
|
|
||||||
vm = proc->vm;
|
vm = proc->vm;
|
||||||
free_all_process_memory_range(vm);
|
free_all_process_memory_range(vm);
|
||||||
|
|
||||||
@@ -2036,6 +2041,49 @@ SYSCALL_DECLARE(set_tid_address)
|
|||||||
return cpu_local_var(current)->proc->pid;
|
return cpu_local_var(current)->proc->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned long
|
||||||
|
timespec_to_jiffy(const struct timespec *ats)
|
||||||
|
{
|
||||||
|
return ats->tv_sec * 100 + ats->tv_nsec / 10000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSCALL_DECLARE(times)
|
||||||
|
{
|
||||||
|
struct tms {
|
||||||
|
unsigned long tms_utime;
|
||||||
|
unsigned long tms_stime;
|
||||||
|
unsigned long tms_cutime;
|
||||||
|
unsigned long tms_cstime;
|
||||||
|
};
|
||||||
|
struct tms mytms;
|
||||||
|
struct tms *buf = (struct tms *)ihk_mc_syscall_arg0(ctx);
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
struct process *proc = thread->proc;
|
||||||
|
struct timespec ats;
|
||||||
|
|
||||||
|
mytms.tms_utime = timespec_to_jiffy(&thread->utime);
|
||||||
|
mytms.tms_stime = timespec_to_jiffy(&thread->stime);
|
||||||
|
ats.tv_sec = proc->utime.tv_sec;
|
||||||
|
ats.tv_nsec = proc->utime.tv_nsec;
|
||||||
|
ts_add(&ats, &proc->utime_children);
|
||||||
|
mytms.tms_cutime = timespec_to_jiffy(&ats);
|
||||||
|
ats.tv_sec = proc->stime.tv_sec;
|
||||||
|
ats.tv_nsec = proc->stime.tv_nsec;
|
||||||
|
ts_add(&ats, &proc->stime_children);
|
||||||
|
mytms.tms_cstime = timespec_to_jiffy(&ats);
|
||||||
|
if(copy_to_user(buf, &mytms, sizeof mytms))
|
||||||
|
return -EFAULT;
|
||||||
|
if(gettime_local_support){
|
||||||
|
calculate_time_from_tsc(&ats);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
ats.tv_sec = 0;
|
||||||
|
ats.tv_nsec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return timespec_to_jiffy(&ats);
|
||||||
|
}
|
||||||
|
|
||||||
SYSCALL_DECLARE(kill)
|
SYSCALL_DECLARE(kill)
|
||||||
{
|
{
|
||||||
int pid = ihk_mc_syscall_arg0(ctx);
|
int pid = ihk_mc_syscall_arg0(ctx);
|
||||||
@@ -2077,6 +2125,24 @@ SYSCALL_DECLARE(tgkill)
|
|||||||
return do_kill(thread, tgid, tid, sig, &info, 0);
|
return do_kill(thread, tgid, tid, sig, &info, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SYSCALL_DECLARE(tkill)
|
||||||
|
{
|
||||||
|
int tid = ihk_mc_syscall_arg0(ctx);
|
||||||
|
int sig = ihk_mc_syscall_arg1(ctx);
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
struct siginfo info;
|
||||||
|
|
||||||
|
memset(&info, '\0', sizeof info);
|
||||||
|
info.si_signo = sig;
|
||||||
|
info.si_code = SI_TKILL;
|
||||||
|
info._sifields._kill.si_pid = thread->proc->pid;
|
||||||
|
|
||||||
|
if(tid <= 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
return do_kill(thread, -1, tid, sig, &info, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int *
|
int *
|
||||||
getcred(int *_buf)
|
getcred(int *_buf)
|
||||||
{
|
{
|
||||||
@@ -2359,34 +2425,85 @@ do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SYSCALL_DECLARE(read)
|
||||||
|
{
|
||||||
|
int fd = ihk_mc_syscall_arg0(ctx);
|
||||||
|
long rc;
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
struct process *proc = thread->proc;
|
||||||
|
struct mckfd *fdp;
|
||||||
|
long irqstate;
|
||||||
|
|
||||||
|
irqstate = ihk_mc_spinlock_lock(&proc->mckfd_lock);
|
||||||
|
for(fdp = proc->mckfd; fdp; fdp = fdp->next)
|
||||||
|
if(fdp->fd == fd)
|
||||||
|
break;
|
||||||
|
ihk_mc_spinlock_unlock(&proc->mckfd_lock, irqstate);
|
||||||
|
|
||||||
|
if(fdp && fdp->read_cb){
|
||||||
|
kprintf("read: found system fd %d\n", fd);
|
||||||
|
rc = fdp->read_cb(fdp, ctx);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
rc = syscall_generic_forwarding(__NR_read, ctx);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSCALL_DECLARE(ioctl)
|
||||||
|
{
|
||||||
|
int fd = ihk_mc_syscall_arg0(ctx);
|
||||||
|
long rc;
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
struct process *proc = thread->proc;
|
||||||
|
struct mckfd *fdp;
|
||||||
|
long irqstate;
|
||||||
|
|
||||||
|
irqstate = ihk_mc_spinlock_lock(&proc->mckfd_lock);
|
||||||
|
for(fdp = proc->mckfd; fdp; fdp = fdp->next)
|
||||||
|
if(fdp->fd == fd)
|
||||||
|
break;
|
||||||
|
ihk_mc_spinlock_unlock(&proc->mckfd_lock, irqstate);
|
||||||
|
|
||||||
|
if(fdp && fdp->ioctl_cb){
|
||||||
|
kprintf("ioctl: found system fd %d\n", fd);
|
||||||
|
rc = fdp->ioctl_cb(fdp, ctx);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
rc = syscall_generic_forwarding(__NR_ioctl, ctx);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
SYSCALL_DECLARE(close)
|
SYSCALL_DECLARE(close)
|
||||||
{
|
{
|
||||||
int fd = ihk_mc_syscall_arg0(ctx);
|
int fd = ihk_mc_syscall_arg0(ctx);
|
||||||
int rc;
|
long rc;
|
||||||
struct thread *thread = cpu_local_var(current);
|
struct thread *thread = cpu_local_var(current);
|
||||||
struct sigfd *sfd;
|
struct process *proc = thread->proc;
|
||||||
struct sigfd *sb;
|
struct mckfd *fdp;
|
||||||
long irqstate;
|
struct mckfd *fdq;
|
||||||
|
long irqstate;
|
||||||
|
|
||||||
irqstate = ihk_mc_spinlock_lock(&thread->sigcommon->lock);
|
irqstate = ihk_mc_spinlock_lock(&proc->mckfd_lock);
|
||||||
for(sfd = thread->sigcommon->sigfd, sb = NULL; sfd; sb = sfd, sfd = sfd->next)
|
for(fdp = proc->mckfd, fdq = NULL; fdp; fdq = fdp, fdp = fdp->next)
|
||||||
if(sfd->fd == fd)
|
if(fdp->fd == fd)
|
||||||
break;
|
break;
|
||||||
if(sfd){
|
|
||||||
struct syscall_request request IHK_DMA_ALIGN;
|
if(fdp){
|
||||||
if(sb)
|
kprintf("close: found system fd %d pid=%d\n", fd, proc->pid);
|
||||||
sb->next = sfd->next;
|
if(fdq)
|
||||||
|
fdq->next = fdp->next;
|
||||||
else
|
else
|
||||||
thread->sigcommon->sigfd = sfd->next;
|
proc->mckfd = fdp->next;
|
||||||
ihk_mc_spinlock_unlock(&thread->sigcommon->lock, irqstate);
|
ihk_mc_spinlock_unlock(&proc->mckfd_lock, irqstate);
|
||||||
request.number = __NR_signalfd4;
|
if(fdp->close_cb)
|
||||||
request.args[0] = 1;
|
fdp->close_cb(fdp, ctx);
|
||||||
request.args[1] = sfd->fd;
|
kfree(fdp);
|
||||||
kfree(sfd);
|
rc = syscall_generic_forwarding(__NR_close, ctx);
|
||||||
rc = do_syscall(&request, ihk_mc_get_processor_id(), 0);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ihk_mc_spinlock_unlock(&thread->sigcommon->lock, irqstate);
|
ihk_mc_spinlock_unlock(&proc->mckfd_lock, irqstate);
|
||||||
rc = syscall_generic_forwarding(__NR_close, ctx);
|
rc = syscall_generic_forwarding(__NR_close, ctx);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
@@ -2487,7 +2604,8 @@ SYSCALL_DECLARE(signalfd4)
|
|||||||
{
|
{
|
||||||
int fd = ihk_mc_syscall_arg0(ctx);
|
int fd = ihk_mc_syscall_arg0(ctx);
|
||||||
struct thread *thread = cpu_local_var(current);
|
struct thread *thread = cpu_local_var(current);
|
||||||
struct sigfd *sfd;
|
struct process *proc = thread->proc;
|
||||||
|
struct mckfd *sfd;
|
||||||
long irqstate;
|
long irqstate;
|
||||||
sigset_t *maskp = (sigset_t *)ihk_mc_syscall_arg1(ctx);;
|
sigset_t *maskp = (sigset_t *)ihk_mc_syscall_arg1(ctx);;
|
||||||
__sigset_t mask;
|
__sigset_t mask;
|
||||||
@@ -2501,10 +2619,9 @@ SYSCALL_DECLARE(signalfd4)
|
|||||||
if(flags & ~(SFD_NONBLOCK | SFD_CLOEXEC))
|
if(flags & ~(SFD_NONBLOCK | SFD_CLOEXEC))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
irqstate = ihk_mc_spinlock_lock(&thread->sigcommon->lock);
|
|
||||||
if(fd == -1){
|
if(fd == -1){
|
||||||
struct syscall_request request IHK_DMA_ALIGN;
|
struct syscall_request request IHK_DMA_ALIGN;
|
||||||
ihk_mc_spinlock_unlock(&thread->sigcommon->lock, irqstate);
|
|
||||||
request.number = __NR_signalfd4;
|
request.number = __NR_signalfd4;
|
||||||
request.args[0] = 0;
|
request.args[0] = 0;
|
||||||
request.args[1] = flags;
|
request.args[1] = flags;
|
||||||
@@ -2512,25 +2629,73 @@ SYSCALL_DECLARE(signalfd4)
|
|||||||
if(fd < 0){
|
if(fd < 0){
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
sfd = kmalloc(sizeof(struct sigfd), IHK_MC_AP_NOWAIT);
|
sfd = kmalloc(sizeof(struct mckfd), IHK_MC_AP_NOWAIT);
|
||||||
if(!sfd)
|
if(!sfd)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
sfd->fd = fd;
|
sfd->fd = fd;
|
||||||
irqstate = ihk_mc_spinlock_lock(&thread->sigcommon->lock);
|
irqstate = ihk_mc_spinlock_lock(&proc->mckfd_lock);
|
||||||
sfd->next = thread->sigcommon->sigfd;
|
sfd->next = proc->mckfd;
|
||||||
thread->sigcommon->sigfd = sfd;
|
proc->mckfd = sfd;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
for(sfd = thread->sigcommon->sigfd; sfd; sfd = sfd->next)
|
irqstate = ihk_mc_spinlock_lock(&proc->mckfd_lock);
|
||||||
|
for(sfd = proc->mckfd; sfd; sfd = sfd->next)
|
||||||
if(sfd->fd == fd)
|
if(sfd->fd == fd)
|
||||||
break;
|
break;
|
||||||
if(!sfd){
|
if(!sfd){
|
||||||
ihk_mc_spinlock_unlock(&thread->sigcommon->lock, irqstate);
|
ihk_mc_spinlock_unlock(&proc->mckfd_lock, irqstate);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(&sfd->mask, &mask, sizeof mask);
|
memcpy(&sfd->data, &mask, sizeof mask);
|
||||||
ihk_mc_spinlock_unlock(&thread->sigcommon->lock, irqstate);
|
ihk_mc_spinlock_unlock(&proc->mckfd_lock, irqstate);
|
||||||
|
return sfd->fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
perf_event_read(struct mckfd *sfd, ihk_mc_user_context_t *ctx)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
perf_event_ioctl(struct mckfd *sfd, ihk_mc_user_context_t *ctx)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
perf_event_close(struct mckfd *sfd, ihk_mc_user_context_t *ctx)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSCALL_DECLARE(perf_event_open)
|
||||||
|
{
|
||||||
|
struct syscall_request request IHK_DMA_ALIGN;
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
struct process *proc = thread->proc;
|
||||||
|
struct mckfd *sfd;
|
||||||
|
int fd;
|
||||||
|
long irqstate;
|
||||||
|
|
||||||
|
request.number = __NR_perf_event_open;
|
||||||
|
request.args[0] = 0;
|
||||||
|
fd = do_syscall(&request, ihk_mc_get_processor_id(), 0);
|
||||||
|
if(fd < 0){
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
sfd = kmalloc(sizeof(struct mckfd), IHK_MC_AP_NOWAIT);
|
||||||
|
if(!sfd)
|
||||||
|
return -ENOMEM;
|
||||||
|
sfd->fd = fd;
|
||||||
|
sfd->read_cb = perf_event_read;
|
||||||
|
sfd->ioctl_cb = perf_event_ioctl;
|
||||||
|
sfd->close_cb = perf_event_close;
|
||||||
|
irqstate = ihk_mc_spinlock_lock(&proc->mckfd_lock);
|
||||||
|
sfd->next = proc->mckfd;
|
||||||
|
proc->mckfd = sfd;
|
||||||
|
ihk_mc_spinlock_unlock(&proc->mckfd_lock, irqstate);
|
||||||
return sfd->fd;
|
return sfd->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5073,6 +5238,125 @@ static void calculate_time_from_tsc(struct timespec *ts)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SYSCALL_DECLARE(setitimer)
|
||||||
|
{
|
||||||
|
int which = (int)ihk_mc_syscall_arg0(ctx);
|
||||||
|
struct itimerval *new = (struct itimerval *)ihk_mc_syscall_arg1(ctx);
|
||||||
|
struct itimerval *old = (struct itimerval *)ihk_mc_syscall_arg2(ctx);
|
||||||
|
struct syscall_request request IHK_DMA_ALIGN;
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
int timer_start = 1;
|
||||||
|
struct itimerval wkval;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
if(which != ITIMER_REAL &&
|
||||||
|
which != ITIMER_VIRTUAL &&
|
||||||
|
which != ITIMER_PROF)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if(which == ITIMER_REAL){
|
||||||
|
request.number = __NR_setitimer;
|
||||||
|
request.args[0] = ihk_mc_syscall_arg0(ctx);
|
||||||
|
request.args[1] = ihk_mc_syscall_arg1(ctx);
|
||||||
|
request.args[2] = ihk_mc_syscall_arg2(ctx);
|
||||||
|
|
||||||
|
return do_syscall(&request, ihk_mc_get_processor_id(), 0);
|
||||||
|
}
|
||||||
|
else if(which == ITIMER_VIRTUAL){
|
||||||
|
if(old){
|
||||||
|
memcpy(&wkval, &thread->itimer_virtual, sizeof wkval);
|
||||||
|
if(wkval.it_value.tv_sec != 0 ||
|
||||||
|
wkval.it_value.tv_usec != 0){
|
||||||
|
ts_to_tv(&tv, &thread->itimer_virtual_value);
|
||||||
|
tv_sub(&wkval.it_value, &tv);
|
||||||
|
}
|
||||||
|
if(copy_to_user(old, &wkval, sizeof wkval))
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
if(!new){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(copy_from_user(&thread->itimer_virtual, new, sizeof(struct itimerval)))
|
||||||
|
thread->itimer_virtual_value.tv_sec = 0;
|
||||||
|
thread->itimer_virtual_value.tv_nsec = 0;
|
||||||
|
if(thread->itimer_virtual.it_value.tv_sec == 0 &&
|
||||||
|
thread->itimer_virtual.it_value.tv_usec == 0)
|
||||||
|
timer_start = 0;
|
||||||
|
}
|
||||||
|
else if(which == ITIMER_PROF){
|
||||||
|
if(old){
|
||||||
|
memcpy(&wkval, &thread->itimer_prof, sizeof wkval);
|
||||||
|
if(wkval.it_value.tv_sec != 0 ||
|
||||||
|
wkval.it_value.tv_usec != 0){
|
||||||
|
ts_to_tv(&tv, &thread->itimer_prof_value);
|
||||||
|
tv_sub(&wkval.it_value, &tv);
|
||||||
|
}
|
||||||
|
if(copy_to_user(old, &wkval, sizeof wkval))
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
if(!new){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(copy_from_user(&thread->itimer_prof, new, sizeof(struct itimerval)))
|
||||||
|
thread->itimer_prof_value.tv_sec = 0;
|
||||||
|
thread->itimer_prof_value.tv_nsec = 0;
|
||||||
|
if(thread->itimer_prof.it_value.tv_sec == 0 &&
|
||||||
|
thread->itimer_prof.it_value.tv_usec == 0)
|
||||||
|
timer_start = 0;
|
||||||
|
}
|
||||||
|
thread->itimer_enabled = timer_start;
|
||||||
|
set_timer();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSCALL_DECLARE(getitimer)
|
||||||
|
{
|
||||||
|
int which = (int)ihk_mc_syscall_arg0(ctx);
|
||||||
|
struct itimerval *old = (struct itimerval *)ihk_mc_syscall_arg1(ctx);
|
||||||
|
struct syscall_request request IHK_DMA_ALIGN;
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
struct itimerval wkval;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
if(which != ITIMER_REAL &&
|
||||||
|
which != ITIMER_VIRTUAL &&
|
||||||
|
which != ITIMER_PROF)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if(which == ITIMER_REAL){
|
||||||
|
request.number = __NR_getitimer;
|
||||||
|
request.args[0] = ihk_mc_syscall_arg0(ctx);
|
||||||
|
request.args[1] = ihk_mc_syscall_arg1(ctx);
|
||||||
|
|
||||||
|
return do_syscall(&request, ihk_mc_get_processor_id(), 0);
|
||||||
|
}
|
||||||
|
else if(which == ITIMER_VIRTUAL){
|
||||||
|
if(old){
|
||||||
|
memcpy(&wkval, &thread->itimer_virtual, sizeof wkval);
|
||||||
|
if(wkval.it_value.tv_sec != 0 ||
|
||||||
|
wkval.it_value.tv_usec != 0){
|
||||||
|
ts_to_tv(&tv, &thread->itimer_virtual_value);
|
||||||
|
tv_sub(&wkval.it_value, &tv);
|
||||||
|
}
|
||||||
|
if(copy_to_user(old, &wkval, sizeof wkval))
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(which == ITIMER_PROF){
|
||||||
|
if(old){
|
||||||
|
memcpy(&wkval, &thread->itimer_prof, sizeof wkval);
|
||||||
|
if(wkval.it_value.tv_sec != 0 ||
|
||||||
|
wkval.it_value.tv_usec != 0){
|
||||||
|
ts_to_tv(&tv, &thread->itimer_prof_value);
|
||||||
|
tv_sub(&wkval.it_value, &tv);
|
||||||
|
}
|
||||||
|
if(copy_to_user(old, &wkval, sizeof wkval))
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
SYSCALL_DECLARE(clock_gettime)
|
SYSCALL_DECLARE(clock_gettime)
|
||||||
{
|
{
|
||||||
/* TODO: handle clock_id */
|
/* TODO: handle clock_id */
|
||||||
@@ -5096,6 +5380,41 @@ SYSCALL_DECLARE(clock_gettime)
|
|||||||
dkprintf("clock_gettime(): %d\n", error);
|
dkprintf("clock_gettime(): %d\n", error);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
else if(clock_id == CLOCK_PROCESS_CPUTIME_ID){
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
struct process *proc = thread->proc;
|
||||||
|
struct thread *child;
|
||||||
|
struct mcs_rwlock_node lock;
|
||||||
|
|
||||||
|
mcs_rwlock_reader_lock_noirq(&proc->children_lock, &lock);
|
||||||
|
list_for_each_entry(child, &proc->threads_list, siblings_list){
|
||||||
|
if(child != thread &&
|
||||||
|
child->status == PS_RUNNING &&
|
||||||
|
!child->in_kernel){
|
||||||
|
child->times_update = 0;
|
||||||
|
ihk_mc_interrupt_cpu(get_x86_cpu_local_variable(child->cpu_id)->apic_id, 0xd1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ats.tv_sec = proc->utime.tv_sec;
|
||||||
|
ats.tv_nsec = proc->utime.tv_nsec;
|
||||||
|
ts_add(&ats, &proc->stime);
|
||||||
|
list_for_each_entry(child, &proc->threads_list, siblings_list){
|
||||||
|
while(!child->times_update)
|
||||||
|
cpu_pause();
|
||||||
|
ts_add(&ats, &child->utime);
|
||||||
|
ts_add(&ats, &child->stime);
|
||||||
|
}
|
||||||
|
mcs_rwlock_reader_unlock_noirq(&proc->children_lock, &lock);
|
||||||
|
return copy_to_user(ts, &ats, sizeof ats);
|
||||||
|
}
|
||||||
|
else if(clock_id == CLOCK_THREAD_CPUTIME_ID){
|
||||||
|
struct thread *thread = cpu_local_var(current);
|
||||||
|
|
||||||
|
ats.tv_sec = thread->utime.tv_sec;
|
||||||
|
ats.tv_nsec = thread->utime.tv_nsec;
|
||||||
|
ts_add(&ats, &thread->stime);
|
||||||
|
return copy_to_user(ts, &ats, sizeof ats);
|
||||||
|
}
|
||||||
|
|
||||||
/* Otherwise offload */
|
/* Otherwise offload */
|
||||||
request.number = __NR_clock_gettime;
|
request.number = __NR_clock_gettime;
|
||||||
@@ -6489,13 +6808,136 @@ SYSCALL_DECLARE(pmc_reset)
|
|||||||
return ihk_mc_perfctr_reset(counter);
|
return ihk_mc_perfctr_reset(counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
reset_cputime()
|
||||||
|
{
|
||||||
|
struct thread *thread;
|
||||||
|
|
||||||
|
if(clv == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!(thread = cpu_local_var(current)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
thread->btime.tv_sec = 0;
|
||||||
|
thread->btime.tv_nsec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mode == 0: kernel -> user
|
||||||
|
* mode == 1: user -> kernel
|
||||||
|
* mode == 2: kernel -> kernel
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
set_cputime(int mode)
|
||||||
|
{
|
||||||
|
struct thread *thread;
|
||||||
|
struct timespec ats;
|
||||||
|
struct cpu_local_var *v;
|
||||||
|
|
||||||
|
if(clv == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
v = get_this_cpu_local_var();
|
||||||
|
if(!(thread = v->current))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!gettime_local_support){
|
||||||
|
thread->times_update = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
calculate_time_from_tsc(&ats);
|
||||||
|
if(thread->btime.tv_sec != 0 && thread->btime.tv_nsec != 0){
|
||||||
|
struct timespec dts;
|
||||||
|
|
||||||
|
dts.tv_sec = ats.tv_sec;
|
||||||
|
dts.tv_nsec = ats.tv_nsec;
|
||||||
|
ts_sub(&dts, &thread->btime);
|
||||||
|
if(mode == 1){
|
||||||
|
ts_add(&thread->utime, &dts);
|
||||||
|
ts_add(&thread->itimer_virtual_value, &dts);
|
||||||
|
ts_add(&thread->itimer_prof_value, &dts);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
ts_add(&thread->stime, &dts);
|
||||||
|
ts_add(&thread->itimer_prof_value, &dts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mode == 2){
|
||||||
|
thread->btime.tv_sec = 0;
|
||||||
|
thread->btime.tv_nsec = 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
thread->btime.tv_sec = ats.tv_sec;
|
||||||
|
thread->btime.tv_nsec = ats.tv_nsec;
|
||||||
|
}
|
||||||
|
thread->times_update = 1;
|
||||||
|
thread->in_kernel = mode;
|
||||||
|
|
||||||
|
if(thread->itimer_enabled){
|
||||||
|
struct timeval tv;
|
||||||
|
int ev = 0;
|
||||||
|
|
||||||
|
if(thread->itimer_virtual.it_value.tv_sec != 0 ||
|
||||||
|
thread->itimer_virtual.it_value.tv_usec){
|
||||||
|
ts_to_tv(&tv, &thread->itimer_virtual_value);
|
||||||
|
tv_sub(&tv, &thread->itimer_virtual.it_value);
|
||||||
|
if(tv.tv_sec > 0 ||
|
||||||
|
(tv.tv_sec == 0 &&
|
||||||
|
tv.tv_usec > 0)){
|
||||||
|
thread->itimer_virtual_value.tv_sec = 0;
|
||||||
|
thread->itimer_virtual_value.tv_nsec = 0;
|
||||||
|
thread->itimer_virtual.it_value.tv_sec =
|
||||||
|
thread->itimer_virtual.it_interval.tv_sec;
|
||||||
|
thread->itimer_virtual.it_value.tv_usec =
|
||||||
|
thread->itimer_virtual.it_interval.tv_usec;
|
||||||
|
do_kill(thread, thread->proc->pid, thread->tid,
|
||||||
|
SIGVTALRM, NULL, 0);
|
||||||
|
ev = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(thread->itimer_prof.it_value.tv_sec != 0 ||
|
||||||
|
thread->itimer_prof.it_value.tv_usec){
|
||||||
|
ts_to_tv(&tv, &thread->itimer_prof_value);
|
||||||
|
tv_sub(&tv, &thread->itimer_prof.it_value);
|
||||||
|
if(tv.tv_sec > 0 ||
|
||||||
|
(tv.tv_sec == 0 &&
|
||||||
|
tv.tv_usec > 0)){
|
||||||
|
thread->itimer_prof_value.tv_sec = 0;
|
||||||
|
thread->itimer_prof_value.tv_nsec = 0;
|
||||||
|
thread->itimer_prof.it_value.tv_sec =
|
||||||
|
thread->itimer_prof.it_interval.tv_sec;
|
||||||
|
thread->itimer_prof.it_value.tv_usec =
|
||||||
|
thread->itimer_prof.it_interval.tv_usec;
|
||||||
|
do_kill(thread, thread->proc->pid, thread->tid,
|
||||||
|
SIGPROF, NULL, 0);
|
||||||
|
ev = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(ev){
|
||||||
|
if(thread->itimer_virtual.it_value.tv_sec == 0 &&
|
||||||
|
thread->itimer_virtual.it_value.tv_usec == 0 &&
|
||||||
|
thread->itimer_prof.it_value.tv_sec == 0 &&
|
||||||
|
thread->itimer_prof.it_value.tv_usec == 0){
|
||||||
|
thread->itimer_enabled = 0;
|
||||||
|
set_timer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long syscall(int num, ihk_mc_user_context_t *ctx)
|
long syscall(int num, ihk_mc_user_context_t *ctx)
|
||||||
{
|
{
|
||||||
long l;
|
long l;
|
||||||
|
|
||||||
|
set_cputime(1);
|
||||||
if(cpu_local_var(current)->proc->status == PS_EXITED &&
|
if(cpu_local_var(current)->proc->status == PS_EXITED &&
|
||||||
(num != __NR_exit && num != __NR_exit_group)){
|
(num != __NR_exit && num != __NR_exit_group)){
|
||||||
check_signal(-EINVAL, NULL, 0);
|
check_signal(-EINVAL, NULL, 0);
|
||||||
|
set_cputime(0);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6554,5 +6996,6 @@ long syscall(int num, ihk_mc_user_context_t *ctx)
|
|||||||
ptrace_syscall_exit(cpu_local_var(current));
|
ptrace_syscall_exit(cpu_local_var(current));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_cputime(0);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|||||||
12
lib/string.c
12
lib/string.c
@@ -223,7 +223,7 @@ int flatten_strings(int nr_strings, char *first, char **strings, char **flat)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Count full length */
|
/* Count full length */
|
||||||
full_len = sizeof(int) + sizeof(char *); // Counter and terminating NULL
|
full_len = sizeof(long) + sizeof(char *); // Counter and terminating NULL
|
||||||
if (first) {
|
if (first) {
|
||||||
full_len += sizeof(char *) + strlen(first) + 1;
|
full_len += sizeof(char *) + strlen(first) + 1;
|
||||||
}
|
}
|
||||||
@@ -233,6 +233,8 @@ int flatten_strings(int nr_strings, char *first, char **strings, char **flat)
|
|||||||
full_len += sizeof(char *) + strlen(strings[string_i]) + 1;
|
full_len += sizeof(char *) + strlen(strings[string_i]) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
full_len = (full_len + sizeof(long) - 1) & ~(sizeof(long) - 1);
|
||||||
|
|
||||||
_flat = (char *)kmalloc(full_len, IHK_MC_AP_NOWAIT);
|
_flat = (char *)kmalloc(full_len, IHK_MC_AP_NOWAIT);
|
||||||
if (!_flat) {
|
if (!_flat) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -241,14 +243,14 @@ int flatten_strings(int nr_strings, char *first, char **strings, char **flat)
|
|||||||
memset(_flat, 0, full_len);
|
memset(_flat, 0, full_len);
|
||||||
|
|
||||||
/* Number of strings */
|
/* Number of strings */
|
||||||
*((int*)_flat) = nr_strings + (first ? 1 : 0);
|
*((long *)_flat) = nr_strings + (first ? 1 : 0);
|
||||||
|
|
||||||
// Actual offset
|
// Actual offset
|
||||||
flat_offset = sizeof(int) + sizeof(char *) * (nr_strings + 1 +
|
flat_offset = sizeof(long) + sizeof(char *) * (nr_strings + 1 +
|
||||||
(first ? 1 : 0));
|
(first ? 1 : 0));
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
*((char **)(_flat + sizeof(int))) = (void *)flat_offset;
|
*((char **)(_flat + sizeof(long))) = (void *)flat_offset;
|
||||||
memcpy(_flat + flat_offset, first, strlen(first) + 1);
|
memcpy(_flat + flat_offset, first, strlen(first) + 1);
|
||||||
flat_offset += strlen(first) + 1;
|
flat_offset += strlen(first) + 1;
|
||||||
}
|
}
|
||||||
@@ -256,7 +258,7 @@ int flatten_strings(int nr_strings, char *first, char **strings, char **flat)
|
|||||||
for (string_i = 0; string_i < nr_strings; ++string_i) {
|
for (string_i = 0; string_i < nr_strings; ++string_i) {
|
||||||
|
|
||||||
/* Fabricate the string */
|
/* Fabricate the string */
|
||||||
*((char **)(_flat + sizeof(int) + (string_i + (first ? 1 : 0))
|
*((char **)(_flat + sizeof(long) + (string_i + (first ? 1 : 0))
|
||||||
* sizeof(char *))) = (void *)flat_offset;
|
* sizeof(char *))) = (void *)flat_offset;
|
||||||
memcpy(_flat + flat_offset, strings[string_i], strlen(strings[string_i]) + 1);
|
memcpy(_flat + flat_offset, strings[string_i], strlen(strings[string_i]) + 1);
|
||||||
flat_offset += strlen(strings[string_i]) + 1;
|
flat_offset += strlen(strings[string_i]) + 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user