123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- /*++
- Copyright (c) 2013 Minoca Corp. All Rights Reserved
- Module Name:
- osbasep.h
- Abstract:
- This header contains internal definitions for the Operating System Base
- library.
- Author:
- Evan Green 25-Feb-2013
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #define OS_API __DLLPROTECTED
- #define RTL_API __DLLPROTECTED
- #include <minoca/lib/minocaos.h>
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // TODO: Implement syscall system call mechanism on x64, in addition to keeping
- // the old int mechanism for full save/restore.
- //
- #if defined(__amd64)
- #define OsSystemCall OspSystemCallFull
- #endif
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- typedef
- INTN
- (*POS_SYSTEM_CALL) (
- ULONG SystemCallNumber,
- PVOID SystemCallParameter
- );
- /*++
- Routine Description:
- This routine executes a system call.
- Arguments:
- SystemCallNumber - Supplies the system call number.
- SystemCallParameter - Supplies the system call parameter.
- Return Value:
- STATUS_SUCCESS or positive integer on success.
- Error status code on failure.
- --*/
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // Store a pointer to the environment.
- //
- extern PPROCESS_ENVIRONMENT OsEnvironment;
- //
- // On x86, the system call is a function pointer depending on which processor
- // features are supported.
- //
- #if defined(__i386)
- extern POS_SYSTEM_CALL OsSystemCall;
- #endif
- //
- // Store a pointer to the list head of all loaded images.
- //
- extern LIST_ENTRY OsLoadedImagesHead;
- //
- // Store the module generation number, which increments whenever a module is
- // loaded or unloaded. It is protected under the image list lock.
- //
- extern UINTN OsImModuleGeneration;
- //
- // Store the page shift and mask for easy use during image section mappings.
- //
- extern UINTN OsPageShift;
- extern UINTN OsPageSize;
- //
- // -------------------------------------------------------- Function Prototypes
- //
- INTN
- OspSystemCallFull (
- ULONG SystemCallNumber,
- PVOID SystemCallParameter
- );
- /*++
- Routine Description:
- This routine executes a system call using the traditional method that looks
- a lot like an interrupt. On some architectures, this method is highly
- compatible, but slow. On other architectures, this is the only system call
- mechanism.
- Arguments:
- SystemCallNumber - Supplies the system call number.
- SystemCallParameter - Supplies the system call parameter.
- Return Value:
- STATUS_SUCCESS or positive integer on success.
- Error status code on failure.
- --*/
- #if defined (__arm__)
- INTN
- OsSystemCall (
- ULONG SystemCallNumber,
- PVOID SystemCallParameter
- );
- /*++
- Routine Description:
- This routine executes a system call.
- Arguments:
- SystemCallNumber - Supplies the system call number.
- SystemCallParameter - Supplies the system call parameter.
- Return Value:
- STATUS_SUCCESS or positive integer on success.
- Error status code on failure.
- --*/
- #endif
- VOID
- OspSetUpSystemCalls (
- VOID
- );
- /*++
- Routine Description:
- This routine sets up the system call handler.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- VOID
- OspSignalHandler (
- PSIGNAL_PARAMETERS Parameters,
- PSIGNAL_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine is called directly by the kernel when a signal occurs. It
- marshals the parameters and calls the C routine for handling the signal.
- The parameters are stored on the stack with the signal parameters followed
- by the signal context.
- Arguments:
- Parameters - Supplies a pointer to the signal parameters.
- Context - Supplies a pointer to the signal context from the kernel.
- Return Value:
- None.
- --*/
- VOID
- OspInitializeMemory (
- VOID
- );
- /*++
- Routine Description:
- This routine initializes the memory heap portion of the OS base library.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- VOID
- OspInitializeImageSupport (
- VOID
- );
- /*++
- Routine Description:
- This routine initializes the image library for use in the image creation
- tool.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- VOID
- OspAcquireImageLock (
- BOOL Exclusive
- );
- /*++
- Routine Description:
- This routine acquires the global image lock.
- Arguments:
- Exclusive - Supplies a boolean indicating whether the lock should be
- held shared (FALSE) or exclusive (TRUE).
- Return Value:
- None.
- --*/
- VOID
- OspReleaseImageLock (
- VOID
- );
- /*++
- Routine Description:
- This routine releases the global image lock.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- PUSER_SHARED_DATA
- OspGetUserSharedData (
- VOID
- );
- /*++
- Routine Description:
- This routine returns a pointer to the user shared data.
- Arguments:
- None.
- Return Value:
- Returns a pointer to the user shared data area.
- --*/
- //
- // Thread-Local storage functions
- //
- VOID
- OspInitializeThreadSupport (
- VOID
- );
- /*++
- Routine Description:
- This routine initializes thread and TLS support in the OS library.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- KSTATUS
- OspTlsAllocate (
- PLIST_ENTRY ImageList,
- PVOID *ThreadData
- );
- /*++
- Routine Description:
- This routine creates the OS library data necessary to manage a new thread.
- This function is usually called by the C library.
- Arguments:
- ImageList - Supplies a pointer to the head of the list of loaded images.
- Elements on this list have type LOADED_IMAGE.
- ThreadData - Supplies a pointer where a pointer to the thread data will be
- returned on success. It is the callers responsibility to destroy this
- thread data.
- Return Value:
- Status code.
- --*/
- VOID
- OspTlsDestroy (
- PVOID ThreadData
- );
- /*++
- Routine Description:
- This routine destroys a previously created thread data structure. Callers
- may not use OS library assisted TLS after this routine completes. Signals
- should also probably be masked.
- Arguments:
- ThreadData - Supplies a pointer to the thread data to destroy.
- Return Value:
- None.
- --*/
- VOID
- OspTlsTearDownModule (
- PLOADED_IMAGE Image
- );
- /*++
- Routine Description:
- This routine is called when a module is unloaded. It goes through and
- frees all the TLS images for the module.
- Arguments:
- Image - Supplies a pointer to the image being unloaded.
- Return Value:
- None.
- --*/
|