127 |
packet->buf = 0; |
packet->buf = 0; |
128 |
packet->buf_len = 0; |
packet->buf_len = 0; |
129 |
packet->ports = 0; |
packet->ports = 0; |
130 |
packet->num_ports = packet->ports_alloced = 0; |
packet->ports_alloced = 0; |
|
packet->buf_start = packet->buf_end = packet->buf; |
|
131 |
packet->buf_vm_alloced = 0; |
packet->buf_vm_alloced = 0; |
132 |
} |
} |
133 |
else |
else |
134 |
pq->free = packet->next; |
pq->free = packet->next; |
135 |
|
|
136 |
|
packet->num_ports = 0; |
137 |
|
packet->buf_start = packet->buf_end = packet->buf; |
138 |
|
|
139 |
packet->type = type; |
packet->type = type; |
140 |
packet->source = source; |
packet->source = source; |
141 |
packet->next = 0; |
packet->next = 0; |
297 |
packet_dealloc_ports (packet); |
packet_dealloc_ports (packet); |
298 |
if (num_ports > packet->ports_alloced) |
if (num_ports > packet->ports_alloced) |
299 |
{ |
{ |
300 |
mach_port_t *new_ports = malloc (sizeof (mach_port_t *) * num_ports); |
mach_port_t *new_ports = malloc (sizeof (mach_port_t) * num_ports); |
301 |
if (! new_ports) |
if (! new_ports) |
302 |
return ENOMEM; |
return ENOMEM; |
303 |
free (packet->ports); |
free (packet->ports); |
304 |
|
packet->ports = new_ports; |
305 |
packet->ports_alloced = num_ports; |
packet->ports_alloced = num_ports; |
306 |
} |
} |
307 |
bcopy (ports, packet->ports, sizeof (mach_port_t *) * num_ports); |
bcopy (ports, packet->ports, sizeof (mach_port_t) * num_ports); |
308 |
packet->num_ports = num_ports; |
packet->num_ports = num_ports; |
309 |
return 0; |
return 0; |
310 |
} |
} |
315 |
packet_read_ports (struct packet *packet, |
packet_read_ports (struct packet *packet, |
316 |
mach_port_t **ports, size_t *num_ports) |
mach_port_t **ports, size_t *num_ports) |
317 |
{ |
{ |
318 |
int length = packet->num_ports * sizeof (mach_port_t *); |
int length = packet->num_ports * sizeof (mach_port_t); |
319 |
if (*num_ports < packet->num_ports) |
if (*num_ports < packet->num_ports) |
320 |
{ |
{ |
321 |
*ports = mmap (0, length, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); |
*ports = mmap (0, length, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); |