]> git.proxmox.com Git - mirror_edk2.git/blob - StdLibPrivateInternalFiles/Include/MainData.h
Add device abstraction code for the UEFI Console and UEFI Shell-based file systems.
[mirror_edk2.git] / StdLibPrivateInternalFiles / Include / MainData.h
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
22 #include <kfile.h>
23 #include <Device/Device.h>
24
25 #include "Device/Console.h"
26
27 /* ################## Type Declarations ################################# */
28
29 /** The type of an atexit handler function. **/
30 typedef void __xithandler_t(void);
31
32 /* ################## Global Declarations ############################### */
33 #ifndef TYPE_BIT
34 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
35 #endif /* !defined TYPE_BIT */
36
37 #ifndef TYPE_SIGNED
38 #define TYPE_SIGNED(type) (((type) -1) < 0)
39 #endif /* !defined TYPE_SIGNED */
40
41 #ifndef INT_STRLEN_MAXIMUM
42 /*
43 ** 302 / 1000 is log10(2.0) rounded up.
44 ** Subtract one for the sign bit if the type is signed;
45 ** add one for integer division truncation;
46 ** add one more for a minus sign if the type is signed.
47 */
48 #define INT_STRLEN_MAXIMUM(type) \
49 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))
50 #endif /* !defined INT_STRLEN_MAXIMUM */
51
52 /*
53 ** Big enough for something such as
54 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
55 ** (two three-character abbreviations, five strings denoting integers,
56 ** three explicit spaces, two explicit colons, a newline,
57 ** and a trailing ASCII nul).
58 */
59 #define ASCTIME_BUFLEN ((2 * 3) + (5 * INT_STRLEN_MAXIMUM(int)) + 3 + 2 + 1 + 1)
60
61 struct __filedes; /* Forward Reference */
62 struct stat; /* Forward Reference so I don't have to include <stat.h> */
63
64 struct __MainData {
65 // File descriptors
66 struct __filedes fdarray[OPEN_MAX];
67 // Low-level File abstractions for the stdin, stdout, stderr streams
68 ConInstance *StdIo[3];
69
70 // Signal Handlers
71 __sighandler_t *sigarray[SIG_LAST]; // Pointers to signal handlers
72
73 char *NArgV[ARGC_MAX]; // Narrow character argv array
74 char *NCmdLine; // Narrow character version of command line arguments.
75
76 void (*cleanup)(void); // Stdio Cleanup Function Pointer
77 void (*FinalCleanup)(void); // Function to free this structure and cleanup before exit.
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 BOOLEAN aborting; // Ensures cleanup function only called once when aborting.
92 };
93
94 extern struct __MainData *gMD;