1 | /* $Id: tstSupLoadModule.cpp 25320 2009-12-11 11:03:44Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * SUP Testcase - Test SUPR3LoadModule.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2009 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | *
|
---|
26 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #include <VBox/sup.h>
|
---|
36 | #include <VBox/err.h>
|
---|
37 |
|
---|
38 | #include <iprt/getopt.h>
|
---|
39 | #include <iprt/initterm.h>
|
---|
40 | #include <iprt/mem.h>
|
---|
41 | #include <iprt/message.h>
|
---|
42 | #include <iprt/path.h>
|
---|
43 | #include <iprt/stream.h>
|
---|
44 | #include <iprt/string.h>
|
---|
45 |
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Makes a path to a file in the executable directory.
|
---|
49 | */
|
---|
50 | static char *ExeDirFile(char *pszFile, const char *pszArgv0, const char *pszFilename)
|
---|
51 | {
|
---|
52 | char *psz;
|
---|
53 | char *psz2;
|
---|
54 |
|
---|
55 | strcpy(pszFile, pszArgv0);
|
---|
56 | psz = strrchr(pszFile, '/');
|
---|
57 | psz2 = strrchr(pszFile, '\\');
|
---|
58 | if (psz < psz2)
|
---|
59 | psz = psz2;
|
---|
60 | if (!psz)
|
---|
61 | psz = strrchr(pszFile, ':');
|
---|
62 | if (!psz)
|
---|
63 | {
|
---|
64 | strcpy(pszFile, "./");
|
---|
65 | psz = &pszFile[1];
|
---|
66 | }
|
---|
67 | strcpy(psz + 1, "VMMR0.r0");
|
---|
68 | return pszFile;
|
---|
69 | }
|
---|
70 |
|
---|
71 | int main(int argc, char **argv)
|
---|
72 | {
|
---|
73 | /*
|
---|
74 | * Init.
|
---|
75 | */
|
---|
76 | int rc = RTR3InitAndSUPLib();
|
---|
77 | if (RT_FAILURE(rc))
|
---|
78 | {
|
---|
79 | RTMsgError("RTR3InitAndSUPLib failed with rc=%Rrc\n", rc);
|
---|
80 | return 1;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /*
|
---|
84 | * Process arguments.
|
---|
85 | */
|
---|
86 | static const RTGETOPTDEF s_aOptions[] =
|
---|
87 | {
|
---|
88 | { "--help", 'h', 0 }
|
---|
89 | };
|
---|
90 |
|
---|
91 | int ch;
|
---|
92 | RTGETOPTUNION ValueUnion;
|
---|
93 | RTGETOPTSTATE GetState;
|
---|
94 | RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
|
---|
95 | while ((ch = RTGetOpt(&GetState, &ValueUnion)))
|
---|
96 | {
|
---|
97 | switch (ch)
|
---|
98 | {
|
---|
99 | case VINF_GETOPT_NOT_OPTION:
|
---|
100 | {
|
---|
101 | void *pvImageBase;
|
---|
102 | rc = SUPR3LoadModule(ValueUnion.psz, RTPathFilename(ValueUnion.psz), &pvImageBase);
|
---|
103 | if (RT_FAILURE(rc))
|
---|
104 | {
|
---|
105 | RTMsgError("%Rrc when attempting to load '%s'\n", rc, ValueUnion.psz);
|
---|
106 | return 1;
|
---|
107 | }
|
---|
108 | RTPrintf("Loaded '%s' at %p\n", ValueUnion.psz, pvImageBase);
|
---|
109 |
|
---|
110 | rc = SUPR3FreeModule(pvImageBase);
|
---|
111 | if (RT_FAILURE(rc))
|
---|
112 | {
|
---|
113 | RTMsgError("%Rrc when attempting to load '%s'\n", rc, ValueUnion.psz);
|
---|
114 | return 1;
|
---|
115 | }
|
---|
116 | break;
|
---|
117 | }
|
---|
118 |
|
---|
119 | case 'h':
|
---|
120 | RTPrintf("%s [mod1 [mod2...]]\n");
|
---|
121 | return 1;
|
---|
122 |
|
---|
123 | default:
|
---|
124 | return RTGetOptPrintError(ch, &ValueUnion);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | return 0;
|
---|
129 | }
|
---|
130 |
|
---|