mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Change to proto2::MessageLite and resolve reflextion for mobile builds
PiperOrigin-RevId: 432164927 Change-Id: I0821cf443393b0bb16a68fc5750a9633a3f27725
This commit is contained in:
parent
e1a9513783
commit
077203fcf2
|
@ -143,7 +143,7 @@ class FunctionCallPreparer {
|
|||
|
||||
private:
|
||||
// Deserializes the protobuf argument.
|
||||
google::protobuf::Message** GetDeserializedProto(LenValStruct* src) {
|
||||
google::protobuf::MessageLite** GetDeserializedProto(LenValStruct* src) {
|
||||
ProtoArg proto_arg;
|
||||
if (!proto_arg.ParseFromArray(src->data, src->size)) {
|
||||
LOG(FATAL) << "Unable to parse ProtoArg.";
|
||||
|
@ -153,7 +153,7 @@ class FunctionCallPreparer {
|
|||
proto_arg.full_name());
|
||||
LOG_IF(FATAL, desc == nullptr) << "Unable to find the descriptor for '"
|
||||
<< proto_arg.full_name() << "'" << desc;
|
||||
google::protobuf::Message* deserialized_proto =
|
||||
google::protobuf::MessageLite* deserialized_proto =
|
||||
google::protobuf::MessageFactory::generated_factory()->GetPrototype(desc)->New();
|
||||
LOG_IF(FATAL, deserialized_proto == nullptr)
|
||||
<< "Unable to create deserialized proto for " << proto_arg.full_name();
|
||||
|
@ -168,7 +168,8 @@ class FunctionCallPreparer {
|
|||
// Use list instead of vector to preserve references even with modifications.
|
||||
// Contains pairs of lenval message pointer -> deserialized message
|
||||
// so that we can serialize the argument again after the function call.
|
||||
std::list<std::pair<LenValStruct*, google::protobuf::Message*>> protos_to_be_destroyed_;
|
||||
std::list<std::pair<LenValStruct*, google::protobuf::MessageLite*>>
|
||||
protos_to_be_destroyed_;
|
||||
ffi_type* ret_type_;
|
||||
ffi_type* arg_types_[FuncCall::kArgsMax];
|
||||
const void* arg_values_[FuncCall::kArgsMax];
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace sapi {
|
|||
namespace internal {
|
||||
|
||||
absl::Status DeserializeProto(const char* data, size_t len,
|
||||
google::protobuf::Message& output) {
|
||||
google::protobuf::MessageLite& output) {
|
||||
ProtoArg envelope;
|
||||
if (!envelope.ParseFromArray(data, len)) {
|
||||
return absl::InternalError("Unable to parse proto from array");
|
||||
|
@ -37,13 +37,12 @@ absl::Status DeserializeProto(const char* data, size_t len,
|
|||
} // namespace internal
|
||||
|
||||
absl::StatusOr<std::vector<uint8_t>> SerializeProto(
|
||||
const google::protobuf::Message& proto) {
|
||||
const google::protobuf::MessageLite& proto) {
|
||||
// Wrap protobuf in a envelope so that we know the name of the protobuf
|
||||
// structure when deserializing in the sandboxee.
|
||||
ProtoArg proto_arg;
|
||||
proto_arg.set_protobuf_data(proto.SerializeAsString());
|
||||
proto_arg.set_full_name(proto.GetDescriptor()->full_name());
|
||||
|
||||
proto_arg.set_full_name(proto.GetTypeName());
|
||||
std::vector<uint8_t> serialized_proto(proto_arg.ByteSizeLong());
|
||||
if (!proto_arg.SerializeToArray(serialized_proto.data(),
|
||||
serialized_proto.size())) {
|
||||
|
|
|
@ -31,16 +31,16 @@ namespace sapi {
|
|||
namespace internal {
|
||||
|
||||
absl::Status DeserializeProto(const char* data, size_t len,
|
||||
google::protobuf::Message& output);
|
||||
google::protobuf::MessageLite& output);
|
||||
|
||||
} // namespace internal
|
||||
|
||||
absl::StatusOr<std::vector<uint8_t>> SerializeProto(
|
||||
const google::protobuf::Message& proto);
|
||||
const google::protobuf::MessageLite& proto);
|
||||
|
||||
template <typename T>
|
||||
absl::StatusOr<T> DeserializeProto(const char* data, size_t len) {
|
||||
static_assert(std::is_base_of<google::protobuf::Message, T>::value,
|
||||
static_assert(std::is_base_of<google::protobuf::MessageLite, T>::value,
|
||||
"Template argument must be a proto message");
|
||||
T result;
|
||||
SAPI_RETURN_IF_ERROR(
|
||||
|
|
|
@ -437,7 +437,7 @@ bool Comms::SendFD(int fd) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Comms::RecvProtoBuf(google::protobuf::Message* message) {
|
||||
bool Comms::RecvProtoBuf(google::protobuf::MessageLite* message) {
|
||||
uint32_t tag;
|
||||
std::vector<uint8_t> bytes;
|
||||
if (!RecvTLV(&tag, &bytes)) {
|
||||
|
@ -457,7 +457,7 @@ bool Comms::RecvProtoBuf(google::protobuf::Message* message) {
|
|||
return message->ParseFromArray(bytes.data(), bytes.size());
|
||||
}
|
||||
|
||||
bool Comms::SendProtoBuf(const google::protobuf::Message& message) {
|
||||
bool Comms::SendProtoBuf(const google::protobuf::MessageLite& message) {
|
||||
std::string str;
|
||||
if (!message.SerializeToString(&str)) {
|
||||
SAPI_RAW_LOG(ERROR, "Couldn't serialize the ProtoBuf");
|
||||
|
|
|
@ -155,8 +155,8 @@ class Comms {
|
|||
bool SendFD(int fd);
|
||||
|
||||
// Receives/sends protobufs.
|
||||
bool RecvProtoBuf(google::protobuf::Message* message);
|
||||
bool SendProtoBuf(const google::protobuf::Message& message);
|
||||
bool RecvProtoBuf(google::protobuf::MessageLite* message);
|
||||
bool SendProtoBuf(const google::protobuf::MessageLite& message);
|
||||
|
||||
// Receives/sends Status objects.
|
||||
bool RecvStatus(absl::Status* status);
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace sapi::v {
|
|||
template <typename T>
|
||||
class Proto : public Var {
|
||||
public:
|
||||
static_assert(std::is_base_of<google::protobuf::Message, T>::value,
|
||||
static_assert(std::is_base_of<google::protobuf::MessageLite, T>::value,
|
||||
"Template argument must be a proto message");
|
||||
|
||||
ABSL_DEPRECATED("Use Proto<>::FromMessage() instead")
|
||||
|
|
Loading…
Reference in New Issue
Block a user