add arm64 support

- add arm64 dependent codes with GICv3 and SVE support
- fix bugs based on architecture separation requests
This commit is contained in:
Takayuki Okamoto
2017-09-05 15:06:27 +09:00
parent 704096b139
commit 9989f41fd3
192 changed files with 26941 additions and 34 deletions

View File

@@ -1,3 +1,4 @@
# Makefile.in COPYRIGHT FUJITSU LIMITED 2015-2016
CC=@CC@
MCC=mpicc
BINDIR=@BINDIR@
@@ -25,13 +26,19 @@ ifeq ($(ENABLE_QLMPI),yes)
TARGET+= libqlmpi.so ql_server ql_mpiexec_start ql_mpiexec_finalize ql_talker libqlfort.so
endif
CFLAGS += $(foreach i, $(shell seq 1 100), $(addprefix -DPOSTK_DEBUG_ARCH_DEP_, $(i)))
CFLAGS += $(foreach i, $(shell seq 1 100), $(addprefix -DPOSTK_DEBUG_TEMP_FIX_, $(i)))
all: $(TARGET)
mcexec: mcexec.c libmcexec.a
$(CC) -I${KDIR} $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) -DLIBDIR=\"$(LIBDIR)\" -fPIE -pie -L. $(MCEXEC_LIBS) -o $@ $^ $(EXTRA_OBJS) $(RPATH)
eclair: eclair.c
$(CC) $(CFLAGS) -I${IHKDIR} -o $@ $^ $(LIBS)
# POSTK_DEBUG_ARCH_DEP_34, eclair arch depend separate.
#eclair: eclair.c
# $(CC) $(CFLAGS) -I${IHKDIR} -o $@ $^ $(LIBS)
eclair: eclair.c arch/$(ARCH)/arch-eclair.c
$(CC) -I.. -I. -I./arch/$(ARCH)/include -I${IHKDIR} $(CFLAGS) -o $@ $^ $(LIBS)
libsched_yield: libsched_yield.c
$(CC) -shared -fPIC -Wl,-soname,sched_yield.so.1 -o libsched_yield.so.1.0.0 $^ -lc -ldl

View File

@@ -0,0 +1,23 @@
CC=@CC@
AR=ar
BINDIR=@BINDIR@
KDIR ?= @KDIR@
CFLAGS=-Wall -O -I.
VPATH=@abs_srcdir@
TARGET=../../libmcexec.a
LIBS=@LIBS@
all: $(TARGET)
../../libmcexec.a: archdep.o
$(AR) cr ../../libmcexec.a archdep.o
archdep.o: archdep.S
$(CC) -c -I${KDIR} $(CFLAGS) $(EXTRA_CFLAGS) -fPIE -pie -pthread $<
clean:
$(RM) $(TARGET) *.o
.PHONY: all clean install
install:

View File

@@ -0,0 +1,51 @@
/* arch-eclair.c COPYRIGHT FUJITSU LIMITED 2016 */
#include <stdio.h>
#include <eclair.h>
#include <arch-eclair.h>
int print_kregs(char *rbp, size_t rbp_size, const struct arch_kregs *kregs)
{
int i, ret, total = 0;
const unsigned long *regs[] = {&kregs->x19, &kregs->x20, &kregs->x21,
&kregs->x22, &kregs->x23, &kregs->x24,
&kregs->x25, &kregs->x26, &kregs->x27,
&kregs->x28};
for (i = 0; i < 18; i++) /* x0-x18 */{
ret = snprintf(rbp, rbp_size, "xxxxxxxxxxxxxxxx");
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
}
for (i = 0; i < sizeof(regs)/sizeof(regs[0]); i++) { /* x19-x28 */
ret = print_bin(rbp, rbp_size, (void *)regs[i], sizeof(*regs[0]));
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
}
for (i = 0; i < 2; i++) { /* x29-x30 */
ret = snprintf(rbp, rbp_size, "xxxxxxxxxxxxxxxx");
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
}
ret += print_bin(rbp, rbp_size, (void *)&kregs->sp, sizeof(kregs->sp));
if (ret < 0) {
return ret;
}
total += ret;
return total;
}

View File

@@ -0,0 +1,126 @@
/* arch_args.h COPYRIGHT FUJITSU LIMITED 2017 */
#ifndef ARCH_ARGS_H
#define ARCH_ARGS_H
#include <asm/ptrace.h>
typedef struct user_pt_regs syscall_args;
static inline int
get_syscall_args(int pid, syscall_args *args)
{
/* TODO: skeleton for UTI */
return -1;
}
static inline int
set_syscall_args(int pid, syscall_args *args)
{
/* TODO: skeleton for UTI */
return -1;
}
static inline unsigned long
get_syscall_number(syscall_args *args)
{
/* TODO: skeleton for UTI */
return 0;
}
static inline unsigned long
get_syscall_return(syscall_args *args)
{
/* TODO: skeleton for UTI */
return 0;
}
static inline unsigned long
get_syscall_arg1(syscall_args *args)
{
/* TODO: skeleton for UTI */
return 0;
}
static inline unsigned long
get_syscall_arg2(syscall_args *args)
{
/* TODO: skeleton for UTI */
return 0;
}
static inline unsigned long
get_syscall_arg3(syscall_args *args)
{
/* TODO: skeleton for UTI */
return 0;
}
static inline unsigned long
get_syscall_arg4(syscall_args *args)
{
/* TODO: skeleton for UTI */
return 0;
}
static inline unsigned long
get_syscall_arg5(syscall_args *args)
{
/* TODO: skeleton for UTI */
return 0;
}
static inline unsigned long
get_syscall_arg6(syscall_args *args)
{
/* TODO: skeleton for UTI */
return 0;
}
static inline void
set_syscall_number(syscall_args *args, unsigned long value)
{
/* TODO: skeleton for UTI */
}
static inline void
set_syscall_return(syscall_args *args, unsigned long value)
{
/* TODO: skeleton for UTI */
}
static inline void
set_syscall_arg1(syscall_args *args, unsigned long value)
{
/* TODO: skeleton for UTI */
}
static inline void
set_syscall_arg2(syscall_args *args, unsigned long value)
{
/* TODO: skeleton for UTI */
}
static inline void
set_syscall_arg3(syscall_args *args, unsigned long value)
{
/* TODO: skeleton for UTI */
}
static inline void
set_syscall_arg4(syscall_args *args, unsigned long value)
{
/* TODO: skeleton for UTI */
}
static inline void
set_syscall_arg5(syscall_args *args, unsigned long value)
{
/* TODO: skeleton for UTI */
}
static inline void
set_syscall_arg6(syscall_args *args, unsigned long value)
{
/* TODO: skeleton for UTI */
}
#endif /* !ARCH_ARGS_H */

View File

