]>
git.saurik.com Git - cycript.git/blob - Trampoline.t.cpp
7229c2552592b1508918e81451d25aeed2b3d17c
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2010 Jay Freeman (saurik)
5 /* GNU Lesser General Public License, Version 3 {{{ */
7 * Cycript is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
12 * Cycript is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
22 #define _PTHREAD_ATTR_T
23 #include <pthread_internals.h>
25 #include "Standard.hpp"
28 template <typename Type_
>
29 static _finline
void dlset(Baton
*baton
, Type_
&function
, const char *name
, void *handle
= RTLD_DEFAULT
) {
30 function
= reinterpret_cast<Type_
>(baton
->dlsym(handle
, name
));
35 #define Framework(framework) \
36 "/System/Library/Frameworks/" #framework ".framework/" #framework
38 static void *Routine(void *arg
) {
39 Baton
*baton(reinterpret_cast<Baton
*>(arg
));
41 void *(*dlopen
)(const char *, int);
42 dlset(baton
, dlopen
, "dlopen");
44 if (baton
->dlsym(RTLD_DEFAULT
, "JSEvaluateScript") == NULL
)
45 dlopen(Framework(JavaScriptCore
), RTLD_GLOBAL
| RTLD_LAZY
);
47 void *(*objc_getClass
)(const char *);
48 dlset(baton
, objc_getClass
, "objc_getClass");
50 if (objc_getClass("WebUndefined") == NULL
)
51 dlopen(Framework(WebKit
), RTLD_GLOBAL
| RTLD_LAZY
);
53 void *handle(dlopen(baton
->library
, RTLD_LAZY
| RTLD_LOCAL
));
59 void (*CYHandleServer
)(pid_t
);
60 dlset(baton
, CYHandleServer
, "CYHandleServer", handle
);
62 CYHandleServer(baton
->pid
);
67 static void *Thread(void *arg
) {
68 Baton
*baton(reinterpret_cast<Baton
*>(arg
));
70 int (*pthread_create
)(pthread_t
*, const pthread_attr_t
*, void *(*)(void *), void *);
71 dlset(baton
, pthread_create
, "pthread_create");
74 pthread_create(&thread
, NULL
, &Routine
, baton
);
76 int (*pthread_join
)(pthread_t
, void **);
77 dlset(baton
, pthread_join
, "pthread_join");
80 pthread_join(thread
, &result
);
85 extern "C" void Start(Baton
*baton
) {
87 baton
->_pthread_start(&self
, NULL
, &Thread
, baton
, 8 * 1024, 0);