diff --git a/repos/dde_linux/include/lxip/lxip.h b/repos/dde_linux/include/lxip/lxip.h index c94bacdb9..88cded637 100644 --- a/repos/dde_linux/include/lxip/lxip.h +++ b/repos/dde_linux/include/lxip/lxip.h @@ -39,7 +39,7 @@ namespace Lxip { * * \return Reference to Socketcall object */ - Socketcall & init(char *address_config); + Socketcall & init(char const *address_config); typedef Genode::uint8_t uint8_t; typedef Genode::uint16_t uint16_t; diff --git a/repos/dde_linux/lib/import/import-lxip_include.mk b/repos/dde_linux/lib/import/import-lxip_include.mk new file mode 100644 index 000000000..0c06540bf --- /dev/null +++ b/repos/dde_linux/lib/import/import-lxip_include.mk @@ -0,0 +1,35 @@ +LXIP_CONTRIB_DIR := $(call select_from_ports,dde_linux)/src/lib/lxip +SRC_DIR := $(REP_DIR)/src/lib/lxip + +# architecture-dependent includes +ifeq ($(filter-out $(SPECS),x86),) + ARCH_SRC_INC_DIR += $(REP_DIR)/src/include/spec/x86 + ifeq ($(filter-out $(SPECS),32bit),) + ARCH_SRC_INC_DIR += $(REP_DIR)/src/include/spec/x86_32 + endif # 32bit + ifeq ($(filter-out $(SPECS),64bit),) + ARCH_SRC_INC_DIR += $(REP_DIR)/src/include/spec/x86_64 + endif # 64bit +endif # x86 + +ifeq ($(filter-out $(SPECS),arm),) + ARCH_SRC_INC_DIR += $(REP_DIR)/src/include/spec/arm + ifeq ($(filter-out $(SPECS),arm_v6),) + ARCH_SRC_INC_DIR += $(REP_DIR)/src/include/spec/arm_v6 + endif # arm_v6 + ifeq ($(filter-out $(SPECS),arm_v7),) + ARCH_SRC_INC_DIR += $(REP_DIR)/src/include/spec/arm_v7 + endif # arm_v7 +endif # arm + +# +# The order of include-search directories is important, we need to look into +# 'contrib' before falling back to our custom 'lx_emul.h' header. +# +INC_DIR += $(SRC_DIR) \ + $(SRC_DIR)/include +INC_DIR += $(REP_DIR)/src/include +INC_DIR += $(ARCH_SRC_INC_DIR) +INC_DIR += $(LXIP_CONTRIB_DIR)/include \ + $(LXIP_CONTRIB_DIR)/include/uapi \ +INC_DIR += $(LIB_CACHE_DIR)/lxip_include/include/include/include diff --git a/repos/dde_linux/lib/mk/lxip.mk b/repos/dde_linux/lib/mk/lxip.mk index c3181e965..a9f20a5e8 100644 --- a/repos/dde_linux/lib/mk/lxip.mk +++ b/repos/dde_linux/lib/mk/lxip.mk @@ -3,19 +3,11 @@ SHARED_LIB = yes LIB_DIR = $(REP_DIR)/src/lib/lxip LIB_INC_DIR = $(LIB_DIR)/include -LIBS += lx +LIBS += lxip_include LX_CONTRIB_DIR := $(call select_from_ports,dde_linux)/src/lib/lxip NET_DIR := $(LX_CONTRIB_DIR)/net -# -# The order of include-search directories is important, we need to look into -# 'contrib' before falling back to our custom 'lx_emul.h' header. -# -INC_DIR += $(LIB_INC_DIR) -INC_DIR += $(LX_CONTRIB_DIR)/include $(LX_CONTRIB_DIR)/include/uapi \ - $(LX_CONTRIB_DIR) - CC_OLEVEL = -O2 SETUP_SUFFIX = @@ -34,10 +26,12 @@ CC_C_OPT += -Wno-unused-but-set-variable -Wno-pointer-sign CC_C_OPT += -include $(LIB_INC_DIR)/lx_emul.h CC_CXX_OPT = -fpermissive -SRC_CC = dummies.cc env.cc lxcc_emul.cc nic_handler.cc socket_handler.cc \ +SRC_CC = dummies.cc lxcc_emul.cc nic_handler.cc socket_handler.cc \ timer_handler.cc -SRC_C += driver.c dummies_c.c init.c lxc_emul.c socket.c +SRC_CC += malloc.cc printf.cc + +SRC_C += driver.c dummies_c.c lxc_emul.c SRC_C += net/802/p8023.c SRC_C += $(addprefix net/core/,$(notdir $(wildcard $(NET_DIR)/core/*.c))) @@ -46,6 +40,7 @@ SRC_C += net/ethernet/eth.c SRC_C += net/netlink/af_netlink.c SRC_C += net/sched/sch_generic.c SRC_C += lib/checksum.c +SRC_C += lib/rhashtable.c SRC_C += drivers/net/loopback.c # DHCP support @@ -53,41 +48,9 @@ SRC_C += net/ipv4/ipconfig.c #SRC_C = net/ipv4/inet_connection_sock.c -# -# Determine the header files included by the contrib code. For each -# of these header files we create a symlink to 'lx_emul.h'. -# -GEN_INCLUDES := $(shell grep -rh "^\#include .*\/" $(LX_CONTRIB_DIR) |\ - sed "s/^\#include [^<\"]*[<\"]\([^>\"]*\)[>\"].*/\1/" | sort | uniq) - -# -# Filter out original Linux headers that exist in the contrib directory -# -NO_GEN_INCLUDES := $(shell cd $(LX_CONTRIB_DIR); find -name "*.h" | sed "s/.\///" | sed "s/.*include\///") -GEN_INCLUDES := $(filter-out $(NO_GEN_INCLUDES),$(GEN_INCLUDES)) - -# -# Put Linux headers in 'GEN_INC' dir, since some include use "../../" paths use -# three level include hierarchy -# -GEN_INC := $(shell pwd)/include/include/include - -$(shell mkdir -p $(GEN_INC)) - -GEN_INCLUDES := $(addprefix $(GEN_INC)/,$(GEN_INCLUDES)) -INC_DIR += $(GEN_INC) - -# -# Make sure to create the header symlinks prior building -# -$(SRC_C:.c=.o) $(SRC_CC:.cc=.o): $(GEN_INCLUDES) - net/ethernet/eth.o: SETUP_SUFFIX="_eth" -$(GEN_INCLUDES): - $(VERBOSE)mkdir -p $(dir $@) - $(VERBOSE)ln -s $(LIB_INC_DIR)/lx_emul.h $@ - vpath %.c $(LX_CONTRIB_DIR) vpath %.c $(LIB_DIR) vpath %.cc $(LIB_DIR) +vpath %.cc $(REP_DIR)/src/lx_kit diff --git a/repos/dde_linux/lib/mk/lxip_include.mk b/repos/dde_linux/lib/mk/lxip_include.mk new file mode 100644 index 000000000..bf8842109 --- /dev/null +++ b/repos/dde_linux/lib/mk/lxip_include.mk @@ -0,0 +1,35 @@ +ifeq ($(called_from_lib_mk),yes) + +LXIP_CONTRIB_DIR := $(call select_from_ports,dde_linux)/src/lib/lxip +LX_EMUL_H := $(REP_DIR)/src/lib/lxip/include/lx_emul.h + +# +# Determine the header files included by the contrib code. For each +# of these header files we create a symlink to 'lx_emul.h'. +# +GEN_INCLUDES := $(shell grep -rh "^\#include" $(LXIP_CONTRIB_DIR) |\ + sed "s/^\#include [^<\"]*[<\"]\([^>\"]*\)[>\"].*/\1/" |\ + sort | uniq) +# +# Filter out original Linux headers that exist in the contrib directory +# +NO_GEN_INCLUDES := $(shell cd $(LXIP_CONTRIB_DIR)/; find include -name "*.h" |\ + sed "s/.\///" | sed "s/.*include\///") +GEN_INCLUDES := $(filter-out $(NO_GEN_INCLUDES),$(GEN_INCLUDES)) + +# +# Put Linux headers in 'GEN_INC' dir, since some include use "../../" paths use +# three level include hierarchy +# +GEN_INC := $(shell pwd)/include/include/include +GEN_INCLUDES := $(addprefix $(GEN_INC)/,$(GEN_INCLUDES)) + +all: $(GEN_INCLUDES) + +$(GEN_INCLUDES): + $(VERBOSE)mkdir -p $(dir $@) + $(VERBOSE)ln -s $(LX_EMUL_H) $@ + +endif + +# vi: set ft=make : diff --git a/repos/dde_linux/lxip.list b/repos/dde_linux/lxip.list index fe26dabe8..1913bfbd4 100644 --- a/repos/dde_linux/lxip.list +++ b/repos/dde_linux/lxip.list @@ -1,141 +1,153 @@ -linux-3.9/drivers/net/loopback.c -linux-3.9/include/asm-generic/bitops/non-atomic.h -linux-3.9/include/linux/errqueue.h -linux-3.9/include/linux/etherdevice.h -linux-3.9/include/linux/ethtool.h -linux-3.9/include/linux/icmp.h -linux-3.9/include/linux/if_arp.h -linux-3.9/include/linux/if_ether.h -linux-3.9/include/linux/if_link.h -linux-3.9/include/linux/inetdevice.h -linux-3.9/include/linux/jhash.h -linux-3.9/include/linux/list.h -linux-3.9/include/linux/list_nulls.h -linux-3.9/include/linux/netdev_features.h -linux-3.9/include/linux/netdevice.h -linux-3.9/include/linux/net.h -linux-3.9/include/linux/netlink.h -linux-3.9/include/linux/skbuff.h -linux-3.9/include/linux/socket.h -linux-3.9/include/linux/swab.h -linux-3.9/include/linux/tcp.h -linux-3.9/include/linux/udp.h -linux-3.9/include/net/arp.h -linux-3.9/include/net/datalink.h -linux-3.9/include/net/dsfield.h -linux-3.9/include/net/dst.h -linux-3.9/include/net/dst_ops.h -linux-3.9/include/net/flow.h -linux-3.9/include/net/icmp.h -linux-3.9/include/net/inet_connection_sock.h -linux-3.9/include/net/inet_frag.h -linux-3.9/include/net/inet_hashtables.h -linux-3.9/include/net/inetpeer.h -linux-3.9/include/net/inet_sock.h -linux-3.9/include/net/inet_timewait_sock.h -linux-3.9/include/net/ipconfig.h -linux-3.9/include/net/ip_fib.h -linux-3.9/include/net/ip.h -linux-3.9/include/net/neighbour.h -linux-3.9/include/net/netlink.h -linux-3.9/include/net/netns/ipv4.h -linux-3.9/include/net/netns/mib.h -linux-3.9/include/net/ping.h -linux-3.9/include/net/pkt_sched.h -linux-3.9/include/net/protocol.h -linux-3.9/include/net/raw.h -linux-3.9/include/net/request_sock.h -linux-3.9/include/net/route.h -linux-3.9/include/net/sch_generic.h -linux-3.9/include/net/snmp.h -linux-3.9/include/net/sock.h -linux-3.9/include/net/tcp.h -linux-3.9/include/net/tcp_states.h -linux-3.9/include/net/timewait_sock.h -linux-3.9/include/net/udp.h -linux-3.9/include/net/udplite.h -linux-3.9/include/uapi/asm-generic/socket.h -linux-3.9/include/uapi/linux/byteorder/little_endian.h -linux-3.9/include/uapi/linux/errqueue.h -linux-3.9/include/uapi/linux/ethtool.h -linux-3.9/include/uapi/linux/fib_rules.h -linux-3.9/include/uapi/linux/gen_stats.h -linux-3.9/include/uapi/linux/icmp.h -linux-3.9/include/uapi/linux/if_addr.h -linux-3.9/include/uapi/linux/if_arp.h -linux-3.9/include/uapi/linux/if_ether.h -linux-3.9/include/uapi/linux/if.h -linux-3.9/include/uapi/linux/if_link.h -linux-3.9/include/uapi/linux/if_packet.h -linux-3.9/include/uapi/linux/in6.h -linux-3.9/include/uapi/linux/inet_diag.h -linux-3.9/include/uapi/linux/in.h -linux-3.9/include/uapi/linux/in_route.h -linux-3.9/include/uapi/linux/ip.h -linux-3.9/include/uapi/linux/neighbour.h -linux-3.9/include/uapi/linux/netconf.h -linux-3.9/include/uapi/linux/netdevice.h -linux-3.9/include/uapi/linux/netfilter.h -linux-3.9/include/uapi/linux/net.h -linux-3.9/include/uapi/linux/netlink.h -linux-3.9/include/uapi/linux/pkt_sched.h -linux-3.9/include/uapi/linux/route.h -linux-3.9/include/uapi/linux/rtnetlink.h -linux-3.9/include/uapi/linux/snmp.h -linux-3.9/include/uapi/linux/socket.h -linux-3.9/include/uapi/linux/sockios.h -linux-3.9/include/uapi/linux/swab.h -linux-3.9/include/uapi/linux/tcp.h -linux-3.9/include/uapi/linux/udp.h -linux-3.9/lib/checksum.c -linux-3.9/net/802/p8023.c -linux-3.9/net/core/datagram.c -linux-3.9/net/core/dev_addr_lists.c -linux-3.9/net/core/dev.c -linux-3.9/net/core/dst.c -linux-3.9/net/core/ethtool.c -linux-3.9/net/core/iovec.c -linux-3.9/net/core/neighbour.c -linux-3.9/net/core/net-sysfs.h -linux-3.9/net/core/request_sock.c -linux-3.9/net/core/skbuff.c -linux-3.9/net/core/sock.c -linux-3.9/net/core/stream.c -linux-3.9/net/core/utils.c -linux-3.9/net/ethernet/eth.c -linux-3.9/net/ipv4/af_inet.c -linux-3.9/net/ipv4/arp.c -linux-3.9/net/ipv4/devinet.c -linux-3.9/net/ipv4/fib_frontend.c -linux-3.9/net/ipv4/fib_lookup.h -linux-3.9/net/ipv4/fib_semantics.c -linux-3.9/net/ipv4/fib_trie.c -linux-3.9/net/ipv4/icmp.c -linux-3.9/net/ipv4/inet_connection_sock.c -linux-3.9/net/ipv4/inet_fragment.c -linux-3.9/net/ipv4/inet_hashtables.c -linux-3.9/net/ipv4/inetpeer.c -linux-3.9/net/ipv4/ipconfig.c -linux-3.9/net/ipv4/ip_forward.c -linux-3.9/net/ipv4/ip_fragment.c -linux-3.9/net/ipv4/ip_input.c -linux-3.9/net/ipv4/ip_options.c -linux-3.9/net/ipv4/ip_output.c -linux-3.9/net/ipv4/ip_sockglue.c -linux-3.9/net/ipv4/ping.c -linux-3.9/net/ipv4/protocol.c -linux-3.9/net/ipv4/raw.c -linux-3.9/net/ipv4/route.c -linux-3.9/net/ipv4/tcp_cong.c -linux-3.9/net/ipv4/tcp_cubic.c -linux-3.9/net/ipv4/tcp_diag.c -linux-3.9/net/ipv4/tcp_input.c -linux-3.9/net/ipv4/tcp_ipv4.c -linux-3.9/net/ipv4/tcp_minisocks.c -linux-3.9/net/ipv4/tcp.c -linux-3.9/net/ipv4/tcp_output.c -linux-3.9/net/ipv4/tcp_timer.c -linux-3.9/net/ipv4/udp_impl.h -linux-3.9/net/ipv4/udp.c -linux-3.9/net/netlink/af_netlink.c -linux-3.9/net/sched/sch_generic.c +linux-4.4.3/drivers/net/loopback.c +linux-4.4.3/include/asm-generic/atomic64.h +linux-4.4.3/include/asm-generic/bitops/__ffs.h +linux-4.4.3/include/asm-generic/bitops/__fls.h +linux-4.4.3/include/asm-generic/bitops/ffs.h +linux-4.4.3/include/asm-generic/bitops/fls.h +linux-4.4.3/include/asm-generic/bitops/fls64.h +linux-4.4.3/include/asm-generic/bitops/non-atomic.h +linux-4.4.3/include/linux/errqueue.h +linux-4.4.3/include/linux/etherdevice.h +linux-4.4.3/include/linux/ethtool.h +linux-4.4.3/include/linux/icmp.h +linux-4.4.3/include/linux/if_arp.h +linux-4.4.3/include/linux/if_ether.h +linux-4.4.3/include/linux/if_link.h +linux-4.4.3/include/linux/inetdevice.h +linux-4.4.3/include/linux/jhash.h +linux-4.4.3/include/linux/list.h +linux-4.4.3/include/linux/list_nulls.h +linux-4.4.3/include/linux/log2.h +linux-4.4.3/include/linux/netdev_features.h +linux-4.4.3/include/linux/netdevice.h +linux-4.4.3/include/linux/net.h +linux-4.4.3/include/linux/netlink.h +linux-4.4.3/include/linux/rbtree.h +linux-4.4.3/include/linux/rhashtable.h +linux-4.4.3/include/linux/skbuff.h +linux-4.4.3/include/linux/socket.h +linux-4.4.3/include/linux/swab.h +linux-4.4.3/include/linux/tcp.h +linux-4.4.3/include/linux/udp.h +linux-4.4.3/include/net/arp.h +linux-4.4.3/include/net/datalink.h +linux-4.4.3/include/net/dsfield.h +linux-4.4.3/include/net/dst.h +linux-4.4.3/include/net/dst_metadata.h +linux-4.4.3/include/net/dst_ops.h +linux-4.4.3/include/net/flow.h +linux-4.4.3/include/net/icmp.h +linux-4.4.3/include/net/inet_connection_sock.h +linux-4.4.3/include/net/inet_frag.h +linux-4.4.3/include/net/inet_hashtables.h +linux-4.4.3/include/net/inetpeer.h +linux-4.4.3/include/net/inet_sock.h +linux-4.4.3/include/net/inet_timewait_sock.h +linux-4.4.3/include/net/ipconfig.h +linux-4.4.3/include/net/ip_fib.h +linux-4.4.3/include/net/ip.h +linux-4.4.3/include/net/neighbour.h +linux-4.4.3/include/net/netlink.h +linux-4.4.3/include/net/netns/ipv4.h +linux-4.4.3/include/net/netns/mib.h +linux-4.4.3/include/net/ping.h +linux-4.4.3/include/net/pkt_sched.h +linux-4.4.3/include/net/protocol.h +linux-4.4.3/include/net/raw.h +linux-4.4.3/include/net/request_sock.h +linux-4.4.3/include/net/route.h +linux-4.4.3/include/net/sch_generic.h +linux-4.4.3/include/net/snmp.h +linux-4.4.3/include/net/sock.h +linux-4.4.3/include/net/tcp.h +linux-4.4.3/include/net/tcp_states.h +linux-4.4.3/include/net/timewait_sock.h +linux-4.4.3/include/net/udp.h +linux-4.4.3/include/net/udplite.h +linux-4.4.3/include/uapi/asm-generic/socket.h +linux-4.4.3/include/uapi/linux/byteorder/little_endian.h +linux-4.4.3/include/uapi/linux/errqueue.h +linux-4.4.3/include/uapi/linux/ethtool.h +linux-4.4.3/include/uapi/linux/fib_rules.h +linux-4.4.3/include/uapi/linux/gen_stats.h +linux-4.4.3/include/uapi/linux/icmp.h +linux-4.4.3/include/uapi/linux/if_addr.h +linux-4.4.3/include/uapi/linux/if_arp.h +linux-4.4.3/include/uapi/linux/if_ether.h +linux-4.4.3/include/uapi/linux/if.h +linux-4.4.3/include/uapi/linux/if_link.h +linux-4.4.3/include/uapi/linux/if_packet.h +linux-4.4.3/include/uapi/linux/in6.h +linux-4.4.3/include/uapi/linux/inet_diag.h +linux-4.4.3/include/uapi/linux/in.h +linux-4.4.3/include/uapi/linux/in_route.h +linux-4.4.3/include/uapi/linux/ip.h +linux-4.4.3/include/uapi/linux/neighbour.h +linux-4.4.3/include/uapi/linux/netconf.h +linux-4.4.3/include/uapi/linux/netdevice.h +linux-4.4.3/include/uapi/linux/netfilter.h +linux-4.4.3/include/uapi/linux/net.h +linux-4.4.3/include/uapi/linux/netlink.h +linux-4.4.3/include/uapi/linux/pkt_sched.h +linux-4.4.3/include/uapi/linux/route.h +linux-4.4.3/include/uapi/linux/rtnetlink.h +linux-4.4.3/include/uapi/linux/snmp.h +linux-4.4.3/include/uapi/linux/socket.h +linux-4.4.3/include/uapi/linux/sockios.h +linux-4.4.3/include/uapi/linux/swab.h +linux-4.4.3/include/uapi/linux/tcp.h +linux-4.4.3/include/uapi/linux/udp.h +linux-4.4.3/lib/checksum.c +linux-4.4.3/lib/rbtree.c +linux-4.4.3/lib/rhashtable.c +linux-4.4.3/net/802/p8023.c +linux-4.4.3/net/core/datagram.c +linux-4.4.3/net/core/dev_addr_lists.c +linux-4.4.3/net/core/dev.c +linux-4.4.3/net/core/dst.c +linux-4.4.3/net/core/ethtool.c +linux-4.4.3/net/core/neighbour.c +linux-4.4.3/net/core/net-sysfs.h +linux-4.4.3/net/core/request_sock.c +linux-4.4.3/net/core/skbuff.c +linux-4.4.3/net/core/sock.c +linux-4.4.3/net/core/stream.c +linux-4.4.3/net/core/utils.c +linux-4.4.3/net/ethernet/eth.c +linux-4.4.3/net/ipv4/af_inet.c +linux-4.4.3/net/ipv4/arp.c +linux-4.4.3/net/ipv4/devinet.c +linux-4.4.3/net/ipv4/fib_frontend.c +linux-4.4.3/net/ipv4/fib_lookup.h +linux-4.4.3/net/ipv4/fib_semantics.c +linux-4.4.3/net/ipv4/fib_trie.c +linux-4.4.3/net/ipv4/icmp.c +linux-4.4.3/net/ipv4/inet_connection_sock.c +linux-4.4.3/net/ipv4/inet_fragment.c +linux-4.4.3/net/ipv4/inet_hashtables.c +linux-4.4.3/net/ipv4/inetpeer.c +linux-4.4.3/net/ipv4/ipconfig.c +linux-4.4.3/net/ipv4/ip_forward.c +linux-4.4.3/net/ipv4/ip_fragment.c +linux-4.4.3/net/ipv4/ip_input.c +linux-4.4.3/net/ipv4/ip_options.c +linux-4.4.3/net/ipv4/ip_output.c +linux-4.4.3/net/ipv4/ip_sockglue.c +linux-4.4.3/net/ipv4/ping.c +linux-4.4.3/net/ipv4/protocol.c +linux-4.4.3/net/ipv4/raw.c +linux-4.4.3/net/ipv4/route.c +linux-4.4.3/net/ipv4/tcp_cong.c +linux-4.4.3/net/ipv4/tcp_cubic.c +linux-4.4.3/net/ipv4/tcp_diag.c +linux-4.4.3/net/ipv4/tcp_input.c +linux-4.4.3/net/ipv4/tcp_ipv4.c +linux-4.4.3/net/ipv4/tcp_minisocks.c +linux-4.4.3/net/ipv4/tcp.c +linux-4.4.3/net/ipv4/tcp_output.c +linux-4.4.3/net/ipv4/tcp_timer.c +linux-4.4.3/net/ipv4/udp_impl.h +linux-4.4.3/net/ipv4/udp.c +linux-4.4.3/net/netlink/af_netlink.c +linux-4.4.3/net/netlink/af_netlink.h +linux-4.4.3/net/sched/sch_generic.c diff --git a/repos/dde_linux/patches/lxip_request_sock.patch b/repos/dde_linux/patches/lxip_request_sock.patch new file mode 100644 index 000000000..2f35391f8 --- /dev/null +++ b/repos/dde_linux/patches/lxip_request_sock.patch @@ -0,0 +1,23 @@ +diff --git a/include/net/request_sock.h b/include/net/request_sock.h +index a0dde04..dccc51f 100644 +--- a/include/net/request_sock.h ++++ b/include/net/request_sock.h +@@ -109,7 +109,7 @@ reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener, + static inline void reqsk_free(struct request_sock *req) + { + /* temporary debugging */ +- WARN_ON_ONCE(atomic_read(&req->rsk_refcnt) != 0); ++ // WARN_ON_ONCE(atomic_read(&req->rsk_refcnt) != 0); + + req->rsk_ops->destructor(req); + if (req->rsk_listener) +@@ -120,7 +120,8 @@ static inline void reqsk_free(struct request_sock *req) + + static inline void reqsk_put(struct request_sock *req) + { +- if (atomic_dec_and_test(&req->rsk_refcnt)) ++ if (atomic_dec_and_test(&req->rsk_refcnt) ++ || req->rsk_refcnt.counter == 1) + reqsk_free(req); + } + diff --git a/repos/dde_linux/patches/lxip_sk_wq.patch b/repos/dde_linux/patches/lxip_sk_wq.patch new file mode 100644 index 000000000..33b50d2d8 --- /dev/null +++ b/repos/dde_linux/patches/lxip_sk_wq.patch @@ -0,0 +1,13 @@ +diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c +index 5c5db66..6cb68a1 100644 +--- a/net/ipv4/af_inet.c ++++ b/net/ipv4/af_inet.c +@@ -764,6 +764,8 @@ int inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, + + sock_rps_record_flow(sk); + ++ if (sk->sk_wq == 0) sk->sk_wq = sock->wq; ++ + err = sk->sk_prot->recvmsg(sk, msg, size, flags & MSG_DONTWAIT, + flags & ~MSG_DONTWAIT, &addr_len); + if (err >= 0) diff --git a/repos/dde_linux/patches/lxip_skbuff.patch b/repos/dde_linux/patches/lxip_skbuff.patch deleted file mode 100644 index a7464538d..000000000 --- a/repos/dde_linux/patches/lxip_skbuff.patch +++ /dev/null @@ -1,35 +0,0 @@ -commit 1843c9d95c0a7f6cf04357bf26633cfd2e5bdda4 -Author: Sebastian Sumpf -Date: Mon Jun 2 13:34:18 2014 +0200 - - skbuff.patch - ---- a/net/core/skbuff.c -+++ b/net/core/skbuff.c -@@ -414,23 +414,9 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, - unsigned int fragsz = SKB_DATA_ALIGN(length + NET_SKB_PAD) + - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); - -- if (fragsz <= PAGE_SIZE && !(gfp_mask & (__GFP_WAIT | GFP_DMA))) { -- void *data; -- -- if (sk_memalloc_socks()) -- gfp_mask |= __GFP_MEMALLOC; -- -- data = __netdev_alloc_frag(fragsz, gfp_mask); -- -- if (likely(data)) { -- skb = build_skb(data, fragsz); -- if (unlikely(!skb)) -- put_page(virt_to_head_page(data)); -- } -- } else { -- skb = __alloc_skb(length + NET_SKB_PAD, gfp_mask, -- SKB_ALLOC_RX, NUMA_NO_NODE); -- } -+ skb = __alloc_skb(length + NET_SKB_PAD, gfp_mask, -+ SKB_ALLOC_RX, NUMA_NO_NODE); -+ - if (likely(skb)) { - skb_reserve(skb, NET_SKB_PAD); - skb->dev = dev; diff --git a/repos/dde_linux/patches/lxip_skbuff_cast.patch b/repos/dde_linux/patches/lxip_skbuff_cast.patch new file mode 100644 index 000000000..5e63596db --- /dev/null +++ b/repos/dde_linux/patches/lxip_skbuff_cast.patch @@ -0,0 +1,13 @@ +diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h +index 9147f9f..c63ee5c 100644 +--- a/include/linux/skbuff.h ++++ b/include/linux/skbuff.h +@@ -3281,7 +3281,7 @@ static inline void skb_remcsum_process(struct sk_buff *skb, void *ptr, + + if (unlikely(skb->ip_summed != CHECKSUM_COMPLETE)) { + __skb_checksum_complete(skb); +- skb_postpull_rcsum(skb, skb->data, ptr - (void *)skb->data); ++ skb_postpull_rcsum(skb, skb->data, (unsigned char*)ptr - skb->data); + } + + delta = remcsum_adjust(ptr, skb->csum, start, offset); diff --git a/repos/dde_linux/patches/lxip_tcp.patch b/repos/dde_linux/patches/lxip_tcp.patch deleted file mode 100644 index 4b9b04f94..000000000 --- a/repos/dde_linux/patches/lxip_tcp.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 8b2f74f2258b62ca0e62656cdccbc9159aeab893 Mon Sep 17 00:00:00 2001 -From: Sebastian Sumpf -Date: Tue, 6 Aug 2013 16:12:54 +0200 -Subject: [PATCH] L4Linux: Increase TCP-window size - -TCP window size is calculated by the amount of memory within L4Linux, use a -larger window size to allow acceptable performance even on smaller VMs. ---- - net/ipv4/tcp.c | 7 +++++++ - 1 file changed, 7 insertions(+) - -diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c -index e220207..29613bf 100644 ---- a/net/ipv4/tcp.c -+++ b/net/ipv4/tcp.c -@@ -3648,6 +3648,13 @@ void __init tcp_init(void) - tcp_init_mem(&init_net); - /* Set per-socket limits to no more than 1/128 the pressure threshold */ - limit = nr_free_buffer_pages() << (PAGE_SHIFT - 7); -+ -+ /* -+ * Adjust limit so it performs well on systems with little memory. If -+ * this causes errors increase L4Linux main memory -+ */ -+ limit = limit < 1024U * 1024 ? 1024U * 1024 : limit; -+ - max_wshare = min(4UL*1024*1024, limit); - max_rshare = min(6UL*1024*1024, limit); - --- -1.8.4 - diff --git a/repos/dde_linux/ports/dde_linux.hash b/repos/dde_linux/ports/dde_linux.hash index 76513228b..40cd28816 100644 --- a/repos/dde_linux/ports/dde_linux.hash +++ b/repos/dde_linux/ports/dde_linux.hash @@ -1 +1 @@ -0391d74c0aa610098907fafca8ef399875a12a70 +9f095930834c35a2dfc8eaf58b6905081f206c34 diff --git a/repos/dde_linux/ports/dde_linux.port b/repos/dde_linux/ports/dde_linux.port index 46a3db59c..dc9ee93c4 100644 --- a/repos/dde_linux/ports/dde_linux.port +++ b/repos/dde_linux/ports/dde_linux.port @@ -54,7 +54,8 @@ HASH_INPUT += $(REP_DIR)/intel_fb.list # mac80211 stack, iwlwifi sources # SRC_DIR_WIFI := src/lib/wifi -URL(wifi) := https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.4.3.tar.xz +VERSION_WIFI := 4.4.3 +URL(wifi) := https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-$(VERSION_WIFI).tar.xz SHA(wifi) := 336d66925a15ce9077cbf2c38acbdc6c2644e33f DIR(wifi) := $(SRC_DIR_WIFI) TAR_OPT(wifi) := --strip-components=1 --files-from $(REP_DIR)/wifi.list @@ -64,9 +65,9 @@ HASH_INPUT += $(REP_DIR)/wifi.list # IP stack sources # SRC_DIR_LXIP := src/lib/lxip -VERSION_LXIP := 3.9 -URL(lxip) := http://www.kernel.org/pub/linux/kernel/v3.x/linux-$(VERSION_LXIP).tar.gz -SHA(lxip) := 7979f0d670838d0552c7ede5cc06497b81dcd812 +VERSION_LXIP := 4.4.3 +URL(lxip) := http://www.kernel.org/pub/linux/kernel/v4.x/linux-$(VERSION_LXIP).tar.xz +SHA(lxip) := 336d66925a15ce9077cbf2c38acbdc6c2644e33f DIR(lxip) := $(SRC_DIR_LXIP) TAR_OPT(lxip) := --strip-components=1 --files-from $(REP_DIR)/lxip.list HASH_INPUT += $(REP_DIR)/lxip.list @@ -155,11 +156,12 @@ PATCHES += $(addprefix patches/,$(notdir $(wildcard $(REP_DIR)/patches/usb*.patc #IP stack LXIP_OPT = -p1 -d$(SRC_DIR_LXIP) -PATCH_OPT(patches/lxip_icmp.patch) := $(LXIP_OPT) -PATCH_OPT(patches/lxip_ip_config.patch) := $(LXIP_OPT) -PATCH_OPT(patches/lxip_skbuff.patch) := $(LXIP_OPT) -PATCH_OPT(patches/lxip_tcp.patch) := $(LXIP_OPT) -PATCH_OPT(patches/lxip_netlink.patch) := $(LXIP_OPT) +PATCH_OPT(patches/lxip_icmp.patch) := $(LXIP_OPT) +PATCH_OPT(patches/lxip_ip_config.patch) := $(LXIP_OPT) +PATCH_OPT(patches/lxip_netlink.patch) := $(LXIP_OPT) +PATCH_OPT(patches/lxip_request_sock.patch) := $(LXIP_OPT) +PATCH_OPT(patches/lxip_sk_wq.patch) := $(LXIP_OPT) +PATCH_OPT(patches/lxip_skbuff_cast.patch) := $(LXIP_OPT) # WIFI WIFI_OPT = -p1 -d$(SRC_DIR_WIFI) diff --git a/repos/dde_linux/run/lxip_http_srv.run b/repos/dde_linux/run/lxip_http_srv.run new file mode 100644 index 000000000..fd8b6e5fd --- /dev/null +++ b/repos/dde_linux/run/lxip_http_srv.run @@ -0,0 +1,149 @@ +set use_usb_driver [expr [have_spec omap4] || [have_spec arndale] || [have_spec rpi]] +set use_nic_driver [expr [have_spec linux] || [expr !$use_usb_driver && ![have_spec imx53] && ![have_spec hw_odroid_xu] && ![have_spec linux] && ![have_spec hw_wand_quad]]] + +requires_installation_of lynx + +# +# Build +# + +set build_components { + core init + drivers/timer drivers/nic + test/lxip/http_srv +} + +lappend_if $use_usb_driver build_components drivers/usb +lappend_if [have_spec gpio] build_components drivers/gpio + +source ${genode_dir}/repos/base/run/platform_drv.inc +append_platform_drv_build_components + +build $build_components + +create_boot_directory + +# +# Generate config +# + +set config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if [have_spec gpio] config { + + + + + } + +append_if $use_usb_driver config { + + + + + + + + + } + +append_platform_drv_config + +append_if $use_nic_driver config { + + + + } + +append config { + +} + +install_config $config + +# +# Boot modules +# + +# generic modules +set boot_modules { + core init timer + ld.lib.so libc.lib.so lxip.lib.so test-lxip_http_srv + libc_resolv.lib.so +} + +# platform-specific modules +lappend_if $use_usb_driver boot_modules usb_drv +lappend_if $use_nic_driver boot_modules nic_drv +lappend_if [have_spec gpio] boot_modules gpio_drv + +append_platform_drv_boot_modules + +build_boot_image $boot_modules + +# +# Execute test case +# + +# qemu config +append qemu_args " -m 128 -nographic " + +append_if [have_spec x86] qemu_args " -net nic,model=e1000 " +append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 " + +append qemu_args " -net user -redir tcp:5555::80 " + + run_genode_until forever + +set match_string "ipaddr=(\[0-9\]+\.\[0-9\]+\.\[0-9\]+\.\[0-9\]+).*\n" +run_genode_until $match_string 30 + +if {[have_include "power_on/qemu"]} { + set uri "http://localhost:5555/" +} else { + regexp $match_string $output all ip_addr + + set uri "http://$ip_addr:80/" +} + +puts "http server is up, try to query website $uri" + +set website [exec lynx -dump $uri] + +puts "response:\n$website" + +if {![regexp {Welcome to our HTTP demonstration server!} $website dummy]} { + puts stderr "Query returned unexpected website" + exit 2; +} + +# vi: set ft=tcl : diff --git a/repos/dde_linux/run/lxip_udp_echo.run b/repos/dde_linux/run/lxip_udp_echo.run new file mode 100644 index 000000000..1178cdb1d --- /dev/null +++ b/repos/dde_linux/run/lxip_udp_echo.run @@ -0,0 +1,125 @@ +set use_usb_driver [expr [have_spec omap4] || [have_spec arndale] || [have_spec rpi]] +set use_nic_driver [expr [have_spec linux] || [expr !$use_usb_driver && ![have_spec imx53] && ![have_spec hw_odroid_xu] && ![have_spec linux] && ![have_spec hw_wand_quad]]] + +# +# Build +# + +set build_components { + core init + drivers/timer drivers/nic + test/lxip/udp_echo +} + +lappend_if $use_usb_driver build_components drivers/usb +lappend_if [have_spec gpio] build_components drivers/gpio + +source ${genode_dir}/repos/base/run/platform_drv.inc +append_platform_drv_build_components + +build $build_components + +create_boot_directory + +# +# Generate config +# + +set config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if [have_spec gpio] config { + + + + + } + +append_if $use_usb_driver config { + + + + + + + + + } + +append_platform_drv_config + +append_if $use_nic_driver config { + + + + } + +append config { + +} + +install_config $config + +# +# Boot modules +# + +# generic modules +set boot_modules { + core init timer + ld.lib.so libc.lib.so lxip.lib.so test-lxip_udp_echo + libc_resolv.lib.so +} + +# platform-specific modules +lappend_if $use_usb_driver boot_modules usb_drv +lappend_if $use_nic_driver boot_modules nic_drv +lappend_if [have_spec gpio] boot_modules gpio_drv + +append_platform_drv_boot_modules + +build_boot_image $boot_modules + +# +# Execute test case +# + +# qemu config +append qemu_args " -m 128 -nographic " + +append_if [have_spec x86] qemu_args " -net nic,model=e1000 " +append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 " + +append qemu_args " -net user -redir tcp:5555::80 " + +run_genode_until forever + +# vi: set ft=tcl : diff --git a/repos/dde_linux/src/lib/libc_lxip/init.cc b/repos/dde_linux/src/lib/libc_lxip/init.cc index 3b3bcb387..46762e0d6 100644 --- a/repos/dde_linux/src/lib/libc_lxip/init.cc +++ b/repos/dde_linux/src/lib/libc_lxip/init.cc @@ -18,7 +18,7 @@ #include #include -extern void create_lxip_plugin(char *address_config); +extern void create_lxip_plugin(char const *address_config); void __attribute__((constructor)) init_libc_lxip(void) { @@ -26,7 +26,7 @@ void __attribute__((constructor)) init_libc_lxip(void) char netmask_str[16] = {0}; char gateway_str[16] = {0}; char address_buf[128]; - char *address_config; + char const *address_config; try { Genode::Xml_node libc_node = Genode::config()->xml_node().sub_node("libc"); diff --git a/repos/dde_linux/src/lib/libc_lxip/plugin.cc b/repos/dde_linux/src/lib/libc_lxip/plugin.cc index 674104d0d..af6fdf0eb 100644 --- a/repos/dde_linux/src/lib/libc_lxip/plugin.cc +++ b/repos/dde_linux/src/lib/libc_lxip/plugin.cc @@ -81,7 +81,7 @@ struct Plugin : Libc::Plugin /** * Constructor */ - Plugin(char *address_config); + Plugin(char const *address_config); bool supports_select(int nfds, fd_set *readfds, @@ -138,7 +138,7 @@ struct Plugin : Libc::Plugin }; -Plugin::Plugin(char *address_config) : socketcall(Lxip::init(address_config)) +Plugin::Plugin(char const *address_config) : socketcall(Lxip::init(address_config)) { PDBG("using the lxip libc plugin"); } @@ -649,7 +649,7 @@ int Plugin::translate_ops_linux(int optname) } /* unnamed namespace */ -void create_lxip_plugin(char *address_config) +void create_lxip_plugin(char const *address_config) { static Plugin lxip_plugin(address_config); } diff --git a/repos/dde_linux/src/lib/lxip/driver.c b/repos/dde_linux/src/lib/lxip/driver.c index 01a66ef23..e9ff9fed0 100644 --- a/repos/dde_linux/src/lib/lxip/driver.c +++ b/repos/dde_linux/src/lib/lxip/driver.c @@ -6,27 +6,31 @@ */ /* - * Copyright (C) 2013 Genode Labs GmbH + * Copyright (C) 2013-2016 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. */ +/* Linux includes */ #include #include +/* local includes */ #include #include + static struct net_device *_dev; + static int driver_net_open(struct net_device *dev) { - printk("%s called\n",__func__); _dev = dev; return 0; } + int driver_net_xmit(struct sk_buff *skb, struct net_device *dev) { struct net_device_stats *stats = (struct net_device_stats*) netdev_priv(dev); @@ -52,37 +56,6 @@ int driver_net_xmit(struct sk_buff *skb, struct net_device *dev) } -void net_driver_rx(void *addr, unsigned long size) -{ - struct net_device_stats *stats; - - if (!_dev) - return; - - stats = (struct net_device_stats*) netdev_priv(_dev); - - /* allocate skb */ - struct sk_buff *skb = dev_alloc_skb(size + 4); - if (!skb) { - printk(KERN_NOTICE "genode_net_rx: low on mem - packet dropped!\n"); - stats->rx_dropped++; - return; - } - - /* copy packet */ - memcpy(skb_put(skb, size), addr, size); - - skb->dev = _dev; - skb->protocol = eth_type_trans(skb, _dev); - skb->ip_summed = CHECKSUM_NONE; - - netif_receive_skb(skb); - - stats->rx_packets++; - stats->rx_bytes += size; -} - - static const struct net_device_ops driver_net_ops = { .ndo_open = driver_net_open, @@ -118,6 +91,42 @@ out: return err; } + module_init(driver_init); +/** + * Called by Nic_client when a packet was received + */ +void net_driver_rx(void *addr, unsigned long size) +{ + struct net_device_stats *stats; + + if (!_dev) + return; + + stats = (struct net_device_stats*) netdev_priv(_dev); + + /* allocate skb */ + enum { + ADDITIONAL_HEADROOM = 4, /* smallest value found by trial & error */ + }; + struct sk_buff *skb = dev_alloc_skb(size + ADDITIONAL_HEADROOM); + if (!skb) { + printk(KERN_NOTICE "genode_net_rx: low on mem - packet dropped!\n"); + stats->rx_dropped++; + return; + } + + /* copy packet */ + memcpy(skb_put(skb, size), addr, size); + + skb->dev = _dev; + skb->protocol = eth_type_trans(skb, _dev); + skb->ip_summed = CHECKSUM_NONE; + + netif_receive_skb(skb); + + stats->rx_packets++; + stats->rx_bytes += size; +} diff --git a/repos/dde_linux/src/lib/lxip/dummies.cc b/repos/dde_linux/src/lib/lxip/dummies.cc index 036ae83bf..dcd3ecc25 100644 --- a/repos/dde_linux/src/lib/lxip/dummies.cc +++ b/repos/dde_linux/src/lib/lxip/dummies.cc @@ -5,13 +5,16 @@ */ /* - * Copyright (C) 2013 Genode Labs GmbH + * Copyright (C) 2013-2016 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. */ +/* Genode includes */ #include +#include + extern "C" { typedef long DUMMY; @@ -20,6 +23,7 @@ enum { SHOW_DUMMY = 0, SHOW_SKIP = 0, SHOW_RET = 0, + SHOW_SHOW = 1, }; #define DUMMY(retval, name) \ @@ -43,6 +47,22 @@ enum { return retval; \ } +#define DUMMY_SHOW(retval, name) \ + DUMMY name(void) { \ + if (SHOW_SHOW) \ + PWRN( #name " called (from %p) return %d", __builtin_return_address(0), retval); \ + return retval; \ +} + +#define DUMMY_STOP(retval, name) \ + DUMMY name(void) { \ + do { \ + PWRN( #name " called (from %p) stopped", __builtin_return_address(0)); \ + Genode::sleep_forever(); \ + } while (0); \ + return retval; \ +} + /* * Changed return values @@ -76,6 +96,7 @@ DUMMY_RET(0, vlan_tx_tag_present) DUMMY_RET(1, xfrm4_policy_check) DUMMY_RET(0, xfrm_sk_clone_policy) DUMMY_RET(0, xfrm_decode_session_reverse) +DUMMY_RET(1, try_module_get) /* important in sk_prot_alloc() */ /* @@ -114,7 +135,7 @@ DUMMY_SKIP(-1, smp_mb) DUMMY_SKIP(-1, smp_rmb) DUMMY_SKIP(-1, smp_wmb) DUMMY_SKIP(-1, spin_lock_irqsave) -DUMMY_SKIP( 1, spin_trylock) +DUMMY_RET( 1, spin_trylock) DUMMY_SKIP(-1, spin_unlock_irqrestore) DUMMY_SKIP(-1, synchronize_rcu) DUMMY_SKIP(-1, trace_kfree_skb) @@ -207,8 +228,6 @@ DUMMY(-1, dump_stack) DUMMY(-1, ether_addr_equal_64bits) DUMMY(-1, exit_fn) DUMMY(-1, file_inode) -DUMMY(-1, finish_wait) -DUMMY(-1, __fls) DUMMY(-1, fls64) DUMMY(-1, free_pages) DUMMY(-1, from_kgid) @@ -222,7 +241,10 @@ DUMMY(-1, gen_kill_estimator) DUMMY(-1, get_current_groups) DUMMY(-1, get_ds) DUMMY(-1, __get_free_pages) -DUMMY(-1, get_fs) + +DUMMY_SKIP(0, get_fs) +DUMMY_SKIP(0, set_fs) + DUMMY(-1, get_net_ns_by_fd) DUMMY(-1, get_net_ns_by_pid) DUMMY(-1, getnstimeofday) @@ -238,8 +260,7 @@ DUMMY(-1, hlist_add_before_rcu) DUMMY(-1, hlist_nulls_del) DUMMY(-1, hlist_nulls_empty) DUMMY(-1, hotcpu_notifier) -DUMMY(-1, hweight32) -DUMMY(-1, hweight64) +DUMMY_STOP(0, hweight64) DUMMY(-1, inet_ctl_sock_destroy) DUMMY(-1, inet_diag_dump_icsk) DUMMY(-1, inet_diag_dump_one_icsk) @@ -291,17 +312,11 @@ DUMMY(-1, is_a_nulls) DUMMY(-1, is_multicast_ether_addr) DUMMY(-1, is_valid_ether_addr) DUMMY(-1, is_vlan_dev) -DUMMY(-1, jiffies_delta_to_clock_t) -DUMMY(-1, jiffies_to_clock_t) -DUMMY(-1, jiffies_to_msecs) -DUMMY(-1, jiffies_to_usecs) DUMMY(-1, kernel_sendmsg) DUMMY(-1, kmem_cache_destroy) DUMMY(-1, kobject_put) DUMMY(-1, kobject_uevent) DUMMY(-1, krealloc) -DUMMY(-1, kref_init) -DUMMY(-1, kref_put) DUMMY(-1, kstrdup) DUMMY(-1, kstrtoul) DUMMY(-1, ktime_equal) @@ -319,7 +334,7 @@ DUMMY(-1, list_replace_rcu) DUMMY(-1, local_softirq_pending) DUMMY(-1, lockdep_rtnl_is_held) DUMMY(-1, min) -DUMMY(-1, mod_delayed_work) +DUMMY_STOP(-1, mod_delayed_work) DUMMY(-1, module_put) DUMMY(-1, move_addr_to_kernel) DUMMY(-1, mq_qdisc_ops) @@ -360,8 +375,11 @@ DUMMY(-1, preempt_disable) DUMMY(-1, preempt_enable) DUMMY(-1, prefetch) DUMMY(-1, pr_emerg) -DUMMY(-1, prepare_to_wait) -DUMMY(-1, prepare_to_wait_exclusive) + +DUMMY_SKIP(0, finish_wait) +DUMMY_SKIP(0, prepare_to_wait) +DUMMY_SKIP(0, prepare_to_wait_exclusive) + DUMMY(-1, pr_err) DUMMY(-1, pr_info) DUMMY(-1, pr_info_once) @@ -372,7 +390,6 @@ DUMMY(-1, put_cpu_var) DUMMY(-1, put_cred) DUMMY(-1, put_device) DUMMY(-1, put_pid) -DUMMY(-1, put_unaligned_be32) DUMMY(-1, __raise_softirq_irqoff) DUMMY(-1, raise_softirq_irqoff) DUMMY(-1, random32) @@ -391,10 +408,10 @@ DUMMY(-1, roundup_pow_of_two) DUMMY(-1, rt_genid_bump) DUMMY(-1, rtnetlink_init) DUMMY(-1, __rtnl_unlock) -DUMMY(-1, schedule) -DUMMY(-1, schedule_delayed_work) -DUMMY(-1, schedule_timeout_interruptible) -DUMMY(-1, schedule_work) +DUMMY_STOP(-1, schedule) +DUMMY_STOP(-1, schedule_delayed_work) +DUMMY_STOP(-1, schedule_timeout_interruptible) +DUMMY_STOP(-1, schedule_work) DUMMY(-1, scm_destroy) DUMMY(-1, scm_recv) DUMMY(-1, scm_send) @@ -418,14 +435,12 @@ DUMMY(-1, security_socket_getpeersec_stream) DUMMY(-1, security_sock_graft) DUMMY(-1, send_sigurg) DUMMY(-1, send_sig) -DUMMY(-1, __set_bit) -DUMMY(-1, set_bit) +DUMMY_STOP(-1, set_bit) DUMMY(-1, __set_current_state) DUMMY(-1, set_current_state) -DUMMY(-1, set_fs) -DUMMY(-1, sg_mark_end) -DUMMY(-1, sg_set_buf) -DUMMY(-1, sg_set_page) +DUMMY_STOP(-1, sg_mark_end) +DUMMY_STOP(-1, sg_set_buf) +DUMMY_STOP(-1, sg_set_page) DUMMY(-1, sha_transform) DUMMY(-1, si_meminfo) DUMMY(-1, S_ISSOCK) @@ -476,14 +491,13 @@ DUMMY(-1, test_and_set_bit) DUMMY(-1, test_bit) DUMMY(-1, textsearch_find) DUMMY(-1, __this_cpu_read) -DUMMY(-1, trace_napi_poll) -DUMMY(-1, trace_net_dev_queue) -DUMMY(-1, trace_netif_rx) -DUMMY(-1, trace_skb_copy_datagram_iovec) -DUMMY(-1, trace_sock_exceed_buf_limit) -DUMMY(-1, trace_sock_rcvqueue_full) -DUMMY(-1, trace_udp_fail_queue_rcv_skb) -DUMMY(-1, try_module_get) +DUMMY_SKIP(-1, trace_napi_poll) +DUMMY_SKIP(-1, trace_net_dev_queue) +DUMMY_SKIP(-1, trace_netif_rx) +DUMMY_SKIP(-1, trace_skb_copy_datagram_iovec) +DUMMY_SKIP(-1, trace_sock_exceed_buf_limit) +DUMMY_SKIP(-1, trace_sock_rcvqueue_full) +DUMMY_SKIP(-1, trace_udp_fail_queue_rcv_skb) DUMMY(-1, tsk_restore_flags) DUMMY(-1, u64_stats_fetch_begin_bh) DUMMY(-1, u64_stats_fetch_retry_bh) @@ -491,7 +505,6 @@ DUMMY(-1, u64_stats_update_begin) DUMMY(-1, u64_stats_update_end) DUMMY(-1, udplite4_register) DUMMY(-1, uid_eq) -DUMMY(-1, vfree) DUMMY(-1, virt_to_page) DUMMY(-1, vlan_do_receive) DUMMY(-1, __vlan_put_tag) @@ -511,6 +524,160 @@ DUMMY(-1, xfrm4_udp_encap_rcv) DUMMY(-1, xfrm_sk_free_policy) DUMMY(-1, xfrm_user_policy) DUMMY(-1, yield) -DUMMY(-1, __xchg) -} /* extern "C" */ +DUMMY(0, __inet_twsk_schedule) +// DUMMY_RET(0xdeadbeef, __netlink_kernel_create) /* needs to be != 0, otherwise FIB will nag */ +// DUMMY(0, __nlmsg_put) +DUMMY(0, __skb_flow_dissect) +DUMMY(0, __skb_get_hash) +DUMMY(0, __skb_get_poff) +DUMMY(0, __sock_tx_timestamp) +DUMMY(0, __this_cpu_write) +DUMMY(0, __vlan_get_protocol) +DUMMY(0, __vlan_hwaccel_push_inside) +DUMMY(0, __vlan_hwaccel_put_tag) +DUMMY(0, __vlan_insert_tag) +DUMMY(0, bpf_tell_extensions) +DUMMY_STOP(0, cancel_work_sync) +DUMMY_STOP(0, copy_from_iter_nocache) +// DUMMY(0, core_netlink_proto_init) +// DUMMY(0, csum_and_copy_from_iter) +// DUMMY_STOP(0, csum_and_copy_to_iter) +DUMMY(0, csum_ipv6_magic) +DUMMY(0, csum_replace4) +DUMMY(0, file_ns_capable) +DUMMY(0, find_first_bit) +DUMMY(0, find_next_bit) +DUMMY(0, flow_keys_buf_dissector) +DUMMY(0, fnhe_genid) +DUMMY(0, gfpflags_allow_blocking) +DUMMY(0, hlist_add_behind_rcu) +DUMMY(0, hlist_replace_rcu) +DUMMY(0, hrtimer_cancel) +DUMMY(0, hrtimer_init) +DUMMY(0, hrtimer_start) +DUMMY(0, icmp6_hdr) +DUMMY(0, inet_twsk_deschedule_put) +DUMMY(0, inet_twsk_free) +DUMMY_STOP(0, iov_iter_advance) +DUMMY_STOP(0, iov_iter_get_pages) +DUMMY(0, ip_tunnel_core_init) +DUMMY(0, iptunnel_metadata_reply) +DUMMY(0, ipv6_hdr) +DUMMY(0, ipv6_sk_rxinfo) +DUMMY(0, is_vmalloc_addr) +DUMMY(0, kstrtou8) +DUMMY(0, kvfree) + +/* only relevant when CONFIG_NET_L3_MASTER_DEV set */ +DUMMY_RET(0, l3mdev_fib_oif_rcu) +DUMMY_RET(0, l3mdev_fib_table) /* 0 is valid if !CONFIG_IP_MULTIPLE_TABLES */ +DUMMY_RET(0, l3mdev_fib_table_by_index) +DUMMY_RET(0, l3mdev_get_rtable) +DUMMY_RET(0, l3mdev_get_saddr) +DUMMY_RET(0, l3mdev_master_ifindex) +DUMMY_RET(0, l3mdev_master_ifindex_rcu) + +DUMMY(0, local_clock) + +/* only relevant when CONFIG_LWTUNNEL set */ +DUMMY(0, lwt_tun_info) +DUMMY(0, lwtstate_free) +DUMMY(0, lwtstate_get) +DUMMY_RET(0, lwtstate_put) /* no return value */ +DUMMY_RET(0, lwtunnel_cmp_encap) +DUMMY(0, lwtunnel_fill_encap) +DUMMY(0, lwtunnel_get_encap_size) +DUMMY(0, lwtunnel_input_redirect) +DUMMY(0, lwtunnel_output_redirect) + +DUMMY(0, make_kgid) +DUMMY(0, mod_timer_pending) +DUMMY(0, mod_timer_pinned) +DUMMY(0, netif_index_is_l3_master) +// DUMMY(0, netlink_kernel_release) +// DUMMY(0, netlink_unicast) +DUMMY(0, netpoll_poll_disable) +DUMMY(0, netpoll_poll_enable) +DUMMY(0, nf_hook_ingress_init) +DUMMY(0, nosteal_pipe_buf_ops) +DUMMY(0, ns_to_ktime) +DUMMY(0, page_is_pfmemalloc) +DUMMY(0, page_private) +DUMMY(0, percpu_counter_sum) +DUMMY(0, pr_warn_once) +DUMMY(0, prandom_seed) +DUMMY(0, prandom_u32_max) +DUMMY(0, put_group_info) +DUMMY_SHOW(0, queue_delayed_work) +DUMMY(0, raw_seqcount_begin) +DUMMY(0, read_seqcount_retry) +DUMMY(0, reciprocal_scale) +DUMMY(0, round_down) +DUMMY(0, rt_genid_bump_ipv4) +DUMMY(0, rt_genid_ipv4) +DUMMY(0, rtmsg_ifinfo_build_skb) +DUMMY(0, rtmsg_ifinfo_send) +DUMMY_SKIP(0, sched_annotate_sleep) +DUMMY(0, set_page_private) +DUMMY(0, sk_attach_bpf) +DUMMY(0, sk_busy_loop) +DUMMY(0, sk_can_busy_loop) +DUMMY(0, sk_filter_charge) +DUMMY(0, sk_filter_uncharge) +DUMMY(0, sk_mark_napi_id) +DUMMY(0, skb_vlan_tag_get) +DUMMY(0, skb_vlan_tag_get_id) +DUMMY(0, skb_vlan_tag_present) +DUMMY(0, skb_vlan_tagged) +DUMMY(0, smp_mb__after_atomic) +DUMMY(0, sock_diag_broadcast_destroy) +DUMMY(0, sock_diag_has_destroy_listeners) + +/* only relevant when CONFIG_NET_SWITCHDEV was set */ +DUMMY_RET(0, switchdev_fib_ipv4_abort) /* actually void, no return value */ +DUMMY_RET(0, switchdev_fib_ipv4_add) +DUMMY_RET(0, switchdev_fib_ipv4_del) + +DUMMY(0, sysctl_tcp_recovery) +DUMMY(0, sysfs_create_link) +DUMMY(0, sysfs_remove_link) +DUMMY(0, tcp_fastopen_init_key_once) +DUMMY(0, tcp_rack_advance) +DUMMY(0, tcp_rack_mark_lost) +DUMMY(0, tcp_try_fastopen) +DUMMY(0, tcpv4_offload_init) +DUMMY(0, this_cpu_ksoftirqd) +DUMMY_SKIP(0, trace_fib_table_lookup) +DUMMY_SKIP(0, trace_fib_table_lookup_nh) +DUMMY_SKIP(0, trace_fib_validate_source) +DUMMY_SKIP(0, trace_napi_gro_frags_entry) +DUMMY_SKIP(0, trace_napi_gro_receive_entry) +DUMMY_SKIP(0, trace_net_dev_start_xmit) +DUMMY_SKIP(0, trace_netif_receive_skb_entry) +DUMMY_SKIP(0, trace_netif_rx_entry) +DUMMY_SKIP(0, trace_netif_rx_ni_entry) +DUMMY(0, u64_stats_fetch_begin_irq) +DUMMY(0, u64_stats_fetch_retry_irq) +DUMMY(0, u64_stats_init) +DUMMY(0, udpv4_offload_init) +DUMMY(0, vlan_features_check) +DUMMY(0, vlan_hw_offload_capable) +DUMMY(0, vlan_set_encap_proto) +DUMMY(0, wait_woken) +DUMMY_STOP(0, work_pending) +DUMMY(0, __module_get) +DUMMY_RET(0, peernet2id) +DUMMY(0, ktime_get_ns) +DUMMY(0, ipv6_get_dsfield) + +DUMMY_SKIP(0, spin_lock_init) +DUMMY_SKIP(0, spin_lock_nested) +DUMMY_SKIP(0, spin_lock) +DUMMY_SKIP(0, spin_unlock) +DUMMY_SKIP(0, spin_lock_bh) +DUMMY_SKIP(0, spin_unlock_bh) + +DUMMY(0, peernet_has_id) + +} /* extern "C" */ diff --git a/repos/dde_linux/src/lib/lxip/dummies_c.c b/repos/dde_linux/src/lib/lxip/dummies_c.c index e5073aff1..971708dc8 100644 --- a/repos/dde_linux/src/lib/lxip/dummies_c.c +++ b/repos/dde_linux/src/lib/lxip/dummies_c.c @@ -11,8 +11,10 @@ * under the terms of the GNU General Public License version 2. */ +/* local includes */ #include + int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) { printk("%s called (from %p) not implemented", __func__, __builtin_return_address(0)); diff --git a/repos/dde_linux/src/lib/lxip/env.cc b/repos/dde_linux/src/lib/lxip/env.cc deleted file mode 100644 index 3e89b7c7d..000000000 --- a/repos/dde_linux/src/lib/lxip/env.cc +++ /dev/null @@ -1,20 +0,0 @@ -/* - * \brief Global environment - * \author Stefan Kalkowski - * \date 2013-05-23 - */ - -/* - * Copyright (C) 2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#include "env.h" - -Genode::Signal_receiver* Net::Env::receiver() -{ - static Genode::Signal_receiver receiver; - return &receiver; -} diff --git a/repos/dde_linux/src/lib/lxip/include/env.h b/repos/dde_linux/src/lib/lxip/include/env.h deleted file mode 100644 index 3853d8b1c..000000000 --- a/repos/dde_linux/src/lib/lxip/include/env.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * \brief Proxy-ARP environment - * \author Stefan Kalkowski - * \date 2013-05-24 - * - * A database containing all clients sorted by IP and MAC addresses. - */ - -/* - * Copyright (C) 2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _SRC__SERVER__NIC_BRIDGE__ENV_H_ -#define _SRC__SERVER__NIC_BRIDGE__ENV_H_ - -#include - -namespace Net { - struct Env; -} - -struct Net::Env -{ - static Genode::Signal_receiver* receiver(); -}; - -#endif /* _SRC__SERVER__NIC_BRIDGE__ENV_H_ */ diff --git a/repos/dde_linux/src/lib/lxip/include/init.h b/repos/dde_linux/src/lib/lxip/include/init.h deleted file mode 100644 index b23cc1b3b..000000000 --- a/repos/dde_linux/src/lib/lxip/include/init.h +++ /dev/null @@ -1,22 +0,0 @@ -/** - * \brief IP stack initialization - * \author Sebastian Sumpf - * \date 2013-09-26 - */ - -/* - * Copyright (C) 2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ -#ifndef _INCLUDE__INIT_H_ -#define _INCLUDE__INIT_H_ - -#ifdef __cplusplus -extern "C" -#endif - -int lxip_init(char *address_config); - -#endif diff --git a/repos/dde_linux/src/lib/lxip/include/linux/in.h b/repos/dde_linux/src/lib/lxip/include/linux/in.h new file mode 100644 index 000000000..9fdef9490 --- /dev/null +++ b/repos/dde_linux/src/lib/lxip/include/linux/in.h @@ -0,0 +1,5 @@ +#define __UAPI_DEF_IN_ADDR 1 +#define __UAPI_DEF_SOCKADDR_IN 1 +#include +#undef __UAPI_DEF_SOCKADDR_IN +#undef __UAPI_DEF_IN_ADDR diff --git a/repos/dde_linux/src/lib/lxip/include/linux/in6.h b/repos/dde_linux/src/lib/lxip/include/linux/in6.h new file mode 100644 index 000000000..863720bc2 --- /dev/null +++ b/repos/dde_linux/src/lib/lxip/include/linux/in6.h @@ -0,0 +1,5 @@ +#define __UAPI_DEF_IPPROTO_V6 1 +#define __UAPI_DEF_IN6_ADDR 1 +#include +#undef __UAPI_DEF_IN6_ADDR +#undef __UAPI_DEF_IPPROTO_V6 diff --git a/repos/dde_linux/src/lib/lxip/include/lx_emul.h b/repos/dde_linux/src/lib/lxip/include/lx_emul.h index 35aa2fe8e..d525ac42f 100644 --- a/repos/dde_linux/src/lib/lxip/include/lx_emul.h +++ b/repos/dde_linux/src/lib/lxip/include/lx_emul.h @@ -8,7 +8,7 @@ */ /* - * Copyright (C) 2012-2013 Genode Labs GmbH + * Copyright (C) 2012-2016 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. @@ -17,305 +17,325 @@ #ifndef _LX_EMUL_H_ #define _LX_EMUL_H_ -#include +#include +#include + +#include #define DEBUG_PRINTK 1 #define DEBUG_SLAB 0 #define DEBUG_TIMER 0 -#define DEBUG_CONG 0 #define DEBUG_LEVEL 0 - -#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) -#define LINUX_VERSION_CODE KERNEL_VERSION(3,9,0) - #define KBUILD_MODNAME "mod-noname" -/******************************* - ** linux/errno.h and friends ** - *******************************/ +/***************** + ** asm/param.h ** + *****************/ -/** - * Error codes - * - * Note that the codes do not correspond to those of the Linux kernel. - */ -enum { - /* - * The following numbers correspond to FreeBSD - */ - EPERM = 1, - ENOENT = 2, - ESRCH = 3, - EINTR = 4, - EIO = 5, - ENXIO = 6, - E2BIG = 7, - ENOMEM = 12, - EACCES = 13, - EFAULT = 14, - EBUSY = 16, - EEXIST = 17, - EXDEV = 18, - ENODEV = 19, - EINVAL = 22, - ENFILE = 23, - EFBIG = 27, - ESPIPE = 29, - EPIPE = 32, - EDOM = 33, - ERANGE = 34, - EAGAIN = 35, - EINPROGRESS = 36, - EALREADY = 37, - ENOTSOCK = 38, - EDESTADDRREQ = 39, - EMSGSIZE = 40, - ENOPROTOOPT = 42, - EPROTONOSUPPORT = 43, - ESOCKTNOSUPPORT = 44, - EOPNOTSUPP = 45, - EPFNOSUPPORT = 46, - EAFNOSUPPORT = 47, - EADDRINUSE = 48, - EADDRNOTAVAIL = 49, - ENETDOWN = 50, - ENETUNREACH = 51, - ECONNABORTED = 53, - ECONNRESET = 54, - ENOBUFS = 55, - EISCONN = 56, - ENOTCONN = 57, - ETIMEDOUT = 60, - ECONNREFUSED = 61, - EHOSTDOWN = 64, - EHOSTUNREACH = 65, - ENOSYS = 78, - ENOMSG = 83, - EPROTO = 92, - EOVERFLOW = 84, - - /* - * The following numbers correspond to nothing - */ - EREMOTEIO = 200, - ERESTARTSYS = 201, - ENODATA = 202, - ETOOSMALL = 203, - ENOIOCTLCMD = 204, - ENONET = 205, - - MAX_ERRNO = 4095, -}; - - -/********************** - ** linux/compiler.h ** - **********************/ - -#define likely -#define unlikely - -#define __user -#define __rcu -#define __percpu -#define __must_check -#define __force - -#define __releases(x) -#define __acquires(x) - -#define __aligned(x) __attribute__((aligned(x))) - -#define noinline_for_stack -#define noinline __attribute__((noinline)) - -#define __printf(a, b) __attribute__((format(printf, a, b))) -#define __attribute_const__ __attribute__((__const__)) - -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) - -#define __HAVE_BUILTIN_BSWAP32__ -#define __HAVE_BUILTIN_BSWAP64__ +enum { HZ = 100UL }; /****************** - ** linux/init.h ** + ** asm/atomic.h ** ******************/ -#define __init -#define __initdata -#define __exit - -#define _SETUP_CONCAT(a, b) __##a##b -#define SETUP_CONCAT(a, b) _SETUP_CONCAT(a, b) -#define __setup(str, fn) void SETUP_CONCAT(fn, SETUP_SUFFIX)(void *addrs) { fn(addrs); } - -/* these must be called by us during initialization */ -#define core_initcall(fn) void core_##fn(void) { fn(); } -#define subsys_initcall(fn) void subsys_##fn(void) { fn(); } -#define fs_initcall(fn) void fs_##fn(void) { fn(); } -#define late_initcall(fn) void late_##fn(void) { fn(); } - - -/******************** - ** linux/module.h ** - ********************/ - -#define EXPORT_SYMBOL(x) -#define EXPORT_SYMBOL_GPL(x) -#define MODULE_LICENSE(x) -#define MODULE_NAME_LEN (64 - sizeof(long)) -#define MODULE_ALIAS(name) -#define MODULE_AUTHOR(name) -#define MODULE_DESCRIPTION(desc) -#define MODULE_VERSION(version) -#define THIS_MODULE 0 - - -struct module; -#define module_init(fn) void module_##fn(void) { fn(); } -#define module_exit(fn) void module_exit_##fn(void) { fn(); } - -void module_put(struct module *); -int try_module_get(struct module *); - -/******************* - ** asm/barrier.h ** - *******************/ - -#define mb() asm volatile ("": : :"memory") -#define smp_mb() mb() -#define smp_rmb() mb() -#define smp_wmb() mb() - - -/************************* - ** linux/moduleparam.h ** - *************************/ - -#define module_param(name, type, perm) -#define MODULE_PARM_DESC(_parm, desc) - - -/********************* - ** linux/kconfig.h ** - *********************/ - -#define IS_ENABLED(x) x -#define CONFIG_DEFAULT_TCP_CONG "cubic" +#include /******************* ** linux/types.h ** *******************/ -typedef uint32_t uint; - -typedef int8_t s8; -typedef int16_t s16; -typedef int32_t s32; -typedef int64_t s64; - -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; - - - -typedef uint8_t __u8; -typedef uint16_t __u16; -typedef uint32_t __u32; -typedef uint64_t __u64; +#include typedef __u8 u_int8_t; -typedef int16_t __s16; -typedef int32_t __s32; - typedef __u16 __le16; typedef __u32 __le32; typedef __u64 __le64; -typedef __u16 __be16; -typedef __u32 __be32; typedef __u64 __be64; typedef __u16 __sum16; typedef __u32 __wsum; -typedef unsigned gfp_t; -typedef unsigned long dma_addr_t; -typedef long long loff_t; -typedef size_t __kernel_size_t; -typedef long __kernel_time_t; -typedef long __kernel_suseconds_t; -typedef int pid_t; -typedef long ssize_t; -typedef unsigned short umode_t; -typedef unsigned long clock_t; -typedef int pid_t; -typedef unsigned int uid_t; -typedef unsigned int gid_t; - - #define __aligned_u64 __u64 __attribute__((aligned(8))) -#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) -#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, 8 * sizeof(long)) #define DECLARE_BITMAP(name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] -struct list_head { - struct list_head *next, *prev; + +/********************** + ** linux/compiler.h ** + **********************/ + +#include + + +/************************** + ** asm-generic/bitops.h ** + **************************/ + +#include + +#define ffz(x) ffs(~(x)) + +/******************************* + ** asm-generic/bitops/find.h ** + *******************************/ + +unsigned long find_first_zero_bit(unsigned long const *addr, unsigned long size); + +static inline unsigned long find_next_bit(const unsigned long *addr, unsigned long size, + unsigned long offset) +{ + unsigned long i = offset / BITS_PER_LONG; + offset -= (i * BITS_PER_LONG); + + for (; offset < size; offset++) + if (addr[i] & (1UL << offset)) + return offset; + + return size; +} + +#define find_first_bit(addr, size) find_next_bit((addr), (size), 0) + + +/**************************** + ** bitops/const_hweight.h ** + ****************************/ + +static inline unsigned int hweight32(unsigned int w) +{ + w -= (w >> 1) & 0x55555555; + w = (w & 0x33333333) + ((w >> 2) & 0x33333333); + w = (w + (w >> 4)) & 0x0f0f0f0f; + return (w * 0x01010101) >> 24; + +} + +unsigned int hweight64(__u64 w); + + +/**************************** + ** asm-generic/getorder.h ** + ****************************/ + +int get_order(unsigned long size); + + +/************************ + ** uapi/linux/types.h ** + ************************/ + +struct callback_head { + struct callback_head *next; + void (*func)(struct callback_head *head); }; +#define rcu_head callback_head -struct hlist_head { - struct hlist_node *first; -}; -struct hlist_node { - struct hlist_node *next, **pprev; -}; +/******************************* + ** linux/errno.h and friends ** + *******************************/ -#ifndef __cplusplus -typedef _Bool bool; -enum { true = 1, false = 0 }; -#endif /* __cplusplus */ +#include -#ifndef NULL -#ifdef __cplusplus -#define NULL nullptr + +/******************** + ** linux/module.h ** + ********************/ + +#include + +#ifdef __setup +#undef __setup +#endif + +#define __setup(str, fn) void SETUP_CONCAT(fn, SETUP_SUFFIX)(void *addrs) { fn(addrs); } + + +/****************** + ** linux/init.h ** + ******************/ + +#define __initdata +#define fs_initcall(fn) void fs_##fn(void) { fn(); } +#define late_initcall(fn) void late_##fn(void) { fn(); } + + +/******************* + ** asm/barrier.h ** + *******************/ + +#include + +#define smp_load_acquire(p) *(p) +#define smp_store_release(p, v) *(p) = v; +#define smp_mb__before_atomic() mb() +#define smp_mb__after_atomic() mb() + + +/********************* + ** linux/kconfig.h ** + *********************/ + +#define CONFIG_DEFAULT_TCP_CONG "cubic" + + +/********************** + ** linux/compiler.h ** + **********************/ + +#include + +#define __deprecated + +#define __aligned(x) __attribute__((aligned(x))) + +#define noinline_for_stack + +static inline void __write_once_size(volatile void *p, void *res, int size) +{ + switch (size) { + case 1: *(volatile __u8 *)p = *(__u8 *)res; break; + case 2: *(volatile __u16 *)p = *(__u16 *)res; break; + case 4: *(volatile __u32 *)p = *(__u32 *)res; break; + case 8: *(volatile __u64 *)p = *(__u64 *)res; break; + default: + barrier(); + __builtin_memcpy((void *)p, (const void *)res, size); + barrier(); + } +} + +static inline void __read_once_size(const volatile void *p, void *res, int size) +{ + switch (size) { + case 1: *(__u8 *)res = *(volatile __u8 *)p; break; + case 2: *(__u16 *)res = *(volatile __u16 *)p; break; + case 4: *(__u32 *)res = *(volatile __u32 *)p; break; + case 8: *(__u64 *)res = *(volatile __u64 *)p; break; + default: + barrier(); + __builtin_memcpy((void *)res, (const void *)p, size); + barrier(); + } +} + +#define READ_ONCE(x) \ +({ \ + union { typeof(x) __val; char __c[1]; } __u; \ + __read_once_size(&(x), __u.__c, sizeof(x)); \ + __u.__val; \ +}) + +#define __HAVE_BUILTIN_BSWAP32__ +#define __HAVE_BUILTIN_BSWAP64__ + + +/*************** + ** asm/bug.h ** + ***************/ + +#include + + +/******************** + ** linux/printk.h ** + ********************/ + +#include + +#define pr_crit(fmt, ...) lx_printf(KERN_CRIT fmt, ##__VA_ARGS__) +#define pr_emerg(fmt, ...) lx_printf(KERN_EMERG fmt, ##__VA_ARGS__) +#define pr_err(fmt, ...) lx_printf(KERN_ERR fmt, ##__VA_ARGS__) +#define pr_warn(fmt, ...) lx_printf(KERN_WARN fmt, ##__VA_ARGS__) +#define pr_warn_once(fmt, ...) lx_printf(KERN_WARN fmt, ##__VA_ARGS__) +#define pr_info(fmt, ...) lx_printf(KERN_INFO fmt, ##__VA_ARGS__) +#define pr_notice(fmt, ...) lx_printf(KERN_NOTICE fmt, ##__VA_ARGS__) +#define pr_cont(fmt, ...) lx_printf(KERN_CONT fmt, ##__VA_ARGS__) +#define pr_info_once(fmt, ...) lx_printf(KERN_INFO fmt, ##__VA_ARGS__) +#define pr_err_once(fmt, ...) lx_printf(KERN_ERR fmt, ##__VA_ARGS__) + +#if DEBUG_LEVEL +#define pr_debug(fmt, ...) lx_printf(KERN_DEBUG fmt, ##__VA_ARGS__) #else -#define NULL ((void *)0) -#endif /* __cplusplus */ -#endif /* NULL */ +#define pr_debug(fmt, ...) +#endif -#define __bitwise +static inline __printf(1, 2) int no_printk(const char *fmt, ...) { return 0; } + + +/******************** + ** linux/kernel.h ** + ********************/ + +#include + +#define KERN_CONT "" + +#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) + +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) + +#define SIZE_MAX (~(size_t)0) + +#define U32_MAX ((u32)~0U) +#define S32_MAX ((s32)(U32_MAX>>1)) +#define S32_MIN ((s32)(-S32_MAX - 1)) + +#define PTR_ALIGN(p, a) ({ \ + unsigned long _p = (unsigned long)p; \ + _p = (_p + a - 1) & ~(a - 1); \ + p = (typeof(p))_p; \ + p; \ +}) + +enum { SPRINTF_STR_LEN = 64 }; + +int snprintf(char *buf, size_t size, const char *fmt, ...); +int sprintf(char *buf, const char *fmt, ...); +int sscanf(const char *, const char *, ...); +int kstrtoul(const char *, unsigned int, unsigned long *); +int scnprintf(char *, size_t, const char *, ...); + +#define sprintf(buf, fmt, ...) snprintf(buf, SPRINTF_STR_LEN, fmt, __VA_ARGS__) + +#define kasprintf(gfp, fmt, ...) ({ \ + void *buf = kmalloc(SPRINTF_STR_LEN, 0); \ + sprintf(buf, fmt, __VA_ARGS__); \ + buf; \ +}) + +#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) + +char *get_options(const char *str, int nints, int *ints); +int hex_to_bin(char); + +u32 reciprocal_scale(u32 val, u32 ep_ro); + +#define sched_annotate_sleep() do { } while (0) + +int kstrtou8(const char *s, unsigned int base, u8 *res); /********************* ** linux/jiffies.h ** *********************/ -extern unsigned long jiffies; +#include -enum { INITIAL_JIFFIES = 0 }; +enum { + INITIAL_JIFFIES = 0, +}; -unsigned int jiffies_to_msecs(const unsigned long); -unsigned int jiffies_to_usecs(const unsigned long); -unsigned long msecs_to_jiffies(const unsigned int); +static inline unsigned int jiffies_to_usecs(const unsigned long j) { return j * JIFFIES_TICK_US; } -long time_after(long a, long b); -long time_after_eq(long a, long b); - -static inline long time_before(long a, long b) { return time_after(b, a); } -static inline long time_before_eq(long a, long b) { return time_after_eq(b ,a); } - -clock_t jiffies_to_clock_t(unsigned long); -void update_jiffies(void); +void update_jiffies(void); /****************** @@ -331,6 +351,7 @@ int request_module(const char *name, ...); enum { SIGPIPE }; + /******************** ** linux/bitmap.h ** ********************/ @@ -346,24 +367,6 @@ void bitmap_zero(unsigned long *dst, int nbits); #define __ismask(x) (_ctype[(int)(unsigned char)(x)]) #define isspace(c) ((unsigned char)c == 0x20U) -/***************** - ** linux/err.h ** - *****************/ - -#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) - -static inline bool IS_ERR(void const *ptr) { - return (unsigned long)(ptr) > (unsigned long)(-1000); } - -static inline void * ERR_PTR(long error) { - return (void *) error; -} - -static inline long IS_ERR_OR_NULL(const void *ptr) { - return !ptr || IS_ERR_VALUE((unsigned long)ptr); } - -static inline long PTR_ERR(const void *ptr) { return (long) ptr; } - /******************************* ** asm-generic/scatterlist.h ** @@ -371,6 +374,7 @@ static inline long PTR_ERR(const void *ptr) { return (long) ptr; } struct scatterlist { + unsigned dummy; }; struct page; @@ -380,57 +384,6 @@ void sg_set_buf(struct scatterlist *, const void *, unsigned int); void sg_set_page(struct scatterlist *, struct page *, unsigned int, unsigned int); -/******************** - ** linux/printk.h ** - ********************/ - -#define KERN_WARNING KERN_WARN - -#define pr_crit(fmt, ...) lx_printf(KERN_CRIT fmt, ##__VA_ARGS__) -#define pr_emerg(fmt, ...) lx_printf(KERN_EMERG fmt, ##__VA_ARGS__) -#define pr_err(fmt, ...) lx_printf(KERN_ERR fmt, ##__VA_ARGS__) -#define pr_warn(fmt, ...) lx_printf(KERN_WARN fmt, ##__VA_ARGS__) -#define pr_info(fmt, ...) lx_printf(KERN_INFO fmt, ##__VA_ARGS__) -#define pr_notice(fmt, ...) printk(KERN_NOTICE fmt, ##__VA_ARGS__) -#define pr_cont(fmt, ...) printk(KERN_CONT fmt, ##__VA_ARGS__) - -#define pr_info_once(fmt, ...) printk(KERN_INFO fmt, ##__VA_ARGS__) -#define pr_err_once(fmt, ...) printk(KERN_ERR fmt, ##__VA_ARGS__) - -#if DEBUG_LEVEL -#define pr_debug(fmt, ...) printk(KERN_DEBUG fmt, ##__VA_ARGS__) -#else -#define pr_debug(fmt, ...) -#endif - -struct va_format -{ - const char *fmt; - va_list *va; -}; - -static inline int _printk(const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - lx_vprintf(fmt, args); - va_end(args); - return 0; -} - -#if DEBUG_PRINTK -#define printk _printk -#define vprintk lx_vprintf -#else - -static inline int printk(const char *fmt, ...) -{ - return 0; -} - -#define vprintk(...) -#endif - /****************** ** linux/hash.h ** @@ -456,18 +409,7 @@ void *current_text_addr(void); ** linux/byteorder/little_endian.h ** *************************************/ -#include - - -/******************************* - ** linux/byteorder/generic.h ** - *******************************/ - -#define cpu_to_be16 __cpu_to_be16 -#define cpu_to_be32 __cpu_to_be32 - -#define be16_to_cpup __be16_to_cpup -#define be32_to_cpup __be32_to_cpup +#include #define htons(x) __cpu_to_be16(x) #define ntohs(x) __be16_to_cpu(x) @@ -479,26 +421,17 @@ void *current_text_addr(void); ** linux/unaligned/access_ok.h ** *********************************/ -static inline u16 get_unaligned_be16(const void *p) -{ - return be16_to_cpup((__be16 *)p); -} +static inline u16 get_unaligned_be16(const void *p) { + return be16_to_cpup((__be16 *)p); } -static inline u32 get_unaligned_be32(const void *p) -{ - return be32_to_cpup((__be32 *)p); -} +static inline u32 get_unaligned_be32(const void *p) { + return be32_to_cpup((__be32 *)p); } -u32 __get_unaligned_cpu32(const void *); +static inline u32 __get_unaligned_cpu32(const void *p) { + return *(u32*)p; } -void put_unaligned_be32(u32 val, void *); - - -/***************** - ** asm/param.h ** - *****************/ - -#define HZ 100UL +static inline void put_unaligned_be32(u32 val, void *p) { + *((__le32 *)p) = cpu_to_be32(val); } /********************* @@ -509,98 +442,6 @@ void put_unaligned_be32(u32 val, void *); #define __stringify(x...) __stringify_1(x) -/******************** - ** linux/kernel.h ** - ********************/ - -#define KERN_DEBUG "DEBUG: " -#define KERN_INFO "INFO: " -#define KERN_ERR "ERROR: " -#define KERN_CRIT "CRTITCAL: " -#define KERN_NOTICE "NOTICE: " -#define KERN_EMERG "EMERG: " -#define KERN_ALERT "ALERT: " -#define KERN_CONT "" -#define KERN_WARN "WARNING: " - - -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - -/* normally provided by linux/stddef.h, needed by linux/list.h */ -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) - -#define ALIGN(x, a) x -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) - -#define USHRT_MAX ((u16)(~0U)) -#define INT_MAX ((int)(~0U>>1)) -#define INT_MIN (-INT_MAX - 1) -#define UINT_MAX (~0U) - -static inline size_t min(size_t a, size_t b) { - return a < b ? a : b; } - -#define max(x, y) ({ \ - typeof(x) _max1 = (x); \ - typeof(y) _max2 = (y); \ - (void) (&_max1 == &_max2); \ - _max1 > _max2 ? _max1 : _max2; }) - -#define min_t(type, x, y) ({ \ - type __min1 = (x); \ - type __min2 = (y); \ - __min1 < __min2 ? __min1: __min2; }) - -#define max_t(type, x, y) ({ \ - type __max1 = (x); \ - type __max2 = (y); \ - __max1 > __max2 ? __max1: __max2; }) - -#define swap(a, b) ({ \ - typeof(a) __tmp = (a); \ - (a) = (b); \ - (b) = __tmp; }) - -#define PTR_ALIGN(p, a) ({ \ - unsigned long _p = (unsigned long)p; \ - _p = (_p + a - 1) & ~(a - 1); \ - p = (typeof(p))_p; \ - p; \ -}) - -#define BUILD_BUG_ON(condition) - -#define _RET_IP_ (unsigned long)__builtin_return_address(0) - -void might_sleep(); -#define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) - -enum { SPRINTF_STR_LEN = 64 }; - -int snprintf(char *buf, size_t size, const char *fmt, ...); -int sprintf(char *buf, const char *fmt, ...); -int sscanf(const char *, const char *, ...); -int kstrtoul(const char *, unsigned int, unsigned long *); -int scnprintf(char *, size_t, const char *, ...); - -#define sprintf(buf, fmt, ...) snprintf(buf, SPRINTF_STR_LEN, fmt, __VA_ARGS__) - -#define kasprintf(gfp, fmt, ...) ({ \ - void *buf = kmalloc(SPRINTF_STR_LEN, 0); \ - sprintf(buf, fmt, __VA_ARGS__); \ - buf; \ -}) - -#define clamp(val, min, max) printk("clamp is not implemented\n") - -//char *kasprintf(gfp_t gfp, const char *fmt, ...); - -char *get_options(const char *str, int nints, int *ints); -int hex_to_bin(char); - - /************************** ** uapi/linux/sysinfo.h ** **************************/ @@ -611,93 +452,6 @@ struct sysinfo }; -/******************* - ** asm/cmpxchg.h ** - *******************/ - -#define cmpxchg(ptr, o, n) ({ \ - typeof(*ptr) prev = *ptr; \ - *ptr = (*ptr == o) ? n : *ptr; \ - prev;\ -}) - -unsigned long __xchg(unsigned long, volatile void *, int); - -#define xchg(ptr, x) \ - ((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr)))) - - -/****************** - ** asm/atomic.h ** - ******************/ - -#define ATOMIC_INIT(i) { (i) } - -typedef struct atomic { unsigned long counter; } atomic_t; -typedef atomic_t atomic_long_t; - -static inline unsigned int atomic_read(const atomic_t *p) { return p->counter; } -static inline void atomic_set(atomic_t *p, int i) { p->counter = i; } -static inline void atomic_sub(int i, atomic_t *p) { p->counter -= i; } -static inline int atomic_sub_return(int i, atomic_t *p) { p->counter -= i; return p->counter; } -static inline int atomic_sub_and_test(int i, atomic_t *p) { return atomic_sub_return(i, p) == 0; } - -static inline int atomic_dec_return(atomic_t *p) { return atomic_sub_return(1, p); } -static inline int atomic_dec_and_test(atomic_t *p) { return atomic_sub_return(1, p) == 0; } -static inline void atomic_dec(atomic_t *p) { atomic_sub_return(1, p); } - - -static inline void atomic_inc(atomic_t *p) { p->counter++; } -static inline int atomic_inc_return(atomic_t *p) { return p->counter++; } -static inline int atomic_inc_not_zero(atomic_t *p) { return p->counter ? p->counter++ : 0; } - -static inline void atomic_add(int i, atomic_t *p) { p->counter += i; } - - -static inline void atomic_long_inc(atomic_long_t *p) { p->counter++; } -static inline void atomic_long_sub(int i, atomic_long_t *p) { atomic_sub(i, p); } -static inline long atomic_long_add_return(long i, atomic_long_t *p) { - atomic_add(i, p); return p->counter; } -static inline long atomic_long_read(atomic_long_t *p) { return (long)atomic_read(p); } - -static inline int atomic_cmpxchg(atomic_t *v, int old, int n) -{ - return cmpxchg(&v->counter, old, n); -} - - -static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint) -{ - int val, c = hint; - - /* sanity test, should be removed by compiler if hint is a constant */ - if (!hint) - return atomic_inc_not_zero(v); - - do { - val = atomic_cmpxchg(v, c, c + 1); - if (val == c) - return 1; - c = val; - } while (c); - - return 0; -} - -static inline int atomic_add_unless(atomic_t *v, int a, int u) -{ - int ret; - unsigned long flags; - - ret = v->counter; - if (ret != u) - v->counter += a; - - return ret != u; -} - -#define smp_mb__before_atomic_dec() - /**************************** ** tools/perf/util/util.h ** ****************************/ @@ -705,23 +459,10 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) void dump_stack(void); -/****************** - ** linux/kref.h ** - ******************/ - -struct kref { atomic_t refcount; }; - -void kref_init(struct kref *); -int kref_put(struct kref *, void (*)(struct kref *)); - - /******************** ** linux/uidgid.h ** ********************/ -typedef unsigned kuid_t; -typedef unsigned kgid_t; - struct user_namespace; #define GLOBAL_ROOT_UID (kuid_t)0 @@ -731,6 +472,7 @@ gid_t from_kgid_munged(struct user_namespace *, kgid_t); uid_t from_kuid(struct user_namespace *, kuid_t); gid_t from_kgid(struct user_namespace *, kgid_t); bool uid_eq(kuid_t, kuid_t); +kgid_t make_kgid(struct user_namespace *from, gid_t gid); /***************** @@ -742,6 +484,7 @@ struct pid; pid_t pid_vnr(struct pid *); void put_pid(struct pid *); + /*********************** ** linux/kmemcheck.h ** ***********************/ @@ -804,7 +547,7 @@ enum { NUMA_NO_NODE = -1 }; ** linux/jump_label.h ** ************************/ -struct static_key { }; +struct static_key { unsigned dummy; }; #define STATIC_KEY_INIT_FALSE ((struct static_key) {}) @@ -818,90 +561,7 @@ bool static_key_enabled(struct static_key *); ** linux/poison.h ** ********************/ -/* - * In list.h, LIST_POISON1 and LIST_POISON2 are assigned to 'struct list_head - * *' as well as 'struct hlist_node *' pointers. Consequently, C++ compiler - * produces an error "cannot convert... in assignment". To compile 'list.h' - * included by C++ source code, we have to define these macros to the only - * value universally accepted for pointer assigments.h - */ - -#ifdef __cplusplus -#define LIST_POISON1 0 -#define LIST_POISON2 0 -#else -#define LIST_POISON1 ((void *)0x00100100) -#define LIST_POISON2 ((void *)0x00200200) -#endif /* __cplusplus */ - -/********************************** - ** linux/bitops.h, asm/bitops.h ** - **********************************/ - -enum { BITS_PER_LONG = sizeof(long) * 8 }; -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) - -#include - -#define test_and_clear_bit(nr, addr) \ - __test_and_clear_bit(nr, (volatile unsigned long *)(addr)) -#define test_and_set_bit(nr, addr) \ - __test_and_set_bit(nr, (volatile unsigned long *)(addr)) -#define set_bit(nr, addr) \ - __set_bit(nr, (volatile unsigned long *)(addr)) -#define clear_bit(nr, addr) \ - __clear_bit(nr, (volatile unsigned long *)(addr)) - -#define smp_mb__before_clear_bit() - -unsigned long __fls(unsigned long); -int fls64(__u64 x); - -static int get_bitmask_order(unsigned int count) { - return __builtin_clz(count) ^ 0x1f; } - -#define ffs(x) __builtin_ffs(x) -#define ffz(x) ffs(~(x)) - -static inline __u32 rol32(__u32 word, unsigned int shift) -{ - return (word << shift) | (word >> (32 - shift)); -} - - -/******************************* - ** asm-generic/bitops/find.h ** - *******************************/ - -#define smp_mb__after_clear_bit() smp_mb() - -unsigned long find_first_zero_bit(unsigned long const *addr, unsigned long size); - - -/**************************** - ** bitops/const_hweight.h ** - ****************************/ - -#define hweight32(w) printk("hweight32 not implemented\n") -#define hweight64(w) printk("hweight64 not implemented\n") - - -/**************************** - ** asm-generic/getorder.h ** - ****************************/ - -int get_order(unsigned long size); - - -/****************** - ** linux/log2.h ** - ******************/ - -unsigned long ilog2(unsigned long n); - -#define roundup_pow_of_two(n) ( \ - 1UL << (ilog2((n) - 1) + 1)) +#include /**************** @@ -912,6 +572,7 @@ unsigned long ilog2(unsigned long n); * For now, hardcoded */ #define PAGE_SIZE 4096 +#define PAGE_MASK (~(PAGE_SIZE-1)) enum { PAGE_SHIFT = 12, @@ -939,9 +600,82 @@ u64 res_counter_uncharge(struct res_counter *, unsigned long); u64 res_counter_read_u64(struct res_counter *counter, int member); +/**************************** + ** linux/percpu_counter.h ** + ****************************/ + +struct percpu_counter +{ + s64 count; +}; + +static inline int percpu_counter_init(struct percpu_counter *fbc, s64 amount, gfp_t gfp) +{ + fbc->count = amount; + return 0; +} + +static inline s64 percpu_counter_read(struct percpu_counter *fbc) +{ + return fbc->count; +} + +static inline +void percpu_counter_add(struct percpu_counter *fbc, s64 amount) +{ + fbc->count += amount; +} + +static inline +void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch) +{ + percpu_counter_add(fbc, amount); +} + +s64 percpu_counter_sum_positive(struct percpu_counter *fbc); + +static inline void percpu_counter_inc(struct percpu_counter *fbc) +{ + percpu_counter_add(fbc, 1); +} + +static inline void percpu_counter_dec(struct percpu_counter *fbc) +{ + percpu_counter_add(fbc, -1); +} + +static inline +s64 percpu_counter_read_positive(struct percpu_counter *fbc) +{ + return fbc->count; +} + +void percpu_counter_destroy(struct percpu_counter *fbc); + +s64 percpu_counter_sum(struct percpu_counter *fbc); + + +/************************** + ** linux/page_counter.h ** + **************************/ + +struct page_counter +{ + atomic_long_t count; + unsigned long limit; +}; + +static inline unsigned long page_counter_read(struct page_counter *counter) { + return atomic_long_read(&counter->count); } + +void page_counter_charge(struct page_counter *counter, unsigned long nr_pages); +void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages); + + /************************ ** linux/memcontrol.h ** ************************/ + struct sock; enum { UNDER_LIMIT, SOFT_LIMIT, OVER_LIMIT }; @@ -949,6 +683,14 @@ enum { UNDER_LIMIT, SOFT_LIMIT, OVER_LIMIT }; void sock_update_memcg(struct sock *); void sock_release_memcg(struct sock *); +struct cg_proto +{ + struct page_counter memory_allocated; + struct percpu_counter sockets_allocated; + int memory_pressure; + long sysctl_mem[3]; +}; + /********************* ** mm/memcontrol.c ** @@ -961,18 +703,25 @@ struct mem_cgroup; ** linux/mm-types.h ** **********************/ -struct page_frag +struct page_frag { struct page *page; __u16 offset; __u16 size; }; +struct page_frag_cache +{ + bool pfmemalloc; +}; + /**************** ** linux/mm.h ** ****************/ +int is_vmalloc_addr(const void *x); + extern unsigned long totalram_pages; extern unsigned long num_physpages; @@ -987,11 +736,17 @@ struct page *virt_to_page(const void *x); void si_meminfo(struct sysinfo *); +bool page_is_pfmemalloc(struct page *page); + +#define page_private(page) ((page)->private) +#define set_page_private(page, v) ((page)->private = (v)) + /******************** ** linux/mmzone.h ** ********************/ +enum { PAGE_ALLOC_COSTLY_ORDER = 3u }; int PageHighMem(struct page *); @@ -1003,29 +758,11 @@ int PageHighMem(struct page *); unsigned long nr_free_buffer_pages(void); - /***************** ** linux/gfp.h ** *****************/ -enum { - __GFP_DMA = 0x01u, - __GFP_WAIT = 0x10u, - __GFP_COLD = 0x100u, - __GFP_NOWARN = 0x200u, - __GFP_REPEAT = 0x400u, - __GFP_MEMALLOC = 0x2000u, - __GFP_ZERO = 0x8000u, - __GFP_COMP = 0x4000u, - __GFP_NOMEMALLOC = 0x10000u, -}; - -enum { - GFP_DMA = __GFP_DMA, - GFP_KERNEL = 0x0u, - GFP_USER = 0x1u, - GFP_ATOMIC = 0x20u, -}; +#include struct page *alloc_pages_node(int nid, gfp_t gfp_mask, unsigned int order); @@ -1040,6 +777,11 @@ unsigned long get_zeroed_page(gfp_t gfp_mask); bool gfp_pfmemalloc_allowed(gfp_t); unsigned long __get_free_pages(gfp_t, unsigned int); void free_pages(unsigned long, unsigned int); +void __free_page_frag(void *addr); +bool gfpflags_allow_blocking(const gfp_t gfp_flags); + +void *__alloc_page_frag(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask); + /****************** ** linux/slab.h ** @@ -1054,13 +796,16 @@ enum { }; void *kmalloc(size_t size, gfp_t flags); +void *kmalloc_array(size_t n, size_t size, gfp_t flags); void *kzalloc(size_t size, gfp_t flags); void *kcalloc(size_t n, size_t size, gfp_t flags); void *krealloc(const void *, size_t, gfp_t); void *kzalloc_node(size_t size, gfp_t flags, int node); void *kmalloc_node_track_caller(size_t size, gfp_t flags, int node); void kfree(const void *); -size_t ksize(const void *objp); +void kvfree(const void *); +void kzfree(const void *); +size_t ksize(void *objp); /* XXX is void const* */ struct kmem_cache; @@ -1071,12 +816,14 @@ void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node); void kmem_cache_free(struct kmem_cache *cache, void *objp); void kmem_cache_destroy(struct kmem_cache *); +void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags); /********************* ** linux/vmalloc.h ** *********************/ +void *vmalloc(unsigned long size); void *vzalloc(unsigned long size); void vfree(const void *addr); @@ -1118,40 +865,14 @@ void debug_check_no_locks_freed(const void *from, unsigned long len); ** linux/spinlock.h ** **********************/ -typedef unsigned spinlock_t; -#define DEFINE_SPINLOCK(name) spinlock_t name = 0; -#define spin_lock_nested(lock, subclass) -static inline void spin_lock_init(spinlock_t *lock) { } - -static inline void spin_lock(spinlock_t *lock) { } -static inline void spin_unlock(spinlock_t *lock) { } - -static inline void spin_lock_bh(spinlock_t *lock) { } -static inline void spin_unlock_bh(spinlock_t *lock) { } - -void spin_lock_irqsave(spinlock_t *, unsigned long); -void spin_unlock_irqrestore(spinlock_t *, unsigned long); - -int spin_trylock(spinlock_t *lock); - -/**************************** - ** linux/spinlock_types.h ** - ****************************/ - -#define __SPIN_LOCK_UNLOCKED(x) 0 +#include /******************* ** linux/mutex.h ** *******************/ -struct mutex { }; - -#define DEFINE_MUTEX(n) struct mutex n; - -void mutex_lock(struct mutex *); -void mutex_unlock(struct mutex *); -void mutex_init(struct mutex *); +#include /*********************************** @@ -1182,9 +903,7 @@ void read_unlock_bh(rwlock_t *); ** linux/rwsem.h ** *******************/ -struct rw_semaphore { int dummy; }; - -#define __RWSEM_INITIALIZER(name) { 0 } +#include /********************* @@ -1197,6 +916,7 @@ void seqlock_init (seqlock_t *); #define __SEQLOCK_UNLOCKED(x) 0 + /****************** ** linux/time.h ** ******************/ @@ -1213,9 +933,12 @@ struct timespec { }; enum { + CLOCK_MONOTONIC = 1, + MSEC_PER_SEC = 1000L, USEC_PER_SEC = MSEC_PER_SEC * 1000L, NSEC_PER_MSEC = 1000L * 1000L, + NSEC_PER_USEC = NSEC_PER_MSEC * 1000L, NSEC_PER_SEC = MSEC_PER_SEC * NSEC_PER_MSEC, USEC, USEC_PER_MSEC = 1000L, @@ -1229,8 +952,8 @@ void getnstimeofday(struct timespec *); ** linux/ktime.h ** *******************/ -union ktime { - s64 tv64; +union ktime { + s64 tv64; }; typedef union ktime ktime_t; @@ -1260,6 +983,15 @@ static inline ktime_t ktime_get_real(void) return (ktime_t) { .tv64 = (s64)(jiffies * (1000 / HZ) * NSEC_PER_MSEC) }; } +ktime_t ns_to_ktime(u64 ns); + + +/************************* + ** linux/timekeeping.h ** + *************************/ + +u64 ktime_get_ns(void); + /******************* ** linux/timer.h ** @@ -1283,6 +1015,8 @@ struct timer_list void init_timer(struct timer_list *timer); void add_timer(struct timer_list *timer); int mod_timer(struct timer_list *timer, unsigned long expires); +int mod_timer_pending(struct timer_list *timer, unsigned long expires); +int mod_timer_pinned(struct timer_list *timer, unsigned long expires); void setup_timer(struct timer_list *timer,void (*function)(unsigned long), unsigned long data); int timer_pending(const struct timer_list * timer); @@ -1293,7 +1027,6 @@ long round_jiffies_relative(unsigned long); unsigned long round_jiffies(unsigned long); unsigned long round_jiffies_up(unsigned long); - #define del_timer_sync del_timer @@ -1301,7 +1034,25 @@ unsigned long round_jiffies_up(unsigned long); ** linux/hrtimer.h ** *********************/ -struct hrtimer { }; +enum hrtimer_restart +{ + HRTIMER_NORESTART, +}; + +enum hrtimer_mode { + HRTIMER_MODE_REL_PINNED = 0x03, +}; + +struct hrtimer +{ + enum hrtimer_restart (*function)(struct hrtimer *); +}; + +typedef int clockid_t; + +void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, enum hrtimer_mode mode); +void hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode); +int hrtimer_cancel(struct hrtimer *timer); /******************* @@ -1331,6 +1082,7 @@ struct ratelimit_state extern int ___ratelimit(struct ratelimit_state *, const char *); #define __ratelimit(state) ___ratelimit(state, __func__) + /******************* ** linux/sched.h ** *******************/ @@ -1378,6 +1130,8 @@ void __set_current_state(int); void set_current_state(int); pid_t task_tgid_vnr(struct task_struct *); +u64 local_clock(void); + /************************ ** linux/textsearch.h ** @@ -1429,7 +1183,7 @@ enum { #define lockdep_set_class(lock, key) #define lockdep_set_class_and_name(lock, key, name) #define mutex_acquire(l, s, t, i) -#define mutex_release(l, n, i) +#define mutex_release(l, n, i) struct lock_class_key { }; struct lockdep_map { }; @@ -1442,6 +1196,7 @@ void lockdep_init_map(struct lockdep_map *, const char *, ** linux/smp.h ** *****************/ +#define raw_smp_processor_id() 0 #define smp_processor_id() 0 #define put_cpu() @@ -1449,12 +1204,11 @@ typedef void (*smp_call_func_t)(void *info); int on_each_cpu(smp_call_func_t, void *, int); + /********************** ** linux/rcupdate.h ** **********************/ -struct rcu_head { }; - #define kfree_rcu(ptr, offset) kfree(ptr) #define rcu_dereference(p) p @@ -1485,10 +1239,13 @@ static inline void call_rcu(struct rcu_head *head, #define RCU_INIT_POINTER(p, v) p = (typeof(*v) *)v + /********************* ** linux/rculist.h ** *********************/ +#define hlist_first_rcu(head) (*((struct hlist_node **)(&(head)->first))) + #define hlist_for_each_entry_rcu(pos, head, member) \ hlist_for_each_entry(pos, head, member) @@ -1507,6 +1264,8 @@ static inline void call_rcu(struct rcu_head *head, #define list_add_tail_rcu list_add_tail #define hlist_add_head_rcu hlist_add_head +#define list_entry_rcu(ptr, type, member) container_of(ptr, type, member) + #define list_del_rcu list_del #define hlist_del_rcu hlist_del @@ -1518,6 +1277,8 @@ void hlist_add_after_rcu(struct hlist_node *, struct hlist_node *); void hlist_add_before_rcu(struct hlist_node *,struct hlist_node *); void list_replace_rcu(struct list_head *, struct list_head *); +void hlist_replace_rcu(struct hlist_node *old, struct hlist_node *new); +void hlist_add_behind_rcu(struct hlist_node *n, struct hlist_node *prev); /*************************** @@ -1532,8 +1293,21 @@ void list_replace_rcu(struct list_head *, struct list_head *); ** linux/rcutree.h ** *********************/ - void rcu_barrier(void); - void synchronize_rcu_expedited(void); +void rcu_barrier(void); +void synchronize_rcu_expedited(void); + + +/*********************** + ** linux/hashtable.h ** + ***********************/ + +#define HASH_SIZE(name) (ARRAY_SIZE(name)) + +#define HLIST_HEAD_INIT { .first = NULL } + +#define DEFINE_HASHTABLE(name, bits) \ + struct hlist_head name[1 << (bits)] = \ + { [0 ... ((1 << (bits)) - 1)] = HLIST_HEAD_INIT } /************************* @@ -1543,6 +1317,9 @@ void list_replace_rcu(struct list_head *, struct list_head *); #define DECLARE_PER_CPU_ALIGNED(type, name) \ extern typeof(type) name +#define DECLARE_PER_CPU(type, name) \ + extern typeof(type) name + #define DEFINE_PER_CPU_ALIGNED(type, name) \ typeof(type) name @@ -1551,14 +1328,20 @@ void list_replace_rcu(struct list_head *, struct list_head *); #define EXPORT_PER_CPU_SYMBOL(x) + /******************** ** linux/percpu.h ** ********************/ void *__alloc_percpu(size_t size, size_t align); -#define alloc_percpu(type) \ - (typeof(type) __percpu *)__alloc_percpu(sizeof(type), __alignof__(type)) +#define __alloc_percpu_gfp(size, align, gfp) __alloc_percpu(size, align) + +#define alloc_percpu_gfp(type, gfp) \ + (typeof(type) __percpu *)__alloc_percpu_gfp(sizeof(type), __alignof__(type), gfp) + +#define alloc_percpu(type) \ + (typeof(type) __percpu *)__alloc_percpu(sizeof(type), __alignof__(type)) #define per_cpu(var, cpu) var #define per_cpu_ptr(ptr, cpu) ({ (void)(cpu);(typeof(*(ptr)) *)(ptr); }) @@ -1567,7 +1350,9 @@ void *__alloc_percpu(size_t size, size_t align); #define __get_cpu_var(var) var #define __this_cpu_ptr(ptr) per_cpu_ptr(ptr, 0) #define this_cpu_ptr(ptr) per_cpu_ptr(ptr, 0) +#define __this_cpu_write(pcp, val) pcp = val #define __this_cpu_read(pcp) pcp +#define this_cpu_read(pcp) __this_cpu_read(pcp) #define this_cpu_inc(pcp) pcp += 1 #define this_cpu_dec(pcp) pcp -= 1 @@ -1579,6 +1364,9 @@ void *__alloc_percpu(size_t size, size_t align); #define __this_cpu_add(pcp, val) this_cpu_add(pcp, val) #define get_cpu() 0 +#define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0) +#define raw_cpu_inc(pcp) pcp += 1 + /********************* ** linux/cpumask.h ** @@ -1589,58 +1377,6 @@ void *__alloc_percpu(size_t size, size_t align); unsigned num_possible_cpus(void); -/**************************** - ** linux/percpu_counter.h ** - ****************************/ - -struct percpu_counter -{ - s64 count; -}; - -static inline int percpu_counter_init(struct percpu_counter *fbc, s64 amount) -{ - fbc->count = amount; - return 0; -} - -static inline s64 percpu_counter_read(struct percpu_counter *fbc) -{ - return fbc->count; -} - -static inline -void percpu_counter_add(struct percpu_counter *fbc, s64 amount) -{ - fbc->count += amount; -} - -static inline -void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch) -{ - percpu_counter_add(fbc, amount); -} - -s64 percpu_counter_sum_positive(struct percpu_counter *fbc); - -static inline void percpu_counter_inc(struct percpu_counter *fbc) -{ - percpu_counter_add(fbc, 1); -} - -static inline void percpu_counter_dec(struct percpu_counter *fbc) -{ - percpu_counter_add(fbc, -1); -} - -static inline -s64 percpu_counter_read_positive(struct percpu_counter *fbc) -{ - return fbc->count; -} - -void percpu_counter_destroy(struct percpu_counter *fbc); - /***************** ** linux/cpu.h ** *****************/ @@ -1716,6 +1452,8 @@ void tasklet_init(struct tasklet_struct *, void (*)(unsigned long), unsigned long); void tasklet_schedule(struct tasklet_struct *); +struct task_struct *this_cpu_ksoftirqd(void); + /*********************** ** /linux/irqflags.h ** @@ -1726,6 +1464,7 @@ void local_irq_restore(unsigned long); void local_irq_enable(void); void local_irq_disable(void); + /********************* ** linux/hardirq.h ** *********************/ @@ -1753,26 +1492,9 @@ void local_bh_enable(void); ** linux/string.h ** ********************/ -int memcmp(const void *, const void *, size_t); -void *memmove(void *, const void *, size_t); -void *memset(void *s, int c, size_t n); -void *kmemdup(const void *src, size_t len, gfp_t gfp); -char *kstrdup(const char *s, gfp_t gfp); -char *strchr(const char *, int); -size_t strnlen(const char *s, size_t maxlen); -size_t strlen(const char *); -char *strnchr(const char *, size_t, int); -char *strcat(char *dest, const char *src); -int strcmp(const char *, const char *); -int strncmp(const char *, const char *, size_t); -char *strcpy(char *to, const char *from); -char * strncpy(char *,const char *, __kernel_size_t); -size_t strlcpy(char *dest, const char *src, size_t size); -char * strsep(char **,const char *); +#include -void *genode_memcpy(void *d, const void *s, size_t n); -static inline void *memcpy(void *d, const void *s, size_t n) { - return genode_memcpy(d, s, n); } +char *strnchr(const char *, size_t, int); /*************************** @@ -1822,6 +1544,7 @@ void set_fs(mm_segment_t); enum { CAP_NET_BIND_SERVICE = 10, + CAP_NET_BROADCAST = 11, CAP_NET_ADMIN = 12, CAP_NET_RAW = 13, }; @@ -1833,6 +1556,8 @@ enum { bool capable(int cap); bool ns_capable(struct user_namespace *, int); +struct file; +bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap); /******************** @@ -1872,12 +1597,14 @@ enum POLL_HUP = 6, }; + /******************** ** linux/pm_qos.h ** ********************/ struct pm_qos_request { }; + /********************************* ** (uapi|linux|kernel)/audit.h ** *********************************/ @@ -1921,6 +1648,7 @@ void put_device(struct device *); int dev_printk_emit(int, const struct device *, const char *, ...); + /************************* ** linux/dma-direction ** *************************/ @@ -1950,11 +1678,16 @@ void net_dmaengine_put(void); *****************/ struct ethtool_ts_info; +struct ethtool_modinfo; +struct ethtool_eeprom; + struct phy_device; struct phy_driver { int (*ts_info)(struct phy_device *phydev, struct ethtool_ts_info *ti); + int (*module_info)(struct phy_device *dev, struct ethtool_modinfo *modinfo); + int (*module_eeprom)(struct phy_device *dev, struct ethtool_eeprom *ee, u8 *data); }; struct phy_device @@ -1962,6 +1695,7 @@ struct phy_device struct phy_driver *drv; }; + /***************************** ** uapi/asm-generic/poll.h ** *****************************/ @@ -1980,45 +1714,23 @@ enum { }; +/*********************** + ** linux/workqueue.h ** + ***********************/ + +#include + +void INIT_DEFERRABLE_WORK(struct delayed_work *, void (*func)(struct work_struct *)); + +#define system_power_efficient_wq 0 +#define work_pending(work) 0 + + /****************** ** linux/wait.h ** ******************/ -typedef struct wait_queue_head { int dummy; } wait_queue_head_t; -typedef struct wait_queue { } wait_queue_t; - -#define DEFINE_WAIT(name) \ - wait_queue_t name; - -#define __WAIT_QUEUE_HEAD_INITIALIZER(name) { 0 } - -#define DECLARE_WAITQUEUE(name, tsk) \ - wait_queue_t name - -#define DECLARE_WAIT_QUEUE_HEAD(name) \ - wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name) - -#define DEFINE_WAIT_FUNC(name, function) \ - wait_queue_t name - -#define wake_up(x) -#define wake_up_interruptible_all(x) - -void init_waitqueue_head(wait_queue_head_t *); -int waitqueue_active(wait_queue_head_t *); - -void wake_up_interruptible(wait_queue_head_t *); -void wake_up_interruptible_sync_poll(wait_queue_head_t *, int); -void wake_up_interruptible_poll(wait_queue_head_t *, int); - -void prepare_to_wait(wait_queue_head_t *, wait_queue_t *, int); -void prepare_to_wait_exclusive(wait_queue_head_t *, wait_queue_t *, int); -void finish_wait(wait_queue_head_t *, wait_queue_t *); - -int autoremove_wake_function(wait_queue_t *, unsigned, int, void *); -void add_wait_queue(wait_queue_head_t *, wait_queue_t *); -void add_wait_queue_exclusive(wait_queue_head_t *, wait_queue_t *); -void remove_wait_queue(wait_queue_head_t *, wait_queue_t *); +long wait_woken(wait_queue_t *wait, unsigned mode, long timeout); /****************** @@ -2031,12 +1743,14 @@ struct file; void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p); bool poll_does_not_wait(const poll_table *); + /**************************** ** linux/user_namespace.h ** ****************************/ struct user_namespace { }; + /****************** ** linux/cred.h ** ******************/ @@ -2064,6 +1778,7 @@ extern struct user_namespace init_user_ns; struct group_info *get_current_groups(); void put_cred(const struct cred *); +void put_group_info(struct group_info*); static inline void current_uid_gid(kuid_t *u, kgid_t *g) { @@ -2149,6 +1864,8 @@ void *generic_pipe_buf_map(struct pipe_inode_info *, struct pipe_buffer *, int); void generic_pipe_buf_unmap(struct pipe_inode_info *, struct pipe_buffer *, void *); int generic_pipe_buf_confirm(struct pipe_inode_info *, struct pipe_buffer *); +extern const struct pipe_buf_operations nosteal_pipe_buf_ops; + /******************** ** linux/splice.h ** @@ -2205,6 +1922,36 @@ struct kvec int memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len); +struct iov_iter { + int type; + size_t iov_offset; + size_t count; + union { + const struct iovec *iov; + const struct kvec *kvec; + const struct bio_vec *bvec; + }; + unsigned long nr_segs; +}; + +static inline size_t iov_iter_count(struct iov_iter *i) { return i->count; } + +size_t copy_to_iter(void *addr, size_t bytes, struct iov_iter *i); +size_t copy_from_iter(void *addr, size_t bytes, struct iov_iter *i); +size_t copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i); + +size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, struct iov_iter *i); +size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, struct iov_iter *i); + +void iov_iter_advance(struct iov_iter *i, size_t bytes); +ssize_t iov_iter_get_pages(struct iov_iter *i, struct page **pages, + size_t maxsize, unsigned maxpages, size_t *start); + +size_t csum_and_copy_to_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); +size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); + +bool iter_is_iovec(struct iov_iter *i); + /******************************* ** uapi/asm-generic/ioctls.h ** @@ -2244,6 +1991,7 @@ struct new_utsname *utsname(void); struct sock_fprog { }; + /******************** ** linux/filter.h ** ********************/ @@ -2258,9 +2006,15 @@ struct sk_filter unsigned int sk_filter_len(const struct sk_filter *); int sk_filter(struct sock *, struct sk_buff *); +bool sk_filter_charge(struct sock *sk, struct sk_filter *fp); +void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp); int sk_attach_filter(struct sock_fprog *, struct sock *); int sk_detach_filter(struct sock *); int sk_get_filter(struct sock *, struct sock_filter *, unsigned); +int sk_attach_bpf(u32 ufd, struct sock *sk); + +int bpf_tell_extensions(void); + /***************************** ** uapi/linux/hdlc/ioctl.h ** @@ -2275,50 +2029,8 @@ typedef struct { } te1_settings; typedef struct { } sync_serial_settings; -/*********************** - ** linux/workquque.h ** - ***********************/ - -struct workqueue_struct { }; - -struct work_struct; -typedef void (*work_func_t)(struct work_struct *work); - -struct work_struct { - work_func_t func; - struct list_head entry; -}; - -struct delayed_work -{ - struct work_struct work; -}; - -#define DECLARE_DELAYED_WORK(n, f) \ - struct delayed_work n - -#define __WORK_INITIALIZER(n, f) { \ - .entry = { &(n).entry, &(n).entry }, \ - .func = (f) \ -} - -#define INIT_WORK(_work, _func) printk("INIT_WORK not implemented\n"); - -extern struct workqueue_struct *system_wq; - -bool schedule_work(struct work_struct *work); -bool schedule_delayed_work(struct delayed_work *, unsigned long); -bool cancel_delayed_work(struct delayed_work *); -bool cancel_delayed_work_sync(struct delayed_work *); -bool mod_delayed_work(struct workqueue_struct *, struct delayed_work *, - unsigned long); - - -void INIT_DEFERRABLE_WORK(struct delayed_work *, void (*func)(struct work_struct *)); - - /********************** - ** linux/inerrupt.h ** + ** linux/interrupt.h ** **********************/ struct tasklet_struct @@ -2331,6 +2043,7 @@ struct tasklet_struct struct hash_desc { }; + /************************ ** linux/cryptohash.h ** ************************/ @@ -2380,6 +2093,79 @@ void __rtnl_unlock(void); int rtnl_is_locked(void); int rtnl_put_cacheinfo(struct sk_buff *, struct dst_entry *, u32, long, u32); +bool lockdep_rtnl_is_held(void); + +struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev, unsigned change, gfp_t flags); +void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, gfp_t flags); + + +/*********************** + ** linux/genetlink.h ** + ***********************/ + +extern atomic_t genl_sk_destructing_cnt; +extern wait_queue_head_t genl_sk_destructing_waitq; + + +/********************* + ** net/flow_keys.h ** + *********************/ + +enum flow_dissector_key_id +{ + FLOW_DISSECTOR_KEY_IPV4_ADDRS, +}; + +struct flow_dissector_key_control +{ + u16 thoff; + u16 addr_type; + u32 flags; +}; + +struct flow_dissector_key_ipv4_addrs { + /* (src,dst) must be grouped, in the same way than in IP header */ + __be32 src; + __be32 dst; +}; + +struct flow_dissector_key_addrs { + union { + struct flow_dissector_key_ipv4_addrs v4addrs; + }; +}; + +struct flow_keys +{ + /* (src,dst) must be grouped, in the same way than in IP header */ + __be32 src; + __be32 dst; + union { + __be32 ports; + __be16 port16[2]; + }; + u16 thoff; + u8 ip_proto; + + struct flow_dissector_key_control control; + struct flow_dissector_key_addrs addrs; +}; + +struct flow_dissector_key +{ + unsigned dummy; +}; + +struct flow_dissector +{ + unsigned dummy; +}; + +extern struct flow_dissector flow_keys_dissector; +extern struct flow_dissector flow_keys_buf_dissector; + +bool flow_keys_have_l4(struct flow_keys *keys); + /******************** ** net/netevent.h ** @@ -2417,21 +2203,41 @@ void scm_destroy(struct scm_cookie *); ** net/fib_rules.h ** *********************/ -enum { FIB_LOOKUP_NOREF = 1 }; +enum +{ + FIB_LOOKUP_NOREF = 1, + FIB_LOOKUP_IGNORE_LINKSTATE = 2, +}; /**************************** ** linux/u64_stats_sync.h ** ****************************/ -struct u64_stats_sync { }; +struct u64_stats_sync { unsigned dummy; }; + +void u64_stats_init(struct u64_stats_sync *syncp); +void u64_stats_update_begin(struct u64_stats_sync *syncp); +void u64_stats_update_end(struct u64_stats_sync *syncp); + +unsigned int u64_stats_fetch_begin_irq(const struct u64_stats_sync *p); +bool u64_stats_fetch_retry_irq(const struct u64_stats_sync *p, unsigned int s); + + +/********************** + ** net/netns/core.h ** + **********************/ + +struct netns_core +{ + int sysctl_somaxconn; +}; /************************* ** net/net_namespace.h ** *************************/ -#include #include #include #include @@ -2455,14 +2261,16 @@ struct net struct hlist_head *dev_index_head; unsigned int dev_base_seq; int ifindex; + unsigned int dev_unreg_count; struct net_device *loopback_dev; + struct netns_core core; struct user_namespace *user_ns; struct proc_dir_entry *proc_net_stat; struct sock *rtnl; struct netns_mib mib; struct netns_ipv4 ipv4; atomic_t rt_genid; - + atomic_t fnhe_genid; }; @@ -2491,6 +2299,8 @@ static inline void put_net(struct net *net) { } static inline int net_eq(const struct net *net1, const struct net *net2) { return net1 == net2; } +typedef struct { unsigned dummy; } possible_net_t; + struct net *get_net_ns_by_pid(pid_t pid); struct net *get_net_ns_by_fd(int pid); @@ -2499,7 +2309,14 @@ int register_pernet_device(struct pernet_operations *); void release_net(struct net *net); int rt_genid(struct net *); +int rt_genid_ipv4(struct net *net); void rt_genid_bump(struct net *); +void rt_genid_bump_ipv4(struct net *net); + +int fnhe_genid(struct net *net); + +int peernet2id(struct net *net, struct net *peer); +bool peernet_has_id(struct net *net, struct net *peer); /************************** @@ -2537,6 +2354,9 @@ void write_sequnlock(seqlock_t *); void write_seqcount_begin(seqcount_t *); void write_seqcount_end(seqcount_t *); +unsigned raw_seqcount_begin(const seqcount_t *s); +int read_seqcount_retry(const seqcount_t *s, unsigned start); + /********************** ** net/secure_seq.h ** @@ -2662,7 +2482,7 @@ __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len, return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum)); } -static inline +static inline __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len, __wsum sum, int *err_ptr) { @@ -2672,16 +2492,23 @@ __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len, return sum; } +__wsum remcsum_adjust(void *ptr, __wsum csum, int start, int offset); +void csum_replace4(__sum16 *sum, __be32 from, __be32 to); + /********************* ** linux/if_vlan.h ** *********************/ -enum { VLAN_HLEN = 4 }; +enum { + VLAN_HLEN = 4, + VLAN_ETH_HLEN = 18, +}; struct vlan_hdr { - __be16 h_vlan_encapsulated_proto; + __be16 h_vlan_TCI; + __be16 h_vlan_encapsulated_proto; }; struct vlan_ethhdr @@ -2692,7 +2519,7 @@ struct vlan_ethhdr static inline struct net_device *vlan_dev_real_dev(const struct net_device *dev) { - return NULL; + return NULL; } #define vlan_tx_tag_get(__skb) 0 @@ -2703,6 +2530,38 @@ u16 vlan_tx_tag_present(struct sk_buff *); bool vlan_do_receive(struct sk_buff **); bool vlan_tx_nonzero_tag_present(struct sk_buff *); +enum { + VLAN_VID_MASK = 0x0fff, + VLAN_CFI_MASK = 0x1000, /* Canonical Format Indicator */ + VLAN_TAG_PRESENT = VLAN_CFI_MASK, +}; + +#define skb_vlan_tag_get(__skb) ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT) +#define skb_vlan_tag_present(__skb) ((__skb)->vlan_tci & VLAN_TAG_PRESENT) +#define skb_vlan_tag_get_id(__skb) ((__skb)->vlan_tci & VLAN_VID_MASK) + +__be16 __vlan_get_protocol(struct sk_buff *skb, __be16 type, int *depth); +void __vlan_hwaccel_put_tag(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci); +int __vlan_insert_tag(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci); + + +typedef u64 netdev_features_t; /* XXX actually defined in netdev_features.h */ + +bool skb_vlan_tagged(const struct sk_buff *skb); +netdev_features_t vlan_features_check(const struct sk_buff *skb, netdev_features_t features); +bool vlan_hw_offload_capable(netdev_features_t features, __be16 proto); +struct sk_buff *__vlan_hwaccel_push_inside(struct sk_buff *skb); +void vlan_set_encap_proto(struct sk_buff *skb, struct vlan_hdr *vhdr); + + +/***************************** + ** uapi/linux/if_bonding.h ** + *****************************/ + +typedef struct ifbond { unsigned dummy; } ifbond; + +typedef struct ifslave { unsigned dummy; } ifslave; + /******************** ** net/checksum.h ** @@ -2718,8 +2577,18 @@ __wsum csum_block_sub(__wsum, __wsum, int); __wsum csum_sub(__wsum csum, __wsum addend); __wsum csum_unfold(__sum16 n); +static inline __wsum csum_partial_ext(const void *buff, int len, __wsum sum) +{ + return csum_partial(buff, len, sum); +} + +__wsum csum_block_add_ext(__wsum csum, __wsum csum2, int offset, int len); + void csum_replace2(__sum16 *, __be16, __be16); +static inline void remcsum_unadjust(__sum16 *psum, __wsum delta) { + *psum = csum_fold(csum_sub(delta, *psum)); } + /***************************** ** uapi/linux/net_tstamp.h ** @@ -2734,8 +2603,12 @@ enum { SOF_TIMESTAMPING_RX_HARDWARE = 1 << 2, SOF_TIMESTAMPING_RX_SOFTWARE = 1 << 3, SOF_TIMESTAMPING_SOFTWARE = 1 << 4, - SOF_TIMESTAMPING_SYS_HARDWARE = 1 << 5, - SOF_TIMESTAMPING_RAW_HARDWARE = 1 << 6, + SOF_TIMESTAMPING_SYS_HARDWARE = 1 << 5, + SOF_TIMESTAMPING_RAW_HARDWARE = 1 << 6, + SOF_TIMESTAMPING_OPT_ID = 1 << 7, + SOF_TIMESTAMPING_TX_ACK = 1 << 9, + SOF_TIMESTAMPING_OPT_CMSG = 1 << 10, + SOF_TIMESTAMPING_OPT_TSONLY = 1 << 11, SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_RAW_HARDWARE - 1) | SOF_TIMESTAMPING_RAW_HARDWARE, }; @@ -2793,7 +2666,7 @@ typedef u16 (*rtnl_calcit_func)(struct sk_buff *, struct nlmsghdr *); extern const struct nla_policy ifla_policy[IFLA_MAX+1]; -void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change); +void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change, gfp_t flags); /********************** @@ -2802,6 +2675,7 @@ void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change); struct gnet_dump { }; + /*************** ** net/tcp.h ** ***************/ @@ -2815,6 +2689,56 @@ enum { extern int sysctl_tcp_fastopen; +/********************** + ** net/ip_tunnels.h ** + **********************/ + +enum +{ + IP_TUNNEL_INFO_TX = 0x01, + IP_TUNNEL_INFO_IPV6 = 0x02, +}; + +struct ip_tunnel_key { + __be64 tun_id; + union { + struct { + __be32 src; + __be32 dst; + } ipv4; + struct { + struct in6_addr src; + struct in6_addr dst; + } ipv6; + } u; + __be16 tun_flags; + u8 tos; /* TOS for IPv4, TC for IPv6 */ + u8 ttl; /* TTL for IPv4, HL for IPv6 */ + __be16 tp_src; + __be16 tp_dst; +}; + +struct ip_tunnel_info +{ + struct ip_tunnel_key key; + + u8 options_len; + u8 mode; +}; + +void ip_tunnel_key_init(struct ip_tunnel_key *key, + __be32 saddr, __be32 daddr, + u8 tos, u8 ttl, + __be16 tp_src, __be16 tp_dst, + __be64 tun_id, __be16 tun_flags); + +struct lwtunnel_state; +struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate); +struct metadata_dst *iptunnel_metadata_reply(struct metadata_dst *md, gfp_t flags); + +void ip_tunnel_core_init(void); + + /******************************** ** uapi/asm-generic/sockios.h ** ********************************/ @@ -2830,18 +2754,78 @@ enum { ** net/cls_cgroup.h ** **********************/ -void sock_update_classid(struct sock *, struct task_struct *); +void sock_update_classid(struct sock *); /**************** ** linux/ip.h ** ****************/ +#include + struct ip_hdr; struct iphdr *ip_hdr(const struct sk_buff *skb); +/************************* + ** uapi/linux/icmpv6.h ** + *************************/ + +enum +{ + ICMPV6_ECHO_REQUEST = 128, +}; + + +struct icmp6hdr +{ + __u8 icmp6_type; + __u8 icmp6_code; +}; + + +/******************** + ** linux/icmpv6.h ** + ********************/ + +struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb); + + +/*********************** + ** uapi/linux/ipv6.h ** + ***********************/ + +struct ipv6hdr +{ + __u8 priority:4, version:4; + __be16 payload_len; + __u8 hop_limit; + __u8 nexthdr; + struct in6_addr saddr; + struct in6_addr daddr; +}; + +struct ipv6_opt_hdr +{ + __u8 nexthdr; + __u8 hdrlen; +} __attribute__((packed)); + +struct frag_hdr +{ + __u8 nexthdr; + /* __u8 reserved; */ + __be16 frag_off; + /* __be32 identification; */ +}; + + +static inline __u8 ipv6_get_dsfield(const struct ipv6hdr *ipv6h); + +struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb); + + /******************************** ** uapi/linux/netfilter_arp.h ** ********************************/ @@ -2852,6 +2836,56 @@ enum { }; +/*************************** + ** uapi/linux/lwtunnel.h ** + ***************************/ + +enum lwtunnel_encap_types +{ + LWTUNNEL_ENCAP_NONE, +}; + + +/******************** + ** net/lwtunnel.h ** + ********************/ + +struct lwtunnel_state +{ + int (*orig_output)(struct net *net, struct sock *sk, struct sk_buff *skb); + int (*orig_input)(struct sk_buff *); +}; + +static inline int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb) +{ + return -EOPNOTSUPP; +} + +static inline int lwtunnel_input(struct sk_buff *skb) +{ + return -EOPNOTSUPP; +} + +static inline int lwtunnel_build_state(struct net_device *dev, u16 encap_type, + struct nlattr *encap, + unsigned int family, const void *cfg, + struct lwtunnel_state **lws) +{ + return -EOPNOTSUPP; +} + +void lwtstate_free(struct lwtunnel_state *lws); +void lwtstate_put(struct lwtunnel_state *lws); +int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate); + +static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate) { return false; } +static inline bool lwtunnel_input_redirect(struct lwtunnel_state *lwtstate) { return false; } + +struct lwtunnel_state * lwtstate_get(struct lwtunnel_state *lws); +int lwtunnel_cmp_encap(struct lwtunnel_state *a, struct lwtunnel_state *b); +int lwtunnel_get_encap_size(struct lwtunnel_state *lwtstate); + + /**************** ** net/ax25.h ** ****************/ @@ -2906,7 +2940,7 @@ struct sec_path struct xfrm_state *xvec[XFRM_MAX_DEPTH]; }; -int xfrm_sk_clone_policy(struct sock *); +int xfrm_sk_clone_policy(struct sock *, const struct sock *osk); int xfrm_decode_session_reverse(struct sk_buff *, struct flowi *, unsigned int); void xfrm_sk_free_policy(struct sock *); @@ -2982,6 +3016,7 @@ int inet_ctl_sock_create(struct sock **, unsigned short, unsigned short, unsigned char, struct net *); void inet_ctl_sock_destroy(struct sock *); +int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len); /*********************** @@ -3005,6 +3040,7 @@ struct inet_diag_handler struct inet_diag_msg *r, void *info); __u16 idiag_type; + __u16 idiag_info_size; }; @@ -3052,6 +3088,9 @@ bool netpoll_rx_on(struct sk_buff *); int netpoll_receive_skb(struct sk_buff *); void netpoll_poll_unlock(void *); +void netpoll_poll_disable(struct net_device *dev); +void netpoll_poll_enable(struct net_device *dev); + /************************ ** net/ethernet/eth.c ** @@ -3064,14 +3103,23 @@ extern const struct header_ops eth_header_ops; ** linux/netfilter.h ** ***********************/ -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb) -#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb) +#define NF_HOOK(pf, hook, net, sk, skb, indev, outdev, okfn) (okfn)(net, sk, skb) +#define NF_HOOK_COND(pf, hook, net, sk, skb, indev, outdev, okfn, cond) (okfn)(net, sk, skb) -int nf_hook(u_int8_t, unsigned int, struct sk_buff *, struct net_device *, - struct net_device *, int (*)(struct sk_buff *)); +int nf_hook(u_int8_t pf, unsigned int hook, struct net *net, + struct sock *sk, struct sk_buff *skb, + struct net_device *indev, struct net_device *outdev, + int (*okfn)(struct net *, struct sock *, struct sk_buff *)); void nf_ct_attach(struct sk_buff *, struct sk_buff *); +/******************************* + ** linux/netfilter_ingress.h ** + *******************************/ + +void nf_hook_ingress_init(struct net_device *dev); + + /****************************** ** linux/netfilter_bridge.h ** ******************************/ @@ -3113,7 +3161,25 @@ static inline bool ipv4_is_loopback(__be32 addr) #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x" #define MAC_ARG(x) x[0], x[1], x[2], x[3], x[4], x[5] +#define __UAPI_DEF_IPPROTO_V6 1 +#define __UAPI_DEF_IN6_ADDR 1 #include +#undef __UAPI_DEF_IN6_ADDR +#undef __UAPI_DEF_IPPROTO_V6 + +#define __UAPI_DEF_IN_IPPROTO 1 +#define __UAPI_DEF_IN_ADDR 1 +#define __UAPI_DEF_SOCKADDR_IN 1 +#define __UAPI_DEF_IN_CLASS 1 +#define __UAPI_DEF_IP_MREQ 1 +#define __UAPI_DEF_IN_PKTINFO 1 +#include +#undef __UAPI_DEF_IN_PKTINFO +#undef __UAPI_DEF_IP_MREQ +#undef __UAPI_DEF_IN_CLASS +#undef __UAPI_DEF_SOCKADDR_IN +#undef __UAPI_DEF_IN_IPPROTO +#undef __UAPI_DEF_IN_ADDR /******************** @@ -3130,10 +3196,24 @@ static inline void get_random_bytes(void *buf, int nbytes) b[i] = i + 1; } +static inline void get_random_once(void *buf, int nbytes) +{ + return get_random_bytes(buf, nbytes); +} + +static inline u32 prandom_u32(void) { return 4; /* fair dice roll */ } + +static inline void prandom_bytes(void *buf, size_t nbytes) +{ + get_random_bytes(buf, nbytes); +} + u32 random32(void); void add_device_randomness(const void *, unsigned int); u32 next_pseudo_random32(u32); void srandom32(u32 seed); +u32 prandom_u32_max(u32 ep_ro); +void prandom_seed(u32 seed); /********************** @@ -3163,23 +3243,45 @@ int security_netlink_send(struct sock *, struct sk_buff *); ** net/netns/hash.h ** **********************/ -unsigned int net_hash_mix(struct net *); +unsigned int net_hash_mix(struct net const *); /************************** ** net/netprio_cgroup.h ** **************************/ -void sock_update_netprioidx(struct sock *, struct task_struct *); +void sock_update_netprioidx(struct sock *); + + +/**************** + ** net/ipv6.h ** + ****************/ + +enum { + IP6_MF = 0x0001, + IP6_OFFSET = 0xfff8, +}; /****************** ** linux/ipv6.h ** ******************/ +struct inet6_skb_parm { unsigned dummy; }; + int inet_v6_ipv6only(const struct sock *); int ipv6_only_sock(const struct sock *); +#define ipv6_optlen(p) (((p)->hdrlen+1) << 3) +#define ipv6_authlen(p) (((p)->hdrlen+2) << 2) +#define ipv6_sk_rxinfo(sk) 0 + +/* XXX not the sanest thing to do... */ +struct ipv6_pinfo { + __u16 recverr:1; +}; +static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk) { return NULL; } + /******************** ** linux/mroute.h ** @@ -3203,6 +3305,7 @@ __be32 in_aton(const char *); int cipso_v4_validate(const struct sk_buff *, unsigned char **option); + /*********************** ** uapi/linux/stat.h ** ***********************/ @@ -3214,6 +3317,11 @@ bool S_ISSOCK(int); ** net/gen_stats.h ** *********************/ +struct gnet_stats_basic_cpu { + unsigned bstats; /* normally gnet_stats_basic_packed */ + unsigned syncp; /* normally u64_stats_sync */ +}; + struct gnet_stats_basic_packed; struct gnet_stats_rate_est; @@ -3221,6 +3329,70 @@ void gen_kill_estimator(struct gnet_stats_basic_packed *, struct gnet_stats_rate_est *); +/******************* + ** linux/sysfs.h ** + *******************/ + +struct attribute { + const char *name; + mode_t mode; +}; + +int sysfs_create_link(struct kobject *kobj, struct kobject *target, const char *name); +void sysfs_remove_link(struct kobject *kobj, const char *name); +void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, const char *link_name); + + +/********************* + ** net/pusy_poll.h ** + *********************/ + +bool sk_busy_loop(struct sock *sk, int nonblock); +bool sk_can_busy_loop(struct sock *sk); +void sk_mark_napi_id(struct sock *sk, struct sk_buff *skb); + + +/****************** + ** net/l3mdev.h ** + ******************/ + +int l3mdev_get_saddr(struct net *net, int ifindex, struct flowi4 *fl4); +struct rtable *l3mdev_get_rtable(const struct net_device *dev, const struct flowi4 *fl4); +bool netif_index_is_l3_master(struct net *net, int ifindex); +u32 l3mdev_fib_table(const struct net_device *dev); +int l3mdev_master_ifindex_rcu(struct net_device *dev); +int l3mdev_fib_oif_rcu(struct net_device *dev); +u32 l3mdev_fib_table_by_index(struct net *net, int ifindex); +int l3mdev_master_ifindex(struct net_device *dev); + + +/*********************** + ** linux/sock_diag.h ** + ***********************/ + +bool sock_diag_has_destroy_listeners(const struct sock *sk); +void sock_diag_broadcast_destroy(struct sock *sk); + + +/************************ + ** net/ip6_checksum.h ** + ************************/ + +__sum16 csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr, + __u32 len, unsigned short proto, __wsum csum); + + +/*********************** + ** linux/switchdev.h ** + ***********************/ + +struct fib_info; + +int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, u8 tos, u8 type, u32 nlflags, u32 tb_id); +int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, u8 tos, u8 type, u32 tb_id); +void switchdev_fib_ipv4_abort(struct fib_info *fi); + + /******************* ** Tracing stuff ** *******************/ @@ -3239,17 +3411,27 @@ void trace_netif_receive_skb(struct sk_buff *); void trace_napi_poll(struct napi_struct *); void trace_skb_copy_datagram_iovec(const struct sk_buff *, int); void trace_udp_fail_queue_rcv_skb(int, struct sock*); +void trace_net_dev_start_xmit(struct sk_buff*, struct net_device*); +void trace_netif_rx_entry(struct sk_buff*); +void trace_netif_rx_ni_entry(struct sk_buff*); +void trace_netif_receive_skb_entry(struct sk_buff*); +void trace_napi_gro_receive_entry(struct sk_buff*); +void trace_napi_gro_frags_entry(struct sk_buff*); +void trace_fib_validate_source(struct net_device *, struct flowi4*); +void trace_fib_table_lookup(void*, void*); +void trace_fib_table_lookup_nh(void*); -/** - * Misc - */ +/****************** + ** Lxip private ** + ******************/ void set_sock_wait(struct socket *sock, unsigned long ptr); -int socket_check_state(struct socket *sock); +int socket_check_state(struct socket *sock); void log_sock(struct socket *sock); void lx_trace_event(char const *, ...) __attribute__((format(printf, 1, 2))); -#endif /* _LX_EMUL_H_ */ +#include +#endif /* _LX_EMUL_H_ */ diff --git a/repos/dde_linux/src/lib/lxip/include/packet_handler.h b/repos/dde_linux/src/lib/lxip/include/packet_handler.h deleted file mode 100644 index a7eb5a9e0..000000000 --- a/repos/dde_linux/src/lib/lxip/include/packet_handler.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * \brief Signal driven network handler - * \author Stefan Kalkowski - * \auhtor Sebastian Sumpf - * \date 2013-09-24 - */ - -/* - * Copyright (C) 2010-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _PACKET_HANDLER_H_ -#define _PACKET_HANDLER_H_ - -/* Genode */ -#include - -namespace Net { - - class Packet_handler; - - using Nic::Packet_stream_sink; - using Nic::Packet_stream_source; - using Nic::Packet_descriptor; -} - - -/** - * Generic packet handler used as base for NIC and client packet handlers. - */ -class Net::Packet_handler -{ - protected: - - /** - * submit queue not empty anymore - */ - void _packet_avail(unsigned); - - /** - * acknoledgement queue not full anymore - */ - void _ready_to_ack(unsigned); - - /** - * acknoledgement queue not empty anymore - */ - void _ack_avail(unsigned); - - /** - * submit queue not full anymore - * - * TODO: by now, we just drop packets that cannot be transferred - * to the other side, that's why we ignore this signal. - */ - void _ready_to_submit(unsigned) { } - - Genode::Signal_dispatcher _sink_ack; - Genode::Signal_dispatcher _sink_submit; - Genode::Signal_dispatcher _source_ack; - Genode::Signal_dispatcher _source_submit; - - public: - - Packet_handler(); - - virtual Packet_stream_sink< ::Nic::Session::Policy> * sink() = 0; - virtual Packet_stream_source< ::Nic::Session::Policy> * source() = 0; -}; - -#endif /* _PACKET_HANDLER_H_ */ diff --git a/repos/dde_linux/src/lib/lxip/init.c b/repos/dde_linux/src/lib/lxip/init.c deleted file mode 100644 index 26f0a652d..000000000 --- a/repos/dde_linux/src/lib/lxip/init.c +++ /dev/null @@ -1,87 +0,0 @@ -/** - * \brief IP stack initialization - * \author Sebastian Sumpf - * \date 2013-08-26 - */ - -/* - * Copyright (C) 2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ -#include -#include -#include - -/* - * Header declarations and tuning - */ -struct net init_net; - -unsigned long *sysctl_local_reserved_ports; -struct pernet_operations loopback_net_ops; - - -/** - * nr_free_buffer_pages - count number of pages beyond high watermark - * - * nr_free_buffer_pages() counts the number of pages which are beyond the - * high - * watermark within ZONE_DMA and ZONE_NORMAL. - */ -unsigned long nr_free_buffer_pages(void) -{ - return 1000; -} - - -/* - * Declare stuff used - */ -int __ip_auto_config_setup(char *addrs); -void core_sock_init(void); -void core_netlink_proto_init(void); -void subsys_net_dev_init(void); -void fs_inet_init(void); -void module_driver_init(void); -void module_cubictcp_register(void); -void late_ip_auto_config(void); -void late_tcp_congestion_default(void); - -/** - * Initialize sub-systems - */ -int lxip_init(char *address_config) -{ - /* init data */ - INIT_LIST_HEAD(&init_net.dev_base_head); - - /* call __setup stuff */ - __ip_auto_config_setup(address_config); - - core_sock_init(); - core_netlink_proto_init(); - - /* sub-systems */ - subsys_net_dev_init(); - fs_inet_init(); - - /* enable local accepts */ - IPV4_DEVCONF_ALL(&init_net, ACCEPT_LOCAL) = 0x1; - - /* congestion control */ - module_cubictcp_register(); - - /* driver */ - module_driver_init(); - - /* late */ - late_tcp_congestion_default(); - - /* dhcp or static configuration */ - late_ip_auto_config(); - - return 1; -} - diff --git a/repos/dde_linux/src/lib/lxip/lx.h b/repos/dde_linux/src/lib/lxip/lx.h new file mode 100644 index 000000000..a1e9e40ad --- /dev/null +++ b/repos/dde_linux/src/lib/lxip/lx.h @@ -0,0 +1,30 @@ +/* + * \brief Lx env + * \author Josef Soentgen + * \date 2014-10-17 + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _LX_H_ +#define _LX_H_ + +#include + +namespace Lx { + + void nic_client_init(Genode::Signal_receiver &); + void timer_init(Genode::Signal_receiver &); + void event_init(Genode::Signal_receiver &); + + void timer_update_jiffies(); +} + +extern "C" int lxip_init(char const *address_config); + +#endif /* _LX_H_ */ diff --git a/repos/dde_linux/src/lib/lxip/lxc_emul.c b/repos/dde_linux/src/lib/lxip/lxc_emul.c index 11389af41..df91a0cf2 100644 --- a/repos/dde_linux/src/lib/lxip/lxc_emul.c +++ b/repos/dde_linux/src/lib/lxip/lxc_emul.c @@ -1,77 +1,51 @@ /** * \brief Linux emulation code * \author Sebastian Sumpf + * \author Josef Soentgen * \date 2013-08-30 */ /* - * Copyright (C) 2013 Genode Labs GmbH + * Copyright (C) 2013-2016 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. */ + +/* Linux includes */ +#include +#include #include -#include #include #include #include +#include #include +#include -/******************** - ** linux/slab.h ** - ********************/ +/*********************** + ** linux/genetlink.h ** + ***********************/ -struct kmem_cache +/* needed by af_netlink.c */ +atomic_t genl_sk_destructing_cnt; +wait_queue_head_t genl_sk_destructing_waitq; + + +/**************************** + ** asm-generic/atomic64.h ** + ****************************/ + +long long atomic64_read(const atomic64_t *v) { - const char *name; /* cache name */ - unsigned size; /* object size */ -}; - - -struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align, - unsigned long falgs, void (*ctor)(void *)) -{ - lx_log(DEBUG_SLAB, "\"%s\" obj_size=%zd", name, size); - - struct kmem_cache *cache; - - if (!name) { - pr_info("kmem_cache name required\n"); - return 0; - } - - cache = (struct kmem_cache *)kmalloc(sizeof(*cache), 0); - if (!cache) { - pr_crit("No memory for slab cache\n"); - return 0; - } - - cache->name = name; - cache->size = size; - - return cache; + return v->counter; } -void *kmem_cache_alloc_node(struct kmem_cache *cache, gfp_t flags, int node) +void atomic64_set(atomic64_t *v, long long i) { - lx_log(DEBUG_SLAB, "\"%s\" alloc obj_size=%u", cache->name,cache->size); - return kmalloc(cache->size, 0); -} - - -void *kmem_cache_alloc(struct kmem_cache *cache, gfp_t flags) -{ - lx_log(DEBUG_SLAB, "\"%s\" alloc obj_size=%u", cache->name,cache->size); - return kmalloc(cache->size, 0); -} - - -void kmem_cache_free(struct kmem_cache *cache, void *objp) -{ - lx_log(DEBUG_SLAB, "\"%s\" (%p)", cache->name, objp); - kfree(objp); + v->counter = i; } @@ -134,6 +108,7 @@ u32 hash_32(u32 val, unsigned int bits) return hash; } + /****************** ** linux/dcache ** ******************/ @@ -147,6 +122,7 @@ unsigned int full_name_hash(const unsigned char *name, unsigned int len) return hash; } + /****************************** * net/core/net/namespace.h ** ******************************/ @@ -196,16 +172,6 @@ struct iphdr *ip_hdr(const struct sk_buff *skb) } -/*********************** - ** linux/netdevice.h ** - ***********************/ - - struct netdev_queue *netdev_pick_tx(struct net_device *dev, struct sk_buff *skb) - { - return netdev_get_tx_queue(dev, 0); - } - - /******************************* ** asm-generic/bitops/find.h ** *******************************/ @@ -249,8 +215,10 @@ int get_order(unsigned long size) ** linux/jiffies.h ** *********************/ -long time_after_eq(long a, long b) { return (a - b) >= 0; } -long time_after(long a, long b) { return (b - a) < 0; } +clock_t jiffies_to_clock_t(unsigned long j) +{ + return j / HZ; /* XXX not sure if this is enough */ +} /********************* @@ -356,14 +324,211 @@ __wsum csum_block_add(__wsum csum, __wsum csum2, int offset) } -/** - * Misc +__wsum csum_block_add_ext(__wsum csum, __wsum csum2, int offset, int len) +{ + return csum_block_add(csum, csum2, offset); +} + + +/*************************** + ** Linux socket function ** + ***************************/ + +static const struct net_proto_family *net_families[NPROTO]; + + +int sock_register(const struct net_proto_family *ops) +{ + if (ops->family >= NPROTO) { + printk("protocol %d >= NPROTO (%d)\n", ops->family, NPROTO); + return -ENOBUFS; + } + + net_families[ops->family] = ops; + pr_info("NET: Registered protocol family %d\n", ops->family); + return 0; +} + + +struct socket *sock_alloc(void) +{ + struct socket *sock = (struct socket *)kzalloc(sizeof(struct socket), 0); + + /* + * Linux normally allocates the socket_wq when calling + * sock_alloc_inode() while we do it here hoping for the best. + */ + sock->wq = (struct socket_wq*)kzalloc(sizeof(*sock->wq), 0); + if (!sock->wq) { + kfree(sock); + return NULL; + } + + return sock; +} + + +int sock_create_lite(int family, int type, int protocol, struct socket **res) + +{ + struct socket *sock = sock_alloc(); + + if (!sock) + return -ENOMEM; + + sock->type = type; + *res = sock; + return 0; +} + + +int sock_create_kern(struct net *net, int family, int type, int proto, + struct socket **res) +{ + struct socket *sock; + const struct net_proto_family *pf; + int err; + + if (family < 0 || family > NPROTO) + return -EAFNOSUPPORT; + + if (type < 0 || type > SOCK_MAX) + return -EINVAL; + + pf = net_families[family]; + + if (!pf) { + printk("No protocol found for family %d\n", family); + return -ENOPROTOOPT; + } + + sock = sock_alloc(); + if (!sock) { + printk("Could not allocate socket\n"); + return -ENFILE; + } + + sock->type = type; + + err = pf->create(&init_net, sock, proto, 1); + if (err) { + kfree(sock); + return err; + } + + *res = sock; + + return 0; +} + + +static void sock_init(void) +{ + skb_init(); +} + + +core_initcall(sock_init); + + +/************************* + ** Lxip initialization ** + *************************/ + +/* + * Header declarations and tuning */ +struct net init_net; + +unsigned long *sysctl_local_reserved_ports; +struct pernet_operations loopback_net_ops; + + +/** + * nr_free_buffer_pages - count number of pages beyond high watermark + * + * nr_free_buffer_pages() counts the number of pages which are beyond the + * high + * watermark within ZONE_DMA and ZONE_NORMAL. + */ +unsigned long nr_free_buffer_pages(void) +{ + return 1000; +} + + +/* + * Declare stuff used + */ +int __ip_auto_config_setup(char *addrs); +void core_sock_init(void); +void core_netlink_proto_init(void); +void subsys_net_dev_init(void); +void fs_inet_init(void); +void module_driver_init(void); +void module_cubictcp_register(void); +void late_ip_auto_config(void); +void late_tcp_congestion_default(void); + + +/** + * Initialize sub-systems + */ +int lxip_init(char const *address_config) +{ + /* init data */ + INIT_LIST_HEAD(&init_net.dev_base_head); + + /* call __setup stuff */ + __ip_auto_config_setup((char *)address_config); + + core_sock_init(); + core_netlink_proto_init(); + + /* sub-systems */ + subsys_net_dev_init(); + fs_inet_init(); + + /* enable local accepts */ + IPV4_DEVCONF_ALL(&init_net, ACCEPT_LOCAL) = 0x1; + + /* congestion control */ + module_cubictcp_register(); + + /* driver */ + module_driver_init(); + + /* late */ + late_tcp_congestion_default(); + + /* dhcp or static configuration */ + late_ip_auto_config(); + + return 0; +} + + +/****************** + ** Lxip private ** + ******************/ void set_sock_wait(struct socket *sock, unsigned long ptr) { - sock->sk->sk_wq = (struct socket_wq *)ptr; } +int socket_check_state(struct socket *socket) +{ + if (socket->sk->sk_state == TCP_CLOSE_WAIT) + return -EINTR; + + return 0; +} + + +void log_sock(struct socket *socket) +{ + printk("\nNEW socket %p sk %p fsk %x &sk %p &fsk %p\n\n", + socket, socket->sk, socket->flags, &socket->sk, &socket->flags); +} diff --git a/repos/dde_linux/src/lib/lxip/lxcc_emul.cc b/repos/dde_linux/src/lib/lxip/lxcc_emul.cc index f2d2952ea..3e87b6b51 100644 --- a/repos/dde_linux/src/lib/lxip/lxcc_emul.cc +++ b/repos/dde_linux/src/lib/lxip/lxcc_emul.cc @@ -5,401 +5,87 @@ */ /* - * Copyright (C) 2013 Genode Labs GmbH + * Copyright (C) 2013-2016 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. */ + +/* Genode includes */ #include +#include +#include #include #include #include #include #include -#include +/* local includes */ #include -#include - -#include +#include -/* - * VM-area to reserve for back-end allocator - */ -enum { VM_RESERVATION = 24 * 1024 * 1024 }; +/********************************* + ** Lx::Backend_alloc interface ** + *********************************/ -/* - * TODO: fine tune these - */ -unsigned long totalram_pages = VM_RESERVATION / PAGE_SIZE; -unsigned long num_physpages = totalram_pages; +#include -namespace Genode { - template class Slab_backend_alloc; - typedef Slab_backend_alloc Backend_alloc; - class Slab_alloc; + +struct Memory_object_base : Genode::Object_pool::Entry +{ + Memory_object_base(Genode::Ram_dataspace_capability cap) + : Genode::Object_pool::Entry(cap) {} + + void free() { Genode::env()->ram_session()->free(ram_cap()); } + + Genode::Ram_dataspace_capability ram_cap() + { + using namespace Genode; + return reinterpret_cap_cast(cap()); + } +}; + + +static Genode::Object_pool memory_pool; + + +Genode::Ram_dataspace_capability +Lx::backend_alloc(Genode::addr_t size, Genode::Cache_attribute cached) +{ + using namespace Genode; + + Genode::Ram_dataspace_capability cap = env()->ram_session()->alloc(size); + Memory_object_base *o = new (env()->heap()) Memory_object_base(cap); + + memory_pool.insert(o); + return cap; } -/** - * Back-end allocator for Genode's slab allocator - */ -template -class Genode::Slab_backend_alloc : public Genode::Allocator, - public Genode::Rm_connection, - public Genode::Region_map_client + +void Lx::backend_free(Genode::Ram_dataspace_capability cap) { - private: + using namespace Genode; - enum { - BLOCK_SIZE = 1024 * 1024, /* 1 MB */ - ELEMENTS = VM_SIZE / BLOCK_SIZE, /* MAX number of dataspaces in VM */ - }; + Memory_object_base *object; + memory_pool.apply(cap, [&] (Memory_object_base *o) { + if (!o) return; - addr_t _base; /* virt. base address */ - Cache_attribute _cached; /* non-/cached RAM */ - Ram_dataspace_capability _ds_cap[ELEMENTS]; /* dataspaces to put in VM */ - addr_t _ds_phys[ELEMENTS]; /* physical bases of dataspaces */ - int _index; /* current index in ds_cap */ - Allocator_avl _range; /* manage allocations */ + o->free(); + memory_pool.remove(o); - bool _alloc_block() - { - if (_index == ELEMENTS) { - PERR("Slab-backend exhausted!"); - return false; - } - - try { - _ds_cap[_index] = Genode::env()->ram_session()->alloc(BLOCK_SIZE, _cached); - /* attach at index * BLOCK_SIZE */ - Region_map_client::attach_at(_ds_cap[_index], _index * BLOCK_SIZE, BLOCK_SIZE, 0); - - /* lookup phys. address */ - _ds_phys[_index] = Dataspace_client(_ds_cap[_index]).phys_addr(); - } catch (...) { return false; } - - /* return base + offset in VM area */ - addr_t block_base = _base + (_index * BLOCK_SIZE); - ++_index; - - _range.add_range(block_base, BLOCK_SIZE); - return true; - } - - public: - - Slab_backend_alloc(Cache_attribute cached) - : - Region_map_client(Rm_connection::create(VM_SIZE)), - _cached(cached), _index(0), _range(env()->heap()) - { - /* reserver attach us, anywere */ - _base = env()->rm_session()->attach(dataspace()); - } - - /** - * Allocate - */ - bool alloc(size_t size, void **out_addr) override - { - bool done = _range.alloc(size, out_addr); - - if (done) - return done; - - done = _alloc_block(); - if (!done) { - PERR("Backend allocator exhausted\n"); - return false; - } - - return _range.alloc(size, out_addr); - } - - void free(void *addr, size_t size) override { _range.free(addr, size); } - size_t overhead(size_t size) const override { return 0; } - bool need_size_for_free() const override { return false; } - - /** - * Return phys address for given virtual addr. - */ - addr_t phys_addr(addr_t addr) - { - if (addr < _base || addr >= (_base + VM_SIZE)) - return ~0UL; - - int index = (addr - _base) / BLOCK_SIZE; - - /* physical base of dataspace */ - addr_t phys = _ds_phys[index]; - - if (!phys) - return ~0UL; - - /* add offset */ - phys += (addr - _base - (index * BLOCK_SIZE)); - return phys; - } - - addr_t start() const { return _base; } - addr_t end() const { return _base + VM_SIZE - 1; } -}; - - -/** - * Slab allocator using our back-end allocator - */ -class Genode::Slab_alloc : public Genode::Slab -{ - private: - - Genode::size_t const _object_size; - - static Genode::size_t _calculate_block_size(Genode::size_t object_size) - { - Genode::size_t const block_size = 16*object_size; - return align_addr(block_size, 12); - } - - public: - - Slab_alloc(size_t object_size, Backend_alloc *allocator) - : - Slab(object_size, _calculate_block_size(object_size), 0, allocator), - _object_size(object_size) - { } - - inline addr_t alloc() - { - Genode::addr_t result; - return (Slab::alloc(_object_size, (void **)&result) ? result : 0); - } - - void free(void *ptr) { Slab::free(ptr, _object_size); } -}; - -/** - * Memory interface used used for Linux emulation - */ -class Malloc -{ - private: - - enum { - SLAB_START_LOG2 = 3, /* 8 B */ - SLAB_STOP_LOG2 = 16, /* 64 KB */ - NUM_SLABS = (SLAB_STOP_LOG2 - SLAB_START_LOG2) + 1, - }; - - typedef Genode::addr_t addr_t; - typedef Genode::Slab_alloc Slab_alloc; - typedef Genode::Slab_backend_alloc Slab_backend_alloc; - - Slab_backend_alloc *_back_allocator; - Slab_alloc *_allocator[NUM_SLABS]; - bool _cached; /* cached or un-cached memory */ - addr_t _start; /* VM region of this allocator */ - addr_t _end; - - /** - * Set 'value' at 'addr' - */ - void _set_at(addr_t addr, addr_t value) { *((addr_t *)addr) = value; } - - /** - * Retrieve slab index belonging to given address - */ - unsigned _slab_index(Genode::addr_t **addr) - { - using namespace Genode; - /* get index */ - addr_t index = *(*addr - 1); - - /* - * If index large, we use aligned memory, retrieve beginning of slab entry - * and read index from there - */ - if (index > 32) { - *addr = (addr_t *)*(*addr - 1); - index = *(*addr - 1); - } - - return index; - } - - public: - - Malloc(Slab_backend_alloc *alloc, Genode::Cache_attribute cached) - : _back_allocator(alloc), _cached(cached), _start(alloc->start()), - _end(alloc->end()) - { - /* init slab allocators */ - for (unsigned i = SLAB_START_LOG2; i <= SLAB_STOP_LOG2; i++) - _allocator[i - SLAB_START_LOG2] = new (Genode::env()->heap()) - Slab_alloc(1U << i, alloc); - } - - /** - * Alloc in slabs - */ - void *alloc(Genode::size_t size, int align = 0, Genode::addr_t *phys = 0) - { - using namespace Genode; - /* += slab index + aligment size */ - size += sizeof(addr_t) + (align > 2 ? (1 << align) : 0); - - int msb = Genode::log2(size); - - if (size > (1U << msb)) - msb++; - - if (size < (1U << SLAB_START_LOG2)) - msb = SLAB_STOP_LOG2; - - if (msb > SLAB_STOP_LOG2) { - PERR("Slab too large %u requested %zu cached %d", 1U << msb, size, _cached); - return 0; - } - - addr_t addr = _allocator[msb - SLAB_START_LOG2]->alloc(); - if (!addr) { - PERR("Failed to get slab for %u", 1 << msb); - return 0; - } - - _set_at(addr, msb - SLAB_START_LOG2); - addr += sizeof(addr_t); - - if (align > 2) { - /* save */ - addr_t ptr = addr; - addr_t align_val = (1U << align); - addr_t align_mask = align_val - 1; - /* align */ - addr = (addr + align_val) & ~align_mask; - /* write start address before aligned address */ - _set_at(addr - sizeof(addr_t), ptr); - } - - if (phys) - *phys = _back_allocator->phys_addr(addr); - return (addr_t *)addr; - } - - void free(void const *a) - { - using namespace Genode; - addr_t *addr = (addr_t *)a; - - unsigned nr = _slab_index(&addr); - _allocator[nr]->free((void *)(addr - 1)); - } - - size_t slab_size(void const *a) - { - using namespace Genode; - addr_t *addr =(addr_t *)a; - - unsigned nr = _slab_index(&addr); - size_t size = 1 << (SLAB_START_LOG2 + nr); - size -= (addr_t)a - (addr_t)(addr - 1); - return size; - } - - Genode::addr_t phys_addr(void *a) - { - return _back_allocator->phys_addr((addr_t)a); - } - - /** - * Belongs given address to this allocator - */ - bool inside(addr_t const addr) const { return (addr > _start) && (addr <= _end); } - - /** - * Cached memory allocator - */ - static Malloc *mem() - { - static Slab_backend_alloc _b(Genode::CACHED); - static Malloc _m(&_b, Genode::CACHED); - return &_m; - } -}; + object = o; /* save for destroy */ + }); + destroy(env()->heap(), object); +} /************************************* ** Memory allocation, linux/slab.h ** *************************************/ -void *kmalloc(size_t size, gfp_t flags) -{ - void *addr = Malloc::mem()->alloc(size); - - unsigned long a = (unsigned long)addr; - - if (a & 0x3) - PERR("Unaligned kmalloc %lx", a); - -// PDBG("Kmalloc: [%lx-%lx) from %p", a, a + size, __builtin_return_address(0)); - return addr; -} - - -void *kzalloc(size_t size, gfp_t flags) -{ - void *addr = kmalloc(size, flags); - if (addr) - Genode::memset(addr, 0, size); - - //PDBG("Kmalloc: [%lx-%lx) from %p", (unsigned)addr, (unsigned)addr + size, __builtin_return_address(0)); - return addr; -} - - -void *kcalloc(size_t n, size_t size, gfp_t flags) -{ - if (size != 0 && n > ~0UL / size) - return 0; - - return kzalloc(n * size, flags); -} - -void kfree(const void *p) -{ - if (!p) return; - - if (Malloc::mem()->inside((Genode::addr_t)p)) - Malloc::mem()->free(p); - else - PWRN("%p is not within our memory range called from %p", - p, __builtin_return_address(0)); -} - - -void *kmalloc_node_track_caller(size_t size, gfp_t flags, int node) -{ - return kmalloc(size, 0); -} - - -void *kzalloc_node(size_t size, gfp_t flags, int node) -{ - return kzalloc(size, 0); -} - - -size_t ksize(const void *p) -{ - if (!(Malloc::mem()->inside((Genode::addr_t)p))) { - PDBG("%p not in slab allocator", p); - return 0; - } - - size_t size = Malloc::mem()->slab_size(p); - return size; -} +#include void *alloc_large_system_hash(const char *tablename, @@ -427,6 +113,46 @@ void *alloc_large_system_hash(const char *tablename, } +void *kmalloc_array(size_t n, size_t size, gfp_t flags) +{ + if (size != 0 && n > SIZE_MAX / size) return NULL; + return kmalloc(n * size, flags); +} + + +/******************** + ** linux/slab.h ** + ********************/ + +void *kmem_cache_alloc_node(struct kmem_cache *cache, gfp_t flags, int node) +{ + return (void*)cache->alloc(); +} + +void *kmem_cache_zalloc(struct kmem_cache *cache, gfp_t flags) +{ + void *addr = (void*)cache->alloc(); + if (addr) { memset(addr, 0, cache->size()); } + + return addr; +} + + +/********************* + ** linux/vmalloc.h ** + *********************/ + +void *vmalloc(unsigned long size) +{ + return kmalloc(size, 0); +} + + +void vfree(void const *addr) +{ + kfree(addr); +} + /******************** ** linux/string.h ** @@ -454,6 +180,7 @@ char *strchr(const char *p, int ch) return 0; } + char *strnchr(const char *p, size_t count, int ch) { char c; @@ -468,6 +195,7 @@ char *strnchr(const char *p, size_t count, int ch) return 0; } + size_t strnlen(const char *s, size_t maxlen) { size_t c; @@ -478,14 +206,19 @@ size_t strnlen(const char *s, size_t maxlen) return maxlen; } + size_t strlen(const char *s) { return Genode::strlen(s); } -int strcmp(const char *s1, const char *s2) { return Genode::strcmp(s1, s2); } -int strncmp(const char *s1, const char *s2, size_t len) { + + +int strcmp(const char *s1, const char *s2) { return Genode::strcmp(s1, s2); } + + +int strncmp(const char *s1, const char *s2, size_t len) { return Genode::strcmp(s1, s2, len); } -int memcmp(const void *p0, const void *p1, size_t size) { - return Genode::memcmp(p0, p1, size); } +int memcmp(const void *p0, const void *p1, size_t size) { + return Genode::memcmp(p0, p1, size); } int snprintf(char *str, size_t size, const char *format, ...) @@ -494,9 +227,7 @@ int snprintf(char *str, size_t size, const char *format, ...) va_start(list, format); Genode::String_console sc(str, size); - sc.vprintf(format, list); - va_end(list); return sc.len(); @@ -516,37 +247,31 @@ size_t strlcpy(char *dest, const char *src, size_t size) } -void *kmemdup(const void *src, size_t len, gfp_t gfp) -{ - void *ptr = kmalloc(len, gfp); - Genode::memcpy(ptr, src, len); - return ptr; -} - - -void *genode_memcpy(void *d, const void *s, size_t n) +void *memcpy(void *d, const void *s, size_t n) { return Genode::memcpy(d, s, n); } -/****************** - ** linux/log2.h ** - ******************/ - -unsigned long ilog2(unsigned long n) { return Genode::log2(n); } - - /******************* ** linux/sched.h ** *******************/ +static Genode::Signal_receiver *_sig_rec; + + +void Lx::event_init(Genode::Signal_receiver &sig_rec) +{ + _sig_rec = &sig_rec; +} + + struct Timeout : Genode::Signal_dispatcher { void handle(unsigned) { update_jiffies(); } Timeout(Timer::Session_client &timer, signed long msec) - : Signal_dispatcher(*Net::Env::receiver(), *this, &Timeout::handle) + : Signal_dispatcher(*_sig_rec, *this, &Timeout::handle) { if (msec > 0) { timer.sigh(*this); @@ -562,7 +287,7 @@ static void __wait_event(signed long timeout) Timeout to(timer, timeout); /* dispatch signal */ - Genode::Signal s = Net::Env::receiver()->wait_for_signal(); + Genode::Signal s = _sig_rec->wait_for_signal(); static_cast(s.context())->dispatch(s.num()); } @@ -581,6 +306,7 @@ signed long schedule_timeout(signed long timeout) return timeout < 0 ? 0 : timeout; } + void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p) { __wait_event(0); @@ -596,6 +322,7 @@ unsigned long get_seconds(void) return jiffies / HZ; } + /***************** ** linux/gfp.h ** *****************/ @@ -625,11 +352,12 @@ class Avl_page : public Genode::Avl_node _page->addr = (void *)_addr; atomic_set(&_page->_count, 1); - lx_log(DEBUG_SLAB, "alloc page: %p addr: %lx-%lx", _page, _addr, _addr + size); + lx_log(DEBUG_SLAB, "alloc page: %p addr: %lx-%lx", _page, _addr, _addr + _size); } virtual ~Avl_page() { + lx_log(DEBUG_SLAB, "free page: %p addr: %lx-%lx", _page, _addr, _addr + _size); kfree((void *)_addr); kfree((void *)_page); } @@ -640,20 +368,22 @@ class Avl_page : public Genode::Avl_node { return c->_addr > _addr; } - + Avl_page *find_by_address(Genode::addr_t addr) { if (addr >= _addr && addr < _addr + _size) return this; - + bool side = addr > _addr; Avl_page *c = Avl_node::child(side); return c ? c->find_by_address(addr) : 0; } }; + static Genode::Avl_tree tree; + struct page *alloc_pages(gfp_t gfp_mask, unsigned int order) { Avl_page *p; @@ -666,6 +396,25 @@ struct page *alloc_pages(gfp_t gfp_mask, unsigned int order) } +void *__alloc_page_frag(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask) +{ + struct page *page = alloc_pages(gfp_mask, fragsz / PAGE_SIZE); + if (!page) return nullptr; + + return page->addr; +} + + +void __free_page_frag(void *addr) +{ + Avl_page *p = tree.first()->find_by_address((Genode::addr_t)addr); + + tree.remove(p); + destroy(Genode::env()->heap(), p); +} + + /**************** ** linux/mm.h ** ****************/ @@ -719,3 +468,165 @@ extern "C" void lx_trace_event(char const *fmt, ...) create_event(fmt, list); va_end(list); } + + +/***************** + ** linux/uio.h ** + *****************/ + +size_t copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) +{ + if (bytes > i->count) + bytes = i->count; + + if (bytes == 0) + return 0; + + char *kdata = reinterpret_cast(addr); + struct iovec const *iov = i->iov; + + size_t len = bytes; + while (len > 0) { + if (iov->iov_len) { + size_t copy_len = (size_t)len < iov->iov_len ? len : iov->iov_len; + Genode::memcpy(kdata, iov->iov_base, copy_len); + + len -= copy_len; + kdata += copy_len; + i->count -= copy_len; /* XXX the vanilla macro does that */ + } + iov++; + } + + return bytes; +} + + +size_t copy_to_iter(void *addr, size_t bytes, struct iov_iter *i) +{ + if (bytes > i->count) + bytes = i->count; + + if (bytes == 0) + return 0; + + char *kdata = reinterpret_cast(addr); + struct iovec const *iov = i->iov; + + size_t len = bytes; + while (len > 0) { + if (iov->iov_len) { + size_t copy_len = (size_t)len < iov->iov_len ? len : iov->iov_len; + Genode::memcpy(iov->iov_base, kdata, copy_len); + + len -= copy_len; + kdata += copy_len; + + i->count -= copy_len; /* XXX the vanilla macro does that */ + } + iov++; + } + + return bytes; +} + + +size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, + struct iov_iter *i) +{ + return copy_to_iter(reinterpret_cast(page->addr) + offset, bytes, i); +} + + +size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, + struct iov_iter *i) +{ + return copy_from_iter(reinterpret_cast(page->addr) + offset, bytes, i); +} + + +size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i) +{ + if (bytes > i->count) + bytes = i->count; + + if (bytes == 0) + return 0; + + char *kdata = reinterpret_cast(addr); + struct iovec const *iov = i->iov; + + __wsum sum = *csum; + size_t len = bytes; + while (len > 0) { + if (iov->iov_len) { + size_t copy_len = (size_t)len < iov->iov_len ? len : iov->iov_len; + int err = 0; + __wsum next = csum_and_copy_from_user(iov->iov_base, kdata, copy_len, 0, &err); + + if (err) { + PERR("%s: err: %d - sleeping", __func__, err); + Genode::sleep_forever(); + } + + sum = csum_block_add(sum, next, bytes-len); + + len -= copy_len; + kdata += copy_len; + + i->count -= copy_len; /* XXX the vanilla macro does that */ + } + iov++; + } + + *csum = sum; + + return bytes; +} + + +size_t csum_and_copy_to_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i) +{ + if (bytes > i->count) + bytes = i->count; + + if (bytes == 0) + return 0; + + char *kdata = reinterpret_cast(addr); + struct iovec const *iov = i->iov; + + __wsum sum = *csum; + size_t len = bytes; + while (len > 0) { + if (iov->iov_len) { + size_t copy_len = (size_t)len < iov->iov_len ? len : iov->iov_len; + int err = 0; + __wsum next = csum_and_copy_to_user(kdata, iov->iov_base, copy_len, 0, &err); + + if (err) { + PERR("%s: err: %d - sleeping", __func__, err); + Genode::sleep_forever(); + } + + sum = csum_block_add(sum, next, bytes-len); + + len -= copy_len; + kdata += copy_len; + + i->count -= copy_len; /* XXX the vanilla macro does that */ + } + iov++; + } + + *csum = sum; + + return bytes; +} + + +/****************** + ** linux/wait.h ** + ******************/ + +void __wake_up(wait_queue_head_t *q, bool all) { } diff --git a/repos/dde_linux/src/lib/lxip/nic_handler.cc b/repos/dde_linux/src/lib/lxip/nic_handler.cc index 37768ea06..eb503c1c8 100644 --- a/repos/dde_linux/src/lib/lxip/nic_handler.cc +++ b/repos/dde_linux/src/lib/lxip/nic_handler.cc @@ -1,38 +1,103 @@ +/** + * \brief Linux emulation code + * \author Sebastian Sumpf + * \author Josef Soentgen + * \date 2013-08-28 + */ + +/* + * Copyright (C) 2013-2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ #include #include #include -#include +/* local includes */ +#include #include -#include - -enum { - MAC_LEN = 17, - ETH_ALEN = 6, -}; - -namespace Net { - class Nic; -} -class Net::Nic : public Net::Packet_handler +class Nic_client { private: enum { - PACKET_SIZE = ::Nic::Packet_allocator::DEFAULT_PACKET_SIZE, - BUF_SIZE = ::Nic::Session::QUEUE_SIZE * PACKET_SIZE, + PACKET_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE, + BUF_SIZE = Nic::Session::QUEUE_SIZE * PACKET_SIZE, }; - ::Nic::Packet_allocator _tx_block_alloc; - ::Nic::Connection _nic; + Nic::Packet_allocator _tx_block_alloc; + Nic::Connection _nic; + + Genode::Signal_dispatcher _sink_ack; + Genode::Signal_dispatcher _sink_submit; + Genode::Signal_dispatcher _source_ack; + Genode::Signal_dispatcher _source_submit; + + /** + * submit queue not empty anymore + */ + void _packet_avail(unsigned) + { + enum { MAX_PACKETS = 20 }; + + int count = 0; + while (_nic.rx()->packet_avail() && + _nic.rx()->ready_to_ack() && + count++ < MAX_PACKETS) + { + Nic::Packet_descriptor p = _nic.rx()->get_packet(); + net_driver_rx(_nic.rx()->packet_content(p), p.size()); + + _nic.rx()->acknowledge_packet(p); + } + + if (_nic.rx()->packet_avail()) + Genode::Signal_transmitter(_sink_submit).submit(); + } + + /** + * acknoledgement queue not full anymore + */ + void _ready_to_ack(unsigned num) + { + _packet_avail(num); + } + + /** + * acknoledgement queue not empty anymore + */ + void _ack_avail(unsigned) + { + while (_nic.tx()->ack_avail()) { + Nic::Packet_descriptor p = _nic.tx()->get_acked_packet(); + _nic.tx()->release_packet(p); + } + } + + /** + * submit queue not full anymore + * + * TODO: by now, we just drop packets that cannot be transferred + * to the other side, that's why we ignore this signal. + */ + void _ready_to_submit(unsigned) { } public: - Nic() - : _tx_block_alloc(Genode::env()->heap()), - _nic(&_tx_block_alloc, BUF_SIZE, BUF_SIZE) + Nic_client(Genode::Signal_receiver &sig_rec) + : + _tx_block_alloc(Genode::env()->heap()), + _nic(&_tx_block_alloc, BUF_SIZE, BUF_SIZE), + _sink_ack(sig_rec, *this, &Nic_client::_ready_to_ack), + _sink_submit(sig_rec, *this, &Nic_client::_packet_avail), + _source_ack(sig_rec, *this, &Nic_client::_ack_avail), + _source_submit(sig_rec, *this, &Nic_client::_ready_to_submit) { _nic.rx_channel()->sigh_ready_to_ack(_sink_ack); _nic.rx_channel()->sigh_packet_avail(_sink_submit); @@ -40,108 +105,58 @@ class Net::Nic : public Net::Packet_handler _nic.tx_channel()->sigh_ready_to_submit(_source_submit); } - /****************************** - ** Packet_handler interface ** - ******************************/ - - Packet_stream_sink< ::Nic::Session::Policy> * sink() { - return _nic.rx(); } - - Packet_stream_source< ::Nic::Session::Policy> * source() { - return _nic.tx(); } - - static Nic *nic() - { - static Nic _net_nic; - return &_net_nic; - } - - static ::Nic::Connection *n() - { - return &nic()->_nic; - } - + Nic::Connection *nic() { return &_nic; } }; -Net::Packet_handler::Packet_handler() -: _sink_ack(*Net::Env::receiver(), *this, &Packet_handler::_ready_to_ack), - _sink_submit(*Net::Env::receiver(), *this, &Packet_handler::_packet_avail), - _source_ack(*Net::Env::receiver(), *this, &Packet_handler::_ack_avail), - _source_submit(*Net::Env::receiver(), *this, &Packet_handler::_ready_to_submit) -{ } +static Nic_client *_nic_client; -void Net::Packet_handler::_ack_avail(unsigned) +void Lx::nic_client_init(Genode::Signal_receiver &sig_rec) { - while (source()->ack_avail()) - source()->release_packet(source()->get_acked_packet()); -} - - -void Net::Packet_handler::_ready_to_ack(unsigned num) -{ - _packet_avail(num); -} - - -void Net::Packet_handler::_packet_avail(unsigned) -{ - using namespace Net; - enum { MAX_PACKETS = 20 }; - - int count = 0; - while(Nic::n()->rx()->packet_avail() && - Nic::n()->rx()->ready_to_ack() && - count++ < MAX_PACKETS) - { - Packet_descriptor p = Nic::n()->rx()->get_packet(); - net_driver_rx(Net::Nic::n()->rx()->packet_content(p), p.size()); - Nic::n()->rx()->acknowledge_packet(p); - } - - if (Nic::n()->rx()->packet_avail()) - Genode::Signal_transmitter(_sink_submit).submit(); -} - - -static void snprint_mac(unsigned char *buf, unsigned char *mac) -{ - for (int i = 0; i < ETH_ALEN; i++) { - Genode::snprintf((char *)&buf[i * 3], 3, "%02x", mac[i]); - if ((i * 3) < MAC_LEN) - buf[(i * 3) + 2] = ':'; - } - - buf[MAC_LEN] = 0; + static Nic_client _inst(sig_rec); + _nic_client = &_inst; } +/** + * Call by back-end driver while initializing + */ void net_mac(void* mac, unsigned long size) { + enum { MAC_LEN = 17, ETH_ALEN = 6, }; + unsigned char str[MAC_LEN + 1]; using namespace Genode; - Nic::Mac_address m = Net::Nic::n()->mac_address(); + Nic::Mac_address m = _nic_client->nic()->mac_address(); Genode::memcpy(mac, &m.addr, min(sizeof(m.addr), (size_t)size)); - snprint_mac(str, (unsigned char *)m.addr); + unsigned char const *mac_addr = (unsigned char const*)m.addr; + for (int i = 0; i < ETH_ALEN; i++) { + Genode::snprintf((char *)&str[i * 3], 3, "%02x", mac_addr[i]); + if ((i * 3) < MAC_LEN) + str[(i * 3) + 2] = ':'; + } + str[MAC_LEN] = 0; + PINF("Received mac: %s", str); } +/** + * Call by back-end driver when a packet should be sent + */ int net_tx(void* addr, unsigned long len) { try { - Net::Packet_descriptor packet = Net::Nic::n()->tx()->alloc_packet(len); - void* content = Net::Nic::n()->tx()->packet_content(packet); + Nic::Packet_descriptor packet = _nic_client->nic()->tx()->alloc_packet(len); + void* content = _nic_client->nic()->tx()->packet_content(packet); Genode::memcpy((char *)content, addr, len); - Net::Nic::n()->tx()->submit_packet(packet); + _nic_client->nic()->tx()->submit_packet(packet); return 0; - /* 'Packet_alloc_failed' */ - } catch(...) { - return 1; - } + /* Packet_alloc_failed */ + } catch(...) { return 1; } } diff --git a/repos/dde_linux/src/lib/lxip/socket.c b/repos/dde_linux/src/lib/lxip/socket.c deleted file mode 100644 index f4a02cf06..000000000 --- a/repos/dde_linux/src/lib/lxip/socket.c +++ /dev/null @@ -1,115 +0,0 @@ -/** - * \brief BSD style socket helpers - * \author Sebastian Sumpf - * \date 2013-08-28 - */ - -/* - * Copyright (C) 2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ -#include -#include -#include - -#include - -static const struct net_proto_family *net_families[NPROTO]; - - -int sock_register(const struct net_proto_family *ops) -{ - if (ops->family >= NPROTO) { - printk("protocol %d >= NPROTO (%d)\n", ops->family, NPROTO); - return -ENOBUFS; - } - - net_families[ops->family] = ops; - pr_info("NET: Registered protocol family %d\n", ops->family); - return 0; -} - - -struct socket *sock_alloc(void) -{ - return (struct socket *)kmalloc(sizeof(struct socket), 0); -} - - -int sock_create_lite(int family, int type, int protocol, struct socket **res) - -{ - struct socket *sock = sock_alloc(); - - if (!sock) - return -ENOMEM; - - sock->type = type; - *res = sock; - return 0; -} - - -int sock_create_kern(int family, int type, int proto, - struct socket **res) -{ - struct socket *sock; - const struct net_proto_family *pf; - int err; - - if (family < 0 || family > NPROTO) - return -EAFNOSUPPORT; - - if (type < 0 || type > SOCK_MAX) - return -EINVAL; - - pf = net_families[family]; - - if (!pf) { - printk("No protocol found for family %d\n", family); - return -ENOPROTOOPT; - } - - if (!(sock = (struct socket *)kzalloc(sizeof(struct socket), 0))) { - printk("Could not allocate socket\n"); - return -ENFILE; - } - - sock->type = type; - - err = pf->create(&init_net, sock, proto, 1); - if (err) { - kfree(sock); - return err; - } - - *res = sock; - - return 0; -} - - -int socket_check_state(struct socket *socket) -{ - if (socket->sk->sk_state == TCP_CLOSE_WAIT) - return -EINTR; - - return 0; -} - - -void log_sock(struct socket *socket) -{ - printk("\nNEW socket %p sk %p fsk %x &sk %p &fsk %p\n\n", - socket, socket->sk, socket->flags, &socket->sk, &socket->flags); -} - - -static void sock_init(void) -{ - skb_init(); -} - -core_initcall(sock_init); diff --git a/repos/dde_linux/src/lib/lxip/socket_handler.cc b/repos/dde_linux/src/lib/lxip/socket_handler.cc index 59d7c76fe..fcc0a6c67 100644 --- a/repos/dde_linux/src/lib/lxip/socket_handler.cc +++ b/repos/dde_linux/src/lib/lxip/socket_handler.cc @@ -5,29 +5,31 @@ */ /* - * Copyright (C) 2013 Genode Labs GmbH + * Copyright (C) 2013-2016 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. */ + +/* Genode includes */ #include #include #include #include +/* local includes */ #include -#include -#include +#include #include -extern "C" void wait_for_continue(); static const bool verbose = false; namespace Linux { - #include #include + + #include #include #include extern int sock_setsockopt(struct socket *sock, int level, @@ -36,7 +38,8 @@ namespace Linux { extern int sock_getsockopt(struct socket *sock, int level, int op, char __user *optval, int __user *optlen); - #include + struct socket *sock_alloc(void); + #include } namespace Net @@ -105,7 +108,6 @@ namespace Net int err; Lxip::ssize_t len; }; - }; @@ -120,8 +122,9 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, Result _result; Lxip::Handle _handle; - Genode::Signal_transmitter _signal; - Genode::Semaphore _block; + Genode::Signal_receiver &_sig_rec; + Genode::Signal_transmitter _signal; + Genode::Semaphore _block; void _submit_and_block() { @@ -169,8 +172,8 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, { using namespace Linux; - struct socket *sock = call_socket(); - struct socket *new_sock = (struct socket *)kzalloc(sizeof(struct socket), 0); + struct socket *sock = call_socket(); + struct socket *new_sock = sock_alloc(); _handle.socket = 0; @@ -187,7 +190,6 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, _handle.socket = static_cast(new_sock); - if (!_call.accept.addr) return; @@ -216,6 +218,7 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, if (s->ops) s->ops->release(s); + kfree(s->wq); kfree(s); } @@ -299,10 +302,12 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, struct msghdr msg; struct iovec iov; - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_iovlen = 1; - msg.msg_iov = &iov; + msg.msg_control = nullptr; + msg.msg_controllen = 0; + msg.msg_iter.iov = &iov; + msg.msg_iter.nr_segs = 1; + msg.msg_iter.count = _call.msg.len; + iov.iov_len = _call.msg.len; iov.iov_base = _call.msg.buf; msg.msg_name = _call.addr_len ? &_call.addr : 0; @@ -313,7 +318,7 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, msg.msg_flags |= MSG_DONTWAIT; //XXX: check for non-blocking flag - _result.len = call_socket()->ops->recvmsg(0, call_socket(), &msg, + _result.len = call_socket()->ops->recvmsg(call_socket(), &msg, _call.msg.len, _call.msg.flags); @@ -333,10 +338,12 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, if (_result.len < 0) return; - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_iovlen = 1; - msg.msg_iov = &iov; + msg.msg_control = nullptr; + msg.msg_controllen = 0; + msg.msg_iter.iov = &iov; + msg.msg_iter.nr_segs = 1; + msg.msg_iter.count = _call.msg.len; + iov.iov_len = _call.msg.len; iov.iov_base = _call.msg.buf; msg.msg_name = _call.addr_len ? &_call.addr : 0; @@ -346,7 +353,7 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, if (_call.handle.non_block) msg.msg_flags |= MSG_DONTWAIT; - _result.len = call_socket()->ops->sendmsg(0, call_socket(), &msg, + _result.len = call_socket()->ops->sendmsg(call_socket(), &msg, _call.msg.len); } @@ -370,32 +377,34 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, int type = _call.socket.type == Lxip::TYPE_STREAM ? SOCK_STREAM : SOCK_DGRAM; - struct socket *s = (struct socket *)kzalloc(sizeof(struct socket), 0); + struct socket *s = sock_alloc(); - if (!sock_create_kern(AF_INET, type, 0, &s)) { - _handle.socket = static_cast(s); + if (sock_create_kern(nullptr, AF_INET, type, 0, &s)) { + _handle.socket = 0; + kfree(s); return; } - _handle.socket = 0; - kfree(s); + _handle.socket = static_cast(s); } public: - Socketcall() - : Thread_deprecated("socketcall"), - _signal(Genode::Signal_context_capability(Env::receiver()->manage(this))) + Socketcall(Genode::Signal_receiver &sig_rec) + : + Thread_deprecated("socketcall"), + _sig_rec(sig_rec), + _signal(Genode::Signal_context_capability(_sig_rec.manage(this))) { start(); } - ~Socketcall() { Env::receiver()->dissolve(this); } + ~Socketcall() { _sig_rec.dissolve(this); } void entry() { while (true) { - Genode::Signal s = Net::Env::receiver()->wait_for_signal(); + Genode::Signal s = _sig_rec.wait_for_signal(); static_cast(s.context())->dispatch(s.num()); } } @@ -626,10 +635,16 @@ class Net::Socketcall : public Genode::Signal_dispatcher_base, }; -Lxip::Socketcall & Lxip::init(char *address_config) +Lxip::Socketcall & Lxip::init(char const *address_config) { - static int init = lxip_init(address_config); - static Net::Socketcall socketcall; + static Genode::Signal_receiver sig_rec; + + Lx::timer_init(sig_rec); + Lx::event_init(sig_rec); + Lx::nic_client_init(sig_rec); + + static int init = lxip_init(address_config); + static Net::Socketcall socketcall(sig_rec); return socketcall; } diff --git a/repos/dde_linux/src/lib/lxip/timer_handler.cc b/repos/dde_linux/src/lib/lxip/timer_handler.cc index 389c8a87a..e6a60a236 100644 --- a/repos/dde_linux/src/lib/lxip/timer_handler.cc +++ b/repos/dde_linux/src/lib/lxip/timer_handler.cc @@ -5,12 +5,13 @@ */ /* - * Copyright (C) 2012-2013 Genode Labs GmbH + * Copyright (C) 2012-2016 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. */ +/* Genode includes */ #include #include #include @@ -18,13 +19,12 @@ #include #include -#include +/* Linux kit includes */ +#include + +/* local includes */ #include -#include - -#include - -#include +#include /********************* @@ -33,8 +33,6 @@ unsigned long jiffies; -unsigned long msecs_to_jiffies(const unsigned int m) { return m / (1000 / HZ); } - /** * Lx::Timer */ @@ -49,7 +47,7 @@ class Lx::Timer /** * Context encapsulates a regular linux timer_list */ - struct Context : public Lx::List::Element + struct Context : public Lx_kit::List::Element { enum { INVALID_TIMEOUT = ~0UL }; enum Type { LIST }; @@ -86,7 +84,7 @@ class Lx::Timer private: ::Timer::Connection _timer_conn; - Lx::List _list; + Lx_kit::List _list; Genode::Signal_dispatcher _dispatcher; Genode::Tslab _timer_alloc; @@ -187,9 +185,9 @@ class Lx::Timer /** * Constructor */ - Timer() + Timer(Genode::Signal_receiver &sig_rec) : - _dispatcher(*Net::Env::receiver(), *this, &Lx::Timer::_handle), + _dispatcher(sig_rec, *this, &Lx::Timer::_handle), _timer_alloc(Genode::env()->heap()) { _timer_conn.sigh(_dispatcher); @@ -283,19 +281,22 @@ class Lx::Timer * Get first timer context */ Context* first() { return _list.first(); } - - static Timer &t() - { - static Lx::Timer _t; - return _t; - } - }; +static Lx::Timer *_timer; + + +void Lx::timer_init(Genode::Signal_receiver &sig_rec) +{ + static Lx::Timer inst(sig_rec); + _timer = &inst; +} + + void update_jiffies() { - Lx::Timer::t().update_jiffies(); + _timer->update_jiffies(); } @@ -305,6 +306,7 @@ void update_jiffies() void init_timer(struct timer_list *timer) { } + void add_timer(struct timer_list *timer) { BUG_ON(timer_pending(timer)); @@ -312,15 +314,14 @@ void add_timer(struct timer_list *timer) } - int mod_timer(struct timer_list *timer, unsigned long expires) { update_jiffies(); - if (!Lx::Timer::t().find(timer)) - Lx::Timer::t().add(timer); + if (!_timer->find(timer)) + _timer->add(timer); - return Lx::Timer::t().schedule(timer, expires); + return _timer->schedule(timer, expires); } @@ -334,7 +335,7 @@ void setup_timer(struct timer_list *timer,void (*function)(unsigned long), int timer_pending(const struct timer_list * timer) { - bool pending = Lx::Timer::t().pending(timer); + bool pending = _timer->pending(timer); lx_log(DEBUG_TIMER, "Pending %p %u", timer, pending); return pending; } @@ -344,10 +345,8 @@ int del_timer(struct timer_list *timer) { update_jiffies(); lx_log(DEBUG_TIMER, "Delete timer %p", timer); - int rv = Lx::Timer::t().del(timer); - Lx::Timer::t().schedule_next(); + int rv = _timer->del(timer); + _timer->schedule_next(); return rv; } - - diff --git a/repos/dde_linux/src/test/lxip/http_srv/main.cc b/repos/dde_linux/src/test/lxip/http_srv/main.cc new file mode 100644 index 000000000..a8fd52f29 --- /dev/null +++ b/repos/dde_linux/src/test/lxip/http_srv/main.cc @@ -0,0 +1,103 @@ +/* + * \brief Minimal HTTP server demonstration using socket API + * \author Josef Soentgen + * \date 2016-03-22 + */ + +/* + * Copyright (C) 2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ +#include + +/* libc includes */ +#include +#include +#include +#include +#include + + +const static char http_html_hdr[] = + "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"; /* HTTP response header */ + +const static char http_index_html[] = + "Congrats!

Welcome to our HTTP demonstration server!

This is a small test page."; /* HTML page */ + +static void serve(int fd) { + char buf[1024]; + ssize_t buflen; + + /* Read the data from the port, blocking if nothing yet there. + We assume the request (the part we care about) is in one packet */ + buflen = recv(fd, buf, 1024, 0); + // PLOG("Packet received!"); + + /* Ignore all receive errors */ + if (buflen > 0) { + + /* Is this an HTTP GET command? (only check the first 5 chars, since + there are other formats for GET, and we're keeping it very simple)*/ + if (buflen >= 5 && + buf[0] == 'G' && + buf[1] == 'E' && + buf[2] == 'T' && + buf[3] == ' ' && + buf[4] == '/' ) { + + // PLOG("Will send response"); + + /* Send http header */ + send(fd, http_html_hdr, sizeof(http_html_hdr), 0); + + /* Send our HTML page */ + send(fd, http_index_html, sizeof(http_index_html), 0); + } + } +} + + +int main() +{ + int s; + + PLOG("Create new socket ..."); + if((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + PERR("No socket available!"); + return -1; + } + + PLOG("Now, I will bind ..."); + struct sockaddr_in in_addr; + in_addr.sin_family = AF_INET; + in_addr.sin_port = htons(80); + in_addr.sin_addr.s_addr = INADDR_ANY; + if(bind(s, (struct sockaddr*)&in_addr, sizeof(in_addr))) { + PERR("bind failed!"); + return -1; + } + + PLOG("Now, I will listen ..."); + if(listen(s, 5)) { + PERR("listen failed!"); + return -1; + } + + PLOG("Start the server loop ..."); + while(true) { + struct sockaddr addr; + socklen_t len = sizeof(addr); + int client = accept(s, &addr, &len); + if(client < 0) { + PWRN("Invalid socket from accept!"); + continue; + } + serve(client); + close(client); + } + return 0; +} diff --git a/repos/dde_linux/src/test/lxip/http_srv/target.mk b/repos/dde_linux/src/test/lxip/http_srv/target.mk new file mode 100644 index 000000000..37896276b --- /dev/null +++ b/repos/dde_linux/src/test/lxip/http_srv/target.mk @@ -0,0 +1,3 @@ +TARGET = test-lxip_http_srv +LIBS = libc libc_lxip +SRC_CC = main.cc diff --git a/repos/dde_linux/src/test/lxip/udp_echo/main.cc b/repos/dde_linux/src/test/lxip/udp_echo/main.cc new file mode 100644 index 000000000..ef90669ee --- /dev/null +++ b/repos/dde_linux/src/test/lxip/udp_echo/main.cc @@ -0,0 +1,72 @@ +/* + * \brief Minimal datagram server demonstration using socket API + * \author Josef Soentgen + * \date 2016-04-22 + */ + +/* + * Copyright (C) 2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ +#include + +/* libc includes */ +#include +#include +#include +#include +#include +#include + + +int main(void) +{ + int s; + + PLOG("Create new socket ..."); + if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + PERR("No socket available!"); + return -1; + } + + PLOG("Now, I will bind ..."); + struct sockaddr_in in_addr; + in_addr.sin_family = AF_INET; + in_addr.sin_port = htons(1337); + in_addr.sin_addr.s_addr = INADDR_ANY; + if(bind(s, (struct sockaddr*)&in_addr, sizeof(in_addr))) { + PERR("bind failed!"); + return -1; + } + + PLOG("Start the server loop ..."); + while(true) { + struct sockaddr_in addr; + addr.sin_family = AF_INET; + socklen_t len = sizeof(addr); + + char buf[4096]; + memset(buf, 0, sizeof(buf)); + + ssize_t n = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&addr, &len); + + if (n == 0) { + PWRN("Invalid request!"); + continue; + } + + if (n < 0) { + PERR("Error %lld", n); + break; + } + + PLOG("Received %lld bytes", n); + n = sendto(s, buf, n, 0, (struct sockaddr*)&addr, len); + PLOG("Send %lld bytes back", n); + } + return 0; +} diff --git a/repos/dde_linux/src/test/lxip/udp_echo/target.mk b/repos/dde_linux/src/test/lxip/udp_echo/target.mk new file mode 100644 index 000000000..7e8a97b9c --- /dev/null +++ b/repos/dde_linux/src/test/lxip/udp_echo/target.mk @@ -0,0 +1,3 @@ +TARGET = test-lxip_udp_echo +LIBS = libc libc_lxip +SRC_CC = main.cc