9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: cinap_lenrek@gmx.de
To: 9fans@9fans.net
Subject: Re: [9fans] Go/Inferno toolchain (Was: comment and newline in
Date: Wed, 30 Jun 2010 00:35:43 +0200	[thread overview]
Message-ID: <0510bb6f1fcb7c2a30557bc374eba6fa@gmx.de> (raw)
In-Reply-To: <AANLkTin7bcjTrQ-Kugu7-vJ8Byq68HKrSKAsLEM9zAAj@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2077 bytes --]

the segment registers are just indices to the kernels descriptor tables.
setting the segment registers can be done with assembly instructions from
userspace. but what you need is being able to modify the descriptors in
a save way from userspace!

i needed this for linuxemu to implement set_thread_area syscalls
under plan9 so i made the modifications to the kernel:

/n/sources/contrib/cinap_lenrek/segdescpatch

it adds the files ldt and gdt to devarch.

heres a linuxemu process where glibc has setup a special descriptor
and loaded %gs to point to it under plan9:

cat /dev/gdt
000b data     WPUBG    3 1819c080 fffff
000c data     -        0 00000000 00000
000d data     -        0 00000000 00000

PC	0x00020439 pread+0x7  /sys/src/libc/9syscall/pread.s:5
SP	0xdeffcd70 ECODE 0xf010080c EFLAG 0x00000286
CS	0x00000023 DS	 0x0000001b SS	0x0000001b
GS	0x0000005b FS	 0x00000000 ES	0x0000001b
TRAP	0x00000040 system call
AX	0x00000032 BX	0x00032b4c CX	0x00000001 DX	0x00000000
DI	0x080e7468 SI	0x00000000 BP	0xdeffcf2c

format of is simple text:

/*
 * format:
 * idx[4] type[8] flags[8] dpl[1] base[8] limit[5]\n
 */

idx is the descriptor index (the one you load into a segment registers by the selector)
type is code or data
dpl is the priority level (usualy just 3 for userspace)
base and limit describe the location of the segment (limit is in pages if G flag is set)

/*
 * flags:
 * P = present
 * A = accessed (for code/data)
 * E = expand down (for data)
 * W = writable (for data)
 * R = readable (for code)
 * C = conforming (for code)
 * G = limit granularity in pages (for code/data)
 * D = 32 bit operand size (for code)
 * B = 32 bit stack pointer (for data)
 * Y = busy (for tss and tss16)
 * U = available for use by system software
 */

gdt and ldt are both per process.  the only difference between gdt and
ldt is that gdt has a small fixed number of descriptors in the gdt
that you can modify.  the ldt refers to the local descriptor table
wich can have up to 2^13 user descriptors.

--
cinap

[-- Attachment #2: Type: message/rfc822, Size: 3896 bytes --]

From: ron minnich <rminnich@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] Go/Inferno toolchain (Was: comment and newline in
Date: Tue, 29 Jun 2010 14:03:36 -0700
Message-ID: <AANLkTin7bcjTrQ-Kugu7-vJ8Byq68HKrSKAsLEM9zAAj@mail.gmail.com>

Can someone remind me of the problem? Is it simply the need to be able
to set %gs?

Could a write to /dev/arch of something like
gs 0xwhatever
which sets %gs for that process solve the problem?

Or is it bigger than that?

ron

  parent reply	other threads:[~2010-06-29 22:35 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-25 15:35 [9fans] comment and newline in define lucio
     [not found] ` <AANLkTilhVWAu8htoIL903rtMK1z9Sw88pSfEASawc5Xi@mail.gmail.com>
2010-06-26  0:50   ` Christopher Nielsen
2010-06-26  0:58     ` erik quanstrom
2010-06-26  4:18       ` Rob Pike
2010-06-26  6:15         ` Christopher Nielsen
2010-06-26  5:19     ` [9fans] Go/Inferno toolchain (Was: comment and newline in define) lucio
2010-06-26  6:46       ` Christopher Nielsen
2010-06-26  9:26         ` [9fans] Go/Inferno toolchain (Was: comment and newline in lucio
2010-06-26 10:34           ` erik quanstrom
2010-06-26 11:00             ` lucio
2010-06-28 22:03           ` Eric Van Hensbergen
2010-06-29 17:24             ` Rob Pike
2010-06-29 17:31               ` Devon H. O'Dell
2010-06-29 17:36               ` Francisco J Ballesteros
2010-06-29 17:48                 ` Francisco J Ballesteros
2010-06-29 18:02                   ` Jack Johnson
2010-06-29 18:10               ` Eric Van Hensbergen
2010-06-29 18:12                 ` Francisco J Ballesteros
2010-06-29 20:30                   ` Eric Van Hensbergen
2010-06-29 18:32                 ` erik quanstrom
2010-06-29 20:45                   ` Eric Van Hensbergen
2010-06-29 20:52                     ` erik quanstrom
2010-06-29 21:03                       ` ron minnich
2010-06-29 21:36                         ` Steve Simon
2010-06-29 21:54                         ` Charles Forsyth
2010-06-30  9:25                           ` Lucio De Re
2010-06-29 22:35                         ` cinap_lenrek [this message]
2010-06-29 23:00                         ` Russ Cox
2010-06-30  8:17                           ` Lucio De Re
2010-06-29 21:15                       ` Devon H. O'Dell
2010-06-29 21:27                         ` ron minnich
2010-06-26  7:37       ` [9fans] Go/Inferno toolchain (Was: comment and newline in define) Ethan Grammatikidis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0510bb6f1fcb7c2a30557bc374eba6fa@gmx.de \
    --to=cinap_lenrek@gmx.de \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).