what packages are required for data flow analysis in LLVM - llvm

my project is based on data flow and control flow analysis of C programs. I am currently working on elementary OS for llvm. I need to know what additional packages do i need to install (other than clang and compiler-rt) for working on data flow and control flow analysis. I am quite new to LLVM.
Also, whether those libraries would be enough for generating intermediate representation of the code?

Related

Need to sandbox application that compiles C++ modules from untrusted sources online

I’m developing a C++ application where I want to compile C++ modules from potentially untrusted sources online, and have them operate on a specific bank of data within a single process. I’d like to sandbox these somehow. This is obviously a complex issue, but hoping to discover if there’s any potential approach or tool/library I haven’t yet thought of. The app will run on Windows & OSX at minimum, and (hopefully) Linux, iOS, Android.
My app would locally compile the C++ modules it downloads, and dynamically link the object code to a process in the app (not necessarily the “main” app process). The C++ modules would only have access to my API via the headers I provide, however the API (and any dependent libraries) need to be linked into the same process. The API’s dependent libraries are compute-based only, such as native SIMD-based math and possibly memory allocation. I don’t expect they will need to call any network, disk, or any other OS functionality, for that matter – except for needing to communicate their input data and computed results to the main process (maybe over shared memory ?)
I don’t care if the sandboxed process’ memory is corrupted or hollowed, as long as it’s contained in that process. I also want to avoid having any system API call addresses linked into in the process memory space, to prevent compromised code from finding them.
I’ve done a review of the basic security issues (stack crashes, return oriented programming hacks, etc.). Also looked at some related projects:
I see Google has a sandbox subproject within the Chromium repo which might be useful, but unsure of it’s utility in my case.
Windows Sandbox is a Microsoft tool for Windows only, and isn’t available on some versions anyway. Moreover. there are big performance issues with using it. The app runs in real time, with frame rate requirements similar to a video game.
considered compiling to WebAssembly, but at the moment it seems too immature (no SIMD, hard to debug, and potentially vulnerable to hacks in the wrapping host or browser.)
I thought there might be some kind of wrapper library already out there to intercept all OS calls and allow custom configuration of what calls get passed through (in my case, anything except what’s needed for the inter-process communication would be denied)
Any other ideas, architectural suggestions, or promising open source projects on the horizon for this ?
Thanks,
C
Compiling untrusted source code and linking to your app sounds really unsafe. If I understand your problem correctly, you need to "provide safe runtime environment for single threaded user code with only access to your API", then in my opinion its better to use runtime interpreter instead. It will provide you more control and sandbox capabilities, safe API calls and users code exceptions handling.
If you have doubts about interpreters performance, its a good trade of to safety, flexibilty and control. Vast of interpreters compile source code to bytecode and runs realy fast. Also you can reach better performance by providing fast API to script.
In my Java enterprise projects I use built-in Rhino JavaScript interpreter to run user scripts and provide API to reach flexibility, required performance and control. This scripts can call nothing but my API. Its safe, flexible and absolutely controllable.
I found these C/C++ (C like syntax) interpreter libraries:
JavaScript (ECMA)
https://v8.dev/
Lua
http://acamara.es/blog/2012/08/running-a-lua-5-2-script-from-c/
C++ interpreter
https://github.com/root-project/cling

Communicate with CoDeSys program on a Linux-based WAGO PFC200 PLC

