05-05-2011
That is still an unsigned int pointer type, implying you are assigning only 32 bits. IBM says some pages are not mprotect friendly this way:
pSeries and AIX Information Center
You might need that env variable. I am familiar with self-modifying code from machine language, what do you want it to do?
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
Hi,
Does anyone seen this error before..
kernel: ENOMEM in journal_alloc_journal_head, retrying.
I encounter this problem on IBM eServers where when the above error appears usually the machine is dead or hanged. Unless a hard reboot is been done. Is this something have to do with the memory... (1 Reply)
Discussion started by: killerserv
1 Replies
2. Programming
When run it, segment fault.
What is wrong?
#include <stdio.h>
#include <stdlib.h>
const int max =20;
//****************************************************
// Input Matrix
//****************************************************
void inMatrixAA(int *AA, int row, int col)... (9 Replies)
Discussion started by: zhshqzyc
9 Replies
3. IP Networking
I do have 2 different segment network which different platform on each segment. E.g. 20 segment, Windows OS can talk to Unix OS and 21 segment practice same rule. Further more, Windows OS from 20 segment can talk to 21 segment other OS but only the UNIX OS in 20 segment fail to talk to 21 segment.... (3 Replies)
Discussion started by: HASM
3 Replies
4. Shell Programming and Scripting
Hey all, could someone please direct me on how to extract a segment from a file between two tags? Thanks! (1 Reply)
Discussion started by: mpang_
1 Replies
5. UNIX for Dummies Questions & Answers
how do i close a do code segment? od? (1 Reply)
Discussion started by: trob
1 Replies
6. Shell Programming and Scripting
I need help in removing a leading zero in a particular position.
For eg.: XYZ*04567472*0099*020091231*0123*0.12
In the above line, I want to replace "*0123" with "123" and "0.12" with ".12". I want to remove the leading zero only in position number 4 and 5 (the bolded segments)
I was able... (10 Replies)
Discussion started by: ananthmm
10 Replies
7. Programming
I mean, I malloc a segment of memory, maybe 1k maybe 20bytes.. assume the pointer is pMem How can I know the content pMem refered is all Zero or \0 . I know memcmp but the second parameter should another memory address... thanx (4 Replies)
Discussion started by: macroideal
4 Replies
8. Programming
Hi to all.
I'm reciving a "Segment violation" error from this code and I don't know why.
void insertAtEnd(NodeType *pList) {
char element;
printf("Introduce a element: \n");
setbuf(stdin, NULL);
scanf("%c", &element);
//Find the end of the list;
while... (4 Replies)
Discussion started by: daniel.gbaena
4 Replies
9. Programming
Hi,
Whether the following piece of code is placed in the read-only memory of code (text) segment or data segment?
char *a = "Hello";
I am getting two different answers while searching in google :( that's why the confusion is (7 Replies)
Discussion started by: royalibrahim
7 Replies
10. Programming
I always get segment fault, why? can sb help me and modify it, I have spend on much time on
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <string.h>
#define MAX 10
pthread_t thread;
void *thread1()
{
int *a;
int i, n;
... (1 Reply)
Discussion started by: yanglei_fage
1 Replies
LEARN ABOUT REDHAT
mprotect
MPROTECT(2) Linux Programmer's Manual MPROTECT(2)
NAME
mprotect - control allowable accesses to a region of memory
SYNOPSIS
#include <sys/mman.h>
int mprotect(const void *addr, size_t len, int prot);
DESCRIPTION
mprotect controls how a section of memory may be accessed. If an access is disallowed by the protection given it, the program receives a
SIGSEGV.
prot is a bitwise-or of the following values:
PROT_NONE The memory cannot be accessed at all.
PROT_READ The memory can be read.
PROT_WRITE The memory can be written to.
PROT_EXEC The memory can contain executing code.
The new protection replaces any existing protection. For example, if the memory had previously been marked PROT_READ, and mprotect is then
called with prot PROT_WRITE, it will no longer be readable.
RETURN VALUE
On success, mprotect returns zero. On error, -1 is returned, and errno is set appropriately.
ERRORS
EINVAL addr is not a valid pointer, or not a multiple of PAGESIZE.
EFAULT The memory cannot be accessed.
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.
ENOMEM Internal kernel structures could not be allocated.
EXAMPLE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
#include <limits.h> /* for PAGESIZE */
#ifndef PAGESIZE
#define PAGESIZE 4096
#endif
int
main(void)
{
char *p;
char c;
/* Allocate a buffer; it will have the default
protection of PROT_READ|PROT_WRITE. */
p = malloc(1024+PAGESIZE-1);
if (!p) {
perror("Couldn't malloc(1024)");
exit(errno);
}
/* Align to a multiple of PAGESIZE, assumed to be a power of two */
p = (char *)(((int) p + PAGESIZE-1) & ~(PAGESIZE-1));
c = p[666]; /* Read; ok */
p[666] = 42; /* Write; ok */
/* Mark the buffer read-only. */
if (mprotect(p, 1024, PROT_READ)) {
perror("Couldn't mprotect");
exit(errno);
}
c = p[666]; /* Read; ok */
p[666] = 42; /* Write; program dies on SIGSEGV */
exit(0);
}
CONFORMING TO
SVr4, POSIX.1b (formerly POSIX.4). SVr4 defines an additional error code EAGAIN. The SVr4 error conditions don't map neatly onto Linux's.
POSIX.1b says that mprotect can be used only on regions of memory obtained from mmap(2).
SEE ALSO
mmap(2)
Linux 2.0 1997-05-31 MPROTECT(2)