Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "AmigaDOS Data Structures"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
Line 112: Line 112:
 
| pr_CES
 
| pr_CES
 
| Error stream - if NULL, use pr_COS
 
| Error stream - if NULL, use pr_COS
  +
|}
  +
  +
To identify the segments that a particular process uses, you must use
  +
pr_SegList. pr_SegList is an array of longwords with its size in
  +
Seg_List[0]. Other elements are either zero or a BPTR to a SegList.
  +
CreateProc() and CreateNewProc() create this array with the first two
  +
elements of the array pointing to resident code and the third element,
  +
being the SegList, passed an argument. When a process terminates,
  +
FreeMem() is used to return the space for the pr_SegList.
  +
  +
The pr_StackSize field indicates the size of the process stack, as
  +
supplied by the user when calling CreateProc() or CreateNewProc(). Note
  +
that the process stack is not the same as the command stack a CLI uses
  +
when it calls a program. The CLI obtains its command stack just before it
  +
runs a program and you may alter the size of this stack with the STACK
  +
command. When you create a process, AmigaDOS obtains the process stack and
  +
stores the size in pr_StackSize. The pointer to the space for the process
  +
control block and the stack is also stored in the MemEntry field of the
  +
task structure. When the process terminates this space is returned via a
  +
call to FreeVec(). You can also chain any memory you obtain into this list
  +
structure so that it, too, gets put back when the task terminates. But be
  +
careful, this method won't work for a program run from the CLI since
  +
memory is not freed until the process goes away.
  +
  +
If a call to CreateProc() or CreateNewProc() creates the process,
  +
GlobVec is a pointer to the Shared Global Vector. However, some internal
  +
handler processes use a private global vector.
  +
  +
The value of pr_TaskNum is normally zero; a CLI process stores the small
  +
integer that identifies the invocation of the CLI here.
  +
  +
The pointer pr_StackBase points to the high-memory end of the process
  +
stack. This is the end of the stack when using languages such as C or
  +
assembler; it is the base of the stack for languages such as BCPL. Note
  +
that pr_StackBase may not be the same as the one your application uses
  +
(eg. if your program is started from the CLI).
  +
  +
The pr_Result2 and pr_CurrentDir fields are handled by the AmigaDOS
  +
functions IoErr() and CurrentDir(), respectively. pr_CIS and pr_COS are
  +
the values Input() and Output() return and refer to the filehandles you
  +
should use when running a program under the CLI. Never access pr_CIS and
  +
pr_COS directly. Instead use the AmigaDOS functions provided for this
  +
purpose.
  +
  +
The pr_ConsoleTask field refers to the console handler for the current
  +
window. The pr_FileSystemTask field refers to the file handler for the
  +
boot device. You use these values when attempting to open the * device or
  +
file by a relative path name when pr_CurrentDir is null.
  +
  +
The pr_CLI pointer is nonzero only for CLI processes. In this case it
  +
refers to a further structure the CLI uses with the following format:
  +
  +
{| class="wikitable"
  +
! Type
  +
! Name
  +
! Description
  +
|-
  +
| LONG
  +
| cli_Result2
  +
| Value of IOErr from last command
  +
|-
  +
| BSTR
  +
| cli_SetName
  +
| Name of current directory
  +
|-
  +
| BPTR
  +
| cli_CommandDir
  +
| BPTR to CLI path
  +
|-
  +
| LONG
  +
| cli_ReturnCode
  +
| Return code from last command
  +
|-
  +
| BSTR
  +
| cli_CommandName
  +
| Name of current command
  +
|-
  +
| LONG
  +
| cli_FailLevel
  +
| Fail level (set by FAILAT)
  +
|-
  +
| BSTR
  +
| cli_Prompt
  +
| Current prompt (set by PROMPT)
  +
|-
  +
| BPTR
  +
| cli_StandardInput
  +
| Default (terminal) CLI input
  +
|-
  +
| BPTR
  +
| cli_CurrentInput
  +
| Current CLI input
  +
|-
  +
| BSTR
  +
| cli_CommandFile
  +
| Name of EXECUTE command file
  +
|-
  +
| LONG
  +
| cli_Interactive
  +
| Boolean; TRUE if prompts required
  +
|-
  +
| LONG
  +
| cli_Background
  +
| Boolean; TRUE if CLI created by RUN
  +
|-
  +
| BPTR
  +
| cli_CurrentOutput
  +
| Current CLI output
  +
|-
  +
| LONG
  +
| cli_DefaultStack
  +
| Stack size to be obtained in longwords
  +
|-
  +
| BPTR
  +
| cli_StandardOutput
  +
| Default (terminal) CLI output
  +
|-
  +
| BPTR
  +
| cli_Module
  +
| SegList of currently loaded command
 
|}
 
|}

Revision as of 17:34, 27 April 2012

Process Data Structures

These values are created as part of an AmigaDOS process; there is a complete set for each process.

