~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/android/ion/ionapp_import.c

Version: ~ [ linux-5.5 ] ~ [ linux-5.4.15 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.98 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.167 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.211 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.211 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.81 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * ionapp_import.c
  3  *
  4  * It is a user space utility to receive android ion memory buffer fd
  5  * over unix domain socket IPC that can be exported by ionapp_export.
  6  * This acts like a client for ionapp_export.
  7  *
  8  * Copyright (C) 2017 Pintu Kumar <pintu.ping@gmail.com>
  9  *
 10  * This software is licensed under the terms of the GNU General Public
 11  * License version 2, as published by the Free Software Foundation, and
 12  * may be copied, distributed, and modified under those terms.
 13  *
 14  * This program is distributed in the hope that it will be useful,
 15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17  * GNU General Public License for more details.
 18  *
 19  */
 20 
 21 #include <stdio.h>
 22 #include <stdlib.h>
 23 #include <unistd.h>
 24 #include <string.h>
 25 #include "ionutils.h"
 26 #include "ipcsocket.h"
 27 
 28 
 29 int main(void)
 30 {
 31         int ret, status;
 32         int sockfd, shared_fd;
 33         unsigned char *map_buf;
 34         unsigned long map_len;
 35         struct ion_buffer_info info;
 36         struct socket_info skinfo;
 37 
 38         /* This is the client part. Here 0 means client or importer */
 39         status = opensocket(&sockfd, SOCKET_NAME, 0);
 40         if (status < 0) {
 41                 fprintf(stderr, "No exporter exists...\n");
 42                 ret = status;
 43                 goto err_socket;
 44         }
 45 
 46         skinfo.sockfd = sockfd;
 47 
 48         ret = socket_receive_fd(&skinfo);
 49         if (ret < 0) {
 50                 fprintf(stderr, "Failed: socket_receive_fd\n");
 51                 goto err_recv;
 52         }
 53 
 54         shared_fd = skinfo.datafd;
 55         printf("Received buffer fd: %d\n", shared_fd);
 56         if (shared_fd <= 0) {
 57                 fprintf(stderr, "ERROR: improper buf fd\n");
 58                 ret = -1;
 59                 goto err_fd;
 60         }
 61 
 62         memset(&info, 0, sizeof(info));
 63         info.buffd = shared_fd;
 64         info.buflen = ION_BUFFER_LEN;
 65 
 66         ret = ion_import_buffer_fd(&info);
 67         if (ret < 0) {
 68                 fprintf(stderr, "Failed: ion_use_buffer_fd\n");
 69                 goto err_import;
 70         }
 71 
 72         map_buf = info.buffer;
 73         map_len = info.buflen;
 74         read_buffer(map_buf, map_len);
 75 
 76         /* Write probably new data to the same buffer again */
 77         map_len = ION_BUFFER_LEN;
 78         write_buffer(map_buf, map_len);
 79 
 80 err_import:
 81         ion_close_buffer_fd(&info);
 82 err_fd:
 83 err_recv:
 84 err_socket:
 85         closesocket(sockfd, SOCKET_NAME);
 86 
 87         return ret;
 88 }
 89 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp