Skip to content

Conversation

mbektchiev
Copy link
Contributor

@mbektchiev mbektchiev commented Dec 20, 2018

JavaScript represents 64-bit integers as floating point double values.
The conversion from JSValue to pointer must be done by
extracting the double value and then converting it to integer.

Caution: This means that pointers with more than 54 significant bits
are likely to be rounded and misrepresented!
However, current OS and hardware implementations are using 48 bits,
so we're safe at the time being.
See https://en.wikipedia.org/wiki/X86-64#Virtual_address_space_details
and https://en.wikipedia.org/wiki/ARM_architecture#ARMv8-A

PR Checklist

The bug has been discovered while looking for a way to pass pointers to Objective-C objects to workers.
See #620 (comment)

@mbektchiev mbektchiev added the bug label Dec 20, 2018
@mbektchiev mbektchiev added this to the 5.2.0 milestone Dec 20, 2018
@mbektchiev mbektchiev self-assigned this Dec 20, 2018
@mbektchiev mbektchiev force-pushed the bektchiev/fix-pointer-constructor-on-64-bit-archs branch from 6fe70c8 to ae98701 Compare December 20, 2018 15:40
@mbektchiev mbektchiev force-pushed the bektchiev/fix-pointer-constructor-on-64-bit-archs branch from ae98701 to 4be9e03 Compare December 21, 2018 08:51
JavaScript represents 64-bit integers as floating point `double` values.
This means that the conversion from JSValue to pointer is done by
extracting the `double` value and then converting it to integer.

**Caution:** This means that pointers with more than 54 significant bits
are likely to be rounded and misrepresented!
However, current OS and hardware implementations are using 48 bits,
so we're safe at the time being.
See https://en.wikipedia.org/wiki/X86-64#Virtual_address_space_details
and https://en.wikipedia.org/wiki/ARM_architecture#ARMv8-A
@mbektchiev mbektchiev force-pushed the bektchiev/fix-pointer-constructor-on-64-bit-archs branch from 4be9e03 to 97386a3 Compare December 21, 2018 09:21
@mbektchiev mbektchiev merged commit 4d6b4ce into master Dec 21, 2018
@NathanaelA

This comment was marked as abuse.

@mbektchiev mbektchiev deleted the bektchiev/fix-pointer-constructor-on-64-bit-archs branch January 30, 2019 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants