From: Keir Fraser Subject: Re: Question regarding user-mode and debugging terminals Date: Fri, 05 Oct 2007 07:27:04 +0100 Message-ID: References: <411903.89270.qm@web50501.mail.re2.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <411903.89270.qm@web50501.mail.re2.yahoo.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: The Evil Geek , xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org On 5/10/07 02:09, "The Evil Geek" wrote: > The code that has been commented out is our attempt to > alter the segment registers and switch to ring 3. > However, this seems to be very wrong. We are > struggling to find examples as to how this switch to > userland might be achieved while running with xen > (and, in fact, in general). Does anyone have any > advice that might help us implement this switch to > userland? Additionally, will returning from a trap > into the kernel from userland automatically switch > back to userland or is additional effort needed? Your problem does not look to be specific to running on Xen. Your approach to switching to user space is a bit broken -- you cannot generally run kernel code in ring 3, since the page-table protection for kernel mappings is set to disallow ring-3 (user) accesses, since _PAGE_USER is clear in the PTEs. So you are probably taking a page fault immediately after the iret that is switching you to ring 3. An approach that works is to set up a dummy trap frame so it looks like user-space trapped to you. Then take your normal exit path from your OS. This raises the question of what to set %esp and %eip to when initially loading an application -- that is generally a question for your loader, and will be discovered by looking at e.g., Elf metadata. -- Keir