@@ -25,14 +25,41 @@ use crate::{
2525 BinderReturnWriter , DArc , DLArc , DTRWrap , DeliverToRead ,
2626} ;
2727
28+ kernel:: impl_flags!(
29+ /// Represents multiple transaction flags.
30+ #[ derive( Debug , Clone , Default , Copy , PartialEq , Eq , Zeroable ) ]
31+ pub struct TransactionFlags ( u32 ) ;
32+
33+ /// Represents a single transaction flag.
34+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
35+ pub enum TransactionFlag {
36+ OneWay = TF_ONE_WAY ,
37+ AcceptFds = TF_ACCEPT_FDS ,
38+ ClearBuf = TF_CLEAR_BUF ,
39+ UpdateTxn = TF_UPDATE_TXN ,
40+ }
41+ ) ;
42+
43+ impl TransactionFlags {
44+ /// Creates a `TransactionFlags` from a raw `u32` value.
45+ pub ( crate ) fn from_bits ( bits : u32 ) -> Self {
46+ Self ( bits)
47+ }
48+
49+ /// Checks if the Oneway flag is set.
50+ pub ( crate ) fn is_oneway ( self ) -> bool {
51+ self . contains ( TransactionFlag :: OneWay )
52+ }
53+ }
54+
2855#[ derive( Zeroable ) ]
2956pub ( crate ) struct TransactionInfo {
3057 pub ( crate ) from_pid : Pid ,
3158 pub ( crate ) from_tid : Pid ,
3259 pub ( crate ) to_pid : Pid ,
3360 pub ( crate ) to_tid : Pid ,
3461 pub ( crate ) code : u32 ,
35- pub ( crate ) flags : u32 ,
62+ pub ( crate ) flags : TransactionFlags ,
3663 pub ( crate ) data_ptr : UserPtr ,
3764 pub ( crate ) data_size : usize ,
3865 pub ( crate ) offsets_ptr : UserPtr ,
@@ -48,7 +75,7 @@ pub(crate) struct TransactionInfo {
4875impl TransactionInfo {
4976 #[ inline]
5077 pub ( crate ) fn is_oneway ( & self ) -> bool {
51- self . flags & TF_ONE_WAY != 0
78+ self . flags . is_oneway ( )
5279 }
5380}
5481
@@ -74,7 +101,7 @@ pub(crate) struct Transaction {
74101 allocation : SpinLock < Option < Allocation > > ,
75102 is_outstanding : Atomic < bool > ,
76103 code : u32 ,
77- pub ( crate ) flags : u32 ,
104+ pub ( crate ) flags : TransactionFlags ,
78105 data_size : usize ,
79106 offsets_size : usize ,
80107 data_address : usize ,
@@ -121,7 +148,7 @@ impl Transaction {
121148 }
122149 alloc. set_info_oneway_node ( node_ref. node . clone ( ) ) ;
123150 }
124- if info. flags & TF_CLEAR_BUF != 0 {
151+ if info. flags . contains ( TransactionFlag :: ClearBuf ) {
125152 alloc. set_info_clear_on_drop ( ) ;
126153 }
127154 let target_node = node_ref. node . clone ( ) ;
@@ -162,7 +189,7 @@ impl Transaction {
162189 return Err ( err) ;
163190 }
164191 } ;
165- if info. flags & TF_CLEAR_BUF != 0 {
192+ if info. flags . contains ( TransactionFlag :: ClearBuf ) {
166193 alloc. set_info_clear_on_drop ( ) ;
167194 }
168195 Ok ( DTRWrap :: arc_pin_init ( pin_init ! ( Transaction {
@@ -195,7 +222,7 @@ impl Transaction {
195222 self . from. id,
196223 self . to. task. pid( ) ,
197224 self . code,
198- self . flags,
225+ u32 :: from ( self . flags) ,
199226 self . start_time. elapsed( ) . as_millis( ) ,
200227 ) ;
201228 if let Some ( target_node) = & self . target_node {
@@ -274,7 +301,7 @@ impl Transaction {
274301 let _t_outdated;
275302 let _oneway_node;
276303
277- let oneway = self . flags & TF_ONE_WAY != 0 ;
304+ let oneway = self . flags . is_oneway ( ) ;
278305 let process = self . to . clone ( ) ;
279306 let mut process_inner = process. inner . lock ( ) ;
280307
@@ -285,7 +312,7 @@ impl Transaction {
285312 crate :: trace:: trace_transaction ( false , & self , None ) ;
286313 if process_inner. is_frozen . is_frozen ( ) {
287314 process_inner. async_recv = true ;
288- if self . flags & TF_UPDATE_TXN != 0 {
315+ if self . flags . contains ( TransactionFlag :: UpdateTxn ) {
289316 if let Some ( t_outdated) =
290317 target_node. take_outdated_transaction ( & self , & mut process_inner)
291318 {
@@ -356,7 +383,8 @@ impl Transaction {
356383 return false ;
357384 }
358385
359- if self . flags & old. flags & ( TF_ONE_WAY | TF_UPDATE_TXN ) != ( TF_ONE_WAY | TF_UPDATE_TXN ) {
386+ let required = TransactionFlag :: OneWay | TransactionFlag :: UpdateTxn ;
387+ if !( self . flags . contains_all ( required) && old. flags . contains_all ( required) ) {
360388 return false ;
361389 }
362390
@@ -393,7 +421,7 @@ impl DeliverToRead for Transaction {
393421 writer : & mut BinderReturnWriter < ' _ > ,
394422 ) -> Result < bool > {
395423 let send_failed_reply = ScopeGuard :: new ( || {
396- if self . target_node . is_some ( ) && self . flags & TF_ONE_WAY == 0 {
424+ if self . target_node . is_some ( ) && ! self . flags . is_oneway ( ) {
397425 let reply = Err ( BR_FAILED_REPLY ) ;
398426 self . from . deliver_reply ( reply, & self ) ;
399427 }
@@ -416,7 +444,7 @@ impl DeliverToRead for Transaction {
416444 tr. cookie = cookie as uapi:: binder_uintptr_t ;
417445 } ;
418446 tr. code = self . code ;
419- tr. flags = self . flags ;
447+ tr. flags = u32 :: from ( self . flags ) ;
420448 tr. data_size = self . data_size as uapi:: binder_size_t ;
421449 tr. data . ptr . buffer = self . data_address as uapi:: binder_uintptr_t ;
422450 tr. offsets_size = self . offsets_size as uapi:: binder_size_t ;
@@ -426,7 +454,7 @@ impl DeliverToRead for Transaction {
426454 }
427455 tr. sender_euid = self . sender_euid . into_uid_in_current_ns ( ) ;
428456 tr. sender_pid = 0 ;
429- if self . target_node . is_some ( ) && self . flags & TF_ONE_WAY == 0 {
457+ if self . target_node . is_some ( ) && ! self . flags . is_oneway ( ) {
430458 // Not a reply and not one-way.
431459 tr. sender_pid = self . from . process . pid_in_current_ns ( ) ;
432460 }
@@ -478,7 +506,7 @@ impl DeliverToRead for Transaction {
478506 drop ( allocation) ;
479507
480508 // If this is not a reply or oneway transaction, then send a dead reply.
481- if self . target_node . is_some ( ) && self . flags & TF_ONE_WAY == 0 {
509+ if self . target_node . is_some ( ) && ! self . flags . is_oneway ( ) {
482510 let reply = Err ( BR_DEAD_REPLY ) ;
483511 self . from . deliver_reply ( reply, & self ) ;
484512 }
@@ -487,7 +515,7 @@ impl DeliverToRead for Transaction {
487515 }
488516
489517 fn should_sync_wakeup ( & self ) -> bool {
490- self . flags & TF_ONE_WAY == 0
518+ ! self . flags . is_oneway ( )
491519 }
492520
493521 fn debug_print ( & self , m : & SeqFile , _prefix : & str , tprefix : & str ) -> Result < ( ) > {
0 commit comments