Skip to content

Commit

Permalink
Create wrapper library for system call instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
YuuichiNakamura authored and xiaoxiang781216 committed Jul 22, 2020
1 parent 2b4d2cd commit 3767862
Show file tree
Hide file tree
Showing 12 changed files with 478 additions and 5 deletions.
1 change: 1 addition & 0 deletions syscall/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.context
/*.ldcmd
36 changes: 32 additions & 4 deletions syscall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,43 @@ include $(TOPDIR)/Make.defs

include proxies/Make.defs
include stubs/Make.defs
include wraps/Make.defs

MKSYSCALL = "$(TOPDIR)$(DELIM)tools$(DELIM)mksyscall$(HOSTEXEEXT)"
CSVFILE = "$(TOPDIR)$(DELIM)syscall$(DELIM)syscall.csv"

ifeq ($(CONFIG_SCHED_INSTRUMENTATION_SYSCALL),y)
ifeq ($(CONFIG_LIB_SYSCALL),y)
PROXY_SRCS += syscall_names.c
else
WRAP_SRCS += syscall_names.c
endif
endif
STUB_SRCS += syscall_stublookup.c

AOBJS = $(ASRCS:.S=$(OBJEXT))

PROXY_OBJS = $(PROXY_SRCS:.c=$(OBJEXT))
STUB_OBJS = $(STUB_SRCS:.c=$(OBJEXT))
WRAP_OBJS = $(WRAP_SRCS:.c=$(OBJEXT))

CSRCS = $(PROXY_SRCS) $(STUB_SRCS)
CSRCS = $(PROXY_SRCS) $(STUB_SRCS) $(WRAP_SRCS)
COBJS = $(CSRCS:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)

PROXYDEPPATH = --dep-path proxies
STUBDEPPATH = --dep-path stubs
VPATH = proxies:stubs
WRAPDEPPATH = --dep-path wraps
VPATH = proxies:stubs:wraps

BIN1 = libproxies$(LIBEXT)
BIN2 = libstubs$(LIBEXT)
BIN3 = libwraps$(LIBEXT)
SYSCALLWRAPS = syscall_wraps.ldcmd

all: $(BIN1) $(BIN2)
all: $(BIN1) $(BIN2) $(BIN3) $(SYSCALLWRAPS)
.PHONY: context depend clean distclean

$(AOBJS): %$(OBJEXT): %.S
Expand All @@ -76,27 +88,41 @@ $(BIN1): $(PROXY_OBJS)
$(BIN2): $(STUB_OBJS)
$(call ARCHIVE, $@, $(STUB_OBJS))

$(BIN3): $(WRAP_OBJS)
$(call ARCHIVE, $@, $(WRAP_OBJS))

$(SYSCALLWRAPS): .context

.depend: Makefile $(SRCS)
$(Q) $(MKDEP) $(PROXYDEPPATH) $(STUBDEPPATH) \
$(Q) $(MKDEP) $(PROXYDEPPATH) $(STUBDEPPATH) $(WRAPDEPPATH) \
"$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
$(Q) touch $@

depend: .depend

.context: syscall.csv
$(Q) $(MAKE) -C $(TOPDIR)$(DELIM)tools -f Makefile.host mksyscall
ifeq ($(CONFIG_LIB_SYSCALL),y)
$(Q) (cd proxies; $(MKSYSCALL) -p $(CSVFILE);)
$(Q) (cd stubs; $(MKSYSCALL) -s $(CSVFILE);)
endif
ifeq ($(CONFIG_SCHED_INSTRUMENTATION_SYSCALL),y)
$(Q) (cd wraps; $(MKSYSCALL) -w $(CSVFILE);)
$(Q) $(CPP) $(CPPFLAGS) $(SYSCALLWRAPS:.ldcmd=.h) | \
sed -e '1,/WRAPOPTSTARTS/d' -e '/^#/d' > $(SYSCALLWRAPS)
endif
$(Q) touch $@

context: .context

clean:
$(call DELFILE, $(BIN1))
$(call DELFILE, $(BIN2))
$(call DELFILE, $(BIN3))
ifneq ($(OBJEXT),)
$(call DELFILE, proxies$(DELIM)*$(OBJEXT))
$(call DELFILE, stubs$(DELIM)*$(OBJEXT))
$(call DELFILE, wraps$(DELIM)*$(OBJEXT))
endif
$(call CLEAN)

Expand All @@ -106,5 +132,7 @@ distclean: clean
$(call DELFILE, .depend)
$(call DELFILE, proxies$(DELIM)*.c)
$(call DELFILE, stubs$(DELIM)*.c)
$(call DELFILE, wraps$(DELIM)*.c)
$(call DELFILE, $(SYSCALLWRAPS))

-include Make.dep
48 changes: 48 additions & 0 deletions syscall/syscall_names.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/****************************************************************************
* syscall/syscall_names.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>

#ifndef CONFIG_LIB_SYSCALL
#define CONFIG_LIB_SYSCALL
#endif
#include <syscall.h>

/****************************************************************************
* Public Data
****************************************************************************/