A process is an Exec task with a number of extra data structures appended. The process structure consists of:

  • Exec task structure
  • Exec message port
  • AmigaDOS process value

The process identifier AmigaDOS uses internally is a pointer to the Exec message port (pr_MessagePort) from which the Exec task may be obtained.

AmigaDOS process values are as follows:

Type Name Description
BPTR pr_SegList Array of seg lists used by this process
LONG pr_StackSize Size of process stack in bytes
APTR pr_GlobVec Global vector for this process (BCPL)
LONG pr_TaskNum CLI task number of zero if not a CLI
BPTR pr_StackBase Ptr to high memory end of process stack
LONG pr_Result2 Value of secondary result from last call
BPTR pr_CurrentDir Lock associated with current directory
BPTR pr_CIS Current CLI Input Stream
BPTR pr_COS Current CLI Output Stream
APTR pr_ConsoleTask Console handler process for current window
APTR pr_FileSystemTask File handler process for current drive
BPTR pr_CLI Pointer to CLI
APTR pr_ReturnAdd Pointer to previous stack frame
APTR pr_PktWait Function to be called when awaiting msg
APTR pr_WindowPtr Window for error printing
BPTR pr_HomeDir Home directory of executing program
LONG pr_Flags Flags telling DOS about process
LONG (*pr_ExitCode)(LONG returncode, LONG pr_ExitData) Code to call on exit of program or NULL
LONG pr_ExitData Passed as an argument to pr_ExitCode
UBYTE* pr_Arguments Arguments passed to the process at start
struct MinList pr_LocalVars Local environment variables
ULONG pr_ShellPrivate For the use of the current Shell
BPTR pr_CES Error stream - if NULL, use pr_COS

To identify the segments that a particular process uses, you must use pr_SegList. pr_SegList is an array of longwords with its size in Seg_List[0]. Other elements are either zero or a BPTR to a SegList. CreateProc() and CreateNewProc() create this array with the first two elements of the array pointing to resident code and the third element, being the SegList, passed an argument. When a process terminates, FreeMem() is used to return the space for the pr_SegList.

The pr_StackSize field indicates the size of the process stack, as supplied by the user when calling CreateProc() or CreateNewProc(). Note that the process stack is not the same as the command stack a CLI uses when it calls a program. The CLI obtains its command stack just before it runs a program and you may alter the size of this stack with the STACK command. When you create a process, AmigaDOS obtains the process stack and stores the size in pr_StackSize. The pointer to the space for the process control block and the stack is also stored in the MemEntry field of the task structure. When the process terminates this space is returned via a call to FreeVec(). You can also chain any memory you obtain into this list structure so that it, too, gets put back when the task terminates. But be careful, this method won't work for a program run from the CLI since memory is not freed until the process goes away.

If a call to CreateProc() or CreateNewProc() creates the process, GlobVec is a pointer to the Shared Global Vector. However, some internal handler processes use a private global vector.

The value of pr_TaskNum is normally zero; a CLI process stores the small integer that identifies the invocation of the CLI here.

The pointer pr_StackBase points to the high-memory end of the process stack. This is the end of the stack when using languages such as C or assembler; it is the base of the stack for languages such as BCPL. Note that pr_StackBase may not be the same as the one your application uses (eg. if your program is started from the CLI).

The pr_Result2 and pr_CurrentDir fields are handled by the AmigaDOS functions IoErr() and CurrentDir(), respectively. pr_CIS and pr_COS are the values Input() and Output() return and refer to the filehandles you should use when running a program under the CLI. Never access pr_CIS and pr_COS directly. Instead use the AmigaDOS functions provided for this purpose.

The pr_ConsoleTask field refers to the console handler for the current window. The pr_FileSystemTask field refers to the file handler for the boot device. You use these values when attempting to open the * device or file by a relative path name when pr_CurrentDir is null.

The pr_CLI pointer is nonzero only for CLI processes. In this case it refers to a further structure the CLI uses with the following format:

Type Name Description
LONG cli_Result2 Value of IOErr from last command
BSTR cli_SetName Name of current directory
BPTR cli_CommandDir BPTR to CLI path
LONG cli_ReturnCode Return code from last command
BSTR cli_CommandName Name of current command
LONG cli_FailLevel Fail level (set by FAILAT)
BSTR cli_Prompt Current prompt (set by PROMPT)
BPTR cli_StandardInput Default (terminal) CLI input
BPTR cli_CurrentInput Current CLI input
BSTR cli_CommandFile Name of EXECUTE command file
LONG cli_Interactive Boolean; TRUE if prompts required
LONG cli_Background Boolean; TRUE if CLI created by RUN
BPTR cli_CurrentOutput Current CLI output
LONG cli_DefaultStack Stack size to be obtained in longwords
BPTR cli_StandardOutput Default (terminal) CLI output
BPTR cli_Module SegList of currently loaded command