Changes in uspace/lib/packet/generic/packet_server.c [a649e73f:28a3e74] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/packet/generic/packet_server.c
ra649e73f r28a3e74 36 36 37 37 #include <packet_server.h> 38 #include <packet_local.h>39 38 40 39 #include <align.h> … … 42 41 #include <async.h> 43 42 #include <errno.h> 44 #include <err.h>45 43 #include <fibril_synch.h> 46 44 #include <unistd.h> 47 45 #include <sys/mman.h> 48 49 #include <ipc/ipc.h>50 46 #include <ipc/packet.h> 51 47 #include <ipc/net.h> 52 53 48 #include <net/packet.h> 54 49 #include <net/packet_header.h> … … 70 65 fibril_mutex_t lock; 71 66 /** Free packet queues. */ 72 packet_t free[FREE_QUEUES_COUNT];67 packet_t *free[FREE_QUEUES_COUNT]; 73 68 74 69 /** … … 104 99 }; 105 100 106 int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id)107 {108 if (!packet)109 return EINVAL;110 111 *packet = pm_find(packet_id);112 return (*packet) ? EOK : ENOENT;113 }114 115 101 /** Clears and initializes the packet according to the given dimensions. 116 102 * … … 123 109 */ 124 110 static void 125 packet_init(packet_t packet, size_t addr_len, size_t max_prefix,111 packet_init(packet_t *packet, size_t addr_len, size_t max_prefix, 126 112 size_t max_content, size_t max_suffix) 127 113 { 128 / / clear the packet content129 bzero(((void *) packet) + sizeof( struct packet),130 packet->length - sizeof( struct packet));131 132 / / clear the packet header114 /* Clear the packet content */ 115 bzero(((void *) packet) + sizeof(packet_t), 116 packet->length - sizeof(packet_t)); 117 118 /* Clear the packet header */ 133 119 packet->order = 0; 134 120 packet->metric = 0; … … 136 122 packet->next = 0; 137 123 packet->addr_len = 0; 138 packet->src_addr = sizeof( struct packet);124 packet->src_addr = sizeof(packet_t); 139 125 packet->dest_addr = packet->src_addr + addr_len; 140 126 packet->max_prefix = max_prefix; … … 145 131 146 132 /** Creates a new packet of dimensions at least as given. 147 *148 * Should be used only when the global data are locked.149 133 * 150 134 * @param[in] length The total length of the packet, including the header, … … 155 139 * @param[in] max_content The maximal content length in bytes. 156 140 * @param[in] max_suffix The maximal suffix length in bytes. 157 * @return sThe packet of dimensions at least as given.158 * @return sNULL if there is not enough memory left.159 */ 160 static packet_t 141 * @return The packet of dimensions at least as given. 142 * @return NULL if there is not enough memory left. 143 */ 144 static packet_t * 161 145 packet_create(size_t length, size_t addr_len, size_t max_prefix, 162 146 size_t max_content, size_t max_suffix) 163 147 { 164 ERROR_DECLARE; 165 166 packet_t packet; 167 168 // already locked 169 packet = (packet_t) mmap(NULL, length, PROTO_READ | PROTO_WRITE, 148 packet_t *packet; 149 int rc; 150 151 assert(fibril_mutex_is_locked(&ps_globals.lock)); 152 153 /* Already locked */ 154 packet = (packet_t *) mmap(NULL, length, PROTO_READ | PROTO_WRITE, 170 155 MAP_SHARED | MAP_ANONYMOUS, 0, 0); 171 156 if (packet == MAP_FAILED) … … 177 162 packet_init(packet, addr_len, max_prefix, max_content, max_suffix); 178 163 packet->magic_value = PACKET_MAGIC_VALUE; 179 if (ERROR_OCCURRED(pm_add(packet))) { 164 rc = pm_add(packet); 165 if (rc != EOK) { 180 166 munmap(packet, packet->length); 181 167 return NULL; … … 199 185 * @return NULL if there is not enough memory left. 200 186 */ 201 static packet_t 187 static packet_t * 202 188 packet_get_local(size_t addr_len, size_t max_prefix, size_t max_content, 203 189 size_t max_suffix) 204 190 { 205 size_t length = ALIGN_UP(sizeof( struct packet) + 2 * addr_len +191 size_t length = ALIGN_UP(sizeof(packet_t) + 2 * addr_len + 206 192 max_prefix + max_content + max_suffix, PAGE_SIZE); 207 193 208 194 fibril_mutex_lock(&ps_globals.lock); 209 195 210 packet_t packet;196 packet_t *packet; 211 197 unsigned int index; 212 198 213 199 for (index = 0; index < FREE_QUEUES_COUNT; index++) { 214 if (length > ps_globals.sizes[index]) 200 if ((length > ps_globals.sizes[index]) && 201 (index < FREE_QUEUES_COUNT - 1)) 215 202 continue; 216 203 … … 241 228 } 242 229 243 packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len,244 size_t max_prefix, size_t max_suffix)245 {246 return packet_get_local(addr_len, max_prefix, max_content, max_suffix);247 }248 249 packet_t packet_get_1_local(int phone, size_t content)250 {251 return packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content,252 DEFAULT_SUFFIX);253 }254 255 230 /** Release the packet and returns it to the appropriate free packet queue. 256 231 * 257 * Should be used only when the global data are locked.258 *259 232 * @param[in] packet The packet to be released. 260 233 * 261 234 */ 262 static void packet_release(packet_t packet)235 static void packet_release(packet_t *packet) 263 236 { 264 237 int index; 265 238 int result; 239 240 assert(fibril_mutex_is_locked(&ps_globals.lock)); 266 241 267 242 for (index = 0; (index < FREE_QUEUES_COUNT - 1) && … … 278 253 * 279 254 * @param[in] packet_id The first packet identifier. 280 * @return sEOK on success.281 * @return sENOENT if there is no such packet.255 * @return EOK on success. 256 * @return ENOENT if there is no such packet. 282 257 */ 283 258 static int packet_release_wrapper(packet_id_t packet_id) 284 259 { 285 packet_t packet;260 packet_t *packet; 286 261 287 262 packet = pm_find(packet_id); … … 296 271 } 297 272 298 void pq_release_local(int phone, packet_id_t packet_id)299 {300 (void) packet_release_wrapper(packet_id);301 }302 303 273 /** Shares the packet memory block. 304 274 * @param[in] packet The packet to be shared. 305 * @return sEOK on success.306 * @return sEINVAL if the packet is not valid.307 * @return sEINVAL if the calling module does not accept the memory.308 * @return sENOMEM if the desired and actual sizes differ.309 * @return sOther error codes as defined for the275 * @return EOK on success. 276 * @return EINVAL if the packet is not valid. 277 * @return EINVAL if the calling module does not accept the memory. 278 * @return ENOMEM if the desired and actual sizes differ. 279 * @return Other error codes as defined for the 310 280 * async_share_in_finalize() function. 311 281 */ 312 static int packet_reply( const packet_tpacket)282 static int packet_reply(packet_t *packet) 313 283 { 314 284 ipc_callid_t callid; … … 319 289 320 290 if (!async_share_in_receive(&callid, &size)) { 321 ipc_answer_0(callid, EINVAL);291 async_answer_0(callid, EINVAL); 322 292 return EINVAL; 323 293 } 324 294 325 295 if (size != packet->length) { 326 ipc_answer_0(callid, ENOMEM);296 async_answer_0(callid, ENOMEM); 327 297 return ENOMEM; 328 298 } … … 339 309 * @param[out] answer_count The last parameter for the actual answer in the 340 310 * answer parameter. 341 * @return sEOK on success.342 * @return sENOMEM if there is not enough memory left.343 * @return sENOENT if there is no such packet as in the packet311 * @return EOK on success. 312 * @return ENOMEM if there is not enough memory left. 313 * @return ENOENT if there is no such packet as in the packet 344 314 * message parameter. 345 * @return sENOTSUP if the message is not known.346 * @return sOther error codes as defined for the315 * @return ENOTSUP if the message is not known. 316 * @return Other error codes as defined for the 347 317 * packet_release_wrapper() function. 348 318 */ 349 319 int 350 320 packet_server_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer, 351 int *answer_count)352 { 353 packet_t packet;321 size_t *answer_count) 322 { 323 packet_t *packet; 354 324 355 325 *answer_count = 0; 356 switch (IPC_GET_ METHOD(*call)) {326 switch (IPC_GET_IMETHOD(*call)) { 357 327 case IPC_M_PHONE_HUNGUP: 358 328 return EOK; … … 360 330 case NET_PACKET_CREATE_1: 361 331 packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, 362 IPC_GET_CONTENT( call), DEFAULT_SUFFIX);332 IPC_GET_CONTENT(*call), DEFAULT_SUFFIX); 363 333 if (!packet) 364 334 return ENOMEM; 365 335 *answer_count = 2; 366 IPC_SET_ARG1(*answer, ( ipcarg_t) packet->packet_id);367 IPC_SET_ARG2(*answer, ( ipcarg_t) packet->length);336 IPC_SET_ARG1(*answer, (sysarg_t) packet->packet_id); 337 IPC_SET_ARG2(*answer, (sysarg_t) packet->length); 368 338 return EOK; 369 339 370 340 case NET_PACKET_CREATE_4: 371 341 packet = packet_get_local( 372 ((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN( call)) ?373 IPC_GET_ADDR_LEN( call) : DEFAULT_ADDR_LEN),374 DEFAULT_PREFIX + IPC_GET_PREFIX( call),375 IPC_GET_CONTENT( call),376 DEFAULT_SUFFIX + IPC_GET_SUFFIX( call));342 ((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(*call)) ? 343 IPC_GET_ADDR_LEN(*call) : DEFAULT_ADDR_LEN), 344 DEFAULT_PREFIX + IPC_GET_PREFIX(*call), 345 IPC_GET_CONTENT(*call), 346 DEFAULT_SUFFIX + IPC_GET_SUFFIX(*call)); 377 347 if (!packet) 378 348 return ENOMEM; 379 349 *answer_count = 2; 380 IPC_SET_ARG1(*answer, ( ipcarg_t) packet->packet_id);381 IPC_SET_ARG2(*answer, ( ipcarg_t) packet->length);350 IPC_SET_ARG1(*answer, (sysarg_t) packet->packet_id); 351 IPC_SET_ARG2(*answer, (sysarg_t) packet->length); 382 352 return EOK; 383 353 384 354 case NET_PACKET_GET: 385 packet = pm_find(IPC_GET_ID( call));355 packet = pm_find(IPC_GET_ID(*call)); 386 356 if (!packet_is_valid(packet)) 387 357 return ENOENT; … … 389 359 390 360 case NET_PACKET_GET_SIZE: 391 packet = pm_find(IPC_GET_ID( call));361 packet = pm_find(IPC_GET_ID(*call)); 392 362 if (!packet_is_valid(packet)) 393 363 return ENOENT; 394 IPC_SET_ARG1(*answer, ( ipcarg_t) packet->length);364 IPC_SET_ARG1(*answer, (sysarg_t) packet->length); 395 365 *answer_count = 1; 396 366 return EOK; 397 367 398 368 case NET_PACKET_RELEASE: 399 return packet_release_wrapper(IPC_GET_ID( call));369 return packet_release_wrapper(IPC_GET_ID(*call)); 400 370 } 401 371
Note:
See TracChangeset
for help on using the changeset viewer.