Build a peer-gated Thor producer fence APK artifact

This commit is contained in:
Kurt Himebauch committed 2026-12-03 10:41:48 -05:00
1 parent affb0da37f
commit 8e579b4d20
15 files changed
+714 -213

No files matched your search

+11 -193
View File
@@ -1,39 +1,13 @@
name: Build APK
run-name: ${{ github.event_name == 'pull_request' && format('building pr {0} on {1} against {2}', github.event.pull_request.number, github.event.pull_request.head.sha, github.event.pull_request.base.sha) || format('building {0} on {1}', github.ref_name, github.sha) }}
name: Build Thor paired compositor probe (artifact only)
run-name: Verify exact paired compositor probe on ${{ github.sha }}
on:
push:
branches: [ main ]
paths-ignore:
- '**/*.md'
- 'LICENSE'
- '.gitignore'
- 'docs/**'
- '.github/ISSUE_TEMPLATE/**'
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened, ready_for_review ]
paths-ignore:
- '**/*.md'
- 'LICENSE'
- '.gitignore'
- 'docs/**'
- '.github/ISSUE_TEMPLATE/**'
workflow_dispatch:
inputs:
rebuild_preloads:
description: Rebuild preloads instead of reusing the approved binary snapshot
type: boolean
default: false
branches: [build/thor-host-producer-fence-affb0da]
permissions:
contents: read
actions: read
pull-requests: write
concurrency:
group: build-${{ github.event.pull_request.number || (github.event_name == 'push' && 'main') || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }}
jobs:
source:
@@ -141,23 +115,13 @@ jobs:
retention-days: 14
overwrite: true
components-runner:
needs: source
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
uses: ./.github/workflows/pick-runner.yml
secrets:
RUNNER_STATUS_TOKEN: ${{ secrets.RUNNER_STATUS_TOKEN }}
components:
name: Prepare verified components
needs: [source, components-runner]
needs: [source]
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
runs-on: ${{ fromJSON(needs.components-runner.outputs.labels) }}
runs-on: ubuntu-24.04
timeout-minutes: 40
steps:
- name: Reclaim files a cancelled container build left owned by root
if: runner.environment == 'self-hosted'
run: sudo -n chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE" || echo "::warning::could not reclaim $GITHUB_WORKSPACE"
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -167,9 +131,6 @@ jobs:
!/docs/releases/media/
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Clear scratch earlier runs left behind
if: runner.environment == 'self-hosted'
run: bash tools/ci/clear-runner-scratch.sh "$GITHUB_WORKSPACE"
- name: Merge the pinned APK base
if: github.event_name == 'pull_request'
env:
@@ -343,25 +304,15 @@ jobs:
retention-days: 14
overwrite: true
build-runner:
needs: [components]
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
uses: ./.github/workflows/pick-runner.yml
secrets:
RUNNER_STATUS_TOKEN: ${{ secrets.RUNNER_STATUS_TOKEN }}
build:
needs: [source, components, xbox, build-runner]
needs: [source, components, xbox]
name: Compile APK
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
runs-on: ${{ fromJSON(needs.build-runner.outputs.labels) }}
runs-on: ubuntu-24.04
timeout-minutes: 45
outputs:
variants: ${{ steps.variants.outputs.list }}
steps:
- name: Reclaim files a cancelled container build left owned by root
if: runner.environment == 'self-hosted'
run: sudo -n chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE" || echo "::warning::could not reclaim $GITHUB_WORKSPACE"
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -373,10 +324,6 @@ jobs:
persist-credentials: false
submodules: recursive
- name: Clear scratch earlier runs left behind
if: runner.environment == 'self-hosted'
run: bash tools/ci/clear-runner-scratch.sh "$GITHUB_WORKSPACE"
- name: Check human authorship
env:
EVENT_NAME: ${{ github.event_name }}
@@ -693,14 +640,16 @@ jobs:
id: build
env:
DROIDDECK_BUILD_LABEL: ${{ steps.build-label.outputs.label }}
SGDB_API_KEY: ${{ secrets.SGDB_API_KEY }}
run: |
set -o pipefail
python3 tools/powervr/fetch.py
python3 tools/release/runtime_inputs.py record
./gradlew assembleRelease --console=plain -PndkVersion="$NDK_VERSION" 2>&1 | tee /tmp/build.log
./gradlew assembleRelease --console=plain -PdroiddeckFrameAcquireProbe=true -PndkVersion="$NDK_VERSION" 2>&1 | tee /tmp/build.log
python3 tools/release/check_session_assets.py app/build/outputs/apk/release/app-release.apk
python3 tools/release/runtime_inputs.py apk app/build/outputs/apk/release/app-release.apk
unzip -p app/build/outputs/apk/release/app-release.apk lib/arm64-v8a/libdroiddeckwayland.so > "$RUNNER_TEMP/compositor-probe.so"
LC_ALL=C grep -aFq 'debug.droiddeck.frame_acquire_pid' "$RUNNER_TEMP/compositor-probe.so"
rm "$RUNNER_TEMP/compositor-probe.so"
- name: Check the store engines' library
run: |
@@ -768,17 +717,6 @@ jobs:
compression-level: 0
overwrite: true
- name: Report on the pull request
if: always() && github.event_name == 'pull_request'
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
BUILD_OUTCOME: ${{ steps.build.outcome }}
APK_OUTCOME: ${{ steps.apk-upload.outcome }}
run: bash tools/release/report-build.sh
store-tests:
name: Store engines host tests
needs: source
@@ -930,123 +868,3 @@ jobs:
PYTHON_RESULT: ${{ needs.python-tests.result }}
STORE_RESULT: ${{ needs.store-tests.result }}
run: test "$BUILD_RESULT" = success && test "$PYTHON_RESULT" = success && test "$STORE_RESULT" = success
sign:
needs: [build, checks]
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
permissions:
contents: read
actions: read
uses: ./.github/workflows/sign.yml
with:
environment: signing-main
variants: ${{ needs.build.outputs.variants }}
secrets: inherit
scan:
needs: sign
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
permissions:
contents: read
uses: ./.github/workflows/scan.yml
with:
artifact: droiddeck-signed
variant: standard
secrets: inherit
packs:
needs: [build, checks]
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
permissions:
contents: read
actions: read
uses: ./.github/workflows/publish-packs.yml
secrets: inherit
announce:
needs: [build, sign, packs]
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
pull-requests: read
env:
CI_REPO: Droid-Deck/DroidDeck-CI
KEEP_DAYS: 14
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/download-artifact@v4
with:
pattern: droiddeck-signed-*
merge-multiple: true
path: signed
- uses: actions/create-github-app-token@v2
id: ci-token
with:
app-id: ${{ vars.DROIDDECK_CI_APP_ID }}
private-key: ${{ secrets.DROIDDECK_CI_APP_KEY }}
owner: Droid-Deck
repositories: DroidDeck-CI
- name: Describe the change
env:
GH_TOKEN: ${{ github.token }}
run: bash tools/release/describe-build.sh
- name: Publish to DroidDeck-CI
id: publish
env:
GH_TOKEN: ${{ steps.ci-token.outputs.token }}
run: bash tools/release/publish-ci.sh
- name: Post the Preview build to Discord
env:
WEBHOOK: ${{ secrets.DISCORD_BUILDS_WEBHOOK }}
GH_TOKEN: ${{ github.token }}
RELEASE: ${{ steps.publish.outputs.release }}
APK: ${{ steps.publish.outputs.apk }}
run: bash tools/release/announce-preview.sh
catalog:
needs: announce
if: ${{ always() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && needs.announce.result != 'skipped' }}
uses: ./.github/workflows/update-catalog.yml
secrets: inherit
retire-tests:
needs: catalog
if: ${{ always() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && needs.catalog.result == 'success' }}
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/create-github-app-token@v2
id: ci-token
with:
app-id: ${{ vars.DROIDDECK_CI_APP_ID }}
private-key: ${{ secrets.DROIDDECK_CI_APP_KEY }}
owner: Droid-Deck
repositories: DroidDeck-CI
- name: Delete the test builds this Preview build replaces
env:
SOURCE_GITHUB_TOKEN: ${{ github.token }}
CI_GITHUB_TOKEN: ${{ steps.ci-token.outputs.token }}
run: python3 tools/release/retire_test_builds.py
catalog-after-retire:
needs: retire-tests
if: ${{ always() && needs.retire-tests.result == 'success' }}
uses: ./.github/workflows/update-catalog.yml
secrets: inherit
+3
View File
@@ -164,6 +164,9 @@ android {
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared'
if (project.findProperty('droiddeckFrameAcquireProbe') == 'true') {
arguments '-DDROIDDECK_FRAME_ACQUIRE_PROBE=ON'
}
arguments "-DDROIDDECK_VITURE_SDK_DIR=${vitureSdkDir.toString().replace('\\', '/')}"
arguments "-DDROIDDECK_UVC_DIR=${uvcDir.toString().replace('\\', '/')}"
}
@@ -42,6 +42,11 @@ add_library(droiddeckwayland SHARED
src/hudframes.c
src/hudframes_jni.c
)
option(DROIDDECK_FRAME_ACQUIRE_PROBE "Advertise test-only signaled producer acquire protocol" OFF)
if (DROIDDECK_FRAME_ACQUIRE_PROBE)
target_sources(droiddeckwayland PRIVATE generated/droiddeck-frame-acquire-v1-protocol.c)
target_compile_definitions(droiddeckwayland PRIVATE DROIDDECK_FRAME_ACQUIRE_PROBE=1)
endif()
target_compile_options(droiddeckwayland PRIVATE
$<$<COMPILE_LANGUAGE:C>:-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers>)
target_include_directories(droiddeckwayland PRIVATE
@@ -0,0 +1,35 @@
/* Generated by wayland-scanner 1.22.0 */
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_buffer_interface;
extern const struct wl_interface wl_surface_interface;
static const struct wl_interface *droiddeck_frame_acquire_v1_types[] = {
&wl_surface_interface,
&wl_buffer_interface,
NULL,
};
static const struct wl_message droiddeck_frame_acquire_v1_requests[] = {
{ "destroy", "", droiddeck_frame_acquire_v1_types + 0 },
{ "set_acquire_fence", "ooh", droiddeck_frame_acquire_v1_types + 0 },
};
WL_PRIVATE const struct wl_interface droiddeck_frame_acquire_v1_interface = {
"droiddeck_frame_acquire_v1", 1,
2, droiddeck_frame_acquire_v1_requests,
0, NULL,
};
@@ -0,0 +1,128 @@
/* Generated by wayland-scanner 1.22.0 */
#ifndef DROIDDECK_FRAME_ACQUIRE_V1_SERVER_PROTOCOL_H
#define DROIDDECK_FRAME_ACQUIRE_V1_SERVER_PROTOCOL_H
#include <stdint.h>
#include <stddef.h>
#include "wayland-server.h"
#ifdef __cplusplus
extern "C" {
#endif
struct wl_client;
struct wl_resource;
/**
* @page page_droiddeck_frame_acquire_v1 The droiddeck_frame_acquire_v1 protocol
* @section page_ifaces_droiddeck_frame_acquire_v1 Interfaces
* - @subpage page_iface_droiddeck_frame_acquire_v1 - DroidDeck producer write completion for a single Wayland attachment
*/
struct droiddeck_frame_acquire_v1;
struct wl_buffer;
struct wl_surface;
#ifndef DROIDDECK_FRAME_ACQUIRE_V1_INTERFACE
#define DROIDDECK_FRAME_ACQUIRE_V1_INTERFACE
/**
* @page page_iface_droiddeck_frame_acquire_v1 droiddeck_frame_acquire_v1
* @section page_iface_droiddeck_frame_acquire_v1_desc Description
*
* Optional explicit acquire sideband independent of DRM syncobj and buffer
* allocation. Binding does not opt the client out of ordinary wl_buffer
* release or existing synchronization protocols. The server advertises it
* only when it implements all semantics for the selected display path.
* @section page_iface_droiddeck_frame_acquire_v1_api API
* See @ref iface_droiddeck_frame_acquire_v1.
*/
/**
* @defgroup iface_droiddeck_frame_acquire_v1 The droiddeck_frame_acquire_v1 interface
*
* Optional explicit acquire sideband independent of DRM syncobj and buffer
* allocation. Binding does not opt the client out of ordinary wl_buffer
* release or existing synchronization protocols. The server advertises it
* only when it implements all semantics for the selected display path.
*/
extern const struct wl_interface droiddeck_frame_acquire_v1_interface;
#endif
#ifndef DROIDDECK_FRAME_ACQUIRE_V1_ERROR_ENUM
#define DROIDDECK_FRAME_ACQUIRE_V1_ERROR_ENUM
enum droiddeck_frame_acquire_v1_error {
/**
* not the same client's pending DMA-BUF attachment
*/
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_ATTACHMENT = 0,
/**
* that attachment already has an acquire fence
*/
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_DUPLICATE_FENCE = 1,
/**
* not a real successfully signaled Linux sync_file
*/
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_FENCE = 2,
/**
* not the paired test peer
*/
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_UNAUTHORIZED_PEER = 3,
};
#endif /* DROIDDECK_FRAME_ACQUIRE_V1_ERROR_ENUM */
/**
* @ingroup iface_droiddeck_frame_acquire_v1
* @struct droiddeck_frame_acquire_v1_interface
*/
struct droiddeck_frame_acquire_v1_interface {
/**
*/
void (*destroy)(struct wl_client *client,
struct wl_resource *resource);
/**
* set a one-shot kernel sync_file for the pending attachment
*
* After wl_surface.attach of a non-null buffer, and before its
* next wl_surface.commit, send the producer's final writer fence
* for that exact attachment. This outer probe requires that fence
* to have already successfully signaled. The fence must be a real
* Linux sync_file, not a dma-buf, eventfd, or Vulkan OPAQUE_FD.
* The server consumes its received descriptor once for that
* attachment; the caller closes its local FD after marshalling.
*
* The receiver validates the matching pending surface and buffer
* and validates the descriptor. A duplicate, invalid, pending or
* mismatched request is a protocol error; it is never downgraded
* to implicit sync. Another attach (even the same wl_buffer),
* detach, surface/resource loss or supersession makes the old
* proof inapplicable. Metadata-only commits may amend
* receiver-side still-pending state but cannot introduce or re-use
* a fence themselves. If no request was made, the receiver keeps
* its established safe path. If a valid fence has been accepted
* and later the layer is ineligible, the buffer must not be
* copied/read before that fence is satisfied or imported as the
* source dependency. Transport never implies readiness on missed
* deadlines and never changes release/retirement requirements.
* @param fence producer's native acquire sync_file
*/
void (*set_acquire_fence)(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *surface,
struct wl_resource *buffer,
int32_t fence);
};
/**
* @ingroup iface_droiddeck_frame_acquire_v1
*/
#define DROIDDECK_FRAME_ACQUIRE_V1_DESTROY_SINCE_VERSION 1
/**
* @ingroup iface_droiddeck_frame_acquire_v1
*/
#define DROIDDECK_FRAME_ACQUIRE_V1_SET_ACQUIRE_FENCE_SINCE_VERSION 1
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="droiddeck_frame_acquire_v1">
<interface name="droiddeck_frame_acquire_v1" version="1">
<description summary="DroidDeck producer write completion for a single Wayland attachment">
Optional explicit acquire sideband independent of DRM syncobj and buffer
allocation. Binding does not opt the client out of ordinary wl_buffer
release or existing synchronization protocols. The server advertises it
only when it implements all semantics for the selected display path and
only to the test fixture's designated same-UID Gamescope peer.
</description>
<request name="destroy" type="destructor"/>
<enum name="error">
<entry name="invalid_attachment" value="0" summary="not the same client's pending DMA-BUF attachment"/>
<entry name="duplicate_fence" value="1" summary="that attachment already has an acquire fence"/>
<entry name="invalid_fence" value="2" summary="not a real successfully signaled Linux sync_file"/>
<entry name="unauthorized_peer" value="3" summary="not the paired test peer"/>
</enum>
<request name="set_acquire_fence">
<description summary="set a one-shot kernel sync_file for the pending attachment">
After wl_surface.attach of a non-null buffer, and before its next
wl_surface.commit, send the producer's final writer fence for that
exact attachment. This outer probe requires that fence to have already
successfully signaled. The fence must be a real Linux sync_file, not a
dma-buf, eventfd, or Vulkan OPAQUE_FD. The server consumes its received
descriptor once for that attachment; the caller closes its local FD
after marshalling.
The receiver validates the matching pending surface and buffer and
validates the descriptor. A duplicate, invalid, pending or mismatched
request is a protocol error; it is never downgraded to implicit sync. Another attach (even the same
wl_buffer), detach, surface/resource loss or supersession makes the
old proof inapplicable. Metadata-only commits may amend receiver-side
still-pending state but cannot introduce or re-use a fence themselves.
If no request was made, the receiver keeps its established safe path.
If a valid fence has been accepted and later the layer is ineligible,
the buffer must not be copied/read before that fence is satisfied or
imported as the source dependency. Transport never implies readiness
on missed deadlines and never changes release/retirement requirements.
</description>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="buffer" type="object" interface="wl_buffer"/>
<arg name="fence" type="fd" summary="producer's native acquire sync_file"/>
</request>
</interface>
</protocol>
@@ -201,28 +201,41 @@ int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_
struct ahb_buf *ab = b ? *droiddeck_dmabuf_ahb_slot(b) : NULL;
if (!ab) return -1;
int dmabuf_fd = droiddeck_dmabuf_fd(b);
int acquire = -1;
struct droiddeck_dma_buf_sync_file exp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = -1};
if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &exp) == 0 && exp.fd >= 0) {
acquire = exp.fd;
} else {
if (!g_export_failed_logged) {
g_export_failed_logged = 1;
droiddeck_log("layer", "zero-copy: no acquire fence from the game's dma-buf (%s): %s",
dmabuf_fd >= 0 ? strerror(errno) : "no dma-buf fd",
draw ? "its frames are copied instead" : "it cannot be copied, so each frame is waited for on the CPU");
int acquire = droiddeck_surface_dup_acquire(s, b);
if (acquire == -2) return -1;
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
const int explicit_acquire = acquire >= 0;
#endif
if (acquire < 0) {
struct droiddeck_dma_buf_sync_file exp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = -1};
if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &exp) == 0 && exp.fd >= 0) {
acquire = exp.fd;
} else {
if (!g_export_failed_logged) {
g_export_failed_logged = 1;
droiddeck_log("layer", "zero-copy: no acquire fence from the game's dma-buf (%s): %s",
dmabuf_fd >= 0 ? strerror(errno) : "no dma-buf fd",
draw ? "its frames are copied instead" : "it cannot be copied, so each frame is waited for on the CPU");
}
if (dmabuf_fd >= 0) {
struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN};
int r;
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
}
if (draw) return -1;
}
if (dmabuf_fd >= 0) {
struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN};
int r;
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
}
if (draw) return -1;
}
int r = sc_layer_present_ahb(ab->ahb, ab->w, ab->h, acquire, (void *)(uintptr_t)ab->id, scene_w, scene_h, draw,
s ? droiddeck_surface_color(s) : NULL, ab->format);
if (r < 0) return -1;
if (r == 1) return 0;
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
static int explicit_logged;
if (explicit_acquire && !explicit_logged) {
explicit_logged = 1;
droiddeck_log("layer", "probe: SurfaceControl accepted a verified producer acquire fence");
}
#endif
if (!ab->on_layer) {
ab->on_layer = 1;
g_stat_zero_copy++;
@@ -21,6 +21,7 @@ int ahb_swapchain_defer_release(struct dmabuf_buffer *b, struct wl_resource *buf
void ahb_swapchain_surface_gone(struct surface *s);
unsigned ahb_swapchain_stats_take(void);
int ahb_swapchain_advertised(void);
int droiddeck_surface_dup_acquire(const struct surface *s, const struct dmabuf_buffer *b);
uint32_t ahb_swapchain_ahb_format(const struct dmabuf_buffer *b);
void ahb_swapchain_layer_released(void *token, int release_fd);
@@ -23,6 +23,11 @@
#include "linux-dmabuf-v1-server-protocol.h"
#include "sc_layer.h"
#include "ahb_swapchain.h"
#include "frame_acquire.h"
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
#include "droiddeck-frame-acquire-v1-server-protocol.h"
#include <sys/system_properties.h>
#endif
#include "display_buffers.h"
#include "viewporter-server-protocol.h"
#include "droiddeck-desktop-v1-server-protocol.h"
@@ -210,6 +215,7 @@ struct surface {
struct wl_list link;
struct wl_resource *pending_buffer;
struct dd_frame_acquire pending_frame_acquire, frame_acquire;
struct wl_listener pending_buffer_destroy;
int pending_attach;
int pending_src_set, pending_dst_set;
@@ -826,6 +832,7 @@ static void unmap_toplevel(struct surface *s) {
}
static void drop_dmabuf(struct surface *s, int paced) {
dd_frame_acquire_clear(&s->frame_acquire);
if (s->dmabuf) {
wl_list_remove(&s->dmabuf_destroy.link);
if (buffer_shown_elsewhere(s->dmabuf, s)) {
@@ -841,18 +848,21 @@ static void drop_dmabuf(struct surface *s, int paced) {
static void on_dmabuf_destroyed(struct wl_listener *l, void *data) {
struct surface *s = wl_container_of(l, s, dmabuf_destroy);
dd_frame_acquire_clear(&s->frame_acquire);
wl_list_remove(&s->dmabuf_destroy.link);
s->dmabuf = NULL;
}
static void on_pending_buffer_destroyed(struct wl_listener *l, void *data) {
struct surface *s = wl_container_of(l, s, pending_buffer_destroy);
dd_frame_acquire_clear(&s->pending_frame_acquire);
wl_list_remove(&s->pending_buffer_destroy.link);
wl_list_init(&s->pending_buffer_destroy.link);
s->pending_buffer = NULL;
}
struct surface_state {
struct dd_frame_acquire frame_acquire;
struct wl_resource *buffer;
struct wl_listener buffer_destroy;
int attach;
@@ -865,6 +875,7 @@ struct surface_state {
static void on_state_buffer_destroyed(struct wl_listener *l, void *data) {
struct surface_state *st = wl_container_of(l, st, buffer_destroy);
dd_frame_acquire_clear(&st->frame_acquire);
wl_list_remove(&st->buffer_destroy.link);
wl_list_init(&st->buffer_destroy.link);
st->buffer = NULL;
@@ -873,6 +884,8 @@ static void on_state_buffer_destroyed(struct wl_listener *l, void *data) {
static void surface_state_take(struct surface *s, struct surface_state *st) {
st->attach = s->pending_attach;
st->frame_acquire = s->pending_frame_acquire;
s->pending_frame_acquire.fd_plus_one = 0;
st->buffer = s->pending_buffer;
wl_list_init(&st->buffer_destroy.link);
if (st->buffer) {
@@ -1185,6 +1198,7 @@ static void surface_attach(struct wl_client *c, struct wl_resource *r,
if (s->pending_buffer) wl_list_remove(&s->pending_buffer_destroy.link);
wl_list_init(&s->pending_buffer_destroy.link);
s->pending_buffer = buffer;
dd_frame_acquire_clear(&s->pending_frame_acquire);
s->pending_attach = 1;
if (buffer) {
s->pending_buffer_destroy.notify = on_pending_buffer_destroyed;
@@ -1450,6 +1464,7 @@ static void surface_state_apply(struct surface *s, struct surface_state *st) {
surface_drop_idle(s);
buf_trace_attach(buffer);
dd_frame_acquire_clear(&s->frame_acquire);
if (s->role == ROLE_CURSOR) {
if (!buffer) {
cursor_publish_hidden();
@@ -1461,6 +1476,8 @@ static void surface_state_apply(struct surface *s, struct surface_state *st) {
if (buffer) surface_hold_idle(s, buffer);
} else if (db) {
take_dmabuf(s, db, buffer);
s->frame_acquire = st->frame_acquire;
st->frame_acquire.fd_plus_one = 0;
} else if (shm) {
drop_dmabuf(s, 1);
take_shm(s, shm, buffer);
@@ -1473,6 +1490,7 @@ static void surface_state_apply(struct surface *s, struct surface_state *st) {
if (buffer) send_buffer_release(buffer);
}
}
dd_frame_acquire_clear(&st->frame_acquire);
pending_releases_apply(s);
wl_list_for_each(child, &s->children, child_link) {
@@ -1537,6 +1555,7 @@ static void settle_unwaited(void) {
}
static void surface_state_discard(struct surface_state *st) {
dd_frame_acquire_clear(&st->frame_acquire);
struct wl_resource *cb, *tmp;
wl_list_remove(&st->buffer_destroy.link);
wl_resource_for_each_safe(cb, tmp, &st->frames) wl_resource_destroy(cb);
@@ -1548,6 +1567,8 @@ static void surface_state_merge(struct surface_state *older, struct surface_stat
if (older->attach && !newer->attach) {
newer->attach = 1;
newer->buffer = older->buffer;
newer->frame_acquire = older->frame_acquire;
older->frame_acquire.fd_plus_one = 0;
wl_list_remove(&older->buffer_destroy.link);
wl_list_init(&older->buffer_destroy.link);
if (newer->buffer) {
@@ -1699,6 +1720,90 @@ static const struct wl_surface_interface surface_impl = {
.offset = surface_offset,
};
int droiddeck_surface_dup_acquire(const struct surface *s, const struct dmabuf_buffer *b) {
return s && s->dmabuf && s->dmabuf_buf == b ? dd_frame_acquire_dup(&s->frame_acquire) : -1;
}
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
// Private, signed test fixture only. The shell designates a single verified
// pre-exec Gamescope PID; same-UID clients and all other Wayland globals keep
// their ordinary behavior but cannot bind (or use) this protocol.
static int frame_acquire_peer_allowed(const struct wl_client *client) {
char value[PROP_VALUE_MAX] = {0};
int len = __system_property_get("debug.droiddeck.frame_acquire_pid", value);
if (len <= 0 || len >= (int)sizeof(value) || value[0] < '1' || value[0] > '9')
return 0;
int wanted = 0;
for (int i = 0; i < len; i++) {
int digit = value[i] - '0';
if (digit < 0 || digit > 9 || wanted > (INT_MAX - digit) / 10)
return 0;
wanted = wanted * 10 + digit;
}
pid_t peer_pid = 0;
uid_t peer_uid = (uid_t)-1;
wl_client_get_credentials(client, &peer_pid, &peer_uid, NULL);
return wanted > 1 && peer_pid == wanted && peer_uid == getuid();
}
static bool frame_acquire_global_filter(const struct wl_client *client, const struct wl_global *global, void *data) {
return wl_global_get_interface(global) != &droiddeck_frame_acquire_v1_interface ||
frame_acquire_peer_allowed(client);
}
static void frame_acquire_destroy(struct wl_client *client, struct wl_resource *resource) {
wl_resource_destroy(resource);
}
static void frame_acquire_set(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *surface, struct wl_resource *buffer, int32_t fd) {
if (!frame_acquire_peer_allowed(client)) {
close(fd);
wl_resource_post_error(resource, DROIDDECK_FRAME_ACQUIRE_V1_ERROR_UNAUTHORIZED_PEER,
"paired capture peer is not authorized");
return;
}
struct surface *s = NULL;
if (surface && buffer && wl_resource_get_client(surface) == client &&
wl_resource_get_client(buffer) == client &&
wl_resource_instance_of(surface, &wl_surface_interface, &surface_impl) &&
get_dmabuf(buffer))
s = wl_resource_get_user_data(surface);
if (!s || !s->pending_attach || s->pending_buffer != buffer) {
close(fd);
wl_resource_post_error(resource, DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_ATTACHMENT,
"fence does not match pending DMA-BUF attachment");
return;
}
enum dd_frame_acquire_result result = dd_frame_acquire_set(&s->pending_frame_acquire, fd);
if (result == DD_ACQUIRE_DUPLICATE)
wl_resource_post_error(resource, DROIDDECK_FRAME_ACQUIRE_V1_ERROR_DUPLICATE_FENCE,
"pending attachment already has a fence");
else if (result == DD_ACQUIRE_INVALID)
wl_resource_post_error(resource, DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_FENCE,
"expected an already signaled Linux sync_file");
}
static const struct droiddeck_frame_acquire_v1_interface frame_acquire_impl = {
.destroy = frame_acquire_destroy,
.set_acquire_fence = frame_acquire_set,
};
static void bind_frame_acquire(struct wl_client *client, void *data, uint32_t version, uint32_t id) {
if (!frame_acquire_peer_allowed(client)) {
wl_client_post_implementation_error(client, "paired capture peer is not authorized");
return;
}
struct wl_resource *resource =
wl_resource_create(client, &droiddeck_frame_acquire_v1_interface, 1, id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &frame_acquire_impl, NULL, NULL);
}
#endif
static void detach_from_parent(struct surface *s) {
if (!s->parent) return;
wl_list_remove(&s->child_link);
@@ -1708,6 +1813,7 @@ static void detach_from_parent(struct surface *s) {
static void surface_resource_destroy(struct wl_resource *r) {
struct surface *s = wl_resource_get_user_data(r);
dd_frame_acquire_clear(&s->pending_frame_acquire);
struct surface *child, *tmp;
struct wl_resource *cb, *cbtmp;
@@ -4985,6 +5091,12 @@ int droiddeck_wayland_run(void) {
wl_global_create(display, &zwp_relative_pointer_manager_v1_interface, 1, NULL, bind_relative_pointer_manager);
droiddeck_ext_init(display);
ahb_swapchain_init(display);
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
if (ahb_swapchain_advertised()) {
wl_display_set_global_filter(display, frame_acquire_global_filter, NULL);
wl_global_create(display, &droiddeck_frame_acquire_v1_interface, 1, NULL, bind_frame_acquire);
}
#endif
display_buffers_init(display);
@@ -0,0 +1,39 @@
#ifndef DD_FRAME_ACQUIRE_H
#define DD_FRAME_ACQUIRE_H
#include <fcntl.h>
#include <limits.h>
#include <linux/sync_file.h>
#include <sys/ioctl.h>
#include <unistd.h>
/* A zero-initialized slot owns no descriptor. Only an already successful
* sync_file can enter this slot; display-side release ownership is separate. */
struct dd_frame_acquire { int fd_plus_one; };
enum dd_frame_acquire_result { DD_ACQUIRE_OK, DD_ACQUIRE_DUPLICATE, DD_ACQUIRE_INVALID };
static inline void dd_frame_acquire_clear(struct dd_frame_acquire *f) {
if (f->fd_plus_one) close(f->fd_plus_one - 1);
f->fd_plus_one = 0;
}
static inline enum dd_frame_acquire_result
dd_frame_acquire_set(struct dd_frame_acquire *f, int fd) {
enum dd_frame_acquire_result result;
struct sync_file_info info = {0};
if (f->fd_plus_one) result = DD_ACQUIRE_DUPLICATE;
else if (fd < 0 || fd == INT_MAX || ioctl(fd, SYNC_IOC_FILE_INFO, &info) != 0 ||
info.status != 1 || info.num_fences == 0) result = DD_ACQUIRE_INVALID;
else {
f->fd_plus_one = fd + 1;
return DD_ACQUIRE_OK;
}
if (fd >= 0) close(fd);
return result;
}
static inline int dd_frame_acquire_dup(const struct dd_frame_acquire *f) {
if (!f->fd_plus_one) return -1; /* Legacy: no explicit attachment proof. */
int fd = fcntl(f->fd_plus_one - 1, F_DUPFD_CLOEXEC, 0);
return fd < 0 ? -2 : fd; /* Do not re-enter the legacy direct path. */
}
#endif
+2
View File
@@ -26,6 +26,8 @@ struct wl_listener { struct wl_list link; void (*notify)(struct wl_listener *, v
struct wl_resource { struct wl_list listeners; int acquired, releases, errors; };
struct dmabuf_buffer { int unused; };
enum surface_role { ROLE_NONE, ROLE_TOPLEVEL, ROLE_SUBSURFACE };
/* These release fixtures exercise legacy attachments, which own no acquire FD. */
#define dd_frame_acquire_clear(slot) ((void)0)
struct surface {
struct wl_list link;
struct wl_resource *dmabuf;
+109
View File
@@ -0,0 +1,109 @@
"""Build the production compositor's designated-peer checks with test doubles.
Linux checks a real socket's SO_PEERCRED; the property source and Wayland
global/resource hooks are doubles. Android NDK builds exercise the real APIs.
"""
from pathlib import Path
import os
import subprocess
import tempfile
import unittest
from test_vk_pending_completion import function
SOURCE = Path(__file__).resolve().parents[2] / 'app/src/main/cpp/waylandcomp/src/compositor.c'
HEAD = r'''
#define _GNU_SOURCE
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#define PROP_VALUE_MAX 92
static const char *property;
struct wl_client { pid_t pid; uid_t uid; int rejected; };
struct wl_global { const void *interface; };
struct wl_resource { int unused; };
static int droiddeck_frame_acquire_v1_interface, frame_acquire_impl, bound, installed;
static struct wl_resource resource;
static int __system_property_get(const char *name, char *value) {
assert(!strcmp(name,"debug.droiddeck.frame_acquire_pid"));
if (!property) return 0;
size_t len = strlen(property);
if (len < PROP_VALUE_MAX) memcpy(value,property,len+1);
return (int)len;
}
static void wl_client_get_credentials(const struct wl_client *c,pid_t *pid,uid_t *uid,gid_t *gid) {
assert(!gid); *pid=c->pid; *uid=c->uid;
}
static const void *wl_global_get_interface(const struct wl_global *g) { return g->interface; }
static void wl_client_post_implementation_error(struct wl_client *c,const char *why) {
assert(why && *why); c->rejected++;
}
static struct wl_resource *wl_resource_create(struct wl_client *c,const void *i,int version,uint32_t id) {
assert(c && i==&droiddeck_frame_acquire_v1_interface && version==1 && id==9);
bound++; return &resource;
}
static void wl_client_post_no_memory(struct wl_client *c) { (void)c; abort(); }
static void wl_resource_set_implementation(struct wl_resource *r,const void *i,void *data,void *destroy) {
assert(r==&resource && i==&frame_acquire_impl && !data && !destroy); installed++;
}
'''
TAIL = r'''
int main(void) {
char pid[32], wrong[32];
struct wl_client permitted={.pid=getpid(),.uid=getuid()};
#ifdef __linux__
int sock[2]; assert(socketpair(AF_UNIX,SOCK_STREAM,0,sock)==0);
struct ucred cred; socklen_t len=sizeof(cred);
assert(getsockopt(sock[0],SOL_SOCKET,SO_PEERCRED,&cred,&len)==0);
assert(cred.pid==getpid() && cred.uid==getuid());
permitted.pid=cred.pid; permitted.uid=cred.uid;
close(sock[0]); close(sock[1]);
#endif
snprintf(pid,sizeof(pid),"%ld",(long)permitted.pid);
snprintf(wrong,sizeof(wrong),"%ld",(long)permitted.pid+1);
const char *bad[] = {NULL, "", "0","1","-2","+25"," 12","12 ","12x","012","2147483648",
"99999999999999999999999999999999999", wrong};
struct wl_global probe={&droiddeck_frame_acquire_v1_interface}, ordinary={NULL};
for (size_t n=0; n<sizeof(bad)/sizeof(*bad); n++) {
property=bad[n];
assert(frame_acquire_global_filter(&permitted,&ordinary,NULL));
assert(!frame_acquire_global_filter(&permitted,&probe,NULL));
bind_frame_acquire(&permitted,NULL,1,9);
assert(!bound && !installed);
}
assert(permitted.rejected==(int)(sizeof(bad)/sizeof(*bad)));
property=pid;
struct wl_client other_uid=permitted, other_pid=permitted;
other_uid.uid++; other_pid.pid++;
assert(!frame_acquire_peer_allowed(&other_uid));
assert(!frame_acquire_peer_allowed(&other_pid));
assert(frame_acquire_global_filter(&permitted,&probe,NULL));
bind_frame_acquire(&permitted,NULL,1,9);
assert(bound==1&&installed==1);
property=NULL; // removal also revokes ability to use an existing binding
assert(!frame_acquire_peer_allowed(&permitted));
return 0;
}
'''
class FrameAcquirePeerGateTest(unittest.TestCase):
def test_only_designated_uid_pid_can_see_or_bind_the_probe(self):
source = SOURCE.read_text()
actual = '\n'.join(function(source, name) for name in (
'frame_acquire_peer_allowed', 'frame_acquire_global_filter', 'bind_frame_acquire'))
with tempfile.TemporaryDirectory(prefix='droiddeck-frame-peer-') as tmp:
tmp = Path(tmp)
probe = tmp / 'probe.c'
binary = tmp / 'probe'
probe.write_text('#include <stdio.h>\n' + HEAD + actual + TAIL)
subprocess.run([os.environ.get('CC', 'cc'), '-std=gnu11', '-Werror', '-Wall', '-Wextra',
'-Wno-unused-parameter', str(probe), '-o', str(binary)], check=True)
subprocess.run([str(binary)], check=True, timeout=10)
+165
View File
@@ -0,0 +1,165 @@
"""Exercise production receiver and attachment replacement with Unix FD passing.
This Linux fixture stubs Wayland resources and only the success/status values of
SYNC_IOC_FILE_INFO. It does not claim a Vulkan or SurfaceFlinger hardware test.
"""
import os
from pathlib import Path
import platform
import subprocess
import tempfile
import unittest
from test_vk_pending_completion import function
SRC = Path(__file__).resolve().parents[2] / 'app/src/main/cpp/waylandcomp/src'
HEAD = r'''
#define _GNU_SOURCE
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/sync_file.h>
static int query_status, query_result;
static unsigned query_count;
static int test_ioctl(int fd, unsigned long request, void *arg) {
assert(fd >= 0 && request == SYNC_IOC_FILE_INFO);
struct sync_file_info *info = arg;
assert(!info->flags && !info->sync_fence_info);
query_count++;
info->status = query_status;
info->num_fences = 1;
return query_result;
}
#define ioctl test_ioctl
#include "frame_acquire.h"
#undef ioctl
#include "wayland-util.h"
void wl_list_init(struct wl_list *list) { list->prev = list->next = list; }
void wl_list_remove(struct wl_list *list) { (void)list; }
struct wl_listener { struct wl_list link; void (*notify)(struct wl_listener *, void *); };
struct wl_client { int identity; };
struct wl_resource { struct wl_client *owner; void *data; int type; unsigned error; };
struct surface {
struct wl_resource *pending_buffer;
struct wl_listener pending_buffer_destroy;
struct dd_frame_acquire pending_frame_acquire;
int pending_attach;
};
static int wl_surface_interface, surface_impl;
static int peer_allowed=1;
static int frame_acquire_peer_allowed(const struct wl_client *c) { (void)c; return peer_allowed; }
static struct wl_client *wl_resource_get_client(struct wl_resource *r) { return r->owner; }
static void *wl_resource_get_user_data(struct wl_resource *r) { return r->data; }
static int wl_resource_instance_of(struct wl_resource *r, const void *iface, const void *impl) {
assert(iface == &wl_surface_interface && impl == &surface_impl);
return r->type == 1;
}
static int get_dmabuf(struct wl_resource *r) { return r->type == 2; }
static void wl_resource_add_destroy_listener(struct wl_resource *r, struct wl_listener *l) { (void)r; (void)l; }
static void wl_resource_post_error(struct wl_resource *r, unsigned err, const char *why) {
assert(why && !r->error);
r->error = err+1;
}
'''
TAIL = r'''
/* Real descriptor transfer and sender close; before dispatch, receiver owns it. */
static int tx(int fd) {
int conn[2]; char byte = 'F';
assert(socketpair(AF_UNIX, SOCK_DGRAM, 0, conn) == 0);
union { struct cmsghdr a; char bytes[CMSG_SPACE(sizeof(fd))]; } control = {0};
struct iovec payload = {.iov_base=&byte, .iov_len=1};
struct msghdr msg = {.msg_iov=&payload, .msg_iovlen=1, .msg_control=control.bytes,
.msg_controllen=sizeof(control.bytes)};
struct cmsghdr *h = CMSG_FIRSTHDR(&msg);
h->cmsg_len=CMSG_LEN(sizeof(fd)); h->cmsg_level=SOL_SOCKET; h->cmsg_type=SCM_RIGHTS;
memcpy(CMSG_DATA(h), &fd, sizeof(fd));
assert(sendmsg(conn[0], &msg, 0) == 1);
assert(close(fd) == 0);
memset(&control, 0, sizeof(control));
assert(recvmsg(conn[1], &msg, MSG_CMSG_CLOEXEC) == 1);
assert(!(msg.msg_flags & (MSG_CTRUNC | MSG_TRUNC)) && byte == 'F');
h=CMSG_FIRSTHDR(&msg);
assert(h && h->cmsg_len==CMSG_LEN(sizeof(fd)) && h->cmsg_level==SOL_SOCKET && h->cmsg_type==SCM_RIGHTS);
memcpy(&fd, CMSG_DATA(h), sizeof(fd));
close(conn[0]); close(conn[1]);
return fd;
}
static int transmit_fd(void) {
int p[2]; assert(pipe(p) == 0); close(p[1]); return tx(p[0]);
}
static void closed(int fd) {
assert(fcntl(fd, F_GETFD) == -1 && errno == EBADF);
}
int main(void) {
struct wl_client client={1}, unrelated={2};
struct surface s={0};
struct wl_resource manager={.owner=&client}, surf={.owner=&client,.data=&s,.type=1};
struct wl_resource buf={.owner=&client,.type=2}, other={.owner=&client,.type=2};
struct wl_resource wrong_owner={.owner=&unrelated,.type=2}, not_dmabuf={.owner=&client,.type=3};
int fd=transmit_fd();
frame_acquire_set(&client,&manager,&surf,&buf,fd);
assert(manager.error == 1 && !query_count); closed(fd);
surface_attach(&client,&surf,&buf,0,0);
struct wl_resource *bad[] = {&other, &wrong_owner, &not_dmabuf, NULL};
for (unsigned i=0; i<sizeof(bad)/sizeof(*bad); i++) {
fd=transmit_fd(); manager.error=0;
frame_acquire_set(&client,&manager,&surf,bad[i],fd);
assert(manager.error == 1 && !query_count); closed(fd);
}
manager.error=0; query_status=1; fd=transmit_fd();
frame_acquire_set(&client,&manager,&surf,&buf,fd);
assert(!manager.error && query_count==1 && s.pending_frame_acquire.fd_plus_one==fd+1);
int display_fd=dd_frame_acquire_dup(&s.pending_frame_acquire);
assert(display_fd>=0 && display_fd!=fd && (fcntl(display_fd,F_GETFD)&FD_CLOEXEC));
close(display_fd);
int duplicate=transmit_fd();
frame_acquire_set(&client,&manager,&surf,&buf,duplicate);
assert(manager.error==2 && query_count==1); closed(duplicate);
/* The same Wayland buffer, attached a second time, is a different write. */
surface_attach(&client,&surf,&buf,0,0);
assert(dd_frame_acquire_dup(&s.pending_frame_acquire)==-1); closed(fd);
for (int status=0; status>=-2; status--) {
manager.error=0; query_status=status;
if (status==-2) query_result=-1; /* non-sync file ioctl failure */
fd=transmit_fd();
frame_acquire_set(&client,&manager,&surf,&buf,fd);
assert(manager.error == 3 && !s.pending_frame_acquire.fd_plus_one); closed(fd);
}
manager.error=0; query_result=0; query_status=1;
fd=transmit_fd();
frame_acquire_set(&client,&manager,&surf,&buf,fd);
assert(!manager.error);
on_pending_buffer_destroyed(&s.pending_buffer_destroy,NULL);
assert(!s.pending_buffer && !s.pending_frame_acquire.fd_plus_one); closed(fd);
peer_allowed=0; manager.error=0;
surface_attach(&client,&surf,&buf,0,0);
fd=transmit_fd();
frame_acquire_set(&client,&manager,&surf,&buf,fd);
assert(manager.error==4&&!s.pending_frame_acquire.fd_plus_one);closed(fd);
return 0;
}
'''
@unittest.skipUnless(platform.system() == 'Linux', 'Linux sync_file UAPI')
class FrameAcquireProtocolTest(unittest.TestCase):
def test_production_receiver_rejects_invalid_and_keeps_exact_attachment(self):
comp = (SRC / 'compositor.c').read_text()
protocol = (SRC.parent / 'generated/droiddeck-frame-acquire-v1-server-protocol.h').read_text()
errors = protocol.split('enum droiddeck_frame_acquire_v1_error {', 1)[1].split('};', 1)[0]
actual = '\n'.join(function(comp, name) for name in (
'on_pending_buffer_destroyed', 'surface_attach', 'frame_acquire_set'))
with tempfile.TemporaryDirectory(prefix='droiddeck-frame-acquire-') as tmp:
probe = Path(tmp) / 'probe.c'
exe = Path(tmp) / 'probe'
probe.write_text(HEAD + '\nenum droiddeck_frame_acquire_v1_error {' + errors + '};\n' + actual + TAIL)
subprocess.run([os.environ.get('CC', 'cc'), '-std=gnu11', '-Wall', '-Wextra',
'-Werror', '-Wno-unused-parameter', '-UNDEBUG', '-fsanitize=address,undefined',
'-I', str(SRC), '-I', str(SRC.parent / 'prebuilt/include'),
str(probe), '-o', str(exe)], check=True)
subprocess.run([str(exe)], check=True, timeout=10)
+28 -4
View File
@@ -38,6 +38,7 @@ static unsigned g_stat_zero_copy;
static int g_export_failed_logged;
static struct surface *g_announced;
static volatile int64_t g_last_zero_copy_ns;
static int explicit_proof;
static int export_ok, exports, presents, presented_acquire, logs, polls;
static int fake_ioctl(int fd, unsigned long req, void *arg) {
struct droiddeck_dma_buf_sync_file *f = arg;
@@ -57,6 +58,13 @@ static int fake_poll(struct pollfd *p, nfds_t n, int timeout) {
static int64_t now_ns(void) { return 1; }
static void **droiddeck_dmabuf_ahb_slot(struct dmabuf_buffer *b) { return &b->slot; }
static int droiddeck_dmabuf_fd(struct dmabuf_buffer *b) { return b->fd; }
static int droiddeck_surface_dup_acquire(const struct surface *s, const struct dmabuf_buffer *b) {
assert(s && b);
if (explicit_proof != 1) return explicit_proof ? -2 : -1;
int fd = dup(0);
assert(fd >= 0);
return fd;
}
static const void *droiddeck_surface_color(struct surface *s) { (void)s; return NULL; }
static void droiddeck_surface_describe(struct surface *s, char *out, size_t n) { (void)s; snprintf(out, n, "game"); }
static void droiddeck_log(const char *tag, const char *fmt, ...) { (void)tag; (void)fmt; ++logs; }
@@ -79,7 +87,15 @@ static void run(int fd, int can_export, int copyable) {
b.slot = &ab;
export_ok = can_export;
int r = ahb_swapchain_present(&b, &s, 64, 64, draw);
if (fd >= 0 && can_export) {
if (explicit_proof) {
assert(exports == 0 && polls == 0);
if (explicit_proof == 1) {
assert(r == 0 && presents == 1 && presented_acquire >= 0 && ab.on_layer);
assert(fcntl(presented_acquire, F_GETFD) == -1 && errno == EBADF);
} else {
assert(r == -1 && presents == 0 && !ab.on_layer);
}
} else if (fd >= 0 && can_export) {
assert(r == 0 && presents == 1 && presented_acquire >= 0 && ab.on_layer && g_stat_zero_copy == 1 && polls == 0);
} else if (copyable) {
assert(r == -1 && presents == 0 && !ab.on_layer && g_stat_zero_copy == 0 && polls == (fd >= 0));
@@ -90,7 +106,8 @@ static void run(int fd, int can_export, int copyable) {
}
}
int main(int argc, char **argv) {
assert(argc == 4);
assert(argc == 5);
explicit_proof = atoi(argv[4]);
run(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
return 0;
}
@@ -121,11 +138,18 @@ class ZeroCopyAcquireFenceTest(unittest.TestCase):
if built.returncode:
raise AssertionError(built.stdout + built.stderr)
def scenario(self, fd, can_export, copyable=1):
result = subprocess.run([str(self.binary), str(fd), str(can_export), str(copyable)], capture_output=True, text=True,
def scenario(self, fd, can_export, copyable=1, explicit_proof=0):
result = subprocess.run([str(self.binary), str(fd), str(can_export), str(copyable), str(explicit_proof)], capture_output=True, text=True,
timeout=10)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
def test_explicit_fence_goes_to_display_without_dmabuf_ioctl(self):
self.scenario(5, 0, explicit_proof=1)
def test_failed_explicit_dup_never_falls_through_to_legacy(self):
self.scenario(5, 1, explicit_proof=2)
self.scenario(5, 0, copyable=0, explicit_proof=2)
def test_exported_fence_goes_to_the_display(self):
self.scenario(5, 1)
+2
View File
@@ -26,6 +26,8 @@ struct dmabuf_buffer {
void *ahb_state;
};
enum surface_role { ROLE_NONE, ROLE_TOPLEVEL, ROLE_SUBSURFACE };
/* These release fixtures exercise legacy attachments, which own no acquire FD. */
#define dd_frame_acquire_clear(slot) ((void)0)
struct surface {
enum surface_role role;
struct surface *parent;