In our project, we are injecting the code at various places by rewriting the IL using .Net CorProfiler APIs. Everything works fine. Now, for logging purpose, we have started opening a file using FILE* as shown below -
FILE* ptLogFile = _fsopen(file_name, "a+t, ccs=UTF-8", _SH_DENYWR);
fwrite(message, sizeof(wchar_t), wcslen(message), ptLogFile);
fflush(ptLogFile);
By introducing the above code, I don't get any error, but at the same time, code injection also does not work for some cases. However, it continues working for some other cases. By removing the above code, again everything start working as expected.
Any idea what is the relationship between FILE with IL rewriting? How do I make both of them work together?
UPDATE:
Any suggestion, how do I debug this?
Related
I'm stumped... it took me a while to track this down.. because I don't have visual C++ IDE installed on the problematic system (it is windows server 2019)... my code works fine with VS 2022 on my laptop (W11 22H2)... anyhow.. I get this exception
Cannot create a file when that file already exists
I tracked it down to this code:
const auto fileTime = fs::last_write_time(p);
apparently this function can also write to the file to modify the time.
but I'm just trying to read it... (I didn't add the arguments necessary to write)
does anyone have any idea why this error might be happening?
https://en.cppreference.com/w/cpp/filesystem/last_write_time
please note it is highly likely that sometimes the file is actually being written to when I call this code (this code is called in a loop, and so is the file that is being written by another program)
I have question about replacing <THC/THC.h> method.
Recently, I'm working on installing different loss functions compiled with cpp and cuda.
However, what I faced was a fatal error of
'THC/THC.h': No such file or directory
I found out that TH(C) methods were currently deprecated in recent version of pytorch, and was replaced by ATen API (https://discuss.pytorch.org/t/question-about-thc-thc-h/147145/8).
For sure, downgrading my pytorch version will solve the problem. However, due to my GPU compatibility issue, I have no choice but to modify the script by myself. Therefore, my question can be summarized into follows.
First, how can I replace codes that have dependency of TH(C) method using ATen API?. Below are codes that I have to modify, replacing those three lines looked enough for my case.
#include <THC/THC.h>
extern THCState *state;
cudaStream_t stream = THCState_getCurrentStream(state);
Second, will single modification on cpp file be enough to clear the issue that I'm facing right now? (This is just a minor question, answer on first question will suffice me).
For reference, I attach the github link of the file I'm trying to build (https://github.com/sshaoshuai/Pointnet2.PyTorch).
After struggling for a while, I found the answer for my own.
In case of THCState_getCurrentStream, it could directly be replaced by at::cuda::getCurrentCUDAStream(). Therefore, modified code block was formulated as below.
//Comment Out
//#include <THE/THC.h>
//extern THCState *state;
//cudaStream_t stream = THCState_getCurrentStream(state);
//Replace with
#include <ATen/cuda/CUDAContext.h>
#include <ATen/cuda/CUDAEvent.h>
cudaStream_t stream = at::cuda::getCurrentCUDAStream();
After replacing the whole source code, I was able to successfully build the module.
Hope this helps.
I have a custom std::ostream that uses WriteConsoleW and similar std::istream using ReadConsoleW.
The code is pretty simple and boils down to:
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD dummy;
if(GetConsoleMode(h, &dummy) != FALSE)
ReadConsoleW(h, ...)
I would like to (unit/integration) test this. The issue:
If I redirect input to the program (echo foo | test.exe) it is no longer a console so I can't use ReadConsoleW so making it a full-blown integration test testing a sample program from the outside seems impossible
Similar for pretty much any unit testing framework which gathers stdout/stderr so WriteConsoleW cannot be used anymore making testing inside any framework hard
How can I still test this?
I imagine either faking STD_INPUT_HANDLE so the above GetConsoleMode returns true and then putting (somehow?) some input there / getting the output checking for the expected stuff.
OR:
Somehow run the program via some WindowsAPI in a way that STD_INPUT_HANDLE/STD_OUTPUT_HANDLE are detected as consoles but in fact being able to fill stdin from the parent program and read stdout, then check that for the expected values.
However I can't find any resources on that. Any ideas/hints? Has anyone ever done this?
PS: Code is for Boost, i.e. OpenSource if that matters.
I've been having an issue with a certain function call in the
dphaseWeighted = af::convolve(dphaseWeighted, m_slowTimeFilter);
which seem to produce nothing but nan's.
The back ground is we have recently switched from using AF OpenCL to AF Cuda and the problem that we are seeing happens in the function.
dphaseWeighted = af::convolve(dphaseWeighted, m_slowTimeFilter);
This seems to work well when using OpenCL.
Unfortunatley, I can't give you the whole function because of IP. only a couple of snippets.
This convolve lies deep with in a phase extract piece of code. and is actualy the second part of that code which uses the af::convolve funtion.
The first function seems to behave as expected, with sensible floating point data out.
but then when it comes to the second function all I'm seeing is nan's coming out ( I view that with af_print amd dumping the data to a file.
in the CMakeList I include
include_directories(${ArrayFire_INCLUDE_DIRS})
and
target_link_libraries(DASPhaseInternalLib ${ArrayFire_CUDA_LIBRARIES})
and it builds as expected.
Has anyone experience any think like this before?
I have an application that collects heart rate data and displays in in a GUI. I don't want to change anything about how the application runs, but want to save the data into a .csv file to use with data manipulation programs. The program is called BluetoothGattHeartRate. I am running the sample code found here.
My addition to the code is just
std::fstream theDump;
theDump.open("path/to/file", std::fstream::out);
if (theDump.is_open())
{
theDump.write("ImHere", 6);
}
theDump.close();
inserted into the file called HeartRateService.cpp in the Shared directory in the void HeartRateService::Characteristic_ValueChanged(GattCharacteristic^ sender, GattValueChangedEventArgs^ args) function just before the call to ValueChangeCompleted(heartRateValue);. I'm using Microsoft Visual Studio to edit and run the code, as the tutorial online says. This exact code succeeds in editing the file when run in an independent application, but it fails to open the file (I tested for this) when run in the Gatt sample code.
I don't expect that anyone has dealt with this before, but if by some miracle one of you has figured this out, please let me know how you fixed it.