A shared event's port is a connection of a new user-client type, 'RGSE' (0x52475345), on the accelerator. The kext can give a process no port of an object of its own: copyPortNameForObjectInTask is in com.apple.kpi.private alone (the macOS 26.7.1 KDK's symbol sets), which check-imports refuses. Its Export (0x113) posts SHARED_EVENT_NAME and answers once the host took the name; its Import (0x114), by any task that holds the port, posts SHARED_EVENT_IMPORT. The port is the capability. A call on it proves the caller holds it, and the kext posts only through the client of the calling task that holds the context the call names (rgfxPortCallerHolds), with that client's asks, which its close waits for. Submit refuses the three messages, so no process names or makes an event in another's context, or imports one it was not handed. The accelerator's client answers IOConnectAddClient of a port: success only for a shared event's port of its accelerator. The kernel looks the port up in the caller's space and sends it nothing, so the bundle asks it before it calls on a port it was handed: an IOKit call on a port that is no kernel object kills the caller (measured on the 5300M and the 630, oracle_events connect), where Metal answers nil. The port holds the name until IOKit frees the connection, once no task holds a send right of it, and its free posts SHARED_EVENT_UNNAME. Its close, and IOKit's word that its creator died, only detach it from the accelerator, so a port another process holds outlives an exporter killed with SIGKILL. The kext takes SHARED_EVENT_NAMES where offered and sets kext feature 1 << 6.
144 lines
8.3 KiB
C++
144 lines
8.3 KiB
C++
// The native test of RgfxSubmitGate.hpp: submitMethod accepts only the object-lifecycle types
|
|
// strictly between QUEUE_CREATE and CONTEXT_CLOSE, and of those only OBJECT_DESTROY (a queue's)
|
|
// must be routed through the queue-destroy path rather than posted to the device raw.
|
|
#include "RgfxSubmitGate.hpp"
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
|
|
namespace {
|
|
int checks = 0;
|
|
|
|
void check(bool ok, const char *what)
|
|
{
|
|
checks++;
|
|
if (!ok) {
|
|
std::fprintf(stderr, "submit_gate_test: FAILED: %s\n", what);
|
|
std::exit(1);
|
|
}
|
|
}
|
|
} // namespace
|
|
|
|
int main()
|
|
{
|
|
// The boundaries: QUEUE_CREATE is made through its own selector, CONTEXT_CLOSE and the
|
|
// block messages above it are the kext's; neither end is accepted through submit.
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_QUEUE_CREATE), "QUEUE_CREATE is not a submit message");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_CONTEXT_CLOSE), "CONTEXT_CLOSE is the kext's");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_RESOURCE_ID_CHUNK), "RESOURCE_ID_CHUNK is the kext's");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_RESOURCE_ID_SMALL_CHUNK),
|
|
"RESOURCE_ID_SMALL_CHUNK is the kext's");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_BLOCK_RELEASE), "BLOCK_RELEASE is the kext's");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_BLOCK_GRANT), "BLOCK_GRANT is the kext's");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_GET_DISPLAYS), "a display command is not a submit message");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_PRESENT_SURFACE), "PRESENT_SURFACE is not one");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_COMMAND_BUFFER), "a command buffer rides a queue's ring");
|
|
// A shared event's name, import and unname are the kext's, built from a port the caller
|
|
// holds: a process that posted one could make an event of another process's without its port.
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_SHARED_EVENT_NAME), "SHARED_EVENT_NAME is the kext's");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_SHARED_EVENT_IMPORT), "SHARED_EVENT_IMPORT is the kext's");
|
|
check(!rgfxSubmitAdmitted(RGFX_CMD_SHARED_EVENT_UNNAME), "SHARED_EVENT_UNNAME is the kext's");
|
|
check(rgfxSubmitAdmitted(RGFX_CMD_SHARED_EVENT_SET_VALUE), "a shared event's set is a process's");
|
|
|
|
// The accepted range: every type strictly between QUEUE_CREATE and CONTEXT_CLOSE.
|
|
check(rgfxSubmitAdmitted(RGFX_CMD_OBJECT_DESTROY), "OBJECT_DESTROY is accepted");
|
|
check(rgfxSubmitAdmitted(RGFX_CMD_BUFFER_OVER_HOST_MEMORY), "a buffer over host memory is");
|
|
check(rgfxSubmitAdmitted(RGFX_CMD_RENDER_PIPELINE_CREATE), "a pipeline create is");
|
|
check(rgfxSubmitAdmitted(RGFX_CMD_VIDEO_SESSION_CREATE), "the last accepted type is");
|
|
|
|
// Only OBJECT_DESTROY, with a tracked queue's id, routes through the queue-destroy path.
|
|
// Every other accepted type names an object only the host tracks and is posted as it is.
|
|
check(rgfxSubmitRoutesQueueDestroy(RGFX_CMD_OBJECT_DESTROY),
|
|
"OBJECT_DESTROY of a tracked queue routes");
|
|
for (uint32_t type = RGFX_CMD_QUEUE_CREATE; type <= RGFX_CMD_CONTEXT_CLOSE; type++) {
|
|
if (type == RGFX_CMD_OBJECT_DESTROY)
|
|
continue;
|
|
check(!rgfxSubmitRoutesQueueDestroy(type),
|
|
"no other type in the range routes as a queue destroy");
|
|
}
|
|
// A type the gate rejects never reaches the routing question, but is not a queue destroy.
|
|
check(!rgfxSubmitRoutesQueueDestroy(RGFX_CMD_QUEUE_CREATE), "QUEUE_CREATE does not route");
|
|
check(!rgfxSubmitRoutesQueueDestroy(RGFX_CMD_BLOCK_RELEASE), "BLOCK_RELEASE does not route");
|
|
|
|
// Which accepted types make an object a destroy then drops: every type of the accepted
|
|
// range is decided here, so a new wire type has to be placed.
|
|
const uint32_t makes[] = {
|
|
RGFX_CMD_HEAP_CREATE, RGFX_CMD_HEAP_OVER_HOST_MEMORY, RGFX_CMD_BUFFER_CREATE,
|
|
RGFX_CMD_BUFFER_OVER_HOST_MEMORY, RGFX_CMD_BUFFER_AT_OFFSET, RGFX_CMD_TEXTURE_CREATE,
|
|
RGFX_CMD_TEXTURE_FROM_BUFFER, RGFX_CMD_TEXTURE_FROM_IOSURFACE, RGFX_CMD_SAMPLER_CREATE,
|
|
RGFX_CMD_DEPTH_STENCIL_CREATE, RGFX_CMD_LIBRARY_CREATE, RGFX_CMD_RENDER_PIPELINE_CREATE,
|
|
RGFX_CMD_COMPUTE_PIPELINE_CREATE, RGFX_CMD_EVENT_CREATE, RGFX_CMD_SHARED_EVENT_CREATE,
|
|
RGFX_CMD_FENCE_CREATE, RGFX_CMD_LIBRARY_FROM_REGION, RGFX_CMD_LIBRARY_LOOKUP,
|
|
RGFX_CMD_MANAGED_TEXTURE_CREATE, RGFX_CMD_TEXTURE_VIEW, RGFX_CMD_LINEAR_TEXTURE_FROM_BUFFER,
|
|
RGFX_CMD_BUFFER_OVER_SURFACE_PAGES, RGFX_CMD_VIDEO_SESSION_CREATE,
|
|
RGFX_CMD_BUFFER_OVER_PAGES, RGFX_CMD_ICB_CREATE, RGFX_CMD_BUFFER_MANAGED_AT_OFFSET,
|
|
RGFX_CMD_HEAP_OVER_PAGES, RGFX_CMD_MANAGED_BUFFER_CREATE,
|
|
RGFX_CMD_MESH_RENDER_PIPELINE_CREATE,
|
|
};
|
|
const uint32_t makesNone[] = {
|
|
RGFX_CMD_OBJECT_DESTROY, RGFX_CMD_BUFFER_DID_MODIFY_RANGE, RGFX_CMD_TEXTURE_REPLACE_REGION,
|
|
RGFX_CMD_HEAP_TEXTURE_SIZE_AND_ALIGN, RGFX_CMD_ARGUMENT_LAYOUT,
|
|
RGFX_CMD_SHARED_EVENT_SET_VALUE, RGFX_CMD_ICB_WRITE,
|
|
};
|
|
for (uint32_t t : makes)
|
|
check(rgfxSubmitAdmitted(t) && rgfxSubmitMakes(t), "a create makes an object");
|
|
for (uint32_t t : makesNone)
|
|
check(rgfxSubmitAdmitted(t) && !rgfxSubmitMakes(t),
|
|
"a destroy, a query or a write into an object makes none");
|
|
for (uint32_t type = RGFX_CMD_QUEUE_CREATE + 1; type < RGFX_CMD_CONTEXT_CLOSE; type++) {
|
|
bool listed = false;
|
|
for (uint32_t t : makes)
|
|
listed |= t == type;
|
|
for (uint32_t t : makesNone)
|
|
listed |= t == type;
|
|
if (type <= RGFX_CMD_BUFFER_OVER_PAGES || type == RGFX_CMD_BUFFER_MANAGED_AT_OFFSET ||
|
|
type == RGFX_CMD_HEAP_OVER_PAGES || type == RGFX_CMD_MANAGED_BUFFER_CREATE ||
|
|
type == RGFX_CMD_MESH_RENDER_PIPELINE_CREATE)
|
|
check(listed, "every wire type of the accepted range is placed");
|
|
else if (!listed)
|
|
check(!rgfxSubmitMakes(type), "a type the wire does not name makes none");
|
|
}
|
|
|
|
// The pipeline creates, which the device answers with a PIPELINE_REFLECTION and a client may
|
|
// post deferred: the render, mesh render and compute pipelines', and no other type.
|
|
for (uint32_t type = RGFX_CMD_QUEUE_CREATE + 1; type < RGFX_CMD_CONTEXT_CLOSE; type++)
|
|
check(rgfxSubmitIsPipelineCreate(type) == (type == RGFX_CMD_RENDER_PIPELINE_CREATE ||
|
|
type == RGFX_CMD_MESH_RENDER_PIPELINE_CREATE ||
|
|
type == RGFX_CMD_COMPUTE_PIPELINE_CREATE),
|
|
"the render, mesh render and compute pipeline creates are the pipeline creates");
|
|
check(rgfxSubmitAdmitted(RGFX_CMD_MESH_RENDER_PIPELINE_CREATE), "a mesh pipeline create is accepted");
|
|
|
|
// A destroy follows a create only where it was posted and made something, and either timed
|
|
// out or its context closed since the submit's check.
|
|
check(rgfxSubmitDestroysBehind(RGFX_CMD_TEXTURE_CREATE, true, false, true),
|
|
"a span-less create posted across its context's close is destroyed behind");
|
|
check(rgfxSubmitDestroysBehind(RGFX_CMD_RENDER_PIPELINE_CREATE, true, false, true),
|
|
"a pipeline create across the close too");
|
|
check(rgfxSubmitDestroysBehind(RGFX_CMD_SAMPLER_CREATE, true, true, false),
|
|
"a create not answered in time is destroyed behind");
|
|
check(!rgfxSubmitDestroysBehind(RGFX_CMD_TEXTURE_CREATE, true, false, false),
|
|
"an answered create of an open context is kept");
|
|
check(!rgfxSubmitDestroysBehind(RGFX_CMD_TEXTURE_CREATE, false, false, true),
|
|
"nothing follows a message never posted");
|
|
check(!rgfxSubmitDestroysBehind(RGFX_CMD_ARGUMENT_LAYOUT, true, true, true),
|
|
"a query makes nothing, so nothing follows it");
|
|
check(!rgfxSubmitDestroysBehind(RGFX_CMD_OBJECT_DESTROY, true, false, true),
|
|
"a destroy is not destroyed behind");
|
|
check(!rgfxSubmitDestroysBehind(RGFX_CMD_SHARED_EVENT_SET_VALUE, true, false, true),
|
|
"nor a write into an object");
|
|
check(!rgfxSubmitDestroysBehind(RGFX_CMD_ICB_WRITE, true, true, true),
|
|
"nor an indirect command buffer's commands");
|
|
// The timeout path is as before for every type that waits for an answer.
|
|
const uint32_t answered[] = {RGFX_CMD_RENDER_PIPELINE_CREATE, RGFX_CMD_COMPUTE_PIPELINE_CREATE,
|
|
RGFX_CMD_MESH_RENDER_PIPELINE_CREATE, RGFX_CMD_SAMPLER_CREATE, RGFX_CMD_ICB_CREATE, RGFX_CMD_LIBRARY_CREATE,
|
|
RGFX_CMD_LIBRARY_LOOKUP, RGFX_CMD_LIBRARY_FROM_REGION};
|
|
for (uint32_t t : answered)
|
|
check(rgfxSubmitDestroysBehind(t, true, true, false),
|
|
"an answered create that times out is destroyed behind, as before");
|
|
check(!rgfxSubmitDestroysBehind(RGFX_CMD_HEAP_TEXTURE_SIZE_AND_ALIGN, true, true, false),
|
|
"a size query that times out is not, as before");
|
|
|
|
std::printf("submit_gate_test: OK (%d checks)\n", checks);
|
|
return 0;
|
|
}
|