]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UnixPkg/Sec/UnixThunk.c
Add special treatment for EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE and EFI_PCI_IO_ATTRIBU...
[mirror_edk2.git] / UnixPkg / Sec / UnixThunk.c
index 5dfba7a73436e7adab2ee3c3a92f2d848a35eeea..f65acab10062c09b096c32af622eeeb83a2fb2f6 100644 (file)
@@ -1,8 +1,8 @@
 /*++
 
-Copyright (c) 2004 - 2009, Intel Corporation                                                         
-Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.
-All rights reserved. This program and the accompanying materials                          
+Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
+This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD License         
 which accompanies this distribution.  The full text of the license may be found at        
 http://opensource.org/licenses/bsd-license.php                                            
@@ -36,10 +36,17 @@ Abstract:
 #include "Uefi.h"
 #include "Library/UnixLib.h"
 
+#if defined(__APPLE__) || defined(MDE_CPU_X64)
+#include "Gasket.h"
+#endif
+
 int settimer_initialized;
 struct timeval settimer_timeval;
 void (*settimer_callback)(UINT64 delta);
 
+BOOLEAN gEmulatorInterruptEnabled = FALSE;
+
+
 void
 settimer_handler (int sig)
 {
@@ -51,8 +58,14 @@ settimer_handler (int sig)
     - ((UINT64)settimer_timeval.tv_sec * 1000) 
     - (settimer_timeval.tv_usec / 1000);
   settimer_timeval = timeval;
-  if (settimer_callback)
+  
+  if (settimer_callback) {
+#if defined(__APPLE__) || defined(MDE_CPU_X64)
+   ReverseGasketUint64 (settimer_callback, delta);
+#else
     (*settimer_callback)(delta);
+#endif
+  }
 }
 
 VOID
@@ -68,6 +81,7 @@ SetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs))
     act.sa_handler = settimer_handler;
     act.sa_flags = 0;
     sigemptyset (&act.sa_mask);
+    gEmulatorInterruptEnabled = TRUE;
     if (sigaction (SIGALRM, &act, NULL) != 0) {
       printf ("SetTimer: sigaction error %s\n", strerror (errno));
     }
@@ -87,16 +101,58 @@ SetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs))
   settimer_callback = CallBack;
 }
 
+
+void
+UnixEnableInterrupt (void)
+{
+  sigset_t  sigset;
+
+  gEmulatorInterruptEnabled = TRUE;
+  // Since SetTimer() uses SIGALRM we emulate turning on and off interrupts 
+  // by enabling/disabling SIGALRM.
+  sigemptyset (&sigset);
+  sigaddset (&sigset, SIGALRM);
+  sigprocmask (SIG_UNBLOCK, &sigset, NULL);
+}
+
+
+void
+UnixDisableInterrupt (void)
+{
+  sigset_t  sigset;
+
+  // Since SetTimer() uses SIGALRM we emulate turning on and off interrupts 
+  // by enabling/disabling SIGALRM.
+  sigemptyset (&sigset);
+  sigaddset (&sigset, SIGALRM);
+  sigprocmask (SIG_BLOCK, &sigset, NULL);
+  gEmulatorInterruptEnabled = FALSE;
+}
+
+
+BOOLEAN
+UnixInterruptEanbled (void)
+{
+  return gEmulatorInterruptEnabled;
+}
+
+
+
 void
 msSleep (unsigned long Milliseconds)
 {
-  struct timespec ts;
+  struct timespec rq, rm;
+
+  rq.tv_sec = Milliseconds / 1000;
+  rq.tv_nsec = (Milliseconds % 1000) * 1000000;
 
-  ts.tv_sec = Milliseconds / 1000;
-  ts.tv_nsec = (Milliseconds % 1000) * 1000000;
+  while (nanosleep (&rq, &rm) != -1) {
+    if (errno != EINTR) {
+      break;
+    }
+    rq = rm;
+  } 
 
-  while (nanosleep (&ts, &ts) != 0 && errno == EINTR)
-    ;
 }
 
 void
@@ -115,7 +171,7 @@ GetLocalTime (EFI_TIME *Time)
   Time->Minute = tm->tm_min;
   Time->Second = tm->tm_sec;
   Time->Nanosecond = 0;
-  Time->TimeZone = timezone;
+  Time->TimeZone = GetTimeZone ();
   Time->Daylight = (daylight ? EFI_TIME_ADJUST_DAYLIGHT : 0)
     | (tm->tm_isdst > 0 ? EFI_TIME_IN_DAYLIGHT : 0);
 }
@@ -150,81 +206,13 @@ GetErrno(void)
   return errno;
 }
 
-#if __APPLE__
-void GasketmsSleep (unsigned long Milliseconds);
-void Gasketexit (int status);
-void GasketSetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs));
-void GasketGetLocalTime (EFI_TIME *Time);
-struct tm *Gasketgmtime (const time_t *clock);
-long GasketGetTimeZone (void);
-int GasketGetDayLight (void);
-int Gasketpoll (struct pollfd *pfd, int nfds, int timeout);
-int Gasketread (int fd, void *buf, int count);
-int Gasketwrite (int fd, const void *buf, int count);
-char *Gasketgetenv (const char *name);
-int Gasketopen (const char *name, int flags, int mode);
-off_t Gasketlseek (int fd, off_t off, int whence);
-int Gasketftruncate (int fd, long int len);
-int Gasketclose (int fd);
-int Gasketmkdir (const char *pathname, mode_t mode);
-int Gasketrmdir (const char *pathname);
-int Gasketunlink (const char *pathname);
-int GasketGetErrno (void);
-DIR *Gasketopendir (const char *pathname);
-void *Gasketrewinddir (DIR *dir);
-struct dirent *Gasketreaddir (DIR *dir);
-int Gasketclosedir (DIR *dir);
-int Gasketstat (const char *path, struct stat *buf);
-int Gasketstatfs (const char *path, struct statfs *buf);
-int Gasketrename (const char *oldpath, const char *newpath);
-time_t Gasketmktime (struct tm *tm);
-int Gasketfsync (int fd);
-int Gasketchmod (const char *path, mode_t mode);
-int Gasketutime (const char *filename, const struct utimbuf *buf);
-int Gaskettcflush (int fildes, int queue_selector);
-EFI_STATUS GasketUgaCreate(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title);
-void Gasketperror (__const char *__s);
-
-//
-// ... is always an int or pointer to device specific data structure
-//
-int Gasketioctl (int fd, unsigned long int __request, ...);
-int Gasketfcntl (int __fd, int __cmd, ...);
-
-int Gasketcfsetispeed (struct termios *__termios_p, speed_t __speed);
-int Gasketcfsetospeed (struct termios *__termios_p, speed_t __speed);
-int Gaskettcgetattr (int __fd, struct termios *__termios_p); 
-int Gaskettcsetattr (int __fd, int __optional_actions, __const struct termios *__termios_p);
-int Gasketsigaction (int sig, const struct sigaction *act, struct sigaction *oact);
-int Gasketsetcontext (const ucontext_t *ucp);
-int Gasketgetcontext (ucontext_t *ucp);
-int Gasketsigemptyset (sigset_t *set);
-int Gasketsigaltstack (const stack_t *ss, stack_t *oss);
-
-RETURN_STATUS
-GasketUnixPeCoffGetEntryPoint (
-  IN     VOID  *Pe32Data,
-  IN OUT VOID  **EntryPoint
-  );
-
-VOID
-GasketUnixPeCoffRelocateImageExtraAction (
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext
-  );
-
-VOID
-GasketPeCoffLoaderUnloadImageExtraAction (
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext
-  );
-
-#endif
 
 extern EFI_STATUS
 UgaCreate(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title);
 
 EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = {
   EFI_UNIX_THUNK_PROTOCOL_SIGNATURE,
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(MDE_CPU_X64)
 //
 // Mac OS X requires the stack to be 16-byte aligned for IA-32. So on an OS X build
 // we add an assembly wrapper that makes sure the stack ges aligned. 
@@ -238,20 +226,20 @@ EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = {
   Gasketgmtime,
   GasketGetTimeZone,
   GasketGetDayLight,
-  (UnixPoll)Gasketpoll,
-  (UnixRead)Gasketread,
-  (UnixWrite)Gasketwrite,
+  Gasketpoll,
+  Gasketread,
+  Gasketwrite,
   Gasketgetenv,
-  (UnixOpen)Gasketopen,
-  (UnixSeek)Gasketlseek,
-  (UnixFtruncate)Gasketftruncate,
+  Gasketopen,
+  Gasketlseek,
+  Gasketftruncate,
   Gasketclose,
   Gasketmkdir,
   Gasketrmdir,
   Gasketunlink,
   GasketGetErrno,
   Gasketopendir,
-  (UnixRewindDir)Gasketrewinddir,
+  Gasketrewinddir,
   Gasketreaddir,
   Gasketclosedir,
   Gasketstat,
@@ -270,14 +258,16 @@ EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = {
   Gasketcfsetospeed,
   Gaskettcgetattr,
   Gaskettcsetattr,
+  GasketUnixPeCoffGetEntryPoint,                
+  GasketUnixPeCoffRelocateImageExtraAction,     
+  GasketUnixPeCoffUnloadImageExtraAction,  
   
-  dlopen,  // Update me with a gasket
-  dlerror, // Update me with a gasket
-  dlsym,   // Update me with a gasket
+  GasketUnixEnableInterrupt,
+  GasketUnixDisableInterrupt,
 
-  SecPeCoffGetEntryPoint,                // Update me with a gasket
-  SecPeCoffRelocateImageExtraAction,     // Update me with a gasket
-  SecPeCoffLoaderUnloadImageExtraAction  // Update me with a gasket
+  Gasketgetifaddrs,
+  Gasketfreeifaddrs,
+  Gasketsocket,
 
 #else
   msSleep, /* Sleep */
@@ -303,7 +293,7 @@ EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = {
   rewinddir,
   readdir,
   closedir,
-  stat,
+  (UnixStat)stat,
   statfs,
   rename,
   mktime,
@@ -319,12 +309,14 @@ EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = {
   cfsetospeed,
   tcgetattr,
   tcsetattr,
-  dlopen,
-  dlerror,
-  dlsym,
   SecPeCoffGetEntryPoint,
   SecPeCoffRelocateImageExtraAction,
-  SecPeCoffLoaderUnloadImageExtraAction
+  SecPeCoffLoaderUnloadImageExtraAction,
+  UnixEnableInterrupt,
+  UnixDisableInterrupt,
+  getifaddrs,
+  freeifaddrs,
+  socket
 #endif
 };