MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / GetStatusFileDescriptor

Function GetStatusFileDescriptor

tests/gtest/gtest-all.cc:9118–9177  ·  view source on GitHub ↗

Recreates the pipe and event handles from the provided parameters, signals the event, and returns a file descriptor wrapped around the pipe handle. This function is called in the child process only.

Source from the content-addressed store, hash-verified

9116// signals the event, and returns a file descriptor wrapped around the pipe
9117// handle. This function is called in the child process only.
9118static int GetStatusFileDescriptor(unsigned int parent_process_id,
9119 size_t write_handle_as_size_t,
9120 size_t event_handle_as_size_t) {
9121 AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE,
9122 FALSE, // Non-inheritable.
9123 parent_process_id));
9124 if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {
9125 DeathTestAbort("Unable to open parent process " +
9126 StreamableToString(parent_process_id));
9127 }
9128
9129 GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t));
9130
9131 const HANDLE write_handle =
9132 reinterpret_cast<HANDLE>(write_handle_as_size_t);
9133 HANDLE dup_write_handle;
9134
9135 // The newly initialized handle is accessible only in the parent
9136 // process. To obtain one accessible within the child, we need to use
9137 // DuplicateHandle.
9138 if (!::DuplicateHandle(parent_process_handle.Get(), write_handle,
9139 ::GetCurrentProcess(), &dup_write_handle,
9140 0x0, // Requested privileges ignored since
9141 // DUPLICATE_SAME_ACCESS is used.
9142 FALSE, // Request non-inheritable handler.
9143 DUPLICATE_SAME_ACCESS)) {
9144 DeathTestAbort("Unable to duplicate the pipe handle " +
9145 StreamableToString(write_handle_as_size_t) +
9146 " from the parent process " +
9147 StreamableToString(parent_process_id));
9148 }
9149
9150 const HANDLE event_handle = reinterpret_cast<HANDLE>(event_handle_as_size_t);
9151 HANDLE dup_event_handle;
9152
9153 if (!::DuplicateHandle(parent_process_handle.Get(), event_handle,
9154 ::GetCurrentProcess(), &dup_event_handle,
9155 0x0,
9156 FALSE,
9157 DUPLICATE_SAME_ACCESS)) {
9158 DeathTestAbort("Unable to duplicate the event handle " +
9159 StreamableToString(event_handle_as_size_t) +
9160 " from the parent process " +
9161 StreamableToString(parent_process_id));
9162 }
9163
9164 const int write_fd =
9165 ::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);
9166 if (write_fd == -1) {
9167 DeathTestAbort("Unable to convert pipe handle " +
9168 StreamableToString(write_handle_as_size_t) +
9169 " to a file descriptor");
9170 }
9171
9172 // Signals the parent that the write end of the pipe has been acquired
9173 // so the parent can release its own write end.
9174 ::SetEvent(dup_event_handle);
9175

Callers 1

Calls 3

DeathTestAbortFunction · 0.85
StreamableToStringFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected