Rev 3912 | Rev 4192 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3912 | Rev 3914 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup packet |
29 | /** @addtogroup packet |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * Packet server implementation. |
34 | * Packet server implementation. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <async.h> |
- | |
38 | #include <align.h> |
37 | #include <align.h> |
- | 38 | #include <async.h> |
|
39 | #include <errno.h> |
39 | #include <errno.h> |
- | 40 | #include <futex.h> |
|
40 | //#include <stdio.h> |
41 | //#include <stdio.h> |
41 | #include <unistd.h> |
42 | #include <unistd.h> |
42 | 43 | ||
43 | #include <ipc/ipc.h> |
44 | #include <ipc/ipc.h> |
44 | #include <ipc/services.h> |
45 | #include <ipc/services.h> |
45 | #include <sys/mman.h> |
46 | #include <sys/mman.h> |
46 | 47 | ||
47 | #include "../../err.h" |
48 | #include "../../err.h" |
48 | #include "../../messages.h" |
49 | #include "../../messages.h" |
49 | 50 | ||
50 | #include "packet.h" |
51 | #include "packet.h" |
51 | #include "packet_header.h" |
52 | #include "packet_header.h" |
52 | #include "packet_server.h" |
53 | #include "packet_server.h" |
53 | 54 | ||
54 | /** Returns the packet identifier message parameter. |
55 | /** Returns the packet identifier message parameter. |
55 | */ |
56 | */ |
56 | #define IPC_GET_ID( call ) ( packet_id_t ) IPC_GET_ARG1( * call ) |
57 | #define IPC_GET_ID( call ) ( packet_id_t ) IPC_GET_ARG1( * call ) |
57 | 58 | ||
58 | /** Returns the owner message parameter. |
59 | /** Returns the owner message parameter. |
59 | */ |
60 | */ |
60 | #define IPC_GET_OWNER( call ) ( services_t ) IPC_GET_ARG1( * call ) |
61 | #define IPC_GET_OWNER( call ) ( services_t ) IPC_GET_ARG1( * call ) |
61 | 62 | ||
62 | /** Returns the maximal content length message parameter. |
63 | /** Returns the maximal content length message parameter. |
63 | */ |
64 | */ |
64 | #define IPC_GET_CONTENT( call ) ( size_t ) IPC_GET_ARG2( * call ) |
65 | #define IPC_GET_CONTENT( call ) ( size_t ) IPC_GET_ARG2( * call ) |
65 | 66 | ||
66 | /** Returns the maximal address length message parameter. |
67 | /** Returns the maximal address length message parameter. |
67 | */ |
68 | */ |
68 | #define IPC_GET_ADDR_LEN( call ) ( size_t ) IPC_GET_ARG3( * call ) |
69 | #define IPC_GET_ADDR_LEN( call ) ( size_t ) IPC_GET_ARG3( * call ) |
69 | 70 | ||
70 | /** Returns the maximal prefix length message parameter. |
71 | /** Returns the maximal prefix length message parameter. |
71 | */ |
72 | */ |
72 | #define IPC_GET_PREFIX( call ) ( size_t ) IPC_GET_ARG4( * call ) |
73 | #define IPC_GET_PREFIX( call ) ( size_t ) IPC_GET_ARG4( * call ) |
73 | 74 | ||
74 | /** Returns the maximal suffix length message parameter. |
75 | /** Returns the maximal suffix length message parameter. |
75 | */ |
76 | */ |
76 | #define IPC_GET_SUFIX( call ) ( size_t ) IPC_GET_ARG5( * call ) |
77 | #define IPC_GET_SUFIX( call ) ( size_t ) IPC_GET_ARG5( * call ) |
77 | 78 | ||
78 | #define FREE_QUEUES_COUNT 7 |
79 | #define FREE_QUEUES_COUNT 7 |
79 | 80 | ||
80 | /** Packet server global data. |
81 | /** Packet server global data. |
81 | */ |
82 | */ |
82 | static struct{ |
83 | static struct{ |
- | 84 | /** Safety lock. |
|
- | 85 | */ |
|
- | 86 | futex_t lock; |
|
83 | /** Free packet queues. |
87 | /** Free packet queues. |
84 | */ |
88 | */ |
85 | packet_t free[ FREE_QUEUES_COUNT ]; |
89 | packet_t free[ FREE_QUEUES_COUNT ]; |
86 | /** Packet length upper bounds of the free packet queues. |
90 | /** Packet length upper bounds of the free packet queues. |
87 | * The maximal lengths of packets in each queue in the ascending order. |
91 | * The maximal lengths of packets in each queue in the ascending order. |
88 | * The last queue is not limited. |
92 | * The last queue is not limited. |
89 | */ |
93 | */ |
90 | int sizes[ FREE_QUEUES_COUNT ]; |
94 | int sizes[ FREE_QUEUES_COUNT ]; |
91 | /** Total packets allocated. |
95 | /** Total packets allocated. |
92 | */ |
96 | */ |
93 | unsigned int count; |
97 | unsigned int count; |
94 | } ps_globals = { |
98 | } ps_globals = { |
- | 99 | { 1 }, |
|
95 | { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, |
100 | { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, |
96 | { PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 4, PAGE_SIZE * 8, PAGE_SIZE * 16, PAGE_SIZE * 32, PAGE_SIZE * 64 }, |
101 | { PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 4, PAGE_SIZE * 8, PAGE_SIZE * 16, PAGE_SIZE * 32, PAGE_SIZE * 64 }, |
97 | 0 |
102 | 0 |
98 | }; |
103 | }; |
99 | 104 | ||
100 | /** Releases the packet and returns it to the appropriate free packet queue. |
105 | /** Releases the packet and returns it to the appropriate free packet queue. |
- | 106 | * Should be used only when the global data are locked. |
|
101 | * @param packet The packet to be released. Input parameter. |
107 | * @param packet The packet to be released. Input parameter. |
102 | */ |
108 | */ |
103 | void packet_release( packet_t packet ); |
109 | void packet_release( packet_t packet ); |
104 | 110 | ||
105 | /** Returns the packet of dimensions at least as given. |
111 | /** Returns the packet of dimensions at least as given. |
106 | * Tries to reuse free packets first. |
112 | * Tries to reuse free packets first. |
107 | * Creates a new packet aligned to the memory page size if none available. |
113 | * Creates a new packet aligned to the memory page size if none available. |
- | 114 | * Locks the global data during its processing. |
|
108 | * @param owner The new owner of the packet. Input parameter. |
115 | * @param owner The new owner of the packet. Input parameter. |
109 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
116 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
110 | * @param max_prefix The maximal prefix length in bytes. Input parameter. |
117 | * @param max_prefix The maximal prefix length in bytes. Input parameter. |
111 | * @param max_content The maximal content length in bytes. Input parameter. |
118 | * @param max_content The maximal content length in bytes. Input parameter. |
112 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
119 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
113 | * @returns The packet of dimensions at least as given. |
120 | * @returns The packet of dimensions at least as given. |
114 | * @returns NULL if there is not enough memory left. |
121 | * @returns NULL if there is not enough memory left. |
115 | */ |
122 | */ |
116 | packet_t packet_get( services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ); |
123 | packet_t packet_get( services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ); |
117 | 124 | ||
118 | /** Creates a new packet of dimensions at least as given. |
125 | /** Creates a new packet of dimensions at least as given. |
- | 126 | * Should be used only when the global data are locked. |
|
119 | * @param length The total length of the packet, including the header, the addresses and the data of the packet. Input parameter. |
127 | * @param length The total length of the packet, including the header, the addresses and the data of the packet. Input parameter. |
120 | * @param owner The new owner of the packet. Input parameter. |
128 | * @param owner The new owner of the packet. Input parameter. |
121 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
129 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
122 | * @param max_prefix The maximal prefix length in bytes. Input parameter. |
130 | * @param max_prefix The maximal prefix length in bytes. Input parameter. |
123 | * @param max_content The maximal content length in bytes. Input parameter. |
131 | * @param max_content The maximal content length in bytes. Input parameter. |
124 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
132 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
125 | * @returns The packet of dimensions at least as given. |
133 | * @returns The packet of dimensions at least as given. |
126 | * @returns NULL if there is not enough memory left. |
134 | * @returns NULL if there is not enough memory left. |
127 | */ |
135 | */ |
128 | packet_t packet_create( size_t length, services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ); |
136 | packet_t packet_create( size_t length, services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ); |
129 | 137 | ||
130 | /** Initializes the packet according to the given dimensions. |
138 | /** Initializes the packet according to the given dimensions. |
131 | * @param packet The packet to be initialized. Input parameter. |
139 | * @param packet The packet to be initialized. Input parameter. |
132 | * @param owner The new owner of the packet. Input parameter. |
140 | * @param owner The new owner of the packet. Input parameter. |
133 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
141 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
134 | * @param max_prefix The maximal prefix length in bytes. Input parameter. |
142 | * @param max_prefix The maximal prefix length in bytes. Input parameter. |
135 | * @param max_content The maximal content length in bytes. Input parameter. |
143 | * @param max_content The maximal content length in bytes. Input parameter. |
136 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
144 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
137 | */ |
145 | */ |
138 | void packet_init( packet_t packet, services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ); |
146 | void packet_init( packet_t packet, services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ); |
139 | 147 | ||
140 | /** Shares the packet memory block. |
148 | /** Shares the packet memory block. |
141 | * @param packet The packet to be shared. |
149 | * @param packet The packet to be shared. |
142 | * @returns EOK on success. |
150 | * @returns EOK on success. |
143 | * @returns EINVAL if the packet is not valid. |
151 | * @returns EINVAL if the packet is not valid. |
144 | * @returns EINVAL if the calling module does not accept the memory. |
152 | * @returns EINVAL if the calling module does not accept the memory. |
145 | * @returns ENOMEM if the desired and actual sizes differ. |
153 | * @returns ENOMEM if the desired and actual sizes differ. |
146 | * @returns Other error codes as defined for the ipc_share_in_finalize() function. |
154 | * @returns Other error codes as defined for the ipc_share_in_finalize() function. |
147 | */ |
155 | */ |
148 | int packet_reply( const packet_t packet ); |
156 | int packet_reply( const packet_t packet ); |
149 | 157 | ||
150 | int packet_server_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
158 | int packet_server_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
151 | packet_t packet; |
159 | packet_t packet; |
152 | 160 | ||
153 | * answer_count = 0; |
161 | * answer_count = 0; |
154 | switch( IPC_GET_METHOD( * call )){ |
162 | switch( IPC_GET_METHOD( * call )){ |
155 | case IPC_M_PHONE_HUNGUP: |
163 | case IPC_M_PHONE_HUNGUP: |
156 | return EOK; |
164 | return EOK; |
157 | case NET_PACKET_CREATE_1: |
165 | case NET_PACKET_CREATE_1: |
158 | packet = packet_get( IPC_GET_OWNER( call ), 0, 0, IPC_GET_CONTENT( call ), 0 ); |
166 | packet = packet_get( IPC_GET_OWNER( call ), 0, 0, IPC_GET_CONTENT( call ), 0 ); |
159 | if( ! packet ) return ENOMEM; |
167 | if( ! packet ) return ENOMEM; |
160 | * answer_count = 2; |
168 | * answer_count = 2; |
161 | IPC_SET_ARG1( * answer, packet->packet_id ); |
169 | IPC_SET_ARG1( * answer, packet->packet_id ); |
162 | IPC_SET_ARG2( * answer, packet->length ); |
170 | IPC_SET_ARG2( * answer, packet->length ); |
163 | return EOK; |
171 | return EOK; |
164 | case NET_PACKET_CREATE_5: |
172 | case NET_PACKET_CREATE_5: |
165 | packet = packet_get( IPC_GET_OWNER( call ), IPC_GET_ADDR_LEN( call ), IPC_GET_PREFIX( call ), IPC_GET_CONTENT( call ), IPC_GET_SUFIX( call )); |
173 | packet = packet_get( IPC_GET_OWNER( call ), IPC_GET_ADDR_LEN( call ), IPC_GET_PREFIX( call ), IPC_GET_CONTENT( call ), IPC_GET_SUFIX( call )); |
166 | if( ! packet ) return ENOMEM; |
174 | if( ! packet ) return ENOMEM; |
167 | * answer_count = 2; |
175 | * answer_count = 2; |
168 | IPC_SET_ARG1( * answer, packet->packet_id ); |
176 | IPC_SET_ARG1( * answer, packet->packet_id ); |
169 | IPC_SET_ARG2( * answer, packet->length ); |
177 | IPC_SET_ARG2( * answer, packet->length ); |
170 | return EOK; |
178 | return EOK; |
171 | case NET_PACKET_GET: |
179 | case NET_PACKET_GET: |
172 | packet = pm_find( IPC_GET_ID( call )); |
180 | packet = pm_find( IPC_GET_ID( call )); |
173 | if( ! packet_is_valid( packet )) return ENOENT; |
181 | if( ! packet_is_valid( packet )) return ENOENT; |
174 | return packet_reply( packet ); |
182 | return packet_reply( packet ); |
175 | case NET_PACKET_GET_SIZE: |
183 | case NET_PACKET_GET_SIZE: |
176 | packet = pm_find( IPC_GET_ID( call )); |
184 | packet = pm_find( IPC_GET_ID( call )); |
177 | if( ! packet_is_valid( packet )) return ENOENT; |
185 | if( ! packet_is_valid( packet )) return ENOENT; |
178 | * answer_count = 1; |
186 | * answer_count = 1; |
179 | IPC_SET_ARG1( * answer, packet->length ); |
187 | IPC_SET_ARG1( * answer, packet->length ); |
180 | return EOK; |
188 | return EOK; |
181 | case NET_PACKET_RELEASE: |
189 | case NET_PACKET_RELEASE: |
182 | packet = pm_find( IPC_GET_ID( call )); |
190 | packet = pm_find( IPC_GET_ID( call )); |
183 | if( ! packet_is_valid( packet )) return ENOENT; |
191 | if( ! packet_is_valid( packet )) return ENOENT; |
- | 192 | futex_down( & ps_globals.lock ); |
|
184 | pq_destroy( packet, packet_release ); |
193 | pq_destroy( packet, packet_release ); |
- | 194 | futex_up( & ps_globals.lock ); |
|
185 | return EOK; |
195 | return EOK; |
186 | } |
196 | } |
187 | return ENOTSUP; |
197 | return ENOTSUP; |
188 | } |
198 | } |
189 | 199 | ||
190 | void packet_release( packet_t packet ){ |
200 | void packet_release( packet_t packet ){ |
191 | int index; |
201 | int index; |
192 | 202 | ||
193 | for( index = 0; ( index < FREE_QUEUES_COUNT - 1 ) && ( packet->length > ps_globals.sizes[ index ] ); ++ index ); |
203 | for( index = 0; ( index < FREE_QUEUES_COUNT - 1 ) && ( packet->length > ps_globals.sizes[ index ] ); ++ index ); |
194 | ps_globals.free[ index ] = pq_add( ps_globals.free[ index ], packet, packet->length, packet->length ); |
204 | ps_globals.free[ index ] = pq_add( ps_globals.free[ index ], packet, packet->length, packet->length ); |
195 | } |
205 | } |
196 | 206 | ||
197 | packet_t packet_get( services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |
207 | packet_t packet_get( services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |
198 | int index; |
208 | int index; |
199 | packet_t packet; |
209 | packet_t packet; |
200 | size_t length; |
210 | size_t length; |
201 | 211 | ||
202 | length = ALIGN_UP( sizeof( struct packet ) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE ); |
212 | length = ALIGN_UP( sizeof( struct packet ) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE ); |
- | 213 | futex_down( & ps_globals.lock ); |
|
203 | for( index = 0; index < FREE_QUEUES_COUNT - 1; ++ index ){ |
214 | for( index = 0; index < FREE_QUEUES_COUNT - 1; ++ index ){ |
204 | if( length <= ps_globals.sizes[ index ] ){ |
215 | if( length <= ps_globals.sizes[ index ] ){ |
205 | packet = ps_globals.free[ index ]; |
216 | packet = ps_globals.free[ index ]; |
206 | while( packet_is_valid( packet ) && ( packet->length < length )){ |
217 | while( packet_is_valid( packet ) && ( packet->length < length )){ |
207 | packet = pm_find( packet->next ); |
218 | packet = pm_find( packet->next ); |
208 | } |
219 | } |
209 | if( packet ){ |
220 | if( packet ){ |
210 | packet_init( packet, owner, addr_len, max_prefix, max_content, max_suffix ); |
221 | packet_init( packet, owner, addr_len, max_prefix, max_content, max_suffix ); |
- | 222 | futex_up( & ps_globals.lock ); |
|
211 | return packet; |
223 | return packet; |
212 | } |
224 | } |
213 | } |
225 | } |
214 | } |
226 | } |
215 | return packet_create( length, owner, addr_len, max_prefix, max_content, max_suffix ); |
227 | packet = packet_create( length, owner, addr_len, max_prefix, max_content, max_suffix ); |
- | 228 | futex_up( & ps_globals.lock ); |
|
- | 229 | return packet; |
|
216 | } |
230 | } |
217 | 231 | ||
218 | packet_t packet_create( size_t length, services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |
232 | packet_t packet_create( size_t length, services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |
219 | ERROR_DECLARE; |
233 | ERROR_DECLARE; |
220 | 234 | ||
221 | packet_t packet; |
235 | packet_t packet; |
222 | 236 | ||
- | 237 | // already locked |
|
223 | packet = ( packet_t ) mmap( NULL, length, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0 ); |
238 | packet = ( packet_t ) mmap( NULL, length, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0 ); |
224 | if( packet == MAP_FAILED ) return NULL; |
239 | if( packet == MAP_FAILED ) return NULL; |
225 | ++ ps_globals.count; |
240 | ++ ps_globals.count; |
226 | packet->packet_id = ps_globals.count; |
241 | packet->packet_id = ps_globals.count; |
227 | packet->mode = PM_ONE_WAY; |
242 | packet->mode = PM_ONE_WAY; |
228 | packet->length = length; |
243 | packet->length = length; |
229 | packet_init( packet, owner, addr_len, max_prefix, max_content, max_suffix ); |
244 | packet_init( packet, owner, addr_len, max_prefix, max_content, max_suffix ); |
230 | packet->magic_value = PACKET_MAGIC_VALUE; |
245 | packet->magic_value = PACKET_MAGIC_VALUE; |
231 | if( ERROR_OCCURRED( pm_add( packet ))){ |
246 | if( ERROR_OCCURRED( pm_add( packet ))){ |
232 | munmap( packet, packet->length ); |
247 | munmap( packet, packet->length ); |
233 | return NULL; |
248 | return NULL; |
234 | } |
249 | } |
235 | packet_release( packet ); |
250 | packet_release( packet ); |
236 | return packet; |
251 | return packet; |
237 | } |
252 | } |
238 | 253 | ||
239 | void packet_init( packet_t packet, services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |
254 | void packet_init( packet_t packet, services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |
240 | packet->owner = owner; |
255 | packet->owner = owner; |
241 | packet->order = 0; |
256 | packet->order = 0; |
242 | packet->metric = 0; |
257 | packet->metric = 0; |
243 | packet->previous = 0; |
258 | packet->previous = 0; |
244 | packet->next = 0; |
259 | packet->next = 0; |
245 | packet->addr_len = addr_len; |
260 | packet->addr_len = addr_len; |
246 | packet->src_addr = sizeof( struct packet ); |
261 | packet->src_addr = sizeof( struct packet ); |
247 | packet->dest_addr = packet->src_addr + packet->addr_len; |
262 | packet->dest_addr = packet->src_addr + packet->addr_len; |
248 | packet->max_prefix = max_prefix; |
263 | packet->max_prefix = max_prefix; |
249 | packet->max_content = max_content; |
264 | packet->max_content = max_content; |
250 | packet->data_start = packet->dest_addr + packet->addr_len + packet->max_prefix; |
265 | packet->data_start = packet->dest_addr + packet->addr_len + packet->max_prefix; |
251 | packet->data_end = packet->data_start; |
266 | packet->data_end = packet->data_start; |
252 | } |
267 | } |
253 | 268 | ||
254 | int packet_reply( const packet_t packet ){ |
269 | int packet_reply( const packet_t packet ){ |
255 | ipc_callid_t callid; |
270 | ipc_callid_t callid; |
256 | size_t size; |
271 | size_t size; |
257 | 272 | ||
258 | if( ! packet_is_valid( packet )) return EINVAL; |
273 | if( ! packet_is_valid( packet )) return EINVAL; |
259 | if( ipc_share_in_receive( & callid, & size ) <= 0 ) return EINVAL; |
274 | if( ipc_share_in_receive( & callid, & size ) <= 0 ) return EINVAL; |
260 | if( size != packet->length ) return ENOMEM; |
275 | if( size != packet->length ) return ENOMEM; |
261 | return ipc_share_in_finalize( callid, packet, PROTO_READ | PROTO_WRITE ); |
276 | return ipc_share_in_finalize( callid, packet, PROTO_READ | PROTO_WRITE ); |
262 | } |
277 | } |
263 | 278 | ||
264 | /** @} |
279 | /** @} |
265 | */ |
280 | */ |
266 | 281 |