Bug 1211432 - provide PodCopy and PodMove safe-when-racy operations. r=waldo

--HG--
extra : rebase_source : 1d8059acaf0e383a4e1198f8e56d6e9a55585c94
extra : amend_source : 9e8797bbeaced043bedf0e7b63b58ebdeb81ebdd
This commit is contained in:
Lars T Hansen 2015-12-03 09:08:48 +01:00
Родитель 1fb6a0d3e4
Коммит a8df8d57e6
4 изменённых файлов: 45 добавлений и 13 удалений

Просмотреть файл

@ -1269,7 +1269,7 @@ Load(JSContext* cx, unsigned argc, Value* vp)
SharedMem<Elem*> src = AnyTypedArrayViewData(typedArray).addBytes(byteStart).cast<Elem*>();
Elem* dst = reinterpret_cast<Elem*>(result->typedMem());
jit::AtomicOperations::memcpySafeWhenRacy(dst, src, sizeof(Elem) * NumElem);
jit::AtomicOperations::podCopySafeWhenRacy(SharedMem<Elem*>::unshared(dst), src, NumElem);
args.rval().setObject(*result);
return true;
@ -1295,7 +1295,7 @@ Store(JSContext* cx, unsigned argc, Value* vp)
Elem* src = TypedObjectMemory<Elem*>(args[2]);
SharedMem<Elem*> dst = AnyTypedArrayViewData(typedArray).addBytes(byteStart).cast<Elem*>();
js::jit::AtomicOperations::memcpySafeWhenRacy(dst, src, sizeof(Elem) * NumElem);
js::jit::AtomicOperations::podCopySafeWhenRacy(dst, SharedMem<Elem*>::unshared(src), NumElem);
args.rval().setObject(args[2].toObject());
return true;

Просмотреть файл

@ -225,23 +225,35 @@ class AtomicOperations
}
template<typename T>
static void memcpySafeWhenRacy(SharedMem<T> dest, SharedMem<T> src, size_t nbytes) {
memcpySafeWhenRacy(static_cast<void*>(dest.unwrap()), static_cast<void*>(src.unwrap()), nbytes);
static void memcpySafeWhenRacy(SharedMem<T*> dest, SharedMem<T*> src, size_t nbytes) {
memcpySafeWhenRacy(dest.template cast<void*>().unwrap(),
src.template cast<void*>().unwrap(), nbytes);
}
template<typename T>
static void memcpySafeWhenRacy(SharedMem<T> dest, T src, size_t nbytes) {
memcpySafeWhenRacy(static_cast<void*>(dest.unwrap()), static_cast<void*>(src), nbytes);
static void memcpySafeWhenRacy(SharedMem<T*> dest, T* src, size_t nbytes) {
memcpySafeWhenRacy(dest.template cast<void*>().unwrap(), static_cast<void*>(src), nbytes);
}
template<typename T>
static void memcpySafeWhenRacy(T dest, SharedMem<T> src, size_t nbytes) {
memcpySafeWhenRacy(static_cast<void*>(dest), static_cast<void*>(src.unwrap()), nbytes);
static void memcpySafeWhenRacy(T* dest, SharedMem<T*> src, size_t nbytes) {
memcpySafeWhenRacy(static_cast<void*>(dest), src.template cast<void*>().unwrap(), nbytes);
}
template<typename T>
static void memmoveSafeWhenRacy(SharedMem<T> dest, SharedMem<T> src, size_t nbytes) {
memmoveSafeWhenRacy(static_cast<void*>(dest.unwrap()), static_cast<void*>(src.unwrap()), nbytes);
static void memmoveSafeWhenRacy(SharedMem<T*> dest, SharedMem<T*> src, size_t nbytes) {
memmoveSafeWhenRacy(dest.template cast<void*>().unwrap(),
src.template cast<void*>().unwrap(), nbytes);
}
template<typename T>
static void podCopySafeWhenRacy(SharedMem<T*> dest, SharedMem<T*> src, size_t nelem) {
memcpySafeWhenRacy(dest, src, nelem * sizeof(T));
}
template<typename T>
static void podMoveSafeWhenRacy(SharedMem<T*> dest, SharedMem<T*> src, size_t nelem) {
memmoveSafeWhenRacy(dest, src, nelem * sizeof(T));
}
};

Просмотреть файл

@ -1091,7 +1091,7 @@ intrinsic_SetOverlappingTypedElements(JSContext* cx, unsigned argc, Value* vp)
if (!copyOfSrcData)
return false;
jit::AtomicOperations::memcpySafeWhenRacy(copyOfSrcData.get(),
jit::AtomicOperations::memcpySafeWhenRacy(SharedMem<uint8_t*>::unshared(copyOfSrcData.get()),
unsafeSrcCrossCompartment->viewDataEither().cast<uint8_t*>(),
sourceByteLen);

Просмотреть файл

@ -146,6 +146,16 @@ class SharedOps
js::jit::AtomicOperations::memmoveSafeWhenRacy(dest, src, size);
}
template<typename T>
static void podCopy(SharedMem<T*> dest, SharedMem<T*> src, size_t nelem) {
js::jit::AtomicOperations::podCopySafeWhenRacy(dest, src, nelem);
}
template<typename T>
static void podMove(SharedMem<T*> dest, SharedMem<T*> src, size_t nelem) {
js::jit::AtomicOperations::podMoveSafeWhenRacy(dest, src, nelem);
}
static SharedMem<void*> extract(TypedArrayObject* obj) {
return obj->viewDataEither();
}
@ -174,6 +184,16 @@ class UnsharedOps
::memmove(dest.unwrapUnshared(), src.unwrapUnshared(), size);
}
template<typename T>
static void podCopy(SharedMem<T*> dest, SharedMem<T*> src, size_t nelem) {
mozilla::PodCopy(dest.unwrapUnshared(), src.unwrapUnshared(), nelem);
}
template<typename T>
static void podMove(SharedMem<T*> dest, SharedMem<T*> src, size_t nelem) {
mozilla::PodMove(dest.unwrapUnshared(), src.unwrapUnshared(), nelem);
}
static SharedMem<void*> extract(TypedArrayObject* obj) {
return SharedMem<void*>::unshared(obj->viewDataUnshared());
}
@ -212,7 +232,7 @@ class ElementSpecific
uint32_t count = AnyTypedArrayLength(source);
if (AnyTypedArrayType(source) == target->type()) {
Ops::memcpy(dest.template cast<void*>(), AnyTypedArrayViewData(source), count*sizeof(T));
Ops::podCopy(dest, AnyTypedArrayViewData(source).template cast<T*>(), count);
return true;
}
@ -359,7 +379,7 @@ class ElementSpecific
uint32_t len = source->length();
if (source->type() == target->type()) {
Ops::memmove(dest, AnyTypedArrayViewData(source).template cast<T*>(), len*sizeof(T));
Ops::podMove(dest, AnyTypedArrayViewData(source).template cast<T*>(), len);
return true;
}