20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <strings.h>
31 #include <unistd.h>
32 #include <sys/auxv.h>
33 #include <sys/bitmap.h>
34 #include <sys/brand.h>
35 #include <sys/inttypes.h>
36 #include <sys/lwp.h>
37 #include <sys/syscall.h>
38 #include <sys/systm.h>
39 #include <sys/utsname.h>
40 #include <sys/zone.h>
41 #include <sys/stat.h>
42 #include <sys/mntent.h>
43 #include <sys/ctfs.h>
44 #include <sys/priv.h>
45 #include <sys/acctctl.h>
46 #include <libgen.h>
47
48 #include <s10_brand.h>
49 #include <s10_misc.h>
50
51 /*
52 * Principles of emulation 101.
53 *
54 *
55 * *** Setting errno
56 *
57 * Just don't do it. This emulation library is loaded onto a
58 * seperate link map from the application who's address space we're
59 * running in. We have our own private copy of libc, so there for,
628 struct utsname un, *unp = (struct utsname *)p1;
629 int rev, err;
630
631 if ((err = __systemcall(rv, SYS_uname + 1024, &un)) != 0)
632 return (err);
633
634 rev = atoi(&un.release[2]);
635 s10_assert(rev >= 11);
636 bzero(un.release, _SYS_NMLN);
637 (void) strlcpy(un.release, S10_UTS_RELEASE, _SYS_NMLN);
638 bzero(un.version, _SYS_NMLN);
639 (void) strlcpy(un.version, S10_UTS_VERSION, _SYS_NMLN);
640
641 /* copy out the modified uname info */
642 if (s10_uucopy(&un, unp, sizeof (un)) != 0)
643 return (EFAULT);
644
645 return (0);
646 }
647
648 /*
649 * If the emul_global_zone flag is set then emulate some aspects of the
650 * zone system call. In particular, emulate the global zone ID on the
651 * ZONE_LOOKUP subcommand and emulate some of the global zone attributes
652 * on the ZONE_GETATTR subcommand. If the flag is not set or we're performing
653 * some other operation, simply pass the calls through.
654 */
655 int
656 s10_zone(sysret_t *rval, int cmd, void *arg1, void *arg2, void *arg3,
657 void *arg4)
658 {
659 char *aval;
660 int len;
661 zoneid_t zid;
662 int attr;
663 char *buf;
664 size_t bufsize;
665
666 /*
667 * We only emulate the zone syscall for a subset of specific commands,
1114 NOSYS, /* 119 */
1115 NOSYS, /* 120 */
1116 NOSYS, /* 121 */
1117 NOSYS, /* 122 */
1118 NOSYS, /* 123 */
1119 NOSYS, /* 124 */
1120 NOSYS, /* 125 */
1121 NOSYS, /* 126 */
1122 NOSYS, /* 127 */
1123 NOSYS, /* 128 */
1124 NOSYS, /* 129 */
1125 NOSYS, /* 130 */
1126 NOSYS, /* 131 */
1127 NOSYS, /* 132 */
1128 NOSYS, /* 133 */
1129 NOSYS, /* 134 */
1130 EMULATE(s10_uname, 1 | RV_DEFAULT), /* 135 */
1131 NOSYS, /* 136 */
1132 NOSYS, /* 137 */
1133 NOSYS, /* 138 */
1134 NOSYS, /* 139 */
1135 NOSYS, /* 140 */
1136 NOSYS, /* 141 */
1137 NOSYS, /* 142 */
1138 NOSYS, /* 143 */
1139 NOSYS, /* 144 */
1140 NOSYS, /* 145 */
1141 NOSYS, /* 146 */
1142 NOSYS, /* 147 */
1143 NOSYS, /* 148 */
1144 NOSYS, /* 149 */
1145 NOSYS, /* 150 */
1146 NOSYS, /* 151 */
1147 NOSYS, /* 152 */
1148 NOSYS, /* 153 */
1149 NOSYS, /* 154 */
1150 NOSYS, /* 155 */
1151 NOSYS, /* 156 */
1152 NOSYS, /* 157 */
1153 NOSYS, /* 158 */
1154 NOSYS, /* 159 */
|
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <strings.h>
31 #include <unistd.h>
32 #include <sys/auxv.h>
33 #include <sys/bitmap.h>
34 #include <sys/brand.h>
35 #include <sys/inttypes.h>
36 #include <sys/lwp.h>
37 #include <sys/syscall.h>
38 #include <sys/systm.h>
39 #include <sys/utsname.h>
40 #include <sys/systeminfo.h>
41 #include <sys/zone.h>
42 #include <sys/stat.h>
43 #include <sys/mntent.h>
44 #include <sys/ctfs.h>
45 #include <sys/priv.h>
46 #include <sys/acctctl.h>
47 #include <libgen.h>
48
49 #include <s10_brand.h>
50 #include <s10_misc.h>
51
52 /*
53 * Principles of emulation 101.
54 *
55 *
56 * *** Setting errno
57 *
58 * Just don't do it. This emulation library is loaded onto a
59 * seperate link map from the application who's address space we're
60 * running in. We have our own private copy of libc, so there for,
629 struct utsname un, *unp = (struct utsname *)p1;
630 int rev, err;
631
632 if ((err = __systemcall(rv, SYS_uname + 1024, &un)) != 0)
633 return (err);
634
635 rev = atoi(&un.release[2]);
636 s10_assert(rev >= 11);
637 bzero(un.release, _SYS_NMLN);
638 (void) strlcpy(un.release, S10_UTS_RELEASE, _SYS_NMLN);
639 bzero(un.version, _SYS_NMLN);
640 (void) strlcpy(un.version, S10_UTS_VERSION, _SYS_NMLN);
641
642 /* copy out the modified uname info */
643 if (s10_uucopy(&un, unp, sizeof (un)) != 0)
644 return (EFAULT);
645
646 return (0);
647 }
648
649 int
650 s10_sysinfo(sysret_t *rv, int command, char *buf, long count)
651 {
652 char *value;
653 int err, len;
654
655 /*
656 * We must interpose on the sysinfo(2) commands SI_RELEASE and
657 * SI_VERSION; all others get passed to the native sysinfo(2)
658 * command.
659 */
660 switch (command) {
661 case SI_RELEASE:
662 value = S10_UTS_RELEASE;
663 break;
664
665 case SI_VERSION:
666 value = S10_UTS_VERSION;
667 break;
668
669 default:
670 /*
671 * The default action is to pass the command to the
672 * native sysinfo(2) syscall.
673 */
674 if ((err = __systemcall(rv, SYS_systeminfo + 1024,
675 command, buf, count)) != 0)
676 return (err);
677
678 return (0);
679 }
680
681 len = strlen(value) + 1;
682 if (count > 0) {
683 if (s10_uucopystr(value, buf, count) != 0)
684 return (EFAULT);
685
686 /* Assure NULL termination of buf as s10_uucopystr() doesn't. */
687 if (len > count && s10_uucopy("\0", buf + (count - 1), 1) != 0)
688 return (EFAULT);
689 }
690
691 /*
692 * On success, sysinfo(2) returns the size of buffer required to hold
693 * the complete value plus its terminating NULL byte.
694 */
695 rv->sys_rval1 = len;
696 rv->sys_rval2 = 0;
697 S10_TRUSS_POINT_3(rv, SYS_systeminfo, 0, command, buf, count);
698 return (0);
699 }
700
701 /*
702 * If the emul_global_zone flag is set then emulate some aspects of the
703 * zone system call. In particular, emulate the global zone ID on the
704 * ZONE_LOOKUP subcommand and emulate some of the global zone attributes
705 * on the ZONE_GETATTR subcommand. If the flag is not set or we're performing
706 * some other operation, simply pass the calls through.
707 */
708 int
709 s10_zone(sysret_t *rval, int cmd, void *arg1, void *arg2, void *arg3,
710 void *arg4)
711 {
712 char *aval;
713 int len;
714 zoneid_t zid;
715 int attr;
716 char *buf;
717 size_t bufsize;
718
719 /*
720 * We only emulate the zone syscall for a subset of specific commands,
1167 NOSYS, /* 119 */
1168 NOSYS, /* 120 */
1169 NOSYS, /* 121 */
1170 NOSYS, /* 122 */
1171 NOSYS, /* 123 */
1172 NOSYS, /* 124 */
1173 NOSYS, /* 125 */
1174 NOSYS, /* 126 */
1175 NOSYS, /* 127 */
1176 NOSYS, /* 128 */
1177 NOSYS, /* 129 */
1178 NOSYS, /* 130 */
1179 NOSYS, /* 131 */
1180 NOSYS, /* 132 */
1181 NOSYS, /* 133 */
1182 NOSYS, /* 134 */
1183 EMULATE(s10_uname, 1 | RV_DEFAULT), /* 135 */
1184 NOSYS, /* 136 */
1185 NOSYS, /* 137 */
1186 NOSYS, /* 138 */
1187 EMULATE(s10_sysinfo, 3 | RV_DEFAULT), /* 139 */
1188 NOSYS, /* 140 */
1189 NOSYS, /* 141 */
1190 NOSYS, /* 142 */
1191 NOSYS, /* 143 */
1192 NOSYS, /* 144 */
1193 NOSYS, /* 145 */
1194 NOSYS, /* 146 */
1195 NOSYS, /* 147 */
1196 NOSYS, /* 148 */
1197 NOSYS, /* 149 */
1198 NOSYS, /* 150 */
1199 NOSYS, /* 151 */
1200 NOSYS, /* 152 */
1201 NOSYS, /* 153 */
1202 NOSYS, /* 154 */
1203 NOSYS, /* 155 */
1204 NOSYS, /* 156 */
1205 NOSYS, /* 157 */
1206 NOSYS, /* 158 */
1207 NOSYS, /* 159 */
|