phobos/gc2/gclinux.d
2007-09-10 02:16:36 +00:00

89 lines
1.7 KiB
D

// Copyright (C) 2001-2003 by Digital Mars, www.digitalmars.com
// All Rights Reserved
// Written by Walter Bright
import linuxextern;
extern (C)
{
// from <sys/mman.h>
void* mmap(void* addr, uint len, int prot, int flags, int fd, uint offset);
int munmap(void* addr, uint len);
const void* MAP_FAILED = (void*)-1;
// from <bits/mman.h>
enum { PROT_NONE = 0, PROT_READ = 1, PROT_WRITE = 2, PROT_EXEC = 4 }
enum { MAP_SHARED = 1, MAP_PRIVATE = 2, MAP_TYPE = 0x0F,
MAP_FIXED = 0x10, MAP_FILE = 0, MAP_ANON = 0x20 }
}
/***********************************
* Map memory.
*/
void *os_mem_map(uint nbytes)
{ void *p;
//errno = 0;
p = mmap(null, nbytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
return (p == MAP_FAILED) ? null : p;
}
/***********************************
* Commit memory.
* Returns:
* 0 success
* !=0 failure
*/
int os_mem_commit(void *base, uint offset, uint nbytes)
{
return 0;
}
/***********************************
* Decommit memory.
* Returns:
* 0 success
* !=0 failure
*/
int os_mem_decommit(void *base, uint offset, uint nbytes)
{
return 0;
}
/***********************************
* Unmap memory allocated with os_mem_map().
* Returns:
* 0 success
* !=0 failure
*/
int os_mem_unmap(void *base, uint nbytes)
{
return munmap(base, nbytes);
}
/**********************************************
* Determine "bottom" of stack (actually the top on x86 systems).
*/
void *os_query_stackBottom()
{
return __libc_stack_end;
}
/**********************************************
* Determine base address and size of static data segment.
*/
void os_query_staticdataseg(void **base, uint *nbytes)
{
*base = (void *)&__data_start;
*nbytes = &_end - &__data_start;
}