/* System call name tables. This table is indexed by the system call numbers
* defined above. Given the system call number, this table provides the
* name of the corresponding system function.
*/

const char *g_funcnames[SYS_nsyscalls] =
{
# define SYSCALL_LOOKUP1(f,n) #f
# define SYSCALL_LOOKUP(f,n) , #f
# include <sys/syscall_lookup.h>
# undef SYSCALL_LOOKUP1
# undef SYSCALL_LOOKUP
};
37 changes: 37 additions & 0 deletions syscall/syscall_wraps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/****************************************************************************
* syscall/syscall_wraps.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <nuttx/arch.h>

#ifndef UP_WRAPOPT
#define UP_WRAPOPT(f) --wrap f
#endif

#define SYSCALL_LOOKUP1(f,n) UP_WRAPOPT(f)
#define SYSCALL_LOOKUP(f,n) UP_WRAPOPT(f)

WRAPOPTSTARTS

#include <sys/syscall_lookup.h>
1 change: 1 addition & 0 deletions syscall/wraps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*.c
21 changes: 21 additions & 0 deletions syscall/wraps/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
############################################################################
# syscall/wraps/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

WRAP_SRCS := ${shell cd wraps; ls *.c 2>/dev/null }
5 changes: 5 additions & 0 deletions tools/Directories.mk
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ ifeq ($(CONFIG_LIB_SYSCALL),y)
CONTEXTDIRS += syscall
USERDEPDIRS += syscall
else
ifeq ($(CONFIG_SCHED_INSTRUMENTATION_SYSCALL),y)
CONTEXTDIRS += syscall
USERDEPDIRS += syscall
else
CLEANDIRS += syscall
endif
endif

ifeq ($(CONFIG_LIB_ZONEINFO_ROMFS),y)
CONTEXTDIRS += libs$(DELIM)libc
Expand Down
6 changes: 6 additions & 0 deletions tools/FlatLibs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ NUTTXLIBS += staging$(DELIM)libstubs$(LIBEXT)
USERLIBS += staging$(DELIM)libproxies$(LIBEXT)
endif

# Add library for system call instrumentation if needed

ifeq ($(CONFIG_SCHED_INSTRUMENTATION_SYSCALL),y)
NUTTXLIBS += staging$(DELIM)libwraps$(LIBEXT)
endif

# Add libraries for two pass build support. The special directory pass1
# may be populated so that application generated logic can be included into
# the kernel build
Expand Down
6 changes: 6 additions & 0 deletions tools/KernelLibs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ NUTTXLIBS += staging$(DELIM)libkmm$(LIBEXT) staging$(DELIM)libkarch$(LIBEXT)
USERLIBS += staging$(DELIM)libproxies$(LIBEXT) staging$(DELIM)libc$(LIBEXT)
USERLIBS += staging$(DELIM)libmm$(LIBEXT) staging$(DELIM)libarch$(LIBEXT)

# Add library for system call instrumentation if needed

ifeq ($(CONFIG_SCHED_INSTRUMENTATION_SYSCALL),y)
NUTTXLIBS += staging$(DELIM)libwraps$(LIBEXT)
endif

# Add libraries for C++ support. CXX, CXXFLAGS, and COMPILEXX must
# be defined in Make.defs for this to work!

Expand Down
6 changes: 6 additions & 0 deletions tools/LibTargets.mk
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ syscall$(DELIM)libstubs$(LIBEXT): pass2dep
staging$(DELIM)libstubs$(LIBEXT): syscall$(DELIM)libstubs$(LIBEXT)
$(Q) $(call INSTALL_LIB,$<,$@)

syscall$(DELIM)libwraps$(LIBEXT): pass2dep
$(Q) $(MAKE) -C syscall TOPDIR="$(TOPDIR)" libwraps$(LIBEXT) EXTRAFLAGS="$(KDEFINE) $(EXTRAFLAGS)"

staging$(DELIM)libwraps$(LIBEXT): syscall$(DELIM)libwraps$(LIBEXT)
$(Q) $(call INSTALL_LIB,$<,$@)

# Special case

ifeq ($(CONFIG_BUILD_FLAT),y)
Expand Down
6 changes: 6 additions & 0 deletions tools/ProtectedLibs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ NUTTXLIBS += staging$(DELIM)libkmm$(LIBEXT) staging$(DELIM)libkarch$(LIBEXT)
USERLIBS += staging$(DELIM)libproxies$(LIBEXT) staging$(DELIM)libc$(LIBEXT)
USERLIBS += staging$(DELIM)libmm$(LIBEXT) staging$(DELIM)libarch$(LIBEXT)

# Add library for system call instrumentation if needed

ifeq ($(CONFIG_SCHED_INSTRUMENTATION_SYSCALL),y)
NUTTXLIBS += staging$(DELIM)libwraps$(LIBEXT)
endif

# Add libraries for two pass build support. The special directory pass1
# may be populated so that application generated logic can be included into
# the kernel build
Expand Down
Loading

0 comments on commit 3767862

Please sign in to comment.