예제 #1
0
 public static void InitType(Type ty)
 {
     VTable.initType((RuntimeType)ty);
 }
예제 #2
0
        public static unsafe int AppStart(Type userClass)
        {
            System.GCs.Transitions.ThreadStart();

            int result = 0;

            string arg0 = "(unknown)";

            try {
                Tracing.Log(Tracing.Audit, "Runtime.Main()");

                // Initialize the primitive runtime, which calls the
                // class constructor for Runtime().
                VTable.Initialize((RuntimeType)typeof(AppRuntime));
                //VTable.ParseArgs(args);

                Tracing.Log(Tracing.Audit, "Enabling GC Heap");
                GC.EnableHeap();
                Controller.InitializeSystem();
                GCProfilerLogger.StartProfiling();

                InitializeConsole();

                SetDebuggerPresence(DebugService.IsDebuggerPresent());

                int argCount  = 0;
                int argMaxLen = 0;
                for (;; argCount++)
                {
                    int len = ProcessService.GetStartupArg(argCount, null, 0);
                    if (len == 0)
                    {
                        break;
                    }
                    if (argMaxLen < len)
                    {
                        argMaxLen = len;
                    }
                }
                char[]   argArray = new char [argMaxLen];
                string[] args     = new string[argCount];
                for (int arg = 0; arg < argCount; arg++)
                {
                    fixed(char *argptr = &argArray[0])
                    {
                        int len = ProcessService.GetStartupArg(arg,
                                                               argptr,
                                                               argArray.Length);

                        args[arg] = String.StringCTOR(argptr, 0, len);
                        if (arg == 0)
                        {
                            arg0 = args[arg];
                        }
                    }
                }

#if DEBUG || true
                // Record the first argument passed to this program, under the assumption that
                // this is the application name.  We use this string in DebugStub.WriteLine.
                // Also, if the name has an extension, such as ".x86", chop it off.
                // Also chop off any path prefix, such as "/init/".
                appName = arg0;
                int index = appName.LastIndexOf('.');
                if (index != -1)
                {
                    appName = appName.Substring(0, index);
                }
                index = appName.LastIndexOf('/');
                if (index != -1)
                {
                    appName = appName.Substring(index + 1);
                }

                // The default DebugName value for the main thread is "main";
                // apps can override this by setting Thread.CurrentThread.DebugName.
                Thread mainThread = Thread.CurrentThread;
                if (mainThread != null)
                {
                    mainThread.DebugName = "main";
                }
#endif

                if (userClass != null)
                {
                    VTable.initType((RuntimeType)userClass);
                }

                result = CallMain(args);
                if (!MainReturnsInt())
                {
                    result = 0;
                }

                Tracing.Log(Tracing.Audit, "Main thread exited [{0}]",
                            (UIntPtr) unchecked ((uint)result));
            }
            catch (Exception e) {
                Tracing.Log(Tracing.Fatal, "Failed with exception {0}.{1}",
                            e.GetType().Namespace, e.GetType().Name);
                Tracing.Log(Tracing.Trace, "Exception message was {0}",
                            e.ToString());
                TopLevelException(e);
                result = -1;
            }

            Thread.RemoveThread(Thread.CurrentThread.threadIndex);
            Thread.JoinAll();

            try {
                FinalizeConsole();
            }
            catch (Exception e) {
                Tracing.Log(Tracing.Fatal, "An exception occurred while shutting down the console: {0}",
                            e.ToString());
            }

            Controller.Finalize();
            Tracing.Log(Tracing.Audit, "Runtime shutdown started.");
            VTable.Shutdown(result);
            Tracing.Log(Tracing.Audit, "Runtime exiting [{0}]",
                        (UIntPtr) unchecked ((uint)result));
            return(result);
        }