Exemple #1
0
/*
 * 从给定目录中搜索与指定版本最匹配的jre安装路径
 */
static char *ProcessDir(manifest_info *info, char *dirname)
{
    DIR     *dirp;
    struct dirent *dp;
    char    *best = NULL;
    int     offset;
    int     best_offset = 0;
    char    *ret_str = NULL;
    char    buffer[PATH_MAX];

    printf("%s[%d] [tid: %lu]: 开始从目录[%]中搜索安装的最佳jre版本...\n", __FILE__, __LINE__, pthread_self(), dirname);

    if ((dirp = opendir(dirname)) == NULL)
        return (NULL);

    do {
        if ((dp = readdir(dirp)) != NULL) {
            offset = 0;
            if ((JLI_StrNCmp(dp->d_name, "jre", 3) == 0) ||
                (JLI_StrNCmp(dp->d_name, "jdk", 3) == 0))
                offset = 3;
            else if (JLI_StrNCmp(dp->d_name, "j2re", 4) == 0)
                offset = 4;
            else if (JLI_StrNCmp(dp->d_name, "j2sdk", 5) == 0)
                offset = 5;

            if (offset > 0) {
                if ((JLI_AcceptableRelease(dp->d_name + offset,
                    info->jre_version)) && CheckSanity(dirname, dp->d_name)){

                    if ((best == NULL) || (JLI_ExactVersionId(
                      dp->d_name + offset, best + best_offset) > 0)) {
                        if (best != NULL)
                            JLI_MemFree(best);
                        best = JLI_StringDup(dp->d_name);
                        best_offset = offset;
                    }
                }
            }
        }

    } while (dp != NULL);

    (void) closedir(dirp);

    if (best == NULL){
    	printf("%s[%d] [tid: %lu]: 目录[%]中没有找到合适的jre版本...\n", __FILE__, __LINE__, pthread_self(), dirname);

        return (NULL);
    }
    else {
        ret_str = JLI_MemAlloc(JLI_StrLen(dirname) + JLI_StrLen(best) + 2);
        sprintf(ret_str, "%s/%s", dirname, best);
        JLI_MemFree(best);

        printf("%s[%d] [tid: %lu]: 搜索到最合适的jre版本: %s...\n", __FILE__, __LINE__, pthread_self(), ret_str);

        return (ret_str);
    }
}
/*
 * Allocated memory will be surrounded by 8 guard-bytes that will be
 * checked at deallocation. (a leading and trailing unsigned int)
 */
inline void * allocate(unsigned int size, const char *file, int line, const char *type)
{
	// before allocation new memory, check for corruption in existing markers
	CheckSanity();

	Uint32 extraNomansLand = 0;
	size = size + extraNomansLand;

	Uint32 neededSize = (size + 3) & 0xffffffc;  // actual allocated memory for data (assumption: 32 bit architecture)
    neededSize += markerSize;                    // add area of markers

    void * ptr = (void *) malloc(neededSize);
    memset(ptr, 0xa6, neededSize);		// no-mans land poison

	unsigned int *markBegin = (unsigned int *) ptr;
	*markBegin = 0xa1a2a3a4;

    unsigned int *markEnd = (unsigned int *) ADDPTR(ptr, neededSize-postfix);
 	*markEnd = 0xf1f2f3f4;

	// increse ptr behound the magic marker
	ptr = ADDPTR(ptr, prefix);

	memset(ptr, 0xa5, size);		// un-initialized poison
	
	traceMap[ptr] = new TraceItem(size, neededSize, file, line, type);
    DBERR("MEMORY allocation at 0x%08X (%s) of %u bytes from %s:%u\n", ptr, type, size, file, line);
    return ptr;
}