Commit Graph

489 Commits

Author SHA1 Message Date
2778ec3a88 debug logs 2025-10-18 13:49:55 +08:00
6697470380 debian files 2025-10-17 23:30:56 +08:00
Ratchanan Srirattanamet
a9dfd6e453 writer: don't write object offset for NULL binder object
Writing offset will trigger the kernel-side code to transform the flat
binder object into the handle form, which (in my understanding) is not
a valid operation for a NULL binder object. Meanwhile, the receiving
side will create a corresponding Binder object from such handle,
tripping the stability check as it will no longer accept UNDECLARED.

OTOH, if the offset is not written, then the receiving side will receive
the flat binder object as-is, with type BINDER and pointer NULL, which
will be interpreted as NULL binder. This is also what Android's
Parcel.cpp does [1][2].

IMO, this is sort of a hack. Binder kernel driver should handle the NULL
binder internally, and not relying on the sender doing the correct
thing. Meanwhile, the receiver should always reject a flat binder object
of type BINDER. But that's how Android work, so... 🤷

[1]: https://github.com/LineageOS/android_frameworks_native/blob/lineage-19.1/libs/binder/Parcel.cpp#L1327-L1332
[2]: https://github.com/LineageOS/android_frameworks_native/blob/lineage-19.1/libs/binder/Parcel.cpp#L2023-L2029

Origin: vendor
Forwarded: https://github.com/mer-hybris/libgbinder/pull/135
2025-10-17 23:29:53 +08:00
Ratchanan Srirattanamet
2439ff878d use BINDER_TYPE_BINDER for NULL local object
3 reasons:
- This is what encode_remote_object() does. I see no reason a NULL local
  object should be encoded differently than a NULL remote object.
- This is what Parcel.cpp does when flattening a NULL binder [1]. This
  is contrary to what is said in PR #99 [2]; I'm not sure why PR #99
  said it uses BINDER_TYPE_HANDLE.
- More importantly, BINDER_TYPE_HANDLE number 0 does NOT represent a
  NULL binder. According to the comment at [3], handle number 0 actually
  represent the context manager. So, by sending BINDER_TYPE_HANDLE
  number 0, we're sending context manager, not a NULL binder.

[1]: https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-14.0.0_r1/libs/binder/Parcel.cpp#277
[2]: https://github.com/mer-hybris/libgbinder/pull/99
[3]: https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-14.0.0_r1/libs/binder/ProcessState.cpp#336

