On 2010/08/26 16:07:46, rsc1 wrote: > I don't know what to do about this. > ...
14 years, 6 months ago
(2010-08-27 01:04:33 UTC)
#3
On 2010/08/26 16:07:46, rsc1 wrote:
> I don't know what to do about this.
> Is there something this is driving toward?
The code is out of date, but the idea here is fine. The outcome is, we should be
able to callback from outside of Go back in. This will allow us to implement
some apis, like create and manipulate gui objects, create windows service apps
and so on.
I was hoping to settle all our existing issues with stdcalls and stacks first,
but, perhaps, I should move forward, this could push things a bit and might give
us more clues.
Alex
On 2010/09/14 01:59:47, brainman wrote: > Hello rsc (cc: mailto:golang-dev@googlegroups.com), > > I'd like you ...
14 years, 5 months ago
(2010-09-27 20:30:43 UTC)
#5
On 2010/09/14 01:59:47, brainman wrote:
> Hello rsc (cc: mailto:golang-dev@googlegroups.com),
>
> I'd like you to review this change.
Hi,
I have applied this patch to my local Go installation (release 2010-09-22) and
have started to adjust the Walk library in a separate branch to use callbacks:
http://github.com/lxn/walk/tree/callbacks
There is a drawing example app, which works fine and an image viewer example
that crashes when opening an image file.
The problem seems to be insufficient stack space and does not show up in the
master branch of Walk that uses a helper dll instead of callbacks.
It would be very nice if someone who knows the inner workings of the Go Windows
port could give it a try - and maybe come up with a fix ;)
Working callback support is a game changer for stuff like Walk and I really hope
it will make its way into one of the next Go releases.
Thanks
Alex
Hi Alex, > I have applied this patch to my local Go installation (release > ...
14 years, 5 months ago
(2010-09-28 06:16:53 UTC)
#6
Hi Alex,
> I have applied this patch to my local Go installation (release
> 2010-09-22) and have started to adjust the Walk library in a separate
> branch to use callbacks:
> http://github.com/lxn/walk/tree/callbacks
I tried to download your source, but I can't see callbacks branch (I'm
not good with git):
git clone http://github.com/lxn/walk.git
cd walk
git branch says: * master
?
Alex
On 2010/09/27 20:30:43, lxn wrote: > The problem seems to be insufficient stack space ...
14 years, 5 months ago
(2010-09-29 05:36:28 UTC)
#7
On 2010/09/27 20:30:43, lxn wrote:
> The problem seems to be insufficient stack space ...
You're right on the money.
Lucky for you, I've been over this code million times, I didn't have to think
twice <g>.
Windows syscalls run on scheduler stack. The stack is working as all go stacks
do: it is set to fixed size (8k at the moment), it grows, once it reaches its
limit, it spills into new fixed size stack that is created out of malloced
memory. The special thing about scheduler stack is its first 8k section is
layout on real windows stack (it is huge). Also scheduler never uses more than
8k of stack, therefore scheduler stack never split. When windows syscall called,
it is always on real huge windows stack, it can use as much as needed, but once
back from the call, stack is back where it is started before the call.
With callbacks things becomes trickier. If callback occurs during windows
syscall execution, scheduler stack will be smaller by the amount of space used
by syscall. This, I suspect, will lead to the fact that all 8k of first fragment
will get used and scheduler will mallocate new stack section (this time on heap,
not os stack). If go makes another windows syscall now, there is a risk of
windows writing beyond new stack boundary (windows expects one huge stack). This
will write over your heap memory. Lights off.
What you need to do is tell go scheduler, that its stack is bigger then 8k. You
use real os stack here, so size doesn't matter, you could go as big as biggest
possible os stack (1 gig or something).
These changes do just that. Increase go scheduler stack for first os thread in
runtime/386/asm.s:
@@ -44,7 +44,7 @@
MOVL CX, m_g0(AX)
// create istack out of the OS stack
- LEAL (-8192+104)(SP), AX // TODO: 104?
+ LEAL (-65536+104)(SP), AX // TODO: 104?
MOVL AX, g_stackguard(CX)
MOVL SP, g_stackbase(CX)
CALL emptyfunc(SB) // fault if stack check is wrong
You must also do the same for every new os thread in runtime/windows/386/sys.s:
99c99
< SUBL $8192, AX // stack size
---
> SUBL $65536, AX // stack size
It works for me.
Alex
PS: It is much nicer that you have Makefiles now <g>.
On 2010/09/29 05:36:28, brainman wrote: > On 2010/09/27 20:30:43, lxn wrote: > > > The ...
14 years, 5 months ago
(2010-09-29 08:24:56 UTC)
#8
On 2010/09/29 05:36:28, brainman wrote:
> On 2010/09/27 20:30:43, lxn wrote:
>
> > The problem seems to be insufficient stack space ...
>
> You're right on the money.
>
> Lucky for you, I've been over this code million times, I didn't have to think
> twice <g>.
>
> Windows syscalls run on scheduler stack. The stack is working as all go stacks
> do: it is set to fixed size (8k at the moment), it grows, once it reaches its
> limit, it spills into new fixed size stack that is created out of malloced
> memory. The special thing about scheduler stack is its first 8k section is
> layout on real windows stack (it is huge). Also scheduler never uses more than
> 8k of stack, therefore scheduler stack never split. When windows syscall
called,
> it is always on real huge windows stack, it can use as much as needed, but
once
> back from the call, stack is back where it is started before the call.
>
> With callbacks things becomes trickier. If callback occurs during windows
> syscall execution, scheduler stack will be smaller by the amount of space used
> by syscall. This, I suspect, will lead to the fact that all 8k of first
fragment
> will get used and scheduler will mallocate new stack section (this time on
heap,
> not os stack). If go makes another windows syscall now, there is a risk of
> windows writing beyond new stack boundary (windows expects one huge stack).
This
> will write over your heap memory. Lights off.
>
> What you need to do is tell go scheduler, that its stack is bigger then 8k.
You
> use real os stack here, so size doesn't matter, you could go as big as biggest
> possible os stack (1 gig or something).
>
> These changes do just that. Increase go scheduler stack for first os thread in
> runtime/386/asm.s:
>
> @@ -44,7 +44,7 @@
> MOVL CX, m_g0(AX)
>
> // create istack out of the OS stack
> - LEAL (-8192+104)(SP), AX // TODO: 104?
> + LEAL (-65536+104)(SP), AX // TODO: 104?
> MOVL AX, g_stackguard(CX)
> MOVL SP, g_stackbase(CX)
> CALL emptyfunc(SB) // fault if stack check is wrong
>
> You must also do the same for every new os thread in
runtime/windows/386/sys.s:
>
> 99c99
> < SUBL $8192, AX // stack size
> ---
> > SUBL $65536, AX // stack size
>
> It works for me.
Works here as well. This helps me a lot, thanks. Also a nice explanation what's
going on with stacks and callbacks!
Now this just has to make its way into the Go repo :)
>
> Alex
>
> PS: It is much nicer that you have Makefiles now <g>.
It was about time. When I introduced them, they immediately uncovered some
errors that I didn't notice before, because some rarely used parts of the lib
weren't built for a while.
Thanks
Alex
> > It works for me. > > Works here as well. This helps me ...
14 years, 5 months ago
(2010-09-30 16:09:02 UTC)
#9
> > It works for me.
>
> Works here as well. This helps me a lot, thanks.
Cheered too soon.
Stack overflows still occur after slightly modifying the imageviewer example. I
tried to increase stack size to 1 meg by naively replacing the suggested 65536
with 1048576, but it seems to have no effect.
Sadly I have no experience with x86 assembly, only ever did some 6502 stuff long
time ago, so I am probably wrong, but isn't AX a 16 bit register, so it can't
work with greater values?
Hopefully someone could help with this once again.
Thanks
Alex
2010/9/30 <an2048@googlemail.com>: >> > It works for me. > >> Works here as well. This ...
14 years, 5 months ago
(2010-09-30 22:52:34 UTC)
#10
2010/9/30 <an2048@googlemail.com>:
>> > It works for me.
>
>> Works here as well. This helps me a lot, thanks.
>
> Cheered too soon.
>
> Stack overflows still occur after slightly modifying the imageviewer
> example. I tried to increase stack size to 1 meg by naively replacing
> the suggested 65536 with 1048576, but it seems to have no effect.
>
> Sadly I have no experience with x86 assembly, only ever did some 6502
> stuff long time ago, so I am probably wrong, but isn't AX a 16 bit
> register, so it can't work with greater values?
I think the deal is that you just use AX / BX / etc as necessary, and
the "proper" register is determined based on the instruction used.
E.g. MOVL $1234, AX and MOVB $1, AX will generate different machine
code, but you don't have to think about what permutation of register
you are supposed to be using. So that's not likely the issue.
--dho
> Hopefully someone could help with this once again.
>
> Thanks
> Alex
>
> http://codereview.appspot.com/1696051/
>
> I think the deal is that you just use AX / BX / etc ...
14 years, 5 months ago
(2010-10-01 04:35:31 UTC)
#11
> I think the deal is that you just use AX / BX / etc as necessary, and
> the "proper" register is determined based on the instruction used.
> E.g. MOVL $1234, AX and MOVB $1, AX will generate different machine
> code, but you don't have to think about what permutation of register
> you are supposed to be using. So that's not likely the issue.
Yes: the size is given in the instruction, not by a prefix on the
register name.
Russ
On 2010/09/30 16:09:02, lxn wrote: > > Cheered too soon. > > Stack overflows still ...
14 years, 5 months ago
(2010-10-01 07:30:46 UTC)
#12
On 2010/09/30 16:09:02, lxn wrote:
>
> Cheered too soon.
>
> Stack overflows still occur after slightly modifying the imageviewer example.
I
Now that I have checked some variables in windows/thread.c/callback(), I think I
have a problem, because I'm not switching on OS stack, but small 4k stack in
m->curg. I'll just have to learn more about scheduler <g>.
Alex
On 2010/10/01 07:30:46, brainman wrote: It looks like we need to make stack splitting code ...
14 years, 5 months ago
(2010-10-04 00:20:14 UTC)
#13
On 2010/10/01 07:30:46, brainman wrote:
It looks like we need to make stack splitting code work across syscall.
Russ,
From old CL #834045:
http://codereview.appspot.com/834045/diff/2001/3003#newcode66
src/pkg/runtime/cgocall.c:66: sp = g->sched.sp - argsize;
if(sp < g->stackguard)
throw("g stack overflow in cgocallback");
(and eventually we can do the right thing
but adding a stack split to this code seems
like a good thing for a separate CL)
If you give me an idea of what to do, I'll have a go.
Alex
On 2010/09/30 16:09:02, lxn wrote: > Hopefully someone could help with this once again. > ...
14 years, 2 months ago
(2011-01-11 04:18:05 UTC)
#15
On 2010/09/30 16:09:02, lxn wrote:
> Hopefully someone could help with this once again.
>
We're getting nowhere, so I looked again and these small changes will let me
overcome your problem:
1) Disable check for "g stack overflow in callback" altogether. Perhaps will
come back to it, but for now I can see the stack gets beyond stackguard just by
20-40 bytes. I hope it is enough to survive.
2) Marked runtime.callback() as "#pragma textflag 7" (thanks to czaplinski),
this function is running on os stack and shouldn't attempt to allocate more
stack.
3) Increase (double) size of scheduler stack. All callbacks are happening on
scheduler stack and 8k is not enough - I can see "morestack()" gets called from
startcgocallback() and it shouldn't. Both initial and every new os thread stacks
have been increased.
Alex
http://codereview.appspot.com/1696051/diff/43001/src/pkg/exp/wingui/Makefile File src/pkg/exp/wingui/Makefile (right): http://codereview.appspot.com/1696051/diff/43001/src/pkg/exp/wingui/Makefile#newcode1 src/pkg/exp/wingui/Makefile:1: # Copyright 2009 The Go Authors. All rights reserved. ...
14 years, 2 months ago
(2011-01-11 16:43:58 UTC)
#16
Looks pretty good. I think you should address the sys.s TODO now. http://codereview.appspot.com/1696051/diff/55001/src/pkg/runtime/windows/386/sys.s File src/pkg/runtime/windows/386/sys.s ...
14 years, 2 months ago
(2011-01-13 18:21:44 UTC)
#19
I applied your latest changes to release.2011-01-20 and checked the examples from the Walk[1] library ...
14 years, 1 month ago
(2011-01-21 11:28:38 UTC)
#22
I applied your latest changes to release.2011-01-20 and checked the examples
from the Walk[1] library and the only problem I still see is a crasher when the
WebView widget is involved, which is the case in the filebrowser and webbrowser
examples.
The WebView widget embeds the IE control which requires the use of COM. I
wouldn't be surprised if the problem is in the COM handling code of Walk, but
with a Go runtime patch from Mateusz Czapliński the WebView worked. Only when I
later added code for WebView event handling, it stopped working with his patch.
Maybe this has to be dealt with in Walk, so don't let it hold up the commit ;)
[1] https://github.com/lxn/walk
Cheers
Alex
*** Submitted as http://code.google.com/p/go/source/detail?r=7195d7795c6b *** runtime: implementation of callback functions for windows R=rsc, lxn, alex.brainman, ...
14 years, 1 month ago
(2011-01-22 02:56:05 UTC)
#27
Issue 1696051: code review 1696051: runtime: implementation of callback functions for windows
(Closed)
Created 14 years, 8 months ago by brainman
Modified 14 years, 1 month ago
Reviewers:
Base URL:
Comments: 35