Index: mojo/android/system/core_impl.cc |
diff --git a/mojo/android/system/core_impl.cc b/mojo/android/system/core_impl.cc |
index b8621300a4b37ac3649cd248fa58215edfbec9eb..35d1b3682cac2aa723d3503e9ff69016758e2829 100644 |
--- a/mojo/android/system/core_impl.cc |
+++ b/mojo/android/system/core_impl.cc |
@@ -57,19 +57,35 @@ static jint WaitMany(JNIEnv* env, |
jobject jcaller, |
jobject buffer, |
jlong deadline) { |
- // Buffer contains first the list of handles, then the list of signals. |
- const void* buffer_start = env->GetDirectBufferAddress(buffer); |
+ // |buffer| contains, in this order |
+ // input: The array of N handles (MojoHandle, 4 bytes each) |
+ // input: The array of N signals (MojoHandleSignals, 4 bytes each) |
+ // space for output: The array of N handle states (MojoHandleSignalsState, 8 |
+ // bytes each) |
+ // space for output: The result index (uint32_t, 4 bytes) |
+ uint8_t* buffer_start = |
+ static_cast<uint8_t*>(env->GetDirectBufferAddress(buffer)); |
DCHECK(buffer_start); |
- DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); |
- const size_t record_size = 8; |
+ DCHECK_EQ(reinterpret_cast<uintptr_t>(buffer_start) % 8, 0u); |
+ // Each handle of the input array contributes 4 (MojoHandle) + 4 |
+ // (MojoHandleSignals) + 8 (MojoHandleSignalsState) = 16 bytes to the size of |
+ // the buffer. |
+ const size_t size_per_handle = 16; |
const size_t buffer_size = env->GetDirectBufferCapacity(buffer); |
- DCHECK_EQ(buffer_size % record_size, 0u); |
+ DCHECK_EQ((buffer_size - 4) % size_per_handle, 0u); |
- const size_t nb_handles = buffer_size / record_size; |
- const MojoHandle* handle_start = static_cast<const MojoHandle*>(buffer_start); |
+ const size_t nb_handles = (buffer_size - 4) / size_per_handle; |
+ const MojoHandle* handle_start = |
+ reinterpret_cast<const MojoHandle*>(buffer_start); |
const MojoHandleSignals* signals_start = |
- static_cast<const MojoHandleSignals*>(handle_start + nb_handles); |
- return MojoWaitMany(handle_start, signals_start, nb_handles, deadline); |
+ reinterpret_cast<const MojoHandleSignals*>(buffer_start + 4 * nb_handles); |
+ MojoHandleSignalsState* states_start = |
+ reinterpret_cast<MojoHandleSignalsState*>(buffer_start + 8 * nb_handles); |
+ uint32_t* result_index = |
+ reinterpret_cast<uint32_t*>(buffer_start + 16 * nb_handles); |
+ *result_index = static_cast<uint32_t>(-1); |
+ return MojoNewWaitMany(handle_start, signals_start, nb_handles, deadline, |
+ result_index, states_start); |
} |
static jobject CreateMessagePipe(JNIEnv* env, |
@@ -138,10 +154,19 @@ static jint Close(JNIEnv* env, jobject jcaller, jint mojo_handle) { |
static jint Wait(JNIEnv* env, |
jobject jcaller, |
+ jobject buffer, |
jint mojo_handle, |
jint signals, |
jlong deadline) { |
- return MojoWait(mojo_handle, signals, deadline); |
+ // Buffer contains space for the MojoHandleSignalsState |
+ void* buffer_start = env->GetDirectBufferAddress(buffer); |
+ DCHECK(buffer_start); |
+ DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); |
+ DCHECK_EQ(sizeof(struct MojoHandleSignalsState), |
+ static_cast<size_t>(env->GetDirectBufferCapacity(buffer))); |
+ struct MojoHandleSignalsState* signals_state = |
+ static_cast<struct MojoHandleSignalsState*>(buffer_start); |
+ return MojoNewWait(mojo_handle, signals, deadline, signals_state); |
} |
static jint WriteMessage(JNIEnv* env, |