0

I spent a good part of today trying to port the expresso logic heuristic to windows/visual studios so that I can link it as a static library. Github Link (I spent a good part of yesterday trying to find a version that works on windows that's not just a exe so I can link it to my c++ code before giving up and trying to implement it myself)

Most of my effort was fixing all the link errors and editing a NodeJS bridge for it so that I can (somewhat easily) link it as a static library with a "minimize_from_data" function however a lot of my "porting" was pretty hamfisted and I simply disabled some functions that were POSIX only.

Now that I've gotten it to compile I'm trying to go back over and make sure it's not buggy before I use it safely in some personal projects (I don't fully trust that I ported it correctly). One of the functions I "disabled" was a sys/resource function that sets the RLIMIT_CPU to some seconds value functioning as what I can understand a timeout function that kills the program If it takes too long. copying here

void set_time_limit(int seconds){
#ifndef _WIN32
    struct rlimit rlp_st, *rlp = &rlp_st;
    rlp->rlim_cur = seconds;
    setrlimit(RLIMIT_CPU, rlp);
#endif
}

Is there any way to replace this functionality in windows? Currently, I've set all the expresso source code to compile as c (/TC /Za in VS) however as my final environment is linking it to C++ a C++ method that I can extern "C" into the c code works just as well. (I know tagging both c and c++ is frowned upon)

The closest relevant question I found was about stack size using strlimit

EDIT: was a non-issue in my case. Leaving a potential solution for the future

BlueLightning42
  • 344
  • 4
  • 15
  • I don't fully agree with removing the c++ tag. A c++ solution that can be linked to the c code would solve this and my final environment is linking to several c++17 projects – BlueLightning42 Dec 18 '20 at 19:11

1 Answers1

1

In my specific case, the set_time_limit function is not called in any part of expresso. (disabling it does not change the functionality of the program) so deleting it is fine and I can move on to validating other parts.

For future readers, while trying to port it information I received, the functionality for setrlimit RLIMIT_CPU on windows can be achieved with job objects from windows.h https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_limit_information

//roughly/adding validation and error checking
// create job then
JOBOBJECT_BASIC_LIMIT_INFORMATION job_object_basic_limit_information = {
        .LimitFlags = JOB_OBJECT_LIMIT_PROCESS_TIME,
        .PerProcessUserTimeLimit = {
                .QuadPart = (long long) seconds * 10ll * 1000000ll
        }
};
// set information job object then
// assign getCurrentProcess to job object
BlueLightning42
  • 344
  • 4
  • 15