/* virtual */ signed
  application::run()
  {
    TRACE("win::application::run");

    return message_loop();
  }
Exemplo n.º 2
0
Arquivo: memsup.c Projeto: 1153/otp
/*
 *  main
 */
int
MAIN(int argc, char **argv)
{
  program_name = argv[0];
  message_loop(ERLIN_FD);
  return 0;
}
Exemplo n.º 3
0
    void Thread::ThreadMain()
    {
        {
            // 本线程的消息循环.
            MessageLoop message_loop(startup_data_->options.message_loop_type);

            // 完成线程对象的初始化.
            thread_id_ = GetCurrentThreadId();
            SetName(name_.c_str());
            message_loop.set_thread_name(name_);
            message_loop_ = &message_loop;
            message_loop_proxy_ = MessageLoopProxy::CreateForCurrentThread();

            // 允许线程做额外的初始化工作, 在通知启动线程前调用.
            Init();

            startup_data_->event.Signal();
            // 不能再使用startup_data_, 因为启动线程此时已经解锁.

            Run(message_loop_);

            // 允许线程做额外的清理工作.
            CleanUp();

            // 断言MessageLoop::Quit是被ThreadQuitTask调用的.
            DCHECK(GetThreadWasQuitProperly());

            // 不再接受任何消息.
            message_loop_ = NULL;
            message_loop_proxy_ = NULL;
        }
        CleanUpAfterMessageLoopDestruction();
        thread_id_ = 0;
    }
Exemplo n.º 4
0
int main(int argc, char **argv)
{
    if (argc < 3)
        err_quit("usage: lan_chat <subnet-address> <user-name> <start-idx>");

    subnet_address = argv[1];
    if (!inet_aton(subnet_address, NULL))
        err_quit("The subnet address must be a valid IPv4 address");

    user_name = argv[2];
    if (strlen(user_name) > 10)
        err_quit("The user_name must be at most 10 characters");

    if (argc == 4)
        start_idx = atoi(argv[3]);

    /*
     * Spawns a listener process which accepts any connection and outputs each
     * received message on the terminal.
     */
    int listenerpid = spawn_listener(CHAT_PORT);

    /*
     * Connects to a listener and waits for user input. On each new line input
     * by user, creates a message according to the protocol and sends it over
     * the socket.
     */
    int sockfd = connect_to_listener();
    message_loop(sockfd);


    kill(listenerpid, SIGKILL);
    exit(0);
}
Exemplo n.º 5
0
int main(int argc, char ** argv){

    _setmode(0, _O_BINARY);
    _setmode(1, _O_BINARY);
    load_if_possible();
    message_loop();
    return 0;    
}
void
MozillaChildThread::Init()
{
  ChildThread::Init();

#ifdef XP_WIN
  // Silverlight depends on the host calling CoInitialize.
  ::CoInitialize(NULL);
#endif

  // Certain plugins, such as flash, steal the unhandled exception filter
  // thus we never get crash reports when they fault. This call fixes it.
  message_loop()->set_exception_restoration(true);

  NS_LogInit();
}
Exemplo n.º 7
0
	void Thread::ThreadMain(){
		{
			assert(startup_data_ != nullptr);
			//note: we can only create message loop here because of the tls feature.
			MessageLoop message_loop(startup_data_->options_.message_loop_type_);
			message_loop_ = &message_loop;
			thread_id_ = ThreadHelper::CurrentId();
			SetUp();
			// wait message loop to be created.
			startup_data_->event_.Signal();
			//from now on you can never use startup data.
			Run(message_loop_);
			TearDown();
			message_loop_ = nullptr;
		}
		thread_id_ = kInvalidThreadId;
	}