Origin: vendor
Bug-UBports: https://gitlab.com/ubports/development/core/packaging/libgbinder/-/merge_requests/9#note_2138653925
Forwarded: https://github.com/mer-hybris/libgbinder/pull/135
2025-10-17 23:29:52 +08:00
Ratchanan Srirattanamet
8c65520173 uses aidl3 servicemanager on API level 31 & 32
Nikita (@NotKit) noticed that the change in commit f227ae4291
("[gbinder] All binder objects need stability field in Android 11.
JB#58951") has made the aidl4 servicemanager variant redundant. In fact,
using aidl4 variant will cause an extra stability field to be sent on
the wire (luckily it has not caused any problem).

I've tried using aidl3 variant on Volla Phone X23 which runs Halium 12
(API level 32), and service registration still work, which seems to
validate this theory. Thus, stop using aidl4 servicemanager variant on
any of the API level-based config, as it no longer correspond to any of
Android versions.

Note that this commit doesn't outright remove aidl4 variant, as doing so
would break configurations which explicitly request its use. This commit
doesn't doesn't alias the aidl4 variant to aidl3 variant either.
Manually requesting a certain variant could mean some unusual setup;
aliasing aidl4 to aidl3 could break such setup.

Origin: vendor
Forwarded: https://github.com/mer-hybris/libgbinder/pull/133
2025-10-17 23:29:52 +08:00
Ratchanan Srirattanamet
e3764d7002 correct stability field wire format on Android 12
On Android 12, the wire format of stability field is changed to also
include so-called "Binder wire format version", which starts at 1 [1].
A 32-bit-sized struct is re-interpreted into a 32-bit integer, with a
layout which makes it incompatible with the old version. Interestingly,
they reverted this idea in Android 13 [2], which makes the wire format
of the stability field the same as Android 11 again (as far as I know).

Add a new RPC protocol variant 'aidl4' to account for this difference.
Use this protocol on API level 31 through 32 and use 'aidl3' from API
level 33 onwards. The only difference from 'aidl3' is `finish_flatten_
binder()` function.

Interestingly, there is also a 16-bit-sized struct variant of the field
too [3]. However, to the best of my knowledge, this version is not used
in any of the released Android versions.

[1]: 89ddfc5f8c
[2]: 16a4106cb7
[3]: 14e4cfae36

Origin: vendor
Forwarded: https://github.com/mer-hybris/libgbinder/pull/133
2025-10-17 23:29:52 +08:00
Slava Monich
624bfa843d Version 1.1.40 1.1.40 2024-07-18 05:35:00 +03:00
Slava Monich
6d71a0649c [gbinder] Housekeeping 2024-07-18 05:32:36 +03:00
Slava Monich
c31cd7e964 Acknowledge Nikita's contribution 2024-07-18 05:08:47 +03:00
Slava Monich
c1db86e734 Merge pull request #130 from mer-hybris/aidl-stability
Make stability field of local object configurable
2024-07-18 05:04:50 +03:00
Nikita Ukhrenkov
bfb95f2bf5 [gbinder] Make stability field of local object configurable. JB#61912
AIDL HALs require stability field value to be set to VINTF as
opposed to the default SYSTEM, so expose a way to let the caller
set the value to used by finish_flatten_binder per local object.
2024-07-15 18:42:20 +03:00
Slava Monich
6f4c69d58a Merge pull request #131 from monich/unit_conf
Make more unit tests independent on system config
2024-07-15 17:29:17 +03:00
Slava Monich
c6b09a10d4 [unit] Make more unit tests independent on system config. JB#42956
System gbinder config shouldn't break unit tests.
2024-07-14 06:15:19 +03:00
Slava Monich
545f5bc28d Version 1.1.39 1.1.39 2024-05-05 20:09:11 +03:00
Slava Monich
78e006f1cf Acknowledge Martin's contribution 2024-05-05 20:08:23 +03:00
Slava Monich
3c9cc1711a [spec] Cleaned up macro syntax 2024-04-30 20:25:43 +03:00
Slava Monich
71aa3acc08 [spec] Restore compatibility with rpm < 4.12 (again) 2024-04-30 02:42:25 +03:00
Slava Monich
eee26c5e98 [spec] Restore compatibility with rpm < 4.12 2024-04-30 02:18:18 +03:00
Slava Monich
736a29aa4c Merge pull request #128 from mer-hybris/jb61933
Utilize make_build macro
2024-04-29 19:54:51 +03:00
Martin Kampas
0d7105edbe [gbinder] Utilize make_build macro. JB#61933
Allow the build system to override the way make is invoked.

Cannot use make_install equally as that does not allow to pass
additional arguments to make.
2024-04-16 13:36:50 +02:00
Slava Monich
4420c7b2ae Merge pull request #126 from mer-hybris/jb61912
Eliminate defects found by Coverity
2024-04-12 04:51:00 +03:00
Martin Kampas
52726a07b0 [gbinder] Add model file for Coverity. JB#61912
Eliminate false positive. Help Coverity see there is no resource leak
(CID 444479).
2024-04-11 12:59:39 +02:00
Martin Kampas
12b9fd49ad [gbinder] Avoid double-checked locking in gbinder_ipc_looper_check. JB#61912
Data race condition detected by Coverity (CID 444481, CID 444483).

According to Slava the effect of this particular optimization is
negligible, so let's simply drop it to make Coverity happy.
2024-04-11 12:57:13 +02:00
Martin Kampas
e75959e389 [gbinder] Explicitly ignore return value. JB#61912
Recognized by Coverity (CID 444485) that this is the single call to
gbinder_driver_write out of the total of 9, where the return value is
not checked.

This change is implemented just to make Coverity happy.  The compiler
does not complain.
2024-04-11 12:45:33 +02:00
Slava Monich
9d35ca22fb Merge pull request #127 from monich/set_data
Remove unnecessary checks for NULL
2024-04-11 13:09:34 +03:00
Slava Monich
3e0d0005ce [gbinder] Remove unnecessary checks for NULL. JB#61912
And fix potential use after free.
2024-04-11 03:29:28 +03:00
Slava Monich
29718f921f Version 1.1.38 1.1.38 2024-03-02 02:13:19 +02:00
Slava Monich
99b2dd85c1 [unit] Test byte array padding. JB#42956 2024-03-02 02:09:44 +02:00
Slava Monich
cf5417d5db [gbinder] Housekeeping 2024-03-02 02:01:11 +02:00
Slava Monich
03f214eb24 [gbinder] Fixed FF padding 2024-03-02 01:59:43 +02:00
Slava Monich
6508a73dcd Merge pull request #124 from mer-hybris/bytearraypad 2024-03-02 01:46:57 +02:00
Andrew Branson
1100d8ede1 [gbinder] Byte array padding
Android aligns byte array reads and writes to 4 bytes and pads with 0xFF.
Not accounting for this causes misalignment issues on further reading.
2024-03-01 10:09:41 +01:00
Slava Monich
f89469b1a5 Version 1.1.37 1.1.37 2024-02-26 16:25:25 +02:00
Slava Monich
fcf2ef0ea4 Merge pull request #123 from Tomin1/jb61613
Fix gbinder_driver_reply_data return value
2024-02-26 16:18:55 +02:00
Tomi Leppänen
f9202cab37 [gbinder] Fix gbinder_driver_reply_data return value. Fixes JB#61613
Previously this always returned 1. Drop the first comparison so status
can be negative and errors will return 0.

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
2024-02-26 10:54:39 +02:00
Slava Monich
49729d95c9 Version 1.1.36 1.1.36 2024-02-10 05:05:39 +02:00
Slava Monich
11765cd80d [unit] Added test for surrogate pairs 2024-02-10 05:00:25 +02:00
Slava Monich
4820b2971f [gbinder] Housekeeping 2024-02-10 04:57:24 +02:00
Slava Monich
0623fb85db [license] Freshened up the license 2024-02-10 04:54:52 +02:00
Slava Monich
e655d8992a Merge pull request #122 from mer-hybris/jb61524
Calculate correct size for UTF-16 buffer in advance.
2024-02-10 04:49:11 +02:00
Andrew Branson
44e57ea98d [gbinder] Calculate correct size for UTF-16 buffer in advance. Fixes JB#61524
In UTF-16, code points U+010000 to U+10FFFF are encoded using 'surrogate
pairs' where 32 bits are actually used. If a string is mostly emojis,
that can end up larger than the len*2 bytes assumed padded_len.
Convert the string to UTF-16 before allocating the extra buffer size so
it will be correct.
2024-02-09 17:29:19 +01:00
Slava Monich
e3f705c4cc Merge pull request #120 from JamiKettunen/cross-pkgconf
[build] Support pkg-config cross-compilation
2023-12-01 03:44:46 +02:00
Jami Kettunen
6f0e8a693d [build] Support pkg-config cross-compilation
Previously to cross-compile one would need to add a pkg-config
executable in $PATH wrapping all the search paths required; now one can
e.g.

  make PKG_CONFIG=foreign-arch-target-pkg-config

with the wrapper executable being separate and allowing programs for
host to also be built if needed for example.
2023-11-30 20:54:40 +02:00
Slava Monich
c7fab6373b Version 1.1.35 1.1.35 2023-11-23 01:45:18 +02:00
Slava Monich
9aded94555 Merge pull request #119 from monich/test_config
Make unit tests independent on system config
2023-11-23 01:38:15 +02:00
Slava Monich
b5bab2431e [unit] Make unit tests independent on system config. JB#42956
System gbinder config shouldn't break unit tests.
2023-11-19 18:41:26 +02:00
Slava Monich
509faccba0 Merge pull request #117 from JamiKettunen/make-var
[build] Use MAKE var instead of explicitly calling make
2023-09-11 02:13:30 +03:00
Jami Kettunen
a89dcd2702 [build] Use MAKE var instead of explicitly calling make
There are multiple make implementations and nothing guarantees that the
make executable is gmake, which is what this Makefile requires.
2023-09-08 15:20:10 +03:00
Slava Monich
62b9b30865 Version 1.1.34 1.1.34 2023-04-30 06:10:45 +03:00
Slava Monich
4a913590d9 [gbinder] Require glib 2.32 2023-04-30 06:07:16 +03:00