Changeset 23558
- Timestamp:
- 03/18/08 14:32:54 (9 months ago)
- Files:
-
- 1 modified
-
trunk/launchd/src/liblaunch.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/launchd/src/liblaunch.c
r23556 r23558 67 67 extern void __OSBogusByteSwap__(void); 68 68 69 #define host2 big(x) \69 #define host2wire(x) \ 70 70 ({ typeof (x) _X, _x = (x); \ 71 71 switch (sizeof(_x)) { \ 72 72 case 8: \ 73 _X = OSSwapHostTo BigInt64(_x); \73 _X = OSSwapHostToLittleInt64(_x); \ 74 74 break; \ 75 75 case 4: \ 76 _X = OSSwapHostTo BigInt32(_x); \76 _X = OSSwapHostToLittleInt32(_x); \ 77 77 break; \ 78 78 case 2: \ 79 _X = OSSwapHostTo BigInt16(_x); \79 _X = OSSwapHostToLittleInt16(_x); \ 80 80 break; \ 81 81 case 1: \ … … 90 90 91 91 92 #define big2 host(x) \92 #define big2wire(x) \ 93 93 ({ typeof (x) _X, _x = (x); \ 94 94 switch (sizeof(_x)) { \ 95 95 case 8: \ 96 _X = OSSwap BigToHostInt64(_x); \96 _X = OSSwapLittleToHostInt64(_x); \ 97 97 break; \ 98 98 case 4: \ 99 _X = OSSwap BigToHostInt32(_x); \99 _X = OSSwapLittleToHostInt32(_x); \ 100 100 break; \ 101 101 case 2: \ 102 _X = OSSwap BigToHostInt16(_x); \102 _X = OSSwapLittleToHostInt16(_x); \ 103 103 break; \ 104 104 case 1: \ … … 613 613 where += total_data_len; 614 614 615 o_in_w->type = host2 big(d->type);615 o_in_w->type = host2wire(d->type); 616 616 617 617 switch (d->type) { 618 618 case LAUNCH_DATA_INTEGER: 619 o_in_w->number = host2 big(d->number);619 o_in_w->number = host2wire(d->number); 620 620 break; 621 621 case LAUNCH_DATA_REAL: 622 o_in_w->float_num = host2 big(d->float_num);622 o_in_w->float_num = host2wire(d->float_num); 623 623 break; 624 624 case LAUNCH_DATA_BOOL: 625 o_in_w->boolean = host2 big(d->boolean);625 o_in_w->boolean = host2wire(d->boolean); 626 626 break; 627 627 case LAUNCH_DATA_ERRNO: 628 o_in_w->err = host2 big(d->err);628 o_in_w->err = host2wire(d->err); 629 629 break; 630 630 case LAUNCH_DATA_FD: 631 o_in_w->fd = host2 big(d->fd);631 o_in_w->fd = host2wire(d->fd); 632 632 if (fd_where && d->fd != -1) { 633 633 fd_where[*fd_cnt] = d->fd; … … 636 636 break; 637 637 case LAUNCH_DATA_STRING: 638 o_in_w->string_len = host2 big(d->string_len);638 o_in_w->string_len = host2wire(d->string_len); 639 639 total_data_len += ROUND_TO_64BIT_WORD_SIZE(strlen(d->string) + 1); 640 640 if (total_data_len > len) { … … 644 644 break; 645 645 case LAUNCH_DATA_OPAQUE: 646 o_in_w->opaque_size = host2 big(d->opaque_size);646 o_in_w->opaque_size = host2wire(d->opaque_size); 647 647 total_data_len += ROUND_TO_64BIT_WORD_SIZE(d->opaque_size); 648 648 if (total_data_len > len) { … … 653 653 case LAUNCH_DATA_DICTIONARY: 654 654 case LAUNCH_DATA_ARRAY: 655 o_in_w->_array_cnt = host2 big(d->_array_cnt);655 o_in_w->_array_cnt = host2wire(d->_array_cnt); 656 656 total_data_len += d->_array_cnt * sizeof(uint64_t); 657 657 if (total_data_len > len) { … … 687 687 *data_offset += sizeof(struct _launch_data); 688 688 689 switch (big2 host(r->type)) {689 switch (big2wire(r->type)) { 690 690 case LAUNCH_DATA_DICTIONARY: 691 691 case LAUNCH_DATA_ARRAY: 692 tmpcnt = big2 host(r->_array_cnt);692 tmpcnt = big2wire(r->_array_cnt); 693 693 if ((data_size - *data_offset) < (tmpcnt * sizeof(uint64_t))) { 694 694 errno = EAGAIN; … … 705 705 break; 706 706 case LAUNCH_DATA_STRING: 707 tmpcnt = big2 host(r->string_len);707 tmpcnt = big2wire(r->string_len); 708 708 if ((data_size - *data_offset) < (tmpcnt + 1)) { 709 709 errno = EAGAIN; … … 715 715 break; 716 716 case LAUNCH_DATA_OPAQUE: 717 tmpcnt = big2 host(r->opaque_size);717 tmpcnt = big2wire(r->opaque_size); 718 718 if ((data_size - *data_offset) < tmpcnt) { 719 719 errno = EAGAIN; … … 731 731 break; 732 732 case LAUNCH_DATA_INTEGER: 733 r->number = big2 host(r->number);733 r->number = big2wire(r->number); 734 734 break; 735 735 case LAUNCH_DATA_REAL: 736 r->float_num = big2 host(r->float_num);736 r->float_num = big2wire(r->float_num); 737 737 break; 738 738 case LAUNCH_DATA_BOOL: 739 r->boolean = big2 host(r->boolean);739 r->boolean = big2wire(r->boolean); 740 740 break; 741 741 case LAUNCH_DATA_ERRNO: 742 r->err = big2 host(r->err);742 r->err = big2wire(r->err); 743 743 case LAUNCH_DATA_MACHPORT: 744 744 break; … … 749 749 } 750 750 751 r->type = big2 host(r->type);751 r->type = big2wire(r->type); 752 752 753 753 return r; … … 789 789 lh->sendfdcnt = fd_slots_used; 790 790 791 msglen = lh->sendlen + sizeof(struct launch_msg_header); /* type promotion to make the host2 big() macro work right */792 lmh.len = host2 big(msglen);793 lmh.magic = host2 big(LAUNCH_MSG_HEADER_MAGIC);791 msglen = lh->sendlen + sizeof(struct launch_msg_header); /* type promotion to make the host2wire() macro work right */ 792 lmh.len = host2wire(msglen); 793 lmh.magic = host2wire(LAUNCH_MSG_HEADER_MAGIC); 794 794 795 795 iov[0].iov_base = &lmh; … … 1020 1020 goto need_more_data; 1021 1021 1022 tmplen = big2 host(lmhp->len);1023 1024 if (big2 host(lmhp->magic) != LAUNCH_MSG_HEADER_MAGIC || tmplen <= sizeof(struct launch_msg_header)) {1022 tmplen = big2wire(lmhp->len); 1023 1024 if (big2wire(lmhp->magic) != LAUNCH_MSG_HEADER_MAGIC || tmplen <= sizeof(struct launch_msg_header)) { 1025 1025 errno = EBADRPC; 1026 1026 goto out_bad;

