[gbinder] Don't compile fmq code if __NR_memfd_create is undefined

This commit is contained in:
Slava Monich 2021-11-24 14:19:20 +02:00
parent e5542027c2
commit 8b621fe7d3
5 changed files with 64 additions and 16 deletions

View File

@ -39,9 +39,10 @@
#include <linux/futex.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <unistd.h>
#if GBINDER_FMQ_SUPPORTED
/* Grantor data positions */
enum {
READ_PTR_POS = 0,
@ -685,6 +686,10 @@ gbinder_fmq_wake(
return ret;
}
#else /* !GBINDER_FMQ_SUPPORTED */
#pragma message("Not compiling FMQ")
#endif
/*
* Local Variables:
* mode: C

View File

@ -36,6 +36,15 @@
#include "gbinder_types_p.h"
/* FMQ functionality requires __NR_memfd_create syscall */
#include <sys/syscall.h>
#ifdef __NR_memfd_create
# define GBINDER_FMQ_SUPPORTED 1
#else
# define GBINDER_FMQ_SUPPORTED 0
#endif
/*
* From linux/memfd.h
*/

View File

@ -997,6 +997,9 @@ gbinder_writer_append_byte_array(
}
}
#if GBINDER_FMQ_SUPPORTED
static
void
gbinder_writer_data_append_fmq_descriptor(
GBinderWriterData* data,
@ -1052,6 +1055,8 @@ gbinder_writer_append_fmq_descriptor(
}
}
#endif /* GBINDER_FMQ_SUPPORTED */
void
gbinder_writer_data_append_remote_object(
GBinderWriterData* data,

View File

@ -31,8 +31,10 @@
#include "test_common.h"
#include "gbinder_driver.h"
#include "gbinder_fmq_p.h"
#if GBINDER_FMQ_SUPPORTED
#include "gbinder_log.h"
#include <errno.h>
@ -526,6 +528,8 @@ test_zero_copy(
gbinder_fmq_unref(fmq);
}
#endif /* GBINDER_FMQ_SUPPORTED */
/*==========================================================================*
* Common
*==========================================================================*/
@ -535,6 +539,7 @@ test_zero_copy(
int main(int argc, char* argv[])
{
#if GBINDER_FMQ_SUPPORTED
guint i;
int test_fd;
@ -551,7 +556,7 @@ int main(int argc, char* argv[])
}
/* Some test environments don't know how handle this syscall */
test_fd = syscall(__NR_memfd_create, "MessageQueue", MFD_CLOEXEC);
test_fd = syscall(__NR_memfd_create, "test", MFD_CLOEXEC);
if (test_fd < 0 && errno == ENOSYS) {
GINFO("Skipping tests that rely on memfd_create");
} else {
@ -577,7 +582,9 @@ int main(int argc, char* argv[])
g_test_add_func(TEST_("wait_wake"), test_wait_wake);
g_test_add_func(TEST_("zero_copy"), test_zero_copy);
}
#else /* GBINDER_FMQ_SUPPORTED */
g_test_init(&argc, &argv, NULL);
#endif
return g_test_run();
}

View File

@ -39,8 +39,10 @@
#include "gbinder_io.h"
#include <gutil_intarray.h>
#include <gutil_log.h>
#include <unistd.h>
#include <errno.h>
static TestOpt test_opt;
@ -100,12 +102,15 @@ test_null(
gbinder_writer_append_remote_object(&writer, NULL);
gbinder_writer_append_byte_array(NULL, NULL, 0);
gbinder_writer_append_byte_array(&writer, NULL, 0);
gbinder_writer_append_fmq_descriptor(NULL, NULL);
gbinder_writer_append_fmq_descriptor(&writer, NULL);
gbinder_writer_add_cleanup(NULL, NULL, 0);
gbinder_writer_add_cleanup(NULL, g_free, 0);
gbinder_writer_overwrite_int32(NULL, 0, 0);
#if GBINDER_FMQ_SUPPORTED
gbinder_writer_append_fmq_descriptor(NULL, NULL);
gbinder_writer_append_fmq_descriptor(&writer, NULL);
#endif
g_assert(!gbinder_writer_bytes_written(NULL));
g_assert(!gbinder_writer_get_data(NULL, NULL));
g_assert(!gbinder_writer_get_data(NULL, &size));
@ -978,6 +983,8 @@ test_byte_array(
* fmq descriptor
*==========================================================================*/
#if GBINDER_FMQ_SUPPORTED
static
void
test_fmq_descriptor(
@ -987,31 +994,33 @@ test_fmq_descriptor(
GBinderOutputData* data;
GUtilIntArray* offsets;
GBinderWriter writer;
gint32 in_len = 3 * BUFFER_OBJECT_SIZE_64 /* Buffer objects */
const gint32 len = 3 * BUFFER_OBJECT_SIZE_64 /* Buffer objects */
+ sizeof(gint64) /* gint64 */
+ 4 * sizeof(gint64); /* binder_fd_array_object */
GBinderFmq* in_data = gbinder_fmq_new(sizeof(guint32), 5,
GBINDER_FMQ_TYPE_SYNC_READ_WRITE, GBINDER_FMQ_FLAG_CONFIGURE_EVENT_FLAG,
-1, 0);
GBinderFmq* fmq = gbinder_fmq_new(sizeof(guint32), 5,
GBINDER_FMQ_TYPE_SYNC_READ_WRITE,
GBINDER_FMQ_FLAG_CONFIGURE_EVENT_FLAG, -1, 0);
g_assert(fmq);
req = gbinder_local_request_new(&gbinder_io_64, NULL);
gbinder_local_request_init_writer(req, &writer);
gbinder_writer_append_fmq_descriptor(&writer, in_data);
gbinder_writer_append_fmq_descriptor(&writer, fmq);
data = gbinder_local_request_data(req);
offsets = gbinder_output_data_offsets(data);
g_assert(offsets);
g_assert(offsets->count == 4);
g_assert_cmpuint(offsets->count, == ,4);
g_assert(offsets->data[0] == 0);
g_assert(offsets->data[1] == BUFFER_OBJECT_SIZE_64);
g_assert(offsets->data[2] == 2 * BUFFER_OBJECT_SIZE_64 + sizeof(gint64));
g_assert(offsets->data[3] == 3 * BUFFER_OBJECT_SIZE_64 + sizeof(gint64));
g_assert(data->bytes->len == in_len);
g_assert_cmpuint(data->bytes->len, == ,len);
gbinder_local_request_unref(req);
gbinder_fmq_unref(in_data);
gbinder_fmq_unref(fmq);
}
#endif /* GBINDER_FMQ_SUPPORTED */
/*==========================================================================*
* bytes_written
*==========================================================================*/
@ -1114,8 +1123,21 @@ int main(int argc, char* argv[])
g_test_add_func(TEST_("local_object"), test_local_object);
g_test_add_func(TEST_("remote_object"), test_remote_object);
g_test_add_func(TEST_("byte_array"), test_byte_array);
g_test_add_func(TEST_("fmq_descriptor"), test_fmq_descriptor);
g_test_add_func(TEST_("bytes_written"), test_bytes_written);
#if GBINDER_FMQ_SUPPORTED
{
int test_fd = syscall(__NR_memfd_create, "test", MFD_CLOEXEC);
if (test_fd < 0 && errno == ENOSYS) {
GINFO("Skipping tests that rely on memfd_create");
} else {
close(test_fd);
g_test_add_func(TEST_("fmq_descriptor"), test_fmq_descriptor);
}
}
#endif /* GBINDER_FMQ_SUPPORTED */
test_init(&test_opt, argc, argv);
return g_test_run();
}