/* Initialization code run first thing by the XCOFF startup code. AIX version.
Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
/* hack to use uchar's */
typedef unsigned char uchar;
#include <xcoff.h>
#include <rtinit.h>
#include <dlldr.h>
#include <bits/libc-lock.h>
extern void __libc_init_first (int argc, char **argv, char **envp);
/* XXX disable for now
extern int __libc_multiple_libcs; */
/* XXX normally defined in generic/dl-sydep.c, hack it into existance
extern void *__libc_stack_end; */
void *__libc_stack_end;
struct __libc_start_data_rec {
void *stack;
void *toc;
int argc;
char **argv;
char **envp;
char *data;
char *text;
unsigned mcount;
unsigned special;
int (*main)(int, char **, char **);
void (*init)(void);
void (*fini)(void);
void (*rtld_fini)(void);
};
extern struct __libc_start_data_rec __libc_start_data;
extern int errno;
/* The first piece of initialized data. */
int __data_start = 0;
#ifndef HAVE_ELF
/* Since gcc/crtstuff.c won't define it unless the ELF format is used
we will need to define it here. */
void *__dso_handle = NULL;
#endif
/* AIX kernel function */
extern int __loadx (int flag, void *module, void *arg1, void *arg2,
void *arg3);
/* Needed by setenv */
char **__environ;
/*
* Find __rtinit symbol
*
* __RTINIT *find_rtinit()
*
* __RTINIT *rti - pointer to __rtinit data structure
*/
static __RTINIT *
find_rtinit (void)
{
struct xcoffhdr *xcoff_hdr;
SCNHDR *sec_hdr;
SCNHDR *ldr_sec_hdr;
SCNHDR *data_sec_hdr;
LDSYM *ldsym_hdr;
__RTINIT *rtl;
xcoff_hdr = (struct xcoffhdr *) __libc_start_data.text;
sec_hdr = (SCNHDR *) ((caddr_t) &xcoff_hdr->aouthdr
+ xcoff_hdr->filehdr.f_opthdr);
ldr_sec_hdr = (SCNHDR *) (sec_hdr + (xcoff_hdr->aouthdr.o_snloader - 1));
ldsym_hdr = (LDSYM *) ((caddr_t) xcoff_hdr + ldr_sec_hdr->s_scnptr
+ LDHDRSZ);
if (__libc_start_data.mcount <= 0)
{
if (!ldr_sec_hdr->s_scnptr)
return NULL;
if (memcmp (ldsym_hdr, RTINIT_NAME, sizeof(RTINIT_NAME) - 1) != 0)
return NULL;
}
data_sec_hdr = (SCNHDR *) (sec_hdr + (xcoff_hdr->aouthdr.o_sndata - 1));
rtl = (__RTINIT *) (ldsym_hdr->l_value
+ (__libc_start_data.data - data_sec_hdr->s_vaddr));
return rtl;
}
/* The mod_init1 calls every initialization function
for a given module.
void mod_init1(handler, rti)
void *handler - if NULL init funtions for modules loaded at exec time
are being executed. Otherwise, the handler points to the
module loaded.
__RTINIT *rti - pointer to __rtinit data structure (with rti->init_offset
not equal to zero)
*/
static void
mod_init1 (void *handler,__RTINIT *rtl)
{
__RTINIT_DESCRIPTOR *descriptor;
descriptor = (__RTINIT_DESCRIPTOR *) ((caddr_t) &rtl->rtl
+ rtl->init_offset);
while (descriptor->f != NULL)
{
if (!(descriptor->flags & _RT_CALLED))
{
descriptor->flags |= _RT_CALLED;
/* Execute init/fini. */
descriptor->f (handler, rtl, descriptor);
}
descriptor = (__RTINIT_DESCRIPTOR *) ((caddr_t) descriptor
+ rtl->__rtinit_descriptor_size);
}
}
/* The modinit() function performs run-time linking, if enabled, and calling
the init() function for all loaded modules.
int modinit()
*/
#define DL_BUFFER_SIZE 1000
static int
modinit (void)
{
int *handler = NULL;
__RTINIT *rtinit_info = NULL;
int flag;
DL_INFO dl_buffer[DL_BUFFER_SIZE];
DL_INFO *dl_info = dl_buffer;
int i;
/* Find __rtinit symbols */
rtinit_info = find_rtinit ();
flag = DL_EXECQ;
if (rtinit_info && rtinit_info->rtl)
flag |= DL_LOAD_RTL;
/* Get a list of modules that have __rtinit. */
if (__loadx (flag, dl_info, (void *) sizeof (dl_buffer), NULL, NULL))
exit (0x90);
if (( dl_info[0].dlinfo_xflags & DL_INFO_OK))
{
rtinit_info = find_rtinit ();
if ((rtinit_info != NULL) & (rtinit_info->rtl != NULL))
{
if ((*rtinit_info->rtl) (dl_info, 0))
exit (0x90);
}
}
/* Initialization each module loaded that has __rtinit. */
if (dl_info[0].dlinfo_xflags & DL_INFO_OK)
{
for (i = 1; i < dl_info[0].dlinfo_arraylen + 1; ++i)
if (dl_info[i].dlinfo_flags & DL_HAS_RTINIT)
{
rtinit_info = find_rtinit ();
if (rtinit_info)
mod_init1 (handler, rtinit_info);
}
}
return 0;
}
void
__libc_start_init (void)
{
/* Do run-time linking, if enabled and call the init()
for all loaded modules. */
if (__libc_start_data.mcount != __libc_start_data.special)
modinit ();
}
/* For now these are just stubs. */
void
__libc_start_fini (void)
{
}
void
__libc_start_rtld_fini (void)
{
}
void
__libc_start_main (void)
{
#ifndef SHARED
/* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
If the address would be taken inside the expression the optimizer
would try to be too smart and throws it away. Grrr. */
/* XXX disable for now
int *dummy_addr = &_dl_starting_up;
__libc_multiple_libcs = dummy_addr && !_dl_starting_up; */
#endif
/* Store the lowest stack address. */
__libc_stack_end = __libc_start_data.stack;
/* Used by setenv */
__environ = __libc_start_data.envp;
#ifndef SHARED
/* Clear errno. */
errno = 0;
/* Some security at this point. Prevent starting a SUID binary where
the standard file descriptors are not opened. We have to do this
only for statically linked applications since otherwise the dynamic
loader did the work already. */
if (__builtin_expect (__libc_enable_secure, 0))
__libc_check_standard_fds ();
#endif
/* Register the destructor of the dynamic linker if there is any. */
if (__builtin_expect (__libc_start_data.rtld_fini != NULL, 1))
__cxa_atexit ((void (*) (void *)) __libc_start_data.rtld_fini, NULL, NULL);
/* Call the initializer of the libc. This is only needed here if we
are compiling for the static library in which case we haven't
run the constructors in `_dl_start_user'. */
#ifndef SHARED
__libc_init_first (__libc_start_data.argc, __libc_start_data.argv,
__libc_start_data.envp);
#endif
/* Register the destructor of the program, if any. */
if (__libc_start_data.fini)
__cxa_atexit ((void (*) (void *)) __libc_start_data.fini, NULL, NULL);
/* Call the initializer of the program, if any. */
#ifdef SHARED
if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_IMPCALLS, 0))
_dl_debug_printf ("\ninitialize program: %s\n\n",
__libc_start_data.argv[0]);
#endif
if (__libc_start_data.init)
(*__libc_start_data.init) ();
#ifdef SHARED
if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_IMPCALLS, 0))
_dl_debug_printf ("\ntransferring control: %s\n\n",
__libc_start_data.argv[0]);
#endif
exit ((*__libc_start_data.main) (__libc_start_data.argc,
__libc_start_data.argv,
__libc_start_data.envp));
}
没有合适的资源?快使用搜索试试~ 我知道了~
glibc-ports-2.3.6.tar.gz
需积分: 1 0 下载量 91 浏览量
2024-03-04
14:42:33
上传
评论
收藏 196KB GZ 举报
温馨提示
共653个文件
c:312个
h:138个
s:120个
gnu安装包
资源推荐
资源详情
资源评论
收起资源包目录
glibc-ports-2.3.6.tar.gz (653个子文件)
ChangeLog.am33 8KB
Banner 71B
libc-start.c 8KB
start-libc.c 7KB
sysconf.c 6KB
errlist.c 5KB
tcsetattr.c 5KB
tcgetattr.c 5KB
__longjmp.c 5KB
console.c 5KB
dl-open.c 4KB
console.c 4KB
getdents.c 4KB
waitpid.c 4KB
init-first.c 3KB
setjmp.c 3KB
open.c 3KB
gettimeofday.c 3KB
start.c 3KB
fraiseexcpt.c 2KB
read.c 2KB
sigaction.c 2KB
waitid.c 2KB
brdinit.c 2KB
pspinlock.c 2KB
write.c 2KB
speed.c 2KB
waitpid.c 2KB
sigvec.c 2KB
console.c 2KB
sigtramp.c 2KB
fsetexcptflg.c 2KB
fesetenv.c 2KB
sysconf.c 2KB
brdinit.c 2KB
setitimer.c 2KB
_exit.c 2KB
brk.c 2KB
_exit.c 2KB
fclrexcpt.c 2KB
wait3.c 2KB
getpriority.c 2KB
dl-sym.c 2KB
feupdateenv.c 2KB
memccpy.c 2KB
fgetexcptflg.c 2KB
writev.c 1KB
readv.c 1KB
_exit.c 1KB
uitrunc.c 1KB
dl-close.c 1KB
nanosleep.c 1KB
brdinit.c 1KB
brk.c 1KB
getgroups.c 1KB
close.c 1KB
setpriority.c 1KB
ffs.c 1KB
fedisblxcpt.c 1KB
feenablxcpt.c 1KB
sigaction.c 1KB
feholdexcpt.c 1KB
ioctl.c 1KB
brk.c 1KB
fcntl.c 1KB
ffs.c 1KB
setpgid.c 1KB
usleep.c 1KB
write.c 1KB
ffs.c 1KB
getrusage.c 1KB
wait4.c 1KB
open.c 1KB
gethostname.c 1KB
ftruncate.c 1KB
fegetenv.c 1KB
sleep.c 1KB
setsid.c 1KB
setreuid.c 1KB
setregid.c 1KB
dl-libc.c 1KB
recvfrom.c 1KB
revoke.c 1KB
xstat64.c 1KB
lxstat64.c 1KB
fegetexcept.c 1KB
sigsuspend.c 1KB
lseek64.c 1KB
sysconf.c 1KB
sethostname.c 1KB
pathconf.c 1KB
fpathconf.c 1KB
__setpgid.c 1KB
fxstat64.c 1KB
sigpending.c 1KB
getgroups.c 1KB
ftestexcept.c 1KB
times.c 1KB
setgroups.c 1KB
mmap64.c 1KB
共 653 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
程序员Chino的日记
- 粉丝: 2914
- 资源: 4万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功