char *platform_get_nextopenstep_runtime_os(void)
{
    kern_return_t ret;
    kernel_version_t string;
    char *version = NULL;
    int i = 0;

    if (!got_os) {
        ret = host_kernel_version(host_self(), string);
        if (ret != KERN_SUCCESS) {
            sprintf(os, "Unknown NextStep or OpenStep version\n");
        } else {
            version = string;
            while (*version != ' ') {
                version ++;
            }
            version++;
            while (*version != ' ') {
                version ++;
            }
            version++;
            while (version[i] != ':') {
                i++;
            }
            version[i] = 0;
            if (version[0] == '4') {
                sprintf(os, "OpenStep %s", version);
            } else {
                sprintf(os, "NextStep %s", version);
            }
        }
        got_os = 1;
    }
    return os;
}
Exemplo n.º 2
0
static int proc_readosfmach3(
	struct inode *inode,
	struct file *file,
	char *buf,
	int count)
{
	char * page;
	int length;
	unsigned int ino;
	kern_return_t	kr;

	if (count < 0)
		return -EINVAL;
	if (!(page = (char*) __get_free_page(GFP_KERNEL)))
		return -ENOMEM;
	ino = inode->i_ino;

	switch (ino) 
	{
	case PROC_OSFMACH3_VERSION:

		kr = host_kernel_version(host_port, page);
		
		if (kr != KERN_SUCCESS) {
			MACH3_DEBUG(2, kr,
				    ("proc_readosfmach3: host_kernel_version"));
		}
			
		length = strlen(page);
		break;
	case PROC_OSFMACH3_VM_STATISTICS: {
		
		extern struct vm_statistics osfmach3_vm_stats;

		osfmach3_update_vm_info();

		length = sprintf(page,
				 "free_count      : %d\n"
				 "active_count    : %d\n"
				 "inactive_count  : %d\n"
				 "wire_count      : %d\n"
				 "zero_fill_count : %d\n"
				 "reactivations   : %d\n"
				 "pageins         : %d\n"
				 "pageouts        : %d\n"
				 "faults          : %d\n"
				 "cow_faults      : %d\n"
				 "lookups         : %d\n"
				 "hits            : %d\n",
				 osfmach3_vm_stats.free_count,
				 osfmach3_vm_stats.active_count,
				 osfmach3_vm_stats.inactive_count,
				 osfmach3_vm_stats.wire_count,
				 osfmach3_vm_stats.zero_fill_count,
				 osfmach3_vm_stats.reactivations,
				 osfmach3_vm_stats.pageins,
				 osfmach3_vm_stats.pageouts,
				 osfmach3_vm_stats.faults,
				 osfmach3_vm_stats.cow_faults,
				 osfmach3_vm_stats.lookups,
				 osfmach3_vm_stats.hits);
		break;
	}

        case PROC_OSFMACH3_HOST_SCHED_INFO: {
		
		struct host_sched_info sched_info;
		int count = sizeof(sched_info);

		kr = host_info(host_port,
			       HOST_SCHED_INFO,
			       (host_info_t)&sched_info,
			       &count);

                if (kr != KERN_SUCCESS) {
                        MACH3_DEBUG(2, kr,
                                    ("proc_readosfmach3: host_info"));
                }

		length = sprintf(page,
				 "min_timeout : %d ms\n"
				 "min_quantum : %d ms\n",
				 sched_info.min_timeout,
				 sched_info.min_quantum);
		break;
	}

        case PROC_OSFMACH3_HOST_BASIC_INFO: {
		
		struct host_basic_info basic_info;
		int count = sizeof(basic_info);

		kr = host_info(host_port,
			       HOST_BASIC_INFO,
			       (host_info_t)&basic_info,
			       &count);

                if (kr != KERN_SUCCESS) {
                        MACH3_DEBUG(2, kr,
                                    ("proc_readosfmach3: host_info"));
                }

		length = sprintf(page,
				 "max_cpus    : %d\n"
				 "avail_cpus  : %d\n"
				 "memory_size : %d Mb\n",
				 basic_info.max_cpus,
				 basic_info.avail_cpus,
				 basic_info.memory_size / (1024 * 1024));

		break;
	}

	default:
		free_page((unsigned long) page);
		return -EBADF;
	}
		
	if (file->f_pos >= length) {
		free_page((unsigned long) page);
		return 0;
	}
	if (count + file->f_pos > length)
		count = length - file->f_pos;

	/*
	 *	Copy the bytes
	 */
	memcpy_tofs(buf, page + file->f_pos, count);

	free_page((unsigned long) page);

	file->f_pos += count;	/* Move down the file */

	return count;	/* all transfered correctly */
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    kern_return_t		ret;
    unsigned int		size, count;
    char			*cpu_name, *cpu_subname;
    int			i;
    int 			mib[2];
    size_t			len;
    uint64_t		memsize;
    processor_set_name_port_t		default_pset;
    host_name_port_t			host;
    struct processor_set_basic_info	basic_info;
    struct processor_set_load_info	load_info;

    host = mach_host_self();
    ret = host_kernel_version(host, version);
    if (ret != KERN_SUCCESS) {
        mach_error(argv[0], ret);
        exit(EXIT_FAILURE);
    }
    printf("Mach kernel version:\n\t %s\n", version);
    size = sizeof(hi)/sizeof(int);
    ret = host_info(host, HOST_BASIC_INFO, (host_info_t)&hi, &size);
    if (ret != KERN_SUCCESS) {
        mach_error(argv[0], ret);
        exit(EXIT_FAILURE);
    }

    ret = processor_set_default(host, &default_pset);
    if (ret != KERN_SUCCESS) {
        mach_error(argv[0], ret);
        exit(EXIT_FAILURE);
    }

    count = PROCESSOR_SET_BASIC_INFO_COUNT;
    ret = processor_set_info(default_pset, PROCESSOR_SET_BASIC_INFO,
                             &host, (processor_set_info_t)&basic_info, &count);
    if (ret != KERN_SUCCESS) {
        mach_error(argv[0], ret);
        exit(EXIT_FAILURE);
    }

    count = PROCESSOR_SET_LOAD_INFO_COUNT;
    ret = processor_set_statistics(default_pset, PROCESSOR_SET_LOAD_INFO,
                                   (processor_set_info_t)&load_info, &count);
    if (ret != KERN_SUCCESS) {
        mach_error(argv[0], ret);
        exit(EXIT_FAILURE);
    }

    mib[0] = CTL_HW;
    mib[1] = HW_MEMSIZE;
    len = sizeof(memsize);
    memsize = 0L;
    if(sysctl(mib, 2, &memsize, &len, NULL, 0 ) == -1)
    {
        perror("sysctl");
        exit(EXIT_FAILURE);
    }


    if (hi.max_cpus > 1)
        printf("Kernel configured for up to %d processors.\n",
               hi.max_cpus);
    else
        printf("Kernel configured for a single processor only.\n");
    printf("%d processor%s physically available.\n", hi.physical_cpu,
           (hi.physical_cpu > 1) ? "s are" : " is");

    printf("%d processor%s logically available.\n", hi.logical_cpu,
           (hi.logical_cpu > 1) ? "s are" : " is");

    printf("Processor type:");
    slot_name(hi.cpu_type, hi.cpu_subtype, &cpu_name, &cpu_subname);
    printf(" %s (%s)\n", cpu_name, cpu_subname);

    printf("Processor%s active:", (hi.avail_cpus > 1) ? "s" : "");
    for (i = 0; i < hi.avail_cpus; i++)
        printf(" %d", i);
    printf("\n");

    if (((float)memsize / (1024.0 * 1024.0)) >= 1024.0)
        printf("Primary memory available: %.2f gigabytes\n",
               (float)memsize/(1024.0*1024.0*1024.0));
    else
        printf("Primary memory available: %.2f megabytes\n",
               (float)memsize/(1024.0*1024.0));

    printf("Default processor set: %d tasks, %d threads, %d processors\n",
           load_info.task_count, load_info.thread_count, basic_info.processor_count);
    printf("Load average: %d.%02d, Mach factor: %d.%02d\n",
           load_info.load_average/LOAD_SCALE,
           (load_info.load_average%LOAD_SCALE)/10,
           load_info.mach_factor/LOAD_SCALE,
           (load_info.mach_factor%LOAD_SCALE)/10);

    exit(0);
}
Exemplo n.º 4
0
/* 
 * This function will send a single Mach message in an attempt 
 * to obtain the kernel version.  Once it has the reply from Mach, 
 * it will iterate the string and obtain a release number, system 
 * name, and kernel version string. 
 * 
 * This is trying to be as efficient as possible, but will probably 
 * end up being a very gnarly hack with no real value whatsoever. 
 */ 