I'm currently getting familiar with PLC's, the WAGO 750-8206 PLC in particular. It offers a linux OS and can run CoDeSys programs. There are some I/O modules attached to the controller: 750-530, 750-430 and 750-600. What I would like to know is this:
Is it possible to write a C++ linux application that runs on the PLC and gets/sets the digital inputs and outputs?
Even better: can I write a CoDeSys program that "talks to the I/O's" and handles all the logic and at the same time can be accessed by a C++ linux program? THe idea is this: I would like the CoDeSys program to check for let's say two digital inputs. If both are high, a variable should be set to a defined value. The linux application should be able to read that variable and conduct further processing (such as sending JSon data to a server or similar).
Also, I would need to be able to send commands from the linux application to the CoDeSys program in order to switch digital outputs (or set values on analog outputs etc) when the linux application receives a message that triggers the command.
Any thoughts and comments on this topic are greatly appreciated as I am completely new to this topic. Thanks in advance!
The answer you might want
The actual situation has changed into the opposite of the previous answer.
WAGO's recent Board Support Packages and Documentation actively support you in making changes and extensions to the PLC200 line. Specifically the WAGO 750-8206 and 17 (as of March 2016) other PLCs :
wago.us -> Products -> Components for Automation -> Modular WAGO-I/O-SYSTEM, IP 20 (750/753 Series)
What you have to do is get in touch with them and ask for their latest Board Support Package (BSP) for the PLC200 line.
I quote from the previous answer and mark the changes, my additions are in bold.
Synopsis
Could you hack a PFC200 and get custom binaries executed? Probably Absolutely yes. As long as the program is content to run on the Linux-3.6.11 kernel and glibc-2.16 and is compiled for the "armhf" API, any existing ARM application, provided you also copy the libraries it uses as well, will just run without even compiling it specifically for the PFC200.
Would it be easy or quick? No. Yes, if you have no fear of the Linux Command line. It is as easy as using the Cross Compiler provided by the Board Support Package (BSP) with the provided C-libraries and then run this to transfer your program to the PFC's flash and run it: scp your-program root#PFC200:/usr/bin
ssh root#FC200 /usr/bin/your-programOf course, you can use Eclipse CDT with the Cross Toolchain for the PFC200 and configure Eclipse to do do remote run and debug.
Will this change in the future? Maybe. Remember that PFC200 is fairly new in North America.It has, PFC200 has appeared in September 2014
The public HOWTO Building FORTE for Wago describes how to use the initial BSP to run FORTE, which is the IEC 61499 run-time environment of 4DIAC (link: sf.net/projects/fordiac ), an open source PLC environment allowing to implement industrial control solutions in a vendor neutral way. 4DIAC implements IEC 61499 extending IEC 61131-3 with better support for controller to controller communication and dynamic reconfiguration.
In case you want to access the KBUS (which talks to the I/Os) directly, you have to know that currently only one application can be in charge of KBUS.
So either CODESYS, or FORTE, or your own KBUS application can be in charge of the KBUS.
The BSP from 2015 has many examples and demos how to use all the I/O of the PLC200 (KBUS, CAN, MODBUS, PROFIBUS as well as the Switches and LEDs on the PFC200 directly). Sources for the kernel and with all kernel drivers and the other Open Source components is provided and compiled in the Board Support Package (BSP).
But, the sources for the libraries and tools developed from scratch by WAGO and are not based on GPL/Open Source code are not provided: These include the Application Device Interface(ADI)/Device Abstraction Layer(DAL) libraries which do CANopen, PROFIBUS-Slave and KBus (which is used all PLC I/O modules connected to the main PLC unit)
While CANopen is using the standard Linux Socketcan API to talk to the kernel and you could just write a normal socketcan program using the provided libsocketcan, the KBus API is an WAGO-specific invention and there, you'd have to do some reverse-engineering if you'd not want to use WAGO's DAL for accessing all the electrical I/O of the PLC, but the DAL is documented and examples how to use it are provided in the BSP.
If you use CODESYS however, there is an "codesys_lib_demo-0.1" example library which shows how to provide a library for CODESYS to use.
Outdated Answer
This answer was very specific to circumstances in 2014 and 2015. As of 2016, it contains incorrect information. Still going to leave as-is for now to provide background.
The quick answer you probably don't want
You could very reasonably write code using Codesys that put together a JSON packet and sent it off to a server elsewhere. JSON is just text, and Codesys can manipulate text in a fashion very similar to C. And there are many ethernet protocols available from within Codesys using addon libraries provided by Wago.
Now the long Answers
First some background
Since you seem to be new to Wago and the philosophy of Codesys in general... a short history.
Codesys is used to build and deploy Hard Realtime execution environments, and it is important to understand that utilizing libraries without fully understanding the consequences can destabilize performance of the entire system (bringing Codesys to its knees and throwing watchdog errors in the program). Remember, many PLC's are controlling equipment that could kill someone if it ever crashed.
Wago is fond of using Linux to provide the preemptive RT kernel for the low level task scheduling and then configuring Codesys to utilize much of the standard C-libraries that often accompany linux. Wago has been doing this for quite some time, but they would never allow you to peel back the covers without going through Codesys (which means using IEC 61131 languages, of which C++ is not included), and this was for your own safety (and their product image). If you wanted the power of linux on a Wago, you had to get a special PLC with a completely naked OS, practically no manual or support, and forfeit the entire Codesys runtime.
The new PFC200's have much more RAM and memory available than recent models, allowing for more of the standard linux userland stack (ssh, ftp, http,...) to be included without compromising the Codesys runtime, and they advertise this. BUT... they are still keeping a lid on compilation tools and required header files needed to compile and link to Codesys libraries or access specialized hardware (the Wago KBUS, which interfaces your I/O modules).
The Synapsis
Could you hack a PFC200 and get custom binaries executed? Probably yes.
Would it be easy or quick? No.
Will this change in the future? Maybe. Remember that PFC200 is fairly new in North America.
Things you may not know
Codesys does not necessarily know or care about Wago. You can get Target Platforms for Codesys that do target Intel processors running a linux os. Codesys DOES SUPPORT accessing external libraries (communication in the reverse direction is dangerous), but they often expect a C style interface, and you can only access those libraries by defining C-headers that Codesys will analyze, so you may need to do some magic to get C++ working seemlessly. What you can do is create a segment of shared memory that both C++ and Codesys access, and that is how they pass information (synchronization is another problem).
You can get an Open Wago PLC, running Codesys on Linux. Wago's IPC are made specifically for this purpose. They have more power, memory, and communication capabilities in general; but they do cost more than double your typical Wago PLC.
If you feel like toying with the idea of hacking a Wago, you will need to tear apart the manuals for Codesys (it has its own), the manuals for the Wago IPC's, and already be familiar with linux style inter-process-communication and/or dynamic libraries.
Also, there is an older Wago PLC that had the naked Linux on it 750-8??. It also has a very good manual on how to access the Wago hardware using supplied headers.
You must first understand how Codesys expects to talk to its target operating system. Then you work backwards to make it talk to Wago specific libraries living on that operating system. You must be careful not to hijack Codesys.
Your extra C++ libs should assist Codesys, not take it over. For instance, host a sqlite database on the same device, and use C++ to manage the database and provide a very simple interface that Codesys can utilize. All Codesys would do is call a function and pass some values, but your C++ would actually build an SQL query and issue it to the database (Codesys doesn't need to know why or how this is happening).
I hope at least one paragraph is helpful in some way.

Which softwares (in terms of software function, rather than name) are necessary to program an indie game in c++ on mac?

I am interested in programming an indie game on my mac. I understand there is software such as DirectX, DirectX SDK, Visual C++ which is available only for Microsoft OS. Firstly, what functions do these softwares have and why are they required? Why could a simple editor, like vim, not perform the same task?
I understand the overarching question seems rather broad as there may be equivalent softwares available for mac for which people have their particular preferences. Therefore, I am not asking for this directly (although a few examples of preferred softwares for mac would be useful). Instead, I am asking which softwares are necessary and sufficient in terms of the function they perform in order to develop an indie game on a mac.
As an example of an answer: 'a compiler is a necessity, as it is required to compile source code and run c++ programs'
Optionaly: For example g++
Many thanks!
A compiler and a text editor. Using the standard library, you can write a basic text adventure.
A debugger is relatively key, so you can see the state of your program in the middle of execution. Some people program without using one much.
Having a solution system (be it make and makefiles or whatever) makes building less of a pain. Having a source control repository and utilities will allow you to reverse changes when you make serious screwups, provide a backup for your local source when your system dies half way through the project. Diff tools to see what you did in a particular changeset can be useful to track down bugs.
If you want a graphical game, you'll need a graphics library, or a library that includes a graphics library, for your platform of choice. This may or may not imply an application architecture (like a message pump). Different styles of graphics (hypercard-esque, 2d sidescroller, isometric, 3d free-move, etc) can find different graphical libraries useful.
If you want a traditional GUI with buttons, text rendered from fonts, and scroll bars and the like, reinventing the wheel will take a bunch of time, and early prototypes (where you care less about look&feel than you do about other problems) will take longer. So a framework that provides for that can be useful.
An IDE (integrated development environment) like MSVC or Eclipse usually hooks together a solution building system (including compiler) with a text editor and a debugger, and can have hooks to attach to a source control system and changeset difference viewer. The functions an IDE provide are available piecemeal: IDEs just integrate them all into one package.

C/C++ Wrapper for SIMULINK models

I have a very big C/C++ software project in Visual Studio and Eclipse. There are some third party software in the form of SIMULINK models. Is it currently possible to:
1) Write C/C++ wrapper functions for SIMULINK models?
2) Invoke the functions from external environment such as VS or Eclipse C/C++ projects to perform integration and further tasks?
I know that you can use MEX (MATLAB Exec.) functions which are C/C++ or FORTRAN wrapped for MATLAB usage. But this is not ideal for me.
USE CASE
My use case is based on modelling and simulation, but my subsystems are quite diverse in terms of data format. 50% is in C/C++, 35% is in SIMULINK models, and the rest are in binary executables, object code, symbol data, etc. I am doing some complex system modelling; Sorry, but cannot tell you further due to protective reasons.
From the answers I am getting, it seems people are keen to just use what Mathworks offers. My intention was to get more like a yes no answer, but so far I got good explanations too.
UPDATE
I will have to evaluate SIMULINK's embedded coder and see how much extra effort is required on polishing the generated code. I read that there is production-level code generation facility in Embedded Coder; should be interesting.
There are two choices depending on exactly what your requirements are:
convert the Simulink models to C using Simulink Coder. This effectively gets you out of the Simulink environment, so integrating the model functionality into you existing environment is identical to incorporating any other C code. Of course you need access to Simulink Coder to do this.
Calling the MATLAB Engine. Note you cannot call just Simulink. You call MATLAB and issue various MATLAB commands to load, execute, and interrogate the Simulink model.

A stand alone software using fortran / C/ C++

I need to build a standalone Windows-based software, using the Fortran and or C/C ++. I expect users to download the program, install it and use it generically in a Windows environment.
Main aim of the software is to perform complex nonlinear optimization, and possibly constrained optimization. I expect users to interact with the program using a highly interactive graphics user interface. Practically, depicting results user high-end graphics is a necessity.
I want to know whether it is possible to achieve these using freely available libraries for Fortran/C/C++.
Many, if not most, of the (freely available) open source optimization codes are written in Fortran and or C/C++. For a quick overview, please have a look at Hans Mittelmann's Decision Tree for Optimization Software.
There is also the COIN-OR Foundation, which hosts many optimization codes (most written in C/C++, I believe) and support tools. You can find the list of available projects here.
If by complex optimization you refer to complex numbers, please have a look at this SO question for further elaboration on how to formulate optimization problems involving complex numbers.
You can use Fortran to write routines for computation and transform everything into a dll.
The application can be written in C++ (for example GUI in Qt).
For visualization there are good libraries in C++, like VTK, otherwise you can use OpenGl.
If you want numerical libraries additionally, you can use LAPACK for example.