mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +00:00
fix(quest): keep timestamp read failures for unknown contexts
Answer a failed read only for a context created on the same file descriptor, so an invalid context or a closed descriptor stays an error instead of reading as timestamp zero.
This commit is contained in:
1 parent
9fce12730c
commit
bf0ee99b6d
2 files changed
+35
-5
No files matched your search
@@ -12,6 +12,7 @@
|
||||
static struct {
|
||||
uint32_t submitted;
|
||||
uint32_t retired;
|
||||
int owner;
|
||||
} contexts[KGSL_CONTEXTS];
|
||||
|
||||
static void report_denied(unsigned long request, int error) {
|
||||
@@ -34,7 +35,9 @@ static int read_retired(int (*real)(int, unsigned long, void *), int fd,
|
||||
uint32_t id = read->context_id;
|
||||
uint32_t timestamp, submitted;
|
||||
|
||||
if (read->type != KGSL_TIMESTAMP_RETIRED || id >= KGSL_CONTEXTS) return -1;
|
||||
if (read->type != KGSL_TIMESTAMP_RETIRED || id >= KGSL_CONTEXTS ||
|
||||
__atomic_load_n(&contexts[id].owner, __ATOMIC_RELAXED) != fd + 1)
|
||||
return -1;
|
||||
timestamp = __atomic_load_n(&contexts[id].retired, __ATOMIC_RELAXED);
|
||||
submitted = __atomic_load_n(&contexts[id].submitted, __ATOMIC_RELAXED);
|
||||
while (timestamp != submitted) {
|
||||
@@ -72,14 +75,19 @@ __attribute__((visibility("hidden"))) void bl_kgsl_track(int (*real)(int, unsign
|
||||
if (create->drawctxt_id < KGSL_CONTEXTS) {
|
||||
note_submit(create->drawctxt_id, 0);
|
||||
__atomic_store_n(&contexts[create->drawctxt_id].retired, 0, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&contexts[create->drawctxt_id].owner, fd + 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
} else if (request == IOCTL_KGSL_DRAWCTXT_DESTROY) {
|
||||
const struct kgsl_drawctxt_destroy *destroy = arg;
|
||||
if (destroy->drawctxt_id < KGSL_CONTEXTS)
|
||||
__atomic_store_n(&contexts[destroy->drawctxt_id].owner, 0, __ATOMIC_RELAXED);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (_IOC_TYPE(request) == KGSL_IOC_TYPE && (saved == EACCES || saved == EPERM ||
|
||||
request == IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID))
|
||||
report_denied(request, saved);
|
||||
if (request != IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID) return;
|
||||
if (request != IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID || saved == EBADF) return;
|
||||
if (read_retired(real, fd, arg) == 0)
|
||||
*rc = 0;
|
||||
else if (errno != saved)
|
||||
|
||||
@@ -11,7 +11,7 @@ static int read_error, wait_error, waits;
|
||||
static unsigned int retired;
|
||||
|
||||
static int mock(int fd, unsigned long request, void *arg) {
|
||||
assert(fd == 42);
|
||||
assert(fd == 42 || fd == 43);
|
||||
if (request == IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID) {
|
||||
if (read_error) {
|
||||
errno = read_error;
|
||||
@@ -56,6 +56,12 @@ static int read_timestamp(unsigned int context, unsigned int *timestamp) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void create_context(unsigned int context) {
|
||||
struct kgsl_drawctxt_create create = {.drawctxt_id = context};
|
||||
int rc = 0;
|
||||
bl_kgsl_track(mock, 42, IOCTL_KGSL_DRAWCTXT_CREATE, &create, &rc);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
unsigned int timestamp;
|
||||
|
||||
@@ -64,8 +70,21 @@ int main(void) {
|
||||
|
||||
read_error = EACCES;
|
||||
retired = 0;
|
||||
errno = EACCES;
|
||||
assert(read_timestamp(3, ×tamp) == -1 && errno == EACCES && waits == 0);
|
||||
|
||||
create_context(3);
|
||||
assert(read_timestamp(3, ×tamp) == 0 && timestamp == 0 && waits == 0);
|
||||
|
||||
read_error = EBADF;
|
||||
assert(read_timestamp(3, ×tamp) == -1 && errno == EBADF && waits == 0);
|
||||
read_error = EACCES;
|
||||
|
||||
struct kgsl_cmdstream_readtimestamp_ctxtid other = {.context_id = 3, .type = KGSL_TIMESTAMP_RETIRED};
|
||||
int other_rc = mock(43, IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, &other);
|
||||
bl_kgsl_track(mock, 43, IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, &other, &other_rc);
|
||||
assert(other_rc == -1 && errno == EACCES && waits == 0);
|
||||
|
||||
submit(1);
|
||||
submit(2);
|
||||
submit(3);
|
||||
@@ -97,12 +116,15 @@ int main(void) {
|
||||
retired = 6;
|
||||
assert(read_timestamp(3, ×tamp) == 0 && timestamp == 6);
|
||||
|
||||
struct kgsl_drawctxt_create create = {.drawctxt_id = 3};
|
||||
bl_kgsl_track(mock, 42, IOCTL_KGSL_DRAWCTXT_CREATE, &create, &rc);
|
||||
create_context(3);
|
||||
retired = 0;
|
||||
waits = 0;
|
||||
assert(read_timestamp(3, ×tamp) == 0 && timestamp == 0 && waits == 0);
|
||||
|
||||
struct kgsl_drawctxt_destroy destroy = {.drawctxt_id = 3};
|
||||
bl_kgsl_track(mock, 42, IOCTL_KGSL_DRAWCTXT_DESTROY, &destroy, &rc);
|
||||
assert(read_timestamp(3, ×tamp) == -1 && errno == EACCES);
|
||||
|
||||
errno = EACCES;
|
||||
assert(read_timestamp(5000, ×tamp) == -1 && errno == EACCES);
|
||||
|
||||
|
||||
Reference in new issue
Block a user