Skip to content
Permalink
Browse files

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpa…

…ths.

Improvements and okay matthew@, millert@, guenther@
  • Loading branch information
bsdkurt committed Apr 5, 2013
1 parent 593ef08 commit 337bd349eb33d0246bac63f39f4679daba26f895
@@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.42 2013/03/20 21:49:59 kurt Exp $
# $OpenBSD: Makefile,v 1.43 2013/04/05 12:58:03 kurt Exp $

SUBDIR=ldconfig ldd
MAN= ld.so.1
@@ -16,6 +16,7 @@ VPATH=${.CURDIR}/../../lib/libc/string

SRCS= ldasm.S loader.c resolve.c dlfcn.c dl_printf.c rtld_machine.c path.c
SRCS+= util.c sod.c strsep.c strtol.c dir.c library_subr.c dl_prebind.c
SRCS+= dl_realpath.c dl_uname.c dl_dirname.c strlcat.c strlen.c
.if (${MACHINE_ARCH} == "i386")
SRCS+= library_mquery.c
.else
@@ -29,7 +30,7 @@ SRCS+= library.c
DEBUG?= -g
CFLAGS += -Wall -Werror
CFLAGS += -I${.CURDIR} -I${.CURDIR}/${MACHINE_CPU} \
-Dstrsep=_dl_strsep
-Dstrsep=_dl_strsep -Dstrlcat=_dl_strlcat -Dstrlen=_dl_strlen
CDIAGFLAGS=
INSTALL_STRIP=

@@ -1,4 +1,4 @@
/* $OpenBSD: ldasm.S,v 1.18 2012/10/24 03:26:55 guenther Exp $ */
/* $OpenBSD: ldasm.S,v 1.19 2013/04/05 12:58:03 kurt Exp $ */

/*
* Copyright (c) 2001 Niklas Hallqvist
@@ -307,3 +307,21 @@ LEAF_NOPROFILE(_dl_gettimeofday, 2)
RET
END(_dl_gettimeofday)

LEAF_NOPROFILE(_dl_readlink, 3)
ldiq v0, SYS_readlink
call_pal PAL_OSF1_callsys
RET
END(_dl_readlink)

LEAF_NOPROFILE(_dl_lstat, 2)
ldiq v0, SYS_lstat
call_pal PAL_OSF1_callsys
RET
END(_dl_lstat)

LEAF_NOPROFILE(_dl_getcwd, 2)
ldiq v0, SYS___getcwd
call_pal PAL_OSF1_callsys
RET
END(_dl_getcwd)

@@ -1,4 +1,4 @@
/* $OpenBSD: syscall.h,v 1.18 2012/10/24 03:26:55 guenther Exp $ */
/* $OpenBSD: syscall.h,v 1.19 2013/04/05 12:58:03 kurt Exp $ */

/*
* Copyright (c) 2001 Niklas Hallqvist
@@ -53,6 +53,9 @@ long _dl__syscall(quad_t, ...);
int _dl_sigprocmask(int, const sigset_t *, sigset_t *);
int _dl_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int _dl_gettimeofday(struct timeval *tp, struct timezone *tzp);
int _dl_readlink(const char *path, char *buf, size_t bufsiz);
int _dl_lstat(const char *path, struct stat *sb);
int _dl_getcwd(char *buf, size_t size);

static inline off_t
_dl_lseek(int fildes, off_t offset, int whence)
@@ -1,4 +1,4 @@
/* $OpenBSD: ldasm.S,v 1.10 2012/10/24 03:26:56 guenther Exp $ */
/* $OpenBSD: ldasm.S,v 1.11 2013/04/05 12:58:03 kurt Exp $ */

