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
iomap(7) Miscellaneous Information Manual iomap(7)
NAME
iomap - physical I/O address mapping
SYNOPSIS
DESCRIPTION
The mechanism allows the mapping (thus direct access) of physical I/O addresses into the user process address space. For PA-RISC machines,
the physical I/O address space begins at and extends to
The special (device) files for devices are character special files using the dynamic major number allocation scheme.
The minor number for devices is of the form:
The physical I/O address is formed by prefixing 0xAAAA with 0xF, and by appending 0x000 (this forces the I/O address to be page-aligned).
The size of the region to be mapped is given by the expression M*(2^S) 4K pages. For example, the minor number for a device starting at
that occupies 64MB is
The driver must be explicitly added to the file, the kernel rebuilt, and the system subsequently rebooted prior to first using
I/O space is always mapped with both read and write access rights, regardless of the actual permissions on the device special file.
Multiple processes can have concurrently a single device opened and mapped. It is the responsibility of the processes to synchronize their
access.
Successive calls to to map the same I/O space must be identical to the first mapping. Identical mappings have the same address and size.
Note that a process can additionally share I/O space (mapped by with a kernel driver. However, this is only possible if the driver maps in
the I/O space with user read/write access rights using the appropriate driver I/O mapping services. Any I/O space mapped by drivers with
kernel read/write access rights cannot be concurrently mapped by processes using
No or system calls are supported by the driver.
The function is used to control the device. The following requests are defined in
Map the device into user address space at the location specified by the pointer to which the third argument to points. If
the argument points to a variable containing a null pointer, the system selects an appropriate address. then
returns the user address where the device was mapped, storing it at the address pointed to by the third argument
(see below). Multiple processes can concurrently have the same device mapped.
Unmap the device from the user address space.
shuts down the file descriptor associated with the device. If the close is for the last system wide open on the device, the device is also
unmapped from the user address space; otherwise it is left mapped into the user address space (see above).
WARNINGS
Be extremely careful when creating and using devices. Inappropriate accesses to I/O devices or RAM can result in a system crash.
ERRORS
The address field was out of range,
or the request was invalid.
Not enough memory could be allocated for the mapping.
Device was already mapped and this mapping was not identical
to the initial mapping (same address, size and access rights).
Read and write calls are unsupported.
No such device at the address specified by the minor number.
Required resources for mapping could not be allocated.
Inappropriate request for this device type; fildes is not a file descriptor for an device file.
EXAMPLES
Consider the following code fragment:
...
...
where is an open file descriptor for the device special file and is the address originally requested by the program.
If is a null pointer, the system selects a suitable address then returns the selected address in addr.
If the value in addr is not a null pointer, it is used as a specified address for allocating memory. If the specified address cannot be
used, an error is returned (see
SEE ALSO
mknod(1M).
OBSOLETED iomap(7)