Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions core/libs/prx/libSceFreeTypeOt/src/GlyphSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GuestSlotInternalRec* Internal(const GuestGlyphSlotRec& slot) {
}

GuestMemoryRec* FaceMemory(const GuestGlyphSlotRec& slot, const char* function) {
if (!slot.face) NotImplemented_nid_no_patch(function);
if (!slot.face) GuestFault_nid_no_patch(function);
GuestFaceRec guestFace{};
const int savedErrno = errno;
const bool copied = GuestCopyIn_nid_no_patch(&guestFace, slot.face, sizeof(guestFace));
Expand All @@ -39,7 +39,7 @@ GuestMemoryRec* FaceMemory(const GuestGlyphSlotRec& slot, const char* function)
}

bool FreeOwned(GuestMemoryRec* memory, GuestGlyphSlotRec* slot, GuestGlyphSlotRec& guestSlot, const char* function) {
if (guestSlot.bitmap.buffer && !memory) NotImplemented_nid_no_patch(function);
if (guestSlot.bitmap.buffer && !memory) GuestFault_nid_no_patch(function);
std::uint8_t* cleared = nullptr;
const int savedErrno = errno;
const bool written = GuestCopyOut_nid_no_patch(&slot->bitmap.buffer, &cleared, sizeof(cleared));
Expand All @@ -54,7 +54,7 @@ bool FreeBitmap(GuestGlyphSlotRec* slot, GuestGlyphSlotRec& guestSlot, const cha
GuestSlotInternalRec* internal = Internal(guestSlot);
if (internal && (internal->flags & GlyphOwnBitmap)) {
GuestMemoryRec* memory = FaceMemory(guestSlot, function);
if (guestSlot.bitmap.buffer && !memory) NotImplemented_nid_no_patch(function);
if (guestSlot.bitmap.buffer && !memory) GuestFault_nid_no_patch(function);
std::uint8_t* cleared = nullptr;
const int savedErrno = errno;
const bool written = GuestCopyOut_nid_no_patch(&slot->bitmap.buffer, &cleared, sizeof(cleared));
Expand Down Expand Up @@ -300,7 +300,7 @@ int APS5_VABI FT_New_GlyphSlot_nid_postfix(GuestFaceRec* face, GuestGlyphSlotRec
}

void APS5_VABI ft_glyphslot_free_bitmap_nid_postfix(GuestGlyphSlotRec* slot) {
if (!slot) NotImplemented_nid_no_patch(__func__);
if (!slot) GuestFault_nid_no_patch(__func__);
GuestGlyphSlotRec guestSlot{};
const int savedErrno = errno;
const bool copied = GuestCopyIn_nid_no_patch(&guestSlot, slot, sizeof(guestSlot));
Expand All @@ -310,7 +310,7 @@ void APS5_VABI ft_glyphslot_free_bitmap_nid_postfix(GuestGlyphSlotRec* slot) {
}

void APS5_VABI ft_glyphslot_set_bitmap_nid_postfix(GuestGlyphSlotRec* slot, std::uint8_t* buffer) {
if (!slot) NotImplemented_nid_no_patch(__func__);
if (!slot) GuestFault_nid_no_patch(__func__);
GuestGlyphSlotRec guestSlot{};
const int readErrno = errno;
const bool copied = GuestCopyIn_nid_no_patch(&guestSlot, slot, sizeof(guestSlot));
Expand All @@ -319,7 +319,7 @@ void APS5_VABI ft_glyphslot_set_bitmap_nid_postfix(GuestGlyphSlotRec* slot, std:
GuestSlotInternalRec* internal = Internal(guestSlot);
const bool owned = internal && (internal->flags & GlyphOwnBitmap);
GuestMemoryRec* memory = owned ? FaceMemory(guestSlot, __func__) : nullptr;
if (owned && guestSlot.bitmap.buffer && !memory) NotImplemented_nid_no_patch(__func__);
if (owned && guestSlot.bitmap.buffer && !memory) GuestFault_nid_no_patch(__func__);
const int writeErrno = errno;
const bool written = GuestCopyOut_nid_no_patch(&slot->bitmap.buffer, &buffer, sizeof(buffer));
errno = writeErrno;
Expand All @@ -332,13 +332,13 @@ void APS5_VABI ft_glyphslot_set_bitmap_nid_postfix(GuestGlyphSlotRec* slot, std:

int APS5_VABI ft_glyphslot_alloc_bitmap_nid_postfix(GuestGlyphSlotRec* slot, std::uint64_t size) {
const char* function = __func__;
if (!slot) NotImplemented_nid_no_patch(function);
if (!slot) GuestFault_nid_no_patch(function);
GuestGlyphSlotRec guestSlot{};
const int readErrno = errno;
const bool copied = GuestCopyIn_nid_no_patch(&guestSlot, slot, sizeof(guestSlot));
errno = readErrno;
if (!copied) return InvalidArgument;
if (!guestSlot.internal) NotImplemented_nid_no_patch(function);
if (!guestSlot.internal) GuestFault_nid_no_patch(function);
GuestMemoryRec* memory = FaceMemory(guestSlot, function);
GuestSlotInternalRec* internal = Internal(guestSlot);
const bool owned = (internal->flags & GlyphOwnBitmap) != 0;
Expand All @@ -349,7 +349,7 @@ int APS5_VABI ft_glyphslot_alloc_bitmap_nid_postfix(GuestGlyphSlotRec* slot, std
}
try {
const auto bytes = static_cast<std::int64_t>(size);
if (bytes > 0 && !memory) NotImplemented_nid_no_patch(function);
if (bytes > 0 && !memory) GuestFault_nid_no_patch(function);
std::int32_t error = 0;
auto* allocated = static_cast<std::uint8_t*>(OtMemAlloc(memory, bytes, &error));
const int writeErrno = errno;
Expand Down
6 changes: 3 additions & 3 deletions core/libs/prx/libSceFreeTypeOt/src/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool CopyIn(void* destination, const void* source, std::size_t bytes) {

FT_Library ReadLibrary(FreeType::GuestLibrary* library) {
FT_Library host = nullptr;
if (!CopyIn(&host, &library->host, sizeof(host)) || !host) NotImplemented_nid_no_patch("FT_Lookup_Renderer");
if (!CopyIn(&host, &library->host, sizeof(host)) || !host) GuestFault_nid_no_patch("FT_Lookup_Renderer");
return host;
}

Expand All @@ -53,7 +53,7 @@ namespace {

FT_ListNode ReadNode(FT_Library library, void** node) {
FT_ListNode current = nullptr;
if (!CopyIn(&current, node, sizeof(current))) NotImplemented_nid_no_patch("FT_Lookup_Renderer");
if (!CopyIn(&current, node, sizeof(current))) GuestFault_nid_no_patch("FT_Lookup_Renderer");
if (!current) return nullptr;
FT_ListNode entry = library->renderers.head;
while (entry && entry != current) entry = entry->next;
Expand All @@ -65,7 +65,7 @@ void WriteNode(void** node, FT_ListNode value) {
const int saved = errno;
const bool ok = GuestCopyOut_nid_no_patch(node, &value, sizeof(value));
errno = saved;
if (!ok) NotImplemented_nid_no_patch("FT_Lookup_Renderer");
if (!ok) GuestFault_nid_no_patch("FT_Lookup_Renderer");
}

}
Expand Down
26 changes: 14 additions & 12 deletions core/libs/prx/libSceFreeTypeOt/src/Polar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,19 @@ std::int64_t OtVectorLength(const GuestVector& vector, const char* function) {
extern "C" {

std::int64_t APS5_VABI sceFreeTypeOtVectorLength_nid_no_patch(GuestVector* vector) {
if (!vector) NotImplemented_nid_no_patch(__func__);
if (!vector) GuestFault_nid_no_patch(__func__);
GuestVector localVector{};
if (!GuestCopyIn_nid_no_patch(&localVector, vector, sizeof(localVector))) NotImplemented_nid_no_patch(__func__);
if (!GuestCopyIn_nid_no_patch(&localVector, vector, sizeof(localVector))) GuestFault_nid_no_patch(__func__);
return OtVectorLength(localVector, __func__);
}
APS5_EXPORT("1jmC2QcpRl0", sceFreeTypeOtVectorLength_nid_no_patch);

void APS5_VABI sceFreeTypeOtVectorPolarize_nid_no_patch(GuestVector* vector, std::int64_t* length, std::int64_t* angle) {
if (!vector) NotImplemented_nid_no_patch(__func__);
if (!vector) GuestFault_nid_no_patch(__func__);
GuestVector localVector{};
if (!GuestCopyIn_nid_no_patch(&localVector, vector, sizeof(localVector))) NotImplemented_nid_no_patch(__func__);
if (!GuestCopyIn_nid_no_patch(&localVector, vector, sizeof(localVector))) GuestFault_nid_no_patch(__func__);
if (localVector.x == 0 && localVector.y == 0) return;
if (!length || !angle || !GuestWritable(length, sizeof(*length)) || !GuestWritable(angle, sizeof(*angle))) NotImplemented_nid_no_patch(__func__);
if (!length || !angle || !GuestWritable(length, sizeof(*length)) || !GuestWritable(angle, sizeof(*angle))) GuestFault_nid_no_patch(__func__);
const Normalized normalized = Prenorm(localVector, __func__);
const GuestVector polar = PseudoPolarize(normalized.vector);
const int shift = normalized.shift;
Expand All @@ -215,24 +215,26 @@ void APS5_VABI sceFreeTypeOtVectorPolarize_nid_no_patch(GuestVector* vector, std
};
const std::int64_t result = finish(false);
if (result != finish(true)) NotImplemented_nid_no_patch(__func__);
if (!GuestCopyOut_nid_no_patch(length, &result, sizeof(result))) NotImplemented_nid_no_patch(__func__);
if (!GuestCopyOut_nid_no_patch(angle, &polar.y, sizeof(polar.y))) NotImplemented_nid_no_patch(__func__);
if (!GuestCopyOut_nid_no_patch(length, &result, sizeof(result))) GuestFault_nid_no_patch(__func__);
if (!GuestCopyOut_nid_no_patch(angle, &polar.y, sizeof(polar.y))) GuestFault_nid_no_patch(__func__);
}
APS5_EXPORT("HMcNe70D9TI", sceFreeTypeOtVectorPolarize_nid_no_patch);

void APS5_VABI sceFreeTypeOtVectorFromPolar_nid_no_patch(GuestVector* vector, std::int64_t length, std::int64_t angle) {
if (!vector || !GuestWritable(vector, sizeof(*vector))) NotImplemented_nid_no_patch(__func__);
if (!vector || !GuestWritable(vector, sizeof(*vector))) GuestFault_nid_no_patch(__func__);
const GuestVector rotated = Rotated({length, 0}, angle, __func__);
if (!GuestCopyOut_nid_no_patch(vector, &rotated, sizeof(rotated))) NotImplemented_nid_no_patch(__func__);
if (!GuestCopyOut_nid_no_patch(vector, &rotated, sizeof(rotated))) GuestFault_nid_no_patch(__func__);
}
APS5_EXPORT("2rmvbvOCyjY", sceFreeTypeOtVectorFromPolar_nid_no_patch);

void APS5_VABI sceFreeTypeOtVectorRotate_nid_no_patch(GuestVector* vector, std::int64_t angle) {
if (!vector || !GuestWritable(vector, sizeof(*vector))) NotImplemented_nid_no_patch(__func__);
if (!vector) GuestFault_nid_no_patch(__func__);
GuestVector localVector{};
if (!GuestCopyIn_nid_no_patch(&localVector, vector, sizeof(localVector))) NotImplemented_nid_no_patch(__func__);
if (!GuestCopyIn_nid_no_patch(&localVector, vector, sizeof(localVector))) GuestFault_nid_no_patch(__func__);
if (angle == 0 || (localVector.x == 0 && localVector.y == 0)) return;
if (!GuestWritable(vector, sizeof(*vector))) GuestFault_nid_no_patch(__func__);
const GuestVector rotated = Rotated(localVector, angle, __func__);
if (!GuestCopyOut_nid_no_patch(vector, &rotated, sizeof(rotated))) NotImplemented_nid_no_patch(__func__);
if (!GuestCopyOut_nid_no_patch(vector, &rotated, sizeof(rotated))) GuestFault_nid_no_patch(__func__);
}
APS5_EXPORT("6wJwUIVwAxg", sceFreeTypeOtVectorRotate_nid_no_patch);

Expand Down
14 changes: 11 additions & 3 deletions core/libs/tests/GuestFreeTypeOtPolar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstdlib>
#include <limits>
#include <stdexcept>
#include <string_view>

namespace {

Expand Down Expand Up @@ -41,8 +42,8 @@ void Require(bool condition, const char* message) {
template <typename TCall> bool Throws(TCall call) {
try {
call();
} catch (const std::runtime_error&) {
return true;
} catch (const std::runtime_error& error) {
return std::string_view(error.what()).find("faults on") != std::string_view::npos;
}
return false;
}
Expand Down Expand Up @@ -104,6 +105,7 @@ void Rotate() {
Require(Rotates({0x7FFFFFFFFFFFLL, 3}, 0, {0x7FFFFFFFFFFFLL, 3}), "a zero angle takes any magnitude");
Require(Throws([] { sceFreeTypeOtVectorRotate_nid_no_patch(nullptr, Degree); }), "a null vector throws");
Require(Throws([] { sceFreeTypeOtVectorRotate_nid_no_patch(reinterpret_cast<GuestVector*>(0x10), Degree); }), "an unwritable vector throws");
Require(Throws([] { sceFreeTypeOtVectorRotate_nid_no_patch(nullptr, 0); }) && Throws([] { sceFreeTypeOtVectorRotate_nid_no_patch(reinterpret_cast<GuestVector*>(0x10), 0); }), "a zero angle still reads the vector first");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

GuestVector vector{-1, -1};
sceFreeTypeOtVectorFromPolar_nid_no_patch(&vector, Degree, 30 * Degree);
Expand Down Expand Up @@ -163,7 +165,13 @@ void HostWriteAndErrno() {
expectHostWrite(badVector, sizeof(GuestVector));
errno = 74;
Require(Throws([&] { sceFreeTypeOtVectorRotate_nid_no_patch(badVector, 90 * Degree); }), "rotate bad vector throws");
Require(g_expectedHostWriteHits == 1 && errno == 74, "rotate bad vector opens HostWrite and preserves errno");
Require(g_expectedHostWriteHits == 0 && errno == 74, "rotate reads the vector before it opens HostWrite, as FreeType 2.4.11 reads vec first");

static const GuestVector readOnlyVector{7, -9};
auto* const readOnly = const_cast<GuestVector*>(&readOnlyVector);
sceFreeTypeOtVectorRotate_nid_no_patch(readOnly, 0);
Require(readOnlyVector.x == 7 && readOnlyVector.y == -9, "rotate by a zero angle does not write the vector");
Require(Throws([&] { sceFreeTypeOtVectorRotate_nid_no_patch(readOnly, 90 * Degree); }), "rotate faults on a read-only vector it has to write");

GuestVector rotVector{Degree, 0};
expectHostWrite(&rotVector, sizeof(rotVector));
Expand Down