1 /* $Id: common.c,v 1.1.1.1 2008/08/24 05:34:46 gmcgarry Exp $ */
3 * Copyright (c) 2008 Gregory McGarry <g.mcgarry@ieee.org>
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.
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.
21 _strrchr(char *p
, int ch
)
25 for (save
= NULL
;; ++p
) {
35 _strcmp(char *s1
, char *s2
)
41 return ((long)*s1
- (long)*s2
);
48 monitor(0, 0, 0, 0, 0);
52 extern struct mach_header _mh_execute_header
;
57 struct mach_header
*hdr
= &_mh_execute_header
;
58 char *ptr
= (char *)(hdr
+ 1);
60 struct segment_command
*segp
;
65 for (i
= 0; i
< (int)hdr
->ncmds
; i
++, ptr
+= segp
->cmdsize
) {
66 segp
= (struct segment_command
*)ptr
;
67 if (segp
->cmd
!= LC_SEGMENT
|| segp
->nsects
== 0)
69 secp
= (struct section
*)(segp
+ 1);
70 for (j
= 0; j
< (int)segp
->nsects
; j
++, secp
++) {
71 if (init
&& _strcmp(secp
->sectname
, "__constructor") != 0)
73 if (!init
&& _strcmp(secp
->sectname
, "__destructor") != 0)
76 addr
= (void **)secp
->addr
;
103 _dyld_func_lookup("__dyld_make_delayed_module_initializer_calls",
113 _dyld_func_lookup("__dyld_mod_term_funcs", (void *)&term
);
120 IDENT("$Id: common.c,v 1.1.1.1 2008/08/24 05:34:46 gmcgarry Exp $");