Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 16e1eaee authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder_ndk: array length always next to array

Bug: 111445392
Test: atest android.binder.cts
Change-Id: Ib965bf969163755f63effd8affabc3ddcb1db160
parent 90090213
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -377,9 +377,8 @@ binder_status_t AParcel_writeDoubleArray(AParcel* parcel, const double* value, s
 * getter(arrayData, i) will be called for each i in [0, length) in order to get the underlying
 * getter(arrayData, i) will be called for each i in [0, length) in order to get the underlying
 * values to write to the parcel.
 * values to write to the parcel.
 */
 */
binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData,
binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData, size_t length,
                                       AParcel_boolArrayGetter getter, size_t length)
                                       AParcel_boolArrayGetter getter) __INTRODUCED_IN(29);
        __INTRODUCED_IN(29);


/**
/**
 * Writes an array of char16_t to the next location in a non-null parcel.
 * Writes an array of char16_t to the next location in a non-null parcel.
+2 −2
Original line number Original line Diff line number Diff line
@@ -173,8 +173,8 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, std::vector<dou
 * Writes a vector of bool to the next location in a non-null parcel.
 * Writes a vector of bool to the next location in a non-null parcel.
 */
 */
inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<bool>& vec) {
inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<bool>& vec) {
    return AParcel_writeBoolArray(parcel, static_cast<const void*>(&vec),
    return AParcel_writeBoolArray(parcel, static_cast<const void*>(&vec), vec.size(),
                                  AParcel_stdVectorGetter<bool>, vec.size());
                                  AParcel_stdVectorGetter<bool>);
}
}


/**
/**
+5 −5
Original line number Original line Diff line number Diff line
@@ -142,8 +142,8 @@ binder_status_t ReadArray<char16_t>(const AParcel* parcel, void* arrayData,
}
}


template <typename T>
template <typename T>
binder_status_t WriteArray(AParcel* parcel, const void* arrayData, ArrayGetter<T> getter,
binder_status_t WriteArray(AParcel* parcel, const void* arrayData, size_t length,
                           size_t length, status_t (Parcel::*write)(T)) {
                           ArrayGetter<T> getter, status_t (Parcel::*write)(T)) {
    if (length > std::numeric_limits<int32_t>::max()) return STATUS_BAD_VALUE;
    if (length > std::numeric_limits<int32_t>::max()) return STATUS_BAD_VALUE;


    Parcel* rawParcel = parcel->get();
    Parcel* rawParcel = parcel->get();
@@ -425,9 +425,9 @@ binder_status_t AParcel_writeDoubleArray(AParcel* parcel, const double* value, s
    return WriteArray<double>(parcel, value, length);
    return WriteArray<double>(parcel, value, length);
}
}


binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData,
binder_status_t AParcel_writeBoolArray(AParcel* parcel, const void* arrayData, size_t length,
                                       AParcel_boolArrayGetter getter, size_t length) {
                                       AParcel_boolArrayGetter getter) {
    return WriteArray<bool>(parcel, arrayData, getter, length, &Parcel::writeBool);
    return WriteArray<bool>(parcel, arrayData, length, getter, &Parcel::writeBool);
}
}


binder_status_t AParcel_writeCharArray(AParcel* parcel, const char16_t* value, size_t length) {
binder_status_t AParcel_writeCharArray(AParcel* parcel, const char16_t* value, size_t length) {
+8 −8
Original line number Original line Diff line number Diff line
@@ -89,10 +89,10 @@ def main():
    for pretty, cpp in data_types:
    for pretty, cpp in data_types:
        nca = pretty in non_contiguously_addressable
        nca = pretty in non_contiguously_addressable


        arg_type = "const " + cpp + "* value"
        arg_types = "const " + cpp + "* value, size_t length"
        if nca: arg_type = "const void* arrayData, AParcel_" + pretty.lower() + "ArrayGetter getter"
        if nca: arg_types = "const void* arrayData, size_t length, AParcel_" + pretty.lower() + "ArrayGetter getter"
        args = "value, length"
        args = "value, length"
        if nca: args = "arrayData, getter, length, &Parcel::write" + pretty
        if nca: args = "arrayData, length, getter, &Parcel::write" + pretty


        header += "/**\n"
        header += "/**\n"
        header += " * Writes an array of " + cpp + " to the next location in a non-null parcel.\n"
        header += " * Writes an array of " + cpp + " to the next location in a non-null parcel.\n"
@@ -101,8 +101,8 @@ def main():
            header += " * getter(arrayData, i) will be called for each i in [0, length) in order to get the underlying values to write "
            header += " * getter(arrayData, i) will be called for each i in [0, length) in order to get the underlying values to write "
            header += "to the parcel.\n"
            header += "to the parcel.\n"
        header += " */\n"
        header += " */\n"
        header += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_type + ", size_t length) __INTRODUCED_IN(29);\n\n"
        header += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_types + ") __INTRODUCED_IN(29);\n\n"
        source += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_type + ", size_t length) {\n"
        source += "binder_status_t AParcel_write" + pretty + "Array(AParcel* parcel, " + arg_types + ") {\n"
        source += "    return WriteArray<" + cpp + ">(parcel, " + args + ");\n";
        source += "    return WriteArray<" + cpp + ">(parcel, " + args + ");\n";
        source += "}\n\n"
        source += "}\n\n"


@@ -178,9 +178,9 @@ def main():
        cpp_helper += " * Writes a vector of " + cpp + " to the next location in a non-null parcel.\n"
        cpp_helper += " * Writes a vector of " + cpp + " to the next location in a non-null parcel.\n"
        cpp_helper += " */\n"
        cpp_helper += " */\n"
        cpp_helper += "inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<" + cpp + ">& vec) {\n"
        cpp_helper += "inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<" + cpp + ">& vec) {\n"
        write_args = "vec.data()"
        write_args = "vec.data(), vec.size()"
        if nca: write_args = "static_cast<const void*>(&vec), AParcel_stdVectorGetter<" + cpp + ">"
        if nca: write_args = "static_cast<const void*>(&vec), vec.size(), AParcel_stdVectorGetter<" + cpp + ">"
        cpp_helper += "    return AParcel_write" + pretty + "Array(parcel, " + write_args + ", vec.size());\n"
        cpp_helper += "    return AParcel_write" + pretty + "Array(parcel, " + write_args + ");\n"
        cpp_helper += "}\n\n"
        cpp_helper += "}\n\n"


        cpp_helper += "/**\n"
        cpp_helper += "/**\n"