10-15-2010
Quote:
Originally Posted by
dragonpoint
If user space heap and kernel space heaps are diff, can the allocated kernel/ user areas be accessed by mapping in either case all times?
Heap isn't a special kind of memory, even to the process. It's all just memory as far as they're concerned. Take a look at
The Paging Game to get a rough idea of what virtual memory does.
But it's not exactly direct. User space sees its own memory as a flat memory space but it's not: It's organized in 4K chunks in no particular order and might even be on disk, not in memory, when asked for. It's the kernel's job to keep that mess straight.
The kernel almost never reaches into process space to extract data without being told to do so. That's what read() and write() calls do when you think about it -- tell the kernel what areas of user memory to extract from, or to write into, for some operation or other. Once it's been told, copy_to_user and copy_from_user calls translate memory in and out of user space. Otherwise, the kernel's job is mostly set things up and let them happen in userspace.
Last edited by Corona688; 10-15-2010 at 10:38 PM..
10 More Discussions You Might Find Interesting
1. Programming
hello sir
since by mentioning a integer pointer and storing the integers
by incrementing the pointer value
then what is the purpose of malloc?
u can decalre it as
in t *p;
several integers can be stored by incrementing the value of p,
hence what is the diffrence between this... (2 Replies)
Discussion started by: rajashekaran
2 Replies
2. Programming
Hi!
I hope this is the correct forum to post the question even if I'm a newbie...
I am a C-newbie (and really on the edge to be a C-addict ;) ) and have a question.
When should I use malloc?
To state it differently, when should I NOT use malloc?
For instance, if I have an array of... (5 Replies)
Discussion started by: Tonje
5 Replies
3. UNIX for Dummies Questions & Answers
will kmalloc function allocate memory from kernel space or user space?
what exactly is the difference between kernel api and system call?
can anyone please send me the answer? its urgent. (0 Replies)
Discussion started by: sriram.ec
0 Replies
4. Programming
Some one please explain me what is Dynamic memory allocation and the use of malloc() function.How do we allocate memory dynamically and also the other way? (3 Replies)
Discussion started by: rash123
3 Replies
5. Programming
Hey Guys
I am trying to implement the malloc function for my OS class and I am having a little trouble with it. I would be really grateful if I could get some hints on this problem.
So I am using a doubly-linked list as my data structure and I have to allocate memory for it (duh...). The... (1 Reply)
Discussion started by: Gambit_b
1 Replies
6. UNIX for Advanced & Expert Users
Hey Guys
Some of my friends have got together and we are trying to write a basic kernel similar to Linux. I am trying to implement the malloc function in C and I am using a doubly linked list as the primary data structure. I need to allocate memory for this link list (duh...) and I don't feel... (2 Replies)
Discussion started by: rbansal2
2 Replies
7. Programming
Why when using realloc, john is reversed 3 times but not the other 2 names ? But if I use malloc, then the 3 names are reversed correctly ? (but then there is a memory leak)
How can I reverse all 3 names without a memory leak ?
char *BUFFER = NULL;
char *STRREVERSE(const char *STRING)
{... (5 Replies)
Discussion started by: cyler
5 Replies
8. Programming
Hi i found code in google how to malloc an 2D array and i tried that :
#include<stdio.h>
#include<stdlib.h>
int **A;
int **B;
int main(int argc,char *argv)
{
printf("name of text : %s\n",argv);
//read arrays
int i,j;
int l,m;
int M,n;
FILE *fp;
fp=fopen(argv,"r");
... (0 Replies)
Discussion started by: giampoul
0 Replies
9. Programming
Which one is faster among malloc and new?
My understanding is that since new also has to call constructors after allocating memory it must be slower than malloc.
Am I correct? (1 Reply)
Discussion started by: rupeshkp728
1 Replies
10. UNIX for Dummies Questions & Answers
Good day! I'm a newbie in C. I'm trying to get an unlimited input from the user using malloc then printing the inputs after the user presses enter. My code works, but there's a warning that I don't know how to fix. Please help me. Thank you.
Here's my code:
#include <stdio.h>
#include... (6 Replies)
Discussion started by: eracav
6 Replies
LEARN ABOUT FREEBSD
sf_buf
SF_BUF(9) BSD Kernel Developer's Manual SF_BUF(9)
NAME
sf_buf -- manage temporary kernel address space mapping for memory pages
SYNOPSIS
#include <sys/sf_buf.h>
struct sf_buf *
sf_buf_alloc(struct vm_page *m, int flags);
void
sf_buf_free(struct sf_buf *sf);
vm_offset_t
sf_buf_kva(struct sf_buf *sf);
struct vm_page *
sf_buf_page(struct sf_buf *sf);
DESCRIPTION
The sf_buf interface, historically the sendfile(2) buffer interface, allows kernel subsystems to manage temporary kernel address space map-
pings for physical memory pages. On systems with a direct memory map region (allowing all physical pages to be visible in the kernel address
space at all times), the struct sf_buf will point to an address in the direct map region; on systems without a direct memory map region, the
struct sf_buf will manage a temporary kernel address space mapping valid for the lifetime of the struct sf_buf.
Call sf_buf_alloc() to allocate a struct sf_buf for a physical memory page. sf_buf_alloc() is not responsible for arranging for the page to
be present in physical memory; the caller should already have arranged for the page to be wired, i.e., by calling vm_page_wire(9). Several
flags may be passed to sf_buf_alloc():
SFB_CATCH Cause sf_buf_alloc() to abort and return NULL if a signal is received waiting for a struct sf_buf to become available.
SFB_NOWAIT Cause sf_buf_alloc() to return NULL rather than sleeping if a struct sf_buf is not immediately available.
SFB_CPUPRIVATE Cause sf_buf_alloc() to only arrange that the temporary mapping be valid on the current CPU, avoiding unnecessary TLB shoot-
downs for mappings that will only be accessed on a single CPU at a time. The caller must ensure that accesses to the virtual
address occur only on the CPU from which sf_buf_alloc() was invoked, perhaps by using sched_pin().
Call sf_buf_kva() to return a kernel mapped address for the page.
Call sf_buf_page() to return a pointer to the page originally passed into sf_buf_alloc().
Call sf_buf_free() to release the struct sf_buf reference. The caller is responsible for releasing any wiring they have previously acquired
on the physical page; sf_buf_free() releases only the temporary kernel address space mapping, not the page itself.
Uses of this interface include managing mappings of borrowed pages from user memory, such as in zero-copy socket I/O, or pages of memory from
the buffer cache referenced by mbuf external storage for sendfile(2).
SEE ALSO
sendfile(2), vm_page_wire(9)
AUTHORS
The struct sf_buf API was designed and implemented by Alan L. Cox. This manual page was written by Robert N. M. Watson.
BSD
January 28, 2007 BSD