How can I execute the shell commands like dump memory (d()), xbdCreatePartition, dosFsVolFormat, dosFsShow from an RTP application program?
Linux provides system commands to do this job, how is this achieved in VxWorks6.9?
If you are looking for an equivalent of system(), to allow you to execute an arbitrary command, you are out of luck.
However, the "Shell" that you are used to interacting with is actually a C interpreter, and any command you are running is available to be called from code. So you could call dosFsVolFormat for example from your own code.
There is a caveat here, which is that most functionality is implemented in the kernel, and so these functions may not be available in your RTP. The functions available vary from release to release, and may also be dependant on your kernel configuration. You can compare the user versions of headers to the kernel version to see what might be available.
You can always write your own system calls, however, to expose kernel functionality to a RTP application.
You cannot call kernel functions directly from RTP. You can create a kernel module project that can take commands from TCP and execute kernel functions for you. And from your RTP project you'd be sending these commands from TCP. You can use serial channel protocols or message channel, etc instead of TCP.
The main reason for this is to seperate kernel space from application space so that your application won't cause a crash on kernel.
I assume that you have a host pc and a target running on vxworks. That means you are using a Cross-compiler IDE such as Windriver Workbench or Tornado.
At this moment, you have 2 possibilities.
1) Your target has an VGA or HDMI port on it so you can easyly plug in a monitor and you can see the vxworks shell operating on a blue screen.
There you can run your shell commands.
https://userweb.jlab.org/~brads/Manuals/VxWorks/vxWorks_commands.html
2) You can use the windriver debugging tool. But you need to add components to your vxworks kernel image such as INCLUDE_DEBUG_AGENT. You can configure it yourself. When you connect your remote device, you can open a shell window and start typing system calls.
https://borkhuis.home.xs4all.nl/vxworks/vxw_pt2.html
Good luck...
Related
I am finding a Ubuntu OS command, which lets the program to read the data from keyboard even if the program is in background. I tried to search it a lot but got no success. If any Ubuntu/Linux programmer knows the OS command which lets the program to do so, Please share it with me.
I am a beginner of Ubuntu programming.
You can use the Linux input subsystem to read events from mice and keyboards. It will only work if your application has the necessary privileges. Basically, you have to run the application as root for this to work.
If you cannot run as root, you should not be attempting to monitor the keyboard anyway.
You can create an X11 application to monitor keyboard events in the current session. It only works for the current user, and in the current graphical environment, and may not be able to observe privileged dialogs, for example password inputs. For details, look at the application shortcut launcher for your desktop environment; all Linux DEs I've ever heard of have one.
I think the old Linux Journal articles, The Linux USB Input Subsystem and Using the Input Subsystem, are still one of the best introductions to the Linux input subsystem. Most Linux distributions nowadays also support uinput, a similar device that allows injecting input events back to the kernel subsystem, designed to allow user-space input device drivers. Their interfaces are described in /usr/include/linux/input.h and /usr/include/linux/uinput.h. I recommend you start at the above articles, and then look at some input and uinput examples.
If you are comfortable using a program, have a look at Logkeys project
. It directly takes input from /dev/input/event*.
I'm maintaining code on a real-time system running Red Had Enterprise Linux. I'm afraid that sometimes, despite running things at the highest priority, the network manages to slow the computer down, and I would like to disable the card so that I have the full power of the CPU at my disposal. I need some files at the beginning of my function from the network, but after a certain point, I can effectively disable the network until the program is complete. Is there a way I could disable the network through some sort of an API call?
Hopefully someone could expand on this, but it may be worthwhile to look into how ifconfig disables network devices. You probably can do an ioctl on the interface to disable it. Depending on the driver / nic, the kernel may then be able to cause the network hardware to drop packets instead of the cpu.
The source code for ifconfig is here:
http://net-tools.git.sourceforge.net/git/gitweb.cgi?p=net-tools/net-tools;a=blob;f=ifconfig.c;h=be6999578bd81e91e90e26a35fad91f4928f4226;hb=HEAD
Iproute2, which also is able to do the same things as ifconfig is described here:
http://git.kernel.org/?p=linux/kernel/git/shemminger/iproute2.git;a=blob;f=ip/iplink.c;h=6b051b65faab72ea46534ad33f71b3f6cd35c11b;hb=HEAD#l589
I found the source code of iproute2 slightly easier to understand than ifconfig, but it should be relatively easy to see how they interface with the networking stack to disable an interface.
The way the system does it is by issuing ip link set dev ${DEVICE} down 2> null . Looking at the code of ip.c , e.g. here you can check for yourself how it is done. The key is the netif.h that shuts down the network by calling net_if_set_down() . I think it just sets a flag.
netif->flags &= ~NETIF_FLAG_UP
You can go on from here on your own, but keep in mind netif.h is part of the kernel...
The networking is part of the kernel, rather than a user space process. You could do the equivalent of calling rmmod to remove the network driver module from the kernel, assuming you have module support enabled; or you could just set all the netfilter rules to DROP and see if that speeds things up. I'd probably prefer to do that in a launcher script (using the ready-made iptables-save/iptables-restore) rather than coding that in C++. Or you could even just bring the interfaces down.
You said "API" but did not mention the language of your program/script, nor your OS.
On Linux variants like CentOS, RHEL, SuSE, and Fedora, from a bash/Bourne shell script:
/sbin/service network stop
rc=$?
if [ "$rc" -ne 0 ]; then
echo "***** Failed to stop networking service"
exit $rc
fi
# Do your thing
/sbin/service network start
I'm building a HW-simulator for our driver team. Now, the simulator is devided in to 2 modules:
First module runs inside the driver, in kernel mode and that's where the main interface between the driver and the HW-Simulator.
Second module is an executable user-mode code which generates data for the simulator and transports it to the simulator via calls to DeviceIOControl (under windows API)
My need is this: I want to be able to execute the user-mode executable from within the kernel-mode. And I need to be able to do this in a relatively portable way. Currently I'm only running on Windows, but that should change soon.
Further more, I need to be able to communicate with the user-mode code via it'sstdin pipe, in order to reconfigure it and eventually close it.
I found this:
Executing a user-space function from the kernel space
but it's only relevant for the linux-kernel. Is there a more portable alternative? Or a windows alternative?
Can I do this in Windows by simply using the ShellExecute/RunAs API functions?
Note: We are aware of the security risks involved in invoking user-mode code from the kernel-space. But as this is only meant to be used as a test-environment and will not ever reach our release code, then we are not concerned.
There isn't a clean way to do this in the Windows kernel. The user-mode API CreateProcess to create processes use undocumented APIs (NtCreateProcess/NtCreateThread) to create a process.
The recommended thing to do would be to have a "partner service", a user-mode service that communicates with your driver using IOCTL. You can use the inverted call model to have your driver call your service to have it create a process.
Really, there is no documented way to do it without triggering process creation from user-mode.
But there is one undocumented tricky way if You don't want to create user-mode application:
To create a valid win32 process the driver must communicate with CSRSS (what is undocumented).
You can enqueue a user-mode APC, allocate some virtual memory for the APC code in the context of any existing process. This code should simply call CreateProcess and anything else You want.
I'm developing an application that runs on a small Linux-based SBC (~32MB RAM). Sadly, my app recently became too large to run under GDB anymore. Does anyone know of any good, lightweight debugging methods that I can use in embedded Linux? Even being able to view a thread's stack trace would be extremely helpful.
I should mention that this application is written in C++ and runs multiple threads, so gdbserver is a no-go as it doesn't work with multithreaded apps.
Thanks in advance,
Maha
gdbserver definitely works with multi-threaded applications, I'm working on an embedded project right now with >25 threads and we use gdbserver all the time.
info threads
lists all the threads in the system
thread <thread number from info threads>
switches to that thread of execution.
thread apply XXX <command>
Runs on the thread designated by XXX, which can also be 'all'. So if you want the back trace from all running threads do
thread apply all bt
Once you're in the execution flow of a given threads all your typical commands work as they would in a single threaded process.
I've heard of people doing hacks like running the application in an emulator like QEMU and then running GDB (or things like valgrind) on that. It sounds painful, but if it works....
Would you get anywhere with libunwind (to get stack traces) and printf-style logging?
Serial port printing is the most light weight I can think of ~~~
Easily seen in a Host PC, and simple and light weight code inside your app~~
If you do not have a serial port, once we used an GPIO port and simulated a serial port using it. It worked perfectly well, but was a bit slow :-( ~~~
Is there a reason why you have built your own debugger? I am developing a Linux system using an ARM processor (AT91SAM926x) and we are using both compiler and debugger from CodeSourcery. I do not think that they have released a version with GDB 7 yet but I am debugging multithreaded C++ applications using the gdbserver tool without any problems.
Gdbserver does indeed work with multithreaded applications. However you do need to compile a cross target debugger for your host to get it to work with your target gdb.
See this article for a detailed description of how to do it:
Remote cross-target debugging with GDB and GDBserver
I'm writing some software that automatically connects a Bluetooth device using the Windows Bluetooth API. When it connects, Windows automatically starts installing the Bluetooth HID device driver, as expected:
This takes about 10-15 seconds, after which Windows displays the familar "ready for use" message:
The problem is that BluetoothSetServiceState() returns as soon as the driver install begins, not when the device is actually ready for use. This causes some problems for my code, because it invokes a separate library for device communication as soon as it's "connected". The first few calls fail because the drivers haven't finished installing, and making those connection attempts appears to interfere with the driver installation, because if I try to use the communication library before the driver installation has finished Windows wants to restart before the device can be used.
What I'm looking for is a way to hook that "ready to use" event, when driver installation has actually finished, so I don't make my communication library calls prematurely. Is there some Windows API call I can use to either register a function callback or directly polling the state of driver installation?
I'm writing this in vanilla C/C++, no .NET. Thanks for your help!
You might want to have a look at
this sample code and RegisterDeviceNotification function. I'm not sure for 100%, but it seems to work if you specify correct guid for your device class.
Here is what I would do:
Download Winspector (or use Spy++)
Start up Winspector, and begin watching for Window Messages
Install your driver
Watch for WM's indicative of a completed driver installation
I wish I could be more descriptive on #4, but I'm not familiar with the specific window message you need. Have a look here for possible Window Messages to expect.
However, once you determine the correct window message to look for, then programmatically have your program wait for (and handle) this WM. CodeProject has an excellent write up on how to do this in C++. Personally, I'd prefer to do it in Delphi.
If it is a network binding then RNDIS sends a message when it completes installation as per RNDIS Driver Implemenation guide
and definition of RNDIS
or
You can install or query the device list programatically through Devcon utility (source code is available with MSDN ) as given in Examples