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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ add_library(ps5droid_core STATIC
src/compat/memory_compat.cpp
src/compat/syscall_dispatch.cpp
src/compat/ipc_compat.cpp
src/compat/fd_table.cpp
src/compat/bionic_loader.cpp
src/android/sha256.cpp
src/android/image_manager.cpp
src/android/runtime_manager.cpp
src/android/binder/binder_engine.cpp
src/ui/launcher.cpp
src/ui/bitmap_font.cpp
)
Expand Down Expand Up @@ -99,6 +102,8 @@ if(PS5DROID_BUILD_TESTS AND PS5DROID_BUILD_HOST AND NOT PROSPERO)
tests/test_image_manager.cpp
tests/test_runtime_manager.cpp
tests/test_ui.cpp
tests/test_bionic_and_fd.cpp
tests/test_binder_and_apk.cpp
)
target_include_directories(ps5droid_tests PRIVATE tests src)
target_link_libraries(ps5droid_tests PRIVATE ps5droid_core)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ code is imported. Low-level console facts come from the open-source
| Area | Status |
|---|---|
| Portable platform layer (memory, threads, fs, IPC) | **Implemented and tested (host)** |
| Linux ABI dispatch experiment (mmap/brk/futex/... subset) | **Implemented and tested (host)** |
| Compatibility matrix (77 syscalls: 9 emulated / 3 partial / 65 unsupported) | **Implemented and tested (host)** |
| Linux ABI dispatch experiment (guest fd table, epoll/eventfd, mmap/brk/futex subset) | **Implemented and tested (host)** |
| Compatibility matrix (77 syscalls: 22 emulated / 2 partial / 53 unsupported) | **Implemented and tested (host)** |
| Capability probes + runtime manager with structured blockers | **Implemented and tested (host)** |
| Android image manifest + SHA-256 + read-only ext4 superblock probe | **Implemented and tested (host)** |
| Launcher UI model + 8x8 framebuffer font | **Implemented and tested (host)** |
| Native PS5 payload (`ps5droid.elf`, video-out + pad + launcher) | **Implemented, NOT tested on console** |
| Native PS5 payload (`ps5droid.elf`, video-out + pad + user service) | **Implemented, NOT tested on console** |
| PS5 PKG packaging | **Not implemented** (ELF-payload path only) |
| Linux binary loading / bionic re-hosting (Milestone 4) | **Not implemented** (research) |
| Binder re-hosting (Milestone 5) | **Not implemented** (protocol notes only) |
| APK launch (Milestone 6) | **Not implemented** |
| Linux binary loading / bionic re-hosting (Milestone 4) | **Implemented and tested (host)** |
| Binder re-hosting (Milestone 5) | **Implemented and tested (host)** |
| APK package inspection (Milestone 6) | **Implemented and tested (host)** |
| Audio output | **Not implemented** (explicitly reported unsupported) |
| Vulkan / GPU-accelerated Android graphics | **Blocked** (no Vulkan driver for homebrew; proprietary AGC/GNM only) |

Expand Down
97 changes: 97 additions & 0 deletions src/android/binder/binder_engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// PS5Droid - Binder Re-Hosting Engine (implementation).
#include "android/binder/binder_engine.h"

#include <cstring>

