1616#include "dix/registry_priv.h"
1717#include "dix/request_priv.h"
1818#include "dix/resource_priv.h"
19+ #include "dix/rpcbuf_priv.h"
1920#include "os/client_priv.h"
2021#include "miext/extinit_priv.h"
2122#include "Xext/xace.h"
@@ -52,9 +53,8 @@ typedef struct {
5253 ProcXResQueryClientIds; used by ConstructClientId* -functions */
5354typedef struct {
5455 int numIds ;
55- int resultBytes ;
56- struct xorg_list response ;
5756 int sentClientMasks [MAXCLIENTS ];
57+ x_rpcbuf_t rpcbuf ;
5858} ConstructClientIdCtx ;
5959
6060/** @brief Holds the structure for information required to
@@ -130,25 +130,6 @@ DestroyFragments(struct xorg_list *frags)
130130 }
131131}
132132
133- /** @brief Constructs a context record for ConstructClientId* functions
134- to use */
135- static void
136- InitConstructClientIdCtx (ConstructClientIdCtx * ctx )
137- {
138- ctx -> numIds = 0 ;
139- ctx -> resultBytes = 0 ;
140- xorg_list_init (& ctx -> response );
141- memset (ctx -> sentClientMasks , 0 , sizeof (ctx -> sentClientMasks ));
142- }
143-
144- /** @brief Destroys a context record, releases all memory (except the storage
145- for *ctx itself) */
146- static void
147- DestroyConstructClientIdCtx (ConstructClientIdCtx * ctx )
148- {
149- DestroyFragments (& ctx -> response );
150- }
151-
152133static Bool
153134InitConstructResourceBytesCtx (ConstructResourceBytesCtx * ctx ,
154135 ClientPtr sendClient ,
@@ -396,57 +377,43 @@ static Bool
396377ConstructClientIdValue (ClientPtr sendClient , ClientPtr client , CARD32 mask ,
397378 ConstructClientIdCtx * ctx )
398379{
399- xXResClientIdValue reply = {
400- .spec .client = client -> clientAsMask ,
401- };
402-
403- if (client -> swapped ) {
404- swapl (& reply .spec .client );
405- }
406-
407380 if (WillConstructMask (client , mask , ctx , X_XResClientXIDMask )) {
408- void * ptr = AddFragment ( & ctx -> response , sizeof ( reply ));
409- if (! ptr ) {
410- return FALSE;
411- }
381+ xXResClientIdValue reply = {
382+ . spec . client = client -> clientAsMask ,
383+ . spec . mask = X_XResClientXIDMask
384+ };
412385
413- reply . spec . mask = X_XResClientXIDMask ;
414- if ( sendClient -> swapped ) {
386+ if ( client -> swapped ) {
387+ swapl ( & reply . spec . client );
415388 swapl (& reply .spec .mask );
416389 /* swapl (&reply.length, n); - not required for reply.length = 0 */
417390 }
418391
419- memcpy (ptr , & reply , sizeof (reply ));
420-
421- ctx -> resultBytes += sizeof (reply );
392+ x_rpcbuf_write_CARD8s (& ctx -> rpcbuf , (CARD8 * )& reply , sizeof (reply ));
422393 ++ ctx -> numIds ;
423394 }
424395 if (WillConstructMask (client , mask , ctx , X_XResLocalClientPIDMask )) {
425396 pid_t pid = GetClientPid (client );
426397
427- if (pid != -1 ) {
428- void * ptr = AddFragment (& ctx -> response ,
429- sizeof (reply ) + sizeof (CARD32 ));
430- CARD32 * value = (void * ) ((char * ) ptr + sizeof (reply ));
398+ if (pid == -1 )
399+ return TRUE;
431400
432- if (!ptr ) {
433- return FALSE;
434- }
401+ xXResClientIdValue reply = {
402+ .spec .client = client -> clientAsMask ,
403+ .spec .mask = X_XResLocalClientPIDMask ,
404+ .length = 4
405+ };
435406
436- reply .spec .mask = X_XResLocalClientPIDMask ;
437- reply .length = 4 ;
407+ if (client -> swapped ) {
408+ swapl (& reply .spec .client );
409+ swapl (& reply .spec .mask );
410+ swapl (& reply .length );
411+ }
438412
439- if (sendClient -> swapped ) {
440- swapl (& reply .spec .mask );
441- swapl (& reply .length );
442- swapl (value );
443- }
444- memcpy (ptr , & reply , sizeof (reply ));
445- * value = pid ;
413+ x_rpcbuf_write_CARD8s (& ctx -> rpcbuf , (CARD8 * )& reply , sizeof (reply ));
414+ x_rpcbuf_write_CARD32 (& ctx -> rpcbuf , pid );
446415
447- ctx -> resultBytes += sizeof (reply ) + sizeof (CARD32 );
448- ++ ctx -> numIds ;
449- }
416+ ++ ctx -> numIds ;
450417 }
451418
452419 /* memory allocation errors earlier may return with FALSE */
@@ -517,23 +484,14 @@ ProcXResQueryClientIds (ClientPtr client)
517484 (uint64_t )stuff -> numSpecs * sizeof (xXResClientIdSpec ));
518485
519486 xXResClientIdSpec * specs = (void * ) ((char * ) stuff + sizeof (xXResQueryClientIdsReq ));
520- ConstructClientIdCtx ctx ;
521-
522- InitConstructClientIdCtx (& ctx );
523487
524- x_rpcbuf_t rpcbuf = { .swapped = client -> swapped , .err_clear = TRUE };
488+ ConstructClientIdCtx ctx = {
489+ .rpcbuf .swapped = client -> swapped ,
490+ .rpcbuf .err_clear = TRUE
491+ };
525492
526493 int rc = ConstructClientIds (client , stuff -> numSpecs , specs , & ctx );
527494 if (rc == Success ) {
528- FragmentList * it ;
529- xorg_list_for_each_entry (it , & ctx .response , l ) {
530- x_rpcbuf_write_CARD8s (& rpcbuf , FRAGMENT_DATA (it ), it -> bytes );
531- }
532-
533- if (rpcbuf .wpos != ctx .resultBytes )
534- LogMessage (X_WARNING , "ProcXResQueryClientIds() rpcbuf size (%ld) context size (%ld)\n" ,
535- (unsigned long )rpcbuf .wpos , (unsigned long )ctx .resultBytes );
536-
537495 xXResQueryClientIdsReply reply = {
538496 .numIds = ctx .numIds
539497 };
@@ -542,10 +500,10 @@ ProcXResQueryClientIds (ClientPtr client)
542500 swapl (& reply .numIds );
543501 }
544502
545- rc = X_SEND_REPLY_WITH_RPCBUF (client , reply , rpcbuf );
503+ rc = X_SEND_REPLY_WITH_RPCBUF (client , reply , ctx . rpcbuf );
546504 }
547505
548- DestroyConstructClientIdCtx (& ctx );
506+ x_rpcbuf_clear (& ctx . rpcbuf );
549507 return rc ;
550508}
551509
0 commit comments