how to find physical page of user from kernel - linux-kernel

so I understand I can use get_user_pages to find the page of address but the probelm is that I dont know how to pass the size of the page to get_user_pages
void sys(char *user)
{
char *phyiscal=getphiscal(user);
}

Related

Null pointer when accessing private data of device driver from other device driver

I am developing a module which works as a layer between mac80211 module and ath9k device driver (I have done that by exporting ath9k_ops, then accessing it in my module and changing the callback functions in order to point to functions in my module).
For now, my module just intercepts mac80211 callback operations (by struct ieee80211_ops) and forward them to the device driver.
Part of struct ieee80211_ops is:
struct ieee80211_ops {
void (*tx)(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb);
/* other callback functions ... */
}
This way, when module 80211 calls callback function (*tx) I can access members of the structs ieee80211_hw, ieee80211_tx_control, sk_buff, except the pointer pointing to private data of the device:
struct ath_softc *sc = hw->priv;
What I am not following is that the original callback function of the ath9k device driver (which I call at the end of my callback function) does exactly the same thing:
static void ath9k_tx(struct ieee80211_hw *hw,
struct ieee80211_tx_control *control,
struct sk_buff *skb)
{
struct ath_softc *sc = hw->priv;
/* other code accessing members of struct ath_softc normally */
}
So, why can't my module access the private data and ath9k module can? hw->
I think I provided enough information regarding the problem because the issue is probably related to the way private data is protected from other modules accessing it, and it's my fault in not understanding how memory fully works in linux kernel.
Thank you very much. Let me know if it's worth to provide more information on the question.

Golang (iris webframework) share between handlers

I am currently using the iris web framework and since questions cannot be asked on the issue tracker and the community chat is dead I am asking this here hoping someone helps me out.
I need to pass data to the c.Render function
I have a handler that checks if the user is logged or not. If its not logged I should add an extra button to the html page
iris.Use(userHandler{})
type userHandler struct{
Allow bool
}
func (u userHandler) Serve(c *iris.Context) {
...
if isLogged {
// When I call from another middleware (c.Next) c.Render it should know that the user is logged in
}
c.Next()
}
So is it possible to add some default data to the c.Render function?
// retrieve local storage or previous handler,
// this is how handlers can share values, with the context's Values().
logged := ctx.Values().Get("logged")
// set template data {{.isLogged}}
ctx.ViewData("isLogged", logged)
// and finally, render the mypage.html
ctx.View("mypage.html")
"logged" can be set to your middleware/any previous handler by:
ctx.Values().Set("logged", false)
All these are described to the examples, you're welcome to explore some of those there: https://github.com/kataras/iris/tree/master/_examples
Happy Coding!

MFC disk partitioning

I want to get the hard disk partitions,their individual storage capacity and used space. Then display it in some control(List control would be better). I am using MFC to do this. I have searched online and managed to pull of the partitions. But I managed to display it in an edit box only.
void CDiskManagementClientDlg::OnBnClickedOk()
{
wchar_t drive[512]=L"A:";
unsigned int drives=GetLogicalDrives();
CString strListOfDrives=_T("The drives are:");
if(drives==0)
{
AfxMessageBox(_T("No Partitions"));
}
else
{
while(drives)
{
if(drives & 1)
{
strListOfDrives+=drive;
strListOfDrives+=_T(", ");
}
drive[0]++;
drives>>=1;
}
m_newDrives=strListOfDrives;
UpdateData(FALSE);
}
}
This is the code I have used to display the partions in an edit box when a button is clicked. I want to display the partitions in a control. Can someone pls guide me?

Windows phone 7: facing issue for passing parameters

Right now i am developing a Windows phone app, yes this is my first windows app. Right now i am facing an issue, don't know what's the silly mistake i made. Yes of course i have done debugging.
Now, what exactly i am doing?
Passing data from 1st page to 2nd page,
On the page, catching data inside onNavigateTo() method, yes i am receiving it correctly.
Based on the parameter/data (i.e. ID) i got, i am making web service call.
Problem:
If i move to the 3rd page from 2page and again came back to the 2nd page, its again making web call. i.e. calling DownloadStringAsync again in below code.
i.e. If 2nd page is having ListBox with 5 data, now clicking on particular item i am moving to 3rd page, if i came back to 2nd page from page 3, items get doubled i.e. 10 items (just because its making call again)
Here is the possible code for the reference:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
type = Convert.ToInt32(NavigationContext.QueryString["Type"]);
if (type != 0)
{
if (NetworkInterface.GetIsNetworkAvailable())
{
client.DownloadStringAsync(new Uri(Utils.Constant.WebService_URL));
}
else
{
MessageBox.Show("Please check internet connection!!");
}
}
}
Can't you use the following code to test if the user used the back button?
e.NavigationMode == System.Windows.Navigation.NavigationMode.Back
sometimes this method(QueryString) create problems.
In back event it create problems
its betters to store the id(parameter) in isolatedstorage application key
IsolatedStorageSettings.ApplicationSettings["id"] = "your data";
OnNavigatedTo is called whenever you navigate to the page, either by a forward navigation, or a back navigation. That's why it's retriggered when you navigate back from page #3 to page #2.
You can avoid this by only triggering the network call on a forward navigation.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (this.isInitialized) return;
type = Convert.ToInt32(NavigationContext.QueryString["Type"]);
if (type != 0)
{
if (NetworkInterface.GetIsNetworkAvailable())
{
client.DownloadStringAsync(new Uri(Utils.Constant.WebService_URL));
}
else
{
MessageBox.Show("Please check internet connection!!");
}
}
this.isInitialized = true;
}
Beware that NetworkInterface.GetIsNetworkAvailable can block (in this case the UI thread) for a long time in some scenarios, to work around this you can use network detection events.

Custom memory allocator for OpenCV

Is it possible to set a custom allocator for OpenCV 2.3.1? I have a memory pool created and I want OpenCV to use that pool for what it needs.
Is that possible?
If it is, how can it be done?
Updated:
I made some developments since last answer, but I still have some problems.
This is the code I have now:
CvAllocFunc allocCV()
{
return (CvAllocFunc) MEMPOOL->POOLalloc(sz);
}
CvFreeFunc deallocCV()
{
return (CvFreeFunc) MEMPOOL->POOLfree(ptr);
}
...
cvSetMemoryManager(allocCV(),deallocCV(),data);
Now, my question is, how can I have access to the size and the pointer to the data I want to allocate and later to deallocate?
Just found out:
The version of OpenCV I'm using (2.3.1) throws an error when using cvSetMemoryManager. The reason is in its source code:
void cvSetMemoryManager( CvAllocFunc, CvFreeFunc, void * )
{
CV_Error( -1, "Custom memory allocator is not supported" );
}
I was very disappointed with this. I guess I can't use a custom memory pool with OpenCV anymore!
Right from the docs
http://opencv.willowgarage.com/documentation/c/core_utility_and_system_functions_and_macros.html#setmemorymanager
Use the
void cvSetMemoryManager(CvAllocFunc allocFunc=NULL, CvFreeFunc freeFunc=NULL, void* userdata=NULL)
function.
Your code
cvSetMemoryManager(allocCV(),deallocCV(),data);
is WRONG.
See what happens: you call allocCV and deallocCV functions (they return some pointer which is quietly converted to cvAllocFunc) !
And this is only the beginning. See the docs for alloc/dealloc semantics. You should write allocCV/deallocCV with correct signatures.
void* CV_CDECL allocCV(size_t size, void* userdata)
{
return ((YourMemPoolTypeWhichIDoNotKnow*)userdata)->POOLalloc(size);
}
int CV_CDECL deallocCV(void* pptr, void* userdata)
{
return ((YourMemPoolTypeWhichIDoNotKnow*)userdata)->POOLfree(pptr);
}
and then pass your MEMPOOL in the 'userdata' parameter:
cvSetMemoryManager(&allocCV, &deallocCV, (void*)MEMPOOL);
This is a standard way for a library to provide user callbacks.

Resources