Accessing the vm areas of a process - memory

I am trying to write a LKM that have to read the vm areas address from a process. I am using pid_task() to get the pointer to the task_struct, but i getting compiling error when i try to use it to get the start address of the vmarea.
struct task_struct *ts;
ts = pid_task(find_vpid(pid_t)pid,PIDTYPE_PID);
printk(KERN_INFO "%lu",ts->mm->mmap->start);
And i am getting the error "error: dereferencing pointer to incomplete type"
I am a linux noob and a completely noob in LKM.
I'd appreciate any help.
Thank you all

I have a test on my kernel source tree(2.6.35) with following codes, the compilation is okey:
struct task_struct *ts;
pid_t pid;
ts = pid_task(find_vpid(pid),PIDTYPE_PID);
printk(KERN_INFO "%lu",ts->mm->mmap->vm_start);
Could you try with the above codes in your kernel source tree? I think maybe you have to include all header files needed, such as:
#include <asm/uaccess.h>
#include <linux/errno.h>
#include <linux/time.h>
#include <linux/proc_fs.h>
#include <linux/stat.h>
#include <linux/init.h>
#include <linux/capability.h>
#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/string.h>
#include <linux/namei.h>
#include <linux/mnt_namespace.h>
#include <linux/mm.h>
#include <linux/swap.h>
#include <linux/rcupdate.h>
#include <linux/kallsyms.h>
#include <linux/stacktrace.h>
#include <linux/resource.h>
#include <linux/module.h>
#include <linux/mount.h>
#include <linux/security.h>
#include <linux/ptrace.h>
#include <linux/tracehook.h>
#include <linux/cgroup.h>
#include <linux/cpuset.h>
#include <linux/audit.h>
#include <linux/poll.h>
#include <linux/nsproxy.h>
#include <linux/oom.h>
#include <linux/elf.h>
#include <linux/pid_namespace.h>
#include <linux/fs_struct.h>
Another:
After compilation successfully, you should judge the pointers is NULL or not.

Related

opencv imread not working but other functions are

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include "opencv2\highgui.hpp"
#include "opencv2\imgproc.hpp"
#include "opencv2\features2d.hpp"
#include "opencv2\core.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img = Mat::zeros(Size(60,60),CV_8UC1);
imwrite("test.bmp", img);
Mat img2 = imread("Screw.png");
namedWindow("image", WINDOW_NORMAL);
imshow("image", img);
imshow("img", img2);
waitKey(0);
return 0;
}
I am using Opencv 3.4.6 with visual studio 2015.
I am unable to read any image from system, have tried png and jpg image format.To make sure that image is in the right location I have also used imwrite function to save an blank image, which is working fine.
I have tried opencv 4.0.1 as well giving the same issue.
I think there might be some issue in configuration part. There are so many tutorials available for the configuration procedure. Try below link for the configuration and also
as #mark suggested replace your header file
https://www.youtube.com/watch?v=M-VHaLHC4XI

OpenCV with Code::Blocks

I'm using Code::Blocks with the library OpenCV
I wrote the following code
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
int main(int argc)
{
src = imread( argc[1], 1 );
cout << "Hello world!" << endl;
return 0;
}
When I run the code the following window appear
what is the solution to the problem :(
You have to add the correct libraries: Howto use libraries with Code::Blocks

window "Image" has a strange caption: "# -|TM", which is not dependent on the name

I am aware my question is similar to:
OpenCV 2.0 C++ API using imshow: returns unhandled exception and "bad-flag"
Though I hv tried all the suggested and verified solutions from this page as well as other related pages, I still face the same problem of corrupted window names. Here is my code:
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include <math.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include"ip.h"
#include"histogram.h"
#include <opencv2\highgui\highgui.hpp>
#include "opencv2/core/core.hpp"
using namespace cv;
using namespace std;
void main()
{
IplImage *img01 = cvLoadImage("E:\liberty.jpg",CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat img1(img01, false);
cv::namedWindow("Image 1");
cv::imshow("Image 1",img1);
cv::waitKey(0);
cv::destroyWindow("Image 1");
}
What should i do?Please help.
Is your image loading to img01?
Try changing '\' to'/' in IplImage *img01 = cvLoadImage("E:\liberty.jpg",CV_LOAD_IMAGE_GRAYSCALE);

opencv class "cvKalman" not recognised

I have a problem, in ROS I process a camera feed with openCv.
Now i try to implement the cvKalman, but this type is not recognized, however the opencv example works well.
What am i missing, why is not recognized this type?
here is my include to the ROS node:
#include <ros/ros.h>
#include <math.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
// for img processing
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv/cv.h>
Try including with "s not <s such as:
#include "ros/ros.h"
I solves the problem by using the KalmanFilter wrapper class, but still I dont understand why I cant use the simple Kalman class.

Error with matchTemplate function in OpenCV

These are includes which I am using
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>
This is namespace
using namespace cv;
But when I am using matchTemplate function, I am catching the following problem
error C3861: 'matchTemplate': identifier not found
Can anyone help me to solve this problem?
Additional information:
I am using OpenCV2.3
thank you for spending time to view and comment my problem
Best Regards
Hayk
You need imgproc.hpp included, the one that you included has the C version only : cvMatchTemplate

Resources