/*
* Copyright (c) 2002,2004 Dale Rahn
@@ -95,6 +95,9 @@ DL_SYSCALL(mprotect)
DL_SYSCALL(munmap)
DL_SYSCALL(gettimeofday)
DL_SYSCALL(exit)
DL_SYSCALL(readlink)
DL_SYSCALL(lstat)
DL_SYSCALL2(getcwd,__getcwd)
DL_SYSCALL2(_syscall,__syscall)
DL_SYSCALL2(sysctl,__sysctl)

@@ -1,4 +1,4 @@
/* $OpenBSD: syscall.h,v 1.6 2012/10/24 03:26:56 guenther Exp $ */
/* $OpenBSD: syscall.h,v 1.7 2013/04/05 12:58:03 kurt Exp $ */

/*
* Copyright (c) 2001 Niklas Hallqvist
@@ -53,6 +53,9 @@ int _dl_getdirentries(int, char*, int, off_t *);
int _dl_sigprocmask(int, const sigset_t *, sigset_t *);
int _dl_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int _dl_gettimeofday(struct timeval *tp, struct timezone *tzp);
int _dl_readlink(const char *path, char *buf, size_t bufsiz);
int _dl_lstat(const char *path, struct stat *sb);
int _dl_getcwd(char *buf, size_t size);

static inline off_t
_dl_lseek(int fildes, off_t offset, int whence)
@@ -1,4 +1,4 @@
/* $OpenBSD: ldasm.S,v 1.8 2012/12/22 11:46:16 kettenis Exp $ */
/* $OpenBSD: ldasm.S,v 1.9 2013/04/05 12:58:03 kurt Exp $ */

/*
* Copyright (c) 2004 Dale Rahn
@@ -114,6 +114,9 @@ DL_SYSCALL(write)
DL_SYSCALL(fstat)
DL_SYSCALL(fcntl)
DL_SYSCALL(gettimeofday)
DL_SYSCALL(readlink)
DL_SYSCALL(lstat)
DL_SYSCALL2(getcwd,__getcwd)
DL_SYSCALL2(sysctl,__sysctl)

DL_SYSCALL(getdirentries)
@@ -1,4 +1,4 @@
/* $OpenBSD: syscall.h,v 1.6 2012/10/24 03:26:56 guenther Exp $ */
/* $OpenBSD: syscall.h,v 1.7 2013/04/05 12:58:03 kurt Exp $ */

/*
* Copyright (c) 2001 Niklas Hallqvist
@@ -53,6 +53,9 @@ int _dl_getdirentries(int, char*, int, off_t *);
int _dl_sigprocmask(int, const sigset_t *, sigset_t *);
int _dl_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int _dl_gettimeofday(struct timeval *tp, struct timezone *tzp);
int _dl_readlink(const char *path, char *buf, size_t bufsiz);
int _dl_lstat(const char *path, struct stat *sb);
int _dl_getcwd(char *buf, size_t size);

static inline off_t
_dl_lseek(int fildes, off_t offset, int whence)
@@ -0,0 +1,70 @@
/* $OpenBSD: dl_dirname.c,v 1.1 2013/04/05 12:58:03 kurt Exp $ */

/*
* Copyright (c) 1997, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <sys/param.h>

#include "archdep.h"

/*
* This file was copied from libc/stdlib/realpath.c and modified for ld.so's
* syscall method which returns -errno.
*/

char *
_dl_dirname(const char *path)
{
static char dname[MAXPATHLEN];
size_t len;
const char *endp;

/* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') {
dname[0] = '.';
dname[1] = '\0';
return (dname);
}

/* Strip any trailing slashes */
endp = path + strlen(path) - 1;
while (endp > path && *endp == '/')
endp--;

/* Find the start of the dir */
while (endp > path && *endp != '/')
endp--;

/* Either the dir is "/" or there are no slashes */
if (endp == path) {
dname[0] = *endp == '/' ? '/' : '.';
dname[1] = '\0';
return (dname);
} else {
/* Move forward past the separating slashes */
do {
endp--;
} while (endp > path && *endp == '/');
}

len = endp - path + 1;
if (len >= sizeof(dname)) {
return (NULL);
}
_dl_bcopy(path, dname, len);
dname[len] = '\0';
return (dname);
}

0 comments on commit 337bd34

Please sign in to comment.
You can’t perform that action at this time.