[wasm] Add HB_ARRAY_APP2NATIVE

pull/4131/head
Behdad Esfahbod 2 years ago
parent 1537e252ba
commit 4260de12c1
  1. 7
      src/hb-wasm-api-buffer.hh
  2. 2
      src/hb-wasm-api-face.hh
  3. 4
      src/hb-wasm-api-font.hh
  4. 5
      src/hb-wasm-api.hh

@ -113,10 +113,8 @@ HB_WASM_API (bool_t, buffer_copy_contents) (HB_WASM_EXEC_ENV
if (length <= contents->length)
{
unsigned bytes = length * sizeof (hb_glyph_info_t);
glyph_info_t *info = (glyph_info_t *) (validate_app_addr (contents->info, bytes) ? addr_app_to_native (contents->info) : nullptr);
glyph_position_t *pos = (glyph_position_t *) (validate_app_addr (contents->pos, bytes) ? addr_app_to_native (contents->pos) : nullptr);
glyph_info_t *info = HB_ARRAY_APP2NATIVE (glyph_info_t, contents->info, length);
glyph_position_t *pos = HB_ARRAY_APP2NATIVE (glyph_position_t, contents->pos, length);
if (unlikely (!info || !pos))
{
@ -124,6 +122,7 @@ HB_WASM_API (bool_t, buffer_copy_contents) (HB_WASM_EXEC_ENV
return false;
}
unsigned bytes = length * sizeof (hb_glyph_info_t);
memcpy (info, buffer->info, bytes);
memcpy (pos, buffer->pos, bytes);

@ -48,7 +48,7 @@ HB_WASM_API (bool_t, face_copy_table) (HB_WASM_EXEC_ENV
if (length <= blob->length)
{
char *data = (char *) (validate_app_addr (blob->data, length) ? addr_app_to_native (blob->data) : nullptr);
char *data = HB_ARRAY_APP2NATIVE (char, blob->data, length);
if (unlikely (!data))
{

@ -140,8 +140,8 @@ HB_WASM_API (bool_t, font_copy_glyph_outline) (HB_WASM_EXEC_ENV
if (hb_outline.points.length <= outline->n_points &&
hb_outline.contours.length <= outline->n_contours)
{
glyph_outline_point_t *points = (glyph_outline_point_t *) (validate_app_addr (outline->points, hb_outline.points.get_size ()) ? addr_app_to_native (outline->points) : nullptr);
uint32_t *contours = (uint32_t *) (validate_app_addr (outline->contours, hb_outline.contours.get_size ()) ? addr_app_to_native (outline->contours) : nullptr);
glyph_outline_point_t *points = HB_ARRAY_APP2NATIVE (glyph_outline_point_t, outline->points, hb_outline.points.length);
uint32_t *contours = HB_ARRAY_APP2NATIVE (uint32_t, outline->contours, hb_outline.contours.length);
if (unlikely (!points || !contours))
{

@ -108,5 +108,10 @@ HB_INTERNAL extern hb_user_data_key_t _hb_wasm_ref_type_key;
name = (type *) wasm_runtime_addr_app_to_native (module_inst, name##ptr); \
} HB_STMT_END
#define HB_ARRAY_APP2NATIVE(type, name, length) \
((type *) (!hb_unsigned_mul_overflows (length, sizeof (type)) && \
validate_app_addr (name, (length) * sizeof (type)) ? \
addr_app_to_native (name) : nullptr))
#endif /* HB_WASM_API_HH */

Loading…
Cancel
Save