summaryrefslogtreecommitdiff
path: root/native_client_sdk
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2013-07-23 11:17:05 +0100
committerBen Murdoch <benm@google.com>2013-07-23 11:17:05 +0100
commitca12bfac764ba476d6cd062bf1dde12cc64c3f40 (patch)
tree1cd09db25ea5de98e73c8efbe572e103daee8b2b /native_client_sdk
parentfcb3e05bdd21d752df9c3dff28b6bbf29b5b733b (diff)
downloadchromium_org-ca12bfac764ba476d6cd062bf1dde12cc64c3f40.tar.gz
Merge from Chromium at DEPS revision r213057
This commit was generated by merge_to_master.py. Change-Id: I3e2e2506eb9b0080157e9c5f133559df3e600388
Diffstat (limited to 'native_client_sdk')
-rwxr-xr-xnative_client_sdk/src/build_tools/build_app.py2
-rwxr-xr-xnative_client_sdk/src/build_tools/build_projects.py4
-rwxr-xr-xnative_client_sdk/src/build_tools/build_sdk.py48
-rw-r--r--native_client_sdk/src/build_tools/generate_make.py4
-rw-r--r--native_client_sdk/src/build_tools/library.mk8
-rwxr-xr-xnative_client_sdk/src/build_tools/parse_dsc.py108
-rw-r--r--native_client_sdk/src/build_tools/sdk_files.list5
-rw-r--r--native_client_sdk/src/build_tools/template.mk8
-rwxr-xr-xnative_client_sdk/src/build_tools/test_projects.py324
-rwxr-xr-xnative_client_sdk/src/build_tools/test_sdk.py129
-rw-r--r--native_client_sdk/src/examples/api/graphics_3d/graphics_3d.cc7
-rw-r--r--native_client_sdk/src/examples/api/graphics_3d/matrix.cc7
-rw-r--r--native_client_sdk/src/examples/demo/drive/drive.cc5
-rw-r--r--native_client_sdk/src/examples/demo/earth/earth.cc2
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/example.dsc5
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/handlers.c20
-rw-r--r--native_client_sdk/src/examples/demo/pi_generator/example.dsc5
-rw-r--r--native_client_sdk/src/examples/demo/voronoi/voronoi.cc2
-rw-r--r--native_client_sdk/src/examples/getting_started/simple_hello_world/example.dsc3
-rw-r--r--native_client_sdk/src/examples/tutorial/debugging/example.dsc2
-rw-r--r--native_client_sdk/src/examples/tutorial/dlopen/example.dsc3
-rw-r--r--native_client_sdk/src/examples/tutorial/testing/example.dsc6
-rw-r--r--native_client_sdk/src/libraries/error_handling/error_handling.c9
-rw-r--r--native_client_sdk/src/libraries/error_handling/string_stream.c8
-rw-r--r--native_client_sdk/src/libraries/gmock/library.dsc1
-rw-r--r--native_client_sdk/src/libraries/gtest/library.dsc7
-rw-r--r--native_client_sdk/src/libraries/jsoncpp/library.dsc1
-rw-r--r--native_client_sdk/src/libraries/nacl_io/error.h11
-rw-r--r--native_client_sdk/src/libraries/nacl_io/event_emitter.cc59
-rw-r--r--native_client_sdk/src/libraries/nacl_io/event_emitter.h103
-rw-r--r--native_client_sdk/src/libraries/nacl_io/event_listener.cc243
-rw-r--r--native_client_sdk/src/libraries/nacl_io/event_listener.h149
-rw-r--r--native_client_sdk/src/libraries/nacl_io/inode_pool.h14
-rw-r--r--native_client_sdk/src/libraries/nacl_io/ioctl.h6
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_handle.cc20
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_handle.h27
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc9
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_intercept.h8
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_object.cc16
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_object.h17
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc14
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_proxy.h12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap.h18
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc21
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc13
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h8
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc20
-rw-r--r--native_client_sdk/src/libraries/nacl_io/library.dsc7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount.cc12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount.h16
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_dev.cc12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_dev.h12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_factory.h14
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_html5fs.cc11
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_html5fs.h14
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_http.cc11
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_http.h17
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_mem.cc12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_mem.h12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node.cc12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node.h20
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc14
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node_dir.h17
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.cc11
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.h12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node_http.cc25
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node_http.h15
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node_mem.cc12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_node_mem.h12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_passthrough.cc17
-rw-r--r--native_client_sdk/src/libraries/nacl_io/mount_passthrough.h12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/nacl_io.cc7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/nacl_io.h6
-rw-r--r--native_client_sdk/src/libraries/nacl_io/osdirent.h6
-rw-r--r--native_client_sdk/src/libraries/nacl_io/osinttypes.h10
-rw-r--r--native_client_sdk/src/libraries/nacl_io/osmman.h6
-rw-r--r--native_client_sdk/src/libraries/nacl_io/osstat.h7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/ostime.h26
-rw-r--r--native_client_sdk/src/libraries/nacl_io/ostypes.h6
-rw-r--r--native_client_sdk/src/libraries/nacl_io/osunistd.h7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/osutime.h7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/path.cc12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/path.h12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h8
-rw-r--r--native_client_sdk/src/libraries/nacl_io/pepper/define_empty_macros.h7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/pepper/undef_macros.h7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/pepper_interface.cc11
-rw-r--r--native_client_sdk/src/libraries/nacl_io/pepper_interface.h12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/real_pepper_interface.cc10
-rw-r--r--native_client_sdk/src/libraries/nacl_io/real_pepper_interface.h12
-rw-r--r--native_client_sdk/src/libraries/nacl_io/typed_mount_factory.h17
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/event_test.cc359
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/example.dsc5
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/kernel_object_test.cc11
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.cc7
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.h9
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_test.cc10
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/kernel_wrap_test.cc11
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/mock_util.h7
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/mount_html5fs_test.cc10
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/mount_http_test.cc10
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/mount_mock.cc7
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/mount_mock.h16
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.cc9
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.h15
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/mount_node_test.cc9
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/mount_test.cc9
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/path_test.cc9
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.cc7
-rw-r--r--native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.h12
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps.cc7
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_event.cc7
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc2
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_instance.h5
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_main.cc7
-rw-r--r--native_client_sdk/src/libraries/sdk_util/atomicops.h15
-rw-r--r--native_client_sdk/src/libraries/sdk_util/auto_lock.h13
-rw-r--r--native_client_sdk/src/libraries/sdk_util/macros.h5
-rw-r--r--native_client_sdk/src/libraries/sdk_util/ref_object.h11
-rw-r--r--native_client_sdk/src/libraries/sdk_util/scoped_ref.h11
-rw-r--r--native_client_sdk/src/libraries/sdk_util/simple_lock.h12
-rw-r--r--native_client_sdk/src/libraries/sdk_util/thread_pool.cc6
-rw-r--r--native_client_sdk/src/libraries/sdk_util/thread_pool.h5
-rw-r--r--native_client_sdk/src/libraries/sdk_util/thread_safe_queue.h3
-rw-r--r--native_client_sdk/src/libraries/xray/browser.c132
-rw-r--r--native_client_sdk/src/libraries/xray/demangle.c3
-rw-r--r--native_client_sdk/src/libraries/xray/hashtable.c3
-rw-r--r--native_client_sdk/src/libraries/xray/library.dsc5
-rw-r--r--native_client_sdk/src/libraries/xray/parsesymbols.c3
-rw-r--r--native_client_sdk/src/libraries/xray/report.c12
-rw-r--r--native_client_sdk/src/libraries/xray/stringpool.c3
-rw-r--r--native_client_sdk/src/libraries/xray/symtable.c17
-rw-r--r--native_client_sdk/src/libraries/xray/xray.c63
-rw-r--r--native_client_sdk/src/libraries/xray/xray.h24
-rw-r--r--native_client_sdk/src/libraries/xray/xray.html2
-rw-r--r--native_client_sdk/src/libraries/xray/xray.odtbin52527 -> 52528 bytes
-rw-r--r--native_client_sdk/src/libraries/xray/xray_priv.h21
-rwxr-xr-xnative_client_sdk/src/tools/create_nmf.py24
-rw-r--r--native_client_sdk/src/tools/host_gcc.mk8
-rw-r--r--native_client_sdk/src/tools/nacl_gcc.mk21
140 files changed, 2335 insertions, 693 deletions
diff --git a/native_client_sdk/src/build_tools/build_app.py b/native_client_sdk/src/build_tools/build_app.py
index 81af5992b0..f370b9e3a1 100755
--- a/native_client_sdk/src/build_tools/build_app.py
+++ b/native_client_sdk/src/build_tools/build_app.py
@@ -98,7 +98,7 @@ def main(args):
filters['TOOLS'] = toolchains
filters['DEST'] = ['examples/api', 'examples/getting_started',
'examples/demo', 'examples/tutorial']
- tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, filters=filters)
+ tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
build_projects.UpdateHelpers(app_dir, platform, clobber=True)
build_projects.UpdateProjects(app_dir, platform, tree, clobber=False,
toolchains=toolchains, configs=[config],
diff --git a/native_client_sdk/src/build_tools/build_projects.py b/native_client_sdk/src/build_tools/build_projects.py
index 8e3ebe8c8c..20f3f7ca3a 100755
--- a/native_client_sdk/src/build_tools/build_projects.py
+++ b/native_client_sdk/src/build_tools/build_projects.py
@@ -23,7 +23,7 @@ import getos
import http_download
-MAKE = 'nacl_sdk/make_3_81/make.exe'
+MAKE = 'nacl_sdk/make_3.99.90-26-gf80222c/make.exe'
LIB_DICT = {
'linux': [],
'mac': [],
@@ -263,7 +263,7 @@ def main(args):
print 'Filter by name: ' + str(options.project)
try:
- project_tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, filters=filters)
+ project_tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
except parse_dsc.ValidationError as e:
buildbot_common.ErrorExit(str(e))
parse_dsc.PrintProjectTree(project_tree)
diff --git a/native_client_sdk/src/build_tools/build_sdk.py b/native_client_sdk/src/build_tools/build_sdk.py
index a15163546c..a4ab579d5f 100755
--- a/native_client_sdk/src/build_tools/build_sdk.py
+++ b/native_client_sdk/src/build_tools/build_sdk.py
@@ -590,28 +590,38 @@ def BuildStepBuildToolchains(pepperdir, toolchains):
cwd=NACL_DIR,
shell=shell)
+ # NOTE: For ia32, gyp builds both x86-32 and x86-64 by default.
for arch in ('ia32', 'arm'):
# Fill in the latest native pnacl shim library from the chrome build.
build_dir = GYPBUILD_DIR + '-pnacl-' + arch
GypNinjaBuild_Pnacl(build_dir, arch)
- pnacl_libdir_map = {'ia32': 'x86-64', 'arm': 'arm'}
- release_build_dir = os.path.join(OUT_DIR, build_dir, 'Release',
- 'gen', 'tc_pnacl_translate',
- 'lib-' + pnacl_libdir_map[arch])
-
- buildbot_common.CopyFile(
- os.path.join(release_build_dir, 'libpnacl_irt_shim.a'),
- GetPNaClNativeLib(pnacldir, pnacl_libdir_map[arch]))
-
- release_build_dir = os.path.join(OUT_DIR, build_dir, 'Release',
- 'gen', 'tc_pnacl_newlib', 'lib')
- buildbot_common.CopyFile(
- os.path.join(release_build_dir, 'libminidump_generator.a'),
- GetPNaClNativeLib(pnacldir, pnacl_libdir_map[arch]))
-
- buildbot_common.CopyFile(
- os.path.join(release_build_dir, 'libnacl_exception.a'),
- GetPNaClNativeLib(pnacldir, pnacl_libdir_map[arch]))
+ if arch == 'ia32':
+ nacl_arches = ['x86-32', 'x86-64']
+ elif arch == 'arm':
+ nacl_arches = ['arm']
+ else:
+ buildbot_common.ErrorExit('Unknown architecture: %s' % arch)
+ for nacl_arch in nacl_arches:
+ release_build_dir = os.path.join(OUT_DIR, build_dir, 'Release',
+ 'gen', 'tc_pnacl_translate',
+ 'lib-' + nacl_arch)
+
+ buildbot_common.CopyFile(
+ os.path.join(release_build_dir, 'libpnacl_irt_shim.a'),
+ GetPNaClNativeLib(pnacldir, nacl_arch))
+
+ # TODO: should these next couple of bitcode libraries really be
+ # installed to the native library directory instead of bitcode
+ # library directory?
+ release_build_dir = os.path.join(OUT_DIR, build_dir, 'Release',
+ 'gen', 'tc_pnacl_newlib', 'lib')
+ buildbot_common.CopyFile(
+ os.path.join(release_build_dir, 'libminidump_generator.a'),
+ GetPNaClNativeLib(pnacldir, nacl_arch))
+
+ buildbot_common.CopyFile(
+ os.path.join(release_build_dir, 'libnacl_exception.a'),
+ GetPNaClNativeLib(pnacldir, nacl_arch))
InstallNaClHeaders(GetToolchainNaClInclude('pnacl', pnacldir, 'x86'),
'newlib')
@@ -662,7 +672,7 @@ def BuildStepUpdateUserProjects(pepperdir, toolchains,
'src'
]
- tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, filters=filters)
+ tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
build_projects.UpdateProjects(pepperdir, tree, clobber=clobber,
toolchains=toolchains)
diff --git a/native_client_sdk/src/build_tools/generate_make.py b/native_client_sdk/src/build_tools/generate_make.py
index faad723a43..e74891b26c 100644
--- a/native_client_sdk/src/build_tools/generate_make.py
+++ b/native_client_sdk/src/build_tools/generate_make.py
@@ -199,6 +199,10 @@ def ProcessProject(pepperdir, srcroot, dstroot, desc, toolchains, configs=None,
tools = [tool for tool in toolchains if tool in desc['TOOLS']]
if first_toolchain:
tools = [tools[0]]
+ for target in desc['TARGETS']:
+ target.setdefault('CXXFLAGS', [])
+ target['CXXFLAGS'].insert(0, '-Wall')
+
template_dict = {
'rel_sdk': '/'.join(['..'] * (len(desc['DEST'].split('/')) + 1)),
'pre': desc.get('PRE', ''),
diff --git a/native_client_sdk/src/build_tools/library.mk b/native_client_sdk/src/build_tools/library.mk
index 0dbf368a22..ff991aaca1 100644
--- a/native_client_sdk/src/build_tools/library.mk
+++ b/native_client_sdk/src/build_tools/library.mk
@@ -36,9 +36,14 @@ EXTRA_INC_PATHS={{' '.join(target['INCLUDES'])}}
include $(NACL_SDK_ROOT)/tools/common.mk
TARGET = {{target['NAME']}}
-[[flags = target.get('CCFLAGS', [])]]
+[[flags = target.get('CFLAGS', [])]]
[[flags.extend(target.get('CXXFLAGS', []))]]
[[ExpandDict('CFLAGS', flags)]]
+[[if 'CFLAGS_GCC' in target:]]
+ifneq ($(TOOLCHAIN),pnacl)
+CFLAGS += {{' '.join(target['CFLAGS_GCC'])}}
+endif
+[[]]
SOURCES = \
[[for source in sorted(target['SOURCES']):]]
@@ -57,3 +62,4 @@ ifeq ($(TOOLCHAIN),glibc)
$(eval $(call SO_RULE,$(TARGET),$(SOURCES)))
endif
[[]]
+{{post}}
diff --git a/native_client_sdk/src/build_tools/parse_dsc.py b/native_client_sdk/src/build_tools/parse_dsc.py
index 5256f79292..48c3761aad 100755
--- a/native_client_sdk/src/build_tools/parse_dsc.py
+++ b/native_client_sdk/src/build_tools/parse_dsc.py
@@ -28,7 +28,8 @@ DSC_FORMAT = {
'TYPE': (str, ['main', 'lib', 'static-lib', 'so', 'so-standalone'],
True),
'SOURCES': (list, '', True),
- 'CCFLAGS': (list, '', False),
+ 'CFLAGS': (list, '', False),
+ 'CFLAGS_GCC': (list, '', False),
'CXXFLAGS': (list, '', False),
'DEFINES': (list, '', False),
'LDFLAGS': (list, '', False),
@@ -150,11 +151,56 @@ def LoadProject(filename):
return desc
-def AcceptProject(desc, filters):
- # Check if we should filter node this on toolchain
- if not filters:
- return True
+def LoadProjectTreeUnfiltered(srcpath):
+ # Build the tree
+ out = collections.defaultdict(list)
+ for root, _, files in os.walk(srcpath):
+ for filename in files:
+ if fnmatch.fnmatch(filename, '*.dsc'):
+ filepath = os.path.join(root, filename)
+ try:
+ desc = LoadProject(filepath)
+ except ValidationError as e:
+ raise ValidationError("Failed to validate: %s: %s" % (filepath, e))
+ if desc:
+ key = desc['DEST']
+ out[key].append(desc)
+ return out
+
+
+def LoadProjectTree(srcpath, include, exclude=None):
+ out = LoadProjectTreeUnfiltered(srcpath)
+ return FilterTree(out, MakeDefaultFilterFn(include, exclude))
+
+
+def GenerateProjects(tree):
+ for key in tree:
+ for val in tree[key]:
+ yield key, val
+
+
+def FilterTree(tree, filter_fn):
+ out = collections.defaultdict(list)
+ for branch, desc in GenerateProjects(tree):
+ if filter_fn(desc):
+ out[branch].append(desc)
+ return out
+
+
+def MakeDefaultFilterFn(include, exclude):
+ def DefaultFilterFn(desc):
+ matches_include = not include or DescMatchesFilter(desc, include)
+ matches_exclude = exclude and DescMatchesFilter(desc, exclude)
+
+ # Exclude list overrides include list.
+ if matches_exclude:
+ return False
+ return matches_include
+
+ return DefaultFilterFn
+
+def DescMatchesFilter(desc, filters):
for key, expected in filters.iteritems():
# For any filtered key which is unspecified, assumed False
value = desc.get(key, False)
@@ -172,37 +218,6 @@ def AcceptProject(desc, filters):
return True
-def PruneTree(tree, filters):
- out = collections.defaultdict(list)
- for branch, projects in tree.iteritems():
- for desc in projects:
- if AcceptProject(desc, filters):
- out[branch].append(desc)
-
- return out
-
-
-def LoadProjectTree(srcpath, filters=None):
- # Build the tree
- out = collections.defaultdict(list)
- for root, _, files in os.walk(srcpath):
- for filename in files:
- if fnmatch.fnmatch(filename, '*.dsc'):
- filepath = os.path.join(root, filename)
- try:
- desc = LoadProject(filepath)
- except ValidationError as e:
- raise ValidationError("Failed to validate: %s: %s" % (filepath, e))
- if desc:
- key = desc['DEST']
- out[key].append(desc)
-
- # Filter if needed
- if filters:
- out = PruneTree(out, filters)
- return out
-
-
def PrintProjectTree(tree):
for key in tree:
print key + ':'
@@ -210,26 +225,23 @@ def PrintProjectTree(tree):
print '\t' + val['NAME']
-def GenerateProjects(tree):
- for key in tree:
- for val in tree[key]:
- yield key, val
-
-
def main(argv):
- parser = optparse.OptionParser()
+ parser = optparse.OptionParser(usage='%prog [options] <dir>')
parser.add_option('-e', '--experimental',
help='build experimental examples and libraries', action='store_true')
parser.add_option('-t', '--toolchain',
help='Build using toolchain. Can be passed more than once.',
action='append')
- options, files = parser.parse_args(argv[1:])
+ options, args = parser.parse_args(argv[1:])
filters = {}
- if len(files):
- parser.error('Not expecting files.')
- return 1
+ load_from_dir = '.'
+ if len(args) > 1:
+ parser.error('Expected 0 or 1 args, got %d.' % len(args))
+
+ if args:
+ load_from_dir = args[0]
if options.toolchain:
filters['TOOLS'] = options.toolchain
@@ -238,7 +250,7 @@ def main(argv):
filters['EXPERIMENTAL'] = False
try:
- tree = LoadProjectTree('.', filters=filters)
+ tree = LoadProjectTree(load_from_dir, include=filters)
except ValidationError as e:
sys.stderr.write(str(e) + '\n')
return 1
diff --git a/native_client_sdk/src/build_tools/sdk_files.list b/native_client_sdk/src/build_tools/sdk_files.list
index 5920d3e901..11133cba38 100644
--- a/native_client_sdk/src/build_tools/sdk_files.list
+++ b/native_client_sdk/src/build_tools/sdk_files.list
@@ -302,6 +302,8 @@ include/json/reader.h
include/json/value.h
include/json/writer.h
include/KHR/khrplatform.h
+include/nacl_io/event_emitter.h
+include/nacl_io/event_listener.h
include/nacl_io/error.h
include/nacl_io/inode_pool.h
include/nacl_io/ioctl.h
@@ -328,6 +330,7 @@ include/nacl_io/osdirent.h
include/nacl_io/osinttypes.h
include/nacl_io/osmman.h
include/nacl_io/osstat.h
+include/nacl_io/ostime.h
include/nacl_io/ostypes.h
include/nacl_io/osunistd.h
include/nacl_io/osutime.h
@@ -801,6 +804,8 @@ src/jsoncpp/Makefile
src/jsoncpp/README.chromium
[win]src/make.bat
src/Makefile
+src/nacl_io/event_emitter.cc
+src/nacl_io/event_listener.cc
src/nacl_io/kernel_handle.cc
src/nacl_io/kernel_intercept.cc
src/nacl_io/kernel_object.cc
diff --git a/native_client_sdk/src/build_tools/template.mk b/native_client_sdk/src/build_tools/template.mk
index 8d024950eb..8c6375690c 100644
--- a/native_client_sdk/src/build_tools/template.mk
+++ b/native_client_sdk/src/build_tools/template.mk
@@ -41,15 +41,19 @@ TARGET = {{targets[0]['NAME']}}
[[ source_list = ' \\\n '.join(source_list)]]
[[ sources = target['NAME'] + '_SOURCES']]
[[ cflags = target['NAME'] + '_CFLAGS']]
-[[ flags = target.get('CCFLAGS', [])]]
+[[ flags = target.get('CFLAGS', [])]]
[[ flags.extend(target.get('CXXFLAGS', []))]]
[[ if len(targets) == 1:]]
[[ sources = 'SOURCES']]
[[ cflags = 'CFLAGS']]
[[ ]]
[[ ExpandDict(cflags, flags)]]
+[[ if 'CFLAGS_GCC' in target:]]
+ifneq ($(TOOLCHAIN),pnacl)
+{{cflags}} += {{' '.join(target['CFLAGS_GCC'])}}
+endif
+[[ ]]
{{sources}} = {{source_list}}
-[[]]
# Build rules generated by macros from common.mk:
diff --git a/native_client_sdk/src/build_tools/test_projects.py b/native_client_sdk/src/build_tools/test_projects.py
new file mode 100755
index 0000000000..9c1a057212
--- /dev/null
+++ b/native_client_sdk/src/build_tools/test_projects.py
@@ -0,0 +1,324 @@
+#!/usr/bin/env python
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import optparse
+import os
+import subprocess
+import sys
+import time
+
+import buildbot_common
+import build_version
+import parse_dsc
+
+from build_paths import OUT_DIR, SRC_DIR, SDK_SRC_DIR
+
+sys.path.append(os.path.join(SDK_SRC_DIR, 'tools'))
+import getos
+platform = getos.GetPlatform()
+
+# TODO(binji): ugly hack -- can I get the browser in a cleaner way?
+sys.path.append(os.path.join(SRC_DIR, 'chrome', 'test', 'nacl_test_injection'))
+import find_chrome
+browser_path = find_chrome.FindChrome(SRC_DIR, ['Debug', 'Release'])
+
+
+pepper_ver = str(int(build_version.ChromeMajorVersion()))
+pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
+
+browser_tester_py = os.path.join(SRC_DIR, 'ppapi', 'native_client', 'tools',
+ 'browser_tester', 'browser_tester.py')
+
+
+ALL_CONFIGS = ['Debug', 'Release']
+ALL_TOOLCHAINS = ['newlib', 'glibc', 'pnacl', 'win', 'linux', 'mac']
+
+# Values you can filter by:
+# name: The name of the test. (e.g. "pi_generator")
+# config: See ALL_CONFIGS above.
+# toolchain: See ALL_TOOLCHAINS above.
+# platform: mac/win/linux.
+#
+# All keys must be matched, but any value that matches in a sequence is
+# considered a match for that key. For example:
+#
+# {'name': ('pi_generator', 'input_event'), 'toolchain': ('newlib', 'pnacl')}
+#
+# Will match 8 tests:
+# pi_generator.newlib_debug_test
+# pi_generator.newlib_release_test
+# input_event.newlib_debug_test
+# input_event.newlib_release_test
+# pi_generator.glibc_debug_test
+# pi_generator.glibc_release_test
+# input_event.glibc_debug_test
+# input_event.glibc_release_test
+DISABLED_TESTS = [
+ # TODO(binji): Disable 3D examples on linux/win. See
+ # http://crbug.com/262379.
+ {'name': 'graphics_3d', 'platform': ('win', 'linux')},
+]
+
+DEFAULT_RETRY_ON_FAILURE_TIMES = 3
+
+
+def ValidateToolchains(toolchains):
+ invalid_toolchains = set(toolchains) - set(ALL_TOOLCHAINS)
+ if invalid_toolchains:
+ buildbot_common.ErrorExit('Invalid toolchain(s): %s' % (
+ ', '.join(invalid_toolchains)))
+
+
+def GetServingDirForProject(desc):
+ dest = desc['DEST']
+ path = os.path.join(pepperdir, *dest.split('/'))
+ return os.path.join(path, desc['NAME'])
+
+
+def GetExecutableDirForProject(desc, toolchain, config):
+ return os.path.join(GetServingDirForProject(desc), toolchain, config)
+
+
+def GetBrowserTesterCommand(desc, toolchain, config):
+ args = [
+ sys.executable,
+ browser_tester_py,
+ '--browser_path', browser_path,
+ '--timeout', '30.0', # seconds
+ # Prevent the infobar that shows up when requesting filesystem quota.
+ '--browser_flag', '--unlimited-storage',
+ ]
+
+ args.extend(['--serving_dir', GetServingDirForProject(desc)])
+ exe_dir = GetExecutableDirForProject(desc, toolchain, config)
+
+ if toolchain == platform:
+ ppapi_plugin = os.path.join(exe_dir, desc['NAME'])
+ if platform == 'win':
+ ppapi_plugin += '.dll'
+ else:
+ ppapi_plugin += '.so'
+ args.extend(['--ppapi_plugin', ppapi_plugin])
+
+ if toolchain == 'pnacl':
+ args.extend(['--browser_flag', '--enable-pnacl'])
+
+ url = 'index.html'
+ url += '?tc=%s&config=%s&test=true' % (toolchain, config)
+ args.extend(['--url', url])
+ return args
+
+
+def GetBrowserTesterEnv():
+ # browser_tester imports tools/valgrind/memcheck_analyze, which imports
+ # tools/valgrind/common. Well, it tries to, anyway, but instead imports
+ # common from PYTHONPATH first (which on the buildbots, is a
+ # common/__init__.py file...).
+ #
+ # Clear the PYTHONPATH so it imports the correct file.
+ env = dict(os.environ)
+ env['PYTHONPATH'] = ''
+ return env
+
+
+def RunTestOnce(desc, toolchain, config):
+ args = GetBrowserTesterCommand(desc, toolchain, config)
+ env = GetBrowserTesterEnv()
+ start_time = time.time()
+ try:
+ subprocess.check_call(args, env=env)
+ result = True
+ except subprocess.CalledProcessError:
+ result = False
+ elapsed = (time.time() - start_time) * 1000
+ return result, elapsed
+
+
+def RunTestNTimes(desc, toolchain, config, times):
+ total_elapsed = 0
+ for _ in xrange(times):
+ result, elapsed = RunTestOnce(desc, toolchain, config)
+ total_elapsed += elapsed
+ if result:
+ # Success, stop retrying.
+ break
+ return result, total_elapsed
+
+
+def RunTestWithGtestOutput(desc, toolchain, config, retry_on_failure_times):
+ test_name = GetTestName(desc, toolchain, config)
+ WriteGtestHeader(test_name)
+ result, elapsed = RunTestNTimes(desc, toolchain, config,
+ retry_on_failure_times)
+ WriteGtestFooter(result, test_name, elapsed)
+ return result
+
+
+def WriteGtestHeader(test_name):
+ print '\n[ RUN ] %s' % test_name
+ sys.stdout.flush()
+ sys.stderr.flush()
+
+
+def WriteGtestFooter(success, test_name, elapsed):
+ sys.stdout.flush()
+ sys.stderr.flush()
+ if success:
+ message = '[ OK ]'
+ else:
+ message = '[ FAILED ]'
+ print '%s %s (%d ms)' % (message, test_name, elapsed)
+
+
+def GetTestName(desc, toolchain, config):
+ return '%s.%s_%s_test' % (desc['NAME'], toolchain, config.lower())
+
+
+def IsTestDisabled(desc, toolchain, config):
+ def AsList(value):
+ if type(value) in (list, tuple):
+ return (value,)
+ return value
+
+ test_values = {
+ 'name': desc['NAME'],
+ 'toolchain': toolchain,
+ 'config': config,
+ 'platform': platform
+ }
+
+ for disabled_test in DISABLED_TESTS:
+ for key in test_values:
+ if key in disabled_test:
+ if test_values[key] in AsList(disabled_test[key]):
+ return True
+ return False
+
+
+def WriteHorizontalBar():
+ print '-' * 80
+
+
+def WriteBanner(message):
+ WriteHorizontalBar()
+ print message
+ WriteHorizontalBar()
+
+
+def RunAllTestsInTree(tree, toolchains, configs, retry_on_failure_times):
+ tests_run = 0
+ total_tests = 0
+ failed = []
+ disabled = []
+
+ for _, desc in parse_dsc.GenerateProjects(tree):
+ desc_configs = desc.get('CONFIGS', ALL_CONFIGS)
+ valid_toolchains = set(toolchains) & set(desc['TOOLS'])
+ valid_configs = set(configs) & set(desc_configs)
+ for toolchain in sorted(valid_toolchains):
+ for config in sorted(valid_configs):
+ test_name = GetTestName(desc, toolchain, config)
+ total_tests += 1
+ if IsTestDisabled(desc, toolchain, config):
+ disabled.append(test_name)
+ continue
+
+ tests_run += 1
+ success = RunTestWithGtestOutput(desc, toolchain, config,
+ retry_on_failure_times)
+ if not success:
+ failed.append(test_name)
+
+ if failed:
+ WriteBanner('FAILED TESTS')
+ for test in failed:
+ print ' %s failed.' % test
+
+ if disabled:
+ WriteBanner('DISABLED TESTS')
+ for test in disabled:
+ print ' %s disabled.' % test
+
+ WriteHorizontalBar()
+ print 'Tests run: %d/%d (%d disabled).' % (
+ tests_run, total_tests, len(disabled))
+ print 'Tests succeeded: %d/%d.' % (tests_run - len(failed), tests_run)
+
+ success = len(failed) != 0
+ return success
+
+
+def GetProjectTree(include):
+ # Everything in src is a library, and cannot be run.
+ exclude = {'DEST': 'src'}
+ try:
+ return parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=include,
+ exclude=exclude)
+ except parse_dsc.ValidationError as e:
+ buildbot_common.ErrorExit(str(e))
+
+
+def main(args):
+ parser = optparse.OptionParser()
+ parser.add_option('--config',
+ help='Choose configuration to run (Debug or Release). Runs both '
+ 'by default', action='append')
+ parser.add_option('-x', '--experimental',
+ help='Run experimental projects', action='store_true')
+ parser.add_option('-t', '--toolchain',
+ help='Run using toolchain. Can be passed more than once.',
+ action='append', default=[])
+ parser.add_option('-d', '--dest',
+ help='Select which destinations (project types) are valid.',
+ action='append')
+ parser.add_option('-p', '--project',
+ help='Select which projects are valid.',
+ action='append')
+ parser.add_option('--retry-times',
+ help='Number of types to retry on failure (Default: %default)',
+ type='int', default=DEFAULT_RETRY_ON_FAILURE_TIMES)
+
+ options, args = parser.parse_args(args[1:])
+ if args:
+ parser.error('Not expecting any arguments.')
+
+ if not options.toolchain:
+ options.toolchain = ['newlib', 'glibc', 'pnacl', 'host']
+
+ if 'host' in options.toolchain:
+ options.toolchain.remove('host')
+ options.toolchain.append(platform)
+ print 'Adding platform: ' + platform
+
+ ValidateToolchains(options.toolchain)
+
+ include = {}
+ if options.toolchain:
+ include['TOOLS'] = options.toolchain
+ print 'Filter by toolchain: ' + str(options.toolchain)
+ if not options.experimental:
+ include['EXPERIMENTAL'] = False
+ if options.dest:
+ include['DEST'] = options.dest
+ print 'Filter by type: ' + str(options.dest)
+ if options.project:
+ include['NAME'] = options.project
+ print 'Filter by name: ' + str(options.project)
+ if not options.config:
+ options.config = ALL_CONFIGS
+
+ project_tree = GetProjectTree(include)
+ return RunAllTestsInTree(project_tree, options.toolchain, options.config,
+ options.retry_times)
+
+
+if __name__ == '__main__':
+ script_name = os.path.basename(sys.argv[0])
+ try:
+ sys.exit(main(sys.argv))
+ except parse_dsc.ValidationError as e:
+ buildbot_common.ErrorExit('%s: %s' % (script_name, e))
+ except KeyboardInterrupt:
+ buildbot_common.ErrorExit('%s: interrupted' % script_name)
diff --git a/native_client_sdk/src/build_tools/test_sdk.py b/native_client_sdk/src/build_tools/test_sdk.py
index 67b70904ab..6e7360b8a4 100755
--- a/native_client_sdk/src/build_tools/test_sdk.py
+++ b/native_client_sdk/src/build_tools/test_sdk.py
@@ -12,7 +12,6 @@ import optparse
import os
import subprocess
import sys
-import time
import buildbot_common
import build_projects
@@ -30,12 +29,6 @@ OUT_DIR = os.path.join(SRC_DIR, 'out')
sys.path.append(os.path.join(SDK_SRC_DIR, 'tools'))
import getos
-# TODO(binji): ugly hack -- can I get the browser in a cleaner way?
-sys.path.append(os.path.join(SRC_DIR, 'chrome', 'test', 'nacl_test_injection'))
-import find_chrome
-browser_path = find_chrome.FindChrome(SRC_DIR, ['Debug', 'Release'])
-
-
def StepBuildExamples(pepperdir):
for config in ('Debug', 'Release'):
build_sdk.BuildStepMakeAll(pepperdir, 'examples',
@@ -53,7 +46,7 @@ def StepCopyTests(pepperdir, toolchains, build_experimental):
if not build_experimental:
filters['EXPERIMENTAL'] = False
- tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, filters=filters)
+ tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
build_projects.UpdateHelpers(pepperdir, clobber=False)
build_projects.UpdateProjects(pepperdir, tree, clobber=False,
toolchains=toolchains)
@@ -71,7 +64,7 @@ def StepRunSelLdrTests(pepperdir):
'SEL_LDR': True
}
- tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, filters=filters)
+ tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
def RunTest(test, toolchain, arch, config):
args = ['TOOLCHAIN=%s' % toolchain, 'NACL_ARCH=%s' % arch]
@@ -102,113 +95,22 @@ def StepRunSelLdrTests(pepperdir):
RunTest(location, toolchain, arch, config)
-def StepRunBrowserTests(pepperdir, toolchains, experimental):
+def StepRunBrowserTests(toolchains, experimental):
buildbot_common.BuildStep('Run Tests')
- platform = getos.GetPlatform()
+ args = [
+ sys.executable,
+ os.path.join(SCRIPT_DIR, 'test_projects.py'),
+ ]
- filters = {
- 'DEST': [
- 'examples/api',
- 'examples/demo',
- 'examples/getting_started',
- 'examples/tutorial',
- 'tests'
- ]
- }
- if not experimental:
- filters['EXPERIMENTAL'] = False
+ if experimental:
+ args.append('-x')
+ for toolchain in toolchains:
+ args.extend(['-t', toolchain])
- if not browser_path:
- buildbot_common.ErrorExit('Can\'t find Chrome. Did you build it?')
-
- browser_tester_py = os.path.join(SRC_DIR, 'ppapi', 'native_client', 'tools',
- 'browser_tester', 'browser_tester.py')
-
- # browser_tester imports tools/valgrind/memcheck_analyze, which imports
- # tools/valgrind/common. Well, it tries to, anyway, but instead imports
- # common from PYTHONPATH first (which on the buildbots, is a
- # common/__init__.py file...).
- #
- # Clear the PYTHONPATH so it imports the correct file.
- env = dict(os.environ)
- env['PYTHONPATH'] = ''
-
- failures = []
- tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, filters=filters)
- for dest, desc in parse_dsc.GenerateProjects(tree):
- name = desc['NAME']
- path = os.path.join(pepperdir, *dest.split('/'))
- path = os.path.join(path, name)
-
- for toolchain in desc['TOOLS']:
- if toolchain not in toolchains:
- continue
-
- # TODO(binji): Make a better way to disable tests.
- if name == 'graphics_3d' and platform in ('linux', 'win'):
- continue
-
- for config in desc.get('CONFIGS', ['Debug', 'Release']):
- args = [
- sys.executable,
- browser_tester_py,
- '--browser_path', browser_path,
- '--timeout', '30.0', # seconds
- # Prevent the infobar that shows up when requesting filesystem quota.
- '--browser_flag', '--unlimited-storage',
- ]
-
- args.extend(['--serving_dir', path])
- out_dir = os.path.join(path, toolchain, config)
-
- if toolchain == platform:
- ppapi_plugin = os.path.join(out_dir, name)
- if platform == 'win':
- ppapi_plugin += '.dll'
- else:
- ppapi_plugin += '.so'
- args.extend(['--ppapi_plugin', ppapi_plugin])
-
- if toolchain == 'pnacl':
- args.extend(['--browser_flag', '--enable-pnacl'])
-
- url = 'index.html'
- url += '?tc=%s&config=%s&test=true' % (toolchain, config)
- args.extend(['--url', url])
-
- # Fake gtest-like output
- test_name = '%s.%s_%s_test' % (name, toolchain, config.lower())
-
- print '\n[ RUN ] %s' % test_name
- sys.stdout.flush()
- sys.stderr.flush()
-
- # Don't use buildbot_common.Run here -- we don't wait to exit if the
- # command fails.
- failed = False
- start_time = time.time()
- try:
- subprocess.check_call(args, env=env)
- except subprocess.CalledProcessError:
- failed = True
- failures.append(test_name)
- elapsed = (time.time() - start_time) * 1000
-
- sys.stdout.flush()
- sys.stderr.flush()
- if failed:
- message = '[ FAILED ]'
- else:
- message = '[ OK ]'
- print '%s %s (%d ms)' % (message, test_name, elapsed)
-
- if failures:
- print '-' * 80
- print 'TEST FAILURES'
- print '-' * 80
- for failure in failures:
- print ' %s failed.' % failure
+ try:
+ subprocess.check_call(args)
+ except subprocess.CalledProcessError:
buildbot_common.ErrorExit('Error running tests.')
@@ -239,8 +141,7 @@ def main(args):
('copy_tests', StepCopyTests, pepperdir, toolchains, options.experimental),
('build_tests', StepBuildTests, pepperdir),
('sel_ldr_tests', StepRunSelLdrTests, pepperdir),
- ('browser_tests', StepRunBrowserTests, pepperdir, toolchains,
- options.experimental),
+ ('browser_tests', StepRunBrowserTests, toolchains, options.experimental),
]
if args:
diff --git a/native_client_sdk/src/examples/api/graphics_3d/graphics_3d.cc b/native_client_sdk/src/examples/api/graphics_3d/graphics_3d.cc
index b976c43252..4c852666bd 100644
--- a/native_client_sdk/src/examples/api/graphics_3d/graphics_3d.cc
+++ b/native_client_sdk/src/examples/api/graphics_3d/graphics_3d.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
//-----------------------------------------------------------------------------
// The spinning Cube
diff --git a/native_client_sdk/src/examples/api/graphics_3d/matrix.cc b/native_client_sdk/src/examples/api/graphics_3d/matrix.cc
index b87d496cb1..25778e5fa3 100644
--- a/native_client_sdk/src/examples/api/graphics_3d/matrix.cc
+++ b/native_client_sdk/src/examples/api/graphics_3d/matrix.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
/** @file matrix.cc
* Implements simple matrix manipulation functions.
diff --git a/native_client_sdk/src/examples/demo/drive/drive.cc b/native_client_sdk/src/examples/demo/drive/drive.cc
index 20449ebd97..6632ad0280 100644
--- a/native_client_sdk/src/examples/demo/drive/drive.cc
+++ b/native_client_sdk/src/examples/demo/drive/drive.cc
@@ -135,7 +135,7 @@ int32_t ReadUrl(pp::Instance* instance,
url_request.SetRecordDownloadProgress(false);
- const size_t kReadBufferSize = 16 * 1024;
+ const int32_t kReadBufferSize = 16 * 1024;
uint8_t* buffer_ = new uint8_t[kReadBufferSize];
do {
@@ -257,7 +257,6 @@ int32_t InsertFile(pp::Instance* instance,
Json::Value* root) {
static const char base_url[] =
"https://www.googleapis.com/upload/drive/v2/files";
- const char* method = "POST";
ReadUrlParams p;
p.url = base_url;
@@ -335,8 +334,8 @@ class Instance : public pp::Instance {
Instance::Instance(PP_Instance instance)
: pp::Instance(instance),
- callback_factory_(this),
worker_thread_(this),
+ callback_factory_(this),
is_processing_request_(false) {}
bool Instance::Init(uint32_t /*argc*/,
diff --git a/native_client_sdk/src/examples/demo/earth/earth.cc b/native_client_sdk/src/examples/demo/earth/earth.cc
index d8e35462a5..f363b39eaf 100644
--- a/native_client_sdk/src/examples/demo/earth/earth.cc
+++ b/native_client_sdk/src/examples/demo/earth/earth.cc
@@ -31,6 +31,8 @@
#include "sdk_util/macros.h"
#include "sdk_util/thread_pool.h"
+using namespace sdk_util; // For sdk_util::ThreadPool
+
// Global properties used to setup Earth demo.
namespace {
const float kHugeZ = 1.0e38f;
diff --git a/native_client_sdk/src/examples/demo/nacl_io/example.dsc b/native_client_sdk/src/examples/demo/nacl_io/example.dsc
index a86a5dd635..104c1dd674 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/example.dsc
+++ b/native_client_sdk/src/examples/demo/nacl_io/example.dsc
@@ -1,5 +1,5 @@
{
- 'TOOLS': ['newlib', 'glibc', 'pnacl', 'win'],
+ 'TOOLS': ['newlib', 'glibc', 'pnacl'],
'TARGETS': [
{
'NAME' : 'nacl_io',
@@ -12,7 +12,8 @@
'queue.c',
'queue.h',
],
- 'LIBS': ['nacl_io', 'ppapi', 'pthread']
+ 'DEPS': ['nacl_io'],
+ 'LIBS': ['ppapi', 'pthread']
}
],
'DATA': [
diff --git a/native_client_sdk/src/examples/demo/nacl_io/handlers.c b/native_client_sdk/src/examples/demo/nacl_io/handlers.c
index 2763e03d3b..9182676a5a 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/handlers.c
+++ b/native_client_sdk/src/examples/demo/nacl_io/handlers.c
@@ -120,15 +120,6 @@ static void RemoveFileFromMap(int i) {
}
/**
- * Get a file handle from the g_OpenFiles map.
- * @param[in] i The index of the file handle to get.
- * @return the FILE*, or NULL of there is no open file with that handle.
- */
-static FILE* GetFileFromMap(int i) {
- return (FILE*)GetFromMap((void**)g_OpenFiles, MAX_OPEN_FILES, i);
-}
-
-/**
* Get a file, given a string containing the index.
* @param[in] s The string containing the file index.
* @param[out] file_index The index of this file.
@@ -156,14 +147,6 @@ static int AddDirToMap(DIR* dir) {
static void RemoveDirFromMap(int i) {
RemoveFromMap((void**)g_OpenDirs, MAX_OPEN_DIRS, i);
}
-/**
- * Get a dir handle from the g_OpenDirs map.
- * @param[in] i The index of the dir handle to get.
- * @return the DIR*, or NULL of there is no open dir with that handle.
- */
-static DIR* GetDirFromMap(int i) {
- return (DIR*)GetFromMap((void**)g_OpenDirs, MAX_OPEN_DIRS, i);
-}
/**
* Get a dir, given a string containing the index.
@@ -450,10 +433,7 @@ int HandleFclose(int num_params, char** params, char** output) {
* @param[out] output A string to write informational function output to.
* @return An errorcode; 0 means success, anything else is a failure. */
int HandleStat(int num_params, char** params, char** output) {
- FILE* file;
- int file_index;
const char* filename;
- const char* mode;
int result;
struct stat buf;
diff --git a/native_client_sdk/src/examples/demo/pi_generator/example.dsc b/native_client_sdk/src/examples/demo/pi_generator/example.dsc
index e62adeed80..09a53d5d71 100644
--- a/native_client_sdk/src/examples/demo/pi_generator/example.dsc
+++ b/native_client_sdk/src/examples/demo/pi_generator/example.dsc
@@ -1,11 +1,12 @@
{
- 'TOOLS': ['newlib', 'glibc', 'pnacl', 'win'],
+ 'TOOLS': ['newlib', 'glibc', 'pnacl'],
'TARGETS': [
{
'NAME' : 'pi_generator',
'TYPE' : 'main',
'SOURCES' : ['pi_generator.cc'],
- 'LIBS': ['ppapi_simple', 'nacl_io', 'ppapi_cpp', 'ppapi', 'pthread']
+ 'DEPS': ['ppapi_simple', 'nacl_io', 'ppapi_cpp'],
+ 'LIBS': ['ppapi', 'pthread']
}
],
'DATA': [
diff --git a/native_client_sdk/src/examples/demo/voronoi/voronoi.cc b/native_client_sdk/src/examples/demo/voronoi/voronoi.cc
index 870ffae359..d85d185e04 100644
--- a/native_client_sdk/src/examples/demo/voronoi/voronoi.cc
+++ b/native_client_sdk/src/examples/demo/voronoi/voronoi.cc
@@ -26,6 +26,8 @@
#include "sdk_util/thread_pool.h"
+using namespace sdk_util; // For sdk_util::ThreadPool
+
// Global properties used to setup Voronoi demo.
namespace {
const int kMinRectSize = 4;
diff --git a/native_client_sdk/src/examples/getting_started/simple_hello_world/example.dsc b/native_client_sdk/src/examples/getting_started/simple_hello_world/example.dsc
index 8a7a8de18d..353c7fce09 100644
--- a/native_client_sdk/src/examples/getting_started/simple_hello_world/example.dsc
+++ b/native_client_sdk/src/examples/getting_started/simple_hello_world/example.dsc
@@ -6,7 +6,8 @@
'NAME' : 'simple_hello_world',
'TYPE' : 'main',
'SOURCES' : ['hello_world.c'],
- 'LIBS': ['ppapi_simple', 'nacl_io', 'ppapi_cpp', 'ppapi', 'pthread']
+ 'DEPS': ['ppapi_simple', 'nacl_io', 'ppapi_cpp'],
+ 'LIBS': ['ppapi', 'pthread']
}
],
'DATA': [
diff --git a/native_client_sdk/src/examples/tutorial/debugging/example.dsc b/native_client_sdk/src/examples/tutorial/debugging/example.dsc
index 607ec32516..36ef72639c 100644
--- a/native_client_sdk/src/examples/tutorial/debugging/example.dsc
+++ b/native_client_sdk/src/examples/tutorial/debugging/example.dsc
@@ -12,7 +12,7 @@
'SOURCES' : [
'debugging.c',
],
- 'CCFLAGS': ['-fno-omit-frame-pointer'],
+ 'CFLAGS': ['-fno-omit-frame-pointer'],
'DEPS' : ['error_handling'],
'LIBS' : ['ppapi', 'pthread']
}
diff --git a/native_client_sdk/src/examples/tutorial/dlopen/example.dsc b/native_client_sdk/src/examples/tutorial/dlopen/example.dsc
index d7c1ca18c5..8a1f104f54 100644
--- a/native_client_sdk/src/examples/tutorial/dlopen/example.dsc
+++ b/native_client_sdk/src/examples/tutorial/dlopen/example.dsc
@@ -5,7 +5,8 @@
'NAME': 'dlopen',
'TYPE': 'main',
'SOURCES': ['dlopen.cc'],
- 'LIBS': ['nacl_io', 'dl', 'ppapi_cpp', 'ppapi', 'pthread']
+ 'DEPS': ['nacl_io', 'ppapi_cpp'],
+ 'LIBS': ['dl', 'ppapi', 'pthread']
},
{
'NAME' : 'eightball',
diff --git a/native_client_sdk/src/examples/tutorial/testing/example.dsc b/native_client_sdk/src/examples/tutorial/testing/example.dsc
index 2bf847eea1..40d25a564c 100644
--- a/native_client_sdk/src/examples/tutorial/testing/example.dsc
+++ b/native_client_sdk/src/examples/tutorial/testing/example.dsc
@@ -1,12 +1,14 @@
{
- 'TOOLS': ['glibc', 'newlib', 'pnacl', 'win'],
+ 'TOOLS': ['glibc', 'newlib', 'pnacl'],
'SEL_LDR': True,
'TARGETS': [
{
'NAME' : 'testing',
'TYPE' : 'main',
'SOURCES' : ['testing.cc'],
- 'LIBS' : ['ppapi_simple', 'nacl_io', 'ppapi_cpp', 'ppapi', 'gtest', 'pthread']
+ 'LIBS' : ['ppapi_simple', 'nacl_io', 'ppapi_cpp', 'ppapi', 'gtest', 'pthread'],
+ 'CXXFLAGS': ['-Wno-sign-compare', '-Wno-unused-private-field'],
+ 'CFLAGS_GCC': ['-Wno-unused-local-typedefs'],
}
],
'DATA': [
diff --git a/native_client_sdk/src/libraries/error_handling/error_handling.c b/native_client_sdk/src/libraries/error_handling/error_handling.c
index e2fec208df..a3749da12e 100644
--- a/native_client_sdk/src/libraries/error_handling/error_handling.c
+++ b/native_client_sdk/src/libraries/error_handling/error_handling.c
@@ -1,9 +1,6 @@
-/*
- * Copyright (c) 2013 The Chromium Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
+ * found in the LICENSE file. */
#include <assert.h>
#include <inttypes.h>
@@ -263,4 +260,4 @@ void EHRequestExceptionsJson(EHJsonHandler callback) {
int EHHanderInstalled() {
return s_eh_exception_enabled;
-} \ No newline at end of file
+}
diff --git a/native_client_sdk/src/libraries/error_handling/string_stream.c b/native_client_sdk/src/libraries/error_handling/string_stream.c
index 81046a96f5..b21ab2155b 100644
--- a/native_client_sdk/src/libraries/error_handling/string_stream.c
+++ b/native_client_sdk/src/libraries/error_handling/string_stream.c
@@ -1,8 +1,6 @@
-/*
- * Copyright (c) 2013 The Chromium Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
#include <stdlib.h>
#include <stdio.h>
@@ -49,4 +47,4 @@ int ssprintf(sstream_t* stream, const char* format, ...) {
va_end(args);
return out;
-} \ No newline at end of file
+}
diff --git a/native_client_sdk/src/libraries/gmock/library.dsc b/native_client_sdk/src/libraries/gmock/library.dsc
index d3fb553b92..4cbbb851f8 100644
--- a/native_client_sdk/src/libraries/gmock/library.dsc
+++ b/native_client_sdk/src/libraries/gmock/library.dsc
@@ -19,6 +19,7 @@
],
# gmock-spec-builders.cc:248: error: enumeration value ‘FAIL’ not handled in switch
'CXXFLAGS': ['-Wno-switch-enum'],
+ 'CFLAGS_GCC': ['-Wno-unused-local-typedefs']
}
],
'HEADERS': [
diff --git a/native_client_sdk/src/libraries/gtest/library.dsc b/native_client_sdk/src/libraries/gtest/library.dsc
index 83b5f3614f..310feb117d 100644
--- a/native_client_sdk/src/libraries/gtest/library.dsc
+++ b/native_client_sdk/src/libraries/gtest/library.dsc
@@ -23,8 +23,11 @@
],
# Ignore warnings:
# gtest.cc:2555: error: enumeration value ‘COLOR_DEFAULT’ not handled in switch
- # gtest-typed-test.h:239:47: error: anonymous variadic macros were introduced in C99 [-Werror=variadic-macros]
- 'CXXFLAGS': ['-Wno-switch-enum', '-Wno-variadic-macros'],
+ # gtest-typed-test.h:239:47: error: anonymous variadic macros were introduced in C99
+ # gtest-internal-inl.h:213:8: error: private field 'pretty_' is not used
+ 'CXXFLAGS': ['-Wno-switch-enum', '-Wno-variadic-macros', '-Wno-unused-private-field'],
+ 'CFLAGS_GCC': ['-Wno-unused-local-typedefs'],
+
'INCLUDES': [
# See comment below about gtest-internal-inl.h
'$(NACL_SDK_ROOT)/include/gtest/internal',
diff --git a/native_client_sdk/src/libraries/jsoncpp/library.dsc b/native_client_sdk/src/libraries/jsoncpp/library.dsc
index 44401fd175..9ccc237b44 100644
--- a/native_client_sdk/src/libraries/jsoncpp/library.dsc
+++ b/native_client_sdk/src/libraries/jsoncpp/library.dsc
@@ -17,6 +17,7 @@
'json_value.cpp',
'json_writer.cpp',
],
+ 'CXXFLAGS': ['-Wno-strict-aliasing']
}
],
'HEADERS': [
diff --git a/native_client_sdk/src/libraries/nacl_io/error.h b/native_client_sdk/src/libraries/nacl_io/error.h
index 8f7510e46e..fe6e3048b4 100644
--- a/native_client_sdk/src/libraries/nacl_io/error.h
+++ b/native_client_sdk/src/libraries/nacl_io/error.h
@@ -1,10 +1,11 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_NACL_IO_ERROR_H_
#define LIBRARIES_NACL_IO_ERROR_H_
+namespace nacl_io {
+
struct Error {
// TODO(binji): Add debugging constructor w/ __FILE__, __LINE__.
// crbug.com/247816
@@ -14,4 +15,6 @@ struct Error {
int error;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_ERROR_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/event_emitter.cc b/native_client_sdk/src/libraries/nacl_io/event_emitter.cc
new file mode 100644
index 0000000000..a785c590c0
--- /dev/null
+++ b/native_client_sdk/src/libraries/nacl_io/event_emitter.cc
@@ -0,0 +1,59 @@
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include <assert.h>
+
+#include "nacl_io/event_emitter.h"
+#include "nacl_io/event_listener.h"
+
+#include "sdk_util/auto_lock.h"
+
+namespace nacl_io {
+
+bool operator<(const ScopedEventInfo& src_a, const ScopedEventInfo& src_b) {
+ return src_a.get() < src_b.get();
+}
+
+void EventEmitter::Destroy() {
+ // We can not grab the EmitterLock prior to grabbing the EventListener lock,
+ // however the ref count proves this is the only thread which has a
+ // reference to the emitter at this point so accessing events_ is safe.
+ EventInfoSet_t::iterator it;
+ for (it = events_.begin(); it != events_.end(); it++) {
+ ScopedEventInfo info = *it;
+ info->listener->AbandonedEventInfo(info);
+ }
+}
+
+void EventEmitter::RegisterEventInfo(const ScopedEventInfo& info) {
+ AUTO_LOCK(emitter_lock_);
+
+ events_.insert(info);
+ ChainRegisterEventInfo(info);
+}
+
+void EventEmitter::UnregisterEventInfo(const ScopedEventInfo& info) {
+ AUTO_LOCK(emitter_lock_);
+
+ ChainUnregisterEventInfo(info);
+ events_.erase(info);
+}
+void EventEmitter::RaiseEvent(uint32_t event_bits) {
+ AUTO_LOCK(emitter_lock_);
+
+ EventInfoSet_t::iterator it;
+ for (it = events_.begin(); it != events_.end(); it++) {
+ // If this event is allowed by the filter, signal it
+ ScopedEventInfo info = *it;
+ if (info->filter & event_bits) {
+ info->events |= event_bits & info->filter;
+ info->listener->Signal(info);
+ }
+ }
+}
+
+void EventEmitter::ChainRegisterEventInfo(const ScopedEventInfo& info) {}
+void EventEmitter::ChainUnregisterEventInfo(const ScopedEventInfo& info) {}
+
+} // namespace nacl_io
diff --git a/native_client_sdk/src/libraries/nacl_io/event_emitter.h b/native_client_sdk/src/libraries/nacl_io/event_emitter.h
new file mode 100644
index 0000000000..4cca72fe26
--- /dev/null
+++ b/native_client_sdk/src/libraries/nacl_io/event_emitter.h
@@ -0,0 +1,103 @@
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef LIBRARIES_NACL_IO_EVENT_EMITTER_H_
+#define LIBRARIES_NACL_IO_EVENT_EMITTER_H_
+
+#include <stdint.h>
+
+#include <map>
+#include <set>
+
+#include "nacl_io/error.h"
+
+#include "sdk_util/ref_object.h"
+#include "sdk_util/scoped_ref.h"
+#include "sdk_util/simple_lock.h"
+
+
+namespace nacl_io {
+
+class EventEmitter;
+class EventListener;
+
+// A ref counted object (non POD derived from RefObject) for storing the
+// state of a single signal request. Requests are unique to any
+// FD/EventListener pair.
+struct EventInfo : public sdk_util::RefObject {
+ // User provied data to be returned on EventListener::Wait
+ uint64_t user_data;
+
+ // Bitfield of enum KernelEventType currently signaled.
+ uint32_t events;
+
+ // Bitfield of enum KernelEventType that can signal.
+ uint32_t filter;
+
+ // We do not use a ScopedRef to prevent circular references.
+ EventEmitter* emitter;
+ EventListener* listener;
+ uint32_t id;
+};
+
+typedef sdk_util::ScopedRef<EventInfo> ScopedEventInfo;
+
+// Provide comparison for std::map and std::set
+bool operator<(const ScopedEventInfo& src_a, const ScopedEventInfo& src_b);
+
+typedef std::map<int, ScopedEventInfo> EventInfoMap_t;
+typedef std::set<ScopedEventInfo> EventInfoSet_t;
+
+// EventEmitter
+//
+// The EventEmitter class provides notification of events to EventListeners
+// by registering EventInfo objects and signaling the EventListener
+// whenever thier state is changed.
+//
+// See "Kernel Events" in event_listener.h for additional information.
+class EventEmitter : public sdk_util::RefObject {
+ protected:
+ // Called automatically prior to delete to inform the EventListeners that
+ // this EventEmitter is abandoning an associated EventInfo.
+ virtual void Destroy();
+
+ private:
+ // Register or unregister an EventInfo. The lock of the EventListener
+ // associated with this EventInfo must be held prior to calling these
+ // functions. These functions are private to ensure they are called by the
+ // EventListener.
+ void RegisterEventInfo(const ScopedEventInfo& info);
+ void UnregisterEventInfo(const ScopedEventInfo& info);
+
+ public:
+ // Returns the current state of the emitter as KernelEventType bitfield.
+ virtual uint32_t GetEventStatus() = 0;
+
+ // Returns the type of the emitter (compatible with st_mode in stat)
+ virtual int GetType() = 0;
+
+ protected:
+ // Called by the thread causing the Event.
+ void RaiseEvent(uint32_t events);
+
+ // Provided to allow one EventEmitter to register the same EventInfo with
+ // a child EventEmitter so that they can both signal the EventListener.
+ // Called after registering locally, but while lock is still held.
+ virtual void ChainRegisterEventInfo(const ScopedEventInfo& event);
+
+ // Called before unregistering locally, but while lock is still held.
+ virtual void ChainUnregisterEventInfo(const ScopedEventInfo& event);
+
+private:
+ sdk_util::SimpleLock emitter_lock_;
+ EventInfoSet_t events_;
+ friend class EventListener;
+};
+
+typedef sdk_util::ScopedRef<EventEmitter> ScopedEventEmitter;
+
+} // namespace nacl_io
+
+
+#endif // LIBRARIES_NACL_IO_EVENT_EMITTER_H_ \ No newline at end of file
diff --git a/native_client_sdk/src/libraries/nacl_io/event_listener.cc b/native_client_sdk/src/libraries/nacl_io/event_listener.cc
new file mode 100644
index 0000000000..5eaa0603fc
--- /dev/null
+++ b/native_client_sdk/src/libraries/nacl_io/event_listener.cc
@@ -0,0 +1,243 @@
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+
+#include "nacl_io/error.h"
+#include "nacl_io/event_listener.h"
+#include "nacl_io/kernel_wrap.h"
+#include "nacl_io/osstat.h"
+#include "nacl_io/osunistd.h"
+
+#include "sdk_util/auto_lock.h"
+
+
+namespace nacl_io {
+
+EventListener::EventListener() {
+ pthread_cond_init(&signal_cond_, NULL);
+}
+
+EventListener::~EventListener() {
+ pthread_cond_destroy(&signal_cond_);
+}
+
+// Before we can destroy ourselves, we must first unregister all the
+// EventInfo objects from the various EventListeners
+void EventListener::Destroy() {
+ EventInfoMap_t::iterator it;
+
+ // We do not take the lock since this is the only reference to this object.
+ for (it = event_info_map_.begin(); it != event_info_map_.end(); it++) {
+ if (it->second->emitter) {
+ it->second->emitter->UnregisterEventInfo(it->second);
+ }
+ }
+
+ EventEmitter::Destroy();
+}
+
+uint32_t EventListener::GetEventStatus() {
+ // Always writable, but we can only assume it to be readable if there
+ // is an event waiting.
+ return signaled_.empty() ? KE_WRITE_READY : KE_WRITE_READY | KE_READ_READY;
+}
+
+int EventListener::GetType() {
+ // For lack of a better type, report socket to signify it can be in an
+ // used to signal.
+ return S_IFSOCK;
+}
+
+// Called by EventEmitter, wakes up any blocking threads to verify if the wait
+// conditions have been met.
+void EventListener::Signal(const ScopedEventInfo& info) {
+ AUTO_LOCK(signal_lock_);
+ if (waiting_) {
+ signaled_.insert(info);
+ pthread_cond_broadcast(&signal_cond_);
+ }
+}
+
+static void AbsoluteFromDeltaMS(struct timespec* timeout, int ms_timeout) {
+ if (ms_timeout >= 0) {
+ uint64_t usec = usec_since_epoch();
+ usec += ((int64_t) ms_timeout * 1000);
+
+ timeout->tv_nsec = (usec % 1000000) * 1000;
+ timeout->tv_sec = (usec / 1000000);
+ } else {
+ timeout->tv_sec = 0;
+ timeout->tv_nsec = 0;
+ }
+}
+
+Error EventListener::Wait(EventData* events,
+ int max,
+ int ms_timeout,
+ int* out_count) {
+ *out_count = 0;
+
+ if (max <= 0)
+ return EINVAL;
+
+ if (NULL == events)
+ return EFAULT;
+
+ {
+ AUTO_LOCK(info_lock_);
+
+ // Go through the "live" event infos and see if they are in a signaled state
+ EventInfoMap_t::iterator it = event_info_map_.begin();
+ while ((it != event_info_map_.end()) && (*out_count < max)) {
+ ScopedEventInfo& info = it->second;
+ uint32_t event_bits = info->emitter->GetEventStatus() & info->filter;
+
+ if (event_bits) {
+ events[*out_count].events = event_bits;
+ events[*out_count].user_data = info->user_data;
+ (*out_count)++;
+ }
+
+ it++;
+ }
+ } // End of info_lock scope.
+
+ // We are done if we have a signal or no timeout specified.
+ if ((*out_count > 0) || (0 == ms_timeout))
+ return 0;
+
+ // Compute the absolute time we can wait until.
+ struct timespec timeout;
+ AbsoluteFromDeltaMS(&timeout, ms_timeout);
+
+ // Keep looking if until we receive something.
+ while (0 == *out_count) {
+ // We are now officially waiting.
+ AUTO_LOCK(signal_lock_);
+ waiting_++;
+
+ // If we don't have any signals yet, wait for any Emitter to Signal.
+ while (signaled_.empty()) {
+ int return_code;
+ if (ms_timeout >= 0) {
+ return_code = pthread_cond_timedwait(&signal_cond_,
+ signal_lock_.mutex(),
+ &timeout);
+ } else {
+ return_code = pthread_cond_wait(&signal_cond_, signal_lock_.mutex());
+ }
+
+ Error error(return_code);
+
+ // If there is no error, then we may have been signaled.
+ if (0 == error)
+ break;
+
+ // For any error case:
+ if (ETIMEDOUT == error) {
+ // A "TIMEOUT" is not an error.
+ error = 0;
+ } else {
+ // Otherwise this has gone bad, so return EBADF.
+ error = EBADF;
+ }
+
+ waiting_--;
+ return error;
+ }
+
+ // Copy signals over as long as we have room
+ while (!signaled_.empty() && (*out_count < max)) {
+ EventInfoSet_t::iterator it = signaled_.begin();
+
+ events[*out_count].events = (*it)->events;
+ events[*out_count].user_data = (*it)->user_data;
+ (*out_count)++;
+
+ signaled_.erase(it);
+ }
+
+ // If we are the last thread waiting, clear out the signalled set
+ if (1 == waiting_)
+ signaled_.clear();
+
+ // We are done waiting.
+ waiting_--;
+ }
+
+ return 0;
+}
+
+Error EventListener::Track(int id,
+ const ScopedEventEmitter& emitter,
+ uint32_t filter,
+ uint64_t user_data) {
+ AUTO_LOCK(info_lock_);
+ EventInfoMap_t::iterator it = event_info_map_.find(id);
+
+ // If it's not a streaming type, then it can not be added.
+ if ((emitter->GetType() & (S_IFIFO | S_IFSOCK)) == 0)
+ return EPERM;
+
+ if (it != event_info_map_.end())
+ return EEXIST;
+
+ if (emitter.get() == this)
+ return EINVAL;
+
+ ScopedEventInfo info(new EventInfo);
+ info->emitter = emitter.get();
+ info->listener = this;
+ info->id = id;
+ info->filter = filter;
+ info->user_data = user_data;
+ info->events = 0;
+
+ emitter->RegisterEventInfo(info);
+ event_info_map_[id] = info;
+ return 0;
+}
+
+Error EventListener::Update(int id, uint32_t filter, uint64_t user_data) {
+ AUTO_LOCK(info_lock_);
+ EventInfoMap_t::iterator it = event_info_map_.find(id);
+ if (it == event_info_map_.end())
+ return ENOENT;
+
+ ScopedEventInfo& info = it->second;
+ info->filter = filter;
+ info->user_data = user_data;
+ return 0;
+}
+
+Error EventListener::Free(int id) {
+ AUTO_LOCK(info_lock_);
+ EventInfoMap_t::iterator it = event_info_map_.find(id);
+ if (event_info_map_.end() == it)
+ return ENOENT;
+
+ it->second->emitter->UnregisterEventInfo(it->second);
+ event_info_map_.erase(it);
+ return 0;
+}
+
+void EventListener::AbandonedEventInfo(const ScopedEventInfo& event) {
+ {
+ AUTO_LOCK(info_lock_);
+
+ event->emitter = NULL;
+ event_info_map_.erase(event->id);
+ }
+
+ // EventInfos abandoned by the destroyed emitter must still be kept in
+ // signaled_ set for KE_SHUTDOWN.
+ event->events = KE_SHUTDOWN;
+ Signal(event);
+}
+
+} // namespace nacl_io
diff --git a/native_client_sdk/src/libraries/nacl_io/event_listener.h b/native_client_sdk/src/libraries/nacl_io/event_listener.h
new file mode 100644
index 0000000000..bf2e30761c
--- /dev/null
+++ b/native_client_sdk/src/libraries/nacl_io/event_listener.h
@@ -0,0 +1,149 @@
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef LIBRARIES_NACL_IO_EVENT_LISTENER_H_
+#define LIBRARIES_NACL_IO_EVENT_LISTENER_H_
+
+#include <pthread.h>
+
+#include <map>
+#include <set>
+#include <vector>
+
+#include "nacl_io/error.h"
+#include "nacl_io/event_emitter.h"
+
+#include "sdk_util/scoped_ref.h"
+
+// Kernel Events
+//
+// Certain file objects such as pipes or sockets can become signaled when
+// read or write buffers become available, or when the connection is torn
+// down. EventListener provides a mechanism for a thread to wait on
+// specific events from these objects which are derived from EventEmitters.
+//
+// EventEmitter and EventListener together provide support for an "epoll"
+// like interface. See:
+// http://man7.org/linux/man-pages/man7/epoll.7.html
+//
+// Such that we map the arguments at behavior of
+// epoll_wait maps to Wait, and
+// epoll_ctl maps to Track, Update, Free.
+//
+// Behavior of EventListeners
+// FDs are automatically removed when closed.
+// KE_SHUTDOWN can not be masked.
+// KE_SHUTDOWN is only seen if the hangup happens after Wait starts.
+// Dup'd FDs get their own event info which must also get signaled.
+// Adding a non streaming FD will fail.
+// EventEmitters can also be waited on.
+// It is illegal for an a EventListener to add itself.
+//
+// Locking:
+// EventListener::{Track/Update/Free}
+// AUTO_LOCK(EventListener::info_lock_)
+// EventEmitter::RegisterEventInfo
+// AUTO_LOCK(EventEmitter::emitter_lock_)
+//
+// EventEmitter::Destroy
+// EventListener::AbandonedEventInfo
+// AUTO_LOCK(EventListener::info_lock_)
+//
+// EventListener::RaiseEvent
+// AUTO_LOCK(EventEmitter::emitter_lock_)
+// EventListener::Signal
+// AUTO_LOCK(EventListener::signal_lock_)
+//
+// EventListener::Wait
+// AUTO_LOCK(EventListener::info_lock_)
+// ...
+// AUTO_LOCK(EventListener::signal_lock_)
+// ...
+
+namespace nacl_io {
+
+enum KernelEventType {
+ KE_READ_READY = 1,
+ KE_WRITE_READY = 2,
+ KE_SHUTDOWN = 4
+};
+
+struct EventData {
+ // Bit Mask of signaled KernelEvents
+ uint32_t events;
+ uint64_t user_data;
+};
+
+
+// EventListener
+//
+// The EventListener class provides an object to wait on for specific events
+// from EventEmitter objects. The EventListener becomes signalled for
+// read when events are waiting, making it is also an Emitter.
+class EventListener : public EventEmitter {
+ public:
+ EventListener();
+ ~EventListener();
+
+ protected:
+ // Called prior to free to unregister all EventInfos from the EventEmitters.
+ void Destroy();
+
+ public:
+ // Declared in EventEmitter
+ virtual uint32_t GetEventStatus();
+ virtual int GetType();
+
+ // Called by EventEmitter to signal the Listener that a new event is
+ // available.
+ void Signal(const ScopedEventInfo& info);
+
+ // Wait for one or more previously Tracked events to take place
+ // or until ms_timeout expires, and fills |events| up to |max| limit.
+ // The number of events recored is returned in |count|.
+ Error Wait(EventData* events, int max, int ms_timeout, int* out_count);
+
+ // Tracks a new set of KernelEventTypes for a given unique |id|. The
+ // |user_data| will be returned in the Wait when an event of type |filter|
+ // is received with that |id|.
+ Error Track(int id,
+ const ScopedEventEmitter& emitter,
+ uint32_t filter,
+ uint64_t user_data);
+
+ // Updates the tracking of events for |id|, replacing the |user_data|
+ // that's returned, as well as which events will signal.
+ Error Update(int id, uint32_t filter, uint64_t user_data);
+
+ // Unregisters the existing |id|.
+ Error Free(int id);
+
+ // Notification by EventEmitter that it is abandoning the event. Do not
+ // access the emitter after this.
+ void AbandonedEventInfo(const ScopedEventInfo& event);
+
+ private:
+ // Protects the data in the EventInfo map.
+ sdk_util::SimpleLock info_lock_;
+
+ // Map from ID to live a event info.
+ EventInfoMap_t event_info_map_;
+
+ // Protects waiting_, signaled_ and used with the signal_cond_.
+ sdk_util::SimpleLock signal_lock_;
+ pthread_cond_t signal_cond_;
+
+ // The number of threads currently waiting on this Listener.
+ uint32_t waiting_;
+
+ // Set of event infos signaled during a wait.
+ EventInfoSet_t signaled_;
+};
+
+typedef sdk_util::ScopedRef<EventListener> ScopedEventListener;
+
+} // namespace nacl_io
+
+#endif /* LIBRARIES_NACL_IO_EVENT_LISTENER_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/inode_pool.h b/native_client_sdk/src/libraries/nacl_io/inode_pool.h
index 57bb0f86dc..7bee2e40eb 100644
--- a/native_client_sdk/src/libraries/nacl_io/inode_pool.h
+++ b/native_client_sdk/src/libraries/nacl_io/inode_pool.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_NACL_IO_INODE_POOL_H_
#define LIBRARIES_NACL_IO_INODE_POOL_H_
@@ -13,10 +12,11 @@
#include "pthread.h"
#include "sdk_util/auto_lock.h"
+namespace nacl_io {
class INodePool {
public:
- INodePool() : max_nodes_(0), num_nodes_(0) {}
+ INodePool() : num_nodes_(0), max_nodes_(0) {}
ino_t Acquire() {
AUTO_LOCK(lock_);
@@ -52,7 +52,9 @@ class INodePool {
size_t num_nodes_;
size_t max_nodes_;
std::vector<ino_t> inos_;
- SimpleLock lock_;
+ sdk_util::SimpleLock lock_;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_INODE_POOL_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/ioctl.h b/native_client_sdk/src/libraries/nacl_io/ioctl.h
index 0a730e8568..1d27c61eb5 100644
--- a/native_client_sdk/src/libraries/nacl_io/ioctl.h
+++ b/native_client_sdk/src/libraries/nacl_io/ioctl.h
@@ -1,7 +1,7 @@
/* Copyright 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef LIBRARIES_NACL_IO_IOCTL_H_
#define LIBRARIES_NACL_IO_IOCTL_H_
@@ -22,4 +22,4 @@ struct tioc_nacl_input_string {
const char* buffer;
};
-#endif // LIBRARIES_NACL_IO_NACL_IO_H_
+#endif /* LIBRARIES_NACL_IO_NACL_IO_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc b/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc
index 12b83a3dcd..d93c05b099 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/kernel_handle.h"
#include <errno.h>
@@ -14,6 +14,8 @@
#include "sdk_util/auto_lock.h"
+namespace nacl_io {
+
// It is only legal to construct a handle while the kernel lock is held.
KernelHandle::KernelHandle()
: mount_(NULL), node_(NULL), offs_(0) {}
@@ -21,9 +23,14 @@ KernelHandle::KernelHandle()
KernelHandle::KernelHandle(const ScopedMount& mnt, const ScopedMountNode& node)
: mount_(mnt), node_(node), offs_(0) {}
+KernelHandle::~KernelHandle() {
+ // Force release order for cases where mount_ is not ref'd by mounting.
+ node_.reset(NULL);
+ mount_.reset(NULL);
+}
+
Error KernelHandle::Init(int open_mode) {
if (open_mode & O_APPEND) {
- size_t node_size;
Error error = node_->GetSize(&offs_);
if (error)
return error;
@@ -98,5 +105,4 @@ Error KernelHandle::GetDents(struct dirent* pdir, size_t nbytes, int* cnt) {
return error;
}
-const ScopedRef<MountNode>& KernelHandle::node() { return node_; }
-const ScopedRef<Mount>& KernelHandle::mount() { return mount_; }
+} // namespace nacl_io
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_handle.h b/native_client_sdk/src/libraries/nacl_io/kernel_handle.h
index 0a374c4078..ad2b9002eb 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_handle.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_handle.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_KERNEL_HANDLE_H_
#define LIBRARIES_NACL_IO_KERNEL_HANDLE_H_
@@ -17,13 +17,16 @@
#include "sdk_util/scoped_ref.h"
#include "sdk_util/simple_lock.h"
+namespace nacl_io {
+
// KernelHandle provides a reference counted container for the open
// file information, such as it's mount, node, access type and offset.
// KernelHandle can only be referenced when the KernelProxy lock is held.
-class KernelHandle : public RefObject {
+class KernelHandle : public sdk_util::RefObject {
public:
KernelHandle();
KernelHandle(const ScopedMount& mnt, const ScopedMountNode& node);
+ ~KernelHandle();
Error Init(int open_flags);
@@ -35,19 +38,21 @@ class KernelHandle : public RefObject {
Error Write(const void* buf, size_t nbytes, int* bytes_written);
Error GetDents(struct dirent* pdir, size_t count, int* bytes_written);
- const ScopedRef<MountNode>& node();
- const ScopedRef<Mount>& mount();
+ const ScopedMountNode& node() { return node_; }
+ const ScopedMount& mount() { return mount_; }
private:
- ScopedRef<MountNode> node_;
- ScopedRef<Mount> mount_;
- SimpleLock offs_lock_;
+ ScopedMount mount_;
+ ScopedMountNode node_;
+ sdk_util::SimpleLock offs_lock_;
size_t offs_;
friend class KernelProxy;
DISALLOW_COPY_AND_ASSIGN(KernelHandle);
};
-typedef ScopedRef<KernelHandle> ScopedKernelHandle;
+typedef sdk_util::ScopedRef<KernelHandle> ScopedKernelHandle;
+
+} // namespace nacl_io
#endif // LIBRARIES_NACL_IO_KERNEL_HANDLE_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc
index b237221b3f..c326e1d86d 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include <errno.h>
#include "nacl_io/kernel_intercept.h"
#include "nacl_io/kernel_proxy.h"
@@ -10,6 +10,7 @@
#include "nacl_io/pepper_interface.h"
#include "nacl_io/real_pepper_interface.h"
+using namespace nacl_io;
static KernelProxy* s_kp;
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h
index de9e98e33c..0368e897ed 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_
#define LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_object.cc b/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
index bb67154b62..6cb68faad2 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/kernel_object.h"
#include <assert.h>
@@ -22,6 +22,8 @@
#include "sdk_util/ref_object.h"
#include "sdk_util/scoped_ref.h"
+namespace nacl_io {
+
KernelObject::KernelObject() {
cwd_ = "/";
}
@@ -181,8 +183,8 @@ void KernelObject::FreeAndReassignFD(int fd, const ScopedKernelHandle& handle) {
AUTO_LOCK(handle_lock_);
// If the required FD is larger than the current set, grow the set
- if (fd >= handle_map_.size())
- handle_map_.resize(fd + 1, ScopedRef<KernelHandle>());
+ if (fd >= (int)handle_map_.size())
+ handle_map_.resize(fd + 1);
handle_map_[fd] = handle;
}
@@ -197,3 +199,5 @@ void KernelObject::FreeFD(int fd) {
// Force lower numbered FD to be available first.
std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>());
}
+
+} // namespace nacl_io
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_object.h b/native_client_sdk/src/libraries/nacl_io/kernel_object.h
index 99143b02e4..036ff64e66 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_object.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_object.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_KERNEL_OBJECT_H_
#define LIBRARIES_NACL_IO_KERNEL_OBJECT_H_
@@ -19,6 +19,7 @@
#include "sdk_util/simple_lock.h"
+namespace nacl_io {
// KernelObject provides basic functionality for threadsafe access to kernel
// objects such as the CWD, mount points, file descriptors and file handles.
@@ -81,15 +82,17 @@ private:
MountMap_t mounts_;
// Lock to protect free_fds_ and handle_map_.
- SimpleLock handle_lock_;
+ sdk_util::SimpleLock handle_lock_;
// Lock to protect handle_map_.
- SimpleLock mount_lock_;
+ sdk_util::SimpleLock mount_lock_;
// Lock to protect cwd_.
- SimpleLock cwd_lock_;
+ sdk_util::SimpleLock cwd_lock_;
DISALLOW_COPY_AND_ASSIGN(KernelObject);
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
index 462e1a3de6..8df658933a 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/kernel_proxy.h"
#include <assert.h>
@@ -33,9 +33,7 @@
#define MAXPATHLEN 256
#endif
-// TODO(noelallen) : Grab/Redefine these in the kernel object once available.
-#define USR_ID 1002
-#define GRP_ID 1003
+namespace nacl_io {
KernelProxy::KernelProxy() : dev_(0), ppapi_(NULL) {
}
@@ -642,3 +640,5 @@ int KernelProxy::munmap(void* addr, size_t length) {
return 0;
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h
index 2bbf15bf38..a10d8ac3b9 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_KERNEL_PROXY_H_
#define LIBRARIES_NACL_IO_KERNEL_PROXY_H_
@@ -13,6 +13,8 @@
#include "nacl_io/ostypes.h"
#include "nacl_io/osutime.h"
+namespace nacl_io {
+
class PepperInterface;
// KernelProxy provide one-to-one mapping for libc kernel calls. Calls to the
@@ -124,4 +126,6 @@ protected:
DISALLOW_COPY_AND_ASSIGN(KernelProxy);
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_KERNEL_PROXY_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h b/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h
index ca1ada6af6..105c107cd4 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h
@@ -1,12 +1,14 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_KERNEL_WRAP_H_
#define LIBRARIES_NACL_IO_KERNEL_WRAP_H_
#include <sys/types.h>
+#include <stdint.h>
#include <stdlib.h>
+
#include "nacl_io/ostypes.h"
#include "nacl_io/osutime.h"
#include "sdk_util/macros.h"
@@ -39,11 +41,11 @@ void kernel_wrap_init();
int NAME(access)(const char* path, int amode) NOTHROW;
int NAME(chdir)(const char* path) NOTHROW;
int NAME(chmod)(const char* path, chmod_mode_t mode) NOTHROW;
-int chown(const char* path, uid_t owner, gid_t group);
+int chown(const char* path, uid_t owner, gid_t group) NOTHROW;
int NAME(close)(int fd);
int NAME(dup)(int oldfd) NOTHROW;
int NAME(dup2)(int oldfd, int newfd) NOTHROW;
-int fchown(int fd, uid_t owner, gid_t group);
+int fchown(int fd, uid_t owner, gid_t group) NOTHROW;
#if defined(WIN32)
int _fstat32(int fd, struct _stat32* buf);
int _fstat64(int fd, struct _stat64* buf);
@@ -60,7 +62,7 @@ char* getwd(char* buf) NOTHROW;
int getdents(int fd, void* buf, unsigned int count) NOTHROW;
int ioctl(int d, int request, char* argp) NOTHROW;
int NAME(isatty)(int fd) NOTHROW;
-int lchown(const char* path, uid_t owner, gid_t group);
+int lchown(const char* path, uid_t owner, gid_t group) NOTHROW;
int link(const char* oldpath, const char* newpath) NOTHROW;
off_t NAME(lseek)(int fd, off_t offset, int whence) NOTHROW;
#if defined(WIN32)
@@ -91,6 +93,8 @@ int NAME(unlink)(const char* path) NOTHROW;
int utime(const char* filename, const struct utimbuf* times);
read_ssize_t NAME(write)(int fd, const void* buf, size_t nbyte);
+uint64_t usec_since_epoch();
+
EXTERN_C_END
#endif // LIBRARIES_NACL_IO_KERNEL_WRAP_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc
index 2de85f800c..c32c4b5bef 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <sys/types.h> // Include something that will define __GLIBC__.
@@ -19,6 +18,7 @@
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include "nacl_io/kernel_intercept.h"
@@ -138,7 +138,7 @@ int WRAP(chdir) (const char* pathname) {
return (ki_chdir(pathname)) ? errno : 0;
}
-int chown(const char* path, uid_t owner, gid_t group) {
+int chown(const char* path, uid_t owner, gid_t group) NOTHROW {
return ki_chown(path, owner, group);
}
@@ -155,7 +155,7 @@ int WRAP(dup2)(int fd, int newfd) NOTHROW {
return (ki_dup2(fd, newfd) < 0) ? errno : 0;
}
-int fchown(int fd, uid_t owner, gid_t group) {
+int fchown(int fd, uid_t owner, gid_t group) NOTHROW {
return ki_fchown(fd, owner, group);
}
@@ -231,7 +231,7 @@ int isatty(int fd) NOTHROW {
return ki_isatty(fd);
}
-int lchown(const char* path, uid_t owner, gid_t group) {
+int lchown(const char* path, uid_t owner, gid_t group) NOTHROW {
return ki_lchown(path, owner, group);
}
@@ -264,7 +264,7 @@ int mount(const char* source, const char* target, const char* filesystemtype,
int WRAP(munmap)(void* addr, size_t length) {
// Always let the real munmap run on the address range. It is not an error if
// there are no mapped pages in that range.
- int result = ki_munmap(addr, length);
+ ki_munmap(addr, length);
return REAL(munmap)(addr, length);
}
@@ -424,6 +424,11 @@ int _real_write(int fd, const void *buf, size_t count, size_t *nwrote) {
return REAL(write)(fd, buf, count, nwrote);
}
+uint64_t usec_since_epoch() {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_usec + (tv.tv_sec * 1000000);
+}
void kernel_wrap_init() {
static bool wrapped = false;
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
index d2f824253b..ff5896fda4 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <sys/types.h> // Include something that will define __GLIBC__.
@@ -15,6 +14,7 @@
#include <irt.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include "nacl_io/kernel_intercept.h"
EXTERN_C_BEGIN
@@ -262,6 +262,11 @@ int _real_write(int fd, const void *buf, size_t count, size_t *nwrote) {
return REAL(write)(fd, buf, count, nwrote);
}
+uint64_t usec_since_epoch() {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_usec + (tv.tv_sec * 1000000);
+}
void kernel_wrap_init() {
static bool wrapped = false;
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h
index c4ff5e0e94..b13d7f886b 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_real.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_KERNEL_WRAP_REAL_H_
#define LIBRARIES_NACL_IO_KERNEL_WRAP_REAL_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
index 85bfd0cf06..d99178595b 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
// The entire file is wrapped in this #if. We do this so this .cc file can be
// compiled, even on a non-Windows build.
@@ -308,6 +307,19 @@ int _real_write(int fd, const void *buf, size_t count, size_t *nwrote) {
return 0;
}
+#define USECS_FROM_WIN_TO_TO_UNIX_EPOCH 11644473600000LL
+uint64_t usec_since_epoch() {
+ FILETIME ft;
+ ULARGE_INTEGER ularge;
+ GetSystemTimeAsFileTime(&ft);
+
+ ularge.LowPart = ft.dwLowDateTime;
+ ularge.HighPart = ft.dwHighDateTime;
+
+ // Truncate to usec resolution.
+ return usecs = ularge.QuadPart / 10;
+}
+
// Do nothing for Windows, we replace the library at link time.
void kernel_wrap_init() {
}
diff --git a/native_client_sdk/src/libraries/nacl_io/library.dsc b/native_client_sdk/src/libraries/nacl_io/library.dsc
index a4e85ecde1..6d65846ccd 100644
--- a/native_client_sdk/src/libraries/nacl_io/library.dsc
+++ b/native_client_sdk/src/libraries/nacl_io/library.dsc
@@ -1,5 +1,5 @@
{
- 'TOOLS': ['newlib', 'glibc', 'pnacl', 'win'],
+ 'TOOLS': ['newlib', 'glibc', 'pnacl'],
'SEARCH': [
'.',
'pepper'
@@ -9,6 +9,8 @@
'NAME' : 'nacl_io',
'TYPE' : 'lib',
'SOURCES' : [
+ "event_emitter.cc",
+ "event_listener.cc",
"kernel_handle.cc",
"kernel_intercept.cc",
"kernel_object.cc",
@@ -37,6 +39,8 @@
'HEADERS': [
{
'FILES': [
+ "event_emitter.h",
+ "event_listener.h",
"error.h",
"inode_pool.h",
"ioctl.h",
@@ -63,6 +67,7 @@
"osinttypes.h",
"osmman.h",
"osstat.h",
+ "ostime.h",
"ostypes.h",
"osunistd.h",
"osutime.h",
diff --git a/native_client_sdk/src/libraries/nacl_io/mount.cc b/native_client_sdk/src/libraries/nacl_io/mount.cc
index d944ac96bd..ef5a70a959 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/mount.h"
#include <errno.h>
@@ -20,6 +20,8 @@
#include <windows.h>
#endif
+namespace nacl_io {
+
Mount::Mount() : dev_(0) {}
Mount::~Mount() {}
@@ -60,3 +62,5 @@ void Mount::OnNodeDestroyed(MountNode* node) {
inode_pool_.Release(node->stat_.st_ino);
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount.h b/native_client_sdk/src/libraries/nacl_io/mount.h
index 58cf1a4ed1..4374c9b6f2 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_H_
#define LIBRARIES_NACL_IO_MOUNT_H_
@@ -17,16 +17,18 @@
#include "sdk_util/ref_object.h"
#include "sdk_util/scoped_ref.h"
+namespace nacl_io {
+
class Mount;
class MountNode;
class PepperInterface;
-typedef ScopedRef<Mount> ScopedMount;
+typedef sdk_util::ScopedRef<Mount> ScopedMount;
typedef std::map<std::string, std::string> StringMap_t;
// NOTE: The KernelProxy is the only class that should be setting errno. All
// other classes should return Error (as defined by nacl_io/error.h).
-class Mount : public RefObject {
+class Mount : public sdk_util::RefObject {
protected:
// The protected functions are only used internally and will not
// acquire or release the mount's lock.
@@ -90,4 +92,6 @@ class Mount : public RefObject {
DISALLOW_COPY_AND_ASSIGN(Mount);
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_dev.cc b/native_client_sdk/src/libraries/nacl_io/mount_dev.cc
index e180ef5fad..f409b1985c 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_dev.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_dev.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#if defined(WIN32)
#define _CRT_RAND_S
#endif
@@ -28,6 +28,8 @@
#include <stdlib.h>
#endif
+namespace nacl_io {
+
namespace {
class RealNode : public MountNode {
@@ -413,3 +415,5 @@ Error MountDev::Init(int dev, StringMap_t& args, PepperInterface* ppapi) {
return 0;
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_dev.h b/native_client_sdk/src/libraries/nacl_io/mount_dev.h
index 5d47838b62..a967f5a205 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_dev.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_dev.h
@@ -1,13 +1,15 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_DEV_H_
#define LIBRARIES_NACL_IO_MOUNT_DEV_H_
#include "nacl_io/mount.h"
#include "nacl_io/typed_mount_factory.h"
+namespace nacl_io {
+
class MountNode;
class MountDev : public Mount {
@@ -31,4 +33,6 @@ class MountDev : public Mount {
DISALLOW_COPY_AND_ASSIGN(MountDev);
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_DEV_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_factory.h b/native_client_sdk/src/libraries/nacl_io/mount_factory.h
index 35f77d7609..fd100141f2 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_factory.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_factory.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_FACTORY_H_
#define LIBRARIES_NACL_IO_MOUNT_FACTORY_H_
@@ -11,6 +11,8 @@
#include "nacl_io/error.h"
#include "sdk_util/scoped_ref.h"
+namespace nacl_io {
+
class PepperInterface;
class Mount;
@@ -22,8 +24,10 @@ class MountFactory {
virtual Error CreateMount(int dev,
StringMap_t& args,
PepperInterface* ppapi,
- ScopedRef<Mount>* out_mount) = 0;
+ sdk_util::ScopedRef<Mount>* out_mount) = 0;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_FACTORY_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_html5fs.cc b/native_client_sdk/src/libraries/nacl_io/mount_html5fs.cc
index 3507ae9f74..0394aff899 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_html5fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_html5fs.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "nacl_io/mount_html5fs.h"
@@ -15,6 +14,8 @@
#include "nacl_io/mount_node_html5fs.h"
#include "sdk_util/auto_lock.h"
+namespace nacl_io {
+
namespace {
#if defined(WIN32)
@@ -185,3 +186,5 @@ void MountHtml5Fs::FilesystemOpenCallback(int32_t result) {
pthread_cond_signal(&filesystem_open_cond_);
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_html5fs.h b/native_client_sdk/src/libraries/nacl_io/mount_html5fs.h
index ff104bdbaf..8efa112d30 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_html5fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_html5fs.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_HTML5FS_H_
#define LIBRARIES_NACL_IO_MOUNT_HTML5FS_H_
@@ -12,6 +12,8 @@
#include "nacl_io/typed_mount_factory.h"
#include "sdk_util/simple_lock.h"
+namespace nacl_io {
+
class MountNode;
class MountHtml5Fs : public Mount {
@@ -42,9 +44,11 @@ class MountHtml5Fs : public Mount {
Error filesystem_open_error_; // protected by lock_.
pthread_cond_t filesystem_open_cond_;
- SimpleLock filesysem_open_lock_;
+ sdk_util::SimpleLock filesysem_open_lock_;
friend class TypedMountFactory<MountHtml5Fs>;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_HTML5FS_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_http.cc b/native_client_sdk/src/libraries/nacl_io/mount_http.cc
index 9638746b03..71f65f1bf3 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_http.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_http.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "nacl_io/mount_http.h"
@@ -23,6 +22,8 @@
#include "nacl_io/osinttypes.h"
#include "nacl_io/osunistd.h"
+namespace nacl_io {
+
namespace {
typedef std::vector<char*> StringList_t;
@@ -399,3 +400,5 @@ std::string MountHttp::MakeUrl(const Path& path) {
return url_root_ +
(path.IsAbsolute() ? path.Range(1, path.Size()) : path.Join());
}
+
+} // namespace nacl_io
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_http.h b/native_client_sdk/src/libraries/nacl_io/mount_http.h
index e804f37d5a..761f728d64 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_http.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_http.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_HTTP_H_
#define LIBRARIES_NACL_IO_MOUNT_HTTP_H_
@@ -11,9 +11,12 @@
#include "nacl_io/pepper_interface.h"
#include "nacl_io/typed_mount_factory.h"
-class MountNode;
class MountHttpMock;
+namespace nacl_io {
+
+class MountNode;
+
std::string NormalizeHeaderKey(const std::string& s);
class MountHttp : public Mount {
@@ -55,7 +58,9 @@ class MountHttp : public Mount {
friend class TypedMountFactory<MountHttp>;
friend class MountNodeHttp;
- friend class MountHttpMock;
+ friend class ::MountHttpMock;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_HTTP_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_mem.cc b/native_client_sdk/src/libraries/nacl_io/mount_mem.cc
index 41e0fddef9..715d49a8e4 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_mem.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_mem.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The hromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/mount_mem.h"
#include <errno.h>
@@ -19,6 +19,8 @@
#include "sdk_util/auto_lock.h"
#include "sdk_util/ref_object.h"
+namespace nacl_io {
+
MountMem::MountMem() : root_(NULL) {}
Error MountMem::Init(int dev, StringMap_t& args, PepperInterface* ppapi) {
@@ -221,3 +223,5 @@ Error MountMem::RemoveInternal(const Path& path, int remove_type) {
return parent->RemoveChild(path.Basename());
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_mem.h b/native_client_sdk/src/libraries/nacl_io/mount_mem.h
index 9bd679dba5..04ee66559f 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_mem.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_mem.h
@@ -1,13 +1,15 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_MEM_H_
#define LIBRARIES_NACL_IO_MOUNT_MEM_H_
#include "nacl_io/mount.h"
#include "nacl_io/typed_mount_factory.h"
+namespace nacl_io {
+
class MountMem : public Mount {
protected:
MountMem();
@@ -46,4 +48,6 @@ private:
DISALLOW_COPY_AND_ASSIGN(MountMem);
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_MEM_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node.cc b/native_client_sdk/src/libraries/nacl_io/mount_node.cc
index 81a5df4510..d1d034d07f 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/mount_node.h"
#include <errno.h>
@@ -17,6 +17,8 @@
#include "nacl_io/osmman.h"
#include "sdk_util/auto_lock.h"
+namespace nacl_io {
+
static const int USR_ID = 1001;
static const int GRP_ID = 1002;
@@ -149,3 +151,5 @@ void MountNode::Link() { stat_.st_nlink++; }
void MountNode::Unlink() { stat_.st_nlink--; }
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node.h b/native_client_sdk/src/libraries/nacl_io/mount_node.h
index 749f348a0a..30832dd149 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node.h
@@ -1,30 +1,30 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_NODE_H_
#define LIBRARIES_NACL_IO_MOUNT_NODE_H_
#include <string>
#include "nacl_io/error.h"
+#include "nacl_io/osdirent.h"
#include "nacl_io/osstat.h"
#include "sdk_util/ref_object.h"
#include "sdk_util/scoped_ref.h"
#include "sdk_util/simple_lock.h"
-struct dirent;
-struct stat;
+namespace nacl_io {
class Mount;
class MountNode;
-typedef ScopedRef<MountNode> ScopedMountNode;
+typedef sdk_util::ScopedRef<MountNode> ScopedMountNode;
// NOTE: The KernelProxy is the only class that should be setting errno. All
// other classes should return Error (as defined by nacl_io/error.h).
-class MountNode : public RefObject {
+class MountNode : public sdk_util::RefObject {
protected:
explicit MountNode(Mount* mount);
virtual ~MountNode();
@@ -97,7 +97,7 @@ class MountNode : public RefObject {
protected:
struct stat stat_;
- SimpleLock node_lock_;
+ sdk_util::SimpleLock node_lock_;
// We use a pointer directly to avoid cycles in the ref count.
// TODO(noelallen) We should change this so it's unnecessary for the node
@@ -113,4 +113,6 @@ class MountNode : public RefObject {
friend class MountNodeDir;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_NODE_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc b/native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc
index f2af4db4a5..437d75e838 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_dir.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/mount_node_dir.h"
#include <errno.h>
@@ -12,6 +12,8 @@
#include "sdk_util/auto_lock.h"
#include "sdk_util/macros.h"
+namespace nacl_io {
+
MountNodeDir::MountNodeDir(Mount* mount) : MountNode(mount), cache_(NULL) {
stat_.st_mode |= S_IFDIR;
}
@@ -31,7 +33,7 @@ Error MountNodeDir::Read(size_t offs, void* buf, size_t count, int* out_bytes) {
Error MountNodeDir::FTruncate(off_t size) { return EISDIR; }
Error MountNodeDir::Write(size_t offs,
- void* buf,
+ const void* buf,
size_t count,
int* out_bytes) {
*out_bytes = 0;
@@ -143,3 +145,5 @@ void MountNodeDir::BuildCache() {
}
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_dir.h b/native_client_sdk/src/libraries/nacl_io/mount_node_dir.h
index dd635fe50b..43a95a95a4 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_dir.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_dir.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_NODE_DIR_H_
#define LIBRARIES_NACL_IO_MOUNT_NODE_DIR_H_
@@ -10,7 +10,7 @@
#include "nacl_io/mount_node.h"
-struct dirent;
+namespace nacl_io {
class MountDev;
class MountHtml5Fs;
@@ -18,7 +18,7 @@ class MountHttp;
class MountMem;
class MountNodeDir;
-typedef ScopedRef<MountNodeDir> ScopedMountNodeDir;
+typedef sdk_util::ScopedRef<MountNodeDir> ScopedMountNodeDir;
class MountNodeDir : public MountNode {
protected:
@@ -34,7 +34,8 @@ class MountNodeDir : public MountNode {
size_t count,
int* out_bytes);
virtual Error Read(size_t offs, void *buf, size_t count, int* out_bytes);
- virtual Error Write(size_t offs, void *buf, size_t count, int* out_bytes);
+ virtual Error Write(size_t offs, const void *buf,
+ size_t count, int* out_bytes);
// Adds a finds or adds a directory entry as an INO, updating the refcount
virtual Error AddChild(const std::string& name, const ScopedMountNode& node);
@@ -57,4 +58,6 @@ private:
friend class MountHtml5Fs;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_NODE_DIR_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.cc b/native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.cc
index 4592219b30..09d957ad63 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "nacl_io/mount_node_html5fs.h"
@@ -19,6 +18,8 @@
#include "nacl_io/pepper_interface.h"
#include "sdk_util/auto_lock.h"
+namespace nacl_io {
+
namespace {
struct OutputBuffer {
@@ -305,3 +306,5 @@ void MountNodeHtml5Fs::Destroy() {
MountNode::Destroy();
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.h b/native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.h
index 832d3d40ce..57bc791c3f 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_html5fs.h
@@ -1,13 +1,15 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_HTML5FS_NODE_H_
#define LIBRARIES_NACL_IO_MOUNT_HTML5FS_NODE_H_
#include <ppapi/c/pp_resource.h>
#include "nacl_io/mount_node.h"
+namespace nacl_io {
+
class MountHtml5Fs;
class MountNodeHtml5Fs : public MountNode {
@@ -49,4 +51,6 @@ class MountNodeHtml5Fs : public MountNode {
friend class MountHtml5Fs;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_HTML5FS_NODE_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_http.cc b/native_client_sdk/src/libraries/nacl_io/mount_node_http.cc
index 7f5638f0b0..4dac8bf867 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_http.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_http.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "nacl_io/mount_node_http.h"
@@ -19,6 +18,8 @@
#define snprintf _snprintf
#endif
+namespace nacl_io {
+
namespace {
// If we're attempting to read a partial request, but the server returns a full
@@ -375,8 +376,8 @@ Error MountNodeHttp::DownloadToCache() {
// We don't know how big the file is. Read in chunks.
cached_data_.resize(MAX_READ_BUFFER_SIZE);
- size_t total_bytes_read = 0;
- size_t bytes_to_read = MAX_READ_BUFFER_SIZE;
+ int total_bytes_read = 0;
+ int bytes_to_read = MAX_READ_BUFFER_SIZE;
while (true) {
char* buf = cached_data_.data() + total_bytes_read;
int bytes_read;
@@ -398,14 +399,14 @@ Error MountNodeHttp::DownloadToCache() {
Error MountNodeHttp::ReadPartialFromCache(size_t offs,
void* buf,
- size_t count,
+ int count,
int* out_bytes) {
*out_bytes = 0;
if (offs > cached_data_.size())
return EINVAL;
- count = std::min(count, cached_data_.size() - offs);
+ count = std::min(count, static_cast<int>(cached_data_.size() - offs));
memcpy(buf, &cached_data_.data()[offs], count);
*out_bytes = count;
@@ -507,7 +508,7 @@ Error MountNodeHttp::DownloadPartial(size_t offs,
Error MountNodeHttp::DownloadToBuffer(PP_Resource loader,
void* buf,
- size_t count,
+ int count,
int* out_bytes) {
*out_bytes = 0;
@@ -515,9 +516,9 @@ Error MountNodeHttp::DownloadToBuffer(PP_Resource loader,
URLLoaderInterface* loader_interface = ppapi->GetURLLoaderInterface();
char* out_buffer = static_cast<char*>(buf);
- size_t bytes_to_read = count;
+ int bytes_to_read = count;
while (bytes_to_read > 0) {
- int32_t bytes_read = loader_interface->ReadResponseBody(
+ int bytes_read = loader_interface->ReadResponseBody(
loader, out_buffer, bytes_to_read, PP_BlockUntilComplete());
if (bytes_read == 0) {
@@ -539,3 +540,5 @@ Error MountNodeHttp::DownloadToBuffer(PP_Resource loader,
return 0;
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_http.h b/native_client_sdk/src/libraries/nacl_io/mount_node_http.h
index 6b174681d1..c027ba6218 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_http.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_http.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_NACL_IO_MOUNT_NODE_HTTP_H_
#define LIBRARIES_NACL_IO_MOUNT_NODE_HTTP_H_
@@ -14,6 +13,8 @@
#include "nacl_io/mount_node.h"
#include "nacl_io/pepper_interface.h"
+namespace nacl_io {
+
typedef std::map<std::string, std::string> StringMap_t;
class MountNodeHttp : public MountNode {
@@ -49,12 +50,12 @@ class MountNodeHttp : public MountNode {
Error DownloadToCache();
Error ReadPartialFromCache(size_t offs,
void* buf,
- size_t count,
+ int count,
int* out_bytes);
Error DownloadPartial(size_t offs, void* buf, size_t count, int* out_bytes);
Error DownloadToBuffer(PP_Resource loader,
void* buf,
- size_t count,
+ int count,
int* out_bytes);
std::string url_;
@@ -67,4 +68,6 @@ class MountNodeHttp : public MountNode {
friend class MountHttp;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_NODE_HTTP_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_mem.cc b/native_client_sdk/src/libraries/nacl_io/mount_node_mem.cc
index 5beb0b87b1..e2e2f61f7c 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_mem.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_mem.cc
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/mount_node_mem.h"
#include <errno.h>
@@ -10,6 +10,8 @@
#include "nacl_io/osstat.h"
#include "sdk_util/auto_lock.h"
+namespace nacl_io {
+
#define BLOCK_SIZE (1 << 16)
#define BLOCK_MASK (BLOCK_SIZE - 1)
@@ -93,3 +95,5 @@ Error MountNodeMem::FTruncate(off_t new_size) {
return EIO;
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_mem.h b/native_client_sdk/src/libraries/nacl_io/mount_node_mem.h
index 6457014293..d645cd6df4 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_mem.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_mem.h
@@ -1,12 +1,14 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_NODE_MEM_H_
#define LIBRARIES_NACL_IO_MOUNT_NODE_MEM_H_
#include "nacl_io/mount_node.h"
+namespace nacl_io {
+
class MountNodeMem : public MountNode {
public:
explicit MountNodeMem(Mount* mount);
@@ -29,4 +31,6 @@ class MountNodeMem : public MountNode {
friend class MountMem;
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_NODE_MEM_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_passthrough.cc b/native_client_sdk/src/libraries/nacl_io/mount_passthrough.cc
index 32cde000b2..a84d4c5998 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_passthrough.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_passthrough.cc
@@ -1,11 +1,13 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/mount_passthrough.h"
#include <errno.h>
#include "nacl_io/kernel_wrap_real.h"
+namespace nacl_io {
+
class MountNodePassthrough : public MountNode {
public:
explicit MountNodePassthrough(Mount* mount, int real_fd)
@@ -64,7 +66,10 @@ class MountNodePassthrough : public MountNode {
return ENOSYS;
}
- virtual Error GetDents(size_t offs, struct dirent* pdir, size_t count) {
+ virtual Error GetDents(size_t offs,
+ struct dirent* pdir,
+ size_t count,
+ int* out_bytes) {
size_t nread;
int err = _real_getdents(real_fd_, pdir, count, &nread);
if (err)
@@ -156,3 +161,5 @@ Error MountPassthrough::Remove(const Path& path) {
return ENOSYS;
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_passthrough.h b/native_client_sdk/src/libraries/nacl_io/mount_passthrough.h
index 4d441a0ba7..de4f81ca8a 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_passthrough.h
+++ b/native_client_sdk/src/libraries/nacl_io/mount_passthrough.h
@@ -1,13 +1,15 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_MOUNT_PASSTHROUGH_H_
#define LIBRARIES_NACL_IO_MOUNT_PASSTHROUGH_H_
#include "nacl_io/mount.h"
#include "nacl_io/typed_mount_factory.h"
+namespace nacl_io {
+
class MountPassthrough : public Mount {
protected:
MountPassthrough();
@@ -29,4 +31,6 @@ private:
DISALLOW_COPY_AND_ASSIGN(MountPassthrough);
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_MOUNT_PASSTHROUGH_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/nacl_io.cc b/native_client_sdk/src/libraries/nacl_io/nacl_io.cc
index 29371c9561..5e58a6015b 100644
--- a/native_client_sdk/src/libraries/nacl_io/nacl_io.cc
+++ b/native_client_sdk/src/libraries/nacl_io/nacl_io.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "nacl_io/nacl_io.h"
diff --git a/native_client_sdk/src/libraries/nacl_io/nacl_io.h b/native_client_sdk/src/libraries/nacl_io/nacl_io.h
index b408bb9385..e72b5a5f5a 100644
--- a/native_client_sdk/src/libraries/nacl_io/nacl_io.h
+++ b/native_client_sdk/src/libraries/nacl_io/nacl_io.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef LIBRARIES_NACL_IO_NACL_IO_H_
#define LIBRARIES_NACL_IO_NACL_IO_H_
@@ -114,4 +114,4 @@ int mount(const char* source, const char* target, const char* filesystemtype,
EXTERN_C_END
-#endif // LIBRARIES_NACL_IO_NACL_IO_H_
+#endif /* LIBRARIES_NACL_IO_NACL_IO_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/osdirent.h b/native_client_sdk/src/libraries/nacl_io/osdirent.h
index 39a3b957bb..10e07063c4 100644
--- a/native_client_sdk/src/libraries/nacl_io/osdirent.h
+++ b/native_client_sdk/src/libraries/nacl_io/osdirent.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef LIBRARIES_NACL_IO_OSDIRENT_H_
#define LIBRARIES_NACL_IO_OSDIRENT_H_
@@ -23,4 +23,4 @@ struct dirent {
#endif
-#endif // LIBRARIES_NACL_IO_OSDIRENT_H_
+#endif /* LIBRARIES_NACL_IO_OSDIRENT_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/osinttypes.h b/native_client_sdk/src/libraries/nacl_io/osinttypes.h
index 346d394bcb..438e66f654 100644
--- a/native_client_sdk/src/libraries/nacl_io/osinttypes.h
+++ b/native_client_sdk/src/libraries/nacl_io/osinttypes.h
@@ -1,11 +1,11 @@
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef NACL_IO_OSINTTYPES_H_
#define NACL_IO_OSINTTYPES_H_
-// Define printf/scanf format strings for size_t.
+/* Define printf/scanf format strings for size_t. */
#if defined(WIN32)
@@ -29,6 +29,6 @@
#define SCNuS "zu"
#endif
-#endif // defined(__native_client__)
+#endif /* defined(__native_client__) */
-#endif // NACL_IO_OSINTTYPES_H_
+#endif /* NACL_IO_OSINTTYPES_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/osmman.h b/native_client_sdk/src/libraries/nacl_io/osmman.h
index a652a092b3..9e8e88c999 100644
--- a/native_client_sdk/src/libraries/nacl_io/osmman.h
+++ b/native_client_sdk/src/libraries/nacl_io/osmman.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef LIBRARIES_NACL_IO_OSMMAN_H
#define LIBRARIES_NACL_IO_OSMMAN_H
@@ -24,4 +24,4 @@
#endif
-#endif // LIBRARIES_NACL_IO_OSMMAN_H
+#endif /* LIBRARIES_NACL_IO_OSMMAN_H */
diff --git a/native_client_sdk/src/libraries/nacl_io/osstat.h b/native_client_sdk/src/libraries/nacl_io/osstat.h
index a708b17ebd..ad1cc701ac 100644
--- a/native_client_sdk/src/libraries/nacl_io/osstat.h
+++ b/native_client_sdk/src/libraries/nacl_io/osstat.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef LIBRARIES_NACL_IO_OSSTAT_H_
#define LIBRARIES_NACL_IO_OSSTAT_H_
@@ -13,10 +13,11 @@
#define S_IFIFO _S_IFIFO
#define S_IFREG _S_IFREG
#define S_IFMT _S_IFMT
+#define S_IFSOCK _S_IFIFO
#define S_IREAD _S_IREAD
#define S_IWRITE _S_IWRITE
#define S_IEXEC _S_IEXEC
#endif
-#endif // LIBRARIES_NACL_IO_OSSTAT_H_
+#endif /* LIBRARIES_NACL_IO_OSSTAT_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/ostime.h b/native_client_sdk/src/libraries/nacl_io/ostime.h
new file mode 100644
index 0000000000..a3a92a4a1e
--- /dev/null
+++ b/native_client_sdk/src/libraries/nacl_io/ostime.h
@@ -0,0 +1,26 @@
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef LIBRARIES_NACL_IO_OSTIME_H_
+#define LIBRARIES_NACL_IO_OSTIME_H_
+
+#if defined(WIN32)
+
+#include <pthread.h>
+
+#ifndef CLOCK_REALTIME
+#define CLOCK_REALTIME (clockid_t) 1
+#endif
+
+int clock_gettime(clockid_t clock_id, struct timespec *tp);
+int clock_settime(clockid_t clock_id, const struct timespec *tp);
+
+#else
+
+#include <time.h>
+
+#endif
+
+#endif // LIBRARIES_NACL_IO_OSUNISTD_H_
+
diff --git a/native_client_sdk/src/libraries/nacl_io/ostypes.h b/native_client_sdk/src/libraries/nacl_io/ostypes.h
index 084ec3319f..cc9b6de9aa 100644
--- a/native_client_sdk/src/libraries/nacl_io/ostypes.h
+++ b/native_client_sdk/src/libraries/nacl_io/ostypes.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef LIBRARIES_NACL_IO_OSTYPES_H_
#define LIBRARIES_NACL_IO_OSTYPES_H_
@@ -18,4 +18,4 @@ typedef int gid_t;
#endif
-#endif // LIBRARIES_NACL_IO_OSTYPES_H_
+#endif /* LIBRARIES_NACL_IO_OSTYPES_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/osunistd.h b/native_client_sdk/src/libraries/nacl_io/osunistd.h
index c5da0efe0a..9c0dbca5d7 100644
--- a/native_client_sdk/src/libraries/nacl_io/osunistd.h
+++ b/native_client_sdk/src/libraries/nacl_io/osunistd.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef LIBRARIES_NACL_IO_OSUNISTD_H_
#define LIBRARIES_NACL_IO_OSUNISTD_H_
@@ -18,5 +18,4 @@
#endif
-#endif // LIBRARIES_NACL_IO_OSUNISTD_H_
-
+#endif /* LIBRARIES_NACL_IO_OSUNISTD_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/osutime.h b/native_client_sdk/src/libraries/nacl_io/osutime.h
index 03d98b99a2..8e849d7448 100644
--- a/native_client_sdk/src/libraries/nacl_io/osutime.h
+++ b/native_client_sdk/src/libraries/nacl_io/osutime.h
@@ -1,7 +1,7 @@
/* Copyright 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef LIBRARIES_NACL_IO_OSUTIME_H_
#define LIBRARIES_NACL_IO_OSUTIME_H_
@@ -11,5 +11,4 @@
struct utimbuf;
-#endif // LIBRARIES_NACL_IO_OSUTIME_H_
-
+#endif /* LIBRARIES_NACL_IO_OSUTIME_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/path.cc b/native_client_sdk/src/libraries/nacl_io/path.cc
index 88b6413589..78c0769eed 100644
--- a/native_client_sdk/src/libraries/nacl_io/path.cc
+++ b/native_client_sdk/src/libraries/nacl_io/path.cc
@@ -1,13 +1,15 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/path.h"
#include <stdio.h>
#include <string.h>
#include <string>
+namespace nacl_io {
+
Path::Path() {}
Path::Path(const Path& path) {
@@ -202,3 +204,5 @@ Path& Path::operator =(const std::string& p) {
return Set(p);
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/path.h b/native_client_sdk/src/libraries/nacl_io/path.h
index fcbaa33d67..9131d6a86f 100644
--- a/native_client_sdk/src/libraries/nacl_io/path.h
+++ b/native_client_sdk/src/libraries/nacl_io/path.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_PATH_H_
#define LIBRARIES_NACL_IO_PATH_H_
@@ -10,6 +10,8 @@
#include "sdk_util/macros.h"
+namespace nacl_io {
+
typedef std::vector<std::string> StringArray_t;
class Path {
@@ -66,4 +68,6 @@ class Path {
StringArray_t paths_;
};
+} // namespace nacl_io
+
#endif // PACKAGES_LIBRARIES_NACL_IO_PATH_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h b/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h
index 5bab3b23c4..dbf1daf1d8 100644
--- a/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h
+++ b/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
/* Given an interface like this:
*
diff --git a/native_client_sdk/src/libraries/nacl_io/pepper/define_empty_macros.h b/native_client_sdk/src/libraries/nacl_io/pepper/define_empty_macros.h
index c93b6d8112..4fb479e48e 100644
--- a/native_client_sdk/src/libraries/nacl_io/pepper/define_empty_macros.h
+++ b/native_client_sdk/src/libraries/nacl_io/pepper/define_empty_macros.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString)
#define END_INTERFACE(BaseClass, PPInterface)
diff --git a/native_client_sdk/src/libraries/nacl_io/pepper/undef_macros.h b/native_client_sdk/src/libraries/nacl_io/pepper/undef_macros.h
index 1b75b46d51..d1b8f50c77 100644
--- a/native_client_sdk/src/libraries/nacl_io/pepper/undef_macros.h
+++ b/native_client_sdk/src/libraries/nacl_io/pepper/undef_macros.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#undef BEGIN_INTERFACE
#undef END_INTERFACE
diff --git a/native_client_sdk/src/libraries/nacl_io/pepper_interface.cc b/native_client_sdk/src/libraries/nacl_io/pepper_interface.cc
index 21c346255e..e97c8198a4 100644
--- a/native_client_sdk/src/libraries/nacl_io/pepper_interface.cc
+++ b/native_client_sdk/src/libraries/nacl_io/pepper_interface.cc
@@ -1,11 +1,13 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "nacl_io/pepper_interface.h"
#include <errno.h>
#include <ppapi/c/pp_errors.h>
+namespace nacl_io {
+
ScopedResource::ScopedResource(PepperInterface* ppapi, PP_Resource resource)
: ppapi_(ppapi),
resource_(resource) {
@@ -53,3 +55,4 @@ int PPErrorToErrno(int32_t err) {
return EINVAL;
}
+} // namespace nacl_io
diff --git a/native_client_sdk/src/libraries/nacl_io/pepper_interface.h b/native_client_sdk/src/libraries/nacl_io/pepper_interface.h
index 31915a4e76..9eaec00557 100644
--- a/native_client_sdk/src/libraries/nacl_io/pepper_interface.h
+++ b/native_client_sdk/src/libraries/nacl_io/pepper_interface.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
#define LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
@@ -23,6 +23,8 @@
#include <sdk_util/macros.h>
+namespace nacl_io {
+
// Note: To add a new interface:
//
// 1. Using one of the other interfaces as a template, add your interface to
@@ -98,4 +100,6 @@ class ScopedResource {
DISALLOW_COPY_AND_ASSIGN(ScopedResource);
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/real_pepper_interface.cc b/native_client_sdk/src/libraries/nacl_io/real_pepper_interface.cc
index 861649d1c3..f7743b6861 100644
--- a/native_client_sdk/src/libraries/nacl_io/real_pepper_interface.cc
+++ b/native_client_sdk/src/libraries/nacl_io/real_pepper_interface.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "nacl_io/real_pepper_interface.h"
#include <assert.h>
@@ -9,6 +8,7 @@
#include <ppapi/c/pp_errors.h>
+namespace nacl_io {
#include "nacl_io/pepper/undef_macros.h"
#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
@@ -137,3 +137,5 @@ int32_t RealPepperInterface::InitializeMessageLoop() {
return PP_OK;
}
+} // namespace nacl_io
+
diff --git a/native_client_sdk/src/libraries/nacl_io/real_pepper_interface.h b/native_client_sdk/src/libraries/nacl_io/real_pepper_interface.h
index 2f7fc2fbd4..0bddee171f 100644
--- a/native_client_sdk/src/libraries/nacl_io/real_pepper_interface.h
+++ b/native_client_sdk/src/libraries/nacl_io/real_pepper_interface.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_REAL_PEPPER_INTERFACE_H_
#define LIBRARIES_NACL_IO_REAL_PEPPER_INTERFACE_H_
@@ -10,6 +10,8 @@
#include <ppapi/c/ppb_message_loop.h>
#include "pepper_interface.h"
+namespace nacl_io {
+
// Forward declare interface classes.
#include "nacl_io/pepper/undef_macros.h"
#include "nacl_io/pepper/define_empty_macros.h"
@@ -52,4 +54,6 @@ class RealPepperInterface : public PepperInterface {
#include "nacl_io/pepper/all_interfaces.h"
};
+} // namespace nacl_io
+
#endif // LIBRARIES_NACL_IO_REAL_PEPPER_INTERFACE_H_
diff --git a/native_client_sdk/src/libraries/nacl_io/typed_mount_factory.h b/native_client_sdk/src/libraries/nacl_io/typed_mount_factory.h
index c859b0bb46..824c20e1cd 100644
--- a/native_client_sdk/src/libraries/nacl_io/typed_mount_factory.h
+++ b/native_client_sdk/src/libraries/nacl_io/typed_mount_factory.h
@@ -1,21 +1,23 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_TYPED_MOUNT_FACTORY_H_
#define LIBRARIES_NACL_IO_TYPED_MOUNT_FACTORY_H_
#include "nacl_io/mount.h"
#include "nacl_io/mount_factory.h"
+namespace nacl_io {
+
template <typename T>
class TypedMountFactory : public MountFactory {
public:
virtual Error CreateMount(int dev,
StringMap_t& args,
PepperInterface* ppapi,
- ScopedRef<Mount>* out_mount) {
- ScopedRef<T> mnt(new T());
+ ScopedMount* out_mount) {
+ sdk_util::ScopedRef<T> mnt(new T());
Error error = mnt->Init(dev, args, ppapi);
if (error)
return error;
@@ -25,5 +27,6 @@ class TypedMountFactory : public MountFactory {
}
};
-#endif // LIBRARIES_NACL_IO_TYPED_MOUNT_FACTORY_H_
+} // namespace nacl_io
+#endif // LIBRARIES_NACL_IO_TYPED_MOUNT_FACTORY_H_
diff --git a/native_client_sdk/src/libraries/nacl_io_test/event_test.cc b/native_client_sdk/src/libraries/nacl_io_test/event_test.cc
new file mode 100644
index 0000000000..33a3bb279e
--- /dev/null
+++ b/native_client_sdk/src/libraries/nacl_io_test/event_test.cc
@@ -0,0 +1,359 @@
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+#include "gtest/gtest.h"
+
+#include "nacl_io/event_emitter.h"
+#include "nacl_io/event_listener.h"
+
+
+using namespace nacl_io;
+using namespace sdk_util;
+
+class EventEmitterTester : public EventEmitter {
+ public:
+ EventEmitterTester() : event_status_(0), event_cnt_(0) {}
+
+ void SetEventStatus(uint32_t bits) { event_status_ = bits; }
+ uint32_t GetEventStatus() { return event_status_; }
+
+ int GetType() { return S_IFSOCK; }
+
+ int NumEvents() { return event_cnt_; }
+
+ public:
+ // Make this function public for testing
+ void RaiseEvent(uint32_t events) {
+ EventEmitter::RaiseEvent(events);
+ }
+
+ // Called after registering locally, but while lock is still held.
+ void ChainRegisterEventInfo(const ScopedEventInfo& event) {
+ event_cnt_++;
+ }
+
+ // Called before unregistering locally, but while lock is still held.
+ void ChainUnregisterEventInfo(const ScopedEventInfo& event) {
+ event_cnt_--;
+ }
+
+ protected:
+ uint32_t event_status_;
+ uint32_t event_cnt_;
+};
+
+
+const int MAX_EVENTS = 8;
+
+// IDs for Emitters
+const int ID_EMITTER = 5;
+const int ID_LISTENER = 6;
+const int ID_EMITTER_DUP = 7;
+
+// Kernel Event values
+const uint32_t KE_EXPECTED = 4;
+const uint32_t KE_FILTERED = 2;
+const uint32_t KE_NONE = 0;
+
+// User Data values
+const uint64_t USER_DATA_A = 1;
+const uint64_t USER_DATA_B = 5;
+
+// Timeout durations
+const int TIMEOUT_IMMEDIATE = 0;
+const int TIMEOUT_SHORT= 100;
+const int TIMEOUT_LONG = 500;
+const int TIMEOUT_NEVER = -1;
+const int TIMEOUT_VERY_LONG = 1000;
+
+TEST(EventTest, EmitterBasic) {
+ ScopedRef<EventEmitterTester> emitter(new EventEmitterTester());
+ ScopedRef<EventEmitter> null_emitter;
+
+ ScopedEventListener listener(new EventListener);
+
+ // Verify construction
+ EXPECT_EQ(0, emitter->NumEvents());
+ EXPECT_EQ(0, emitter->GetEventStatus());
+
+ // Verify status
+ emitter->SetEventStatus(KE_EXPECTED);
+ EXPECT_EQ(KE_EXPECTED, emitter->GetEventStatus());
+
+ // Fail to update or free an ID not in the set
+ EXPECT_EQ(ENOENT, listener->Update(ID_EMITTER, KE_EXPECTED, USER_DATA_A));
+ EXPECT_EQ(ENOENT, listener->Free(ID_EMITTER));
+
+ // Fail to Track self
+ EXPECT_EQ(EINVAL, listener->Track(ID_LISTENER,
+ listener,
+ KE_EXPECTED,
+ USER_DATA_A));
+
+ // Set the emitter filter and data
+ EXPECT_EQ(0, listener->Track(ID_EMITTER, emitter, KE_EXPECTED, USER_DATA_A));
+ EXPECT_EQ(1, emitter->NumEvents());
+
+ // Fail to add the same ID
+ EXPECT_EQ(EEXIST,
+ listener->Track(ID_EMITTER, emitter, KE_EXPECTED, USER_DATA_A));
+ EXPECT_EQ(1, emitter->NumEvents());
+
+ int event_cnt = 0;
+ EventData ev[MAX_EVENTS];
+
+ // Do not allow a wait with a zero events count.
+ EXPECT_EQ(EINVAL, listener->Wait(ev, 0, TIMEOUT_IMMEDIATE, &event_cnt));
+
+ // Do not allow a wait with a negative events count.
+ EXPECT_EQ(EINVAL, listener->Wait(ev, -1, TIMEOUT_IMMEDIATE, &event_cnt));
+
+ // Do not allow a wait with a NULL EventData pointer
+ EXPECT_EQ(EFAULT,
+ listener->Wait(NULL, MAX_EVENTS, TIMEOUT_IMMEDIATE, &event_cnt));
+
+ // Return with no events if the Emitter has no signals set.
+ memset(ev, 0, sizeof(ev));
+ event_cnt = 100;
+ emitter->SetEventStatus(KE_NONE);
+ EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, TIMEOUT_IMMEDIATE, &event_cnt));
+ EXPECT_EQ(0, event_cnt);
+
+ // Return with no events if the Emitter has a filtered signals set.
+ memset(ev, 0, sizeof(ev));
+ event_cnt = 100;
+ emitter->SetEventStatus(KE_FILTERED);
+ EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, TIMEOUT_IMMEDIATE, &event_cnt));
+ EXPECT_EQ(0, event_cnt);
+
+ // Return with one event if the Emitter has the expected signal set.
+ memset(ev, 0, sizeof(ev));
+ event_cnt = 100;
+ emitter->SetEventStatus(KE_EXPECTED);
+ EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, TIMEOUT_IMMEDIATE, &event_cnt));
+ EXPECT_EQ(1, event_cnt);
+ EXPECT_EQ(USER_DATA_A, ev[0].user_data);
+ EXPECT_EQ(KE_EXPECTED, ev[0].events);
+
+ // Return with one event containing only the expected signal.
+ memset(ev, 0, sizeof(ev));
+ event_cnt = 100;
+ emitter->SetEventStatus(KE_EXPECTED | KE_FILTERED);
+ EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, TIMEOUT_IMMEDIATE, &event_cnt));
+ EXPECT_EQ(1, event_cnt);
+ EXPECT_EQ(USER_DATA_A, ev[0].user_data);
+ EXPECT_EQ(KE_EXPECTED, ev[0].events);
+
+ // Change the USER_DATA on an existing event
+ EXPECT_EQ(0, listener->Update(ID_EMITTER, KE_EXPECTED, USER_DATA_B));
+
+ // Return with one event signaled with the alternate USER DATA
+ memset(ev, 0, sizeof(ev));
+ event_cnt = 100;
+ emitter->SetEventStatus(KE_EXPECTED | KE_FILTERED);
+ EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, 0, &event_cnt));
+ EXPECT_EQ(1, event_cnt);
+ EXPECT_EQ(USER_DATA_B, ev[0].user_data);
+ EXPECT_EQ(KE_EXPECTED, ev[0].events);
+
+ // Reset the USER_DATA.
+ EXPECT_EQ(0, listener->Update(ID_EMITTER, KE_EXPECTED, USER_DATA_A));
+
+ // Support adding a DUP.
+ EXPECT_EQ(0, listener->Track(ID_EMITTER_DUP,
+ emitter,
+ KE_EXPECTED,
+ USER_DATA_A));
+ EXPECT_EQ(2, emitter->NumEvents());
+
+ // Return unsignaled.
+ memset(ev, 0, sizeof(ev));
+ emitter->SetEventStatus(KE_NONE);
+ event_cnt = 100;
+ EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, TIMEOUT_IMMEDIATE, &event_cnt));
+ EXPECT_EQ(0, event_cnt);
+
+ // Return with two event signaled with expected data.
+ memset(ev, 0, sizeof(ev));
+ emitter->SetEventStatus(KE_EXPECTED);
+ event_cnt = 100;
+ EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, TIMEOUT_IMMEDIATE, &event_cnt));
+ EXPECT_EQ(2, event_cnt);
+ EXPECT_EQ(USER_DATA_A, ev[0].user_data);
+ EXPECT_EQ(KE_EXPECTED, ev[0].events);
+ EXPECT_EQ(USER_DATA_A, ev[1].user_data);
+ EXPECT_EQ(KE_EXPECTED, ev[1].events);
+}
+
+long Duration(struct timeval* start, struct timeval* end) {
+ if (start->tv_usec > end->tv_usec) {
+ end->tv_sec -= 1;
+ end->tv_usec += 1000000;
+ }
+ long cur_time = 1000 * (end->tv_sec - start->tv_sec);
+ cur_time += (end->tv_usec - start->tv_usec) / 1000;
+ return cur_time;
+}
+
+
+// Run a timed wait, and return the average of 8 iterations to reduce
+// chance of false negative on outlier.
+const int TRIES_TO_AVERAGE = 8;
+bool TimedListen(ScopedEventListener& listen,
+ EventData* ev,
+ int ev_max,
+ int ev_expect,
+ int ms_wait,
+ long* duration) {
+
+ struct timeval start;
+ struct timeval end;
+ long total_time = 0;
+
+ for (int a=0; a < TRIES_TO_AVERAGE; a++) {
+ gettimeofday(&start, NULL);
+
+ int signaled;
+
+ EXPECT_EQ(0, listen->Wait(ev, ev_max, ms_wait, &signaled));
+ EXPECT_EQ(signaled, ev_expect);
+
+ if (signaled != ev_expect) {
+ return false;
+ }
+
+ gettimeofday(&end, NULL);
+
+ long cur_time = Duration(&start, &end);
+ total_time += cur_time;
+ }
+
+ *duration = total_time / TRIES_TO_AVERAGE;
+ return true;
+}
+
+
+// NOTE: These timing tests are potentially flaky, the real test is
+// for the zero timeout should be, has the ConditionVariable been waited on?
+// Once we provide a debuggable SimpleCond and SimpleLock we can actually test
+// the correct thing.
+
+// Normal scheduling would expect us to see ~10ms accuracy, but we'll
+// use a much bigger number (yet smaller than the MAX_MS_TIMEOUT).
+const int SCHEDULING_GRANULARITY = 100;
+
+const int EXPECT_ONE_EVENT = 1;
+const int EXPECT_NO_EVENT = 0;
+
+TEST(EventTest, EmitterTimeout) {
+ ScopedRef<EventEmitterTester> emitter(new EventEmitterTester());
+ ScopedEventListener listener(new EventListener());
+ long duration;
+
+ EventData ev[MAX_EVENTS];
+ memset(ev, 0, sizeof(ev));
+ EXPECT_EQ(0, listener->Track(ID_EMITTER, emitter, KE_EXPECTED, USER_DATA_A));
+
+ // Return immediately when emitter is signaled, with no timeout
+ emitter->SetEventStatus(KE_EXPECTED);
+ memset(ev, 0, sizeof(ev));
+ EXPECT_TRUE(TimedListen(listener, ev, MAX_EVENTS, EXPECT_ONE_EVENT,
+ TIMEOUT_IMMEDIATE, &duration));
+ EXPECT_EQ(USER_DATA_A, ev[0].user_data);
+ EXPECT_EQ(KE_EXPECTED, ev[0].events);
+ EXPECT_EQ(0, duration);
+
+ // Return immediately when emitter is signaled, even with timeout
+ emitter->SetEventStatus(KE_EXPECTED);
+ memset(ev, 0, sizeof(ev));
+ EXPECT_TRUE(TimedListen(listener, ev, MAX_EVENTS, EXPECT_ONE_EVENT,
+ TIMEOUT_LONG, &duration));
+ EXPECT_EQ(USER_DATA_A, ev[0].user_data);
+ EXPECT_EQ(KE_EXPECTED, ev[0].events);
+ EXPECT_GT(SCHEDULING_GRANULARITY, duration);
+
+ // Return immediately if Emiiter is already signaled when blocking forever.
+ emitter->SetEventStatus(KE_EXPECTED);
+ memset(ev, 0, sizeof(ev));
+ EXPECT_TRUE(TimedListen(listener, ev, MAX_EVENTS, EXPECT_ONE_EVENT,
+ TIMEOUT_NEVER, &duration));
+ EXPECT_EQ(USER_DATA_A, ev[0].user_data);
+ EXPECT_EQ(KE_EXPECTED, ev[0].events);
+ EXPECT_GT(SCHEDULING_GRANULARITY, duration);
+
+ // Return immediately if Emitter is no signaled when not blocking.
+ emitter->SetEventStatus(KE_NONE);
+ memset(ev, 0, sizeof(ev));
+ EXPECT_TRUE(TimedListen(listener, ev, MAX_EVENTS, EXPECT_NO_EVENT,
+ TIMEOUT_IMMEDIATE, &duration));
+ EXPECT_EQ(0, duration);
+
+ // Wait TIMEOUT_LONG if the emitter is not in a signaled state.
+ emitter->SetEventStatus(KE_NONE);
+ memset(ev, 0, sizeof(ev));
+ EXPECT_TRUE(TimedListen(listener, ev, MAX_EVENTS, EXPECT_NO_EVENT,
+ TIMEOUT_LONG, &duration));
+ EXPECT_LT(TIMEOUT_LONG - 1, duration);
+ EXPECT_GT(TIMEOUT_LONG + SCHEDULING_GRANULARITY, duration);
+}
+
+struct SignalInfo {
+ EventEmitterTester* em;
+ unsigned int ms_wait;
+ uint32_t events;
+};
+
+void *SignalEmitter(void *ptr) {
+ SignalInfo* info = (SignalInfo*) ptr;
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = info->ms_wait * 1000000;
+
+ nanosleep(&ts, NULL);
+
+ info->em->RaiseEvent(info->events);
+ return NULL;
+}
+
+TEST(EventTest, EmitterSignalling) {
+ ScopedRef<EventEmitterTester> emitter(new EventEmitterTester());
+ ScopedEventListener listener(new EventListener);
+
+ SignalInfo siginfo;
+ struct timeval start;
+ struct timeval end;
+ long duration;
+
+ EventData ev[MAX_EVENTS];
+ memset(ev, 0, sizeof(ev));
+ EXPECT_EQ(0, listener->Track(ID_EMITTER, emitter, KE_EXPECTED, USER_DATA_A));
+
+ // Setup another thread to wait 1/4 of the max time, and signal both
+ // an expected, and unexpected value.
+ siginfo.em = emitter.get();
+ siginfo.ms_wait = TIMEOUT_SHORT;
+ siginfo.events = KE_EXPECTED | KE_FILTERED;
+ pthread_t tid;
+ pthread_create(&tid, NULL, SignalEmitter, &siginfo);
+
+ // Wait for the signal from the other thread and time it.
+ gettimeofday(&start, NULL);
+ int cnt = 0;
+ EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, TIMEOUT_VERY_LONG, &cnt));
+ EXPECT_EQ(1, cnt);
+ gettimeofday(&end, NULL);
+
+ // Verify the wait duration, and that we only recieved the expected signal.
+ duration = Duration(&start, &end);
+ EXPECT_GT(TIMEOUT_SHORT + SCHEDULING_GRANULARITY, duration);
+ EXPECT_LT(TIMEOUT_SHORT - 1, duration);
+ EXPECT_EQ(USER_DATA_A, ev[0].user_data);
+ EXPECT_EQ(KE_EXPECTED, ev[0].events);
+}
diff --git a/native_client_sdk/src/libraries/nacl_io_test/example.dsc b/native_client_sdk/src/libraries/nacl_io_test/example.dsc
index 934b25bd8f..220d64c201 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/example.dsc
+++ b/native_client_sdk/src/libraries/nacl_io_test/example.dsc
@@ -1,5 +1,5 @@
{
- 'TOOLS': ['newlib', 'glibc', 'pnacl', 'win'],
+ 'TOOLS': ['newlib', 'glibc', 'pnacl'],
'SEL_LDR': True,
# Need to add ../../examples for common.js
@@ -9,6 +9,7 @@
'NAME' : 'nacl_io_test',
'TYPE' : 'main',
'SOURCES' : [
+ 'event_test.cc',
'kernel_object_test.cc',
'kernel_proxy_mock.cc',
'kernel_proxy_mock.h',
@@ -33,6 +34,8 @@
# referenced before ppapi.
'LIBS': ['gmock', 'ppapi_cpp', 'ppapi', 'gtest', 'pthread'],
'INCLUDES': ['$(NACL_SDK_ROOT)/include/gtest/internal'],
+ 'CXXFLAGS': ['-Wno-sign-compare', '-Wno-unused-private-field'],
+ 'CFLAGS_GCC': ['-Wno-unused-local-typedefs'],
}
],
'DATA': [
diff --git a/native_client_sdk/src/libraries/nacl_io_test/kernel_object_test.cc b/native_client_sdk/src/libraries/nacl_io_test/kernel_object_test.cc
index 7f7f7eadd6..025402f3a5 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/kernel_object_test.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/kernel_object_test.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <errno.h>
#include <fcntl.h>
@@ -18,6 +17,8 @@
#include "gtest/gtest.h"
+using namespace nacl_io;
+
namespace {
class MountNodeRefMock : public MountNode {
@@ -171,7 +172,7 @@ TEST_F(KernelObjectTest, FreeAndReassignFD) {
EXPECT_EQ(2, node->RefCount());
EXPECT_EQ(1, raw_handle->RefCount());
- int fd1 = proxy->AllocateFD(handle);
+ proxy->AllocateFD(handle);
EXPECT_EQ(2, mnt->RefCount());
EXPECT_EQ(2, node->RefCount());
EXPECT_EQ(2, raw_handle->RefCount());
diff --git a/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.cc b/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.cc
index 367569ef13..e3791fa4fa 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "kernel_proxy_mock.h"
#include "nacl_io/kernel_intercept.h"
diff --git a/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.h b/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.h
index defd7deb41..17aee8c7fd 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.h
+++ b/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_mock.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_NACL_IO_TEST_KERNEL_PROXY_MOCK_H_
#define LIBRARIES_NACL_IO_TEST_KERNEL_PROXY_MOCK_H_
@@ -12,7 +11,7 @@
#include "nacl_io/kernel_proxy.h"
-class KernelProxyMock : public KernelProxy {
+class KernelProxyMock : public nacl_io::KernelProxy {
public:
KernelProxyMock();
virtual ~KernelProxyMock();
diff --git a/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_test.cc b/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_test.cc
index 2d61cbc431..b572078959 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_test.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/kernel_proxy_test.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <errno.h>
#include <fcntl.h>
@@ -25,6 +24,9 @@
#include "nacl_io/path.h"
#include "nacl_io/typed_mount_factory.h"
+using namespace nacl_io;
+using namespace sdk_util;
+
using ::testing::_;
using ::testing::DoAll;
using ::testing::Invoke;
diff --git a/native_client_sdk/src/libraries/nacl_io_test/kernel_wrap_test.cc b/native_client_sdk/src/libraries/nacl_io_test/kernel_wrap_test.cc
index 53856a46dd..f16bd476af 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/kernel_wrap_test.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/kernel_wrap_test.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <string>
#include <vector>
@@ -11,6 +10,8 @@
#include "nacl_io/kernel_wrap.h"
#include "kernel_proxy_mock.h"
+using namespace nacl_io;
+
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
@@ -273,7 +274,7 @@ TEST_F(KernelWrapTest, unlink) {
}
TEST_F(KernelWrapTest, utime) {
- const struct utimbuf* times;
+ const struct utimbuf* times = NULL;
EXPECT_CALL(mock, utime(StrEq("utime"), times));
utime("utime", times);
}
diff --git a/native_client_sdk/src/libraries/nacl_io_test/mock_util.h b/native_client_sdk/src/libraries/nacl_io_test/mock_util.h
index 84145bf5bb..290d6cdede 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/mock_util.h
+++ b/native_client_sdk/src/libraries/nacl_io_test/mock_util.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_NACL_IO_TEST_MOCK_UTIL_H_
#define LIBRARIES_NACL_IO_TEST_MOCK_UTIL_H_
diff --git a/native_client_sdk/src/libraries/nacl_io_test/mount_html5fs_test.cc b/native_client_sdk/src/libraries/nacl_io_test/mount_html5fs_test.cc
index a14ef0fae0..b64770dd24 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/mount_html5fs_test.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/mount_html5fs_test.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <errno.h>
#include <fcntl.h>
@@ -21,6 +20,9 @@
#include "nacl_io/osunistd.h"
#include "pepper_interface_mock.h"
+using namespace nacl_io;
+using namespace sdk_util;
+
using ::testing::_;
using ::testing::DoAll;
using ::testing::Invoke;
diff --git a/native_client_sdk/src/libraries/nacl_io_test/mount_http_test.cc b/native_client_sdk/src/libraries/nacl_io_test/mount_http_test.cc
index 3d4facc691..926fe28e09 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/mount_http_test.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/mount_http_test.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <fcntl.h>
#include <gmock/gmock.h>
@@ -19,6 +18,8 @@
#include "nacl_io/osunistd.h"
#include "pepper_interface_mock.h"
+using namespace nacl_io;
+
using ::testing::_;
using ::testing::DoAll;
using ::testing::Mock;
@@ -293,7 +294,6 @@ void MountHttpNodeTest::SetResponseExpectFail(int status_code,
ON_CALL(*response_, GetProperty(response_resource_, _))
.WillByDefault(Return(PP_MakeUndefined()));
- PP_Var var_headers = MakeString(348);
EXPECT_CALL(*response_,
GetProperty(response_resource_,
PP_URLRESPONSEPROPERTY_STATUSCODE))
diff --git a/native_client_sdk/src/libraries/nacl_io_test/mount_mock.cc b/native_client_sdk/src/libraries/nacl_io_test/mount_mock.cc
index 4b69108e21..1006822ed2 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/mount_mock.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/mount_mock.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "mount_mock.h"
diff --git a/native_client_sdk/src/libraries/nacl_io_test/mount_mock.h b/native_client_sdk/src/libraries/nacl_io_test/mount_mock.h
index 7ceebc47b9..10d1cf230a 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/mount_mock.h
+++ b/native_client_sdk/src/libraries/nacl_io_test/mount_mock.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_NACL_IO_TEST_MOUNT_MOCK_H_
#define LIBRARIES_NACL_IO_TEST_MOUNT_MOCK_H_
@@ -10,8 +9,14 @@
#include "nacl_io/mount.h"
-class MountMock : public Mount {
+class MountMock : public nacl_io::Mount {
public:
+ typedef nacl_io::Error Error;
+ typedef nacl_io::Path Path;
+ typedef nacl_io::PepperInterface PepperInterface;
+ typedef nacl_io::ScopedMountNode ScopedMountNode;
+ typedef nacl_io::StringMap_t StringMap_t;
+
MountMock();
virtual ~MountMock();
@@ -27,4 +32,3 @@ class MountMock : public Mount {
};
#endif // LIBRARIES_NACL_IO_TEST_MOUNT_MOCK_H_
-
diff --git a/native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.cc b/native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.cc
index b925b56633..695af3adc6 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.cc
@@ -1,11 +1,10 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "mount_node_mock.h"
-MountNodeMock::MountNodeMock(Mount* mount) : MountNode(mount) {}
+MountNodeMock::MountNodeMock(nacl_io::Mount* mount) : MountNode(mount) {}
MountNodeMock::~MountNodeMock() {}
diff --git a/native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.h b/native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.h
index dbbfda1497..3354682c7b 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.h
+++ b/native_client_sdk/src/libraries/nacl_io_test/mount_node_mock.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_NACL_IO_TEST_MOUNT_NODE_MOCK_H_
#define LIBRARIES_NACL_IO_TEST_MOUNT_NODE_MOCK_H_
@@ -10,9 +9,12 @@
#include "nacl_io/mount.h"
-class MountNodeMock : public MountNode {
+class MountNodeMock : public nacl_io::MountNode {
public:
- explicit MountNodeMock(Mount*);
+ typedef nacl_io::Error Error;
+ typedef nacl_io::ScopedMountNode ScopedMountNode;
+
+ explicit MountNodeMock(nacl_io::Mount*);
virtual ~MountNodeMock();
MOCK_METHOD1(Init, Error(int));
@@ -41,4 +43,3 @@ class MountNodeMock : public MountNode {
};
#endif // LIBRARIES_NACL_IO_TEST_MOUNT_NODE_MOCK_H_
-
diff --git a/native_client_sdk/src/libraries/nacl_io_test/mount_node_test.cc b/native_client_sdk/src/libraries/nacl_io_test/mount_node_test.cc
index 794bbdfbf4..875122ab33 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/mount_node_test.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/mount_node_test.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <errno.h>
#include <fcntl.h>
@@ -19,6 +18,8 @@
#define NULL_NODE ((MountNode*) NULL)
+using namespace nacl_io;
+
static int s_AllocNum = 0;
class MockMemory : public MountNodeMem {
diff --git a/native_client_sdk/src/libraries/nacl_io_test/mount_test.cc b/native_client_sdk/src/libraries/nacl_io_test/mount_test.cc
index e04f513587..cc1c437dbf 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/mount_test.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/mount_test.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <errno.h>
#include <fcntl.h>
@@ -17,6 +16,8 @@
#include "nacl_io/osdirent.h"
#include "nacl_io/osunistd.h"
+using namespace nacl_io;
+
namespace {
class MountMemMock : public MountMem {
diff --git a/native_client_sdk/src/libraries/nacl_io_test/path_test.cc b/native_client_sdk/src/libraries/nacl_io_test/path_test.cc
index 9a8d980b34..ab12f3995e 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/path_test.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/path_test.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <fcntl.h>
#include "nacl_io/kernel_proxy.h"
@@ -9,6 +8,8 @@
#include "gtest/gtest.h"
+using namespace nacl_io;
+
TEST(PathTest, SanityChecks) {
// can we construct and delete?
Path ph1(".");
diff --git a/native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.cc b/native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.cc
index a3418a6d34..18f14efc05 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "pepper_interface_mock.h"
diff --git a/native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.h b/native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.h
index c11cce890d..ae4b579668 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.h
+++ b/native_client_sdk/src/libraries/nacl_io_test/pepper_interface_mock.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#ifndef LIBRARIES_NACL_IO_TEST_PEPPER_INTERFACE_MOCK_H_
#define LIBRARIES_NACL_IO_TEST_PEPPER_INTERFACE_MOCK_H_
@@ -11,7 +11,7 @@
// Mock interface class definitions.
#include "nacl_io/pepper/undef_macros.h"
#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
- class BaseClass##Mock : public BaseClass { \
+ class BaseClass##Mock : public nacl_io::BaseClass { \
public: \
BaseClass##Mock(); \
virtual ~BaseClass##Mock();
@@ -31,7 +31,7 @@
#include "nacl_io/pepper/all_interfaces.h"
-class PepperInterfaceMock : public PepperInterface {
+class PepperInterfaceMock : public nacl_io::PepperInterface {
public:
explicit PepperInterfaceMock(PP_Instance instance);
~PepperInterfaceMock();
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps.cc b/native_client_sdk/src/libraries/ppapi_simple/ps.cc
index eba3c4030b..540488f11d 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps.cc
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_module.h"
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_event.cc b/native_client_sdk/src/libraries/ppapi_simple/ps_event.cc
index ac68fe9b59..daecb4062a 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_event.cc
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_event.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_module.h"
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc
index fb92ca54b2..741697c452 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc
@@ -93,8 +93,8 @@ PSInstance::PSInstance(PP_Instance instance, const char *argv[])
pp::MouseLock(this),
pp::Graphics3DClient(this),
main_loop_(NULL),
- verbosity_(PSV_WARN),
events_enabled_(PSE_NONE),
+ verbosity_(PSV_WARN),
fd_tty_(-1) {
// Set the single Instance object
s_InstanceObject = this;
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h
index f02d574d5c..cf97714cb7 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h
@@ -124,7 +124,7 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
pp::MessageLoop* main_loop_;
PropertyMap_t properties_;
- ThreadSafeQueue<PSEvent> event_queue_;
+ sdk_util::ThreadSafeQueue<PSEvent> event_queue_;
uint32_t events_enabled_;
Verbosity verbosity_;
int fd_tty_;
@@ -134,9 +134,6 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
const PPB_Core* ppb_core_;
const PPB_Var* ppb_var_;
const PPB_View* ppb_view_;
-
- friend class PSGraphics3DClient;
- friend class PSMouseLock;
};
#endif // PPAPI_MAIN_PS_INSTANCE_H_
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc b/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc
index 302aeaf44b..1e8cc8dc1f 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_module.h"
diff --git a/native_client_sdk/src/libraries/sdk_util/atomicops.h b/native_client_sdk/src/libraries/sdk_util/atomicops.h
index cd07b44118..5a0c0195d5 100644
--- a/native_client_sdk/src/libraries/sdk_util/atomicops.h
+++ b/native_client_sdk/src/libraries/sdk_util/atomicops.h
@@ -1,7 +1,6 @@
/* Copyright 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
#ifndef LIBRARIES_SDK_UTIL_ATOMICOPS_H_
#define LIBRARIES_SDK_UTIL_ATOMICOPS_H_
@@ -9,6 +8,9 @@
#ifndef WIN32
#include <stdint.h>
+
+namespace sdk_util {
+
typedef int32_t Atomic32;
#ifndef __llvm__
@@ -39,7 +41,9 @@ inline Atomic32 AtomicXorFetch(volatile Atomic32* ptr, Atomic32 value) {
return __sync_xor_and_fetch(ptr, value);
}
-#else
+} // namespace sdk_util
+
+#else // ifndef WIN32
#include <windows.h>
@@ -49,6 +53,8 @@ inline Atomic32 AtomicXorFetch(volatile Atomic32* ptr, Atomic32 value) {
#undef PostMessage
#undef interface
+namespace sdk_util {
+
typedef long Atomic32;
/* Windows.h already defines a MemoryBarrier macro. */
@@ -96,7 +102,8 @@ inline Atomic32 AtomicXorFetch(volatile Atomic32* ptr, Atomic32 value) {
return newval;
}
-#endif
+} // namespace sdk_util
+#endif // ifndef WIN32
#endif /* LIBRARIES_SDK_UTIL_ATOMICOPS_H_ */
diff --git a/native_client_sdk/src/libraries/sdk_util/auto_lock.h b/native_client_sdk/src/libraries/sdk_util/auto_lock.h
index b60fd8dee1..b4892691f1 100644
--- a/native_client_sdk/src/libraries/sdk_util/auto_lock.h
+++ b/native_client_sdk/src/libraries/sdk_util/auto_lock.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_SDK_UTIL_AUTO_LOCK_H_
#define LIBRARIES_SDK_UTIL_AUTO_LOCK_H_
@@ -10,11 +9,12 @@
#include "sdk_util/macros.h"
#include "sdk_util/simple_lock.h"
+namespace sdk_util {
// This macro is provided to allow us to quickly instrument locking for
// debugging purposes.
#define AUTO_LOCK(lock) \
- AutoLock Lock##__LINE__(lock);
+ ::sdk_util::AutoLock Lock##__LINE__(lock);
class AutoLock {
public:
@@ -38,5 +38,6 @@ class AutoLock {
DISALLOW_COPY_AND_ASSIGN(AutoLock);
};
-#endif // LIBRARIES_SDK_UTIL_AUTO_LOCK_H_
+} // namespace sdk_util
+#endif // LIBRARIES_SDK_UTIL_AUTO_LOCK_H_
diff --git a/native_client_sdk/src/libraries/sdk_util/macros.h b/native_client_sdk/src/libraries/sdk_util/macros.h
index fd15dc38c8..e2e5400895 100644
--- a/native_client_sdk/src/libraries/sdk_util/macros.h
+++ b/native_client_sdk/src/libraries/sdk_util/macros.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
+
#ifndef LIBRARIES_SDK_UTIL_MACROS_H_
#define LIBRARIES_SDK_UTIL_MACROS_H_
@@ -47,4 +47,3 @@
}
#endif /* LIBRARIES_SDK_UTIL_MACROS_H_ */
-
diff --git a/native_client_sdk/src/libraries/sdk_util/ref_object.h b/native_client_sdk/src/libraries/sdk_util/ref_object.h
index 88fcee9b8e..707a335e17 100644
--- a/native_client_sdk/src/libraries/sdk_util/ref_object.h
+++ b/native_client_sdk/src/libraries/sdk_util/ref_object.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_SDK_UTIL_REF_OBJECT
#define LIBRARIES_SDK_UTIL_REF_OBJECT
@@ -11,6 +10,8 @@
#include "sdk_util/atomicops.h"
+namespace sdk_util {
+
class ScopedRefBase;
/*
@@ -67,5 +68,7 @@ class RefObject {
friend class ScopedRefBase;
};
+} // namespace sdk_util
+
#endif // LIBRARIES_SDK_UTIL_REF_OBJECT
diff --git a/native_client_sdk/src/libraries/sdk_util/scoped_ref.h b/native_client_sdk/src/libraries/sdk_util/scoped_ref.h
index 841f12bb66..48c4eb9b9f 100644
--- a/native_client_sdk/src/libraries/sdk_util/scoped_ref.h
+++ b/native_client_sdk/src/libraries/sdk_util/scoped_ref.h
@@ -1,7 +1,6 @@
-/* Copyright 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_SDK_UTIL_SCOPED_REF_H_
#define LIBRARIES_SDK_UTIL_SCOPED_REF_H_
@@ -11,6 +10,8 @@
#include "sdk_util/macros.h"
#include "sdk_util/ref_object.h"
+namespace sdk_util {
+
class ScopedRefBase {
protected:
ScopedRefBase() : ptr_(NULL) {}
@@ -80,4 +81,6 @@ class ScopedRef : public ScopedRefBase {
}
};
+} // namespace sdk_util
+
#endif // LIBRARIES_SDK_UTIL_SCOPED_REF_H_
diff --git a/native_client_sdk/src/libraries/sdk_util/simple_lock.h b/native_client_sdk/src/libraries/sdk_util/simple_lock.h
index 6f5d006486..90f0ad9ee6 100644
--- a/native_client_sdk/src/libraries/sdk_util/simple_lock.h
+++ b/native_client_sdk/src/libraries/sdk_util/simple_lock.h
@@ -1,7 +1,6 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
#define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
@@ -9,6 +8,8 @@
#include "pthread.h"
#include "sdk_util/macros.h"
+namespace sdk_util {
+
/*
* SimpleLock
*
@@ -33,5 +34,6 @@ class SimpleLock {
DISALLOW_COPY_AND_ASSIGN(SimpleLock);
};
-#endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
+} // namespace sdk_util
+#endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
diff --git a/native_client_sdk/src/libraries/sdk_util/thread_pool.cc b/native_client_sdk/src/libraries/sdk_util/thread_pool.cc
index 1a2d2b8d29..1d4e2cb3f7 100644
--- a/native_client_sdk/src/libraries/sdk_util/thread_pool.cc
+++ b/native_client_sdk/src/libraries/sdk_util/thread_pool.cc
@@ -11,6 +11,8 @@
#include "sdk_util/auto_lock.h"
+namespace sdk_util {
+
// Initializes mutex, semaphores and a pool of threads. If 0 is passed for
// num_threads, all work will be performed on the dispatch thread.
ThreadPool::ThreadPool(int num_threads)
@@ -60,7 +62,7 @@ void ThreadPool::Setup(int counter, WorkFunction work, void *data) {
// Return decremented task counter. This function
// can be called from multiple threads at any given time.
int ThreadPool::DecCounter() {
- return AtomicAddFetch(&counter_, 1);
+ return AtomicAddFetch(&counter_, -1);
}
// Set exit flag, post and join all the threads in the pool. This function is
@@ -134,3 +136,5 @@ void ThreadPool::Dispatch(int num_tasks, WorkFunction work, void* data) {
DispatchHere(num_tasks, work, data);
}
+} // namespace sdk_util
+
diff --git a/native_client_sdk/src/libraries/sdk_util/thread_pool.h b/native_client_sdk/src/libraries/sdk_util/thread_pool.h
index 7482347f5d..332a69fdb7 100644
--- a/native_client_sdk/src/libraries/sdk_util/thread_pool.h
+++ b/native_client_sdk/src/libraries/sdk_util/thread_pool.h
@@ -12,6 +12,8 @@
#include "sdk_util/atomicops.h"
+namespace sdk_util {
+
// typdef helper for work function
typedef void (*WorkFunction)(int task_index, void* data);
@@ -43,5 +45,8 @@ class ThreadPool {
sem_t work_sem_;
sem_t done_sem_;
};
+
+} // namespace sdk_util
+
#endif // LIBRARIES_SDK_UTIL_THREAD_POOL_H_
diff --git a/native_client_sdk/src/libraries/sdk_util/thread_safe_queue.h b/native_client_sdk/src/libraries/sdk_util/thread_safe_queue.h
index 5dad028747..37842dba86 100644
--- a/native_client_sdk/src/libraries/sdk_util/thread_safe_queue.h
+++ b/native_client_sdk/src/libraries/sdk_util/thread_safe_queue.h
@@ -12,6 +12,7 @@
#include "sdk_util/auto_lock.h"
#include "sdk_util/macros.h"
+namespace sdk_util {
// ThreadSafeQueue
//
@@ -57,5 +58,7 @@ template<class T> class ThreadSafeQueue {
DISALLOW_COPY_AND_ASSIGN(ThreadSafeQueue);
};
+} // namespace sdk_util
+
#endif // LIBRARIES_SDK_UTIL_THREAD_SAFE_QUEUE_H_
diff --git a/native_client_sdk/src/libraries/xray/browser.c b/native_client_sdk/src/libraries/xray/browser.c
new file mode 100644
index 0000000000..e85d1be7ca
--- /dev/null
+++ b/native_client_sdk/src/libraries/xray/browser.c
@@ -0,0 +1,132 @@
+/* Copyright 2013 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file. */
+
+
+/* XRay -- a simple profiler for Native Client */
+
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+
+#include <alloca.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "ppapi/c/dev/ppb_trace_event_dev.h"
+#include "xray/xray_priv.h"
+
+
+#if defined(XRAY)
+static PPB_Trace_Event_Dev* ppb_trace_event_interface = NULL;
+
+static const char* XRayGetName(struct XRaySymbolTable* symbols,
+ struct XRayTraceBufferEntry* e) {
+ uint32_t addr = XRAY_EXTRACT_ADDR(e->depth_addr);
+ struct XRaySymbol* symbol = XRaySymbolTableLookup(symbols, addr);
+ return XRaySymbolGetName(symbol);
+}
+
+struct XRayTimestampPair XRayGenerateTimestampsNow(void) {
+ struct XRayTimestampPair pair;
+ assert(ppb_trace_event_interface);
+
+ XRayGetTSC(&pair.xray);
+ pair.pepper = ppb_trace_event_interface->Now();
+ return pair;
+}
+
+
+void XRayBrowserTraceReport(struct XRayTraceCapture* capture) {
+
+ const void* cat_enabled = ppb_trace_event_interface->GetCategoryEnabled(
+ "xray");
+ struct XRaySymbolTable* symbols = XRayGetSymbolTable(capture);
+
+ int32_t thread_id = XRayGetSavedThreadID(capture);
+
+ int head = XRayFrameGetHead(capture);
+ int frame = XRayFrameGetTail(capture);
+ while(frame != head) {
+
+ struct XRayTimestampPair start_time = XRayFrameGetStartTimestampPair(
+ capture, frame);
+ struct XRayTimestampPair end_time = XRayFrameGetEndTimestampPair(
+ capture, frame);
+
+ double pdiff = (end_time.pepper - start_time.pepper);
+ double odiff = (end_time.xray - start_time.xray);
+ double scale_a = pdiff / odiff;
+ double scale_b = ((double)end_time.pepper) - (scale_a * end_time.xray);
+ printf("Xray timestamp calibration frame %d: %f %f\n",
+ frame, scale_a, scale_b);
+
+ int start = XRayFrameGetTraceStartIndex(capture, frame);
+ int end = XRayFrameGetTraceEndIndex(capture, frame);
+ int count = XRayFrameGetTraceCount(capture, frame);
+
+ struct XRayTraceBufferEntry** stack_base = XRayMalloc(
+ sizeof(struct XRayTraceBufferEntry*) * (XRAY_TRACE_STACK_SIZE + 1));
+ struct XRayTraceBufferEntry** stack_top = stack_base;
+ *stack_top = NULL;
+
+ int i;
+ for(i = start; i != end; i = XRayTraceNextEntry(capture, i)) {
+ if (XRayTraceIsAnnotation(capture, i)) {
+ continue;
+ }
+
+ uint32_t depth = XRAY_EXTRACT_DEPTH(
+ XRayTraceGetEntry(capture, i)->depth_addr);
+
+ while(*stack_top &&
+ XRAY_EXTRACT_DEPTH((*stack_top)->depth_addr) >= depth) {
+ struct XRayTraceBufferEntry* e = *(stack_top--);
+ ppb_trace_event_interface->AddTraceEventWithThreadIdAndTimestamp(
+ 'E', cat_enabled,
+ XRayGetName(symbols, e),
+ 0, thread_id,
+ (scale_a * e->end_tick) + scale_b,
+ 0, NULL, NULL, NULL, 0
+ );
+ }
+
+ struct XRayTraceBufferEntry* e = XRayTraceGetEntry(capture, i);
+ ppb_trace_event_interface->AddTraceEventWithThreadIdAndTimestamp(
+ 'B', cat_enabled,
+ XRayGetName(symbols, e),
+ 0, thread_id,
+ (scale_a * e->start_tick) + scale_b,
+ 0, NULL, NULL, NULL, 0
+ );
+
+ *(++stack_top) = e;
+ }
+
+ while(*stack_top) {
+ struct XRayTraceBufferEntry* e = *(stack_top--);
+ ppb_trace_event_interface->AddTraceEventWithThreadIdAndTimestamp(
+ 'E', cat_enabled,
+ XRayGetName(symbols, e),
+ 0, thread_id,
+ (scale_a * e->end_tick) + scale_b,
+ 0, NULL, NULL, NULL, 0
+ );
+ }
+
+ frame = XRayFrameGetNext(capture, frame);
+ XRayFree(stack_base);
+ }
+}
+
+void XRayRegisterBrowserInterface(PPB_GetInterface interface) {
+ ppb_trace_event_interface = (PPB_Trace_Event_Dev*)interface(
+ PPB_TRACE_EVENT_DEV_INTERFACE);
+ assert(ppb_trace_event_interface);
+}
+
+#endif /* XRAY */
+#endif /* XRAY_DISABLE_BROWSER_INTEGRATION */
diff --git a/native_client_sdk/src/libraries/xray/demangle.c b/native_client_sdk/src/libraries/xray/demangle.c
index 9871bd3ad8..cf3cbc43de 100644
--- a/native_client_sdk/src/libraries/xray/demangle.c
+++ b/native_client_sdk/src/libraries/xray/demangle.c
@@ -1,7 +1,6 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
#include "xray/xray_priv.h"
diff --git a/native_client_sdk/src/libraries/xray/hashtable.c b/native_client_sdk/src/libraries/xray/hashtable.c
index db67c48937..45f2aa21cb 100644
--- a/native_client_sdk/src/libraries/xray/hashtable.c
+++ b/native_client_sdk/src/libraries/xray/hashtable.c
@@ -1,7 +1,6 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
/* Hashtable for XRay */
diff --git a/native_client_sdk/src/libraries/xray/library.dsc b/native_client_sdk/src/libraries/xray/library.dsc
index 1a918a8558..f7e23ef5b9 100644
--- a/native_client_sdk/src/libraries/xray/library.dsc
+++ b/native_client_sdk/src/libraries/xray/library.dsc
@@ -1,5 +1,5 @@
{
- 'TOOLS': ['newlib', 'glibc'],
+ 'TOOLS': ['newlib', 'glibc', 'pnacl'],
'SEARCH': [
'.'
],
@@ -12,11 +12,12 @@
'hashtable.c',
'parsesymbols.c',
'report.c',
+ 'browser.c',
'stringpool.c',
'symtable.c',
'xray.c'
],
- 'CCFLAGS': [
+ 'CFLAGS': [
'-DXRAY -DXRAY_ANNOTATE -O2'
]
}
diff --git a/native_client_sdk/src/libraries/xray/parsesymbols.c b/native_client_sdk/src/libraries/xray/parsesymbols.c
index 766a6ec8f3..5d59ae4e96 100644
--- a/native_client_sdk/src/libraries/xray/parsesymbols.c
+++ b/native_client_sdk/src/libraries/xray/parsesymbols.c
@@ -1,7 +1,6 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
/* XRay -- a simple profiler for Native Client */
diff --git a/native_client_sdk/src/libraries/xray/report.c b/native_client_sdk/src/libraries/xray/report.c
index 1e679b9586..0176f4509c 100644
--- a/native_client_sdk/src/libraries/xray/report.c
+++ b/native_client_sdk/src/libraries/xray/report.c
@@ -1,7 +1,6 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
/* XRay -- a simple profiler for Native Client */
@@ -75,7 +74,7 @@ void XRayTraceReport(struct XRayTraceCapture* capture,
} else {
strcpy(annotation, "");
}
- fprintf(f, "0x%08X %10ld %5.1f %s%s %s\n",
+ fprintf(f, "0x%08X %10lld %5.1f %s%s %s\n",
(unsigned int)addr, (int64_t)ticks, percent,
&space[256 - depth], symbol_name, annotation);
}
@@ -115,7 +114,7 @@ void XRayFrameReport(struct XRayTraceCapture* capture, FILE* f) {
bool valid = XRayFrameIsValid(capture, frame);
char label[XRAY_MAX_LABEL];
XRayFrameMakeLabel(capture, counter, label);
- fprintf(f, " %3d %s %10ld %10d %10d %s\n",
+ fprintf(f, " %3d %s %10lld %10d %10d %s\n",
counter,
valid ? " " : "*",
(int64_t)total_ticks,
@@ -151,7 +150,7 @@ void XRayFrameReport(struct XRayTraceCapture* capture, FILE* f) {
int annotation_count = XRayFrameGetAnnotationCount(capture, frame);
char label[XRAY_MAX_LABEL];
XRayFrameMakeLabel(capture, index, label);
- fprintf(f, " %3d %10ld %10d %10d %s\n",
+ fprintf(f, " %3d %10lld %10d %10d %s\n",
index,
(int64_t)total_ticks,
capture_size,
@@ -189,7 +188,6 @@ void XRayReport(struct XRayTraceCapture* capture,
fflush(f);
}
-
/* Write a profile report to text file. */
void XRaySaveReport(struct XRayTraceCapture* capture,
const char* filename,
@@ -203,4 +201,4 @@ void XRaySaveReport(struct XRayTraceCapture* capture,
}
}
-#endif // XRAY
+#endif /* XRAY */
diff --git a/native_client_sdk/src/libraries/xray/stringpool.c b/native_client_sdk/src/libraries/xray/stringpool.c
index 4a63581a0c..87791d9094 100644
--- a/native_client_sdk/src/libraries/xray/stringpool.c
+++ b/native_client_sdk/src/libraries/xray/stringpool.c
@@ -1,7 +1,6 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
/* XRay string pool */
diff --git a/native_client_sdk/src/libraries/xray/symtable.c b/native_client_sdk/src/libraries/xray/symtable.c
index 52f5c2b9ee..1f0584c7f9 100644
--- a/native_client_sdk/src/libraries/xray/symtable.c
+++ b/native_client_sdk/src/libraries/xray/symtable.c
@@ -1,7 +1,6 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
/* XRay symbol table */
@@ -16,6 +15,7 @@
#endif
#include "xray/xray_priv.h"
+#define PNACL_STRING_OFFSET (0x10000000)
#if defined(XRAY)
@@ -145,6 +145,19 @@ struct XRaySymbol* XRaySymbolTableLookup(struct XRaySymbolTable* symtab,
uint32_t addr) {
void *x = XRayHashTableLookup(symtab->hash_table, addr);
struct XRaySymbol* r = (struct XRaySymbol*)x;
+
+#if defined(__pnacl__)
+ if (r == NULL) {
+ /* Addresses are trimed to 24 bits for internal storage, so we need to
+ * add this offset back in order to get the real address.
+ */
+ addr |= PNACL_STRING_OFFSET;
+ const char* name = (const char*)addr;
+ struct XRaySymbol* symbol = XRaySymbolCreate(symtab->symbol_pool, name);
+ r = XRaySymbolTableAdd(symtab, symbol, addr);
+ }
+#endif
+
#if defined(__GLIBC__)
if (r == NULL) {
Dl_info info;
diff --git a/native_client_sdk/src/libraries/xray/xray.c b/native_client_sdk/src/libraries/xray/xray.c
index 5cfa42a275..d1b8915c60 100644
--- a/native_client_sdk/src/libraries/xray/xray.c
+++ b/native_client_sdk/src/libraries/xray/xray.c
@@ -1,7 +1,6 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
/* XRay -- a simple profiler for Native Client */
@@ -40,9 +39,9 @@ FORCE_INLINE uint64_t GTOD() {
#define GTSC(_x) _x = GTOD();
#endif
-
/* Use a TLS variable for cheap thread uid. */
__thread struct XRayTraceCapture* g_xray_capture = NULL;
+__thread int g_xray_thread_id_placeholder = 0;
struct XRayTraceStackEntry {
@@ -62,6 +61,11 @@ struct XRayTraceFrameEntry {
uint64_t total_ticks;
int annotation_count;
bool valid;
+
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+ struct XRayTimestampPair start_time;
+ struct XRayTimestampPair end_time;
+#endif
};
@@ -93,6 +97,10 @@ struct XRayTraceCapture {
uint32_t guard3;
struct XRayTraceBufferEntry* buffer;
struct XRayTraceFrame frame;
+
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+ int32_t thread_id;
+#endif
} XRAY_ALIGN64;
@@ -100,10 +108,16 @@ struct XRayTraceCapture {
extern "C" {
#endif
+#if defined(__pnacl__)
+XRAY_NO_INSTRUMENT void __pnacl_profile_func_enter(const char* fname);
+XRAY_NO_INSTRUMENT void __pnacl_profile_func_exit(const char* fname);
+#else
XRAY_NO_INSTRUMENT void __cyg_profile_func_enter(void* this_fn,
void* call_site);
XRAY_NO_INSTRUMENT void __cyg_profile_func_exit(void* this_fn,
void* call_site);
+#endif
+
XRAY_NO_INSTRUMENT void __xray_profile_append_annotation(
struct XRayTraceCapture* capture,
struct XRayTraceStackEntry* se,
@@ -113,7 +127,6 @@ XRAY_NO_INSTRUMENT void __xray_profile_append_annotation(
}
#endif
-
/* Asserts that the guard values haven't changed. */
void XRayCheckGuards(struct XRayTraceCapture* capture) {
assert(capture->guard0 == XRAY_GUARD_VALUE_0x12345678);
@@ -303,11 +316,14 @@ void XRayFree(void* data) {
}
-
/* Main profile capture function that is called at the start */
/* of every instrumented function. This function is implicitly */
/* called when code is compilied with the -finstrument-functions option */
+#if defined(__pnacl__)
+void __pnacl_profile_func_enter(const char* this_fn) {
+#else
void __cyg_profile_func_enter(void* this_fn, void* call_site) {
+#endif
struct XRayTraceCapture* capture = g_xray_capture;
if (capture && capture->recording) {
uint32_t depth = capture->stack_depth;
@@ -329,7 +345,11 @@ void __cyg_profile_func_enter(void* this_fn, void* call_site) {
/* Main profile capture function that is called at the exit of */
/* every instrumented function. This function is implicity called */
/* when the code is compiled with the -finstrument-functions option */
+#if defined(__pnacl__)
+void __pnacl_profile_func_exit(const char* this_fn) {
+#else
void __cyg_profile_func_exit(void* this_fn, void* call_site) {
+#endif
struct XRayTraceCapture* capture = g_xray_capture;
if (capture && capture->recording) {
--capture->stack_depth;
@@ -350,6 +370,25 @@ void __cyg_profile_func_exit(void* this_fn, void* call_site) {
}
}
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+void XRayGetTSC(uint64_t* tsc) {
+ GTSC(*tsc);
+}
+
+int32_t XRayGetSavedThreadID(struct XRayTraceCapture* capture) {
+ return capture->thread_id;
+}
+
+struct XRayTimestampPair XRayFrameGetStartTimestampPair(
+ struct XRayTraceCapture* capture, int frame) {
+ return capture->frame.entry[frame].start_time;
+}
+
+struct XRayTimestampPair XRayFrameGetEndTimestampPair(
+ struct XRayTraceCapture* capture, int frame) {
+ return capture->frame.entry[frame].end_time;
+}
+#endif
/* Special case appending annotation string to trace buffer */
/* this function should only ever be called from __cyg_profile_func_exit() */
@@ -573,6 +612,11 @@ void XRayStartFrame(struct XRayTraceCapture* capture) {
capture->recording = true;
GTSC(capture->frame.entry[i].start_tsc);
g_xray_capture = capture;
+
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+ capture->frame.entry[i].start_time = XRayGenerateTimestampsNow();
+#endif
+
}
@@ -612,6 +656,10 @@ void XRayEndFrame(struct XRayTraceCapture* capture) {
XRayCheckGuards(capture);
}
g_xray_capture = NULL;
+
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+ capture->frame.entry[i].end_time = XRayGenerateTimestampsNow();
+#endif
}
@@ -699,6 +747,11 @@ struct XRayTraceCapture* XRayInit(int stack_depth,
if (NULL != mapfilename)
XRaySymbolTableParseMapfile(capture->symbols, mapfilename);
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+ /* Use the address of a thread local variable as a fake thread id. */
+ capture->thread_id = (int32_t)(&g_xray_thread_id_placeholder);
+#endif
+
return capture;
}
diff --git a/native_client_sdk/src/libraries/xray/xray.h b/native_client_sdk/src/libraries/xray/xray.h
index af3117a230..8c019dbc80 100644
--- a/native_client_sdk/src/libraries/xray/xray.h
+++ b/native_client_sdk/src/libraries/xray/xray.h
@@ -1,7 +1,6 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
+ * found in the LICENSE file. */
/* XRay -- a simple profiler for Native Client */
@@ -11,6 +10,10 @@
#include <stdint.h>
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+#include "ppapi/c/ppb.h"
+#endif
+
#if defined(__arm__)
#undef XRAY
#endif
@@ -53,6 +56,15 @@ XRAY_NO_INSTRUMENT void XRayReport(struct XRayTraceCapture* capture,
FILE* f,
float percent_cutoff,
int ticks_cutoff);
+
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+XRAY_NO_INSTRUMENT void XRayBrowserTraceReport(
+ struct XRayTraceCapture* capture);
+XRAY_NO_INSTRUMENT void XRayRegisterBrowserInterface(
+ PPB_GetInterface get_browser_interface);
+#endif /* XRAY_DISABLE_BROWSER_INTEGRATION */
+
+
#if defined(XRAY_ANNOTATE)
#define XRayAnnotate(...) __XRayAnnotate(__VA_ARGS__)
#define XRayAnnotateFiltered(...) __XRayAnnotateFiltered(__VA_ARGS__)
@@ -86,6 +98,14 @@ inline void XRayReport(struct XRayTraceCapture* capture,
FILE* f,
float percent_cutoff,
int ticks_cutoff);
+
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+inline void XRayBrowserTraceReport(struct XRayTraceCapture* capture) {}
+inline void XRayRegisterBrowserInterface(
+ PPB_GetInterface get_browser_interface) {}
+#endif /* XRAY_DISABLE_BROWSER_INTEGRATION */
+
+
#endif /* defined(XRAY) */
#ifdef __cplusplus
diff --git a/native_client_sdk/src/libraries/xray/xray.html b/native_client_sdk/src/libraries/xray/xray.html
index 6c249a2d1b..a41cc8fe6a 100644
--- a/native_client_sdk/src/libraries/xray/xray.html
+++ b/native_client_sdk/src/libraries/xray/xray.html
@@ -82,4 +82,4 @@ key: X use primary o use both e Photoshop Elements </FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=3>Total
replies: 16 </FONT></FONT></P>
</BODY>
-</HTML> \ No newline at end of file
+</HTML>
diff --git a/native_client_sdk/src/libraries/xray/xray.odt b/native_client_sdk/src/libraries/xray/xray.odt
index 75a9aaa927..a7b1deee2e 100644
--- a/native_client_sdk/src/libraries/xray/xray.odt
+++ b/native_client_sdk/src/libraries/xray/xray.odt
Binary files differ
diff --git a/native_client_sdk/src/libraries/xray/xray_priv.h b/native_client_sdk/src/libraries/xray/xray_priv.h
index ae4de0cda9..405107c342 100644
--- a/native_client_sdk/src/libraries/xray/xray_priv.h
+++ b/native_client_sdk/src/libraries/xray/xray_priv.h
@@ -1,8 +1,6 @@
/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
+ * found in the LICENSE file. */
/* XRay -- a simple profiler for Native Client */
@@ -182,6 +180,23 @@ XRAY_NO_INSTRUMENT void XRayEnableCapture(struct XRayTraceCapture* capture);
XRAY_NO_INSTRUMENT void XRayLoadMapfile(
struct XRayTraceCapture* capture, const char* mapfilename);
+struct XRayTimestampPair {
+ uint64_t xray; /* internal xray timestamp */
+ int64_t pepper; /* corresponding timestamp from PPAPI interface */
+};
+
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
+XRAY_NO_INSTRUMENT void XRayGetTSC(uint64_t* tsc);
+XRAY_NO_INSTRUMENT int32_t XRayGetSavedThreadID(
+ struct XRayTraceCapture* capture);
+XRAY_NO_INSTRUMENT struct XRayTimestampPair XRayFrameGetStartTimestampPair(
+ struct XRayTraceCapture* capture, int frame);
+XRAY_NO_INSTRUMENT struct XRayTimestampPair XRayFrameGetEndTimestampPair(
+ struct XRayTraceCapture* capture, int frame);
+XRAY_NO_INSTRUMENT struct XRayTimestampPair XRayGenerateTimestampsNow(void);
+#endif
+
+
#endif /* defined(XRAY) */
#ifdef __cplusplus
diff --git a/native_client_sdk/src/tools/create_nmf.py b/native_client_sdk/src/tools/create_nmf.py
index bf9e163c4f..880ca008eb 100755
--- a/native_client_sdk/src/tools/create_nmf.py
+++ b/native_client_sdk/src/tools/create_nmf.py
@@ -49,6 +49,7 @@ MAIN_NEXE = 'main.nexe' # Name of entry point for execution
PROGRAM_KEY = 'program' # Key of the program section in an nmf file
URL_KEY = 'url' # Key of the url field for a particular file in an nmf file
FILES_KEY = 'files' # Key of the files section in an nmf file
+PNACL_OPTLEVEL_KEY = 'optlevel' # key for PNaCl optimization level
PORTABLE_KEY = 'portable' # key for portable section of manifest
TRANSLATE_KEY = 'pnacl-translate' # key for translatable objects
@@ -213,7 +214,7 @@ class NmfUtils(object):
def __init__(self, main_files=None, objdump=None,
lib_path=None, extra_files=None, lib_prefix=None,
- remap=None):
+ remap=None, pnacl_optlevel=None):
'''Constructor
Args:
@@ -226,6 +227,7 @@ class NmfUtils(object):
both for staging the libraries and for inclusion into the nmf file.
Examples: ['..'], ['lib_dir']
remap: Remaps the library name in the manifest.
+ pnacl_optlevel: Optimization level for PNaCl translation.
'''
self.objdump = objdump
self.main_files = main_files or []
@@ -236,6 +238,7 @@ class NmfUtils(object):
self.lib_prefix = lib_prefix or []
self.remap = remap or {}
self.pnacl = main_files and main_files[0].endswith('pexe')
+ self.pnacl_optlevel = pnacl_optlevel
for filename in self.main_files:
if not os.path.exists(filename):
@@ -434,9 +437,12 @@ class NmfUtils(object):
manifest = {}
manifest[PROGRAM_KEY] = {}
manifest[PROGRAM_KEY][PORTABLE_KEY] = {}
- manifest[PROGRAM_KEY][PORTABLE_KEY][TRANSLATE_KEY] = {
+ translate_dict = {
"url": os.path.basename(self.main_files[0]),
}
+ if self.pnacl_optlevel is not None:
+ translate_dict[PNACL_OPTLEVEL_KEY] = self.pnacl_optlevel
+ manifest[PROGRAM_KEY][PORTABLE_KEY][TRANSLATE_KEY] = translate_dict
self.manifest = manifest
def _GenerateManifest(self):
@@ -659,6 +665,9 @@ def main(argv):
help=('Add extra key:file tuple to the "files"' +
' section of the .nmf'),
action='append', default=[], metavar='FILE')
+ parser.add_option('-O', '--pnacl-optlevel',
+ help='Set the optimization level to N in PNaCl manifests',
+ metavar='N')
parser.add_option('-v', '--verbose',
help='Verbose output', action='store_true')
parser.add_option('-d', '--debug-mode',
@@ -702,12 +711,21 @@ def main(argv):
config = options.debug_libs and 'Debug' or 'Release'
options.lib_path += GetDefaultLibPath(config)
+ pnacl_optlevel = None
+ if options.pnacl_optlevel is not None:
+ pnacl_optlevel = int(options.pnacl_optlevel)
+ if pnacl_optlevel < 0 or pnacl_optlevel > 3:
+ sys.stderr.write(
+ 'warning: PNaCl optlevel %d is unsupported (< 0 or > 3)\n' %
+ pnacl_optlevel)
+
nmf = NmfUtils(objdump=options.objdump,
main_files=args,
lib_path=options.lib_path,
extra_files=canonicalized,
lib_prefix=path_prefix,
- remap=remap)
+ remap=remap,
+ pnacl_optlevel=pnacl_optlevel)
nmf.GetManifest()
if not options.output:
diff --git a/native_client_sdk/src/tools/host_gcc.mk b/native_client_sdk/src/tools/host_gcc.mk
index e13d1af545..67f273bcaf 100644
--- a/native_client_sdk/src/tools/host_gcc.mk
+++ b/native_client_sdk/src/tools/host_gcc.mk
@@ -27,8 +27,8 @@ $(error Unable to find gcc in PATH while building Host build)
endif
-LINUX_WARNINGS ?= -Wno-long-long
-LINUX_CCFLAGS = -fPIC -pthread $(LINUX_WARNINGS) -I$(NACL_SDK_ROOT)/include -I$(NACL_SDK_ROOT)/include/linux
+LINUX_WARNINGS ?= -Wno-long-long -Wall -Werror
+LINUX_CFLAGS = -fPIC -pthread $(LINUX_WARNINGS) -I$(NACL_SDK_ROOT)/include -I$(NACL_SDK_ROOT)/include/linux
#
@@ -40,14 +40,14 @@ LINUX_CCFLAGS = -fPIC -pthread $(LINUX_WARNINGS) -I$(NACL_SDK_ROOT)/include -I$(
define C_COMPILER_RULE
-include $(call SRC_TO_DEP,$(1))
$(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
- $(call LOG,CC ,$$@,$(HOST_CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(LINUX_FLAGS))
+ $(call LOG,CC ,$$@,$(HOST_CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(LINUX_CFLAGS))
@$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1))
endef
define CXX_COMPILER_RULE
-include $(call SRC_TO_DEP,$(1))
$(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
- $(call LOG,CXX ,$$@,$(HOST_CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(LINUX_FLAGS))
+ $(call LOG,CXX ,$$@,$(HOST_CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(LINUX_CFLAGS))
@$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1))
endef
diff --git a/native_client_sdk/src/tools/nacl_gcc.mk b/native_client_sdk/src/tools/nacl_gcc.mk
index 3a1aee768d..d046714429 100644
--- a/native_client_sdk/src/tools/nacl_gcc.mk
+++ b/native_client_sdk/src/tools/nacl_gcc.mk
@@ -162,22 +162,29 @@ else
ARCHES ?= ${VALID_ARCHES}
endif
+GLIBC_REMAP :=
+
#
# SO Macro
#
+# As well as building and installing a shared library this rule adds dependencies
+# on the library's .stamp file in STAMPDIR. However, the rule for creating the stamp
+# file is part of LIB_RULE, so users of the DEPS system are currently required to
+# use the LIB_RULE macro as well as the SO_RULE for each shared library.
+#
# $1 = Target Name
# $2 = List of Sources
# $3 = List of LIBS
# $4 = List of DEPS
# $5 = 1 => Don't add to NMF.
#
-GLIBC_REMAP :=
define SO_RULE
ifneq (,$(findstring x86_32,$(ARCHES)))
all: $(OUTDIR)/lib$(1)_x86_32.so
$(OUTDIR)/lib$(1)_x86_32.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32_pic)) $(4)
$(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter-out $(4),$$^) -shared -m32 $(LD_X86_32) $$(LD_FLAGS) $(foreach lib,$(3),-l$(lib)))
+$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
$(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so: $(OUTDIR)/lib$(1)_x86_32.so
$(MKDIR) -p $$(dir $$@)
@@ -193,6 +200,7 @@ all: $(OUTDIR)/lib$(1)_x86_64.so
$(OUTDIR)/lib$(1)_x86_64.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64_pic)) $(4)
$(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter-out $(4),$$^) -shared -m64 $(LD_X86_64) $$(LD_FLAGS) $(foreach lib,$(3),-l$(lib)))
+$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
$(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so: $(OUTDIR)/lib$(1)_x86_64.so
$(MKDIR) -p $$(dir $$@)
@@ -204,7 +212,6 @@ endif
endif
endef
-
#
# LIB Macro
#
@@ -214,13 +221,8 @@ endef
# $4 = VC Link Flags (unused)
#
define LIB_RULE
-$(STAMPDIR)/$(1).stamp: $(OUTDIR)/lib$(1)_x86_32.a
-$(STAMPDIR)/$(1).stamp: $(OUTDIR)/lib$(1)_x86_64.a
-ifneq ($(TOOLCHAIN),glibc)
-$(STAMPDIR)/$(1).stamp: $(OUTDIR)/lib$(1)_arm.a
-endif
-
$(STAMPDIR)/$(1).stamp:
+ @echo " STAMP $$@"
@echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp
ifneq (,$(findstring x86_32,$(ARCHES)))
@@ -229,6 +231,7 @@ $(OUTDIR)/lib$(1)_x86_32.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32)
$(MKDIR) -p $$(dir $$@)
$(call LOG,LIB ,$$@,$(X86_32_LIB) -cr $$@ $$^)
+$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a
install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a
$(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a: $(OUTDIR)/lib$(1)_x86_32.a
$(MKDIR) -p $$(dir $$@)
@@ -241,6 +244,7 @@ $(OUTDIR)/lib$(1)_x86_64.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64)
$(MKDIR) -p $$(dir $$@)
$(call LOG,LIB ,$$@,$(X86_64_LIB) -cr $$@ $$^)
+$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a
install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a
$(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a: $(OUTDIR)/lib$(1)_x86_64.a
$(MKDIR) -p $$(dir $$@)
@@ -254,6 +258,7 @@ $(OUTDIR)/lib$(1)_arm.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm))
$(MKDIR) -p $$(dir $$@)
$(call LOG,LIB ,$$@,$(ARM_LIB) -cr $$@ $$^)
+$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a
install: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a
$(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a: $(OUTDIR)/lib$(1)_arm.a
$(MKDIR) -p $$(dir $$@)