1 /** @file 2 Global data for the program environment. 3 4 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR> 5 This program and the accompanying materials are licensed and made available 6 under the terms and conditions of the BSD License which accompanies this 7 distribution. The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php. 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 **/ 13 #include <Uefi.h> 14 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include <sys/types.h> 18 #include <limits.h> 19 #include <signal.h> 20 #include <time.h> 21 #include <setjmp.h> 22 23 #include <kfile.h> 24 #include <Device/Device.h> 25 26 #include "Device/Console.h" 27 28 /* ################## Type Declarations ################################# */ 29 30 /** The type of an atexit handler function. **/ 31 typedef void __xithandler_t(void); 32 33 /* ################## Global Declarations ############################### */ 34 #ifndef TYPE_BIT 35 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) 36 #endif /* !defined TYPE_BIT */ 37 38 #ifndef TYPE_SIGNED 39 #define TYPE_SIGNED(type) (((type) -1) < 0) 40 #endif /* !defined TYPE_SIGNED */ 41 42 #ifndef INT_STRLEN_MAXIMUM 43 /* 44 ** 302 / 1000 is log10(2.0) rounded up. 45 ** Subtract one for the sign bit if the type is signed; 46 ** add one for integer division truncation; 47 ** add one more for a minus sign if the type is signed. 48 */ 49 #define INT_STRLEN_MAXIMUM(type) \ 50 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type)) 51 #endif /* !defined INT_STRLEN_MAXIMUM */ 52 53 /* 54 ** Big enough for something such as 55 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n 56 ** (two three-character abbreviations, five strings denoting integers, 57 ** three explicit spaces, two explicit colons, a newline, 58 ** and a trailing ASCII nul). 59 */ 60 #define ASCTIME_BUFLEN ((2 * 3) + (5 * INT_STRLEN_MAXIMUM(int)) + 3 + 2 + 1 + 1) 61 62 struct __filedes; /* Forward Reference */ 63 struct stat; /* Forward Reference so I don't have to include <stat.h> */ 64 65 struct __MainData { 66 // File descriptors 67 struct __filedes fdarray[OPEN_MAX]; 68 // Low-level File abstractions for the stdin, stdout, stderr streams 69 ConInstance *StdIo[3]; 70 71 // Signal Handlers 72 __sighandler_t *sigarray[SIG_LAST]; // Pointers to signal handlers 73 74 char *NArgV[ARGC_MAX]; // Narrow character argv array 75 char *NCmdLine; // Narrow character version of command line arguments. 76 77 void (*cleanup)(void); // Stdio Cleanup Function Pointer 78 79 __xithandler_t *atexit_handler[ATEXIT_MAX]; // Array of handlers for atexit. 80 clock_t AppStartTime; // Set in Main.c and used for time.h 81 clock_t ClocksPerSecond; // Set in Main.c and used for time.h 82 int num_atexit; ///< Number of registered atexit handlers. 83 84 CHAR16 UString[UNICODE_STRING_MAX]; 85 CHAR16 UString2[UNICODE_STRING_MAX]; 86 struct tm BDTime; // Broken-down time structure for localtime. 87 EFI_TIME TimeBuffer; // Used by <time.h>mk 88 char ASgetenv[ASCII_STRING_MAX]; // Only modified by getenv 89 char ASasctime[ASCTIME_BUFLEN]; // Only modified by asctime 90 91 jmp_buf MainExit; ///< Save environment used for implementing _Exit() 92 int ExitValue; ///< Value being returned by _Exit() 93 94 BOOLEAN aborting; // Ensures cleanup function only called once when aborting. 95 }; 96 97 extern struct __MainData *gMD; 98