Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20110527072349

Diff

Diff from 1.4 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc-libs/csu/darwin/common.c

Annotated File View

gmcgarry
1.4
1 /*      $Id: common.c,v 1.4 2011/05/27 07:23:49 gmcgarry Exp $  */
gmcgarry
1.1
2 /*-
3  * Copyright (c) 2008 Gregory McGarry <g.mcgarry@ieee.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 #include "macho.h"
19
20 static char *
21 _strrchr(char *pint ch)
22 {
23         char *save;
24
25         for (save = NULL;; ++p) {
26                 if (*p == ch)
27                         save = (char *)p;
28                 if (!*p)
29                         return(save);
30         }
31         /* NOTREACHED */
32 }
33
34 static int
35 _strcmp(char *s1char *s2)
36 {
37         while (*s1 == *s2++)
38                 if (*s1++ == 0)
39                         return 0;
40         s2--;
41         return ((long)*s1 - (long)*s2);
42 }
43
44 #ifdef PROFILE
45 static void
46 _mcleanup(void)
47 {
48         monitor(00000);
49 }
50 #endif
51
52 extern struct mach_header _mh_execute_header;
53
54 static void
gmcgarry
1.2
55 _helper(int init)
gmcgarry
1.1
56 {
57         struct mach_header *hdr = &_mh_execute_header;
58         char *ptr = (char *)(hdr + 1);
59         int ijn;
gmcgarry
1.4
60 #ifdef __LP64__
61         struct segment_command_64 *segp;
62         struct section_64 *secp;
63 #else
64         struct segment_command_32 *segp;
65         struct section_32 *secp;
66 #endif
gmcgarry
1.1
67         void (*func)(void);
68         void **addr;
69
gmcgarry
1.3
70         for (i = 0i < (int)hdr->ncmdsi++, ptr += segp->cmdsize) {
gmcgarry
1.4
71 #ifdef __LP64__
72                 segp = (struct segment_command_64 *)ptr;
73 #else
74                 segp = (struct segment_command_32 *)ptr;
75 #endif
gmcgarry
1.1
76                 if (segp->cmd != LC_SEGMENT || segp->nsects == 0)
77                         continue;
gmcgarry
1.4
78 #ifdef __LP64__
79                 secp = (struct section_64 *)(segp + 1);
80 #else
81                 secp = (struct section_32 *)(segp + 1);
82 #endif
gmcgarry
1.3
83                 for (j = 0j < (int)segp->nsectsj++, secp++) {
gmcgarry
1.1
84                         if (init && _strcmp(secp->sectname"__constructor") != 0)
85                                 continue;
86                         if (!init && _strcmp(secp->sectname"__destructor") != 0)
87                                 continue;
88                         n = secp->size / 4;
89                         addr = (void **)secp->addr;
90                         while (n--) {
91                                 func = *addr++;
92                                 (*func)();
93                         }
94                 }
95         }
96 }
97
98 void
99 _init(void)
100 {
gmcgarry
1.2
101         _helper(1);
gmcgarry
1.1
102 }
103
104 void
105 _fini(void)
106 {
gmcgarry
1.2
107         _helper(0);
gmcgarry
1.1
108 }
109
110 #ifdef DYNAMIC
111
112 void
113 _dyld_init(void)
114 {
115         void (*init)(void);
116         _dyld_func_lookup("__dyld_make_delayed_module_initializer_calls",
117             (void *)&init);
118         if (init)
119                 init();
120 }
121
122 void
123 _dyld_fini(void)
124 {
125         void (*term)(void);
126         _dyld_func_lookup("__dyld_mod_term_funcs", (void *)&term);
127         if (term)
128                 term();
129 }
130
131 #endif
gmcgarry
1.3
132
gmcgarry
1.4
133 IDENT("$Id: common.c,v 1.4 2011/05/27 07:23:49 gmcgarry Exp $");
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-26 09:39 +0100