char *platform_get_freebsd_runtime_cpu(void) { char *model = NULL; size_t len = 0; if (!got_freebsd_cpu) { sprintf(freebsd_cpu, "Unknown CPU"); sysctlbyname("hw.model", NULL, &len, NULL, 0); model = lib_malloc(len); sysctlbyname("hw.model", model, &len, NULL, 0); sprintf(freebsd_cpu, "%s", model); #ifndef PLATFORM_NO_X86_ASM if (strstr(freebsd_cpu, "Unknown") || !strlen(freebsd_cpu)) { sprintf(freebsd_cpu, "%s", platform_get_x86_runtime_cpu()); } #endif if (model) { lib_free(model); } got_freebsd_cpu = 1; } return freebsd_cpu; }
char *archdep_get_runtime_cpu(void) { #ifdef WORDS_BIGENDIAN return platform_get_beosppc_runtime_cpu(); #else return platform_get_x86_runtime_cpu(); #endif }
char *platform_get_linux_runtime_cpu(void) { FILE *cpuinfo = NULL; char *buffer = NULL; char *loc1 = NULL; char *loc2 = NULL; char *loc3 = NULL; char *tempfile = NULL; char *tempsystem = NULL; size_t size1 = 0; size_t size2 = 0; struct utsname name; if (!got_linux_cpu) { sprintf(linux_cpu, "Unknown CPU"); cpuinfo = fopen("/proc/cpuinfo", "rb"); if (cpuinfo) { fclose(cpuinfo); cpuinfo = NULL; tempfile = archdep_tmpnam(); tempsystem = util_concat("cat /proc/cpuinfo >", tempfile, NULL); if (system(tempsystem) < 0) { log_warning(LOG_ERR, "`%s' failed.", tempsystem); } cpuinfo = fopen(tempfile, "rb"); } if (cpuinfo) { fseek(cpuinfo, 0L, SEEK_END); size1 = ftell(cpuinfo); fseek(cpuinfo, 0L, SEEK_SET); buffer = (char *)malloc(size1); size2 = fread(buffer, 1, size1, cpuinfo); if (size1 == size2) { loc1 = strstr(buffer, "model name"); if (!loc1) { loc1 = strstr(buffer, "cpu type"); } if (!loc1) { loc1 = strstr(buffer, "cpu model"); } if (!loc1) { loc1 = strstr(buffer, "Processor"); } if (!loc1) { loc1 = strstr(buffer, "cpu"); if (loc1 && loc1 != buffer) { loc1--; if (*loc1 != '\n' && isspace(*loc1)) { loc1 = NULL; } } } if (!loc1) { loc1 = strstr(buffer, "CPU"); } if (!loc1) { loc1 = strstr(buffer, "vendor_id"); } if (loc1) { loc2 = strstr(loc1, ":"); if (loc2) { loc2 += 2; while (isspace(*loc2)) { loc2++; } loc3 = strstr(loc2, "\n"); if (loc3) { *loc3 = 0; sprintf(linux_cpu, "%s", loc2); got_linux_cpu = 1; } } } } fclose(cpuinfo); unlink(tempfile); lib_free(tempfile); lib_free(tempsystem); if (buffer) { free(buffer); } } #ifndef PLATFORM_NO_X86_ASM if (!got_linux_cpu) { sprintf(linux_cpu, "%s", platform_get_x86_runtime_cpu()); got_linux_cpu = 1; } #endif if (!got_linux_cpu) { uname(&name); sprintf(linux_cpu, "%s", name.machine); got_linux_cpu = 1; } } return linux_cpu; }
char *platform_get_netbsd_runtime_cpu(void) { FILE *cpuinfo = NULL; char *buffer = NULL; char *loc1 = NULL; char *loc2 = NULL; char *loc3 = NULL; char *tempfile = NULL; char tempsystem[512]; size_t size1 = 0; size_t size2 = 0; struct utsname name; char *cpu = NULL; char *machine = NULL; char *model = NULL; size_t len = 0; if (!got_netbsd_cpu) { sprintf(netbsd_cpu, "Unknown CPU"); #if !defined(__i386__) && !defined(__amd64__) if (sysctlbyname("hw.machine_arch", NULL, &len, NULL, 0) == 0) { cpu = lib_malloc(len); sysctlbyname("hw.machine_arch", cpu, &len, NULL, 0); sysctlbyname("hw.model", NULL, &len, NULL, 0); model = lib_malloc(len); sysctlbyname("hw.model", model, &len, NULL, 0); sysctlbyname("hw.machine", NULL, &len, NULL, 0); machine = lib_malloc(len); sysctlbyname("hw.machine", machine, &len, NULL, 0); sprintf(netbsd_cpu, "%s", cpu); /* Get specific CPU/MMU/FPU for m68k */ if (!strcasecmp(cpu, "m68k")) { loc1 = strstr(model, "("); if (loc1) { loc1++; loc2 = strstr(loc1, ")"); if (loc2) { loc2[0] = 0; sprintf(netbsd_cpu, "%s", loc1); } } } /* Get specific CPU for hpcmips */ if (!strcasecmp(cpu, "mipsel")) { sprintf(netbsd_cpu, "%s", cpu); if (!strcasecmp(machine, "hpcmips")) { loc1 = strstr(model, "("); if (loc1) { loc1++; loc2 = strstr(loc1, ")"); if (loc2) { loc2[0] = 0; sprintf(netbsd_cpu, "%s (%s)", cpu, loc1); } } } } /* Get specific CPU for sparc or sparc64 */ if (!strcasecmp(cpu, "sparc") || !strcasecmp(cpu, "sparc64")) { loc1 = strstr(model, "("); if (loc1) { loc1++; loc2 = strstr(loc1, ")"); if (loc2) { loc2[0] = 0; sprintf(netbsd_cpu, "%s (%s)", cpu, loc1); } } } if (cpu) { lib_free(cpu); } if (machine) { lib_free(machine); } if (model) { lib_free(model); } got_netbsd_cpu = 1; } else #endif { cpuinfo = fopen("/proc/cpuinfo", "rb"); if (cpuinfo) { fclose(cpuinfo); cpuinfo = NULL; tempfile = archdep_tmpnam(); sprintf(tempsystem, "cat /proc/cpuinfo >%s", tempfile); if (system(tempsystem) < 0) { log_warning(LOG_ERR, "`%s' failed.", tempsystem); } cpuinfo = fopen(tempfile, "rb"); } if (cpuinfo) { fseek(cpuinfo, 0L, SEEK_END); size1 = ftell(cpuinfo); fseek(cpuinfo, 0L, SEEK_SET); buffer = (char *)malloc(size1); size2 = fread(buffer, 1, size1, cpuinfo); if (size1 == size2) { loc1 = strstr(buffer, "model name"); if (loc1) { loc2 = strstr(loc1, ":"); if (loc2) { loc2 += 2; while (isspace(*loc2)) { loc2++; } loc3 = strstr(loc2, "\n"); if (loc3) { *loc3 = 0; sprintf(netbsd_cpu, "%s", loc2); got_netbsd_cpu = 1; } } } } fclose(cpuinfo); unlink(tempfile); lib_free(tempfile); if (buffer) { free(buffer); } } } #ifndef PLATFORM_NO_X86_ASM if (!got_netbsd_cpu) { sprintf(netbsd_cpu, "%s", platform_get_x86_runtime_cpu()); got_netbsd_cpu = 1; } #endif if (!got_netbsd_cpu) { uname(&name); sprintf(netbsd_cpu, "%s", name.machine); got_netbsd_cpu = 1; } } return netbsd_cpu; }