Skip to content

Commit

Permalink
From patchwork series 435893
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox Snowpatch committed Dec 9, 2024
1 parent 1ecdccb commit 329b101
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 47 deletions.
8 changes: 8 additions & 0 deletions tools/testing/selftests/powerpc/include/pkeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@
#define __NR_pkey_alloc 384
#define __NR_pkey_free 385

#ifndef NT_PPC_PKEY
#define NT_PPC_PKEY 0x110
#endif

#define PKEY_BITS_PER_PKEY 2
#define NR_PKEYS 32
#define PKEY_BITS_MASK ((1UL << PKEY_BITS_PER_PKEY) - 1)

#define AMR_BITS_PER_PKEY 2
#define PKEY_REG_BITS (sizeof(u64) * 8)
#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey + 1) * AMR_BITS_PER_PKEY))

inline unsigned long pkeyreg_get(void)
{
return mfspr(SPRN_AMR);
Expand Down
27 changes: 1 addition & 26 deletions tools/testing/selftests/powerpc/ptrace/core-pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,12 @@
#include <unistd.h>
#include "ptrace.h"
#include "child.h"

#ifndef __NR_pkey_alloc
#define __NR_pkey_alloc 384
#endif

#ifndef __NR_pkey_free
#define __NR_pkey_free 385
#endif

#ifndef NT_PPC_PKEY
#define NT_PPC_PKEY 0x110
#endif
#include "pkeys.h"

#ifndef PKEY_DISABLE_EXECUTE
#define PKEY_DISABLE_EXECUTE 0x4
#endif

#define AMR_BITS_PER_PKEY 2
#define PKEY_REG_BITS (sizeof(u64) * 8)
#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey + 1) * AMR_BITS_PER_PKEY))

#define CORE_FILE_LIMIT (5 * 1024 * 1024) /* 5 MB should be enough */

static const char core_pattern_file[] = "/proc/sys/kernel/core_pattern";
Expand All @@ -61,16 +46,6 @@ struct shared_info {
time_t core_time;
};

static int sys_pkey_alloc(unsigned long flags, unsigned long init_access_rights)
{
return syscall(__NR_pkey_alloc, flags, init_access_rights);
}

static int sys_pkey_free(int pkey)
{
return syscall(__NR_pkey_free, pkey);
}

static int increase_core_file_limit(void)
{
struct rlimit rlim;
Expand Down
22 changes: 1 addition & 21 deletions tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,12 @@
*/
#include "ptrace.h"
#include "child.h"

#ifndef __NR_pkey_alloc
#define __NR_pkey_alloc 384
#endif

#ifndef __NR_pkey_free
#define __NR_pkey_free 385
#endif

#ifndef NT_PPC_PKEY
#define NT_PPC_PKEY 0x110
#endif
#include "pkeys.h"

#ifndef PKEY_DISABLE_EXECUTE
#define PKEY_DISABLE_EXECUTE 0x4
#endif

#define AMR_BITS_PER_PKEY 2
#define PKEY_REG_BITS (sizeof(u64) * 8)
#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey + 1) * AMR_BITS_PER_PKEY))

static const char user_read[] = "[User Read (Running)]";
static const char user_write[] = "[User Write (Running)]";
static const char ptrace_read_running[] = "[Ptrace Read (Running)]";
Expand Down Expand Up @@ -61,11 +46,6 @@ struct shared_info {
unsigned long invalid_uamor;
};

static int sys_pkey_alloc(unsigned long flags, unsigned long init_access_rights)
{
return syscall(__NR_pkey_alloc, flags, init_access_rights);
}

static int child(struct shared_info *info)
{
unsigned long reg;
Expand Down

0 comments on commit 329b101

Please sign in to comment.