]> granicus.if.org Git - strace/commitdiff
Do not allocate tiny cap_user_header/data structures, place them on stack.
authorDenys Vlasenko <dvlasenk@redhat.com>
Thu, 23 Jun 2011 11:10:28 +0000 (13:10 +0200)
committerDenys Vlasenko <dvlasenk@redhat.com>
Thu, 23 Jun 2011 11:10:28 +0000 (13:10 +0200)
This allows us to avoid having code to malloc them, and code to check
for malloc failure. Resulting code decrease:
   text    data     bss     dec     hex filename
  10175       0      16   10191    27cf system.o.old
   9797       0       0    9797    2645 system.o

* system.c (sys_capget): Put cap_user_header_t and cap_user_data_t
  on stack, rather than allocating them in heap. These structures
  are very small (a few integer fields), stack is a better place
  for them.
  (sys_capset): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
system.c

index 9176697d7b73454e7f2801e8638301bcb67ec6dc..e35c1175c3f80e47d723b851e3bb18de60d88665 100644 (file)
--- a/system.c
+++ b/system.c
@@ -1572,25 +1572,17 @@ static const struct xlat capabilities[] = {
 int
 sys_capget(struct tcb *tcp)
 {
-       static cap_user_header_t       arg0 = NULL;
-       static cap_user_data_t         arg1 = NULL;
+       /* cap_user_ types are _pointers_ to (small) structs. */
+       /* Structs themselves have no names defined. */
+       /* Have to use ugly hack to place them on stack. */
+       cap_user_header_t arg0;
+       cap_user_data_t   arg1;
+       long a0[sizeof(*arg0) / sizeof(long) + 1];
+       long a1[sizeof(*arg1) / sizeof(long) + 1];
+       arg0 = (cap_user_header_t*) &a0;
+       arg1 = (cap_user_data_t  *) &a1;
 
        if (!entering(tcp)) {
-               if (!arg0) {
-                       if ((arg0 = malloc(sizeof(*arg0))) == NULL) {
-                               fprintf(stderr, "out of memory\n");
-                               tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
-                               return -1;
-                       }
-               }
-               if (!arg1) {
-                       if ((arg1 = malloc(sizeof(*arg1))) == NULL) {
-                               fprintf(stderr, "out of memory\n");
-                               tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
-                               return -1;
-                       }
-               }
-
                if (!tcp->u_arg[0])
                        tprintf("NULL");
                else if (!verbose(tcp))
@@ -1623,25 +1615,14 @@ sys_capget(struct tcb *tcp)
 int
 sys_capset(struct tcb *tcp)
 {
-       static cap_user_header_t       arg0 = NULL;
-       static cap_user_data_t         arg1 = NULL;
+       cap_user_header_t arg0;
+       cap_user_data_t   arg1;
+       long a0[sizeof(*arg0) / sizeof(long) + 1];
+       long a1[sizeof(*arg1) / sizeof(long) + 1];
+       arg0 = (cap_user_header_t*) &a0;
+       arg1 = (cap_user_data_t  *) &a1;
 
        if (entering(tcp)) {
-               if (!arg0) {
-                       if ((arg0 = malloc(sizeof(*arg0))) == NULL) {
-                               fprintf(stderr, "out of memory\n");
-                               tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
-                               return -1;
-                       }
-               }
-               if (!arg1) {
-                       if ((arg1 = malloc(sizeof(*arg1))) == NULL) {
-                               fprintf(stderr, "out of memory\n");
-                               tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
-                               return -1;
-                       }
-               }
-
                if (!tcp->u_arg[0])
                        tprintf("NULL");
                else if (!verbose(tcp))