gen_struct_layout.c revision 894fa7ba71de90ec2b4a468b77d5d20d75299104
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/sysmacros.h>
#include <procfs.h>
#include <sys/old_procfs.h>
/*
* This standalone program is used to generate the contents
* of the struct_layout_XXX.c files that contain per-archtecture
* structure layout information.
*
* Although not part of elfdump, it is built by the makefile
* along with it.
* To use it:
*
* 1) Run it, capturing the output in a file.
* 2) If this is a replacement for an existing file,
* diff the new and old copies to ensure only
* the changes you expected are present.
* 3) Put the new file in the common directory under the name
* struct_layout_XXX.c, where XXX is the name of
* the architecture (i386, amd64, sparc, sparcv9, etc).
* 2) Add any necessary header and copyright comments.
* 3) If this is a new architecture:
* - Add an extern statement for struct_layout_XXX()
* to struct_layout.h
* - Add a case for it to the function sl_struct_layout()
* in struct_layout.c.
*/
/*
* Which machine is this build for?
*/
#if defined(__i386)
#define MACH "i386"
#define MACH "amd64"
#define MACH "sparcv9"
#define MACH "sparc"
#else
#error "unrecognized build host type"
#endif
/*
* START and END bracket a struct layout definition. They issue
* the typedef boilerplate, and the standard first element (sizeof)
* which captures the overall size of the structure.
*
* SCALAR_FIELD is for scalar struct fields
*
* ARRAY_FIELD is for array struct fields
*
* ARRAY is for plain (non-struct) array types
*/
(void) printf("\t{ 0,\t%d,\t0,\t0 },\t\t/* sizeof (%s) */\n", \
(void) printf("\t{ 0,\t%d,\t%d,\t%d },\t\t/* elt0 */\n", \
sizeof (*((_type *)0)[0]), \
static void
gen_auxv(void)
{
END;
}
/* prgregset_t, <sys/prgregset.h> */
static void
gen_prgregset(void)
{
ARRAY(prgregset_t, 0);
END;
}
static void
gen_lwpstatus(void)
{
END;
}
static void
gen_pstatus(void)
{
END;
}
/* prstatus_t, <sys/old_procfs.h> */
static void
gen_prstatus(void)
{
END;
}
static void
gen_psinfo(void)
{
END;
}
/* prpsinfo_t, <sys/old_procfs.h> */
static void
gen_prpsinfo(void)
{
END;
}
static void
gen_lwpsinfo(void)
{
END;
}
static void
gen_prcred(void)
{
END;
}
static void
gen_prpriv(void)
{
END;
}
static void
gen_priv_impl_info(void)
{
END;
}
static void
gen_fltset(void)
{
END;
}
static void
gen_siginfo(void)
{
END;
}
static void
gen_sigset(void)
{
END;
}
static void
gen_sigaction(void)
{
END;
}
static void
gen_stack(void)
{
END;
}
static void
gen_sysset(void)
{
END;
}
/* timestruc_t, <sys/time_impl.h> */
static void
gen_timestruc(void)
{
END;
}
static void
gen_utsname(void)
{
END;
}
static void
gen_prfdinfo(void)
{
END;
}
/*ARGSUSED*/
int
{
const char *fmt = "\t&%s_layout,\n";
printf("#include <struct_layout.h>\n");
gen_auxv();
gen_pstatus();
gen_prstatus();
gen_psinfo();
gen_prpsinfo();
gen_lwpsinfo();
gen_prcred();
gen_prpriv();
gen_fltset();
gen_siginfo();
gen_sigset();
gen_stack();
gen_sysset();
gen_utsname();
gen_prfdinfo();
/*
* Generate the full arch_layout description
*/
(void) printf(
"\n\n\n\nstatic const sl_arch_layout_t layout_%s = {\n",
MACH);
(void) printf("};\n");
/*
* A public function, to make the information available
*/
(void) printf("\n\nconst sl_arch_layout_t *\n");
return (0);
}