root/tools/testing/selftests/android/ion/ionapp_import.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 // SPDX-License-Identifier: GPL-2.0-only
   2 /*
   3  * ionapp_import.c
   4  *
   5  * It is a user space utility to receive android ion memory buffer fd
   6  * over unix domain socket IPC that can be exported by ionapp_export.
   7  * This acts like a client for ionapp_export.
   8  *
   9  * Copyright (C) 2017 Pintu Kumar <pintu.ping@gmail.com>
  10  */
  11 
  12 #include <stdio.h>
  13 #include <stdlib.h>
  14 #include <unistd.h>
  15 #include <string.h>
  16 #include "ionutils.h"
  17 #include "ipcsocket.h"
  18 
  19 
  20 int main(void)
  21 {
  22         int ret, status;
  23         int sockfd, shared_fd;
  24         unsigned char *map_buf;
  25         unsigned long map_len;
  26         struct ion_buffer_info info;
  27         struct socket_info skinfo;
  28 
  29         /* This is the client part. Here 0 means client or importer */
  30         status = opensocket(&sockfd, SOCKET_NAME, 0);
  31         if (status < 0) {
  32                 fprintf(stderr, "No exporter exists...\n");
  33                 ret = status;
  34                 goto err_socket;
  35         }
  36 
  37         skinfo.sockfd = sockfd;
  38 
  39         ret = socket_receive_fd(&skinfo);
  40         if (ret < 0) {
  41                 fprintf(stderr, "Failed: socket_receive_fd\n");
  42                 goto err_recv;
  43         }
  44 
  45         shared_fd = skinfo.datafd;
  46         printf("Received buffer fd: %d\n", shared_fd);
  47         if (shared_fd <= 0) {
  48                 fprintf(stderr, "ERROR: improper buf fd\n");
  49                 ret = -1;
  50                 goto err_fd;
  51         }
  52 
  53         memset(&info, 0, sizeof(info));
  54         info.buffd = shared_fd;
  55         info.buflen = ION_BUFFER_LEN;
  56 
  57         ret = ion_import_buffer_fd(&info);
  58         if (ret < 0) {
  59                 fprintf(stderr, "Failed: ion_use_buffer_fd\n");
  60                 goto err_import;
  61         }
  62 
  63         map_buf = info.buffer;
  64         map_len = info.buflen;
  65         read_buffer(map_buf, map_len);
  66 
  67         /* Write probably new data to the same buffer again */
  68         map_len = ION_BUFFER_LEN;
  69         write_buffer(map_buf, map_len);
  70 
  71 err_import:
  72         ion_close_buffer_fd(&info);
  73 err_fd:
  74 err_recv:
  75 err_socket:
  76         closesocket(sockfd, SOCKET_NAME);
  77 
  78         return ret;
  79 }

/* [<][>][^][v][top][bottom][index][help] */