Skip to content

Commit

Permalink
Bug 1566288 - Port libGraphite usage in libThebes to use the RLBox AP…
Browse files Browse the repository at this point in the history
…I. r=froydnj,jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D39593

--HG--
extra : moz-landing-system : lando
  • Loading branch information
shravanrn committed Dec 12, 2019
1 parent e7f7208 commit c32b58a
Showing 12 changed files with 438 additions and 96 deletions.
6 changes: 4 additions & 2 deletions build/clang-plugin/Utils.h
Original file line number Diff line number Diff line change
@@ -172,7 +172,8 @@ inline bool isInIgnoredNamespaceForImplicitCtor(const Decl *Declaration) {
Name == "dwarf2reader" || // dwarf2reader
Name == "arm_ex_to_module" || // arm_ex_to_module
Name == "testing" || // gtest
Name == "Json"; // jsoncpp
Name == "Json" || // jsoncpp
Name == "rlbox"; // rlbox
}

inline bool isInIgnoredNamespaceForImplicitConversion(const Decl *Declaration) {
@@ -184,7 +185,8 @@ inline bool isInIgnoredNamespaceForImplicitConversion(const Decl *Declaration) {
return Name == "std" || // standard C++ lib
Name == "__gnu_cxx" || // gnu C++ lib
Name == "google_breakpad" || // breakpad
Name == "testing"; // gtest
Name == "testing" || // gtest
Name == "rlbox"; // rlbox
}

inline bool isIgnoredPathForImplicitConversion(const Decl *Declaration) {
1 change: 1 addition & 0 deletions config/external/moz.build
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ external_dirs = []

DIRS += [
'lgpllibs',
'rlbox',
'sqlite',
]
if not CONFIG['MOZ_SYSTEM_JPEG']:
22 changes: 22 additions & 0 deletions config/external/rlbox/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- 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/.

EXPORTS.mozilla.rlbox += [
'/third_party/rlbox/include/rlbox.hpp',
'/third_party/rlbox/include/rlbox_conversion.hpp',
'/third_party/rlbox/include/rlbox_helpers.hpp',
'/third_party/rlbox/include/rlbox_noop_sandbox.hpp',
'/third_party/rlbox/include/rlbox_policy_types.hpp',
'/third_party/rlbox/include/rlbox_range.hpp',
'/third_party/rlbox/include/rlbox_sandbox.hpp',
'/third_party/rlbox/include/rlbox_stdlib.hpp',
'/third_party/rlbox/include/rlbox_stdlib_polyfill.hpp',
'/third_party/rlbox/include/rlbox_struct_support.hpp',
'/third_party/rlbox/include/rlbox_type_traits.hpp',
'/third_party/rlbox/include/rlbox_types.hpp',
'/third_party/rlbox/include/rlbox_unwrap.hpp',
'/third_party/rlbox/include/rlbox_wrapper_traits.hpp',
]
58 changes: 58 additions & 0 deletions gfx/graphite2/geckoextra/include/GraphiteStructsForRLBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vim: set ts=2 et sw=2 tw=80:
// This Source Code is subject to the terms of the Mozilla Public License
// version 2.0 (the "License"). You can obtain a copy of the License at
// http://mozilla.org/MPL/2.0/.

#ifndef GraphiteStructsForRLBox_h__
#define GraphiteStructsForRLBox_h__

#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#elif defined(__GNUC__) || defined(__GNUG__)
// Can't turn off the variadic macro warning emitted from -pedantic
# pragma GCC system_header
#elif defined(_MSC_VER)
// Doesn't seem to emit the warning
#else
// Don't know the compiler... just let it go through
#endif

#define sandbox_fields_reflection_graphite_class_gr_font_ops(f, g, ...) \
f(size_t, size, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(float (*)(const void*, unsigned short), glyph_advance_x, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(float (*)(const void*, unsigned short), glyph_advance_y, FIELD_NORMAL, ##__VA_ARGS__) g()

#define sandbox_fields_reflection_graphite_class_gr_face_ops(f, g, ...) \
f(size_t, size, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(const void* (*)(const void*, unsigned int, size_t*), get_table, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(void (*)(const void*, const void*), release_table, FIELD_NORMAL, ##__VA_ARGS__) g()

#define sandbox_fields_reflection_graphite_class_gr_glyph_to_char_cluster(f, g, ...) \
f(unsigned int, baseChar, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(unsigned int, baseGlyph, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(unsigned int, nChars, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(unsigned int, nGlyphs, FIELD_NORMAL, ##__VA_ARGS__) g()

#define sandbox_fields_reflection_graphite_class_gr_glyph_to_char_association(f, g, ...) \
f(gr_glyph_to_char_cluster*, clusters, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(unsigned short*, gids, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(float*, xLocs, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(float*, yLocs, FIELD_NORMAL, ##__VA_ARGS__) g() \
f(unsigned int, cIndex, FIELD_NORMAL, ##__VA_ARGS__) g()

#define sandbox_fields_reflection_graphite_allClasses(f, ...) \
f(gr_font_ops, graphite, ##__VA_ARGS__) \
f(gr_face_ops, graphite, ##__VA_ARGS__) \
f(gr_glyph_to_char_cluster, graphite, ##__VA_ARGS__) \
f(gr_glyph_to_char_association, graphite, ##__VA_ARGS__)

#if defined(__clang__)
# pragma clang diagnostic pop
#elif defined(__GNUC__) || defined(__GNUG__)
#elif defined(_MSC_VER)
#else
#endif

#endif
1 change: 1 addition & 0 deletions gfx/graphite2/src/moz.build
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
# This should contain all of the _PUBLIC_HEADERS from files.mk
EXPORTS.graphite2 += [
'../geckoextra/include/GraphiteExtra.h',
'../geckoextra/include/GraphiteStructsForRLBox.h',
'../include/graphite2/Font.h',
'../include/graphite2/Log.h',
'../include/graphite2/Segment.h',
44 changes: 44 additions & 0 deletions gfx/thebes/ThebesRLBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* -*- 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 THEBES_RLBOX
#define THEBES_RLBOX

#include "ThebesRLBoxTypes.h"

// RLBox uses c++17's shared_locks by default, even for the noop_sandbox
// However c++17 shared_lock is not supported on macOS 10.9 to 10.11
// Thus we use Firefox's shared lock implementation
// This can be removed if macOS 10.9 to 10.11 support is dropped
#include "mozilla/RWLock.h"
namespace rlbox {
struct rlbox_shared_lock {
mozilla::RWLock rwlock;
rlbox_shared_lock() : rwlock("rlbox") {}
};
} // namespace rlbox
#define RLBOX_USE_CUSTOM_SHARED_LOCK
#define RLBOX_SHARED_LOCK(name) rlbox::rlbox_shared_lock name
#define RLBOX_ACQUIRE_SHARED_GUARD(name, ...) \
mozilla::AutoReadLock name((__VA_ARGS__).rwlock)
#define RLBOX_ACQUIRE_UNIQUE_GUARD(name, ...) \
mozilla::AutoWriteLock name((__VA_ARGS__).rwlock)

#define RLBOX_SINGLE_THREADED_INVOCATIONS

#define RLBOX_USE_STATIC_CALLS() rlbox_noop_sandbox_lookup_symbol

#include "mozilla/rlbox/rlbox.hpp"
#include "mozilla/rlbox/rlbox_noop_sandbox.hpp"

// Struct info needed for rlbox_load_structs_from_library
#include "graphite2/Font.h"
#include "graphite2/GraphiteExtra.h"
#include "graphite2/Segment.h"

#include "graphite2/GraphiteStructsForRLBox.h"
rlbox_load_structs_from_library(graphite);

#endif
22 changes: 22 additions & 0 deletions gfx/thebes/ThebesRLBoxTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* -*- 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 THEBES_RLBOX_TYPES
#define THEBES_RLBOX_TYPES

#include "mozilla/rlbox/rlbox_types.hpp"

using rlbox_gr_sandbox_type = rlbox::rlbox_noop_sandbox;
using rlbox_sandbox_gr = rlbox::rlbox_sandbox<rlbox_gr_sandbox_type>;
template <typename T>
using sandbox_callback_gr = rlbox::sandbox_callback<T, rlbox_gr_sandbox_type>;
template <typename T>
using tainted_gr = rlbox::tainted<T, rlbox_gr_sandbox_type>;
template <typename T>
using tainted_opaque_gr = rlbox::tainted_opaque<T, rlbox_gr_sandbox_type>;
template <typename T>
using tainted_volatile_gr = rlbox::tainted_volatile<T, rlbox_gr_sandbox_type>;

#endif
Loading

0 comments on commit c32b58a

Please sign in to comment.