void SetException(DWORD code, EXCEPTION_RECORD *pr)
{
TCHAR *lpMsgBuf;
lpMsgBuf = FormatError(code);
if(lpMsgBuf) {
PyErr_SetFromWindowsErr(code);
LocalFree(lpMsgBuf);
} else {
switch (code) {
case EXCEPTION_ACCESS_VIOLATION:
/* The thread attempted to read from or write
to a virtual address for which it does not
have the appropriate access. */
if (pr->ExceptionInformation[0] == 0)
PyErr_Format(PyExc_WindowsError,
"exception: access violation reading %p",
pr->ExceptionInformation[1]);
else
PyErr_Format(PyExc_WindowsError,
"exception: access violation writing %p",
pr->ExceptionInformation[1]);
break;
case EXCEPTION_BREAKPOINT:
/* A breakpoint was encountered. */
PyErr_SetString(PyExc_WindowsError,
"exception: breakpoint encountered");
break;
case EXCEPTION_DATATYPE_MISALIGNMENT:
/* The thread attempted to read or write data that is
misaligned on hardware that does not provide
alignment. For example, 16-bit values must be
aligned on 2-byte boundaries, 32-bit values on
4-byte boundaries, and so on. */
PyErr_SetString(PyExc_WindowsError,
"exception: datatype misalignment");
break;
case EXCEPTION_SINGLE_STEP:
/* A trace trap or other single-instruction mechanism
signaled that one instruction has been executed. */
PyErr_SetString(PyExc_WindowsError,
"exception: single step");
break;
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
/* The thread attempted to access an array element
that is out of bounds, and the underlying hardware
supports bounds checking. */
PyErr_SetString(PyExc_WindowsError,
"exception: array bounds exceeded");
break;
case EXCEPTION_FLT_DENORMAL_OPERAND:
/* One of the operands in a floating-point operation
is denormal. A denormal value is one that is too
small to represent as a standard floating-point
value. */
PyErr_SetString(PyExc_WindowsError,
"exception: floating-point operand denormal");
break;
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
/* The thread attempted to divide a floating-point
value by a floating-point divisor of zero. */
PyErr_SetString(PyExc_WindowsError,
"exception: float divide by zero");
break;
case EXCEPTION_FLT_INEXACT_RESULT:
/* The result of a floating-point operation cannot be
represented exactly as a decimal fraction. */
PyErr_SetString(PyExc_WindowsError,
"exception: float inexact");
break;
case EXCEPTION_FLT_INVALID_OPERATION:
/* This exception represents any floating-point
exception not included in this list. */
PyErr_SetString(PyExc_WindowsError,
"exception: float invalid operation");
break;
case EXCEPTION_FLT_OVERFLOW:
/* The exponent of a floating-point operation is
greater than the magnitude allowed by the
corresponding type. */
PyErr_SetString(PyExc_WindowsError,
"exception: float overflow");
break;
case EXCEPTION_FLT_STACK_CHECK:
/* The stack overflowed or underflowed as the result
of a floating-point operation. */
PyErr_SetString(PyExc_WindowsError,
"exception: stack over/underflow");
break;
case EXCEPTION_STACK_OVERFLOW:
/* The stack overflowed or underflowed as the result
//.........这里部分代码省略.........
开发者ID:pieper,项目名称:python,代码行数:101,代码来源:callproc.c
示例6: OpenPortalHandleFromGUID
BOOL OpenPortalHandleFromGUID(GUID guid, PHANDLE phPortalHandle)
{
int memberIndex = 0;
BOOL bResult = TRUE;
HDEVINFO hDevInfo;
SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA pInterfaceDetailData = NULL;
HIDD_ATTRIBUTES attributes;
ULONG requiredLength=0;
hDevInfo = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
deviceInterfaceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
*phPortalHandle = NULL;
for(memberIndex = 0;
SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &guid, memberIndex, &deviceInterfaceData);
memberIndex++)
{
SetupDiGetDeviceInterfaceDetail(hDevInfo, &deviceInterfaceData, NULL, 0, &requiredLength, NULL);
//we got the size, allocate buffer
pInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LPTR, requiredLength);
assert(pInterfaceDetailData);
//get the interface detailed data
pInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if (!SetupDiGetDeviceInterfaceDetail(hDevInfo, &deviceInterfaceData, pInterfaceDetailData, requiredLength, &requiredLength, NULL))
{
continue;
}
*phPortalHandle = CreateFile (
pInterfaceDetailData->DevicePath,
GENERIC_EXECUTE | GENERIC_ALL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
LocalFree(pInterfaceDetailData);
pInterfaceDetailData = NULL;
if(guid == xbox_guid) {
break; // we are done. xbox_guid does not have HID attributes
}
if (*phPortalHandle != INVALID_HANDLE_VALUE)
{
if (HidD_GetAttributes(*phPortalHandle , &attributes))
{
if (((attributes.VendorID == 0x12ba) || (attributes.VendorID == 0x54c)) || (attributes.VendorID == 0x1430))
{
if ((attributes.ProductID == 0x150) || (attributes.ProductID == 0x967))
{
break; // found the portal. leave the handle open
}
}
}
CloseHandle(*phPortalHandle);
*phPortalHandle = NULL;
}
}
SetupDiDestroyDeviceInfoList(hDevInfo);
return (*phPortalHandle != NULL);
}
// get error message from system
const wxChar *wxSysErrorMsg(unsigned long nErrCode)
{
if ( nErrCode == 0 )
nErrCode = wxSysErrorCode();
#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
static wxChar s_szBuf[1024];
// get error message from system
LPVOID lpMsgBuf;
if ( ::FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
nErrCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0,
NULL
) == 0 )
{
// if this happens, something is seriously wrong, so don't use _() here
// for safety
wxSprintf(s_szBuf, wxS("unknown error %lx"), nErrCode);
return s_szBuf;
}
// copy it to our buffer and free memory
// Crashes on SmartPhone (FIXME)
#if !defined(__SMARTPHONE__) /* of WinCE */
if( lpMsgBuf != 0 )
{
wxStrlcpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf));
LocalFree(lpMsgBuf);
// returned string is capitalized and ended with '\r\n' - bad
s_szBuf[0] = (wxChar)wxTolower(s_szBuf[0]);
size_t len = wxStrlen(s_szBuf);
if ( len > 0 ) {
// truncate string
if ( s_szBuf[len - 2] == wxS('\r') )
s_szBuf[len - 2] = wxS('\0');
}
}
else
#endif // !__SMARTPHONE__
{
s_szBuf[0] = wxS('\0');
}
return s_szBuf;
#else // !__WXMSW__
#if wxUSE_UNICODE
static wchar_t s_wzBuf[1024];
wxConvCurrent->MB2WC(s_wzBuf, strerror((int)nErrCode),
WXSIZEOF(s_wzBuf) - 1);
return s_wzBuf;
#else
return strerror((int)nErrCode);
#endif
#endif // __WXMSW__/!__WXMSW__
}
开发者ID:mark711,项目名称:Cafu,代码行数:65,代码来源:log.cpp
示例10: dup
//.........这里部分代码省略.........
StartupInfo.hStdError = mStdErrorHandle;
else
StartupInfo.hStdError =GetStdHandle(STD_ERROR_HANDLE);
if (mStdInputFilename.length())
StartupInfo.hStdInput = mStdInputHandle;
else
StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
if (mStdOutputFilename.length())
StartupInfo.hStdOutput = mStdOutputHandle;
else
StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
//now apply the env variables the user may have set
ApplyEnv();
//3...2...1... LAUNCH!!!!
int retcode = CreateProcess(
NULL,
// name of executable module (null because we want to execute all commands)
// even things such as dir
(char *)cmdLine.data(), // command line string
NULL,
NULL,
//this originally was TRUE but the web browser was never coming back.
FALSE, // handle inheritance flag
// CREATE_NEW_CONSOLE,
CREATE_NO_WINDOW | DETACHED_PROCESS, // creation flags
NULL, // new environment block
startupDir.data(), // startupdir
&StartupInfo,
&ProcessInformation
);
if (retcode != 0)
{
//translate the incoming priority to Wnt values
DWORD wntPrio = NORMAL_PRIORITY_CLASS;
switch(prioClass)
{
case IdlePriorityClass: wntPrio = IDLE_PRIORITY_CLASS;
break;
case NormalPriorityClass: wntPrio = NORMAL_PRIORITY_CLASS;
break;
case HighPriorityClass: wntPrio = HIGH_PRIORITY_CLASS;
break;
case RealtimePriorityClass: wntPrio = REALTIME_PRIORITY_CLASS;
break;
default: osPrintf("**** Invalid process priority class specified!\n");
osPrintf("*** Defaulting to NormalPriorityClass *** \n");
break;
}
if (!SetPriorityClass(ProcessInformation.hProcess, wntPrio))
{
osPrintf("*** Could not change the process priority on launch ***\n");
osPrintf("*** Priority will be the parents priority ! ***\n");
}
if (bExeclusive)
{
//here is where we check if a process by the same name is already running
}
mPID = ProcessInformation.dwProcessId;
mParentPID = getpid();
mhProcess = ProcessInformation.hProcess;
mhThread = ProcessInformation.hThread;
retval = OS_SUCCESS;
}
else
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
osPrintf("***** ERROR FROM LAUNCH: %s",(LPCTSTR)lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
}
/*
dup2(saved_stderr,2);
dup2(saved_stdout,1);
dup2(saved_stdin, 0);
*/
return retval;
}
bool vrpn_Semaphore::init() {
#ifdef sgi
if (vrpn_Semaphore::ppaArena==NULL) {
vrpn_Semaphore::allocArena();
}
if (cResources==1) {
fUsingLock=true;
ps=NULL;
// use lock instead of semaphore
if ((l = usnewlock(vrpn_Semaphore::ppaArena)) == NULL) {
fprintf(stderr,"vrpn_Semaphore::vrpn_Semaphore: error allocating lock from arena.\n");
return false;
}
} else {
fUsingLock=false;
l=NULL;
if ((ps = usnewsema(vrpn_Semaphore::ppaArena, cResources)) == NULL) {
fprintf(stderr,"vrpn_Semaphore::vrpn_Semaphore: error allocating semaphore from arena.\n");
return false;
}
}
#elif defined(_WIN32)
// args are security, initial count, max count, and name
// TCH 20 Feb 2001 - Make the PC behavior closer to the SGI behavior.
int numMax = cResources;
if (numMax < 1) {
numMax = 1;
}
hSemaphore = CreateSemaphore(NULL, cResources, numMax, NULL);
if (!hSemaphore) {
// get error info from windows (from FormatMessage help page)
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
// Default language
(LPTSTR) &lpMsgBuf, 0, NULL );
fprintf(stderr,"vrpn_Semaphore::vrpn_Semaphore: error creating semaphore, "
"WIN32 CreateSemaphore call caused the following error: %s\n", (LPTSTR) lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
return false;
}
#elif defined(__APPLE__)
// We need to use sem_open on the mac because sem_init is not implemented
int numMax = cResources;
if (numMax < 1) {
numMax = 1;
}
char *tempname = new char[100];
sprintf(tempname, "/tmp/vrpn_sem.XXXXXXX");
semaphore = sem_open(mktemp(tempname), O_CREAT, 0600, numMax);
if (semaphore == SEM_FAILED) {
perror("vrpn_Semaphore::vrpn_Semaphore: error opening semaphore");
delete [] tempname;
return false;
}
delete [] tempname;
#else
// Posix threads are the default.
// We use sem_init on linux (instead of sem_open).
int numMax = cResources;
if (numMax < 1) {
numMax = 1;
}
semaphore = new sem_t;
if (sem_init(semaphore, 0, numMax) != 0) {
perror("vrpn_Semaphore::vrpn_Semaphore: error initializing semaphore");
return false;
}
#endif
return true;
}
开发者ID:bilke,项目名称:vrpn,代码行数:76,代码来源:vrpn_Shared.C
示例13: uscsetlock
// 0 if it can't get the resource, 1 if it can
// -1 if fail
int vrpn_Semaphore::condP() {
int iRetVal=1;
#ifdef sgi
if (fUsingLock) {
// don't spin at all
iRetVal = uscsetlock(l, 0);
if (iRetVal<=0) {
perror("vrpn_Semaphore::condP: uscsetlock:");
return -1;
}
} else {
iRetVal = uscpsema(ps);
if (iRetVal<=0) {
perror("vrpn_Semaphore::condP: uscpsema:");
return -1;
}
}
#elif defined(_WIN32)
switch (WaitForSingleObject(hSemaphore, 0)) {
case WAIT_OBJECT_0:
// got the resource
break;
case WAIT_TIMEOUT:
// resource not free
iRetVal=0;
break;
case WAIT_ABANDONED:
ALL_ASSERT(0,"vrpn_Semaphore::condP: thread holding resource died");
return -1;
break;
case WAIT_FAILED:
// get error info from windows (from FormatMessage help page)
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
// Default language
(LPTSTR) &lpMsgBuf, 0, NULL );
fprintf(stderr, "Semaphore::condP: error waiting for resource, "
"WIN32 WaitForSingleObject call caused the following error: %s", (LPTSTR) lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
return -1;
break;
default:
ALL_ASSERT(0,"vrpn_Semaphore::p: unknown return code");
return -1;
}
#else
// Posix by default
iRetVal = sem_trywait(semaphore);
if (iRetVal == 0) { iRetVal = 1;
} else if (errno == EAGAIN) { iRetVal = 0;
} else {
perror("vrpn_Semaphore::condP: ");
iRetVal = -1;
}
#endif
return iRetVal;
}
开发者ID:bilke,项目名称:vrpn,代码行数:64,代码来源:vrpn_Shared.C
示例14: adjustLockDirectoryAccess
// allow different users to read\write\delete files in lock directory
// in case of any error just log it and don't stop engine execution
void adjustLockDirectoryAccess(const char* pathname)
{
PSECURITY_DESCRIPTOR pSecDesc = NULL;
PSID pSID_Users = NULL;
PSID pSID_Administrators = NULL;
PACL pNewACL = NULL;
try
{
// We should pass root directory in format "C:\" into GetVolumeInformation().
// In case of pathname is not local folder (i.e. \\share\folder) let
// GetVolumeInformation() return an error.
Firebird::PathName root(pathname);
const size_t pos = root.find(':', 0);
if (pos == 1)
{
root.erase(pos + 1, root.length());
PathUtils::ensureSeparator(root);
}
DWORD fsflags;
if (!GetVolumeInformation(root.c_str(), NULL, 0, NULL, NULL, &fsflags, NULL, 0))
Firebird::system_error::raise("GetVolumeInformation");
if (!(fsflags & FS_PERSISTENT_ACLS))
return;
// Adjust security for our new folder : allow BUILTIN\Users group to
// read\write\delete files
PACL pOldACL = NULL;
if (GetNamedSecurityInfo((LPSTR) pathname,
SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
NULL, NULL, &pOldACL, NULL,
&pSecDesc) != ERROR_SUCCESS)
{
Firebird::system_error::raise("GetNamedSecurityInfo");
}
SID_IDENTIFIER_AUTHORITY sidAuth = SECURITY_NT_AUTHORITY;
if (!AllocateAndInitializeSid(&sidAuth, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_USERS, 0, 0, 0, 0, 0, 0, &pSID_Users))
{
Firebird::system_error::raise("AllocateAndInitializeSid");
}
if (!AllocateAndInitializeSid(&sidAuth, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pSID_Administrators))
{
Firebird::system_error::raise("AllocateAndInitializeSid");
}
EXPLICIT_ACCESS eas[2];
memset(eas, 0, sizeof(eas));
eas[0].grfAccessPermissions = FILE_GENERIC_READ | FILE_GENERIC_WRITE | DELETE;
eas[0].grfAccessMode = GRANT_ACCESS;
eas[0].grfInheritance = SUB_OBJECTS_ONLY_INHERIT;
eas[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
eas[0].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
eas[0].Trustee.ptstrName = (LPSTR) pSID_Users;
eas[1].grfAccessPermissions = FILE_GENERIC_READ | FILE_GENERIC_WRITE | DELETE;
eas[1].grfAccessMode = GRANT_ACCESS;
eas[1].grfInheritance = SUB_OBJECTS_ONLY_INHERIT;
eas[1].Trustee.TrusteeForm = TRUSTEE_IS_SID;
eas[1].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
eas[1].Trustee.ptstrName = (LPSTR) pSID_Administrators;
if (SetEntriesInAcl(2, eas, pOldACL, &pNewACL) != ERROR_SUCCESS)
Firebird::system_error::raise("SetEntriesInAcl");
if (SetNamedSecurityInfo((LPSTR) pathname,
SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
NULL, NULL, pNewACL, NULL) != ERROR_SUCCESS)
{
Firebird::system_error::raise("SetNamedSecurityInfo");
}
}
catch (const Firebird::Exception& ex)
{
Firebird::string str;
str.printf("Error adjusting access rights for folder \"%s\" :", pathname);
iscLogException(str.c_str(), ex);
}
if (pSID_Users) {
FreeSid(pSID_Users);
}
if (pSID_Administrators) {
FreeSid(pSID_Administrators);
}
if (pNewACL) {
LocalFree(pNewACL);
}
if (pSecDesc) {
LocalFree(pSecDesc);
}
//.........这里部分代码省略.........
请发表评论