aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Gaignard <benjamin.gaignard@linaro.org>2016-05-25 16:40:59 +0200
committerBenjamin Gaignard <benjamin.gaignard@linaro.org>2016-05-25 16:40:59 +0200
commitfc6a8b2b29aceb375aaed226820b50bc3716d6fc (patch)
treece931f44fc49d0e468a651495a938c3ad64ea975
parent7d55a5f578d480ee97689f961891a7e9091d6937 (diff)
downloadlibsmaf-fc6a8b2b29aceb375aaed226820b50bc3716d6fc.tar.gz
adapt libsmaf to new ioctl structure
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
-rw-r--r--lib/libsmaf.c9
-rw-r--r--lib/smaf.h45
-rw-r--r--tests/test_smaf.c15
3 files changed, 46 insertions, 23 deletions
diff --git a/lib/libsmaf.c b/lib/libsmaf.c
index 47a9299..f47796b 100644
--- a/lib/libsmaf.c
+++ b/lib/libsmaf.c
@@ -77,8 +77,10 @@ int smaf_create_buffer(unsigned int length, unsigned int flags, char *name, int
create.length = length;
create.flags = flags;
- if (name)
+ if (name) {
strncpy(&create.name, name, sizeof(create.name));
+ create.name[MAX_NAME_LENGTH - 1] = 0;
+ }
ret = ioctl(smaf_fd, SMAF_IOC_CREATE, &create);
if (ret) {
@@ -161,8 +163,9 @@ char *smaf_get_allocator_name(int index)
if (!info.count)
return NULL;
- name = (char*)malloc(ALLOCATOR_NAME_LENGTH);
- strncpy(name, info.name, ALLOCATOR_NAME_LENGTH);
+ name = (char*)malloc(MAX_NAME_LENGTH);
+ strncpy(name, info.name, MAX_NAME_LENGTH);
+ name[MAX_NAME_LENGTH - 1] = 0;
return name;
}
diff --git a/lib/smaf.h b/lib/smaf.h
index 5a9201b..b453307 100644
--- a/lib/smaf.h
+++ b/lib/smaf.h
@@ -12,42 +12,61 @@
#include <linux/ioctl.h>
#include <linux/types.h>
-#define ALLOCATOR_NAME_LENGTH 64
+#define MAX_NAME_LENGTH 64
+
+#define SMAF_RDWR O_RDWR
+#define SMAF_CLOEXEC O_CLOEXEC
/**
* struct smaf_create_data - allocation parameters
- * @length: size of the allocation
- * @flags: flags passed to allocator
- * @name: name of the allocator to be selected, could be NULL
+ * @version: structure version (must be set to 0)
+ * @length: size of the requested buffer
+ * @flags: mode flags for the file like SMAF_RDWR or SMAF_CLOEXEC
* @fd: returned file descriptor
+ * @name: name of the allocator to be selected
+ * when NULL smaf will iterate over allocator to find
+ * one matching with devices constraints.
*/
struct smaf_create_data {
- size_t length;
- unsigned int flags;
- char name[ALLOCATOR_NAME_LENGTH];
- int fd;
+ __u64 version;
+ __u64 length;
+ __u32 flags;
+ __u32 reserved1;
+ __s32 fd;
+ __u32 reserved2;
+ __u8 name[MAX_NAME_LENGTH];
+ __u8 reserved3[32];
};
/**
* struct smaf_secure_flag - set/get secure flag
+ * @version: structure version (must be set to 0)
* @fd: file descriptor
* @secure: secure flag value (set or get)
*/
struct smaf_secure_flag {
- int fd;
- int secure;
+ __u64 version;
+ __s32 fd;
+ __u32 reserved1;
+ __u32 secure;
+ __u8 reserved2[44];
};
/**
* struct smaf_info - get registered allocator name per index
+ * @version: structure version (must be set to 0)
* @index: allocator's index
* @count: return number of registered allocators
* @name: return allocator name
*/
struct smaf_info {
- int index;
- int count;
- char name[ALLOCATOR_NAME_LENGTH];
+ __u64 version;
+ __u32 index;
+ __u32 reserved1;
+ __u32 count;
+ __u32 reserved2;
+ __u8 name[MAX_NAME_LENGTH];
+ __u8 reserved3[40];
};
#define SMAF_IOC_MAGIC 'S'
diff --git a/tests/test_smaf.c b/tests/test_smaf.c
index e01980a..86caadf 100644
--- a/tests/test_smaf.c
+++ b/tests/test_smaf.c
@@ -20,6 +20,7 @@
*/
#include <../lib/libsmaf.h>
+#include <../lib/smaf.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
@@ -31,7 +32,7 @@ static void test_create_named(char *name)
int ret;
int fd;
- ret = smaf_create_buffer(LENGTH, O_CLOEXEC | O_RDWR, name, &fd);
+ ret = smaf_create_buffer(LENGTH, SMAF_CLOEXEC | SMAF_RDWR, name, &fd);
if (ret || (fd == -1)) {
printf("%s: smaf_create_buffer() failed %d\n", __func__, ret);
@@ -48,7 +49,7 @@ static void test_create_named_invalid(void)
int ret;
int fd;
- ret = smaf_create_buffer(LENGTH, O_CLOEXEC | O_RDWR, "deadbeef", &fd);
+ ret = smaf_create_buffer(LENGTH, SMAF_CLOEXEC | SMAF_RDWR, "deadbeef", &fd);
if (!ret) {
printf("%s: smaf_create_buffer() failed %d\n", __func__, ret);
@@ -109,7 +110,7 @@ static void test_secure(void)
int ret;
int fd;
- ret = smaf_create_buffer(LENGTH, O_CLOEXEC | O_RDWR, NULL, &fd);
+ ret = smaf_create_buffer(LENGTH, SMAF_CLOEXEC | SMAF_RDWR, NULL, &fd);
if (ret || (fd == -1)) {
printf("%s: smaf_create_buffer() failed %d\n", __func__, ret);
@@ -139,7 +140,7 @@ static void test_create_non_page_aligned_mmap(void)
int fd;
void *data;
- ret = smaf_create_buffer(LENGTH+1, O_CLOEXEC | O_RDWR, NULL, &fd);
+ ret = smaf_create_buffer(LENGTH+1, SMAF_CLOEXEC | SMAF_RDWR, NULL, &fd);
if (ret || (fd == -1)) {
printf("%s smaf_create_buffer() failed %d\n", __func__, ret);
@@ -162,7 +163,7 @@ static void test_create_non_page_aligned(void)
int ret;
int fd;
- ret = smaf_create_buffer(LENGTH+1, O_CLOEXEC | O_RDWR, NULL, &fd);
+ ret = smaf_create_buffer(LENGTH+1, SMAF_CLOEXEC | SMAF_RDWR, NULL, &fd);
if (ret || (fd == -1)) {
printf("%s smaf_create_buffer() failed %d\n", __func__, ret);
@@ -183,7 +184,7 @@ static void test_mmap(void)
int ret, fd;
char *data;
- ret = smaf_create_buffer(LENGTH, O_CLOEXEC | O_RDWR, NULL, &fd);
+ ret = smaf_create_buffer(LENGTH, SMAF_CLOEXEC | SMAF_RDWR, NULL, &fd);
if (ret || (fd == -1)) {
printf("%s: smaf_create_buffer() failed %d\n", __func__, ret);
@@ -207,7 +208,7 @@ static void test_mmap_secure(void)
int ret, fd;
char *data;
- ret = smaf_create_buffer(LENGTH, O_CLOEXEC | O_RDWR, NULL, &fd);
+ ret = smaf_create_buffer(LENGTH, SMAF_CLOEXEC | SMAF_RDWR, NULL, &fd);
if (ret || (fd == -1)) {
printf("%s: smaf_create_buffer() failed %d\n", __func__, ret);