re PR go/47515 (Issues porting libgo to IRIX 6.5)

PR go/47515
runtime: If no MAP_ANON, use /dev/zero.

From-SVN: r169388
This commit is contained in:
Ian Lance Taylor 2011-01-29 07:16:20 +00:00
parent e0b77418ce
commit ca7174cf5c
2 changed files with 30 additions and 1 deletions

View File

@ -3,13 +3,39 @@
#include "runtime.h"
#include "malloc.h"
#ifndef MAP_ANON
#ifdef MAP_ANONYMOUS
#define MAP_ANON MAP_ANONYMOUS
#else
#define USE_DEV_ZERO
#define MAP_ANON 0
#endif
#endif
#ifdef USE_DEV_ZERO
static int dev_zero = -1;
#endif
void*
runtime_SysAlloc(uintptr n)
{
void *p;
int fd = -1;
mstats.sys += n;
p = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
#ifdef USE_DEV_ZERO
if (dev_zero == -1) {
dev_zero = open("/dev/zero", O_RDONLY);
if (dev_zero < 0) {
printf("open /dev/zero: errno=%d\n", errno);
exit(2);
}
}
fd = dev_zero;
#endif
p = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, fd, 0);
if (p == MAP_FAILED) {
if(errno == EACCES) {
printf("mmap: access denied\n");

View File

@ -12,6 +12,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>