summaryrefslogtreecommitdiff
path: root/system.c
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-06-23 13:10:28 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2011-06-23 13:10:28 +0200
commitb0bafbb5d106d7dcaebbf76c97fc8e1daaa2e718 (patch)
tree720a20755c3c436374d04086af14b6d1cb2214eb /system.c
parentcb2ad00652e746b370703b5470932b7612308b9c (diff)
downloadstrace-b0bafbb5d106d7dcaebbf76c97fc8e1daaa2e718.tar.gz
strace-b0bafbb5d106d7dcaebbf76c97fc8e1daaa2e718.tar.bz2
strace-b0bafbb5d106d7dcaebbf76c97fc8e1daaa2e718.tar.xz
Do not allocate tiny cap_user_header/data structures, place them on stack.
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>
Diffstat (limited to 'system.c')
-rw-r--r--system.c49
1 files changed, 15 insertions, 34 deletions
diff --git a/system.c b/system.c
index 9176697..e35c117 100644
--- 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))