[1edd6d0] | 1 | /*
|
---|
| 2 | * Copyright (c) 2018 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libc
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file IPC test service API
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <abi/ipc/interfaces.h>
|
---|
[3b3fcf36] | 36 | #include <as.h>
|
---|
[1edd6d0] | 37 | #include <errno.h>
|
---|
| 38 | #include <ipc/services.h>
|
---|
| 39 | #include <ipc/ipc_test.h>
|
---|
| 40 | #include <loc.h>
|
---|
| 41 | #include <stdlib.h>
|
---|
| 42 | #include <ipc_test.h>
|
---|
| 43 |
|
---|
| 44 | /** Create IPC test service session.
|
---|
| 45 | *
|
---|
| 46 | * @param rvol Place to store pointer to volume service session.
|
---|
| 47 | * @return EOK on success, ENOMEM if out of memory, EIO if service
|
---|
| 48 | * cannot be contacted.
|
---|
| 49 | */
|
---|
| 50 | errno_t ipc_test_create(ipc_test_t **rtest)
|
---|
| 51 | {
|
---|
| 52 | ipc_test_t *test;
|
---|
| 53 | service_id_t test_svcid;
|
---|
| 54 | errno_t rc;
|
---|
| 55 |
|
---|
| 56 | test = calloc(1, sizeof(ipc_test_t));
|
---|
| 57 | if (test == NULL) {
|
---|
| 58 | rc = ENOMEM;
|
---|
| 59 | goto error;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | rc = loc_service_get_id(SERVICE_NAME_IPC_TEST, &test_svcid, 0);
|
---|
| 63 | if (rc != EOK) {
|
---|
| 64 | rc = ENOENT;
|
---|
| 65 | goto error;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | test->sess = loc_service_connect(test_svcid, INTERFACE_IPC_TEST, 0);
|
---|
| 69 | if (test->sess == NULL) {
|
---|
| 70 | rc = EIO;
|
---|
| 71 | goto error;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | *rtest = test;
|
---|
| 75 | return EOK;
|
---|
| 76 | error:
|
---|
| 77 | free(test);
|
---|
| 78 | return rc;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | /** Destroy IPC test service session.
|
---|
| 82 | *
|
---|
| 83 | * @param test IPC test service session
|
---|
| 84 | */
|
---|
| 85 | void ipc_test_destroy(ipc_test_t *test)
|
---|
| 86 | {
|
---|
| 87 | if (test == NULL)
|
---|
| 88 | return;
|
---|
| 89 |
|
---|
| 90 | async_hangup(test->sess);
|
---|
| 91 | free(test);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | /** Simple ping.
|
---|
| 95 | *
|
---|
| 96 | * @param test IPC test service
|
---|
| 97 | * @return EOK on success or an error code
|
---|
| 98 | */
|
---|
| 99 | errno_t ipc_test_ping(ipc_test_t *test)
|
---|
| 100 | {
|
---|
| 101 | async_exch_t *exch;
|
---|
| 102 | errno_t retval;
|
---|
| 103 |
|
---|
| 104 | exch = async_exchange_begin(test->sess);
|
---|
| 105 | retval = async_req_0_0(exch, IPC_TEST_PING);
|
---|
| 106 | async_exchange_end(exch);
|
---|
| 107 |
|
---|
| 108 | if (retval != EOK)
|
---|
| 109 | return retval;
|
---|
| 110 |
|
---|
| 111 | return EOK;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[3b3fcf36] | 114 | /** Get size of shared read-only memory area.
|
---|
| 115 | *
|
---|
| 116 | * @param test IPC test service
|
---|
| 117 | * @param rsize Place to store size of the shared area
|
---|
| 118 | * @return EOK on success or an error code
|
---|
| 119 | */
|
---|
| 120 | errno_t ipc_test_get_ro_area_size(ipc_test_t *test, size_t *rsize)
|
---|
| 121 | {
|
---|
| 122 | async_exch_t *exch;
|
---|
| 123 | errno_t retval;
|
---|
| 124 | sysarg_t size;
|
---|
| 125 |
|
---|
| 126 | exch = async_exchange_begin(test->sess);
|
---|
| 127 | retval = async_req_0_1(exch, IPC_TEST_GET_RO_AREA_SIZE, &size);
|
---|
| 128 | async_exchange_end(exch);
|
---|
| 129 |
|
---|
| 130 | if (retval != EOK)
|
---|
| 131 | return retval;
|
---|
| 132 |
|
---|
| 133 | *rsize = size;
|
---|
| 134 | return EOK;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | /** Get size of shared read-write memory area.
|
---|
| 138 | *
|
---|
| 139 | * @param test IPC test service
|
---|
| 140 | * @param rsize Place to store size of the shared area
|
---|
| 141 | * @return EOK on success or an error code
|
---|
| 142 | */
|
---|
| 143 | errno_t ipc_test_get_rw_area_size(ipc_test_t *test, size_t *rsize)
|
---|
| 144 | {
|
---|
| 145 | async_exch_t *exch;
|
---|
| 146 | errno_t retval;
|
---|
| 147 | sysarg_t size;
|
---|
| 148 |
|
---|
| 149 | exch = async_exchange_begin(test->sess);
|
---|
| 150 | retval = async_req_0_1(exch, IPC_TEST_GET_RW_AREA_SIZE, &size);
|
---|
| 151 | async_exchange_end(exch);
|
---|
| 152 |
|
---|
| 153 | if (retval != EOK)
|
---|
| 154 | return retval;
|
---|
| 155 |
|
---|
| 156 | *rsize = size;
|
---|
| 157 | return EOK;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | /** Test share-in of read-only area.
|
---|
| 161 | *
|
---|
| 162 | * @param test IPC test service
|
---|
| 163 | * @param size Size of the shared area
|
---|
| 164 | * @param rptr Place to store pointer to the shared-in area
|
---|
| 165 | * @return EOK on success or an error code
|
---|
| 166 | */
|
---|
| 167 | errno_t ipc_test_share_in_ro(ipc_test_t *test, size_t size, const void **rptr)
|
---|
| 168 | {
|
---|
| 169 | async_exch_t *exch;
|
---|
| 170 | ipc_call_t answer;
|
---|
| 171 | aid_t req;
|
---|
| 172 | void *dst;
|
---|
| 173 | errno_t rc;
|
---|
| 174 |
|
---|
| 175 | exch = async_exchange_begin(test->sess);
|
---|
| 176 | req = async_send_0(exch, IPC_TEST_SHARE_IN_RO, &answer);
|
---|
| 177 |
|
---|
| 178 | dst = NULL;
|
---|
| 179 | rc = async_share_in_start_0_0(exch, size, &dst);
|
---|
| 180 | if (rc != EOK || dst == AS_MAP_FAILED) {
|
---|
| 181 | async_exchange_end(exch);
|
---|
| 182 | async_forget(req);
|
---|
| 183 | return ENOMEM;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | async_exchange_end(exch);
|
---|
| 187 | async_wait_for(req, NULL);
|
---|
| 188 | *rptr = dst;
|
---|
| 189 | return EOK;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /** Test share-in of read-write area.
|
---|
| 193 | *
|
---|
| 194 | * @param test IPC test service
|
---|
| 195 | * @param size Size of the shared area
|
---|
| 196 | * @param rptr Place to store pointer to the shared-in area
|
---|
| 197 | * @return EOK on success or an error code
|
---|
| 198 | */
|
---|
| 199 | errno_t ipc_test_share_in_rw(ipc_test_t *test, size_t size, void **rptr)
|
---|
| 200 | {
|
---|
| 201 | async_exch_t *exch;
|
---|
| 202 | ipc_call_t answer;
|
---|
| 203 | aid_t req;
|
---|
| 204 | void *dst;
|
---|
| 205 | errno_t rc;
|
---|
| 206 |
|
---|
| 207 | exch = async_exchange_begin(test->sess);
|
---|
| 208 | req = async_send_0(exch, IPC_TEST_SHARE_IN_RW, &answer);
|
---|
| 209 |
|
---|
| 210 | rc = async_share_in_start_0_0(exch, size, &dst);
|
---|
| 211 | if (rc != EOK || dst == AS_MAP_FAILED) {
|
---|
| 212 | async_exchange_end(exch);
|
---|
| 213 | async_forget(req);
|
---|
| 214 | return ENOMEM;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | async_exchange_end(exch);
|
---|
| 218 | async_wait_for(req, NULL);
|
---|
| 219 | *rptr = dst;
|
---|
| 220 | return EOK;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[1edd6d0] | 223 | /** @}
|
---|
| 224 | */
|
---|