ACE debugging: How to cause msg queue full? - c++

I am using the method:
ACE_Task::putq (ACE_Message_Block *mb, ACE_Time_Value *tv)
Here is the line where I call it:
ret = putq(mb, const_cast(&ACE_Time_Value::zero));
What I am basically trying is that I need to get regular errors
EWOULDBLOCK and ESHUTDOWN from
int lastErr = ACE_OS::last_error();
in order to debug it right away...
So my question is, it there a simple way how to force such errors ?
I've already tried this:
while ( ret >= 0 )
ret = putq(mb, const_cast(&ACE_Time_Value::max_time));
but my thread gets stuck after few calls and never returns from putq...
Many thanx in advance for hints !
Peter

I think for the first part (EWOULDBLOCK) i can just use:
ACE_Svc_Handler::msg_queue()->high_water_mark(MAX_BUF_SIZE_BYTES);
ACE_Svc_Handler::msg_queue()->low_water_mark(MIN_BUF_SIZE_BYTES);
I assume these fit my needs and what I observe is exactly what I need.
The envoking of ESHUTDOWN error is another problem, and you can simulate it by putting appropriately putting slow down sleep methods.

Related

main: src/unix/core.c:117: uv_close: Assertion `!uv__is_closing(handle)' failed

When I try to use the function uv_close((uv_handle_t*)client,NULL) in libuv library to actively close the TCP connection with the client, the error
"main: src/unix/core.c:117: uv_close: Assertion `!uv__is_closing(handle)' failed."
was reported. I search a lot online, but I still cannot find the correct way to solve the problem. I wish someone can tell me why this problem resulted and how to solve it.
You are trying to close a handle that is either already closed or in a closing state (that is, somewhere along the process that brings the handle from being alive to being closed).
As you can see from the code of libuv, the uv_close function starts as:
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
assert(!uv__is_closing(handle));
handle->flags |= UV_CLOSING;
// ...
Where uv__is_closing is defined as:
#define uv__is_closing(h) \
(((h)->flags & (UV_CLOSING | UV_CLOSED)) != 0)
To sum up, as soon as uv_close is invoked on a handle, the UV_CLOSING flag is set and it's checked on subsequent calls to avoid multiple runs of the close function. In other terms, you can close a handle only once.
The error comes out because you are probably invoking uv_close more than once for a handle. However, it's hard to say without looking at the real code.
As a side note, you can use uv_is_closing to test your handle if you are in doubt. It's a kind of alias for uv__is_closing.

Z3: timeout for optimize in C++

I'm trying to understand how to set a timeout for the optimize class of Z3 using C++ API.
This i my code:
context c;
optimize opt(c);
z3::params par(c);
par.set("timeout", 1000);
opt.set(par);
But I get "unknown parameter 'timeout'" exception on the line opt.set(par). Is it possible to set the timeout for the optimize class (after the timeout, I would like to obtain the best solution found)?
Thank you!
I know this is an old question, but if anyone's still looking for an answer, you need:
Z3_global_param_set("timeout", timeout);
And your timeout should be given as a C string.

DirectX - Error when pressing ctrl + alt + del

