mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-08 20:05:54 +00:00
libports: add 'compat-libc'
Implement FBSD_1.0 versions of libc functions ('stat', 'fstat'). The functions are versioned with @FBSD_1.0, and therefore, will not clash with libc during linking. However, to be called by our dynamic linker, the library must be before libc in the NEEDED section of the binary using it. This requires the lib to be in front of libc in the LIBS variable. The library currently will call libc 'stat' and 'fstat' by looking up the symbols via 'dlsym'. Ref genodelabs/goa#61
This commit is contained in:
parent
da53a11508
commit
0a85964f91
15
repos/libports/lib/mk/compat-libc.mk
Normal file
15
repos/libports/lib/mk/compat-libc.mk
Normal file
@ -0,0 +1,15 @@
|
||||
SHARED_LIB = yes
|
||||
LIBS += libc
|
||||
COMPAT_DIR = $(REP_DIR)/src/lib/compat-libc
|
||||
|
||||
SRC_CC = compat.cc
|
||||
SRC_C = libc.c
|
||||
|
||||
vpath %.cc $(COMPAT_DIR)
|
||||
vpath %.c $(COMPAT_DIR)
|
||||
|
||||
LD_OPT += --version-script=$(COMPAT_DIR)/symbol.map
|
||||
|
||||
CC_CXX_WARN_STRICT_CONVERSION =
|
||||
|
||||
# vi: set ft=make :
|
2
repos/libports/lib/symbols/compat-libc
Normal file
2
repos/libports/lib/symbols/compat-libc
Normal file
@ -0,0 +1,2 @@
|
||||
fstat T
|
||||
stat T
|
16
repos/libports/recipes/api/compat-libc/content.mk
Normal file
16
repos/libports/recipes/api/compat-libc/content.mk
Normal file
@ -0,0 +1,16 @@
|
||||
MIRROR_FROM_REP_DIR := lib/symbols/compat-libc
|
||||
|
||||
content: $(MIRROR_FROM_REP_DIR) LICENSE
|
||||
|
||||
$(MIRROR_FROM_REP_DIR):
|
||||
$(mirror_from_rep_dir)
|
||||
|
||||
content: lib/symbol.map
|
||||
|
||||
lib/symbol.map:
|
||||
cp $(REP_DIR)/src/lib/compat-libc/symbol.map $@
|
||||
|
||||
|
||||
LICENSE:
|
||||
cp $(GENODE_DIR)/LICENSE $@
|
||||
|
1
repos/libports/recipes/api/compat-libc/hash
Normal file
1
repos/libports/recipes/api/compat-libc/hash
Normal file
@ -0,0 +1 @@
|
||||
2023-06-12 1ce2539b566b8d0d1a1f9919b8c7543f32467679
|
1
repos/libports/recipes/src/compat-libc/api
Normal file
1
repos/libports/recipes/src/compat-libc/api
Normal file
@ -0,0 +1 @@
|
||||
compat-libc
|
10
repos/libports/recipes/src/compat-libc/content.mk
Normal file
10
repos/libports/recipes/src/compat-libc/content.mk
Normal file
@ -0,0 +1,10 @@
|
||||
MIRROR_FROM_REP_DIR := lib/mk/compat-libc.mk src/lib/compat-libc
|
||||
|
||||
content: $(MIRROR_FROM_REP_DIR) LICENSE
|
||||
|
||||
$(MIRROR_FROM_REP_DIR):
|
||||
$(mirror_from_rep_dir)
|
||||
|
||||
LICENSE:
|
||||
cp $(GENODE_DIR)/LICENSE $@
|
||||
|
1
repos/libports/recipes/src/compat-libc/hash
Normal file
1
repos/libports/recipes/src/compat-libc/hash
Normal file
@ -0,0 +1 @@
|
||||
2023-06-12-a b499380d630694fbe520d666320b5bba333fce25
|
2
repos/libports/recipes/src/compat-libc/used_apis
Normal file
2
repos/libports/recipes/src/compat-libc/used_apis
Normal file
@ -0,0 +1,2 @@
|
||||
libc
|
||||
so
|
1
repos/libports/src/lib/compat-libc/README
Normal file
1
repos/libports/src/lib/compat-libc/README
Normal file
@ -0,0 +1 @@
|
||||
This library contains FBSD_1.0 symbol versions not enabled in our libc port.
|
63
repos/libports/src/lib/compat-libc/compat.cc
Normal file
63
repos/libports/src/lib/compat-libc/compat.cc
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* \brief FreeBSD-11 function versions
|
||||
* \author Sebastian Sumpf
|
||||
* \date 2023-06-12
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#define _WANT_FREEBSD11_STAT /* enable freebsd11_stat */
|
||||
#define _KERNEL /* disable 'stat' */
|
||||
#include <sys/stat.h>
|
||||
#include "libc.h"
|
||||
|
||||
|
||||
static void _to_freebsd11(struct stat *libc_buf, struct freebsd11_stat *buf)
|
||||
{
|
||||
buf->st_dev = libc_buf->st_dev;
|
||||
buf->st_ino = libc_buf->st_ino;
|
||||
buf->st_mode = libc_buf->st_mode;
|
||||
buf->st_nlink = libc_buf->st_nlink;
|
||||
buf->st_uid = libc_buf->st_uid;
|
||||
buf->st_gid = libc_buf->st_gid;
|
||||
buf->st_atim = libc_buf->st_atim;
|
||||
buf->st_mtim = libc_buf->st_mtim;
|
||||
buf->st_ctim = libc_buf->st_ctim;
|
||||
buf->st_size = libc_buf->st_size;
|
||||
buf->st_blksize = libc_buf->st_blksize;
|
||||
buf->st_flags = libc_buf->st_flags;
|
||||
buf->st_gen = libc_buf->st_gen;
|
||||
buf->st_birthtim = libc_buf->st_birthtim;
|
||||
}
|
||||
|
||||
|
||||
extern "C" int stat(const char *path, struct freebsd11_stat *buf)
|
||||
{
|
||||
struct stat libc_buf { };
|
||||
|
||||
int err = libc_stat(path, &libc_buf);
|
||||
if (err) return err;
|
||||
|
||||
_to_freebsd11(&libc_buf, buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern "C" int fstat(int fd, struct freebsd11_stat *buf)
|
||||
{
|
||||
struct stat libc_buf { };
|
||||
|
||||
int err = libc_fstat(fd, &libc_buf);
|
||||
if (err) return err;
|
||||
|
||||
_to_freebsd11(&libc_buf, buf);
|
||||
|
||||
return 0;
|
||||
}
|
43
repos/libports/src/lib/compat-libc/libc.c
Normal file
43
repos/libports/src/lib/compat-libc/libc.c
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* \brief Interface real libc
|
||||
* \author Sebastian Sumpf
|
||||
* \date 2023-06-12
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
static void* libc_handle(void)
|
||||
{
|
||||
static void *handle = NULL;
|
||||
if (!handle) handle = dlopen("libc.lib.so", RTLD_LAZY);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
int (*_stat)(char const*, struct stat*);
|
||||
int (*_fstat)(int, struct stat *);
|
||||
|
||||
int libc_stat(const char *path, struct stat *buf)
|
||||
{
|
||||
if (!_stat)
|
||||
_stat = dlsym(libc_handle(), "stat");
|
||||
|
||||
return _stat(path, buf);
|
||||
}
|
||||
|
||||
|
||||
int libc_fstat(int fd, struct stat *buf)
|
||||
{
|
||||
if (!_fstat)
|
||||
_fstat = dlsym(libc_handle(), "fstat");
|
||||
|
||||
return _fstat(fd, buf);
|
||||
}
|
20
repos/libports/src/lib/compat-libc/libc.h
Normal file
20
repos/libports/src/lib/compat-libc/libc.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* \brief Interface real libc
|
||||
* \author Sebastian Sumpf
|
||||
* \date 2023-06-12
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_LIBC_H_
|
||||
#define _COMPAT_LIBC_H_
|
||||
|
||||
extern "C" int libc_stat(const char *, struct stat*);
|
||||
extern "C" int libc_fstat(int, struct stat *);
|
||||
|
||||
#endif /* _COMPAT_LIBC_H_ */
|
8
repos/libports/src/lib/compat-libc/symbol.map
Normal file
8
repos/libports/src/lib/compat-libc/symbol.map
Normal file
@ -0,0 +1,8 @@
|
||||
# compatible old version implemeted in this library
|
||||
FBSD_1.0 {
|
||||
global:
|
||||
stat;
|
||||
fstat;
|
||||
local:
|
||||
*;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user