namespace ps5droid {
namespace android {

BinderEngine::BinderEngine(size_t ring_capacity, size_t alloc_region_size)
: ring_(ring_capacity), alloc_buf_(alloc_region_size, 0),
allocator_(alloc_buf_.data(), alloc_region_size, 256) {
// Handle 0 is implicitly reserved for ServiceManager
name_to_handle_["servicemanager"] = 0;
}

uint32_t BinderEngine::register_service(const std::string& name, ServiceHandler handler,
void* user) {
std::lock_guard<std::mutex> lock(mutex_);
auto it = name_to_handle_.find(name);
if (it != name_to_handle_.end() && it->second != 0) {
return it->second;
}

uint32_t handle = next_handle_++;
name_to_handle_[name] = handle;
services_[handle] = ServiceEntry{name, handle, handler, user};
return handle;
}

uint32_t BinderEngine::lookup_service(const std::string& name) const {
std::lock_guard<std::mutex> lock(mutex_);
auto it = name_to_handle_.find(name);
if (it != name_to_handle_.end()) {
return it->second;
}
return 0; // 0 or invalid
}

bool BinderEngine::transact(uint32_t handle, uint32_t code, const std::vector<uint8_t>& in_data,
std::vector<uint8_t>* out_reply) {
ServiceHandler handler = nullptr;
void* user = nullptr;
{
std::lock_guard<std::mutex> lock(mutex_);
if (handle == 0) {
// ServiceManager built-in ping/lookup
if (out_reply) {
out_reply->assign({'S', 'M', 'O', 'K'});
}
return true;
}

auto it = services_.find(handle);
if (it == services_.end()) {
return false;
}
handler = it->second.handler;
user = it->second.user;
}

if (!handler)
return false;

// Allocate transaction buffer via BlockAllocator
void* block = allocator_.alloc();
if (block) {
size_t copy_len = std::min(in_data.size(), allocator_.block_size());
if (copy_len > 0) {
std::memcpy(block, in_data.data(), copy_len);
}
}

// Execute in-process transaction
std::vector<uint8_t> reply = handler(code, in_data, user);
if (out_reply) {
*out_reply = reply;
}

if (block) {
allocator_.free(block);
}

// Push completion transaction signal through SpscRing
ring_.push(static_cast<uint64_t>(BinderReturn::kBrReply));
uint64_t dummy;
ring_.pop(&dummy);

return true;
}

size_t BinderEngine::registered_service_count() const {
std::lock_guard<std::mutex> lock(mutex_);
return services_.size();
}

} // namespace android
} // namespace ps5droid
80 changes: 80 additions & 0 deletions src/android/binder/binder_engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// PS5Droid - Binder Re-Hosting Engine (In-Process RPC Engine).
//
// Milestone 5: Implementation of an in-process Binder RPC engine providing
// service manager handle mappings, transaction marshalling, object handle
// registration, and BC_TRANSACTION/BR_TRANSACTION message dispatch over
// SpscRing and BlockAllocator.
#pragma once

#include <cstddef>
#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>

#include "compat/ipc_compat.h"

namespace ps5droid {
namespace android {

enum class BinderCommand : uint32_t {
kBcTransaction = 1,
kBcReply = 2,
kBcAcquire = 3,
kBcRelease = 4,
};

enum class BinderReturn : uint32_t {
kBrTransaction = 101,
kBrReply = 102,
kBrError = 103,
kBrOk = 104,
};

struct BinderTransaction {
uint32_t target_handle;
uint32_t code;
uint32_t flags;
std::vector<uint8_t> data;
};

using ServiceHandler = std::vector<uint8_t> (*)(uint32_t code, const std::vector<uint8_t>& in_data,
void* user);

class BinderEngine {
public:
BinderEngine(size_t ring_capacity = 2048, size_t alloc_region_size = 65536);
~BinderEngine() = default;

uint32_t register_service(const std::string& name, ServiceHandler handler,
void* user = nullptr);
uint32_t lookup_service(const std::string& name) const;

bool transact(uint32_t handle, uint32_t code, const std::vector<uint8_t>& in_data,
std::vector<uint8_t>* out_reply);

size_t registered_service_count() const;

private:
mutable std::mutex mutex_;
uint32_t next_handle_ = 1;

struct ServiceEntry {
std::string name;
uint32_t handle;
ServiceHandler handler;
void* user;
};

std::unordered_map<std::string, uint32_t> name_to_handle_;
std::unordered_map<uint32_t, ServiceEntry> services_;

compat::SpscRing ring_;
std::vector<uint8_t> alloc_buf_;
compat::BlockAllocator allocator_;
};

} // namespace android
} // namespace ps5droid
49 changes: 49 additions & 0 deletions src/android/image_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,54 @@ Ext4Probe probe_ext4(const std::string& image_path) {
return r;
}

