2
Copyright (C) 2011 Modestas Vainius <modax@debian.org>
4
This file is part of DLRestrictions.
6
This program is free software: you can redistribute it and/or modify it
7
under the terms of the GNU Lesser General Public License as published by
8
the Free Software Foundation, either version 2.1 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#ifndef _LIBRUNTIMERESTRICTIONS_H_
21
#define _LIBRUNTIMERESTRICTIONS_H_
23
#include <sys/types.h>
25
#ifndef DLR_LIBRARY_NAME
26
#define DLR_LIBRARY_NAME "DLRestrictions"
29
#define DLR_STRINGIFY(s) #s
30
#define DLR_STRINGIFY2(s) DLR_STRINGIFY(s)
32
#define DLR_SYMBOL dlrestrictions_data
33
#define DLR_SYMBOL_NAME DLR_STRINGIFY2(DLR_SYMBOL)
34
#define DLR_SYMBOL_MAGIC "DLR_SYMBOL_V1:"
35
#define MAX_DLR_EXPRESSION_LENGTH 4096
38
char magic[sizeof(DLR_SYMBOL_MAGIC)];
39
unsigned int expression_length;
40
const char *expression;
43
/* FIXME: proper visibility stuff */
44
#define DLR_EXPORT_SYMBOL(expression) \
45
__attribute__((visibility("default"))) \
46
const dlr_symbol_t DLR_SYMBOL = { \
48
(unsigned int) sizeof(expression), \
52
/* Get or set the name of the DLRestrictions symbol */
53
void dlr_set_symbol_name(const char *name);
54
const char* dlr_get_symbol_name(void);
57
const char* dlr_error(void);
58
int dlr_snprintf_pretty_error(char *str, size_t n, const char *context);
59
void dlr_print_pretty_error(const char *context);
61
/* Library compatibility checking functions */
64
Public function for verification of the given library file against global
67
* file - if present, the file to dlopen(); if omitted, the handle parameter
69
* handle - if not NULL, the handle of the dlopen()'ed file will be stored here
70
(and the object won't be dlclose()'ed). If file is NULL, handle must
71
be non-NULL and point to the already open shared object.
73
< 0 - error occured while checking compatibility:
74
* -ENOENT - unable to open file;
75
* -ENOTDIR - unable to dlopen() global symbol object;
76
* -EPROTO - syntax or other fatal error while checking compatibility;
77
== 0 - library and its dependencies are NOT compatible with global object;
78
> 0 - library and its dependencies are compatible with global object;
80
int dlr_check_file_compatibility(const char *file, void **handle);
83
An extended wrapper around dlopen() with integrated file compatibility checking.
85
* file - same as to dlopen();
86
* mode - same as to dlopen();
87
* printerror - if enabled, a pretty DLRestrctions error will be printed to stderr
88
when one occurs or if the file is NOT compatible.
89
* fail_on_error - if enabled, NULL will be returned if DLRestrictions specific
90
error occurs. Please note that successful compatibility checking regardless
91
of the outcome is NOT an error.
92
* Return value - a valid dlopen() handle if successful, NULL otherwise.
94
void* dlr_dlopen_extended(const char *file, int mode, int print_error, int fail_on_error);