Loading...
Searching...
No Matches
segment.h
Go to the documentation of this file.
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
/*****************************************************************************/
#ifndef __L4_SYS__ARCH_X86__SEGMENT_H__
#define __L4_SYS__ARCH_X86__SEGMENT_H__
#ifndef L4API_l4f
#error This header file can only be used with a L4API version!
#endif
#include <l4/sys/ipc.h>
L4_INLINE long
fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int num_desc,
unsigned int entry_number_start, l4_utcb_t *utcb);
L4_INLINE long
fiasco_gdt_set(l4_cap_idx_t thread, void *desc, unsigned int size,
unsigned int entry_number_start, l4_utcb_t *utcb);
L4_INLINE unsigned
fiasco_gdt_get_entry_offset(l4_cap_idx_t thread, l4_utcb_t *utcb);
enum L4_task_ldt_x86_consts
{
L4_TASK_LDT_X86_ENTRY_SIZE = 8,
L4_TASK_LDT_X86_MAX_ENTRIES
= (L4_UTCB_GENERIC_DATA_SIZE - 2)
/ (L4_TASK_LDT_X86_ENTRY_SIZE / (L4_MWORD_BITS / 8)),
};
L4_INLINE long
fiasco_amd64_set_fs(l4_cap_idx_t thread, l4_umword_t base, l4_utcb_t *utcb);
enum L4_sys_segment
{
L4_AMD64_SEGMENT_FS = 0,
L4_AMD64_SEGMENT_GS = 1
};
L4_INLINE long
fiasco_amd64_set_segment_base(l4_cap_idx_t thread, enum L4_sys_segment segr,
l4_umword_t base, l4_utcb_t *utcb);
L4_INLINE long
fiasco_amd64_segment_info(l4_cap_idx_t thread, unsigned *user_ds,
unsigned *user_cs, unsigned *user32_cs,
l4_utcb_t *utcb);
/*****************************************************************************
*** Implementation
*****************************************************************************/
#include <l4/sys/task.h>
#include <l4/sys/thread.h>
L4_INLINE long
fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int num_desc,
unsigned int entry_number_start, l4_utcb_t *utcb)
{
if (num_desc > L4_TASK_LDT_X86_MAX_ENTRIES)
return -L4_EINVAL;
l4_utcb_mr_u(utcb)->mr[0] = L4_TASK_LDT_SET_X86_OP;
l4_utcb_mr_u(utcb)->mr[1] = entry_number_start;
__builtin_memcpy(&l4_utcb_mr_u(utcb)->mr[2], ldt,
num_desc * L4_TASK_LDT_X86_ENTRY_SIZE);
return l4_error_u(l4_ipc_call(task, utcb, l4_msgtag(L4_PROTO_TASK, 2 + num_desc * 2, 0, 0), L4_IPC_NEVER), utcb);
}
L4_INLINE unsigned
fiasco_gdt_get_entry_offset(l4_cap_idx_t thread, l4_utcb_t *utcb)
{
l4_utcb_mr_u(utcb)->mr[0] = L4_THREAD_X86_GDT_OP;
if (l4_error_u(l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 1, 0, 0), L4_IPC_NEVER), utcb))
return -1;
return l4_utcb_mr_u(utcb)->mr[0];
}
L4_INLINE long
fiasco_amd64_segment_info(l4_cap_idx_t thread, unsigned *user_ds,
unsigned *user_cs, unsigned *user32_cs,
l4_utcb_t *utcb)
{
l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
int r;
m->mr[0] = L4_THREAD_AMD64_GET_SEGMENT_INFO_OP;
r = l4_error_u(l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 1, 0, 0),
L4_IPC_NEVER), utcb);
if (r < 0)
return r;
*user_ds = m->mr[0];
*user_cs = m->mr[1];
*user32_cs = m->mr[2];
return 0;
}
#endif /* ! __L4_SYS__ARCH_X86__SEGMENT_H__ */
L4_sys_segment
L4_sys_segment
Constants for identifying segments.
Definition segment.h:107
L4_AMD64_SEGMENT_GS
@ L4_AMD64_SEGMENT_GS
Constant identifying the GS segment.
Definition segment.h:111
L4_AMD64_SEGMENT_FS
@ L4_AMD64_SEGMENT_FS
Constant identifying the FS segment.
Definition segment.h:109
L4_task_ldt_x86_consts
L4_task_ldt_x86_consts
Contants for LDT handling.
Definition segment.h:76
L4_TASK_LDT_X86_MAX_ENTRIES
@ L4_TASK_LDT_X86_MAX_ENTRIES
Maximum number of LDT entries that can be written with one call.
Definition segment.h:80
L4_TASK_LDT_X86_ENTRY_SIZE
@ L4_TASK_LDT_X86_ENTRY_SIZE
Size of an LDT entry.
Definition segment.h:78
fiasco_amd64_segment_info
long fiasco_amd64_segment_info(l4_cap_idx_t thread, unsigned *user_ds, unsigned *user_cs, unsigned *user32_cs, l4_utcb_t *utcb)
Get segment information.
Definition segment.h:175
fiasco_amd64_set_segment_base
long fiasco_amd64_set_segment_base(l4_cap_idx_t thread, enum L4_sys_segment segr, l4_umword_t base, l4_utcb_t *utcb)
Set the base address for a segment.
Definition segment.h:32
fiasco_amd64_set_fs
long fiasco_amd64_set_fs(l4_cap_idx_t thread, l4_umword_t base, l4_utcb_t *utcb)
Set the base address for the FS segment.
Definition segment.h:24
fiasco_ldt_set
long fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int num_desc, unsigned int entry_number_start, l4_utcb_t *utcb)
Set LDT segments descriptors.
Definition segment.h:153
fiasco_gdt_get_entry_offset
unsigned fiasco_gdt_get_entry_offset(l4_cap_idx_t thread, l4_utcb_t *utcb)
Return the offset of the entry in the GDT.
Definition segment.h:166
fiasco_gdt_set
long fiasco_gdt_set(l4_cap_idx_t thread, void *desc, unsigned int size, unsigned int entry_number_start, l4_utcb_t *utcb)
Set GDT segment descriptors.
Definition segment.h:41
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
L4_MWORD_BITS
#define L4_MWORD_BITS
Size of machine words in bits.
Definition l4int.h:22
l4_cap_idx_t
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:336
L4_EINVAL
@ L4_EINVAL
Invalid argument.
Definition err.h:46
l4_ipc_call
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition ipc.h:565
l4_msgtag
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition types.h:405
L4_PROTO_TASK
@ L4_PROTO_TASK
Protocol for messages to a task object.
Definition types.h:53
L4_PROTO_THREAD
@ L4_PROTO_THREAD
Protocol for messages to a thread object.
Definition types.h:54
L4_TASK_LDT_SET_X86_OP
@ L4_TASK_LDT_SET_X86_OP
x86: LDT set
Definition task.h:347
L4_THREAD_AMD64_GET_SEGMENT_INFO_OP
@ L4_THREAD_AMD64_GET_SEGMENT_INFO_OP
Get segment information.
Definition thread.h:747
L4_THREAD_X86_GDT_OP
@ L4_THREAD_X86_GDT_OP
Gdt.
Definition thread.h:744
L4_IPC_NEVER
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
l4_utcb_t
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
ipc.h
Common IPC interface.
task.h
Common task related definitions.
thread.h
Common thread related definitions.
l4_msg_regs_t
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:68
l4_msg_regs_t::mr
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:69