summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adb/Android.mk4
-rw-r--r--adb/transport_local.cpp2
-rw-r--r--qemu_pipe/Android.mk19
-rw-r--r--qemu_pipe/include/qemu_pipe.h62
-rw-r--r--qemu_pipe/qemu_pipe.cpp (renamed from include/system/qemu_pipe.h)16
5 files changed, 92 insertions, 11 deletions
diff --git a/adb/Android.mk b/adb/Android.mk
index b444afad1..a2ea699bc 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -124,11 +124,12 @@ LOCAL_SRC_FILES := \
124 adbd_auth.cpp \ 124 adbd_auth.cpp \
125 jdwp_service.cpp \ 125 jdwp_service.cpp \
126 126
127LOCAL_C_INCLUDES := system/core/qemu_pipe/include
127LOCAL_SANITIZE := $(adb_target_sanitize) 128LOCAL_SANITIZE := $(adb_target_sanitize)
128 129
129# Even though we're building a static library (and thus there's no link step for 130# Even though we're building a static library (and thus there's no link step for
130# this to take effect), this adds the includes to our path. 131# this to take effect), this adds the includes to our path.
131LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto libbase 132LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto libqemu_pipe libbase
132 133
133LOCAL_WHOLE_STATIC_LIBRARIES := libadbd_usb 134LOCAL_WHOLE_STATIC_LIBRARIES := libadbd_usb
134 135
@@ -357,6 +358,7 @@ LOCAL_STRIP_MODULE := keep_symbols
357LOCAL_STATIC_LIBRARIES := \ 358LOCAL_STATIC_LIBRARIES := \
358 libadbd \ 359 libadbd \
359 libbase \ 360 libbase \
361 libqemu_pipe \
360 libbootloader_message \ 362 libbootloader_message \
361 libfs_mgr \ 363 libfs_mgr \
362 libfec \ 364 libfec \
diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp
index c17f86914..b5d0ef070 100644
--- a/adb/transport_local.cpp
+++ b/adb/transport_local.cpp
@@ -248,7 +248,7 @@ static void server_socket_thread(void* arg) {
248#define open adb_open 248#define open adb_open
249#define read adb_read 249#define read adb_read
250#define write adb_write 250#define write adb_write
251#include <system/qemu_pipe.h> 251#include <qemu_pipe.h>
252#undef open 252#undef open
253#undef read 253#undef read
254#undef write 254#undef write
diff --git a/qemu_pipe/Android.mk b/qemu_pipe/Android.mk
new file mode 100644
index 000000000..6e0144ce1
--- /dev/null
+++ b/qemu_pipe/Android.mk
@@ -0,0 +1,19 @@
1# Copyright 2011 The Android Open Source Project
2
3LOCAL_PATH:= $(call my-dir)
4
5common_static_libraries := \
6 libbase
7include $(CLEAR_VARS)
8LOCAL_CLANG := true
9LOCAL_SANITIZE := integer
10LOCAL_SRC_FILES:= \
11 qemu_pipe.cpp
12LOCAL_C_INCLUDES := \
13 $(LOCAL_PATH)/include \
14 system/base/include
15LOCAL_MODULE:= libqemu_pipe
16LOCAL_STATIC_LIBRARIES := $(common_static_libraries)
17LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
18LOCAL_CFLAGS := -Werror
19include $(BUILD_STATIC_LIBRARY)
diff --git a/qemu_pipe/include/qemu_pipe.h b/qemu_pipe/include/qemu_pipe.h
new file mode 100644
index 000000000..16486c087
--- /dev/null
+++ b/qemu_pipe/include/qemu_pipe.h
@@ -0,0 +1,62 @@
1/*
2 * Copyright (C) 2011 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#ifndef ANDROID_CORE_INCLUDE_QEMU_PIPE_H
17#define ANDROID_CORE_INCLUDE_QEMU_PIPE_H
18
19#include <stddef.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24// Try to open a new Qemu fast-pipe. This function returns a file descriptor
25// that can be used to communicate with a named service managed by the
26// emulator.
27//
28// This file descriptor can be used as a standard pipe/socket descriptor.
29//
30// 'pipeName' is the name of the emulator service you want to connect to,
31// and must begin with 'pipe:' (e.g. 'pipe:camera' or 'pipe:opengles').
32//
33// On success, return a valid file descriptor, or -1/errno on failure. E.g.:
34//
35// EINVAL -> unknown/unsupported pipeName
36// ENOSYS -> fast pipes not available in this system.
37//
38// ENOSYS should never happen, except if you're trying to run within a
39// misconfigured emulator.
40//
41// You should be able to open several pipes to the same pipe service,
42// except for a few special cases (e.g. GSM modem), where EBUSY will be
43// returned if more than one client tries to connect to it.
44int qemu_pipe_open(const char* pipeName);
45
46// Send a framed message |buff| of |len| bytes through the |fd| descriptor.
47// This really adds a 4-hexchar prefix describing the payload size.
48// Returns 0 on success, and -1 on error.
49int qemu_pipe_frame_send(int fd, const void* buff, size_t len);
50
51// Read a frame message from |fd|, and store it into |buff| of |len| bytes.
52// If the framed message is larger than |len|, then this returns -1 and the
53// content is lost. Otherwise, this returns the size of the message. NOTE:
54// empty messages are possible in a framed wire protocol and do not mean
55// end-of-stream.
56int qemu_pipe_frame_recv(int fd, void* buff, size_t len);
57
58#ifdef __cplusplus
59}
60#endif
61
62#endif /* ANDROID_CORE_INCLUDE_QEMU_PIPE_H */
diff --git a/include/system/qemu_pipe.h b/qemu_pipe/qemu_pipe.cpp
index af2507997..a4529deb8 100644
--- a/include/system/qemu_pipe.h
+++ b/qemu_pipe/qemu_pipe.cpp
@@ -13,13 +13,15 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16#ifndef ANDROID_INCLUDE_SYSTEM_QEMU_PIPE_H 16
17#define ANDROID_INCLUDE_SYSTEM_QEMU_PIPE_H 17#include "qemu_pipe.h"
18 18
19#include <unistd.h> 19#include <unistd.h>
20#include <fcntl.h> 20#include <fcntl.h>
21#include <string.h> 21#include <string.h>
22#include <errno.h> 22#include <errno.h>
23#include <stdio.h>
24
23 25
24// Define QEMU_PIPE_DEBUG if you want to print error messages when an error 26// Define QEMU_PIPE_DEBUG if you want to print error messages when an error
25// occurs during pipe operations. The macro should simply take a printf-style 27// occurs during pipe operations. The macro should simply take a printf-style
@@ -48,7 +50,7 @@
48// You should be able to open several pipes to the same pipe service, 50// You should be able to open several pipes to the same pipe service,
49// except for a few special cases (e.g. GSM modem), where EBUSY will be 51// except for a few special cases (e.g. GSM modem), where EBUSY will be
50// returned if more than one client tries to connect to it. 52// returned if more than one client tries to connect to it.
51static __inline__ int qemu_pipe_open(const char* pipeName) { 53int qemu_pipe_open(const char* pipeName) {
52 // Sanity check. 54 // Sanity check.
53 if (!pipeName || memcmp(pipeName, "pipe:", 5) != 0) { 55 if (!pipeName || memcmp(pipeName, "pipe:", 5) != 0) {
54 errno = EINVAL; 56 errno = EINVAL;
@@ -81,9 +83,7 @@ static __inline__ int qemu_pipe_open(const char* pipeName) {
81// Send a framed message |buff| of |len| bytes through the |fd| descriptor. 83// Send a framed message |buff| of |len| bytes through the |fd| descriptor.
82// This really adds a 4-hexchar prefix describing the payload size. 84// This really adds a 4-hexchar prefix describing the payload size.
83// Returns 0 on success, and -1 on error. 85// Returns 0 on success, and -1 on error.
84static int __inline__ qemu_pipe_frame_send(int fd, 86int qemu_pipe_frame_send(int fd, const void* buff, size_t len) {
85 const void* buff,
86 size_t len) {
87 char header[5]; 87 char header[5];
88 snprintf(header, sizeof(header), "%04zx", len); 88 snprintf(header, sizeof(header), "%04zx", len);
89 ssize_t ret = TEMP_FAILURE_RETRY(write(fd, header, 4)); 89 ssize_t ret = TEMP_FAILURE_RETRY(write(fd, header, 4));
@@ -104,7 +104,7 @@ static int __inline__ qemu_pipe_frame_send(int fd,
104// content is lost. Otherwise, this returns the size of the message. NOTE: 104// content is lost. Otherwise, this returns the size of the message. NOTE:
105// empty messages are possible in a framed wire protocol and do not mean 105// empty messages are possible in a framed wire protocol and do not mean
106// end-of-stream. 106// end-of-stream.
107static int __inline__ qemu_pipe_frame_recv(int fd, void* buff, size_t len) { 107int qemu_pipe_frame_recv(int fd, void* buff, size_t len) {
108 char header[5]; 108 char header[5];
109 ssize_t ret = TEMP_FAILURE_RETRY(read(fd, header, 4)); 109 ssize_t ret = TEMP_FAILURE_RETRY(read(fd, header, 4));
110 if (ret != 4) { 110 if (ret != 4) {
@@ -130,5 +130,3 @@ static int __inline__ qemu_pipe_frame_recv(int fd, void* buff, size_t len) {
130 } 130 }
131 return size; 131 return size;
132} 132}
133
134#endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_PIPE_H */