void detectOpSysVersion(void) 
{ 
  kern_return_t kret; 
  kernel_version_t kver; 
  
  kret = host_kernel_version(host_self(), kver); 
  
  if (kret != KERN_SUCCESS) { 
    mach_error("host_kernel_version() failed.", kret); 
  } else { 
    int idx = 0, len = 0; 
    
    /* Copy the kernel version to a string */ 
    strcpy(version, kver); 
    len = strlen(version); 
    
    /* Remove trailing \n, if it exists */ 
    if (version[len -1] == '\n') 
      version[len - 1] = '\0'; 

    /* This is the slowest part of the whole thing... */ 
    for (idx = 0; idx < len; idx++) { 
      
      /* Version: [0-9].[0-9]: */ 
      if (isdigit(version[idx]) && version[idx + 1] == '.' && 
          isdigit(version[idx + 2]) && version[idx + 3] == ':') 
      { 
        sprintf(release, 
                "%c.%c\0", 
                version[idx], 
                version[idx + 2]); 
        break; 
      } 
      
      /* Version: [0-9].[0-9].[0-9]: */ 
      if (isdigit(version[idx]) && version[idx + 1] == '.' && 
          isdigit(version[idx + 2]) && version[idx + 3] == '.' && 
          isdigit(version[idx + 4]) && version[idx + 5] == ':') 
      { 
        sprintf(release, 
                "%c.%c.%c\0", 
                version[idx], 
                version[idx + 2], 
                version[idx + 4]); 
        break; 
      } 
      
      /* Version: [0-9][0-9].[0-9].[0-9]: */ 
      if (isdigit(version[idx]) && isdigit(version[idx + 1]) && 
          version[idx + 2] == '.' && isdigit(version[idx + 3]) && 
          version[idx + 4] == '.' && isdigit(version[idx + 5]) && 
          version[idx + 6] == ':') 
      { 
        sprintf(release, 
                "%c%c.%c.%c\0", 
                version[idx], 
                version[idx + 1], 
                version[idx + 3], 
                version[idx + 5]); 
        break; 
      } 
    } 
    
    /* 
     * Compute the system name using the major version. 
     * 
     * If release[1] != '.', then it's Darwin... and this program would 
     * look very stupid if it printed 'NEXTSTEP 10.0' on an OSX box. 
     */ 
    if (release[1] == '.') { 
      switch (release[0]) { 
        case '0': 
        case '1': 
        case '2': 
        case '3': 
          sprintf(sysname, "NEXTSTEP\0"); 
          break; 
    
        case '4': 
         sprintf(sysname, "OPENSTEP\0"); 
          break; 

        case '5': 
          sprintf(sysname, "Rhapsody\0"); 
          /* barf barf, Apple. */ 
          for (idx = 0; idx < len; idx++) 
            if (version[idx] == '\n') 
              version[idx] = ' '; 
          break; 

        default: 
          sprintf(sysname, "Darwin\0"); 
      } 
    } else { 
      sprintf(sysname, "Darwin\0"); 
    } 
  } /* if (kret != ... */ 

  /* 
   * Let's get the hostname on our way out 
   */ 
  gethostname(nodename, 255); 
}