flat assembler
Message board for the users of flat assembler.

Index > Windows > CRITICAL_SECTION

Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
Good day all,

I want to use critical section functions and i need to declare a variable of type CRITICAL_SECTION
Where can i found this structure?
I've searched board for an example, but with no luck so far.
Post 16 Jul 2009, 07:57
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
Ok, I think i found it.

Code:
struc RTL_CRITICAL_SECTION {
  .DebugInfo dd ?
     .LockCount dd ?
     .RecursionCount dd ?
        .OwningThread dd ?
  .LockSemaphore dd ?
 .SpinCount dd ?
       }
    
Post 16 Jul 2009, 11:53
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
To be safe better use this:
Code:
struc RTL_CRITICAL_SECTION {
align 4 ; Will pad with NOPs only if more initialized data and/or instructions follows in the current section, otherwise it will only reserve space
.:
        .DebugInfo dd ?
        .LockCount dd ?
        .RecursionCount dd ?
        .OwningThread dd ?
        .LockSemaphore dd ?
        .SpinCount dd ?
       }       


I don't remember if EnterCriticalSection and/or InitializeCriticalSection fail if the structure is unaligned but yet I think there could be some problems on multi-{core|CPU} systems.
Post 16 Jul 2009, 15:59
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
Thank you LocoDelAssembly.
Post 17 Jul 2009, 15:31
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
Hi again guys,
I need to use the in_addr structure in fasm.

Code:
typedef struct in_addr {
  union {
    struct {
      u_char s_b1,s_b2,s_b3,s_b4;
    } S_un_b;
    struct {
      u_short s_w1,s_w2;
    } S_un_w;
    u_long S_addr;
  } S_un;
}IN_ADDR, *PIN_ADDR, FAR *LPIN_ADDR;
    

I found MASM in_addr structure code below..
Code:
S_UN_B STRUCT
  s_b1 BYTE ?
  s_b2 BYTE ?
  s_b3 BYTE ?
  s_b4 BYTE ?
ENDS
 
S_UN_W STRUCT 
  s_w1 WORD ?
  s_w2 WORD ?
ENDS
 
ADDRESS_UNION UNION 
   S_un_b S_UN_B <>
   S_un_w S_UN_W <>
   S_addr DWORD ?
ENDS
 
in_addr STRUCT
  S_un ADDRESS_UNION <>
in_addr ENDS
    

..and attempt a rewrite in fasm.
Is this correct ?
Code:
struc S_un_b {
        .s_b1 db ?
          .s_b2 db ?
          .s_b3 db ?
          .s_b4 db ?
          }

struc S_un_w {
   .s_w1 dw ?
          .s_w2 dw ?
          }

struc ADDRESS_UNION {
   virtual
      .S_un_b S_un_b
      .S_un_w S_un_w
              .S_addr dd ?
   end virtual
      }

struc in_addr  {
         .S_un ADDRESS_UNION
         }

   virtual at 0
       in_addr in_addr
     sizeof.in_addr:
   end virtual
    
Post 21 Jul 2009, 11:12
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2937
Location: vpcmipstrm
bitRAKE
ADDRESS_UNION doesn't seem correct, but the rest is okay.
Code:
struc ADDRESS_UNION {
   virtual at $
        .S_un_b S_un_b
   end virtual
   virtual at $
        .S_un_w S_un_w
   end virtual
   .S_addr dd ?
        }    
...no testing done - maybe, there is a better way?
Post 21 Jul 2009, 14:23
View user's profile Send private message Visit poster's website 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 YouTube, Twitter.

Website powered by rwasa.