Skip to content

Commit

Permalink
Further trim the psx headers and support easy vendoring.
Browse files Browse the repository at this point in the history
Remove psx_pthread_create() from libpsx - given the way -lpsx is
linked this is not needed.

Also, as pointed out by Lorenz Bauer, "go mod vendor" support
was unable to vendor a copy of psx_syscall.h because it didn't
reside in the same directory as the *.go code for the psx package.
(General discussion golang/go#26366 .)
Given that we can, avoid the use of a sub-directory in the libcap
tree.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
  • Loading branch information
AndrewGMorgan committed Dec 9, 2020
1 parent 4b8f2b0 commit d03e78f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 34 deletions.
5 changes: 2 additions & 3 deletions go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ endif

install: all
rm -rf $(FAKEROOT)$(GOPKGDIR)/$(IMPORTDIR)/psx
mkdir -p $(FAKEROOT)$(GOPKGDIR)/$(IMPORTDIR)/psx/include/sys
for x in src/$(IMPORTDIR)/psx/* ; do if [ -d $$x ]; then continue; fi; install -m 0644 $$x $(FAKEROOT)$(GOPKGDIR)/$(IMPORTDIR)/psx; done
install -m 0644 src/$(IMPORTDIR)/psx/include/sys/psx_syscall.h $(FAKEROOT)$(GOPKGDIR)/$(IMPORTDIR)/psx/include/sys/psx_syscall.h
mkdir -p $(FAKEROOT)$(GOPKGDIR)/$(IMPORTDIR)/psx
install -m 0644 src/$(IMPORTDIR)/psx/* $(FAKEROOT)$(GOPKGDIR)/$(IMPORTDIR)/psx
mkdir -p $(FAKEROOT)$(GOPKGDIR)/$(IMPORTDIR)/cap
rm -rf $(FAKEROOT)$(GOPKGDIR)/$(IMPORTDIR)/cap/*
install -m 0644 src/$(IMPORTDIR)/cap/* $(FAKEROOT)$(GOPKGDIR)/$(IMPORTDIR)/cap
Expand Down
2 changes: 1 addition & 1 deletion libcap/include/sys/psx_syscall.h
1 change: 1 addition & 0 deletions libcap/psx_syscall.h
13 changes: 2 additions & 11 deletions psx/psx.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/psx_syscall.h>
#include <sys/syscall.h>

#include "psx_syscall.h"

/*
* psx_load_syscalls() is weakly defined so we can have it overridden
* by libpsx if it is linked. Specifically, when libcap calls
Expand Down Expand Up @@ -486,16 +487,6 @@ int __wrap_pthread_create(pthread_t *thread, const pthread_attr_t *attr,
return ret;
}

/*
* psx_pthread_create is a wrapper for pthread_create() that registers
* the newly created thread. If your threads are created already, they
* can be individually registered with psx_register().
*/
int psx_pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg) {
return __wrap_pthread_create(thread, attr, start_routine, arg);
}

/*
* __psx_immediate_syscall does one syscall using the current
* process.
Expand Down
3 changes: 1 addition & 2 deletions psx/psx.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ import (
"syscall"
)

// #cgo CFLAGS: -I${SRCDIR}/include
// #cgo LDFLAGS: -lpthread -Wl,-wrap,pthread_create
//
// #include <errno.h>
// #include <sys/psx_syscall.h>
// #include "psx_syscall.h"
//
// long __errno_too(long set_errno) {
// long v = errno;
Expand Down
17 changes: 0 additions & 17 deletions psx/include/sys/psx_syscall.h → psx/psx_syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ long int psx_syscall6(long int syscall_nr,
long int arg1, long int arg2, long int arg3,
long int arg4, long int arg5, long int arg6);

/*
* psx_pthread_create() wraps the -lpthread pthread_create() function
* call and registers the generated thread with the psx_syscall
* infrastructure.
*
* Note, to transparently redirect all the pthread_create() calls in
* your binary to psx_pthread_create(), link with:
*
* gcc ... -lpsx -lpthread -Wl,-wrap,pthread_create
*
* [That is, libpsx contains an internal definition for the
* __wrap_pthread_create function to invoke psx_pthread_create
* functionality instead.]
*/
int psx_pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);

/*
* This function should be used by systems to obtain pointers to the
* two syscall functions provided by the PSX library. A linkage trick
Expand Down

0 comments on commit d03e78f

Please sign in to comment.