7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 */
28
29 /*
30 * This program is used to generate the contents of the
31 * struct_layout_XXX.c files that contain per-archtecture
32 * structure layout information.
33 *
34 * Although not part of elfdump, it is built by the makefile
35 * along with it.
36 * To use it:
37 *
38 * 1) Run it, capturing the output in a file.
39 * 2) If this is a replacement for an existing file,
40 * diff the new and old copies to ensure only
41 * the changes you expected are present.
42 * 3) Put the new file in the common directory under the name
43 * struct_layout_XXX.c, where XXX is the name of
44 * the architecture (i386, amd64, sparc, sparcv9, etc).
45 * 2) Add any necessary header and copyright comments.
46 * 3) If this is a new architecture:
47 * - Add an extern statement for struct_layout_XXX()
48 * to struct_layout.h
49 * - Add a case for it to the function sl_struct_layout()
50 * in struct_layout.c.
51 */
582 SCALAR_FIELD(prfdinfo_t, pr_size, 0);
583 SCALAR_FIELD(prfdinfo_t, pr_fileflags, 0);
584 SCALAR_FIELD(prfdinfo_t, pr_fdflags, 0);
585 ARRAY_FIELD(prfdinfo_t, pr_path, 0);
586
587 END;
588 }
589
590 static void
591 gen_prsecflags(void)
592 {
593 START(prsecflags, prsecflags_t);
594 SCALAR_FIELD(prsecflags_t, pr_version, 0);
595 SCALAR_FIELD(prsecflags_t, pr_effective, 0);
596 SCALAR_FIELD(prsecflags_t, pr_inherit, 0);
597 SCALAR_FIELD(prsecflags_t, pr_lower, 0);
598 SCALAR_FIELD(prsecflags_t, pr_upper, 0);
599 END;
600 }
601
602 /*ARGSUSED*/
603 int
604 main(int argc, char *argv[])
605 {
606 const char *fmt = "\t&%s_layout,\n";
607
608 /* get obj file for input */
609 if (argc < 3) {
610 (void) fprintf(stderr,
611 "usage: %s {object_file} {MACH}\n", argv[0]);
612 exit(1);
613 }
614
615 objfile = argv[1];
616 machname = argv[2];
617
618 get_ctf_file(objfile);
619
620 (void) printf("#include <struct_layout.h>\n");
621
623 gen_prgregset();
624 gen_lwpstatus();
625 gen_pstatus();
626 gen_prstatus();
627 gen_psinfo();
628 gen_prpsinfo();
629 gen_lwpsinfo();
630 gen_prcred();
631 gen_prpriv();
632 gen_priv_impl_info();
633 gen_fltset();
634 gen_siginfo();
635 gen_sigset();
636 gen_sigaction();
637 gen_stack();
638 gen_sysset();
639 gen_timestruc();
640 gen_utsname();
641 gen_prfdinfo();
642 gen_prsecflags();
643
644 /*
645 * Generate the full arch_layout description
646 */
647 (void) printf(
648 "\n\n\n\nstatic const sl_arch_layout_t layout_%s = {\n",
649 machname);
650 (void) printf(fmt, "auxv");
651 (void) printf(fmt, "fltset");
652 (void) printf(fmt, "lwpsinfo");
653 (void) printf(fmt, "lwpstatus");
654 (void) printf(fmt, "prcred");
655 (void) printf(fmt, "priv_impl_info");
656 (void) printf(fmt, "prpriv");
657 (void) printf(fmt, "psinfo");
658 (void) printf(fmt, "pstatus");
659 (void) printf(fmt, "prgregset");
660 (void) printf(fmt, "prpsinfo");
661 (void) printf(fmt, "prstatus");
662 (void) printf(fmt, "sigaction");
663 (void) printf(fmt, "siginfo");
664 (void) printf(fmt, "sigset");
665 (void) printf(fmt, "stack");
666 (void) printf(fmt, "sysset");
667 (void) printf(fmt, "timestruc");
668 (void) printf(fmt, "utsname");
669 (void) printf(fmt, "prfdinfo");
670 (void) printf(fmt, "prsecflags");
671 (void) printf("};\n");
672
673 /*
674 * A public function, to make the information available
675 */
676 (void) printf("\n\nconst sl_arch_layout_t *\n");
677 (void) printf("struct_layout_%s(void)\n", machname);
678 (void) printf("{\n\treturn (&layout_%s);\n}\n", machname);
679
680 return (0);
681 }
682
683 /*
684 * Helper functions using the CTF library to get type info.
685 */
686
687 static void
688 get_ctf_file(char *fname)
689 {
690 int ctferr;
|
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 * Copyright 2018 Joyent, Inc.
28 */
29
30 /*
31 * This program is used to generate the contents of the
32 * struct_layout_XXX.c files that contain per-architecture
33 * structure layout information.
34 *
35 * Although not part of elfdump, it is built by the makefile
36 * along with it.
37 * To use it:
38 *
39 * 1) Run it, capturing the output in a file.
40 * 2) If this is a replacement for an existing file,
41 * diff the new and old copies to ensure only
42 * the changes you expected are present.
43 * 3) Put the new file in the common directory under the name
44 * struct_layout_XXX.c, where XXX is the name of
45 * the architecture (i386, amd64, sparc, sparcv9, etc).
46 * 2) Add any necessary header and copyright comments.
47 * 3) If this is a new architecture:
48 * - Add an extern statement for struct_layout_XXX()
49 * to struct_layout.h
50 * - Add a case for it to the function sl_struct_layout()
51 * in struct_layout.c.
52 */
583 SCALAR_FIELD(prfdinfo_t, pr_size, 0);
584 SCALAR_FIELD(prfdinfo_t, pr_fileflags, 0);
585 SCALAR_FIELD(prfdinfo_t, pr_fdflags, 0);
586 ARRAY_FIELD(prfdinfo_t, pr_path, 0);
587
588 END;
589 }
590
591 static void
592 gen_prsecflags(void)
593 {
594 START(prsecflags, prsecflags_t);
595 SCALAR_FIELD(prsecflags_t, pr_version, 0);
596 SCALAR_FIELD(prsecflags_t, pr_effective, 0);
597 SCALAR_FIELD(prsecflags_t, pr_inherit, 0);
598 SCALAR_FIELD(prsecflags_t, pr_lower, 0);
599 SCALAR_FIELD(prsecflags_t, pr_upper, 0);
600 END;
601 }
602
603 static void
604 gen_prlwpname(void)
605 {
606 START(prlwpname, prlwpname_t);
607 SCALAR_FIELD(prlwpname_t, pr_lwpid, 0);
608 ARRAY_FIELD(prlwpname_t, pr_lwpname, 0);
609 END;
610 }
611
612 /*ARGSUSED*/
613 int
614 main(int argc, char *argv[])
615 {
616 const char *fmt = "\t&%s_layout,\n";
617
618 /* get obj file for input */
619 if (argc < 3) {
620 (void) fprintf(stderr,
621 "usage: %s {object_file} {MACH}\n", argv[0]);
622 exit(1);
623 }
624
625 objfile = argv[1];
626 machname = argv[2];
627
628 get_ctf_file(objfile);
629
630 (void) printf("#include <struct_layout.h>\n");
631
633 gen_prgregset();
634 gen_lwpstatus();
635 gen_pstatus();
636 gen_prstatus();
637 gen_psinfo();
638 gen_prpsinfo();
639 gen_lwpsinfo();
640 gen_prcred();
641 gen_prpriv();
642 gen_priv_impl_info();
643 gen_fltset();
644 gen_siginfo();
645 gen_sigset();
646 gen_sigaction();
647 gen_stack();
648 gen_sysset();
649 gen_timestruc();
650 gen_utsname();
651 gen_prfdinfo();
652 gen_prsecflags();
653 gen_prlwpname();
654
655 /*
656 * Generate the full arch_layout description
657 */
658 (void) printf(
659 "\n\n\n\nstatic const sl_arch_layout_t layout_%s = {\n",
660 machname);
661 (void) printf(fmt, "auxv");
662 (void) printf(fmt, "fltset");
663 (void) printf(fmt, "lwpsinfo");
664 (void) printf(fmt, "lwpstatus");
665 (void) printf(fmt, "prcred");
666 (void) printf(fmt, "priv_impl_info");
667 (void) printf(fmt, "prpriv");
668 (void) printf(fmt, "psinfo");
669 (void) printf(fmt, "pstatus");
670 (void) printf(fmt, "prgregset");
671 (void) printf(fmt, "prpsinfo");
672 (void) printf(fmt, "prstatus");
673 (void) printf(fmt, "sigaction");
674 (void) printf(fmt, "siginfo");
675 (void) printf(fmt, "sigset");
676 (void) printf(fmt, "stack");
677 (void) printf(fmt, "sysset");
678 (void) printf(fmt, "timestruc");
679 (void) printf(fmt, "utsname");
680 (void) printf(fmt, "prfdinfo");
681 (void) printf(fmt, "prsecflags");
682 (void) printf(fmt, "prlwpname");
683 (void) printf("};\n");
684
685 /*
686 * A public function, to make the information available
687 */
688 (void) printf("\n\nconst sl_arch_layout_t *\n");
689 (void) printf("struct_layout_%s(void)\n", machname);
690 (void) printf("{\n\treturn (&layout_%s);\n}\n", machname);
691
692 return (0);
693 }
694
695 /*
696 * Helper functions using the CTF library to get type info.
697 */
698
699 static void
700 get_ctf_file(char *fname)
701 {
702 int ctferr;
|