|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This main entry point of Java processes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <unistd.h> |
|
20 #include <string.h> |
|
21 #include <memory> |
|
22 |
|
23 #include "logger.h" |
|
24 #include "javaoslayer.h" |
|
25 #include "exceptionbase.h" |
|
26 #include "dynamiclibloader.h" |
|
27 |
|
28 #include "javaprocessconstants.h" |
|
29 |
|
30 using namespace java::util; |
|
31 |
|
32 typedef int (*DllmainFunc)(int argc, const char *argv[]); |
|
33 |
|
34 |
|
35 const char* allowedDlls[] = {java::runtime::JAVA_MIDP_STARTER_DLL, |
|
36 java::runtime::JAVA_INSTALLER_STARTER_DLL, |
|
37 java::runtime::JAVA_PREINSTALLER_STARTER_DLL, |
|
38 java::runtime::JAVA_SIZE_HELPER_SERVER_DLL |
|
39 }; |
|
40 |
|
41 const int tableSize = sizeof(allowedDlls) / sizeof(char*); |
|
42 int main(int argc, const char *argv[]) |
|
43 { |
|
44 JELOG(EJavaRuntime, "Java main()"); |
|
45 LOG(EJavaRuntime, EInfo, "JAVA MAIN STARTED"); |
|
46 JavaOsLayer::startUpTrace("Java main", -1, -1); |
|
47 |
|
48 int result = -1; |
|
49 try |
|
50 { |
|
51 //Verifying that the dll name has been provided |
|
52 if (argc > 1) |
|
53 { |
|
54 const char* libName = argv[1]; |
|
55 for (int i = 0; i<tableSize; ++i) |
|
56 { |
|
57 if (strcmp(libName, allowedDlls[i]) == 0) // codescanner::accessArrayElementWithoutCheck2 |
|
58 { |
|
59 result = 0; |
|
60 break; |
|
61 } |
|
62 } |
|
63 if (result != 0) |
|
64 { |
|
65 ELOG1(EJavaRuntime, "Tried to create Java process with " |
|
66 "illegal dll: %s ", libName); |
|
67 return -1; |
|
68 } |
|
69 |
|
70 //Loading the defined library |
|
71 std::auto_ptr<DynamicLibLoader> |
|
72 lib(new DynamicLibLoader(libName)); // codescanner::nonleavenew |
|
73 DllmainFunc dllMain = (DllmainFunc)(lib->getFunction("dllMain")); |
|
74 |
|
75 argv[1] = argv[0]; |
|
76 |
|
77 //Calling the main entry point. |
|
78 result = dllMain(argc-1, &argv[1]); // codescanner::accessArrayElementWithoutCheck2 |
|
79 lib->closeLib(); |
|
80 } |
|
81 else |
|
82 { |
|
83 ELOG(EJavaRuntime, "Not enough arguments for loading the runtime " |
|
84 "dll."); |
|
85 } |
|
86 } |
|
87 |
|
88 catch (ExceptionBase& e) |
|
89 { |
|
90 ELOG1(EJavaRuntime, "Java main() ExceptionBase catched: %s ", |
|
91 e.toString().c_str()); |
|
92 } |
|
93 |
|
94 catch (std::exception& e) |
|
95 { |
|
96 |
|
97 ELOG1(EJavaRuntime, "Java main() Exception %s catched", e.what()); |
|
98 } |
|
99 |
|
100 LOG1(EJavaRuntime, EInfo, "JAVA MAIN EXIT = %d", result); |
|
101 return result; |
|
102 } |