Skip to content

Commit

Permalink
Fix tagged date on old *OS (#477)
Browse files Browse the repository at this point in the history
* Run tests on different OS versions

* Fix compilation for older macOS/Xcode

* Use macOS 11 for old builds

* Fix lint for visionOS

* Fix Xcode and macOS versions in unit-tests

* Use Xcode 11 and macOS 11 for watchOS tests

* Use watchOS 7.4.0

* Try to fix tagged NSDate for old *os

* Enable tests back

* Make code a little bit nicer

* Enable tests

---------

Co-authored-by: Nikolay Volosatov <code@bamx23.com>
  • Loading branch information
GLinnik21 and bamx23 committed May 18, 2024
1 parent 1821e05 commit ab612c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@
<Test
Identifier = "KSObjC_Tests/testGetDateContents">
</Test>
<Test
Identifier = "KSObjC_Tests/testDateDescription">
</Test>
<Test
Identifier = "KSObjC_Tests/testDateIsValid">
</Test>
<Test
Identifier = "KSObjC_Tests/testGetDateContents">
</Test>
</SkippedTests>
</TestableReference>
<TestableReference
Expand Down
81 changes: 45 additions & 36 deletions Sources/KSCrashRecordingCore/KSObjC.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,43 +399,52 @@ static uint64_t decodeExponent(uint64_t exp)
*/
static CFAbsoluteTime extractTaggedNSDate(const void* const object)
{
#pragma pack(4)
union {
uintptr_t raw;
struct {
uint64_t fraction : 52;
uint64_t exponent : 7;
uint64_t sign : 1;
uint64_t unused : 4;
} bits;
} encodedBits = { .raw = getTaggedPayload(object) };

if (encodedBits.raw == 0)
{
return 0.0;
}
if (encodedBits.raw == UINT64_MAX)
{
return -0.0;
}

#pragma pack(4)
union {
CFAbsoluteTime value;
struct {
uint64_t fraction : 52;
uint64_t exponent : 11;
uint64_t sign : 1;
} bits;
} decodedBits = {
.bits = {
.fraction = encodedBits.bits.fraction,
.exponent = decodeExponent(encodedBits.bits.exponent),
.sign = encodedBits.bits.sign
}
};
uintptr_t payload = getTaggedPayload(object);

if (kCFCoreFoundationVersionNumber > 1600) // https://github.com/apple/llvm-project/blob/5dc9d563e5a6cd2cdd44117697dead98955ccddf/lldb/source/Plugins/Language/ObjC/Cocoa.cpp#L1041
{
union {
uintptr_t raw;
struct {
uint64_t fraction : 52;
uint64_t exponent : 7;
uint64_t sign : 1;
uint64_t unused : 4;
} bits;
} encodedBits = { .raw = payload };

if (encodedBits.raw == 0)
return 0.0;
if (encodedBits.raw == UINT64_MAX)
return -0.0;

union {
CFAbsoluteTime value;
struct {
uint64_t fraction : 52;
uint64_t exponent : 11;
uint64_t sign : 1;
} bits;
} decodedBits = {
.bits = {
.fraction = encodedBits.bits.fraction,
.exponent = decodeExponent(encodedBits.bits.exponent),
.sign = encodedBits.bits.sign
}
};

return decodedBits.value;
return decodedBits.value;
}
else
{
// Payload is a 60-bit float. Fortunately we can just cast across from
// an integer pointer after shifting out the upper 4 bits.
union {
CFAbsoluteTime value;
uintptr_t raw;
} payloadBits = { .raw = payload << 4 };
return payloadBits.value;
}
}
#endif
/** Get any special class metadata we have about the specified class.
Expand Down

0 comments on commit ab612c4

Please sign in to comment.