Skip to content

Commit

Permalink
Bug 1688452 - Retrofit nsExpatDriver to use RLBoxed libexpat r=tjr,pe…
Browse files Browse the repository at this point in the history
…terv,bholley,glandium

Differential Revision: https://phabricator.services.mozilla.com/D104658
  • Loading branch information
deian committed Nov 19, 2021
1 parent 62a30e3 commit 78d97df
Show file tree
Hide file tree
Showing 18 changed files with 807 additions and 218 deletions.
2 changes: 1 addition & 1 deletion config/recurse.mk
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ endif
ifdef MOZ_USING_WASM_SANDBOXING
security/rlbox/target-objects: config/external/wasm2c_sandbox_compiler/host
security/rlbox/target: security/rlbox/target-objects
dom/media/ogg/target-objects extensions/spellcheck/hunspell/glue/target-objects gfx/thebes/target-objects: security/rlbox/target-objects
dom/media/ogg/target-objects extensions/spellcheck/hunspell/glue/target-objects gfx/thebes/target-objects parser/expat/target-objects parser/htmlparser/target-objects: security/rlbox/target-objects
endif

# Most things are built during compile (target/host), but some things happen during export
Expand Down
1 change: 1 addition & 0 deletions layout/build/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ LOCAL_INCLUDES += [
"/js/xpconnect/src",
"/netwerk/base",
"/netwerk/cookie",
"/parser/htmlparser",
"/toolkit/components/sessionstore",
"/view",
]
Expand Down
4 changes: 4 additions & 0 deletions layout/build/nsLayoutStatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
#include "RestoreTabContentObserver.h"
#include "mozilla/intl/nsComplexBreaker.h"

#include "nsRLBoxExpatDriver.h"

using namespace mozilla;
using namespace mozilla::net;
using namespace mozilla::dom;
Expand Down Expand Up @@ -294,6 +296,8 @@ nsresult nsLayoutStatics::Initialize() {

ComplexBreaker::Initialize();

RLBoxExpatSandboxPool::Initialize();

return NS_OK;
}

Expand Down
17 changes: 5 additions & 12 deletions parser/expat/expat_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@
#ifndef __expat_config_h__
#define __expat_config_h__

#define MOZ_UNICODE
#include "nspr.h"

#ifdef IS_LITTLE_ENDIAN
#define BYTEORDER 1234
#else
#define BYTEORDER 4321
#endif /* IS_LITTLE_ENDIAN */

#if PR_BYTES_PER_INT != 4
#define int int32_t
#endif /* PR_BYTES_PER_INT != 4 */
#ifdef MOZ_IN_WASM_SANDBOX
# include "expat_config_rlbox.h"
#else
# include "expat_config_moz.h"
#endif

/* Other Mozilla code relies on memmove already, so we assume it's available */
#define HAVE_MEMMOVE 1
Expand Down
22 changes: 22 additions & 0 deletions parser/expat/expat_config_moz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __expat_config_moz_h__
#define __expat_config_moz_h__

#define MOZ_UNICODE
#include "nspr.h"

#ifdef IS_LITTLE_ENDIAN
#define BYTEORDER 1234
#else
#define BYTEORDER 4321
#endif /* IS_LITTLE_ENDIAN */

#if PR_BYTES_PER_INT != 4
#define int int32_t
#endif /* PR_BYTES_PER_INT != 4 */

#endif /* __expat_config_moz_h__ */
20 changes: 20 additions & 0 deletions parser/expat/expat_config_rlbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __expat_config_rlbox_h__
#define __expat_config_rlbox_h__

/* Wasm is little endian */
#define BYTEORDER 1234

/* We don't redefine int as int32_t for our 32-bit Wasm machine. */
#ifdef __cplusplus
static_assert(sizeof(int) == sizeof(int32_t), "Expected int and int32_t to be of same size.");
#endif

/* We don't need to nor want to expose getpid() to expat */
#define getpid() 0

#endif /* __expat_config_rlbox_h__ */
11 changes: 5 additions & 6 deletions parser/expat/lib/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

include("sources.mozbuild")

EXPORTS += [
'expat.h',
'expat_external.h',
]

SOURCES += [
'xmlparse.c',
'xmlrole.c',
'xmltok.c',
]
SOURCES += expat_sources

FINAL_LIBRARY = 'gkmedias'

DEFINES['HAVE_EXPAT_CONFIG_H'] = True
for k, v in expat_defines:
DEFINES[k] = v
15 changes: 15 additions & 0 deletions parser/expat/lib/sources.mozbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

expat_sources = [
'xmlparse.c',
'xmlrole.c',
'xmltok.c',
]

expat_defines = [
('HAVE_EXPAT_CONFIG_H', True)
]
7 changes: 7 additions & 0 deletions parser/expat/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ DIRS += ['lib']

EXPORTS += [
'expat_config.h',
'expat_config_moz.h',
'expat_config_rlbox.h',
'rlbox_expat.h',
'rlbox_expat_types.h',
]

LOCAL_INCLUDES += [
'!/security/rlbox',
]
28 changes: 28 additions & 0 deletions parser/expat/rlbox_expat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PARSER_HTML_RLBOX_EXPAT_H_
#define PARSER_HTML_RLBOX_EXPAT_H_

#include "rlbox_expat_types.h"

// Load general firefox configuration of RLBox
#include "mozilla/rlbox/rlbox_config.h"

#ifdef MOZ_WASM_SANDBOXING_EXPAT
// Include the generated header file so that we are able to resolve the symbols
// in the wasm binary
# include "rlbox.wasm.h"
# define RLBOX_USE_STATIC_CALLS() rlbox_wasm2c_sandbox_lookup_symbol
# include "mozilla/rlbox/rlbox_wasm2c_sandbox.hpp"
#else
// Extra configuration for no-op sandbox
# define RLBOX_USE_STATIC_CALLS() rlbox_noop_sandbox_lookup_symbol
# include "mozilla/rlbox/rlbox_noop_sandbox.hpp"
#endif

#include "mozilla/rlbox/rlbox.hpp"

#endif
18 changes: 18 additions & 0 deletions parser/expat/rlbox_expat_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PARSER_HTML_RLBOX_EXPAT_TYPES_H_
#define PARSER_HTML_RLBOX_EXPAT_TYPES_H_

#include <stddef.h>
#include "mozilla/rlbox/rlbox_types.hpp"

#ifdef MOZ_WASM_SANDBOXING_EXPAT
RLBOX_DEFINE_BASE_TYPES_FOR(expat, wasm2c)
#else
RLBOX_DEFINE_BASE_TYPES_FOR(expat, noop)
#endif

#endif
5 changes: 5 additions & 0 deletions parser/htmlparser/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ EXPORTS += [
"nsParserBase.h",
"nsParserCIID.h",
"nsParserConstants.h",
"nsRLBoxExpatDriver.h",
"nsScannerString.h",
]

Expand Down Expand Up @@ -57,4 +58,8 @@ FINAL_LIBRARY = "xul"
if CONFIG["CC_TYPE"] in ("clang", "gcc"):
CXXFLAGS += ["-Wno-error=shadow"]

LOCAL_INCLUDES += [
"!/security/rlbox",
]

REQUIRES_UNIFIED_BUILD = True
Loading

0 comments on commit 78d97df

Please sign in to comment.