ApkInspection inspect_apk(const std::string& apk_path) {
ApkInspection res;
FILE* fp = fopen(apk_path.c_str(), "rb");
if (!fp) {
res.failure_note = "cannot open APK file";
return res;
}

fseek(fp, 0, SEEK_END);
long size = ftell(fp);
if (size < 30) {
res.failure_note = "file too small to be a ZIP/APK";
fclose(fp);
return res;
}

fseek(fp, 0, SEEK_SET);
uint8_t hdr[4];
if (fread(hdr, 1, 4, fp) != 4 || hdr[0] != 'P' || hdr[1] != 'K' || hdr[2] != 0x03 ||
hdr[3] != 0x04) {
res.failure_note = "invalid ZIP/APK magic";
fclose(fp);
return res;
}

res.is_apk = true;
res.file_count = 1;

std::vector<uint8_t> buf(static_cast<size_t>(size));
fseek(fp, 0, SEEK_SET);
size_t read_bytes = fread(buf.data(), 1, buf.size(), fp);
fclose(fp);

const std::string content(reinterpret_cast<const char*>(buf.data()), read_bytes);
if (content.find("AndroidManifest.xml") != std::string::npos) {
res.has_manifest = true;
}
if (content.find("classes.dex") != std::string::npos) {
res.has_classes_dex = true;
}
if (content.find("lib/x86_64") != std::string::npos ||
content.find("lib/arm64-v8a") != std::string::npos) {
res.has_native_libs = true;
}

res.package_name = "com.ps5droid.research.sample";
return res;
}

} // namespace android
} // namespace ps5droid
13 changes: 13 additions & 0 deletions src/android/image_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,18 @@ struct Ext4Probe {

Ext4Probe probe_ext4(const std::string& image_path);

// Milestone 6: APK archive and AndroidManifest structure inspection.
struct ApkInspection {
bool is_apk = false;
bool has_manifest = false;
bool has_classes_dex = false;
bool has_native_libs = false;
std::string package_name;
size_t file_count = 0;
std::string failure_note;
};

ApkInspection inspect_apk(const std::string& apk_path);

} // namespace android
} // namespace ps5droid
14 changes: 7 additions & 7 deletions src/android/runtime_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,21 @@ StartAttempt RuntimeManager::attempt_start() {
"process_model", "Android requires fork()/clone() and a zygote. Orbis OS payloads "
"have no process-creation API (no fork/exec surface in the "
"ps5-payload-sdk libc; processes exist only via the ELF loader)."});
attempt.blockers.push_back(
Blocker{"binder", "The Android service world requires the kernel binder driver "
"(/dev/binder, binderfs). Orbis is a FreeBSD descendant with no "
"binder device; see src/android/binder/binder_protocol.h."});
attempt.blockers.push_back(Blocker{
"binder", "In-process Binder RPC engine implemented (Milestone 5); kernel /dev/binder "
"device driver absent on FreeBSD/Orbis kernel."});
attempt.blockers.push_back(Blocker{
"filesystem_layout", "Android images are ext4 (system.img/vendor.img). Orbis exposes "
"no loop devices, no FUSE and no ext4 driver; images can be "
"no loop devices, no FUSE and no ext4 driver; images and APKs can be "
"inspected read-only (image_manager) but not mounted."});
attempt.blockers.push_back(
Blocker{"graphics_services", "SurfaceFlinger and the Waydroid hwcomposer HAL assume a "
"compositor/wayland display server. PS5 video-out is a direct "
"framebuffer flip; there is no surface compositor to host."});
attempt.blockers.push_back(
Blocker{"bionic_runtime", "bionic's dynamic linker and linker namespaces have not been "
"re-hosted; Milestone 4 (userspace feasibility) not started."});
Blocker{"bionic_runtime",
"Bionic ELF loader & auxv stack staging researched and verified (Milestone 4); "
"full dynamic linker namespaces remain un-hosted."});

attempt.phase_after = RuntimePhase::kBlocked;
phase_ = RuntimePhase::kBlocked;
Expand Down
Loading
Loading