Exemplo n.º 8
0
void CRenderDevice::Run			()
{
//	DUMP_PHASE;
	g_bLoaded		= FALSE;
	Log				("Starting engine...");
	thread_name		("X-RAY Primary thread");

	// Startup timers and calculate timer delta
	dwTimeGlobal				= 0;
	Timer_MM_Delta				= 0;
	{
		u32 time_mm			= timeGetTime	();
		while (timeGetTime()==time_mm);			// wait for next tick
		u32 time_system		= timeGetTime	();
		u32 time_local		= TimerAsync	();
		Timer_MM_Delta		= time_system-time_local;
	}

	// Start all threads
//	InitializeCriticalSection	(&mt_csEnter);
//	InitializeCriticalSection	(&mt_csLeave);
	mt_csEnter.Enter			();
	mt_bMustExit				= FALSE;
	thread_spawn				(mt_Thread,"X-RAY Secondary thread",0,0);

	// Message cycle
	seqAppStart.Process			(rp_AppStart);

	//CHK_DX(HW.pDevice->Clear(0,0,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1,0));
	m_pRender->ClearTarget		();

	message_loop				();

	seqAppEnd.Process		(rp_AppEnd);

	// Stop Balance-Thread
	mt_bMustExit			= TRUE;
	mt_csEnter.Leave		();
	while (mt_bMustExit)	Sleep(0);
//	DeleteCriticalSection	(&mt_csEnter);
//	DeleteCriticalSection	(&mt_csLeave);
}
bool
PluginProcessChild::Init()
{
#if defined(XP_MACOSX)
    // Remove the trigger for "dyld interposing" that we added in
    // GeckoChildProcessHost::PerformAsyncLaunchInternal(), in the host
    // process just before we were launched.  Dyld interposing will still
    // happen in our process (the plugin child process).  But we don't want
    // it to happen in any processes that the plugin might launch from our
    // process.
    nsCString interpose(PR_GetEnv("DYLD_INSERT_LIBRARIES"));
    if (!interpose.IsEmpty()) {
        // If we added the path to libplugin_child_interpose.dylib to an
        // existing DYLD_INSERT_LIBRARIES, we appended it to the end, after a
        // ":" path seperator.
        int32_t lastSeparatorPos = interpose.RFind(":");
        int32_t lastTriggerPos = interpose.RFind("libplugin_child_interpose.dylib");
        bool needsReset = false;
        if (lastTriggerPos != -1) {
            if (lastSeparatorPos == -1) {
                interpose.Truncate();
                needsReset = true;
            } else if (lastTriggerPos > lastSeparatorPos) {
                interpose.SetLength(lastSeparatorPos);
                needsReset = true;
            }
        }
        if (needsReset) {
            nsCString setInterpose("DYLD_INSERT_LIBRARIES=");
            if (!interpose.IsEmpty()) {
                setInterpose.Append(interpose);
            }
            // Values passed to PR_SetEnv() must be seperately allocated.
            char* setInterposePtr = strdup(setInterpose.get());
            PR_SetEnv(setInterposePtr);
        }
    }
#endif

#ifdef XP_WIN
    // Drag-and-drop needs OleInitialize to be called, and Silverlight depends
    // on the host calling CoInitialize (which is called by OleInitialize).
    ::OleInitialize(nullptr);
#endif

    // Certain plugins, such as flash, steal the unhandled exception filter
    // thus we never get crash reports when they fault. This call fixes it.
    message_loop()->set_exception_restoration(true);

    std::string pluginFilename;

#if defined(OS_POSIX)
    // NB: need to be very careful in ensuring that the first arg
    // (after the binary name) here is indeed the plugin module path.
    // Keep in sync with dom/plugins/PluginModuleParent.
    std::vector<std::string> values = CommandLine::ForCurrentProcess()->argv();
    NS_ABORT_IF_FALSE(values.size() >= 2, "not enough args");

    pluginFilename = UnmungePluginDsoPath(values[1]);

#elif defined(OS_WIN)
    std::vector<std::wstring> values =
        CommandLine::ForCurrentProcess()->GetLooseValues();
    NS_ABORT_IF_FALSE(values.size() >= 1, "not enough loose args");

    if (ShouldProtectPluginCurrentDirectory(values[0].c_str())) {
        SanitizeEnvironmentVariables();
        SetDllDirectory(L"");
    }

    pluginFilename = WideToUTF8(values[0]);
#else
#  error Sorry
#endif

    if (NS_FAILED(nsRegion::InitStatic())) {
      NS_ERROR("Could not initialize nsRegion");
      return false;
    }

    return mPlugin.Init(pluginFilename, ParentHandle(),
                        IOThreadChild::message_loop(),
                        IOThreadChild::channel());
}
Exemplo n.º 10
0
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                       _In_opt_ HINSTANCE hPrevInstance,
                       _In_ LPTSTR    lpCmdLine,
                       _In_ int       nCmdShow)
{
  UNREFERENCED_PARAMETER(hInstance);
  UNREFERENCED_PARAMETER(hPrevInstance);
  UNREFERENCED_PARAMETER(lpCmdLine);
  UNREFERENCED_PARAMETER(nCmdShow);
  debug_log("starting process");

  // Prevent error dialogs.
  _set_error_mode(_OUT_TO_STDERR);
  _CrtSetReportHook(CrtDbgHook);
  SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
      SEM_NOOPENFILEERRORBOX);

  // The Visual Studio debugger starts us in the build\ subdirectory by
  // default, which will prevent us from finding the test files in the html\
  // directory. This workaround will locate the html\ directory even if it's
  // in the parent directory so we will work in the debugger out of the box.
  WIN32_FIND_DATA find_data;
  HANDLE h = FindFirstFile("html", &find_data);
  if (h == INVALID_HANDLE_VALUE) {
    h = FindFirstFile("..\\html", &find_data);
    if (h != INVALID_HANDLE_VALUE) {
      SetCurrentDirectory("..");
    }
  }
  if (h != INVALID_HANDLE_VALUE) {
    FindClose(h);
  }

  // Prevent automatic DPI scaling.
  SetProcessDPIAware();

  if (__argc == 1) {
    debug_log("running server");
    HDC desktop = GetDC(NULL);
    assert(desktop);
    if (GetDeviceCaps(desktop, LOGPIXELSX) != 96) {
      MessageBox(NULL, "Warning: DPI scaling is enabled. Non-DPI-aware browsers will not be able to run the test.",
                 "Warning", MB_ICONWARNING | MB_OK);
    }
    ReleaseDC(NULL, desktop);
    run_server();
  }
  debug_log("opening native reference window");
  if (__argc != 3) {
    debug_log("Unrecognized number of arguments");
    return 1;
  }
  // The first argument is the magic pattern to draw on the window, encoded as hex.
  memset(pattern, 0, sizeof(pattern));
  if (!parse_hex_magic_pattern(__argv[1], pattern)) {
    debug_log("Failed to parse pattern");
    return 1;
  }
  // The second argument is the handle of the parent process.
  HANDLE parent_process = (HANDLE)_strtoui64(__argv[2], NULL, 16);
  message_loop(parent_process);
  return 0;
}
Exemplo n.º 11
0
int main(int argc, char **argv) {
	int result = 0;
	int i;

  userui_ops[0] = &userui_text_ops;
	userui_ops[1] = FBSPLASH_OPS;
	userui_ops[2] = USPLASH_OPS;
	active_ops = &userui_text_ops;

	handle_params(argc, argv);
	setup_signal_handlers();
	open_console();
	open_misc();
	if (!test_run) {
		open_netlink();
		get_nofreeze();
		get_info();
	}

	lock_memory();

	prepare_console();

	/* Initialise all that we can, use the first */
//  active_ops = NULL;
	for (i = 0; i < NUM_UIS; i++) {
		if (userui_ops[i] && userui_ops[i]->load) {
			result = userui_ops[i]->load();
			if (result) {
				if (test_run)
					fprintf(stderr, "Failed to initialise %s module.\n", userui_ops[i]->name);
				else
					printk("Failed to initialise %s module.\n", userui_ops[i]->name);
			} else
				if (!active_ops)
					active_ops = userui_ops[i];
		}
	}

	if (active_ops->prepare)
		active_ops->prepare();

	register_keypress_handler();

	need_cleanup = 1;
	running = 1;

	result = nice(1);

	if (active_ops->memory_required)
		reserve_memory(active_ops->memory_required());
	else
		reserve_memory(4*1024*1024); /* say 4MB */

	enforce_lifesavers();

	if (test_run) {
		safe_to_exit = 0;

		do_test_run();
		return 0;
	}

	if (send_ready())
		message_loop();

	/* The only point we ever reach here is if message_loop crashed out.
	 * If this is the case, we should spin for a few hours before exiting to
	 * ensure that we don't corrupt stuff on disk (if we're past the atomic
	 * copy).
	 */
	sleep(60*60*1); /* 1 hours */
	_exit(1);
}
Exemplo n.º 12
0
/* entry point */
int main(int ac, char **av)
{
    int ret;

    memset(&ctx, 0, sizeof(ctx));

    /* instance handle of this module */
    {
        HMODULE module;

        module = GetModuleHandle(NULL);
        if(module == NULL) {
            error_message_le("GetModuleHandle() failed");
            return 1;
        }

        ctx.instance = (HINSTANCE)module;
    }

    /* initialize COM */
    {
        HRESULT hres;

        hres = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
        if(FAILED(hres)) {
            error_message_hr("CoInitializeEx() failed", hres);
            return 1;
        }

        hres = init_regexp();
        if(FAILED(hres)) {
            error_message_hr("init_regexp() failed", hres);
            return 1;
        }
    }

    /* create main message window */
    ctx.main_window = create_main_window();
    if(ctx.main_window == NULL) {
        error_message_le("create_main_window() failed");
        return 1;
    }

    /* logger */
    ret = create_logger();
    if(ret == 0) {
        error_message_le("create_logger() failed");
        return 1;
    }

    ctx.sprocs.hdr.api_ver = MP_OP_API_VERSION;
    ctx.sprocs.hdr.type = MP_OP_TYPE_SUPPORT;
    ctx.sprocs.log_printf = log_printf;
    ctx.sprocs.log_s_exp = log_print_s_exp;
    ctx.sprocs.log_lasterror = log_print_lasterror;
    ctx.sprocs.log_hresult = log_print_hresult;

    /* command line option */
    {
        LPWSTR *avw, file;
        int acw;

        avw = CommandLineToArgvW(GetCommandLineW(), &acw);
        if(avw != NULL && acw >= 2) {
            file = avw[1];
        } else {
            file = NULL;
        }

        /* load setting file */
        load_setting(file, TRUE);
    }

    /* start message */
    log_printf(LOG_LEVEL_NOTIFY, L"\nmouse-processor started\n");

    /* main message loop */
    ret = message_loop();

    /* uninitialize COM */
    CoUninitialize();

    /* end logger */
    destroy_logger();

    return ret;
}
Exemplo n.º 13
0
bool
PluginProcessChild::Init()
{
    nsDebugImpl::SetMultiprocessMode("NPAPI");

#if defined(XP_MACOSX)
    // Remove the trigger for "dyld interposing" that we added in
    // GeckoChildProcessHost::PerformAsyncLaunchInternal(), in the host
    // process just before we were launched.  Dyld interposing will still
    // happen in our process (the plugin child process).  But we don't want
    // it to happen in any processes that the plugin might launch from our
    // process.
    nsCString interpose(PR_GetEnv("DYLD_INSERT_LIBRARIES"));
    if (!interpose.IsEmpty()) {
        // If we added the path to libplugin_child_interpose.dylib to an
        // existing DYLD_INSERT_LIBRARIES, we appended it to the end, after a
        // ":" path seperator.
        int32_t lastSeparatorPos = interpose.RFind(":");
        int32_t lastTriggerPos = interpose.RFind("libplugin_child_interpose.dylib");
        bool needsReset = false;
        if (lastTriggerPos != -1) {
            if (lastSeparatorPos == -1) {
                interpose.Truncate();
                needsReset = true;
            } else if (lastTriggerPos > lastSeparatorPos) {
                interpose.SetLength(lastSeparatorPos);
                needsReset = true;
            }
        }
        if (needsReset) {
            nsCString setInterpose("DYLD_INSERT_LIBRARIES=");
            if (!interpose.IsEmpty()) {
                setInterpose.Append(interpose);
            }
            // Values passed to PR_SetEnv() must be seperately allocated.
            char* setInterposePtr = strdup(setInterpose.get());
            PR_SetEnv(setInterposePtr);
        }
    }
#endif

#ifdef XP_WIN
    // Drag-and-drop needs OleInitialize to be called, and Silverlight depends
    // on the host calling CoInitialize (which is called by OleInitialize).
    ::OleInitialize(nullptr);
#endif

    // Certain plugins, such as flash, steal the unhandled exception filter
    // thus we never get crash reports when they fault. This call fixes it.
    message_loop()->set_exception_restoration(true);

    std::string pluginFilename;

#if defined(OS_POSIX)
    // NB: need to be very careful in ensuring that the first arg
    // (after the binary name) here is indeed the plugin module path.
    // Keep in sync with dom/plugins/PluginModuleParent.
    std::vector<std::string> values = CommandLine::ForCurrentProcess()->argv();
    MOZ_ASSERT(values.size() >= 2, "not enough args");

    pluginFilename = UnmungePluginDsoPath(values[1]);

#elif defined(OS_WIN)
    std::vector<std::wstring> values =
        CommandLine::ForCurrentProcess()->GetLooseValues();
    MOZ_ASSERT(values.size() >= 1, "not enough loose args");

    if (ShouldProtectPluginCurrentDirectory(values[0].c_str())) {
        SanitizeEnvironmentVariables();
        SetDllDirectory(L"");
    }

    pluginFilename = WideToUTF8(values[0]);

#if defined(MOZ_SANDBOX)
    // This is probably the earliest we would want to start the sandbox.
    // As we attempt to tighten the sandbox, we may need to consider moving this
    // to later in the plugin initialization.
    mozilla::SandboxTarget::Instance()->StartSandbox();
#endif
#else
#  error Sorry
#endif

    if (NS_FAILED(nsRegion::InitStatic())) {
      NS_ERROR("Could not initialize nsRegion");
      return false;
    }

    bool retval = mPlugin.InitForChrome(pluginFilename, ParentPid(),
                                        IOThreadChild::message_loop(),
                                        IOThreadChild::channel());
#if defined(XP_MACOSX)
    if (nsCocoaFeatures::OnYosemiteOrLater()) {
      // Explicitly turn off CGEvent logging.  This works around bug 1092855.
      // If there are already CGEvents in the log, turning off logging also
      // causes those events to be written to disk.  But at this point no
      // CGEvents have yet been processed.  CGEvents are events (usually
      // input events) pulled from the WindowServer.  An option of 0x80000008
      // turns on CGEvent logging.
      CGSSetDebugOptions(0x80000007);
    }
#endif
    return retval;
}
Exemplo n.º 14
0
Arquivo: swnd.c Projeto: goriy/sif
// main function.
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinst, LPSTR cmdline, int show)
{
  instance = hinstance;
  InitCommonControls();
  register_classes();
  h_font = CreateFont(-11, 0, 0, 0, FW_NORMAL, 0,
              0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
              DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif");


  GetModuleFileName(NULL, MyPath, sizeof(MyPath));
  //fprintf (stderr, "MyPath = %s\n", MyPath);
  if (!SHGetSpecialFolderPath(NULL, ConfigPath, CSIDL_LOCAL_APPDATA, 0))  {
    //fprintf (stderr, "Cannot determine LocalAppData folder\n");
  }
  else  {
  }
  strcat (ConfigPath, "\\.sif2\\");
  _mkdir (ConfigPath);
  //fprintf (stderr, "ConfigPath = %s\n", ConfigPath);

  config_init ();

  hMainWindow = create_wnd0();

  memset (&clfnt, 0, sizeof(clfnt));
  clfnt.lfHeight = -MulDiv(OptFontHeight, GetDeviceCaps(GetDC(hMainWindow), LOGPIXELSY), 72);
  clfnt.lfWidth = 0;
  clfnt.lfEscapement = 0;
  clfnt.lfOrientation = 0;
  clfnt.lfWeight = FW_NORMAL;
  clfnt.lfItalic = 0;
  clfnt.lfUnderline = 0;
  clfnt.lfStrikeOut = 0;
  clfnt.lfCharSet = RUSSIAN_CHARSET;
  clfnt.lfOutPrecision = OUT_DEFAULT_PRECIS;
  clfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  clfnt.lfQuality =  DEFAULT_QUALITY;
  clfnt.lfPitchAndFamily = DEFAULT_PITCH | FF_MODERN;
  strcpy (clfnt.lfFaceName, OptFontFace);

  h_font_code = CreateFontIndirect(&clfnt);

  create_wnd_content0(hMainWindow);

  _fullpath (CurrentPath, ".", sizeof(CurrentPath));
  strcat (CurrentPath, "\\");
  current_path_to_edit ();

  SetFocus(GetDlgItem(hMainWindow, IDC_TXT));
  resize_controls ();

  recent_load ();
  recent_fill_combo (IDC_RECENT);

  set_options ();
  populate_dir ();

  search_init ();

  hDlgCurrent = hMainWindow;

  if (!SHGetSpecialFolderPath(NULL, SendtoPath, CSIDL_SENDTO, 0))  {
    //fprintf (stderr, "Cannot determine SendTo folder\n");
  }
  else  {
    //fprintf (stderr, "SendtoPath = %s\n", SendtoPath);
  }

  strcat (SendtoPath, "\\Search in files.lnk");

  if (CreateShortCut(MyPath, "", SendtoPath, "Search in files", SW_SHOWNORMAL, "", "", 0) < 0)  {
    //fprintf (stderr, "Error create shortcut %ld\n", GetLastError());
  }

  do_gui_main_action (cmdline);
  return message_loop();
}