aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-04-16 03:03:45 +0000
committerChristopher Faylor <me@cgf.cx>2003-04-16 03:03:45 +0000
commitc448f78fd56ef8d34474adc2678d6394a4d088ec (patch)
tree8b0177d10bddf05d3648e296b07ab13e218115e8
parent9eed5df6392240b46c2506dcb37227ee73f5a806 (diff)
downloadnewlib-c448f78fd56ef8d34474adc2678d6394a4d088ec.zip
newlib-c448f78fd56ef8d34474adc2678d6394a4d088ec.tar.gz
newlib-c448f78fd56ef8d34474adc2678d6394a4d088ec.tar.bz2
* 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.
-rw-r--r--winsup/cygwin/ChangeLog21
-rw-r--r--winsup/cygwin/autoload.cc3
-rw-r--r--winsup/cygwin/cpuid.h35
-rw-r--r--winsup/cygwin/cygwin.din1
-rw-r--r--winsup/cygwin/fhandler_proc.cc32
-rw-r--r--winsup/cygwin/include/cygwin/version.h3
-rw-r--r--winsup/cygwin/syscalls.cc109
-rw-r--r--winsup/cygwin/termios.cc46
8 files changed, 212 insertions, 38 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 454b756..49498f3 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -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.
diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index 59d8469..1ea024d 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -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)
}
diff --git a/winsup/cygwin/cpuid.h b/winsup/cygwin/cpuid.h
new file mode 100644
index 0000000..1f0cc50
--- /dev/null
+++ b/winsup/cygwin/cpuid.h
@@ -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
diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din
index 61aad94..efac0e0 100644
--- a/winsup/cygwin/cygwin.din
+++ b/winsup/cygwin/cygwin.din
@@ -565,6 +565,7 @@ getgrnam32
getgroups
_getgroups = getgroups
getgroups32
+gethostid
getitimer
getlogin
_getlogin = getlogin
diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc
index b9f6b38..28fe879 100644
--- a/winsup/cygwin/fhandler_proc.cc
+++ b/winsup/cygwin/fhandler_proc.cc
@@ -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)
{
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index 9c4f1a4..e789ef6 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -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
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 6fa779f..4a7e20f 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -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;
+}
diff --git a/winsup/cygwin/termios.cc b/winsup/cygwin/termios.cc
index ac1c89b..c7dd20d 100644
--- a/winsup/cygwin/termios.cc
+++ b/winsup/cygwin/termios.cc
@@ -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;
}