flat assembler
Message board for the users of flat assembler.

Index > Windows > [content deleted]

Author
Thread Post new topic Reply to topic
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:55; edited 1 time in total
Post 27 Oct 2008, 16:28
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Post 27 Oct 2008, 18:52
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 19
Location: Czech republic
Hrstka
Perhaps you mean something like spinlock?
Post 29 Oct 2008, 19:36
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:55; edited 1 time in total
Post 16 Nov 2008, 09:47
View user's profile Send private message Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
xchg doesn't need lock prefix at all. this instruction is special about lock.
Post 16 Nov 2008, 13:26
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 19
Location: Czech republic
Hrstka
Have you read http://en.wikipedia.org/wiki/Spinlock#Example_implementation properly?
Code:
lock:                       ; The lock variable. 1 = locked, 0 = unlocked.
    dd      0    

The lock variable is defined somewhere in YOUR program, not in the kernel. You also have to change the name of the variable, otherwise fasm will complain. Then you do this:
Code:
call spin_lock
; now you can manipulate your structure without any harm
; ...
call spin_unlock    
and that's all.
Quote:
xchg doesn't need lock prefix at all.
Right, it's unnecessary in this case, if the lock prefix is there the CPU just ignores it.
Post 17 Nov 2008, 01:38
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3045
Location: vpcmipstrm
bitRAKE
Code:
lock:    ; 0 = locked, address = unlocked
    dd struct_address    
Here is an alternate method...
Code:
    ; here is the spin...
    xor eax,eax
@@: xchg eax,[lock]
    test eax,eax
    je @B


; now use address in EAX


    ; should put a serializing instruction here for safety
    mov [lock],eax ; put it back when done (unlock)    
...unlock doesn't need to be atomic, but all use of the structure should be complete. Serialization forces all instructions to retire prior to lock update. This should be faster, imho. (note: lock needs to be aligned to prevent spliting the write.)
Post 17 Nov 2008, 04:23
View user's profile Send private message Visit poster's website Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
bitRAKE, it's wrong method of acquiring spinlock. it should be done by lock + cmpxchg(8/16b). test eax,eax can be already invalid.
also i doublt that xchg need memory aligned. if it'is aligned even mov is atomic write instruction (on latest processors).
Post 17 Nov 2008, 09:47
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 457
Location: Czech republic, Slovak republic
Feryno
I like this way (simple, no registers destroyed, the PAUSE optimalization for newer CPUs)
Code:
call acquire_spinlock
; ... do the job
call release_spinlock
ret

; subprocedures:

acquire_spinlock_pause:
 pause
align 10h
acquire_spinlock:
 lock bts dword [spinlock],0
 jc      acquire_spinlock_pause
      ret

align 10h
release_spinlock:
       lock btr dword [spinlock],0
 ret

; data:

spinlock dd 0    
Post 17 Nov 2008, 11:49
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:55; edited 1 time in total
Post 17 Nov 2008, 13:47
View user's profile Send private message Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
yes i was wrong. xchg is good for this.
cmpxchg is for more complicated situations.
pause - it's good point for spin-lock loops.
Post 17 Nov 2008, 15:34
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:55; edited 1 time in total
Post 17 Nov 2008, 16:04
View user's profile Send private message Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
Suppose it was to me, then you can "safe" UTFG & RTFM lil script-kiddie malware writer. Your posts here on this forum are so pitiful that sometimes i think that you're not a programmer.
if not, please use google and read something.
Post 17 Nov 2008, 16:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.