load.c revision 236b6e0fdf652661ff4c655314fe488998c5c17d
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#include "cr_spu.h"
#include "cr_net.h"
#include "cr_error.h"
#include "cr_mem.h"
#include "cr_string.h"
#include "cr_net.h"
#include "cr_environment.h"
#include "cr_process.h"
#include "cr_rand.h"
#include "cr_netserver.h"
#include "stub.h"
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#ifndef WINDOWS
#include <unistd.h>
#endif
#ifdef CHROMIUM_THREADSAFE
#include "cr_threads.h"
#endif
/**
* If you change this, see the comments in tilesortspu_context.c
*/
#define MAGIC_CONTEXT_BASE 500
#define CONFIG_LOOKUP_FILE ".crconfigs"
#ifdef WINDOWS
#define PYTHON_EXE "python.exe"
#else
#define PYTHON_EXE "python"
#endif
#ifdef WINDOWS
#endif
static int stub_initialized = 0;
/* NOTE: 'SPUDispatchTable glim' is declared in NULLfuncs.py now */
/* NOTE: 'SPUDispatchTable stubThreadsafeDispatch' is declared in tsfuncs.c */
static void stubInitNativeDispatch( void )
{
#define MAX_FUNCS 1000
int numFuncs;
/* XXX call this after context binding */
}
/** Pointer to the SPU's real glClear and glViewport functions */
static ClearFunc_t origClear;
static ViewportFunc_t origViewport;
static SwapBuffersFunc_t origSwapBuffers;
static DrawBufferFunc_t origDrawBuffer;
static ScissorFunc_t origScissor;
static void stubCheckWindowState(void)
{
bool bForceUpdate = false;
if (!stub.currentContext)
return;
#ifdef WINDOWS
/* @todo install hook and track for WM_DISPLAYCHANGE */
{
{
crDebug("Resolution changed(%d,%d), forcing window Pos/Size update", devMode.dmPelsWidth, devMode.dmPelsHeight);
bForceUpdate = true;
}
}
#endif
{
}
#endif
}
}
}
/**
* Override the head SPU's glClear function.
* We're basically trapping this function so that we can poll the
* application window size at a regular interval.
*/
{
/* call the original SPU glClear function */
}
/**
* As above, but for glViewport. Most apps call glViewport before
* glClear when a window is resized.
*/
{
/* call the original SPU glViewport function */
if (!stub.viewportHack)
{
origViewport(x, y, w, h);
}
else
{
}
}
{
}
{
}
{
}
/**
* Use the GL function pointers in <spu> to initialize the static glim
* dispatch table.
*/
{
if (stub.viewportHack)
/*stub.spuDispatch.SwapBuffers = trapSwapBuffers;
stub.spuDispatch.DrawBuffer = trapDrawBuffer;*/
}
}
// Callback function, used to destroy all created contexts
{
}
/**
* This is called when we exit.
* We call all the SPU's cleanup functions.
*/
static void stubSPUTearDown(void)
{
crDebug("stubSPUTearDown");
if (!stub_initialized) return;
stub_initialized = 0;
#ifdef WINDOWS
#endif
//delete all created contexts
/* shutdown, now trap any calls to a NULL dispatcher */
#ifndef Linux
#endif
#ifdef GLX
{
}
#endif
}
static void stubSPUSafeTearDown(void)
{
#ifdef CHROMIUM_THREADSAFE
#endif
if (!stub_initialized) return;
stub_initialized = 0;
#ifdef CHROMIUM_THREADSAFE
#endif
crDebug("stubSPUSafeTearDown");
#ifdef WINDOWS
#endif
#ifdef CHROMIUM_THREADSAFE
#endif
}
static void stubExitHandler(void)
{
}
/**
* Called when we receive a SIGTERM signal.
*/
static void stubSignalHandler(int signo)
{
exit(0); /* this causes stubExitHandler() to be called */
}
/**
* Init variables in the stub structure, install signal handler.
*/
static void stubInitVars(void)
{
#ifdef CHROMIUM_THREADSAFE
#endif
/* At the very least we want CR_RGB_BIT. */
stub.appDrawCursor = 0;
stub.trackWindowSize = 0;
stub.trackWindowPos = 0;
stub.mothershipPID = 0;
#ifdef WINDOWS
defaultWin->cVisibleRegions = 0;
#endif
#if 1
#ifndef WINDOWS
#endif
#else
(void) stubExitHandler;
(void) stubSignalHandler;
#endif
}
/**
* Return a free port number for the mothership to use, or -1 if we
* can't find one.
*/
static int
GenerateMothershipPort(void)
{
const int MAX_PORT = 10100;
unsigned short port;
/* generate initial port number randomly */
#ifdef WINDOWS
/* XXX should implement a free port check here */
return port;
#else
/*
* See if this port number really is free, try another if needed.
*/
{
struct sockaddr_in servaddr;
int so_reuseaddr = 1;
int sock, k;
/* create socket */
(char *) &so_reuseaddr, sizeof(so_reuseaddr));
CRASSERT(k == 0);
/* initialize the servaddr struct */
/* Bind to the given port number, return -1 if we fail */
if (k) {
/* failed to create port. try next one. */
port++;
}
else {
return port;
}
}
}
#endif /* WINDOWS */
return -1;
}
/**
* Try to determine which mothership configuration to use for this program.
*/
static char **
LookupMothershipConfig(const char *procName)
{
FILE *f;
const char *home;
char configPath[1000];
/* first, check if the CR_CONFIG env var is set */
{
}
/* second, look up config name from config file */
if (home)
else
/* Check if the CR_CONFIG_PATH env var is set. */
{
if (conf)
}
if (!f) {
return NULL;
}
while (!feof(f)) {
char line[1000];
char **args;
{
crWarning("Using Chromium configuration for %s from %s",
return args;
}
}
fclose(f);
return NULL;
}
static int Mothership_Awake = 0;
/**
* Signal handler to determine when mothership is ready.
*/
static void
MothershipPhoneHome(int signo)
{
Mothership_Awake = 1;
}
void stubSetDefaultConfigurationOptions(void)
{
unsigned char key[16]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
stub.appDrawCursor = 0;
stub.numIgnoreWindowID = 0;
crNetSetRank(0);
stub.force_pbuffers = 0;
stub.viewportHack = 0;
#ifdef WINDOWS
{
char name[1000];
int i;
for (i=0; gsViewportHackApps[i]; ++i)
{
{
break;
}
}
}
#endif
}
/**
* Do one-time initializations for the faker.
* Returns TRUE on success, FALSE otherwise.
*/
bool
stubInit(void)
{
/* Here is where we contact the mothership to find out what we're supposed
* to be doing. Networking code in a DLL initializer. I sure hope this
* works :)
*
* HOW can I pass the mothership address to this if I already know it?
*/
char response[1024];
char **spuchain;
int num_spus;
int *spu_ids;
char **spu_names;
const char *app_id;
int i;
if (stub_initialized)
return true;
stubInitVars();
/* @todo check if it'd be of any use on other than guests, no use for windows */
#ifndef WINDOWS
{
{
crWarning("Failed to connect to host. Make sure 3D acceleration is enabled for this VM.");
return false;
}
else
{
}
}
#endif
for (i = 0 ; i < num_spus ; i++)
{
}
for (i = 0; i < num_spus; ++i)
// spu chain load failed somewhere
return false;
}
/* This is unlikely to change -- We still want to initialize our dispatch
* table with the functions of the first SPU in the chain. */
/* we need to plug one special stub function into the dispatch table */
#if !defined(VBOX_NO_NATIVEGL)
/* Load pointers to native OpenGL functions into stub.nativeDispatch */
#endif
/*crDebug("stub init");
raise(SIGINT);*/
#ifdef WINDOWS
#endif
#ifdef GLX
#endif
stub_initialized = 1;
return true;
}
/* Sigh -- we can't do initialization at load time, since Windows forbids
* the loading of other libraries from DLLMain. */
#ifdef LINUX
/* GCC crap
*void (*stub_init_ptr)(void) __attribute__((section(".ctors"))) = __stubInit; */
#endif
#ifdef WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* Windows crap */
{
(void) lpvReserved;
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
{
{
crDebug("Failed to connect to host (is guest 3d acceleration enabled?), aborting ICD load.");
return FALSE;
}
else
break;
}
case DLL_PROCESS_DETACH:
{
break;
}
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
default:
break;
}
return TRUE;
}
#endif