/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
* Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
# include "private/gc_priv.h"
# if defined(LINUX) && !defined(POWERPC)
# include <linux/version.h>
# if (LINUX_VERSION_CODE <= 0x10400)
/* Ugly hack to get struct sigcontext_struct definition. Required */
/* for some early 1.3.X releases. Will hopefully go away soon. */
/* in some later Linux releases, asm/sigcontext.h may have to */
/* be included instead. */
# define __KERNEL__
# include <asm/signal.h>
# undef __KERNEL__
# else
/* Kernels prior to 2.1.1 defined struct sigcontext_struct instead of */
/* struct sigcontext. libc6 (glibc2) uses "struct sigcontext" in */
/* prototypes, so we have to include the top-level sigcontext.h to */
/* make sure the former gets defined to be the latter if appropriate. */
# include <features.h>
# if 2 <= __GLIBC__
# if 2 == __GLIBC__ && 0 == __GLIBC_MINOR__
/* glibc 2.1 no longer has sigcontext.h. But signal.h */
/* has the right declaration for glibc 2.1. */
# include <sigcontext.h>
# endif /* 0 == __GLIBC_MINOR__ */
# else /* not 2 <= __GLIBC__ */
/* libc5 doesn't have <sigcontext.h>: go directly with the kernel */
/* one. Check LINUX_VERSION_CODE to see which we should reference. */
# include <asm/sigcontext.h>
# endif /* 2 <= __GLIBC__ */
# endif
# endif
# if !defined(OS2) && !defined(PCR) && !defined(AMIGA) && !defined(MACOS) \
&& !defined(MSWINCE)
# include <sys/types.h>
# if !defined(MSWIN32) && !defined(SUNOS4)
# include <unistd.h>
# endif
# endif
# include <stdio.h>
# if defined(MSWINCE)
# define SIGSEGV 0 /* value is irrelevant */
# else
# include <signal.h>
# endif
/* Blatantly OS dependent routines, except for those that are related */
/* to dynamic loading. */
# if defined(HEURISTIC2) || defined(SEARCH_FOR_DATA_START)
# define NEED_FIND_LIMIT
# endif
# if !defined(STACKBOTTOM) && defined(HEURISTIC2)
# define NEED_FIND_LIMIT
# endif
# if (defined(SUNOS4) && defined(DYNAMIC_LOADING)) && !defined(PCR)
# define NEED_FIND_LIMIT
# endif
# if (defined(SVR4) || defined(AUX) || defined(DGUX) \
|| (defined(LINUX) && defined(SPARC))) && !defined(PCR)
# define NEED_FIND_LIMIT
# endif
#if defined(FREEBSD) && defined(I386)
# include <machine/trap.h>
# if !defined(PCR)
# define NEED_FIND_LIMIT
# endif
#endif
#if (defined(NETBSD) || defined(OPENBSD)) && defined(__ELF__) \
&& !defined(NEED_FIND_LIMIT)
/* Used by GC_init_netbsd_elf() below. */
# define NEED_FIND_LIMIT
#endif
#ifdef NEED_FIND_LIMIT
# include <setjmp.h>
#endif
#ifdef AMIGA
# define GC_AMIGA_DEF
# include "AmigaOS.c"
# undef GC_AMIGA_DEF
#endif
#if defined(MSWIN32) || defined(MSWINCE)
# define WIN32_LEAN_AND_MEAN
# define NOSERVICE
# include <windows.h>
#endif
#ifdef MACOS
# include <Processes.h>
#endif
#ifdef IRIX5
# include <sys/uio.h>
# include <malloc.h> /* for locking */
#endif
#if defined(USE_MMAP) || defined(USE_MUNMAP)
# ifndef USE_MMAP
--> USE_MUNMAP requires USE_MMAP
# endif
# include <sys/types.h>
# include <sys/mman.h>
# include <sys/stat.h>
# include <errno.h>
#endif
#ifdef UNIX_LIKE
# include <fcntl.h>
# if defined(SUNOS5SIGS) && !defined(FREEBSD)
# include <sys/siginfo.h>
# endif
/* Define SETJMP and friends to be the version that restores */
/* the signal mask. */
# define SETJMP(env) sigsetjmp(env, 1)
# define LONGJMP(env, val) siglongjmp(env, val)
# define JMP_BUF sigjmp_buf
#else
# define SETJMP(env) setjmp(env)
# define LONGJMP(env, val) longjmp(env, val)
# define JMP_BUF jmp_buf
#endif
#ifdef DARWIN
/* for get_etext and friends */
#include <mach-o/getsect.h>
#endif
#ifdef DJGPP
/* Apparently necessary for djgpp 2.01. May cause problems with */
/* other versions. */
typedef long unsigned int caddr_t;
#endif
#ifdef PCR
# include "il/PCR_IL.h"
# include "th/PCR_ThCtl.h"
# include "mm/PCR_MM.h"
#endif
#if !defined(NO_EXECUTE_PERMISSION)
# define OPT_PROT_EXEC PROT_EXEC
#else
# define OPT_PROT_EXEC 0
#endif
#if defined(LINUX) && \
(defined(USE_PROC_FOR_LIBRARIES) || defined(IA64) || !defined(SMALL_CONFIG))
/* We need to parse /proc/self/maps, either to find dynamic libraries, */
/* and/or to find the register backing store base (IA64). Do it once */
/* here. */
#define READ read
/* Repeatedly perform a read call until the buffer is filled or */
/* we encounter EOF. */
ssize_t GC_repeat_read(int fd, char *buf, size_t count)
{
ssize_t num_read = 0;
ssize_t result;
while (num_read < count) {
result = READ(fd, buf + num_read, count - num_read);
if (result < 0) return result;
if (result == 0) break;
num_read += result;
}
return num_read;
}
/*
* Apply fn to a buffer containing the contents of /proc/self/maps.
* Return the result of fn or, if we failed, 0.
* We currently do nothing to /proc/self/maps other than simply read
* it. This code could be simplified if we could determine its size
* ahead of time.
*/
word GC_apply_to_maps(word (*fn)(char *))
{
int f;
int result;
size_t maps_size = 4000; /* Initial guess. */
static char init_buf[1];
static char *maps_buf = init_buf;
static size_t maps_buf_sz = 1;
/* Read /proc/self/maps, growing maps_buf as necessary. */
/* Note that we may not allocate conventionally, and */
/* thus can't use stdio. */
do {
if (maps_size >= maps_buf_sz) {
/* Grow only by powers of 2, since we leak "too small" buffers. */
while (maps_size >= maps_buf_sz) maps_buf_sz *= 2;
maps_buf = GC_scratch_alloc(maps_buf_sz);
if (maps_buf == 0) return 0;
}
f = open("/proc/self/maps", O_RDONLY);
if (-1 == f) return 0;
maps_size = 0;
do {
result = GC_repeat_read(f, maps_buf, maps_buf_sz-1);
if (result <= 0) return 0;
maps_size += result;
} while (result == maps_buf_sz-1);
close(f);
} while (maps_size >= maps_buf_sz);
maps_buf[maps_size] = '\0';
/* Apply fn to result. */
return fn(maps_buf);
}
#endif /* Need GC_apply_to_maps */
#if defined(LINUX) && (defined(USE_PROC_FOR_LIBRARIES) || defined(IA64))
//
// GC_parse_map_entry parses an entry from /proc/self/maps so we can
// locate all writable data segments that belong to shared libraries.
// The format of one of these entries and the fields we care about
// is as follows:
// XXXXXXXX-XXXXXXXX r-xp 00000000 30:05 260537 name of mapping...\n
// ^^^^^^^^ ^^^^^^^^ ^^^^ ^^
// start end prot maj_dev
// 0 9 18 32
//
// For 64 bit ABIs:
// 0 17 34 56
//
// The parser is called with a pointer to the entry and the return value
// is either NULL or is advanced to the next entry(the byte after the
// trailing '\n'.)
//
#if CPP_WORDSZ == 32
# define OFFSET_MAP_START 0
# define OFFSET_MAP_END 9
# define OFFSET_MAP_PROT 18
# define OFFSET_MAP_MAJDEV 32
# define ADDR_WIDTH 8
#endif
#if CPP_WORDSZ == 64
# define OFFSET_MAP_START 0
# define OFFSET_MAP_END 17
# define OFFSET_MAP_PROT 34
# define OFFSET_MAP_MAJDEV 56
# define ADDR_WIDTH 16
#endif
/*
* Assig
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
gc.tar.gz_garbage_garbage collection_回收站_垃圾回收 (179个子文件)
Makefile.am 6KB
Makefile.am 1KB
Makefile.am 1KB
README.amiga 13KB
SMakefile.amiga 4KB
README.autoconf 2KB
barrett_diagram 6KB
BCC_MAKEFILE 2KB
os_dep.c 125KB
mark.c 55KB
test.c 47KB
pthread_support.c 47KB
dyn_load.c 37KB
dbg_mlc.c 33KB
misc.c 32KB
alloc.c 31KB
reclaim.c 28KB
solaris_threads.c 28KB
finalize.c 27KB
cordbscs.c 27KB
typd_mlc.c 26KB
allchblk.c 24KB
win32_threads.c 22KB
mach_dep.c 21KB
aix_irix_threads.c 21KB
mallocx.c 20KB
mark_rts.c 19KB
cordxtra.c 17KB
de.c 16KB
gcc_support.c 15KB
AmigaOS.c 14KB
backgraph.c 14KB
pthread_stop_world.c 14KB
malloc.c 13KB
cordprnt.c 11KB
darwin_stop_world.c 11KB
de_win.c 10KB
headers.c 10KB
gcj_mlc.c 9KB
ptr_chck.c 9KB
blacklst.c 9KB
stubborn.c 9KB
cordtest.c 8KB
new_hblk.c 7KB
checksums.c 6KB
solaris_pthreads.c 5KB
specific.c 5KB
pcr_interface.c 5KB
obj_map.c 4KB
MacOS.c 4KB
setjmp_t.c 3KB
gc_dlopen.c 3KB
threadlibs.c 1KB
real_malloc.c 1021B
thread_leak_test.c 896B
if_not_there.c 876B
if_mach.c 763B
trace_test.c 591B
middle.c 518B
leak_test.c 489B
add_gc_prefix.c 423B
gcname.c 275B
datastart.c 125B
dataend.c 121B
callprocs 148B
test_cpp.cc 8KB
gc_cpp.cc 2KB
README.changes 115KB
configure 298KB
README.contributors 3KB
README.cords 2KB
gc_cpp.cpp 75B
README.arm.cross 2KB
README.darwin 6KB
depcomp 12KB
README.DGUX386 6KB
Makefile.direct 33KB
Makefile.dj 21KB
README.dj 376B
Makefile.DLLs 4KB
EMX_MAKEFILE 5KB
README.environment 7KB
README.ews4800 2KB
config.guess 38KB
gc_priv.h 69KB
gcconfig.h 68KB
gc.h 42KB
gc_locks.h 24KB
new_gc_alloc.h 14KB
cord.h 14KB
gc_pmark.h 13KB
gc_cpp.h 12KB
gc_alloc.h 11KB
gc_mark.h 9KB
weakpointer.h 9KB
gc_allocator.h 7KB
gc_hdrs.h 7KB
dbg_mlc.h 6KB
gc_gcj.h 5KB
gc_typed.h 4KB
共 179 条
- 1
- 2
资源评论
我虽横行却不霸道
- 粉丝: 72
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功