diff --git a/Android.common.mk b/Android.common.mk new file mode 100644 index 000000000000..7366f5c54fb1 --- /dev/null +++ b/Android.common.mk @@ -0,0 +1,110 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +ifndef NODE_PREFIX + NODE_PREFIX := $(LOCAL_PATH) +endif + +include $(CLEAR_VARS) + +intermediates := $(LOCAL_PATH)/out/$(APP_OPTIM) + +include $(LOCAL_PATH)/Android.jsnatives.mk +src/node_javascript.cc : $(jsnatives) + +LOCAL_MODULE := node + +LOCAL_CPP_EXTENSION := .cc + +LOCAL_C_INCLUDES += \ + $(intermediates)/src \ + $(LOCAL_PATH)/src + +LOCAL_SRC_FILES := \ + src/node.cc \ + src/node_buffer.cc \ + src/node_constants.cc \ + src/node_crypto.cc \ + src/node_dtrace.cc \ + src/node_extensions.cc \ + src/node_file.cc \ + src/node_http_parser.cc \ + src/node_io_watcher.cc \ + src/node_javascript.cc \ + src/node_main.cc \ + src/node_os.cc \ + src/node_script.cc \ + src/node_signal_watcher.cc \ + src/node_stat_watcher.cc \ + src/node_string.cc \ + src/node_zlib.cc \ + src/cares_wrap.cc \ + src/fs_event_wrap.cc \ + src/handle_wrap.cc \ + src/pipe_wrap.cc \ + src/process_wrap.cc \ + src/stream_wrap.cc \ + src/tcp_wrap.cc \ + src/timer_wrap.cc \ + src/tty_wrap.cc \ + src/udp_wrap.cc \ + src/v8_typed_array.cc \ + src/platform_android.cc + +LOCAL_SHARED_LIBRARIES += \ + crypto \ + ssl + +LOCAL_STATIC_LIBRARIES := \ + http_parser \ + uv \ + v8 \ + pty + +# debug +ifeq ($(debug),true) +LOCAL_CFLAGS += \ + -DDEBUG \ + -g \ + -O0 \ + -Wall \ + -Wextra +endif + +# common flags +LOCAL_CFLAGS += \ + -D__POSIX__ \ + -DX_STACKSIZE=65536 \ + -D_LARGEFILE_SOURCE \ + -D_FILE_OFFSET_BITS=64 \ + -DHAVE_FDATASYNC=1 \ + -DHAVE_MONOTONIC_CLOCK \ + -D_FORTIFY_SOURCE=2 \ + -DPLATFORM=\"android\" \ + -DARCH=\"arch-arm\" \ + -Wno-unused-parameter + +# node +LOCAL_CFLAGS += \ + -DHAVE_OPENSSL \ + -DNODE_CFLAGS=\"\" \ + -DNODE_PREFIX=\"$(NODE_PREFIX)\" \ + -include sys/select.h + +# ev +LOCAL_CFLAGS += \ + -DEV_FORK_ENABLE=0 \ + -DEV_EMBED_ENABLE=0 \ + -DEV_MULTIPLICITY=0 diff --git a/Android.exe.mk b/Android.exe.mk new file mode 100644 index 000000000000..af2b0fe521fc --- /dev/null +++ b/Android.exe.mk @@ -0,0 +1,34 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +LOCAL_PATH := $(call my-dir) +include $(LOCAL_PATH)/Android.common.mk + +LOCAL_SHARED_LIBRARIES += \ + crypto \ + ssl + +LOCAL_STATIC_LIBRARIES := \ + uv \ + http_parser \ + v8 \ + pty + +include $(BUILD_EXECUTABLE) + +$(call import-module,deps/http_parser) +$(call import-module,deps/uv) +$(call import-module,deps/v8) +$(call import-module,pty) +$(call import-module,openssl-android) diff --git a/Android.jsnatives.mk b/Android.jsnatives.mk new file mode 100644 index 000000000000..481450ffb750 --- /dev/null +++ b/Android.jsnatives.mk @@ -0,0 +1,55 @@ +NODE_LOCAL_JS_LIBRARY_FILES := \ + src/node.js \ + lib/_debugger.js \ + lib/_linklist.js \ + lib/assert.js \ + lib/buffer.js \ + lib/buffer_ieee754.js \ + lib/child_process.js \ + lib/cluster.js \ + lib/console.js \ + lib/constants.js \ + lib/crypto.js \ + lib/dgram.js \ + lib/dns.js \ + lib/events.js \ + lib/freelist.js \ + lib/fs.js \ + lib/http.js \ + lib/https.js \ + lib/module.js \ + lib/net.js \ + lib/os.js \ + lib/path.js \ + lib/punycode.js \ + lib/querystring.js \ + lib/readline.js \ + lib/repl.js \ + lib/stream.js \ + lib/string_decoder.js \ + lib/sys.js \ + lib/timers.js \ + lib/tls.js \ + lib/tty.js \ + lib/url.js \ + lib/util.js \ + lib/vm.js \ + lib/zlib.js \ + macros.py + +PATH_LOCAL_JS_LIBRARY_FILES := $(addprefix $(LOCAL_PATH)/, $(NODE_LOCAL_JS_LIBRARY_FILES)) + +# FIXME: Copy js2c.py to intermediates directory and invoke there to avoid generating +# jsmin.pyc in the source directory +#JS2C_PY := $(intermediates)/js2c.py $(intermediates)/jsmin.py +#$(JS2C_PY): $(intermediates)/%.py : $(LOCAL_PATH)/tools/%.py | $(ACP) +# @echo "Copying $@" +# $(copy-file-to-target) + +# Generate node_natives.h +jsnatives := $(intermediates)/src/node_natives.h +$(jsnatives): SCRIPT := tools/js2c.py +$(jsnatives): $(PATH_LOCAL_JS_LIBRARY_FILES) $(JS2C_PY) + @echo "Building node_natives.h" + @mkdir -p $(dir $@) + python $(SCRIPT) $(jsnatives) $(PATH_LOCAL_JS_LIBRARY_FILES) diff --git a/Android.mk b/Android.mk new file mode 100644 index 000000000000..069005b914c6 --- /dev/null +++ b/Android.mk @@ -0,0 +1,32 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This file builds a static library suitable for inclusion in a +# shared library (eg for JNI). + +LOCAL_PATH := $(call my-dir) +include $(LOCAL_PATH)/Android.common.mk + +LOCAL_SRC_FILES += src/lib_wrapper.cc + +# to override exit handling in node.cc +LOCAL_CFLAGS += -D__LIBNODE__ + +include $(BUILD_STATIC_LIBRARY) + +$(call import-module,deps/http_parser) +$(call import-module,deps/uv) +$(call import-module,deps/v8) +$(call import-module,pty) +$(call import-module,openssl-android) diff --git a/deps/http_parser/Android.mk b/deps/http_parser/Android.mk new file mode 100644 index 000000000000..befea8995454 --- /dev/null +++ b/deps/http_parser/Android.mk @@ -0,0 +1,48 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := http_parser + +LOCAL_SRC_FILES := http_parser.c + +# debug +ifeq ($(debug),true) +LOCAL_CFLAGS += \ + -DHTTP_PARSER_STRICT=1 \ + -DDEBUG \ + -g \ + -O0 \ + -Wall \ + -Wextra +endif + +# common flags +LOCAL_CFLAGS += \ + -D__POSIX__ \ + -DX_STACKSIZE=65536 \ + -D_LARGEFILE_SOURCE \ + -D_FILE_OFFSET_BITS=64 \ + -DHAVE_FDATASYNC=1 \ + -D_FORTIFY_SOURCE=2 \ + -DPLATFORM=\"android\" \ + -Wno-unused-parameter + +LOCAL_EXPORT_C_INCLUDES := \ + $(LOCAL_PATH) + +include $(BUILD_STATIC_LIBRARY) diff --git a/deps/uv/Android.mk b/deps/uv/Android.mk new file mode 100644 index 000000000000..28ad9b566da8 --- /dev/null +++ b/deps/uv/Android.mk @@ -0,0 +1,132 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := uv + +LOCAL_C_INCLUDES += \ + $(LOCAL_PATH)/include \ + $(LOCAL_PATH)/include/uv-private \ + $(LOCAL_PATH)/src \ + $(LOCAL_PATH)/src/ares/config_android + +LOCAL_SRC_FILES := \ + src/uv-common.c \ + src/ares/ares__close_sockets.c \ + src/ares/ares__get_hostent.c \ + src/ares/ares__read_line.c \ + src/ares/ares__timeval.c \ + src/ares/ares_cancel.c \ + src/ares/ares_data.c \ + src/ares/ares_destroy.c \ + src/ares/ares_expand_name.c \ + src/ares/ares_expand_string.c \ + src/ares/ares_fds.c \ + src/ares/ares_free_hostent.c \ + src/ares/ares_free_string.c \ + src/ares/ares_gethostbyaddr.c \ + src/ares/ares_gethostbyname.c \ + src/ares/ares_getnameinfo.c \ + src/ares/ares_getopt.c \ + src/ares/ares_getsock.c \ + src/ares/ares_init.c \ + src/ares/ares_library_init.c \ + src/ares/ares_llist.c \ + src/ares/ares_mkquery.c \ + src/ares/ares_nowarn.c \ + src/ares/ares_options.c \ + src/ares/ares_parse_a_reply.c \ + src/ares/ares_parse_aaaa_reply.c \ + src/ares/ares_parse_mx_reply.c \ + src/ares/ares_parse_ns_reply.c \ + src/ares/ares_parse_ptr_reply.c \ + src/ares/ares_parse_srv_reply.c \ + src/ares/ares_parse_txt_reply.c \ + src/ares/ares_process.c \ + src/ares/ares_query.c \ + src/ares/ares_search.c \ + src/ares/ares_send.c \ + src/ares/ares_strcasecmp.c \ + src/ares/ares_strdup.c \ + src/ares/ares_strerror.c \ + src/ares/ares_timeout.c \ + src/ares/ares_version.c \ + src/ares/ares_writev.c \ + src/ares/bitncmp.c \ + src/ares/inet_net_pton.c \ + src/ares/inet_ntop.c \ + src/unix/cares.c \ + src/unix/core.c \ + src/unix/error.c \ + src/unix/fs.c \ + src/unix/linux.c \ + src/unix/pipe.c \ + src/unix/process.c \ + src/unix/stream.c \ + src/unix/tcp.c \ + src/unix/tty.c \ + src/unix/udp.c \ + src/unix/uv-eio.c \ + src/unix/eio/eio.c \ + src/unix/ev/ev.c + +# debug +ifeq ($(debug),true) +LOCAL_CFLAGS += \ + -DDEBUG \ + -g \ + -O0 \ + -Wall \ + -Wextra +endif + +# ares +LOCAL_CFLAGS += \ + -DHAVE_CONFIG_H \ + -include sys/select.h + +# eio +LOCAL_CFLAGS += \ + -DHAVE_PREADWRITE=1 \ + -DHAVE_SENDFILE \ + -D_GNU_SOURCE \ + -DHAVE_UTIMES + +# ev +LOCAL_CFLAGS += \ + -DEV_FORK_ENABLE=0 \ + -DEV_EMBED_ENABLE=0 \ + -DHAVE_SELECT \ + -DHAVE_SYS_SELECT_H \ + -DEV_SELECT_USE_FD_SET \ + -DEV_STANDALONE + +# common flags +LOCAL_CFLAGS += \ + -D__POSIX__ \ + -DEIO_STACKSIZE=65536 \ + -D_LARGEFILE_SOURCE \ + -D_FILE_OFFSET_BITS=64 \ + -DHAVE_FDATASYNC=1 \ + -D_FORTIFY_SOURCE=2 \ + -DPLATFORM=\"android\" \ + -Wno-unused-parameter + +LOCAL_EXPORT_C_INCLUDES := \ + $(LOCAL_PATH)/include + +include $(BUILD_STATIC_LIBRARY) diff --git a/deps/uv/src/ares/config_android/ares_config.h b/deps/uv/src/ares/config_android/ares_config.h new file mode 100644 index 000000000000..6fc1b0079591 --- /dev/null +++ b/deps/uv/src/ares/config_android/ares_config.h @@ -0,0 +1,512 @@ +/* ares_config.h. Generated from ares_config.h.in by configure. */ +/* ares_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* define this if ares is built for a big endian system */ +/* #undef ARES_BIG_ENDIAN */ + +/* when building as static part of libcurl */ +/* #undef BUILDING_LIBCURL */ + +/* when building c-ares library */ +/* #undef CARES_BUILDING_LIBRARY */ + +/* when not building a shared library */ +/* #undef CARES_STATICLIB */ + +/* Define to 1 to enable hiding of library internal symbols. */ +#define CARES_SYMBOL_HIDING 1 + +/* Definition to make a library symbol externally visible. */ +#define CARES_SYMBOL_SCOPE_EXTERN __attribute__ ((visibility ("default"))) + +/* if a /etc/inet dir is being used */ +/* #undef ETC_INET */ + +/* Define to the type qualifier of arg 1 for getnameinfo. */ +#define GETNAMEINFO_QUAL_ARG1 const + +/* Define to the type of arg 1 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG1 struct sockaddr * + +/* Define to the type of arg 2 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG2 socklen_t + +/* Define to the type of args 4 and 6 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG46 size_t + +/* Define to the type of arg 7 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG7 unsigned int + +/* Specifies the number of arguments to getservbyport_r */ +#define GETSERVBYPORT_R_ARGS 6 + +/* Specifies the size of the buffer to pass to getservbyport_r */ +#define GETSERVBYPORT_R_BUFSIZE 4096 + +/* Define to 1 if you have AF_INET6. */ +#define HAVE_AF_INET6 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +/* #define HAVE_ARPA_NAMESER_COMPAT_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #define HAVE_ARPA_NAMESER_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the `bitncmp' function. */ +/* #undef HAVE_BITNCMP */ + +/* Define to 1 if bool is an available type. */ +#define HAVE_BOOL_T 1 + +/* Define to 1 if you have the clock_gettime function and monotonic timer. */ +#define HAVE_CLOCK_GETTIME_MONOTONIC 1 + +/* Define to 1 if you have the closesocket function. */ +/* #undef HAVE_CLOSESOCKET */ + +/* Define to 1 if you have the CloseSocket camel case function. */ +/* #undef HAVE_CLOSESOCKET_CAMEL */ + +/* Define to 1 if you have the connect function. */ +#define HAVE_CONNECT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the fcntl function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have a working fcntl O_NONBLOCK function. */ +#define HAVE_FCNTL_O_NONBLOCK 1 + +/* Define to 1 if you have the freeaddrinfo function. */ +#define HAVE_FREEADDRINFO 1 + +/* Define to 1 if you have a working getaddrinfo function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if the getaddrinfo function is threadsafe. */ +#define HAVE_GETADDRINFO_THREADSAFE 1 + +/* Define to 1 if you have the gethostbyaddr function. */ +#define HAVE_GETHOSTBYADDR 1 + +/* Define to 1 if you have the gethostbyname function. */ +#define HAVE_GETHOSTBYNAME 1 + +/* Define to 1 if you have the gethostname function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the getnameinfo function. */ +#define HAVE_GETNAMEINFO 1 + +/* Define to 1 if you have the getservbyport_r function. */ +#define HAVE_GETSERVBYPORT_R 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `if_indextoname' function. */ +#define HAVE_IF_INDEXTONAME 1 + +/* Define to 1 if you have the `inet_net_pton' function. */ +/* #undef HAVE_INET_NET_PTON */ + +/* Define to 1 if inet_net_pton supports IPv6. */ +/* #undef HAVE_INET_NET_PTON_IPV6 */ + +/* Define to 1 if you have a IPv6 capable working inet_ntop function. */ +#define HAVE_INET_NTOP 1 + +/* Define to 1 if you have a IPv6 capable working inet_pton function. */ +#define HAVE_INET_PTON 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the ioctl function. */ +#define HAVE_IOCTL 1 + +/* Define to 1 if you have the ioctlsocket function. */ +/* #undef HAVE_IOCTLSOCKET */ + +/* Define to 1 if you have the IoctlSocket camel case function. */ +/* #undef HAVE_IOCTLSOCKET_CAMEL */ + +/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function. + */ +/* #undef HAVE_IOCTLSOCKET_CAMEL_FIONBIO */ + +/* Define to 1 if you have a working ioctlsocket FIONBIO function. */ +/* #undef HAVE_IOCTLSOCKET_FIONBIO */ + +/* Define to 1 if you have a working ioctl FIONBIO function. */ +#define HAVE_IOCTL_FIONBIO 1 + +/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */ +#define HAVE_IOCTL_SIOCGIFADDR 1 + +/* Define to 1 if you have the `resolve' library (-lresolve). */ +/* #undef HAVE_LIBRESOLVE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* if your compiler supports LL */ +#define HAVE_LL 1 + +/* Define to 1 if the compiler supports the 'long long' data type. */ +#define HAVE_LONGLONG 1 + +/* Define to 1 if you have the malloc.h header file. */ +#define HAVE_MALLOC_H 1 + +/* Define to 1 if you have the memory.h header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the MSG_NOSIGNAL flag. */ +#define HAVE_MSG_NOSIGNAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NET_IF_H 1 + +/* Define to 1 if you have PF_INET6. */ +#define HAVE_PF_INET6 1 + +/* Define to 1 if you have the recv function. */ +#define HAVE_RECV 1 + +/* Define to 1 if you have the recvfrom function. */ +#define HAVE_RECVFROM 1 + +/* Define to 1 if you have the send function. */ +#define HAVE_SEND 1 + +/* Define to 1 if you have the setsockopt function. */ +#define HAVE_SETSOCKOPT 1 + +/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */ +/* #undef HAVE_SETSOCKOPT_SO_NONBLOCK */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if sig_atomic_t is an available typedef. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if sig_atomic_t is already defined as volatile. */ +/* #undef HAVE_SIG_ATOMIC_T_VOLATILE */ + +/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */ +#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 + +/* Define to 1 if you have the socket function. */ +#define HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SOCKET_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the strcasecmp function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the strcmpi function. */ +/* #undef HAVE_STRCMPI */ + +/* Define to 1 if you have the strdup function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the stricmp function. */ +/* #undef HAVE_STRICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the strncasecmp function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the strncmpi function. */ +/* #undef HAVE_STRNCMPI */ + +/* Define to 1 if you have the strnicmp function. */ +/* #undef HAVE_STRNICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STROPTS_H 1 + +/* Define to 1 if you have struct addrinfo. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if you have struct in6_addr. */ +#define HAVE_STRUCT_IN6_ADDR 1 + +/* Define to 1 if you have struct sockaddr_in6. */ +#define HAVE_STRUCT_SOCKADDR_IN6 1 + +/* if struct sockaddr_storage is defined */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if you have the timeval struct. */ +#define HAVE_STRUCT_TIMEVAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the windows.h header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the winsock2.h header file. */ +/* #undef HAVE_WINSOCK2_H */ + +/* Define to 1 if you have the winsock.h header file. */ +/* #undef HAVE_WINSOCK_H */ + +/* Define to 1 if you have the writev function. */ +#define HAVE_WRITEV 1 + +/* Define to 1 if you have the ws2tcpip.h header file. */ +/* #undef HAVE_WS2TCPIP_H */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if you are building a native Windows target. */ +/* #undef NATIVE_WINDOWS */ + +/* Define to 1 if you need the malloc.h header file even with stdlib.h */ +/* #undef NEED_MALLOC_H */ + +/* Define to 1 if you need the memory.h header file even with stdlib.h */ +/* #undef NEED_MEMORY_H */ + +/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */ +/* #undef NEED_REENTRANT */ + +/* Define to 1 if _THREAD_SAFE preprocessor symbol must be defined. */ +/* #undef NEED_THREAD_SAFE */ + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* cpu-machine-OS */ +#define OS "i686-pc-linux-gnu" + +/* Name of package */ +#define PACKAGE "c-ares" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "c-ares mailing list => http://cool.haxx.se/mailman/listinfo/c-ares" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "c-ares" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "c-ares 1.7.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "c-ares" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.7.1" + +/* a suitable file/device to read random data from */ +#define RANDOM_FILE "/dev/urandom" + +/* Define to the type of arg 1 for recvfrom. */ +#define RECVFROM_TYPE_ARG1 int + +/* Define to the type pointed by arg 2 for recvfrom. */ +#define RECVFROM_TYPE_ARG2 void + +/* Define to 1 if the type pointed by arg 2 for recvfrom is void. */ +#define RECVFROM_TYPE_ARG2_IS_VOID 1 + +/* Define to the type of arg 3 for recvfrom. */ +#define RECVFROM_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recvfrom. */ +#define RECVFROM_TYPE_ARG4 int + +/* Define to the type pointed by arg 5 for recvfrom. */ +#define RECVFROM_TYPE_ARG5 struct sockaddr + +/* Define to 1 if the type pointed by arg 5 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG5_IS_VOID */ + +/* Define to the type pointed by arg 6 for recvfrom. */ +#define RECVFROM_TYPE_ARG6 socklen_t + +/* Define to 1 if the type pointed by arg 6 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG6_IS_VOID */ + +/* Define to the function return type for recvfrom. */ +#define RECVFROM_TYPE_RETV int + +/* Define to the type of arg 1 for recv. */ +#define RECV_TYPE_ARG1 int + +/* Define to the type of arg 2 for recv. */ +#define RECV_TYPE_ARG2 void * + +/* Define to the type of arg 3 for recv. */ +#define RECV_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recv. */ +#define RECV_TYPE_ARG4 int + +/* Define to the function return type for recv. */ +#define RECV_TYPE_RETV int + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* Define to the type qualifier of arg 2 for send. */ +#define SEND_QUAL_ARG2 const + +/* Define to the type of arg 1 for send. */ +#define SEND_TYPE_ARG1 int + +/* Define to the type of arg 2 for send. */ +#define SEND_TYPE_ARG2 void * + +/* Define to the type of arg 3 for send. */ +#define SEND_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for send. */ +#define SEND_TYPE_ARG4 int + +/* Define to the function return type for send. */ +#define SEND_TYPE_RETV int + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 4 + +/* The size of `struct in6_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN6_ADDR 16 + +/* The size of `struct in_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN_ADDR 4 + +/* The size of `time_t', as computed by sizeof. */ +#define SIZEOF_TIME_T 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Define to disable non-blocking sockets. */ +/* #undef USE_BLOCKING_SOCKETS */ + +/* Version number of package */ +#define VERSION "1.7.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to 1 if OS is AIX. */ +#ifndef _ALL_SOURCE +/* # undef _ALL_SOURCE */ +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#define _FILE_OFFSET_BITS 64 + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Type to use in place of in_addr_t when system does not provide it. */ +/* #undef in_addr_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* the signed version of size_t */ +/* #undef ssize_t */ + +#define HAVE_GETENV 1 diff --git a/deps/v8/Android.mk b/deps/v8/Android.mk new file mode 100644 index 000000000000..8aaa375b17eb --- /dev/null +++ b/deps/v8/Android.mk @@ -0,0 +1,109 @@ +## +LOCAL_PATH := $(call my-dir) +# libv8.so +# =================================================== +include $(CLEAR_VARS) + +# Set up the target identity +LOCAL_MODULE := libv8 +LOCAL_MODULE_CLASS := STATIC_LIBRARIES +#intermediates := $(call local-intermediates-dir) +intermediates_rel := out/$(APP_OPTIM) +intermediates := $(LOCAL_PATH)/$(intermediates_rel) + +PRIVATE_CLEAN_FILES := $(HOST_OUT)/bin/mksnapshot \ + $(HOST_OUT)/obj/EXECUTABLES/mksnapshot_intermediates + +# Android.v8common.mk defines common V8_LOCAL_SRC_FILES +# and V8_LOCAL_JS_LIBRARY_FILES +V8_LOCAL_SRC_FILES := +V8_LOCAL_JS_LIBRARY_FILES := +include $(LOCAL_PATH)/Android.v8common.mk + +# Target can only be linux +V8_LOCAL_SRC_FILES += \ + src/platform-linux.cc \ + src/platform-posix.cc + +LOCAL_SRC_FILES := $(V8_LOCAL_SRC_FILES) + +LOCAL_JS_LIBRARY_FILES := $(addprefix $(LOCAL_PATH)/, $(V8_LOCAL_JS_LIBRARY_FILES)) + +# Copy js2c.py to intermediates directory and invoke there to avoid generating +# jsmin.pyc in the source directory +JS2C_PY := $(intermediates)/js2c.py $(intermediates)/jsmin.py +$(JS2C_PY): $(intermediates)/%.py : $(LOCAL_PATH)/tools/%.py | $(ACP) + @echo "Copying $@" + @mkdir -p $(dir $@) + @cp $(LOCAL_PATH)/tools/$(@F) $@ + +# Generate libraries.cc +GEN1 := $(intermediates)/libraries.cc +$(GEN1): SCRIPT := $(intermediates)/js2c.py +$(GEN1): $(LOCAL_JS_LIBRARY_FILES) $(JS2C_PY) + @echo "Generating libraries.cc" + @mkdir -p $(dir $@) + python $(SCRIPT) $(GEN1) CORE off $(LOCAL_JS_LIBRARY_FILES) +V8_GENERATED_LIBRARIES := $(intermediates_rel)/libraries.cc + +GEN2 := $(intermediates)/experimental-libraries.cc +$(GEN2): SCRIPT := $(intermediates)/js2c.py +$(GEN2): $(LOCAL_JS_LIBRARY_FILES) $(JS2C_PY) + @echo "Generating experimental-libraries.cc" + @mkdir -p $(dir $@) + python $(SCRIPT) $(GEN2) EXPERIMENTAL off $(V8_LOCAL_JS_EXPERIMENTAL_LIBRARY_FILES) +V8_GENERATED_LIBRARIES += $(intermediates_rel)/experimental-libraries.cc + +LOCAL_GENERATED_SOURCES += $(V8_GENERATED_LIBRARIES) + +# Generate snapshot.cc +ifeq ($(ENABLE_V8_SNAPSHOT),true) +SNAP_GEN := $(intermediates)/snapshot.cc +MKSNAPSHOT := $(HOST_OUT_EXECUTABLES)/mksnapshot +$(SNAP_GEN): PRIVATE_CUSTOM_TOOL = $(MKSNAPSHOT) $(SNAP_GEN) +$(SNAP_GEN): $(MKSNAPSHOT) + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(SNAP_GEN) +else +LOCAL_SRC_FILES += \ + src/snapshot-empty.cc +endif + +# The -fvisibility=hidden option below prevents exporting of symbols from +# libv8.a in libwebcore.so. That reduces size of libwebcore.so by 500k. +LOCAL_CFLAGS += \ + -Wno-endif-labels \ + -Wno-import \ + -Wno-format \ + -fno-exceptions \ + -DENABLE_DEBUGGER_SUPPORT \ + -DV8_NATIVE_REGEXP \ + -fvisibility=hidden \ + -DV8_ANDROID_LOG_STDOUT + + +ifeq ($(TARGET_ARCH),arm) + LOCAL_CFLAGS += -DARM -DV8_TARGET_ARCH_ARM +endif + +ifeq ($(TARGET_ARCH),x86) + LOCAL_CFLAGS += -DV8_TARGET_ARCH_IA32 +endif + +ifeq ($(ENABLE_V8_LOGGING_AND_PROFILING),true) + LOCAL_CFLAGS += -DENABLE_LOGGING_AND_PROFILING +endif + +ifeq ($(DEBUG_V8),true) + LOCAL_CFLAGS += -DDEBUG -UNDEBUG +endif + +LOCAL_SRC_FILES += $(V8_GENERATED_LIBRARIES) + +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include + +LOCAL_C_INCLUDES += \ + bionic/libc/include \ + $(LOCAL_PATH)/src + +include $(BUILD_STATIC_LIBRARY) diff --git a/deps/v8/Android.v8common.mk b/deps/v8/Android.v8common.mk new file mode 100644 index 000000000000..9a03976e951c --- /dev/null +++ b/deps/v8/Android.v8common.mk @@ -0,0 +1,180 @@ +LOCAL_CPP_EXTENSION := .cc + +V8_LOCAL_SRC_FILES := \ + src/accessors.cc \ + src/allocation.cc \ + src/api.cc \ + src/assembler.cc \ + src/ast.cc \ + src/bignum.cc \ + src/bignum-dtoa.cc \ + src/bootstrapper.cc \ + src/builtins.cc \ + src/cached-powers.cc \ + src/checks.cc \ + src/circular-queue.cc \ + src/code-stubs.cc \ + src/codegen.cc \ + src/compilation-cache.cc \ + src/compiler.cc \ + src/contexts.cc \ + src/conversions.cc \ + src/counters.cc \ + src/cpu-profiler.cc \ + src/data-flow.cc \ + src/dateparser.cc \ + src/debug.cc \ + src/debug-agent.cc \ + src/deoptimizer.cc \ + src/disassembler.cc \ + src/diy-fp.cc \ + src/dtoa.cc \ + src/elements.cc \ + src/execution.cc \ + src/extensions/externalize-string-extension.cc \ + src/extensions/gc-extension.cc \ + src/factory.cc \ + src/fast-dtoa.cc \ + src/fixed-dtoa.cc \ + src/flags.cc \ + src/frames.cc \ + src/full-codegen.cc \ + src/func-name-inferrer.cc \ + src/global-handles.cc \ + src/handles.cc \ + src/hashmap.cc \ + src/heap.cc \ + src/heap-profiler.cc \ + src/hydrogen.cc \ + src/hydrogen-instructions.cc \ + src/ic.cc \ + src/incremental-marking.cc \ + src/interpreter-irregexp.cc \ + src/isolate.cc \ + src/jsregexp.cc \ + src/lithium.cc \ + src/lithium-allocator.cc \ + src/liveedit.cc \ + src/log.cc \ + src/log-utils.cc \ + src/mark-compact.cc \ + src/messages.cc \ + src/objects.cc \ + src/objects-visiting.cc \ + src/parser.cc \ + src/preparse-data.cc \ + src/preparser.cc \ + src/property.cc \ + src/profile-generator.cc \ + src/regexp-macro-assembler.cc \ + src/regexp-macro-assembler-irregexp.cc \ + src/regexp-macro-assembler-tracer.cc \ + src/regexp-stack.cc \ + src/rewriter.cc \ + src/runtime.cc \ + src/runtime-profiler.cc \ + src/safepoint-table.cc \ + src/scanner.cc \ + src/scanner-character-streams.cc \ + src/scopeinfo.cc \ + src/scopes.cc \ + src/serialize.cc \ + src/snapshot-common.cc \ + src/spaces.cc \ + src/store-buffer.cc \ + src/string-search.cc \ + src/string-stream.cc \ + src/strtod.cc \ + src/stub-cache.cc \ + src/token.cc \ + src/type-info.cc \ + src/unicode.cc \ + src/utils.cc \ + src/v8-counters.cc \ + src/v8.cc \ + src/v8conversions.cc \ + src/v8threads.cc \ + src/v8utils.cc \ + src/variables.cc \ + src/version.cc \ + src/zone.cc + +ifeq ($(TARGET_ARCH),arm) + V8_LOCAL_SRC_FILES += \ + src/arm/assembler-arm.cc \ + src/arm/builtins-arm.cc \ + src/arm/codegen-arm.cc \ + src/arm/code-stubs-arm.cc \ + src/arm/constants-arm.cc \ + src/arm/cpu-arm.cc \ + src/arm/debug-arm.cc \ + src/arm/deoptimizer-arm.cc \ + src/arm/disasm-arm.cc \ + src/arm/frames-arm.cc \ + src/arm/full-codegen-arm.cc \ + src/arm/ic-arm.cc \ + src/arm/lithium-arm.cc \ + src/arm/lithium-codegen-arm.cc \ + src/arm/lithium-gap-resolver-arm.cc \ + src/arm/macro-assembler-arm.cc \ + src/arm/regexp-macro-assembler-arm.cc \ + src/arm/stub-cache-arm.cc +endif + +ifeq ($(TARGET_ARCH),x86) + V8_LOCAL_SRC_FILES += \ + src/ia32/assembler-ia32.cc \ + src/ia32/builtins-ia32.cc \ + src/ia32/codegen-ia32.cc \ + src/ia32/code-stubs-ia32.cc \ + src/ia32/cpu-ia32.cc \ + src/ia32/deoptimizer-ia32.cc \ + src/ia32/disasm-ia32.cc \ + src/ia32/frames-ia32.cc \ + src/ia32/full-codegen-ia32.cc \ + src/ia32/ic-ia32.cc \ + src/ia32/lithium-ia32.cc \ + src/ia32/lithium-codegen-ia32.cc \ + src/ia32/lithium-gap-resolver-ia32.cc \ + src/ia32/macro-assembler-ia32.cc \ + src/ia32/regexp-macro-assembler-ia32.cc \ + src/ia32/stub-cache-ia32.cc +endif + +# Enable DEBUG option. +ifeq ($(DEBUG_V8),true) + V8_LOCAL_SRC_FILES += \ + src/objects-debug.cc \ + src/prettyprinter.cc \ + src/regexp-macro-assembler-tracer.cc +endif + +# The order of these JS library sources is important. The order here determines +# the ordering of the JS code in libraries.cc, which must be in a specific order +# to meet compiler dependency requirements. +V8_LOCAL_JS_LIBRARY_FILES := \ + src/runtime.js \ + src/v8natives.js \ + src/array.js \ + src/string.js \ + src/uri.js \ + src/math.js \ + src/messages.js \ + src/apinatives.js + +# These JS library sources must follow the above sources but their order is not +# important. +V8_LOCAL_JS_LIBRARY_FILES += \ + src/date.js \ + src/debug-debugger.js \ + src/json.js \ + src/liveedit-debugger.js \ + src/mirror-debugger.js \ + src/regexp.js \ + src/macros.py + +# Experimental JS library sources. +V8_LOCAL_JS_EXPERIMENTAL_LIBRARY_FILES += \ + src/proxy.js \ + src/weakmap.js \ + src/macros.py diff --git a/src/platform_android.cc b/src/platform_android.cc new file mode 100644 index 000000000000..c04218e36913 --- /dev/null +++ b/src/platform_android.cc @@ -0,0 +1,398 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +#include "node.h" +#include "platform.h" + +#include + +#include // for MAXPATHLEN +#include // getpagesize, sysconf +#include // sscanf, snprintf + +/* SetProcessTitle */ +#include +#include +#include // free +#include // strdup + +/* GetInterfaceAddresses */ +#include +#include +#include +#include +#include + +#if HAVE_MONOTONIC_CLOCK +#include +#endif + +extern char **environ; + +namespace node { + +using namespace v8; + +static char buf[MAXPATHLEN + 1]; +double Platform::prog_start_time = Platform::GetUptime(); + +static struct { + char *str; + size_t len; +} process_title; + + +char** Platform::SetupArgs(int argc, char *argv[]) { + char **new_argv; + char **new_env; + size_t size; + int envc; + char *s; + int i; + + for (envc = 0; environ[envc]; envc++); + + s = envc ? environ[envc - 1] : argv[argc - 1]; + + process_title.str = argv[0]; + process_title.len = s + strlen(s) + 1 - argv[0]; + + size = process_title.len; + size += (argc + 1) * sizeof(char **); + size += (envc + 1) * sizeof(char **); + + if ((s = (char *) malloc(size)) == NULL) { + process_title.str = NULL; + process_title.len = 0; + return argv; + } + + new_argv = (char **) s; + new_env = new_argv + argc + 1; + s = (char *) (new_env + envc + 1); + memcpy(s, process_title.str, process_title.len); + + for (i = 0; i < argc; i++) + new_argv[i] = s + (argv[i] - argv[0]); + new_argv[argc] = NULL; + + s += environ[0] - argv[0]; + + for (i = 0; i < envc; i++) + new_env[i] = s + (environ[i] - environ[0]); + new_env[envc] = NULL; + + environ = new_env; + return new_argv; +} + + +void Platform::SetProcessTitle(char *title) { + /* No need to terminate, last char is always '\0'. */ + if (process_title.len) + strncpy(process_title.str, title, process_title.len - 1); +} + + +const char* Platform::GetProcessTitle(int *len) { + if (process_title.str) { + *len = strlen(process_title.str); + return process_title.str; + } + else { + *len = 0; + return NULL; + } +} + + +int Platform::GetMemory(size_t *rss) { + FILE *f = fopen("/proc/self/stat", "r"); + if (!f) return -1; + + int itmp; + char ctmp; + size_t page_size = getpagesize(); + char *cbuf; + bool foundExeEnd; + + /* PID */ + if (fscanf(f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Exec file */ + cbuf = buf; + foundExeEnd = false; + if (fscanf (f, "%c", cbuf++) == 0) goto error; // ( + while (1) { + if (fscanf(f, "%c", cbuf) == 0) goto error; + if (*cbuf == ')') { + foundExeEnd = true; + } else if (foundExeEnd && *cbuf == ' ') { + *cbuf = 0; + break; + } + + cbuf++; + } + /* State */ + if (fscanf (f, "%c ", &ctmp) == 0) goto error; /* coverity[secure_coding] */ + /* Parent process */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Process group */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Session id */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* TTY */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* TTY owner process group */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Flags */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Minor faults (no memory page) */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Minor faults, children */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Major faults (memory page faults) */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Major faults, children */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* utime */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* stime */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* utime, children */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* stime, children */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* jiffies remaining in current time slice */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* 'nice' value */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* jiffies until next timeout */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* jiffies until next SIGALRM */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* start time (jiffies since system boot) */ + if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + + /* Virtual memory size */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + + /* Resident set size */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + *rss = (size_t) itmp * page_size; + + /* rlim */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Start of text */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* End of text */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + /* Start of stack */ + if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */ + + fclose (f); + + return 0; + +error: + fclose (f); + return -1; +} + + +int Platform::GetCPUInfo(Local *cpus) { + HandleScope scope; + Local cpuinfo; + Local cputimes; + unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK), + multiplier = ((uint64_t)1000L / ticks), cpuspeed; + int numcpus = 0, i = 0; + unsigned long long ticks_user, ticks_sys, ticks_idle, ticks_nice, ticks_intr; + char line[512], speedPath[256], model[512]; + FILE *fpStat = fopen("/proc/stat", "r"); + FILE *fpModel = fopen("/proc/cpuinfo", "r"); + FILE *fpSpeed; + + if (fpModel) { + while (fgets(line, 511, fpModel) != NULL) { + if (strncmp(line, "model name", 10) == 0) { + numcpus++; + if (numcpus == 1) { + char *p = strchr(line, ':') + 2; + strcpy(model, p); + model[strlen(model)-1] = 0; + } + } else if (strncmp(line, "cpu MHz", 7) == 0) { + if (numcpus == 1) { + sscanf(line, "%*s %*s : %u", &cpuspeed); + } + } + } + fclose(fpModel); + } + + *cpus = Array::New(numcpus); + + if (fpStat) { + while (fgets(line, 511, fpStat) != NULL) { + if (strncmp(line, "cpu ", 4) == 0) { + continue; + } else if (strncmp(line, "cpu", 3) != 0) { + break; + } + + sscanf(line, "%*s %llu %llu %llu %llu %*llu %llu", + &ticks_user, &ticks_nice, &ticks_sys, &ticks_idle, &ticks_intr); + snprintf(speedPath, sizeof(speedPath), + "/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_max_freq", i); + + fpSpeed = fopen(speedPath, "r"); + + if (fpSpeed) { + if (fgets(line, 511, fpSpeed) != NULL) { + sscanf(line, "%u", &cpuspeed); + cpuspeed /= 1000; + } + fclose(fpSpeed); + } + + cpuinfo = Object::New(); + cputimes = Object::New(); + cputimes->Set(String::New("user"), Number::New(ticks_user * multiplier)); + cputimes->Set(String::New("nice"), Number::New(ticks_nice * multiplier)); + cputimes->Set(String::New("sys"), Number::New(ticks_sys * multiplier)); + cputimes->Set(String::New("idle"), Number::New(ticks_idle * multiplier)); + cputimes->Set(String::New("irq"), Number::New(ticks_intr * multiplier)); + + cpuinfo->Set(String::New("model"), String::New(model)); + cpuinfo->Set(String::New("speed"), Number::New(cpuspeed)); + + cpuinfo->Set(String::New("times"), cputimes); + (*cpus)->Set(i++, cpuinfo); + } + fclose(fpStat); + } + + return 0; +} + +double Platform::GetUptimeImpl() { +#if HAVE_MONOTONIC_CLOCK + struct timespec now; + if (0 == clock_gettime(CLOCK_MONOTONIC, &now)) { + double uptime = now.tv_sec; + uptime += (double)now.tv_nsec / 1000000000.0; + return uptime; + } + return -1; +#else + struct sysinfo info; + if (sysinfo(&info) < 0) { + return -1; + } + return static_cast(info.uptime); +#endif +} + + +/* FIXME: implement this +bool IsInternal(struct ifaddrs* addr) { + return addr->ifa_flags & IFF_UP && + addr->ifa_flags & IFF_RUNNING && + addr->ifa_flags & IFF_LOOPBACK; +} +*/ + +Handle Platform::GetInterfaceAddresses() { + /* FIXME: implement this */ + return ThrowException(ErrnoException(errno, "getifaddrs")); + +#if 0 + HandleScope scope; + struct ::ifaddrs *addrs, *ent; + struct ::sockaddr_in *in4; + struct ::sockaddr_in6 *in6; + char ip[INET6_ADDRSTRLEN]; + Local ret, o; + Local name, ipaddr, family; + Local ifarr; + + if (getifaddrs(&addrs) != 0) { + return ThrowException(ErrnoException(errno, "getifaddrs")); + } + + ret = Object::New(); + + for (ent = addrs; ent != NULL; ent = ent->ifa_next) { + bzero(&ip, sizeof (ip)); + if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING)) { + continue; + } + + if (ent->ifa_addr == NULL) { + continue; + } + + /* + * On Linux getifaddrs returns information related to the raw underlying + * devices. We're not interested in this information. + */ + if (ent->ifa_addr->sa_family == PF_PACKET) + continue; + + name = String::New(ent->ifa_name); + if (ret->Has(name)) { + ifarr = Local::Cast(ret->Get(name)); + } else { + ifarr = Array::New(); + ret->Set(name, ifarr); + } + + if (ent->ifa_addr->sa_family == AF_INET6) { + in6 = (struct sockaddr_in6 *)ent->ifa_addr; + inet_ntop(AF_INET6, &(in6->sin6_addr), ip, INET6_ADDRSTRLEN); + family = String::New("IPv6"); + } else if (ent->ifa_addr->sa_family == AF_INET) { + in4 = (struct sockaddr_in *)ent->ifa_addr; + inet_ntop(AF_INET, &(in4->sin_addr), ip, INET6_ADDRSTRLEN); + family = String::New("IPv4"); + } else { + (void) strncpy(ip, "", INET6_ADDRSTRLEN); + family = String::New(""); + } + + o = Object::New(); + o->Set(String::New("address"), String::New(ip)); + o->Set(String::New("family"), family); + o->Set(String::New("internal"), ent->ifa_flags & IFF_LOOPBACK ? + True() : False()); + + ifarr->Set(ifarr->Length(), o); + + } + + freeifaddrs(addrs); + + return scope.Close(ret); +#endif +} + +} // namespace node