The kernel maintains a table to translate selector values to segment base paragraphs.
A Paragraph is a 16byte quantity. This table and translation is necessary because IBM PC uses 16bit selectors in instructions but segments may reside anywhere in the linear addressing space. For example, if a segment with selector 5 resides at 0x400000, we need to have selector translation 5 -> 0x400000. For 16bit programs the selector translation table is usually empty, selector values are equal to segment base paragraphs.
Allocate a selector for a segment if necessary.
You must call this function before calling add_segm_ex(). add_segm() calls this function itself, so you don't need to allocate a selector. This function will allocate a selector if 'segbase' requires more than 16 bits and the current processor is IBM PC. Otherwise it will return the segbase value.
- Parameters
-
segbase | a new segment base paragraph |
- Returns
- the allocated selector number
Allocate a selector for a segment unconditionally.
You must call this function before calling add_segm_ex(). add_segm() calls this function itself, so you don't need to allocate a selector. This function will allocate a new free selector and setup its mapping using find_free_selector() and set_selector() functions.
- Parameters
-
segbase | a new segment base paragraph |
- Returns
- the allocated selector number
Find first unused selector.
- Returns
- a number >= 1
Set mapping of selector to a paragraph.
You should call this function _before_ creating a segment which uses the selector, otherwise the creation of the segment will fail.
- Parameters
-
selector | number of selector to map
- if selector == BADSEL, then return 0 (fail)
- if the selector has had a mapping, old mapping is destroyed
- if the selector number is equal to paragraph value, then the mapping is destroyed because we don't need to keep trivial mappings.
|
paragraph | paragraph to map selector |
- Return values
-
1 | ok |
0 | failure (bad selector or too many mappings) |
Delete mapping of a selector.
Be wary of deleting selectors that are being used in the program, this can make a mess in the segments.
- Parameters
-
selector | number of selector to remove from the translation table |
Get mapping of a selector.
- Parameters
-
selector | number of selector to translate |
- Returns
- paragraph the specified selector is mapped to. if there is no mapping, returns 'selector'.
Get mapping of a selector as a linear address.
- Parameters
-
selector | number of selector to translate to linear address |
- Returns
- linear address the specified selector is mapped to. if there is no mapping, returns to_ea(selector,0);
Find a selector that has mapping to the specified paragraph.
- Parameters
-
base | paragraph to search in the translation table |
- Returns
- selector value or base
Enumerate all selectors from the translation table.
This function calls 'func' for each selector in the translation table. If 'func' returns non-zero code, enumeration is stopped and this code is returned.
- Parameters
-
func | callback function
- sel: selector number
- para: selector mapping
|
- Returns
- 0 or code returned by 'func'.
Enumerate all segments with the specified selector.
This function will call the callback function 'func' for each segment that has the specified selector. Enumeration starts from the last segment and stops at the first segment (reverse order). If the callback function 'func' returns a value != BADADDR, the enumeration is stopped and this value is returned to the caller.
- Parameters
-
selector | segments that have this selector are enumerated |
func | callback function
- s: pointer to segment structure
- ud: user data
|
ud | pointer to user data. this pointer will be passed to the callback function |
- Returns
- BADADDR or the value returned by the callback function 'func'
Get pointer to segment structure.
This function finds a segment by its selector. If there are several segments with the same selectors, the last one will be returned.
- Parameters
-
selector | a segment with the specified selector will be returned |
- Returns
- pointer to segment or NULL