Browse Source

fl_wrapper: added script to generate a header that escapes the syscalls we are overriding

user/amery/test/random-cleanup
Alejandro Mery 14 years ago
committed by Alejandro Mery
parent
commit
d02b5d6e19
4 changed files with 99 additions and 44 deletions
  1. +1
    -0
      src/tools-source/fl_wrapper/.gitignore
  2. +10
    -5
      src/tools-source/fl_wrapper/Makefile
  3. +1
    -39
      src/tools-source/fl_wrapper/fl_wrapper.c
  4. +87
    -0
      src/tools-source/fl_wrapper/fl_wrapper.h.sh

+ 1
- 0
src/tools-source/fl_wrapper/.gitignore

@ -1,3 +1,4 @@
fl_wrapper.so
fl_wrapper_generated.c
fl_wrapper.h
*.o

+ 10
- 5
src/tools-source/fl_wrapper/Makefile

@ -2,7 +2,7 @@
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: src/tools-source/fl_wrapper/Makefile
# Copyright (C) 2009 The OpenSDE Project
# Copyright (C) 2009 - 2010 The OpenSDE Project
#
# More information can be found in the files COPYING and README.
#
@ -27,17 +27,22 @@ endif
LIB=fl_wrapper.so
GENERATED=fl_wrapper_generated.c
HEADER=fl_wrapper.h
SRCS=fl_wrapper.c fl_wrapper_execl.c $(GENERATED)
.PHONY: clean
$(LIB): $(SRCS)
$(LIB): $(SRCS) $(HEADER)
$(CC) $(CFLAGS) -o "$@.tmp" $<
mv "$@.tmp" "$@"
clean:
@rm -vf $(LIB) $(GENERATED) $(GENERATED).tmp
@rm -vf $(LIB) *.o *.tmp $(GENERATED) $(HEADER)
$(GENERATED): $(GENERATED).sh $(wildcard tpl_*.c)
$(SHELL) $< > $(GENERATED).tmp
mv $(GENERATED).tmp $(GENERATED)
$(HEADER): $(HEADER).sh $(GENERATED).sh
$(GENERATED) $(HEADER):
$(SHELL) $< > $@.tmp
mv $@.tmp $@

+ 1
- 39
src/tools-source/fl_wrapper/fl_wrapper.c

@ -34,45 +34,7 @@
# define FLWRAPPER_LIBC "libc.so.6"
#endif
#define _GNU_SOURCE
#define _REENTRANT
#define open xxx_open
#define open64 xxx_open64
#define mknod xxx_mknod
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <utime.h>
#include <stdarg.h>
#include <limits.h>
/* somehow it can happen that PATH_MAX does not get defined...? -- jsaw */
#ifndef PATH_MAX
#include <linux/limits.h>
#endif
#ifndef PATH_MAX
#warning "PATH_MAX was not defined - BUG in your system headers?"
#define PATH_MAX 4095
#endif
#include <libgen.h>
#undef _LARGEFILE64_SOURCE
#undef _LARGEFILE_SOURCE
#undef mknod
#undef open
#undef open64
#include "fl_wrapper.h"
static void * get_dl_symbol(char *);

+ 87
- 0
src/tools-source/fl_wrapper/fl_wrapper.h.sh

@ -0,0 +1,87 @@
#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: src/tools-source/fl_wrapper/fl_wrapper.h.sh
# Copyright (C) 2010 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---
#
# This shell-script genereates the fl_wrapper.h header file.
cat <<EOT
/*
* !!! THIS FILE IS AUTO-GENERATED BY $0 !!!
*/
EOT
DEF="_GNU_SOURCE _REENTRANT _LARGEFILE_SOURCE _LARGEFILE64_SOURCE"
UNDEF=
ESCAPE=
UNESCAPE=
add_wrapper() {
ESCAPE="$ESCAPE $2"
UNESCAPE="$2 $UNESCAPE"
}
eval "$(grep '^add_wrapper ' fl_wrapper_generated.c.sh)"
# defines
for x in $DEF; do
echo "#define $x"
done
# blank line
echo
# and rename the functions we override
for x in $ESCAPE; do
echo "#define $x xxx_$x"
done
cat <<EOT
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <utime.h>
#include <stdarg.h>
#include <limits.h>
/* somehow it can happen that PATH_MAX does not get defined...? -- jsaw */
#ifndef PATH_MAX
#include <linux/limits.h>
#endif
#ifndef PATH_MAX
#warning "PATH_MAX was not defined - BUG in your system headers?"
#define PATH_MAX 4095
#endif
#include <libgen.h>
EOT
# and undefine the stuff we defined above
for x in $UNESCAPE '|' $UNDEF; do
if [ "$x" = "|" ]; then
echo # blank line
else
echo "#undef $x"
fi
done

Loading…
Cancel
Save