Sponsored Content
Full Discussion: mmap
Homework and Emergencies Emergency UNIX and Linux Support mmap Post 302567440 by xerox on Monday 24th of October 2011 08:04:42 AM
Old 10-24-2011
Data mmap

I want to know whether this is possile or ever been tried out.

I want to obtain a chuck of memory using mmap()

I do it so :

Code:
n = mmap(0, 8000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);

And hold on to that memory, when a process requests for memory, some memory is assigned from this chunk.

In Linux is it possible to control where the new process gets it's memory from? Can i create a process that will only get memory from the chunk of memory i reserved?
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

mmap

Hello. I'm writing some random access i/o software on Solaris 8 using mmap64 to memory map large files (my test file is ~25 GB). The abbreviated code fragment is: fd = open(cbuf,O_RDONLY|O_LARGEFILE); struct stat statbuf; fstat(fd,&statbuf); off_t len =... (0 Replies)
Discussion started by: gusm
0 Replies

2. HP-UX

mmap failed

We recently have been seeing the following type of error on our development server. Being somewhat new to HP-UX I was hoping to get some insight. Here is what I have found. I have been doing some research. /usr/lib/dld.sl: Call to mmap() failed - TEXT /u07/mdev/lib/libCLEND.sl... (2 Replies)
Discussion started by: scotbuff
2 Replies

3. UNIX for Advanced & Expert Users

mmap and select

I'm using select() to monitor multiple file descriptors (inet sockets) in application. But this application must also collaborate with other applications on the same host via shared memory (mmap'ed file) due to performance reasons. How can I become notification that mmaped memory is changed or... (1 Reply)
Discussion started by: Hitori
1 Replies

4. Solaris

mmap() on 64 bit m/c

Dear Experts, i have a problem related to mmap(), when i run my program on sun for 64 bit which is throwing SIGBUS when it encounters mmap() function, what is the reason how to resolve this one, because it is working for 32 bit. with regards, vidya. (2 Replies)
Discussion started by: vin_pll
2 Replies

5. UNIX for Dummies Questions & Answers

mmap()

how to use mmap() to map a file to memory space. Do you have any simple program???? Because I have to implement lot of concepts into it. (3 Replies)
Discussion started by: gokult
3 Replies

6. Programming

mmap()

how to use mmap() to map a file to memory space. Do you have any simple program???? Because I have to implement lot of concepts into it. (5 Replies)
Discussion started by: gokult
5 Replies

7. Homework & Coursework Questions

mmap

Descriptions: Develop a program that uses mmap() to map a file to memory space. Prepare such a file by yourself and do the follows. <LI class=MsoNormal>Display the content of the file after mapping; <LI class=MsoNormal>Output how many digits included in the file; <LI class=MsoNormal>Replace... (1 Reply)
Discussion started by: gokult
1 Replies

8. Programming

mmap

hai, How do we map 'n' number of files into memory by using mmap system call?? Thanks in advance...... (5 Replies)
Discussion started by: andrew.paul
5 Replies

9. UNIX for Advanced & Expert Users

Regarding MMAP, MLOCK etc..

Hi I want to lock or prevent a portion of memory which I allocated. So I tried MLOCK, MPROTECT and some like this. But all these functions works only on page border. Can I know why that so. Is that possible to protect a portion of memory which is in middle of the page. Example. int A; ... (1 Reply)
Discussion started by: jionnet
1 Replies

10. BSD

Mmap source

I'm new to kernels and C, and I am tinkering around trying to understand OpenBSD's secure memory management. I'm stumped on a couple points. I've read up on malloc() which was apparently modified years ago to allocate memory using mmap. First question, that would be this here, right? ... (4 Replies)
Discussion started by: dcicc
4 Replies
MPROTECT(2)						     Linux Programmer's Manual						       MPROTECT(2)

NAME
mprotect - set protection on a region of memory SYNOPSIS
#include <sys/mman.h> int mprotect(void *addr, size_t len, int prot); DESCRIPTION
mprotect() changes protection for the calling process's memory page(s) containing any part of the address range in the interval [addr, addr+len-1]. addr must be aligned to a page boundary. If the calling process tries to access memory in a manner that violates the protection, then the kernel generates a SIGSEGV signal for the process. prot is either PROT_NONE or a bitwise-or of the other values in the following list: PROT_NONE The memory cannot be accessed at all. PROT_READ The memory can be read. PROT_WRITE The memory can be modified. PROT_EXEC The memory can be executed. RETURN VALUE
On success, mprotect() returns zero. On error, -1 is returned, and errno is set appropriately. ERRORS
EACCES The memory cannot be given the specified access. This can happen, for example, if you mmap(2) a file to which you have read-only access, then ask mprotect() to mark it PROT_WRITE. EINVAL addr is not a valid pointer, or not a multiple of the system page size. ENOMEM Internal kernel structures could not be allocated. ENOMEM Addresses in the range [addr, addr+len-1] are invalid for the address space of the process, or specify one or more pages that are not mapped. (Before kernel 2.4.19, the error EFAULT was incorrectly produced for these cases.) CONFORMING TO
SVr4, POSIX.1-2001. POSIX says that the behavior of mprotect() is unspecified if it is applied to a region of memory that was not obtained via mmap(2). NOTES
On Linux it is always permissible to call mprotect() on any address in a process's address space (except for the kernel vsyscall area). In particular it can be used to change existing code mappings to be writable. Whether PROT_EXEC has any effect different from PROT_READ is architecture- and kernel version-dependent. On some hardware architectures (e.g., i386), PROT_WRITE implies PROT_READ. POSIX.1-2001 says that an implementation may permit access other than that specified in prot, but at a minimum can allow write access only if PROT_WRITE has been set, and must not allow any access if PROT_NONE has been set. EXAMPLE
The program below allocates four pages of memory, makes the third of these pages read-only, and then executes a loop that walks upward through the allocated region modifying bytes. An example of what we might see when running the program is the following: $ ./a.out Start of region: 0x804c000 Got SIGSEGV at address: 0x804e000 Program source #include <unistd.h> #include <signal.h> #include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <errno.h> #include <sys/mman.h> #define handle_error(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0) char *buffer; static void handler(int sig, siginfo_t *si, void *unused) { printf("Got SIGSEGV at address: 0x%lx ", (long) si->si_addr); exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { char *p; int pagesize; struct sigaction sa; sa.sa_flags = SA_SIGINFO; sigemptyset(&sa.sa_mask); sa.sa_sigaction = handler; if (sigaction(SIGSEGV, &sa, NULL) == -1) handle_error("sigaction"); pagesize = sysconf(_SC_PAGE_SIZE); if (pagesize == -1) handle_error("sysconf"); /* Allocate a buffer aligned on a page boundary; initial protection is PROT_READ | PROT_WRITE */ buffer = memalign(pagesize, 4 * pagesize); if (buffer == NULL) handle_error("memalign"); printf("Start of region: 0x%lx ", (long) buffer); if (mprotect(buffer + pagesize * 2, pagesize, PROT_READ) == -1) handle_error("mprotect"); for (p = buffer ; ; ) *(p++) = 'a'; printf("Loop completed "); /* Should never happen */ exit(EXIT_SUCCESS); } SEE ALSO
mmap(2), sysconf(3) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2012-08-14 MPROTECT(2)
All times are GMT -4. The time now is 04:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy