* termios.cc (setspeed): New function.

(cfsetospeed): Use setspeed to set speed.
(cfsetispeed): Use setspeed to set speed.
* autoload.cc: Add load statement for UuidCreate, and UuidCreateSequential.
* cpuid.h: New file.
* cygwin.din: Export gethostid.
* fhandler_proc.cc (cpuid): Move to cpuid.h.
(can_set_flag): Move to cpuid.h.
* syscalls.cc (gethostid): New function.
* version.h: Bump DLL minor version number to 83.
This commit is contained in:
Christopher Faylor 2003-04-16 03:03:45 +00:00
parent 9eed5df639
commit c448f78fd5
8 changed files with 212 additions and 38 deletions

View file

@ -1,8 +1,25 @@
2003-04-15 Christopher Faylor <cgf@redhat.com>
* termios.cc (setspeed): New function.
(cfsetospeed): Use setspeed to set speed.
(cfsetispeed): Use setspeed to set speed.
2003-04-15 Chris January <chris@atomice.net>
* autoload.cc: Add load statement for UuidCreate, and
UuidCreateSequential.
* cpuid.h: New file.
* cygwin.din: Export gethostid.
* fhandler_proc.cc (cpuid): Move to cpuid.h.
(can_set_flag): Move to cpuid.h.
* syscalls.cc (gethostid): New function.
* version.h: Bump DLL minor version number to 83.
2003-04-15 Thomas Pfaff <tpfaff@gmx.net>
* thread.h (pthread_rwlock::release): New method.
* thread.cc (pthread_rwlock::unlock): Use release to signal
waiting threads.
* thread.cc (pthread_rwlock::unlock): Use release to signal waiting
threads.
(pthread_rwlock::rdlock_cleanup): Signal waiting threads after a
cancelation.
(pthread_rwlock::wrlock_cleanup): Ditto.

View file

@ -523,4 +523,7 @@ LoadDLLfuncEx (timeGetDevCaps, 8, winmm, 1)
LoadDLLfuncEx (timeGetTime, 0, winmm, 1)
LoadDLLfuncEx (timeBeginPeriod, 4, winmm, 1)
LoadDLLfuncEx (timeEndPeriod, 4, winmm, 1)
LoadDLLfuncEx (UuidCreate, 4, rpcrt4, 1)
LoadDLLfuncEx (UuidCreateSequential, 4, rpcrt4, 1)
}

35
winsup/cygwin/cpuid.h Normal file
View file

@ -0,0 +1,35 @@
#ifndef CPUID_H
#define CPUID_H
extern inline void
cpuid (unsigned *a, unsigned *b, unsigned *c, unsigned *d, unsigned in)
{
asm ("cpuid"
: "=a" (*a),
"=b" (*b),
"=c" (*c),
"=d" (*d)
: "a" (in));
}
extern inline bool
can_set_flag (unsigned flag)
{
unsigned r1, r2;
asm("pushfl\n"
"popl %0\n"
"movl %0, %1\n"
"xorl %2, %0\n"
"pushl %0\n"
"popfl\n"
"pushfl\n"
"popl %0\n"
"pushl %1\n"
"popfl\n"
: "=&r" (r1), "=&r" (r2)
: "ir" (flag)
);
return ((r1 ^ r2) & flag) != 0;
}
#endif // !CPUID_H

View file

@ -565,6 +565,7 @@ getgrnam32
getgroups
_getgroups = getgroups
getgroups32
gethostid
getitimer
getlogin
_getlogin = getlogin

View file

@ -28,6 +28,7 @@ details. */
#include <sys/param.h>
#include "ntdll.h"
#include <winioctl.h>
#include "cpuid.h"
#define _COMPILING_NEWLIB
#include <dirent.h>
@ -550,37 +551,6 @@ format_proc_stat (char *destbuf, size_t maxsize)
bufptr += sizeof (x) - 1; \
} while (0)
static inline void
cpuid (unsigned *a, unsigned *b, unsigned *c, unsigned *d, unsigned in)
{
asm ("cpuid"
: "=a" (*a),
"=b" (*b),
"=c" (*c),
"=d" (*d)
: "a" (in));
}
static inline bool
can_set_flag (unsigned flag)
{
unsigned r1, r2;
asm("pushfl\n"
"popl %0\n"
"movl %0, %1\n"
"xorl %2, %0\n"
"pushl %0\n"
"popfl\n"
"pushfl\n"
"popl %0\n"
"pushl %1\n"
"popfl\n"
: "=&r" (r1), "=&r" (r2)
: "ir" (flag)
);
return ((r1 ^ r2) & flag) != 0;
}
static _off64_t
format_proc_cpuinfo (char *destbuf, size_t maxsize)
{

View file

@ -199,12 +199,13 @@ details. */
80: Export pthread_rwlock stuff
81: CW_CHECK_NTSEC addition to external.cc
82: Export wcscoll wcswidth wcwidth
83: Export gethostid
*/
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
#define CYGWIN_VERSION_API_MAJOR 0
#define CYGWIN_VERSION_API_MINOR 82
#define CYGWIN_VERSION_API_MINOR 83
/* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible

View file

@ -36,6 +36,7 @@ details. */
#include <winnls.h>
#include <wininet.h>
#include <lmcons.h> /* for UNLEN */
#include <rpc.h>
#undef fstat
#undef stat
@ -55,6 +56,8 @@ details. */
#define NEED_VFORK
#include "perthread.h"
#include "pwdgrp.h"
#include "cpuid.h"
#include "registry.h"
#undef _close
#undef _lseek
@ -2725,3 +2728,109 @@ pututline (struct utmp *ut)
CloseHandle (mutex);
}
}
extern "C"
long gethostid(void)
{
unsigned data[13] = {0x92895012,
0x10293412,
0x29602018,
0x81928167,
0x34601329,
0x75630198,
0x89860395,
0x62897564,
0x00194362,
0x20548593,
0x96839102,
0x12219854,
0x00290012};
bool has_cpuid = false;
if (!can_set_flag (0x00040000))
debug_printf ("386 processor - no cpuid");
else
{
debug_printf ("486 processor");
if (can_set_flag (0x00200000))
{
debug_printf ("processor supports CPUID instruction");
has_cpuid = true;
}
else
debug_printf ("processor does not support CPUID instruction");
}
if (has_cpuid)
{
unsigned maxf, unused[3];
cpuid (&maxf, &unused[0], &unused[1], &unused[2], 0);
maxf &= 0xffff;
if (maxf >= 1)
{
unsigned features;
cpuid (&data[0], &unused[0], &unused[1], &features, 1);
if (features & (1 << 18))
{
debug_printf ("processor has psn");
if (maxf >= 3)
{
cpuid (&unused[0], &unused[1], &data[1], &data[2], 3);
debug_printf ("Processor PSN: %04x-%04x-%04x-%04x-%04x-%04x",
data[0] >> 16, data[0] & 0xffff, data[2] >> 16, data[2] & 0xffff, data[1] >> 16, data[1] & 0xffff);
}
}
else
debug_printf ("processor does not have psn");
}
}
UUID Uuid;
RPC_STATUS status = UuidCreateSequential (&Uuid);
if (GetLastError () == ERROR_PROC_NOT_FOUND)
status = UuidCreate (&Uuid);
if (status == RPC_S_OK)
{
data[4] = *(unsigned *)&Uuid.Data4[2];
data[5] = *(unsigned short *)&Uuid.Data4[6];
// Unfortunately Windows will sometimes pick a virtual Ethernet card
// e.g. VMWare Virtual Ethernet Adaptor
debug_printf ("MAC address of first Ethernet card: %02x:%02x:%02x:%02x:%02x:%02x",
Uuid.Data4[2], Uuid.Data4[3], Uuid.Data4[4],
Uuid.Data4[5], Uuid.Data4[6], Uuid.Data4[7]);
}
else
{
debug_printf ("no Ethernet card installed");
}
reg_key key (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE", "Microsoft", "Windows", "CurrentVersion", NULL);
key.get_string ("ProductId", (char *)&data[6], 24, "00000-000-0000000-00000");
debug_printf ("Windows Product ID: %s", (char *)&data[6]);
GetDiskFreeSpaceEx ("C:\\", NULL, (PULARGE_INTEGER) &data[11], NULL);
if (GetLastError () == ERROR_PROC_NOT_FOUND)
GetDiskFreeSpace ("C:\\", NULL, NULL, NULL, (DWORD *)&data[11]);
debug_printf ("hostid entropy: %08x %08x %08x %08x "
"%08x %08x %08x %08x "
"%08x %08x %08x %08x "
"%08x",
data[0], data[1],
data[2], data[3],
data[4], data[5],
data[6], data[7],
data[8], data[9],
data[10], data[11],
data[12]);
long hostid = 0x40291372;
// a random hashing algorithm
// dependancy on md5 is probably too costly
for (int i=0;i<13;i++)
hostid ^= ((data[i] << (i << 2)) | (data[i] >> (32 - (i << 2))));
debug_printf ("hostid: %08x", hostid);
return hostid;
}

View file

@ -247,14 +247,52 @@ cfgetispeed (struct termios *tp)
return __tonew_termios (tp)->c_ispeed;
}
static inline int
setspeed (speed_t &set_speed, speed_t from_speed)
{
int res;
switch (from_speed)
{
case B0:
case B50:
case B75:
case B110:
case B134:
case B150:
case B200:
case B300:
case B600:
case B1200:
case B1800:
case B2400:
case B4800:
case B9600:
case B19200:
case B38400:
case B57600:
case B115200:
case B128000:
case B230400:
case B256000:
set_speed = from_speed;
res = 0;
break;
default:
set_errno (EINVAL);
res = -1;
break;
}
return res;
}
/* cfsetospeed: POSIX96 7.1.3.1 */
extern "C" int
cfsetospeed (struct termios *in_tp, speed_t speed)
{
struct termios *tp = __tonew_termios (in_tp);
tp->c_ospeed = speed;
int res = setspeed (tp->c_ospeed, speed);
(void) __toapp_termios (in_tp, tp);
return 0;
return res;
}
/* cfsetispeed: POSIX96 7.1.3.1 */
@ -262,7 +300,7 @@ extern "C" int
cfsetispeed (struct termios *in_tp, speed_t speed)
{
struct termios *tp = __tonew_termios (in_tp);
tp->c_ispeed = speed;
int res = setspeed (tp->c_ispeed, speed);
(void) __toapp_termios (in_tp, tp);
return 0;
return res;
}