| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/android/system/core_impl.h" | 5 #include "mojo/android/system/core_impl.h" |
| 6 | 6 |
| 7 #include "base/android/base_jni_registrar.h" | 7 #include "base/android/base_jni_registrar.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_registrar.h" | 9 #include "base/android/jni_registrar.h" |
| 10 #include "base/android/library_loader/library_loader_hooks.h" | 10 #include "base/android/library_loader/library_loader_hooks.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 namespace android { | 50 namespace android { |
| 51 | 51 |
| 52 static jlong GetTimeTicksNow(JNIEnv* env, jobject jcaller) { | 52 static jlong GetTimeTicksNow(JNIEnv* env, jobject jcaller) { |
| 53 return MojoGetTimeTicksNow(); | 53 return MojoGetTimeTicksNow(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 static jint WaitMany(JNIEnv* env, | 56 static jint WaitMany(JNIEnv* env, |
| 57 jobject jcaller, | 57 jobject jcaller, |
| 58 jobject buffer, | 58 jobject buffer, |
| 59 jlong deadline) { | 59 jlong deadline) { |
| 60 // Buffer contains first the list of handles, then the list of signals. | 60 // |buffer| contains, in this order |
| 61 const void* buffer_start = env->GetDirectBufferAddress(buffer); | 61 // input: The array of N handles (MojoHandle, 4 bytes each) |
| 62 // input: The array of N signals (MojoHandleSignals, 4 bytes each) |
| 63 // space for output: The array of N handle states (MojoHandleSignalsState, 8 |
| 64 // bytes each) |
| 65 // space for output: The result index (uint32_t, 4 bytes) |
| 66 uint8_t* buffer_start = |
| 67 static_cast<uint8_t*>(env->GetDirectBufferAddress(buffer)); |
| 62 DCHECK(buffer_start); | 68 DCHECK(buffer_start); |
| 63 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); | 69 DCHECK_EQ(reinterpret_cast<uintptr_t>(buffer_start) % 8, 0u); |
| 64 const size_t record_size = 8; | 70 // Each handle of the input array contributes 4 (MojoHandle) + 4 |
| 71 // (MojoHandleSignals) + 8 (MojoHandleSignalsState) = 16 bytes to the size of |
| 72 // the buffer. |
| 73 const size_t size_per_handle = 16; |
| 65 const size_t buffer_size = env->GetDirectBufferCapacity(buffer); | 74 const size_t buffer_size = env->GetDirectBufferCapacity(buffer); |
| 66 DCHECK_EQ(buffer_size % record_size, 0u); | 75 DCHECK_EQ((buffer_size - 4) % size_per_handle, 0u); |
| 67 | 76 |
| 68 const size_t nb_handles = buffer_size / record_size; | 77 const size_t nb_handles = (buffer_size - 4) / size_per_handle; |
| 69 const MojoHandle* handle_start = static_cast<const MojoHandle*>(buffer_start); | 78 const MojoHandle* handle_start = |
| 79 reinterpret_cast<const MojoHandle*>(buffer_start); |
| 70 const MojoHandleSignals* signals_start = | 80 const MojoHandleSignals* signals_start = |
| 71 static_cast<const MojoHandleSignals*>(handle_start + nb_handles); | 81 reinterpret_cast<const MojoHandleSignals*>(buffer_start + 4 * nb_handles); |
| 72 return MojoWaitMany(handle_start, signals_start, nb_handles, deadline); | 82 MojoHandleSignalsState* states_start = |
| 83 reinterpret_cast<MojoHandleSignalsState*>(buffer_start + 8 * nb_handles); |
| 84 uint32_t* result_index = |
| 85 reinterpret_cast<uint32_t*>(buffer_start + 16 * nb_handles); |
| 86 *result_index = static_cast<uint32_t>(-1); |
| 87 return MojoNewWaitMany(handle_start, signals_start, nb_handles, deadline, |
| 88 result_index, states_start); |
| 73 } | 89 } |
| 74 | 90 |
| 75 static jobject CreateMessagePipe(JNIEnv* env, | 91 static jobject CreateMessagePipe(JNIEnv* env, |
| 76 jobject jcaller, | 92 jobject jcaller, |
| 77 jobject options_buffer) { | 93 jobject options_buffer) { |
| 78 const MojoCreateMessagePipeOptions* options = NULL; | 94 const MojoCreateMessagePipeOptions* options = NULL; |
| 79 if (options_buffer) { | 95 if (options_buffer) { |
| 80 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); | 96 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); |
| 81 DCHECK(buffer_start); | 97 DCHECK(buffer_start); |
| 82 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); | 98 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return Java_CoreImpl_newNativeCreationResult(env, result, handle, 0) | 147 return Java_CoreImpl_newNativeCreationResult(env, result, handle, 0) |
| 132 .Release(); | 148 .Release(); |
| 133 } | 149 } |
| 134 | 150 |
| 135 static jint Close(JNIEnv* env, jobject jcaller, jint mojo_handle) { | 151 static jint Close(JNIEnv* env, jobject jcaller, jint mojo_handle) { |
| 136 return MojoClose(mojo_handle); | 152 return MojoClose(mojo_handle); |
| 137 } | 153 } |
| 138 | 154 |
| 139 static jint Wait(JNIEnv* env, | 155 static jint Wait(JNIEnv* env, |
| 140 jobject jcaller, | 156 jobject jcaller, |
| 157 jobject buffer, |
| 141 jint mojo_handle, | 158 jint mojo_handle, |
| 142 jint signals, | 159 jint signals, |
| 143 jlong deadline) { | 160 jlong deadline) { |
| 144 return MojoWait(mojo_handle, signals, deadline); | 161 // Buffer contains space for the MojoHandleSignalsState |
| 162 void* buffer_start = env->GetDirectBufferAddress(buffer); |
| 163 DCHECK(buffer_start); |
| 164 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); |
| 165 DCHECK_EQ(sizeof(struct MojoHandleSignalsState), |
| 166 env->GetDirectBufferCapacity(buffer)); |
| 167 struct MojoHandleSignalsState* signals_state = |
| 168 static_cast<struct MojoHandleSignalsState*>(buffer_start); |
| 169 return MojoNewWait(mojo_handle, signals, deadline, signals_state); |
| 145 } | 170 } |
| 146 | 171 |
| 147 static jint WriteMessage(JNIEnv* env, | 172 static jint WriteMessage(JNIEnv* env, |
| 148 jobject jcaller, | 173 jobject jcaller, |
| 149 jint mojo_handle, | 174 jint mojo_handle, |
| 150 jobject bytes, | 175 jobject bytes, |
| 151 jint num_bytes, | 176 jint num_bytes, |
| 152 jobject handles_buffer, | 177 jobject handles_buffer, |
| 153 jint flags) { | 178 jint flags) { |
| 154 const void* buffer_start = 0; | 179 const void* buffer_start = 0; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr)); | 394 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr)); |
| 370 Environment::GetDefaultAsyncWaiter()->CancelWait(id); | 395 Environment::GetDefaultAsyncWaiter()->CancelWait(id); |
| 371 } | 396 } |
| 372 | 397 |
| 373 bool RegisterCoreImpl(JNIEnv* env) { | 398 bool RegisterCoreImpl(JNIEnv* env) { |
| 374 return RegisterNativesImpl(env); | 399 return RegisterNativesImpl(env); |
| 375 } | 400 } |
| 376 | 401 |
| 377 } // namespace android | 402 } // namespace android |
| 378 } // namespace mojo | 403 } // namespace mojo |
| OLD | NEW |