Skip to content

Commit 5506e43

Browse files
committed
Merge pull request #5 from Dridi/master
Fix the i686 build with hardening
2 parents 90ca8ba + 5e699b1 commit 5506e43

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

common/util.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include <signal.h>
4646
#include <stdarg.h>
4747
#include <errno.h>
48-
#include <cpuid.h>
4948
#include "include/types.h"
5049
#include "include/util.h"
5150
#include "include/perf.h"
@@ -315,6 +314,34 @@ cyc2ns(uint64_t cyc)
315314
return (ns);
316315
}
317316

317+
/* ARGSUSED */
318+
static void
319+
cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx,
320+
unsigned int *edx)
321+
{
322+
#if __x86_64
323+
__asm volatile(
324+
"cpuid\n\t"
325+
:"=a" (*eax),
326+
"=b" (*ebx),
327+
"=c" (*ecx),
328+
"=d" (*edx)
329+
:"a" (*eax));
330+
#else
331+
__asm volatile(
332+
"push %%ebx\n\t"
333+
"cpuid\n\t"
334+
"mov %%ebx, (%4)\n\t"
335+
"pop %%ebx"
336+
:"=a" (*eax),
337+
"=c" (*ecx),
338+
"=d" (*edx)
339+
:"0" (*eax),
340+
"S" (ebx)
341+
:"memory");
342+
#endif
343+
}
344+
318345
/*
319346
* Get the CPU type.
320347
*/
@@ -326,7 +353,9 @@ cpu_type_get(void)
326353
cpu_type_t type = CPU_UNSUP;
327354
char vendor[16];
328355

329-
__cpuid(0, eax, ebx, ecx, edx);
356+
eax = 0;
357+
cpuid(&eax, &ebx, &ecx, &edx);
358+
330359
(void) strncpy(&vendor[0], (char *)(&ebx), 4);
331360
(void) strncpy(&vendor[4], (char *)(&ecx), 4);
332361
(void) strncpy(&vendor[8], (char *)(&edx), 4);
@@ -336,7 +365,9 @@ cpu_type_get(void)
336365
return (CPU_UNSUP);
337366
}
338367

339-
__cpuid(1, eax, ebx, ecx, edx);
368+
eax = 1;
369+
cpuid(&eax, &ebx, &ecx, &edx);
370+
340371
family = CPU_FAMILY(eax);
341372
model = CPU_MODEL(eax);
342373
ext_model = CPU_EXT_MODEL(eax);

0 commit comments

Comments
 (0)