This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Go in gcc 4.7
- From: Dennis Clarke <dclarke at blastwave dot org>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: Joel Sherrill <joel dot sherrill at oarcorp dot com>, Andreas Schwab <schwab at linux-m68k dot org>, Rainer Orth <ro at cebitec dot uni-bielefeld dot de>, "dclarke at blastwave dot org" <dclarke at blastwave dot org>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, "gofrontend-dev at googlegroups dot com" <gofrontend-dev at googlegroups dot com>
- Date: Thu, 12 Jan 2012 16:29:42 -0500 (EST)
- Subject: Re: Go in gcc 4.7
- Reply-to: dclarke at blastwave dot org
> Joel Sherrill <joel.sherrill@oarcorp.com> writes:
>
>> On 01/12/2012 12:16 PM, Andreas Schwab wrote:
>>> Ian Lance Taylor<iant@google.com> writes:
>>>
>>>> The functions required are makecontext, getcontext, and setcontext.
>>> Note that these functions are obsolescent in POSIX.1-2004 and removed
>>> from POSIX.1-2008.
>> Are there any alternatives? It is bad that Go is already starting
>> out dependent on obsolete methods. :(
>
> I would be glad to use alternatives but I'm not aware of any.
>
> The getcontext and setcontext functions are easy. The harder one is
> makecontext. POSIX appears to be assuming that any use of makecontext
> can be replaced with pthread_create, but if you care about efficiency
> that simply isn't true.
>
> Ian
>
Stuff from the opensolaris project isn't going to help here is it ?
void
makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
{
greg_t *reg;
long *tsp;
char *sp;
int argno;
va_list ap;
size_t size;
reg = ucp->uc_mcontext.gregs;
reg[REG_PC] = (greg_t)func;
reg[REG_nPC] = reg[REG_PC] + 0x4;
/*
* Reserve enough space for a frame and the arguments beyond the
* sixth; round to stack alignment.
*/
size = sizeof (struct frame);
size += (argc > 6 ? argc - 6 : 0) * sizeof (long);
/*
* The legacy implemenation of makecontext() on sparc has been to
* interpret the uc_stack.ss_sp member incorrectly as the top of the
* stack rather than the base. We preserve this behavior here, but
* provide the correct semantics in __makecontext_v2().
*/
sp = (char *)(((uintptr_t)ucp->uc_stack.ss_sp - size) &
~(STACK_ALIGN - 1));
/*
* Copy all args to the stack, and put the first 6 args into the
* ucontext_t. Zero the other fields of the frame.
*/
/* LINTED pointer cast may result in improper alignment */
tsp = &((struct frame *)sp)->fr_argd[0];
bzero(sp, sizeof (struct frame));
va_start(ap, argc);
for (argno = 0; argno < argc; argno++) {
if (argno < 6)
*tsp++ = reg[REG_O0 + argno] = va_arg(ap, long);
else
*tsp++ = va_arg(ap, long);
}
va_end(ap);
reg[REG_SP] = (greg_t)sp - STACK_BIAS; /* sp (when done) */
reg[REG_O7] = (greg_t)resumecontext - 8; /* return pc */
}
--
--
http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0x1D936C72FA35B44B
+-------------------------+-----------------------------------+
| Dennis Clarke | Solaris and Linux and Open Source |
| dclarke@blastwave.org | Respect for open standards. |
+-------------------------+-----------------------------------+