So far my program is working pretty well. Unfortunately when I press ctrl + alt + del it throws an error. Now I have read this question:
E_ACCESSDENED when using ctrl alt del
In which it is mentioned that the computer switches to a different screen (in which you don't have any writing permissions). It's just that I have no idea how to trace if I have writing permission in the current screen.
My code looks like:
void D3D::StartFrame() {
HRESULT result;
result = pDevice->Clear( 0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(FRAME_BG_R,FRAME_BG_G,FRAME_BG_B),0.0f,0 );
assert( !FAILED( result ) );
result = pBackBuffer->LockRect( &backRect,NULL,NULL );
assert( !FAILED( result ) );
}
void D3D::EndFrame() {
HRESULT result;
result = pBackBuffer->UnlockRect();
assert( !FAILED( result ) );
result = pDevice->Present( NULL,NULL,NULL,NULL );
assert( !FAILED( result ) );
}
Currently I am running the "StartFrame()" function each frame followed by some actions that should be done during the frame. At the end it will call the "EndFrame()" function that will unlock the drawing rectangle.
Now the error that occurs comes from the last assert (the StartFrame() assert doesn't fail?). Should I change these functions to return booleans telling the program if it should continue or not? Should I make it stop the entire program (which feels a bit odd)? Perhaps I am handling the rectangle locking the wrong way (should it work with asserts)?
Error: Assertion failed! - !FAILED(result)
Any help/advice would be appriciated !
First of all, whenever you get an error, before doing somethig, and before even thinking about what happened, you must check what exactly error message said.
In case of DirectX 9, you must not only check if HRESULT variable FAILED but get detailed info from it. You can get details from it using DXGetErrorString() and/or DXGetErrorDescription() functions (dxerr.h + dxerr.lib). For example, you can handle you errors by writing a small helper function, that accepts HRESULT and shows MessageBox() with details if it FAILED. Also, there is a good DXTrace() macro as a quick solution. Or, as a quickest lazy solution, you can just set a breakpoint right after function fail, and inspect value of HRESULT variable in debug watcher.
In your case, because we don't have error description in your post, we can only guess what happened (that's what guys from SO doesn't like the most). And I suspect here Device Lost state. That state sometimes happens when your app looses focus (Alt+tab, Ctrl+Alt+Del, etc.). To prevent crashes you must handle such exceptional states as described on MSDN or this short tutorial.
Of course, my guess can be wrong here, because I dont't know, what exactly happened. Please add proper error handling and provide additional information to get concrete help.
Happy coding!

How to Get Monitor Info with Autohotkey?

I try to get current monitor status and found GetMonitorInfo function at http://msdn.microsoft.com/en-us/library/windows/desktop/dd144901(v=vs.85).aspx but I do not know c++ and how to use it in autohotkey. DllCall line is just a guess so this is what I wrote for now.
MonitorStatus := 1 > 2 ; Creates a boolean variable so size of it is determined.
Sleep 1000
DllCall("GetMonitorInfo","HMONITOR",1,"LPMONITORINFO",MonitorStatus,"int")
Sleep 1000
MsgBox Monitor status is %MonitorStatus%. ; Status should be turned to 1.
Return
Shortly how to detect if monitor is on or off with assuming it has power?
The DllCall returns a pointer to the structure. I think it's somehow possible to use pointers in Autohotkey but i don't think is going to be easy. If you don't know what any of that means don't even bother.
Hmm.. looks like autohotkeys does have everything; Try this:
http://www.autohotkey.com/docs/commands/SysGet.htm
And don't forget to check the examples at the bottom of the page!

NtQuerySystemInformation Hook Failure

After successfully building a trampoline and learning more about process memory space, I tested the trampoline on MessageBoxA. It worked perfectly so I decided to finally put the code to the use it was supposed to be for in the first place, hiding a process by hooking NtQuerySystemInformation. The redirect function should work fine, but the code I used to write the jmp instruction now causes the task manager to crash every time.
BYTE tmpJMP[5] = {0xE9,0x00,0x00,0x00,0x00}; //jmp,A,D,D,R
memcpy(JMP,tmpJMP,5);
DWORD Addr = ((DWORD)func - ((DWORD)oNtQuerySystemInformation + 0x5));
for (int i=0;i<4;++i)
JMP[i+1] = ((BYTE*)&Addr)[i];
if (VirtualProtect((LPVOID)oNtQuerySystemInformation,5,PAGE_EXECUTE_READWRITE,&oldProtect) == FALSE)
MessageBox(NULL,L"Error unprotecting memory",L"",MB_OK);
memcpy(oldBytes,(LPVOID)oNtQuerySystemInformation,5);
if (!WriteProcessMemory(GetCurrentProcess(),(LPVOID)oNtQuerySystemInformation,(LPCVOID)JMP,5,NULL))
MessageBox(NULL,L"Unable to write to process memory space",L"",MB_OK);
VirtualProtect((LPVOID)oNtQuerySystemInformation,5,oldProtect,NULL);
FlushInstructionCache(GetCurrentProcess(),NULL,NULL);
I'm writing to the memory as such. I can't seem to find a problem with the code. I was thinking that maybe the memory changes from API to API but I was told that's incorrect, making me all out confused. Is there anything wrong that you all see? Please be descriptive. I love to learn o3o