@@ -0,0 +1,16 @@
/* archdep.S COPYRIGHT FUJITSU LIMITED 2017 */
/* TODO: skeleton for UTI */
.global switch_ctx
switch_ctx:
ret
/* TODO: skeleton for UTI */
.global compare_and_swap
compare_and_swap:
ret
/* TODO: skeleton for UTI */
.global compare_and_swap_int
compare_and_swap_int:
ret

View File

@@ -0,0 +1,24 @@
/* arch-eclair.h COPYRIGHT FUJITSU LIMITED 2016 */
#ifndef HEADER_USER_ARM64_ECLAIR_H
#define HEADER_USER_ARM64_ECLAIR_H
/* VA_BITS=48, 4K_PAGE address */
#define MAP_KERNEL 0xffffffffff800000
#define MAP_ST 0xffff800000000000
#define MAP_KERNEL_TEXT "0xffffffffff800000"
#define ARCH_CLV_SPAN "arm64_cpu_local_variables_span"
#define ARCH "aarch64"
#define ARCH_REGS 34
#define PANIC_REGS_OFFSET 144
struct arch_kregs {
unsigned long x19, x20, x21, x22, x23;
unsigned long x24, x25, x26, x27, x28;
unsigned long fp, sp, pc;
};
#endif /* HEADER_USER_ARM64_ECLAIR_H */

View File

@@ -0,0 +1,101 @@
/* arch-eclair.c COPYRIGHT FUJITSU LIMITED 2016 */
#include <eclair.h>
#include <stdio.h>
#include <arch-eclair.h>
int print_kregs(char *rbp, size_t rbp_size, const struct arch_kregs *kregs)
{
int i, ret, total = 0;
uintptr_t ihk_mc_switch_context = -1;
const uint64_t *regs_1[] = {&kregs->rsi, &kregs->rdi, &kregs->rbp,
&kregs->rsp};
const uint64_t *regs_2[] = {&kregs->r12, &kregs->r13, &kregs->r14,
&kregs->r15};
ihk_mc_switch_context = lookup_symbol("ihk_mc_switch_context");
if (0) printf("ihk_mc_switch_context: %lx\n", ihk_mc_switch_context);
ret = snprintf(rbp, rbp_size, "xxxxxxxxxxxxxxxx"); /* rax */
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
ret += print_bin(rbp, rbp_size, (void *)&kregs->rbx, sizeof(uint64_t)); /* rbx */
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
for (i = 0; i < 2; i++){ /* rcx, rdx */
ret = snprintf(rbp, rbp_size, "xxxxxxxxxxxxxxxx");
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
}
for (i = 0; i < sizeof(regs_1)/sizeof(regs_1[0]); i++) { /* rsi, rdi, rbp, rsp */
ret = print_bin(rbp, rbp_size, (void *)regs_1[i], sizeof(regs_1[0]));
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
}
for (i = 0; i < 4; i++) { /* r8-x11 */
ret = snprintf(rbp, rbp_size, "xxxxxxxxxxxxxxxx");
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
}
for (i = 0; i < sizeof(regs_2)/sizeof(regs_2[0]); i++) { /* r12-r15 */
ret = print_bin(rbp, rbp_size, (void *)regs_2[i], sizeof(regs_2[0]));
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
}
ret += print_bin(rbp, rbp_size, (void *)&ihk_mc_switch_context, sizeof(uint64_t)); /* rip */
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
ret += print_bin(rbp, rbp_size, (void *)&kregs->rflags, sizeof(uint32_t)); /* rflags */
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
for (i = 0; i < 6; i++) { /* cs, ss, ds, es, fs, gs */
ret = snprintf(rbp, rbp_size, "xxxxxxxx");
if (ret < 0) {
return ret;
}
rbp += ret;
total += ret;
rbp_size -= ret;
}
return total;
}

View File

@@ -1,6 +1,10 @@
#ifndef ARCH_ARGS_H
#define ARCH_ARGS_H
#ifdef POSTK_DEBUG_ARCH_DEP_77 /* arch depend hide */
#include <asm/prctl.h>
#endif /* !POSTK_DEBUG_ARCH_DEP_77 */
typedef struct user_regs_struct syscall_args;
static inline int

View File

@@ -0,0 +1,24 @@
/* arch-eclair.h COPYRIGHT FUJITSU LIMITED 2016 */
#ifndef HEADER_USER_X86_ECLAIR_H
#define HEADER_USER_X86_ECLAIR_H
#define MAP_KERNEL 0xFFFFFFFF80000000
#define MAP_ST 0xFFFF800000000000
#define ARCH_CLV_SPAN "x86_cpu_local_variables_span"
#define ARCH "i386:x86-64"
#define ARCH_REGS 21
#define PANIC_REGS_OFFSET 240
#define MAP_KERNEL_TEXT "0xffffffff80001000"
struct arch_kregs {
uintptr_t rsp, rbp, rbx, rsi;
uintptr_t rdi, r12, r13, r14;
uintptr_t r15, rflags, rsp0;
};
#endif /* HEADER_USER_x86_ECLAIR_H */

View File

