summaryrefslogtreecommitdiff
path: root/libs/binder/Parcel.cpp
diff options
context:
space:
mode:
author Andrei Homescu <ahomescu@google.com> 2022-08-04 01:33:33 +0000
committer Andrei Homescu <ahomescu@google.com> 2022-08-16 21:58:41 +0000
commit24ad36eec712d42f972b4b83311c86aa0b37e3b7 (patch)
treeebfe4315fa402676639ba574964aecfeea7ccd67 /libs/binder/Parcel.cpp
parenta8fa78c5fdb652375440aa2b4b412e9e0bbc4c6d (diff)
libbinder: build ParcelFileDescriptor on Trusty
Adds ParcelFileDescriptor.cpp to the Trusty build which in turn compiles some extra related code from Parcel.cpp. This code uses fcntl(...O_DUPFD_CLOEXEC...) to duplicate file descriptors which is not available on Trusty (or other OSes), so we abstract the relevant calls to that function in a wrapper in OS.cpp. Bug: 224644083 Test: m Test: build on Trusty Change-Id: I2e0ee517e7c7b55458a6ee6db977985aab4d7c58
Diffstat (limited to 'libs/binder/Parcel.cpp')
-rw-r--r--libs/binder/Parcel.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 8b5d11800f..888757214d 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -48,6 +48,7 @@
#include <utils/String8.h>
#include <utils/misc.h>
+#include "OS.h"
#include "RpcState.h"
#include "Static.h"
#include "Utils.h"
@@ -1477,9 +1478,9 @@ status_t Parcel::writeFileDescriptor(int fd, bool takeOwnership) {
status_t Parcel::writeDupFileDescriptor(int fd)
{
- int dupFd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
- if (dupFd < 0) {
- return -errno;
+ int dupFd;
+ if (status_t err = dupFileDescriptor(fd, &dupFd); err != OK) {
+ return err;
}
status_t err = writeFileDescriptor(dupFd, true /*takeOwnership*/);
if (err != OK) {
@@ -1496,9 +1497,9 @@ status_t Parcel::writeParcelFileDescriptor(int fd, bool takeOwnership)
status_t Parcel::writeDupParcelFileDescriptor(int fd)
{
- int dupFd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
- if (dupFd < 0) {
- return -errno;
+ int dupFd;
+ if (status_t err = dupFileDescriptor(fd, &dupFd); err != OK) {
+ return err;
}
status_t err = writeParcelFileDescriptor(dupFd, true /*takeOwnership*/);
if (err != OK) {
@@ -2295,7 +2296,12 @@ status_t Parcel::readUniqueFileDescriptor(base::unique_fd* val) const
return BAD_TYPE;
}
- val->reset(fcntl(got, F_DUPFD_CLOEXEC, 0));
+ int dupFd;
+ if (status_t err = dupFileDescriptor(got, &dupFd); err != OK) {
+ return BAD_VALUE;
+ }
+
+ val->reset(dupFd);
if (val->get() < 0) {
return BAD_VALUE;
@@ -2312,7 +2318,12 @@ status_t Parcel::readUniqueParcelFileDescriptor(base::unique_fd* val) const
return BAD_TYPE;
}
- val->reset(fcntl(got, F_DUPFD_CLOEXEC, 0));
+ int dupFd;
+ if (status_t err = dupFileDescriptor(got, &dupFd); err != OK) {
+ return BAD_VALUE;
+ }
+
+ val->reset(dupFd);
if (val->get() < 0) {
return BAD_VALUE;