@@ -1,3 +1,4 @@
/* eclair.c COPYRIGHT FUJITSU LIMITED 2016 */
/**
* \file eclair.c
* License details are found in the file LICENSE.
@@ -7,6 +8,9 @@
* Copyright (C) 2015 RIKEN AICS
*/
#ifdef POSTK_DEBUG_ARCH_DEP_33
#include "../config.h"
#endif /* POSTK_DEBUG_ARCH_DEP_33 */
#include <bfd.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -18,6 +22,10 @@
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <ihk/ihk_host_user.h>
#ifdef POSTK_DEBUG_ARCH_DEP_34
#include <eclair.h>
#include <arch-eclair.h>
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
#define CPU_TID_BASE 1000000
@@ -51,7 +59,11 @@ struct thread_info {
int idle;
uintptr_t process;
uintptr_t clv;
#ifdef POSTK_DEBUG_ARCH_DEP_34
uintptr_t arch_clv;
#else /* POSTK_DEBUG_ARCH_DEP_34 */
uintptr_t x86_clv;
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
}; /* struct thread_info */
static struct options opt;
@@ -67,9 +79,15 @@ static uintptr_t kernel_base;
static struct thread_info *tihead = NULL;
static struct thread_info **titailp = &tihead;
static struct thread_info *curr_thread = NULL;
#ifndef POSTK_DEBUG_ARCH_DEP_34
static uintptr_t ihk_mc_switch_context = -1;
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
#ifdef POSTK_DEBUG_ARCH_DEP_34
uintptr_t lookup_symbol(char *name) {
#else /* POSTK_DEBUG_ARCH_DEP_34 */
static uintptr_t lookup_symbol(char *name) {
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
int i;
for (i = 0; i < nsyms; ++i) {
@@ -81,12 +99,17 @@ static uintptr_t lookup_symbol(char *name) {
return NOSYMBOL;
} /* lookup_symbol() */
static uintptr_t virt_to_phys(uintptr_t va) {
#ifndef POSTK_DEBUG_ARCH_DEP_34
#define MAP_KERNEL 0xFFFFFFFF80000000
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
if (va >= MAP_KERNEL) {
return (va - MAP_KERNEL + kernel_base);
}
#ifndef POSTK_DEBUG_ARCH_DEP_34
#define MAP_ST 0xFFFF800000000000
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
if (va >= MAP_ST) {
return (va - MAP_ST);
}
@@ -270,9 +293,17 @@ static int setup_threads(void) {
return 1;
}
#ifdef POSTK_DEBUG_ARCH_DEP_34
error = read_symbol_64(ARCH_CLV_SPAN, &locals_span);
#else /* POSTK_DEBUG_ARCH_DEP_34 */
error = read_symbol_64("x86_cpu_local_variables_span", &locals_span);
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
if (error) {
#ifdef POSTK_DEBUG_ARCH_DEP_34
locals_span = sysconf(_SC_PAGESIZE);
#else /* POSTK_DEBUG_ARCH_DEP_34 */
locals_span = 4096;
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
}
if (0) printf("locals 0x%lx span 0x%lx\n", locals, locals_span);
@@ -282,8 +313,10 @@ static int setup_threads(void) {
return 1;
}
#ifndef POSTK_DEBUG_ARCH_DEP_34
ihk_mc_switch_context = lookup_symbol("ihk_mc_switch_context");
if (0) printf("ihk_mc_switch_context: %lx\n", ihk_mc_switch_context);
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
for (cpu = 0; cpu < num_processors; ++cpu) {
uintptr_t v;
@@ -354,7 +387,11 @@ static int setup_threads(void) {
ti->process = thread;
ti->idle = 0;
ti->clv = v;
#ifdef POSTK_DEBUG_ARCH_DEP_34
ti->arch_clv = locals + locals_span*cpu;
#else /* POSTK_DEBUG_ARCH_DEP_34 */
ti->x86_clv = locals + locals_span*cpu;
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
*titailp = ti;
titailp = &ti->next;
@@ -430,7 +467,11 @@ static int setup_threads(void) {
ti->process = thread;
ti->idle = 1;
ti->clv = v;
#ifdef POSTK_DEBUG_ARCH_DEP_34
ti->arch_clv = locals + locals_span*cpu;
#else /* POSTK_DEBUG_ARCH_DEP_34 */
ti->x86_clv = locals + locals_span*cpu;
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
*titailp = ti;
titailp = &ti->next;
@@ -484,7 +525,11 @@ static int setup_threads(void) {
ti->process = current;
ti->idle = 1;
ti->clv = v;
#ifdef POSTK_DEBUG_ARCH_DEP_34
ti->arch_clv = locals + locals_span*cpu;
#else /* POSTK_DEBUG_ARCH_DEP_34 */
ti->x86_clv = locals + locals_span*cpu;
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
*titailp = ti;
titailp = &ti->next;
@@ -506,7 +551,12 @@ static int setup_symbols(char *fname) {
ssize_t needs;
bfd_boolean ok;
#ifdef POSTK_DEBUG_ARCH_DEP_34
symbfd = bfd_openr(fname, NULL);
#else /* POSTK_DEBUG_ARCH_DEP_34 */
symbfd = bfd_openr(fname, "elf64-x86-64");
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
if (!symbfd) {
bfd_perror("bfd_openr");
return 1;
@@ -547,7 +597,11 @@ static int setup_symbols(char *fname) {
static int setup_dump(char *fname) {
bfd_boolean ok;
#ifdef POSTK_DEBUG_ARCH_DEP_34
dumpbfd = bfd_fopen(opt.dump_path, NULL, "r", -1);
#else /* POSTK_DEBUG_ARCH_DEP_34 */
dumpbfd = bfd_fopen(opt.dump_path, "elf64-x86-64", "r", -1);
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
if (!dumpbfd) {
bfd_perror("bfd_fopen");
return 1;
@@ -589,20 +643,40 @@ static int setup_dump(char *fname) {
return 0;
} /* setup_dump() */
#ifdef POSTK_DEBUG_ARCH_DEP_38
static ssize_t print_hex(char *buf, size_t buf_size, char *str) {
#else /* POSTK_DEBUG_ARCH_DEP_38 */
static ssize_t print_hex(char *buf, char *str) {
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
char *p;
char *q;
q = buf;
for (p = str; *p != '\0'; ++p) {
#ifdef POSTK_DEBUG_ARCH_DEP_38
int ret;
ret = snprintf(q, buf_size, "%02x", *p);
if (ret < 0) {
return ret;
}
q += ret;
buf_size -= ret;
#else /* POSTK_DEBUG_ARCH_DEP_38 */
q += sprintf(q, "%02x", *p);
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
}
*q = '\0';
return (q - buf);
} /* print_hex() */
#if defined(POSTK_DEBUG_ARCH_DEP_34) && defined(POSTK_DEBUG_ARCH_DEP_38)
ssize_t print_bin(char *buf, size_t buf_size, void *data, size_t size) {
#else /* POSTK_DEBUG_ARCH_DEP_34 && POSTK_DEBUG_ARCH_DEP_38*/
static ssize_t print_bin(char *buf, void *data, size_t size) {
#endif /* POSTK_DEBUG_ARCH_DEP_34 && POSTK_DEBUG_ARCH_DEP_38*/
uint8_t *p;
char *q;
int i;
@@ -610,7 +684,18 @@ static ssize_t print_bin(char *buf, void *data, size_t size) {
p = data;
q = buf;
for (i = 0; i < size; ++i) {
#ifdef POSTK_DEBUG_ARCH_DEP_38
int ret;
ret = snprintf(q, buf_size, "%02x", *p);
if (ret < 0) {
return ret;
}
q += ret;
buf_size -= ret;
#else /* POSTK_DEBUG_ARCH_DEP_38 */
q += sprintf(q, "%02x", *p);
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
++p;
}
*q = '\0';
@@ -618,8 +703,13 @@ static ssize_t print_bin(char *buf, void *data, size_t size) {
return (q - buf);
} /* print_bin() */
#ifdef POSTK_DEBUG_ARCH_DEP_38
static void command(const char *cmd, char *res, size_t res_size) {
const char *p;
#else /* POSTK_DEBUG_ARCH_DEP_38 */
static void command(char *cmd, char *res) {
char *p;
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
char *rbp;
p = cmd;
@@ -668,13 +758,24 @@ static void command(char *cmd, char *res) {
rbp += sprintf(rbp, "1");
}
else if (!strncmp(p, "qXfer:features:read:target.xml:", 31)) {
#ifdef POSTK_DEBUG_ARCH_DEP_34
char *str =
"<target version=\"1.0\">"
"<architecture>"ARCH"</architecture>"
"</target>";
#else /* POSTK_DEBUG_ARCH_DEP_34 */
char *str =
"<target version=\"1.0\">"
"<architecture>i386:x86-64</architecture>"
"</target>";
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
rbp += sprintf(rbp, "l");
if (0)
#ifdef POSTK_DEBUG_ARCH_DEP_38
rbp += print_hex(rbp, res_size, str);
#else /* POSTK_DEBUG_ARCH_DEP_38 */
rbp += print_hex(rbp, str);
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
rbp += sprintf(rbp, "%s", str);
}
else if (!strcmp(p, "D")) {
@@ -683,14 +784,20 @@ static void command(char *cmd, char *res) {
}
else if (!strcmp(p, "g")) {
if (curr_thread->cpu < 0) {
#ifndef POSTK_DEBUG_ARCH_DEP_34
struct x86_kregs {
uintptr_t rsp, rbp, rbx, rsi;
uintptr_t rdi, r12, r13, r14;
uintptr_t r15, rflags, rsp0;
};
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
int error;
#ifdef POSTK_DEBUG_ARCH_DEP_34
struct arch_kregs kregs;
#else /* POSTK_DEBUG_ARCH_DEP_34 */
struct x86_kregs kregs;
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
error = read_mem(curr_thread->process+K(CTX_OFFSET),
&kregs, sizeof(kregs));
@@ -699,6 +806,9 @@ static void command(char *cmd, char *res) {
break;
}
#ifdef POSTK_DEBUG_ARCH_DEP_34
print_kregs(rbp, res_size, &kregs);
#else /* POSTK_DEBUG_ARCH_DEP_34 */
rbp += sprintf(rbp, "xxxxxxxxxxxxxxxx"); /* rax */
rbp += print_bin(rbp, &kregs.rbx, sizeof(uint64_t));
rbp += sprintf(rbp, "xxxxxxxxxxxxxxxx"); /* rcx */
@@ -725,15 +835,25 @@ static void command(char *cmd, char *res) {
rbp += sprintf(rbp, "xxxxxxxx"); /* es */
rbp += sprintf(rbp, "xxxxxxxx"); /* fs */
rbp += sprintf(rbp, "xxxxxxxx"); /* gs */
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
}
else {
int error;
#ifdef POSTK_DEBUG_ARCH_DEP_34
uintptr_t regs[ARCH_REGS];
#else /* POSTK_DEBUG_ARCH_DEP_34 */
uintptr_t regs[21];
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
uint8_t *pu8;
int i;
#ifdef POSTK_DEBUG_ARCH_DEP_34
error = read_mem(curr_thread->arch_clv+PANIC_REGS_OFFSET,
&regs, sizeof(regs));
#else /* POSTK_DEBUG_ARCH_DEP_34 */
error = read_mem(curr_thread->x86_clv+240,
&regs, sizeof(regs));
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
if (error) {
perror("read_mem");
break;
@@ -780,13 +900,24 @@ static void command(char *cmd, char *res) {
rbp += sprintf(rbp, "T0;tnotrun:0");
}
else if (!strncmp(p, "qXfer:memory-map:read::", 23)) {
#ifdef POSTK_DEBUG_ARCH_DEP_34
char *str =
"<memory-map>"
"<memory type=\"rom\" start=\""MAP_KERNEL_TEXT"\" length=\"0x27000\"/>"
"</memory-map>";
#else /* POSTK_DEBUG_ARCH_DEP_34 */
char *str =
"<memory-map>"
"<memory type=\"rom\" start=\"0xffffffff80001000\" length=\"0x27000\"/>"
"</memory-map>";
#endif /* POSTK_DEBUG_ARCH_DEP_34 */
rbp += sprintf(rbp, "l");
if (0)
#ifdef POSTK_DEBUG_ARCH_DEP_38
rbp += print_hex(rbp, res_size, str);
#else /* POSTK_DEBUG_ARCH_DEP_38 */
rbp += print_hex(rbp, str);
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
rbp += sprintf(rbp, "%s", str);
}
else if (!strncmp(p, "T", 1)) {
@@ -878,7 +1009,11 @@ static void command(char *cmd, char *res) {
else {
q += sprintf(q, "status=%#x", ti->status);
}
#ifdef POSTK_DEBUG_ARCH_DEP_38
rbp += print_hex(rbp, res_size, buf);
#else /* POSTK_DEBUG_ARCH_DEP_38 */
rbp += print_hex(rbp, buf);
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
}
} while (0);
@@ -1107,7 +1242,11 @@ int main(int argc, char *argv[]) {
}
mode = 0;
fputc('+', ofp);
#ifdef POSTK_DEBUG_ARCH_DEP_38
command(lbuf, rbuf, sizeof(rbuf));
#else /* POSTK_DEBUG_ARCH_DEP_38 */
command(lbuf, rbuf);
#endif /* POSTK_DEBUG_ARCH_DEP_38 */
sum = 0;
for (p = rbuf; *p != '\0'; ++p) {
sum += *p;

22
executer/user/eclair.h Normal file
View File

@@ -0,0 +1,22 @@
/* eclair.h COPYRIGHT FUJITSU LIMITED 2016 */
#ifndef HEADER_USER_COMMON_ECLAIR_H
#define HEADER_USER_COMMON_ECLAIR_H
#ifdef POSTK_DEBUG_ARCH_DEP_76 /* header path fix */
#include "../config.h"
#else /* POSTK_DEBUG_ARCH_DEP_76 */
#include <config.h>
#endif /* POSTK_DEBUG_ARCH_DEP_76 */
#include <stdio.h>
#include <inttypes.h>
#include <arch-eclair.h>
/* common */
uintptr_t lookup_symbol(char *name);
ssize_t print_bin(char *buf, size_t buf_size, void *data, size_t size);
/* arch depend */
int print_kregs(char *rbp, size_t rbp_size, const struct arch_kregs *kregs);
#endif /* HEADER_USER_COMMON_ECLAIR_H */

View File

@@ -1,3 +1,4 @@
/* mcexec.c COPYRIGHT FUJITSU LIMITED 2015-2017 */
/**
* \file executer/user/mcexec.c
* License details are found in the file LICENSE.
@@ -63,9 +64,17 @@
#include <sys/signalfd.h>
#include <sys/mount.h>
#include <include/generated/uapi/linux/version.h>
#ifdef POSTK_DEBUG_ARCH_DEP_35
#ifndef __aarch64__
#include <sys/user.h>
#endif /* !__aarch64__ */
#else /* POSTK_DEBUG_ARCH_DEP_35 */
#include <sys/user.h>
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
#include <sys/prctl.h>
#ifndef POSTK_DEBUG_ARCH_DEP_77 /* arch depend hide */
#include <asm/prctl.h>
#endif /* !POSTK_DEBUG_ARCH_DEP_77 */
#include "../include/uprotocol.h"
#include <getopt.h>
#include "archdep.h"
@@ -81,6 +90,7 @@
#include "../include/qlmpi.h"
//#define DEBUG
#define ADD_ENVS_OPTION
#ifndef DEBUG
#define __dprint(msg, ...)
@@ -223,6 +233,11 @@ struct fork_sync_container {
struct fork_sync_container *fork_sync_top;
pthread_mutex_t fork_sync_mutex = PTHREAD_MUTEX_INITIALIZER;
#ifdef POSTK_DEBUG_ARCH_DEP_35
unsigned long page_size;
unsigned long page_mask;
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
pid_t gettid(void)
{
return syscall(SYS_gettid);
@@ -573,6 +588,9 @@ retry:
fprintf(stderr, "lookup_exec_path(): error allocating\n");
return ENOMEM;
}
#ifdef POSTK_DEBUG_TEMP_FIX_6 /* dynamic allocate area initialize clear */
memset(link_path, '\0', max_len);
#endif /* POSTK_DEBUG_TEMP_FIX_6 */
error = readlink(path, link_path, max_len);
if (error == -1 || error == max_len) {
@@ -743,9 +761,15 @@ int transfer_image(int fd, struct program_load_desc *desc)
for (i = 0; i < desc->num_sections; i++) {
fp = desc->sections[i].fp;
#ifdef POSTK_DEBUG_ARCH_DEP_35
s = (desc->sections[i].vaddr) & page_mask;
e = (desc->sections[i].vaddr + desc->sections[i].len
+ page_size - 1) & page_mask;
#else /* POSTK_DEBUG_ARCH_DEP_35 */
s = (desc->sections[i].vaddr) & PAGE_MASK;
e = (desc->sections[i].vaddr + desc->sections[i].len
+ PAGE_SIZE - 1) & PAGE_MASK;
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
rpa = desc->sections[i].remote_pa;
if (fseek(fp, desc->sections[i].offset, SEEK_SET) != 0) {
@@ -761,15 +785,29 @@ int transfer_image(int fd, struct program_load_desc *desc)
memset(&pt, '\0', sizeof pt);
pt.rphys = rpa;
pt.userp = dma_buf;
#ifdef POSTK_DEBUG_ARCH_DEP_35
pt.size = page_size;
#else /* POSTK_DEBUG_ARCH_DEP_35 */
pt.size = PAGE_SIZE;
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
pt.direction = MCEXEC_UP_TRANSFER_TO_REMOTE;
lr = 0;
#ifdef POSTK_DEBUG_ARCH_DEP_35
memset(dma_buf, 0, page_size);
#else /* POSTK_DEBUG_ARCH_DEP_35 */
memset(dma_buf, 0, PAGE_SIZE);
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
if (s < desc->sections[i].vaddr) {
#ifdef POSTK_DEBUG_ARCH_DEP_35
l = desc->sections[i].vaddr
& (page_size - 1);
lr = page_size - l;
#else /* POSTK_DEBUG_ARCH_DEP_35 */
l = desc->sections[i].vaddr
& (PAGE_SIZE - 1);
lr = PAGE_SIZE - l;
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
if (lr > flen) {
lr = flen;
}
@@ -790,8 +828,13 @@ int transfer_image(int fd, struct program_load_desc *desc)
flen -= lr;
}
else if (flen > 0) {
#ifdef POSTK_DEBUG_ARCH_DEP_35
if (flen > page_size) {
lr = page_size;
#else /* POSTK_DEBUG_ARCH_DEP_35 */
if (flen > PAGE_SIZE) {
lr = PAGE_SIZE;
#endif /*POSTK_DEBUG_ARCH_DEP_35 */
} else {
lr = flen;
}
@@ -811,8 +854,13 @@ int transfer_image(int fd, struct program_load_desc *desc)
}
flen -= lr;
}
#ifdef POSTK_DEBUG_ARCH_DEP_35
s += page_size;
rpa += page_size;
#else /* POSTK_DEBUG_ARCH_DEP_35 */
s += PAGE_SIZE;
rpa += PAGE_SIZE;
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
/* No more left to upload.. */
if (lr == 0 && flen == 0) break;
@@ -1198,7 +1246,11 @@ static int reduce_stack(struct rlimit *orig_rlim, char *argv[])
void print_usage(char **argv)
{
#ifdef ADD_ENVS_OPTION
fprintf(stderr, "usage: %s [-c target_core] [-n nr_partitions] [<-e ENV_NAME=value>...] [--mpol-threshold=N] [--enable-straight-map] [--extend-heap-by=N] [--mpol-no-heap] [--mpol-no-bss] [--mpol-no-stack] [<mcos-id>] (program) [args...]\n", argv[0]);
#else /* ADD_ENVS_OPTION */
fprintf(stderr, "usage: %s [-c target_core] [-n nr_partitions] [--mpol-threshold=N] [--enable-straight-map] [--extend-heap-by=N] [--mpol-no-heap] [--mpol-no-bss] [--mpol-no-stack] [<mcos-id>] (program) [args...]\n", argv[0]);
#endif /* ADD_ENVS_OPTION */
}
void init_sigaction(void)
@@ -1375,6 +1427,130 @@ static int rlimits[] = {
char dev[64];
#ifdef ADD_ENVS_OPTION
struct env_list_entry {
char* str;
char* name;
char* value;
struct env_list_entry *next;
};
static int get_env_list_entry_count(struct env_list_entry *head)
{
int list_count = 0;
struct env_list_entry *current = head;
while (current) {
list_count++;
current = current->next;
}
return list_count;
}
static struct env_list_entry *search_env_list(struct env_list_entry *head, char *name)
{
struct env_list_entry *current = head;
while (current) {
if (!(strcmp(name, current->name))) {
return current;
}
current = current->next;
}
return NULL;
}
static void add_env_list(struct env_list_entry **head, char *add_string)
{
struct env_list_entry *current = NULL;
char *value = NULL;
char *name = NULL;
struct env_list_entry *exist = NULL;
name = (char *)malloc(strlen(add_string) + 1);
strcpy(name, add_string);
/* include '=' ? */
if (!(value = strchr(name, '='))) {
printf("\"%s\" is not env value.\n", add_string);
free(name);
return;
}
*value = '\0';
value++;
/* name overlap serch */
if (*head) {
exist = search_env_list(*head, name);
if (exist) {
free(name);
return;
}
}
/* ADD env_list */
current = (struct env_list_entry *)malloc(sizeof(struct env_list_entry));
current->str = add_string;
current->name = name;
current->value = value;
if (*head) {
current->next = *head;
} else {
current->next = NULL;
}
*head = current;
return;
}
static void destroy_env_list(struct env_list_entry *head)
{
struct env_list_entry *current = head;
struct env_list_entry *next = NULL;
while (current) {
next = current->next;
free(current->name);
free(current);
current = next;
}
}
static char **create_local_environ(struct env_list_entry *inc_list)
{
int list_count = 0;
int i = 0;
struct env_list_entry *current = inc_list;
char **local_env = NULL;
list_count = get_env_list_entry_count(inc_list);
local_env = (char **)malloc(sizeof(char **) * (list_count + 1));
local_env[list_count] = NULL;
while (current) {
local_env[i] = (char *)malloc(strlen(current->str) + 1);
strcpy(local_env[i], current->str);
current = current->next;
i++;
}
return local_env;
}
static void destroy_local_environ(char **local_env)
{
int i = 0;
if (!local_env) {
return;
}
for (i = 0; local_env[i]; i++) {
free(local_env[i]);
local_env[i] = NULL;
}
free(local_env);
}
#endif /* ADD_ENVS_OPTION */
unsigned long atobytes(char *string)
{
unsigned long mult = 1;
@@ -1405,6 +1581,8 @@ unsigned long atobytes(char *string)
}
static struct option mcexec_options[] = {
#ifdef POSTK_DEBUG_ARCH_DEP_53
#ifndef __aarch64__
{
.name = "disable-vdso",
.has_arg = no_argument,
@@ -1417,6 +1595,8 @@ static struct option mcexec_options[] = {
.flag = &enable_vdso,
.val = 1,
},
#endif /*__aarch64__*/
#endif /*POSTK_DEBUG_ARCH_DEP_53*/
{
.name = "profile",
.has_arg = no_argument,
@@ -1626,12 +1806,21 @@ int main(int argc, char **argv)
char shell_path[1024];
int num = 0;
int persona;
#ifdef ADD_ENVS_OPTION
char **local_env = NULL;
struct env_list_entry *extra_env = NULL;
#endif /* ADD_ENVS_OPTION */
#ifdef USE_SYSCALL_MOD_CALL
__glob_argc = argc;
__glob_argv = argv;
#endif
#ifdef POSTK_DEBUG_ARCH_DEP_35
page_size = sysconf(_SC_PAGESIZE);
page_mask = ~(page_size - 1);
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
altroot = getenv("MCEXEC_ALT_ROOT");
if (!altroot) {
altroot = "/usr/linux-k1om-4.7/linux-k1om";
@@ -1669,7 +1858,11 @@ int main(int argc, char **argv)
}
/* Parse options ("+" denotes stop at the first non-option) */
#ifdef ADD_ENVS_OPTION
while ((opt = getopt_long(argc, argv, "+c:n:t:m:h:e:", mcexec_options, NULL)) != -1) {
#else /* ADD_ENVS_OPTION */
while ((opt = getopt_long(argc, argv, "+c:n:t:m:h:", mcexec_options, NULL)) != -1) {
#endif /* ADD_ENVS_OPTION */
switch (opt) {
case 'c':
target_core = atoi(optarg);
@@ -1691,6 +1884,11 @@ int main(int argc, char **argv)
heap_extension = atobytes(optarg);
break;
#ifdef ADD_ENVS_OPTION
case 'e':
add_env_list(&extra_env, optarg);
break;
#endif /* ADD_ENVS_OPTION */
case 0: /* long opt */
break;
@@ -1723,8 +1921,11 @@ int main(int argc, char **argv)
ld_preload_init();
#ifdef ADD_ENVS_OPTION
#else /* ADD_ENVS_OPTION */
/* Collect environment variables */
envs_len = flatten_strings(-1, NULL, environ, &envs);
#endif /* ADD_ENVS_OPTION */
#ifdef ENABLE_MCOVERLAYFS
__dprint("mcoverlay enable\n");
@@ -1870,6 +2071,19 @@ int main(int argc, char **argv)
argv[optind] = path;
}
#ifdef ADD_ENVS_OPTION
/* Collect environment variables */
for (i = 0; environ[i]; i++) {
add_env_list(&extra_env, environ[i]);
}
local_env = create_local_environ(extra_env);
envs_len = flatten_strings(-1, NULL, local_env, &envs);
destroy_local_environ(local_env);
local_env = NULL;
destroy_env_list(extra_env);
extra_env = NULL;
#endif /* ADD_ENVS_OPTION */
for(i = 0; i < sizeof(rlimits) / sizeof(int); i += 2)
getrlimit(rlimits[i], &desc->rlimit[rlimits[i + 1]]);
desc->envs_len = envs_len;
@@ -2202,12 +2416,20 @@ do_generic_syscall(
__dprintf("do_generic_syscall(%ld)\n", w->sr.number);
#ifdef POSTK_DEBUG_TEMP_FIX_75 /* syscall return value check add. */
ret = syscall(w->sr.number, w->sr.args[0], w->sr.args[1], w->sr.args[2],
w->sr.args[3], w->sr.args[4], w->sr.args[5]);
if (ret == -1) {
ret = -errno;
}
#else /* POSTK_DEBUG_TEMP_FIX_75 */
errno = 0;
ret = syscall(w->sr.number, w->sr.args[0], w->sr.args[1], w->sr.args[2],
w->sr.args[3], w->sr.args[4], w->sr.args[5]);
if (errno != 0) {
ret = -errno;
}
#endif /* POSTK_DEBUG_TEMP_FIX_75 */
/* Overlayfs /sys/X directory lseek() problem work around */
if (w->sr.number == __NR_lseek && ret == -EINVAL) {
@@ -2244,7 +2466,16 @@ do_generic_syscall(
}
/* Fake that nodeX in /sys/devices/system/node do not exist,
* where X >= number of LWK NUMA nodes */
#ifdef POSTK_DEBUG_ARCH_DEP_55
# ifdef __aarch64__
# define __nr_getdents __NR_getdents64
# else
# define __nr_getdents __NR_getdents
# endif
else if (w->sr.number == __nr_getdents && ret > 0) {
#else /*POSTK_DEBUG_ARCH_DEP_55*/
else if (w->sr.number == __NR_getdents && ret > 0) {
#endif /*POSTK_DEBUG_ARCH_DEP_55*/
struct linux_dirent {
long d_ino;
off_t d_off;
@@ -2327,7 +2558,11 @@ samepage(void *a, void *b)
unsigned long aa = (unsigned long)a;
unsigned long bb = (unsigned long)b;
#ifdef POSTK_DEBUG_ARCH_DEP_35
return (aa & page_mask) == (bb & page_mask);
#else /* POSTK_DEBUG_ARCH_DEP_35 */
return (aa & PAGE_MASK) == (bb & PAGE_MASK);
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
}
#ifdef DEBUG_UTI
@@ -2508,8 +2743,17 @@ create_tracer(void *wp, int mck_tid, unsigned long key)
exited++;
continue;
case __NR_clone:
#ifdef POSTK_DEBUG_ARCH_DEP_78 /* arch dep syscallno hide */
#ifdef __NR_fork
case __NR_fork:
#endif
#ifdef __NR_vfork
case __NR_vfork:
#endif
#else /* POSTK_DEBUG_ARCH_DEP_78 */
case __NR_fork:
case __NR_vfork:
#endif /* POSTK_DEBUG_ARCH_DEP_78 */
case __NR_execve:
set_syscall_number(&args, -1);
set_syscall_args(tid, &args);
@@ -2582,20 +2826,34 @@ util_thread(unsigned long uctx_pa, int remote_tid, unsigned long pattr)
void *param[6];
int rc = 0;
#ifdef POSTK_DEBUG_ARCH_DEP_35
wp = mmap(NULL, page_size * 3, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
#else /* POSTK_DEBUG_ARCH_DEP_35 */
wp = mmap(NULL, PAGE_SIZE * 3, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
if (wp == (void *)-1) {
rc = -errno;
goto out;
}
#ifdef POSTK_DEBUG_ARCH_DEP_35
lctx = (char *)wp + page_size;
rctx = (char *)lctx + page_size;
#else /* POSTK_DEBUG_ARCH_DEP_35 */
lctx = (char *)wp + PAGE_SIZE;
rctx = (char *)lctx + PAGE_SIZE;
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
param[0] = (void *)uctx_pa;
param[1] = rctx;
param[2] = lctx;
param[4] = wp;
#ifdef POSTK_DEBUG_ARCH_DEP_35
param[5] = (void *)(page_size * 3);
#else /* POSTK_DEBUG_ARCH_DEP_35 */
param[5] = (void *)(PAGE_SIZE * 3);
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
if ((rc = ioctl(fd, MCEXEC_UP_UTIL_THREAD1, param)) == -1) {
fprintf(stderr, "util_thread1: %d errno=%d\n", rc, errno);
rc = -errno;
@@ -2625,7 +2883,11 @@ util_thread(unsigned long uctx_pa, int remote_tid, unsigned long pattr)
out:
if (wp)
#ifdef POSTK_DEBUG_ARCH_DEP_35
munmap(wp, page_size * 3);
#else /* POSTK_DEBUG_ARCH_DEP_35 */
munmap(wp, PAGE_SIZE * 3);
#endif /* POSTK_DEBUG_ARCH_DEP_35 */
return rc;
}
@@ -2763,6 +3025,54 @@ chgpath(char *in, char *buf)
return fn;
}
#ifdef POSTK_DEBUG_ARCH_DEP_72 /* add __NR_newfstat */
static int
syscall_pathname(int dirfd, char *pathname, size_t size)
{
int ret = 0;
char *tempbuf = NULL;
size_t tempbuf_size;
if (pathname[0] == '/') {
goto out;
}
if (dirfd != AT_FDCWD) {
int len;
char dfdpath[64];
snprintf(dfdpath, sizeof(dfdpath), "/proc/self/fd/%d", dirfd);
tempbuf_size = size;
tempbuf = malloc(tempbuf_size);
if (tempbuf == NULL) {
ret = -ENOMEM;
goto out;
}
ret = readlink(dfdpath, tempbuf, tempbuf_size);
if (ret == -1) {
ret = -errno;
goto out;
}
len = strlen(pathname);
if (tempbuf_size <= ret + 1 + len + 1) {
ret = -ENAMETOOLONG;
goto out;
}
tempbuf[ret] = '/';
strncpy(&tempbuf[ret+1], pathname, len+1);
strcpy(pathname, tempbuf);
}
out:
if (tempbuf) {
free(tempbuf);
}
return ret;
}
#endif /*POSTK_DEBUG_ARCH_DEP_72*/
int main_loop(struct thread_data_s *my_thread)
{
struct syscall_wait_desc w;
@@ -2795,6 +3105,55 @@ int main_loop(struct thread_data_s *my_thread)
my_thread->remote_cpu = w.cpu;
switch (w.sr.number) {
#ifdef POSTK_DEBUG_ARCH_DEP_13 /* arch depend hide */
#ifdef __aarch64__
case __NR_openat:
/* initialize buffer */
memset(tmpbuf, '\0', sizeof(tmpbuf));
memset(pathbuf, '\0', sizeof(pathbuf));
/* check argument 1 dirfd */
if ((int)w.sr.args[0] != AT_FDCWD) {
/* dirfd != AT_FDCWD */
__dprintf("openat(dirfd != AT_FDCWD)\n");
snprintf(tmpbuf, sizeof(tmpbuf), "/proc/self/fd/%d", (int)w.sr.args[0]);
ret = readlink(tmpbuf, pathbuf, sizeof(pathbuf) - 1);
if (ret < 0) {
do_syscall_return(fd, cpu, -errno, 0, 0, 0, 0);
break;
}
__dprintf(" %s -> %s\n", tmpbuf, pathbuf);
ret = do_strncpy_from_user(fd, tmpbuf, (void *)w.sr.args[1], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
strncat(pathbuf, "/", 1);
strncat(pathbuf, tmpbuf, strlen(tmpbuf) + 1);
} else {
/* dirfd == AT_FDCWD */
__dprintf("openat(dirfd == AT_FDCWD)\n");
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[1], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
}
__dprintf("openat: %s\n", pathbuf);
fn = chgpath(pathbuf, tmpbuf);
ret = open(fn, w.sr.args[2], w.sr.args[3]);
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#else /* __aarch64__ */
case __NR_open:
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX);
if (ret >= PATH_MAX) {
@@ -2812,6 +3171,26 @@ int main_loop(struct thread_data_s *my_thread)
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#endif /* __aarch64__ */
#else /* POSTK_DEBUG_ARCH_DEP_13 */
case __NR_open:
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
__dprintf("open: %s\n", pathbuf);
fn = chgpath(pathbuf, tmpbuf);
ret = open(fn, w.sr.args[1], w.sr.args[2]);
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#endif /* POSTK_DEBUG_ARCH_DEP_13 */
case __NR_futex:
ret = clock_gettime(w.sr.args[1], &tv);
@@ -2932,7 +3311,11 @@ gettid_out:
break;
}
#ifdef POSTK_DEBUG_ARCH_DEP_13 /* arch depend hide */
case 1079: {
#else /* POSTK_DEBUG_ARCH_DEP_13 */
case __NR_fork: {
#endif /* POSTK_DEBUG_ARCH_DEP_13 */
struct fork_sync *fs;
struct fork_sync_container *fsc;
struct fork_sync_container *fp;
@@ -3192,14 +3575,22 @@ fork_err:
goto return_execve1;
}
#ifdef POSTK_DEBUG_TEMP_FIX_9 /* shell-script run via execve arg[0] fix */
if (strlen(shell) >= SHELL_PATH_MAX_LEN) {
#else /* POSTK_DEBUG_TEMP_FIX_9 */
if (strlen(shell_path) >= SHELL_PATH_MAX_LEN) {
#endif /* POSTK_DEBUG_TEMP_FIX_9 */
fprintf(stderr, "execve(): error: shell path too long: %s\n", shell_path);
ret = ENAMETOOLONG;
goto return_execve1;
}
/* Let the LWK know the shell interpreter */
#ifdef POSTK_DEBUG_TEMP_FIX_9 /* shell-script run via execve arg[0] fix */
strcpy(desc->shell_path, shell);
#else /* POSTK_DEBUG_TEMP_FIX_9 */
strcpy(desc->shell_path, shell_path);
#endif /* POSTK_DEBUG_TEMP_FIX_9 */
}
desc->enable_vdso = enable_vdso;
@@ -3328,6 +3719,9 @@ return_execve2:
}
else{
ret = setfsuid(w.sr.args[0]);
#ifdef POSTK_DEBUG_TEMP_FIX_45 /* setfsgid()/setfsuid() mismatch fix. */
ret |= (long)gettid() << 32;
#endif /* POSTK_DEBUG_TEMP_FIX_45 */
}
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
@@ -3376,6 +3770,9 @@ return_execve2:
case __NR_setfsgid:
ret = setfsgid(w.sr.args[0]);
#ifdef POSTK_DEBUG_TEMP_FIX_45 /* setfsgid()/setfsuid() mismatch fix. */
ret |= (long)gettid() << 32;
#endif /*POSTK_DEBUG_TEMP_FIX_45 */
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
@@ -3386,7 +3783,57 @@ return_execve2:
ret = do_generic_syscall(&w);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#ifdef POSTK_DEBUG_ARCH_DEP_36
#ifdef __aarch64__
case __NR_readlinkat:
/* initialize buffer */
memset(tmpbuf, '\0', sizeof(tmpbuf));
memset(pathbuf, '\0', sizeof(pathbuf));
/* check argument 1 dirfd */
if ((int)w.sr.args[0] != AT_FDCWD) {
/* dirfd != AT_FDCWD */
__dprintf("readlinkat(dirfd != AT_FDCWD)\n");
snprintf(tmpbuf, sizeof(tmpbuf), "/proc/self/fd/%d", (int)w.sr.args[0]);
ret = readlink(tmpbuf, pathbuf, sizeof(pathbuf) - 1);
if (ret < 0) {
do_syscall_return(fd, cpu, -errno, 0, 0, 0, 0);
break;
}
__dprintf(" %s -> %s\n", tmpbuf, pathbuf);
ret = do_strncpy_from_user(fd, tmpbuf, (void *)w.sr.args[1], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
strncat(pathbuf, "/", 1);
strncat(pathbuf, tmpbuf, strlen(tmpbuf) + 1);
} else {
/* dirfd == AT_FDCWD */
__dprintf("readlinkat(dirfd == AT_FDCWD)\n");
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[1], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
}
__dprintf("readlinkat: %s\n", pathbuf);
fn = chgpath(pathbuf, tmpbuf);
ret = readlink(fn, (char *)w.sr.args[2], w.sr.args[3]);
__dprintf("readlinkat: dirfd=%d, path=%s, buf=%s, ret=%ld\n",
(int)w.sr.args[0], fn, (char *)w.sr.args[2], ret);
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#else /* __aarch64__ */
case __NR_readlink:
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX);
if (ret >= PATH_MAX) {
@@ -3405,7 +3852,92 @@ return_execve2:
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#endif /* __aarch64__ */
#else /* POSTK_DEBUG_ARCH_DEP_36 */
case __NR_readlink:
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
fn = chgpath(pathbuf, tmpbuf);
ret = readlink(fn, (char *)w.sr.args[1], w.sr.args[2]);
__dprintf("readlink: path=%s, buf=%s, ret=%ld\n",
fn, (char *)w.sr.args[1], ret);
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#endif /* POSTK_DEBUG_ARCH_DEP_36 */
#ifdef POSTK_DEBUG_ARCH_DEP_72 /* add __NR_newfstat */
case __NR_newfstatat:
/* initialize buffer */
memset(tmpbuf, '\0', sizeof(tmpbuf));
memset(pathbuf, '\0', sizeof(pathbuf));
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[1], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
if (pathbuf[0] == '\0') {
// empty string
if ((int)w.sr.args[3] & AT_EMPTY_PATH) {
if ((int)w.sr.args[0] == AT_FDCWD) {
if (NULL == getcwd(pathbuf, PATH_MAX)) {
do_syscall_return(fd, cpu, -errno, 0, 0, 0, 0);
break;
}
} else {
char dfdpath[64];
snprintf(dfdpath, sizeof(dfdpath), "/proc/self/fd/%d", (int)w.sr.args[0]);
ret = readlink(dfdpath, pathbuf, PATH_MAX);
if (ret == -1) {
do_syscall_return(fd, cpu, -errno, 0, 0, 0, 0);
break;
}
pathbuf[ret] = '\0';
}
}
} else if (pathbuf[0] != '/') {
// relative path
ret = syscall_pathname((int)w.sr.args[0], pathbuf, PATH_MAX);
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
}
fn = chgpath(pathbuf, tmpbuf);
if (fn[0] == '/') {
ret = fstatat((int)w.sr.args[0],
fn,
(struct stat*)w.sr.args[2],
(int)w.sr.args[3]);
__dprintf("fstatat: dirfd=%d, pathname=%s, buf=%p, flags=%x, ret=%ld\n",
(int)w.sr.args[0], fn, (void*)w.sr.args[2], (int)w.sr.args[3], ret);
} else {
ret = fstatat((int)w.sr.args[0],
(const char*)w.sr.args[1],
(struct stat*)w.sr.args[2],
(int)w.sr.args[3]);
__dprintf("fstatat: dirfd=%d, pathname=%s, buf=%p, flags=%x, ret=%ld\n",
(int)w.sr.args[0], (char*)w.sr.args[1], (void*)w.sr.args[2], (int)w.sr.args[3], ret);
}
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#ifdef __NR_stat
case __NR_stat:
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX);
if (ret >= PATH_MAX) {
@@ -3423,6 +3955,26 @@ return_execve2:
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#endif /* __NR_stat */
#else /* POSTK_DEBUG_ARCH_DEP_72 */
case __NR_stat:
ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX);
if (ret >= PATH_MAX) {
ret = -ENAMETOOLONG;
}
if (ret < 0) {
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
}
fn = chgpath(pathbuf, tmpbuf);
ret = stat(fn, (struct stat *)w.sr.args[1]);
__dprintf("stat: path=%s, ret=%ld\n", fn, ret);
SET_ERR(ret);
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
break;
#endif /* POSTK_DEBUG_ARCH_DEP_72 */
case __NR_sched_setaffinity:
if (w.sr.args[0] == 0) {