Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
ffb42246
Commit
ffb42246
authored
Nov 03, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use reserved symbols
parent
89fff483
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
95 deletions
+68
-95
hacks.h
native/jni/systemproperties/include/private/hacks.h
+2
-2
missing.cpp
native/jni/utils/missing.cpp
+33
-63
missing.hpp
native/jni/utils/missing.hpp
+33
-30
No files found.
native/jni/systemproperties/include/private/hacks.h
View file @
ffb42246
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
// Missing functions
// Missing functions
#define fsetxattr(...) syscall(__NR_fsetxattr, __VA_ARGS__)
#define fsetxattr(...) syscall(__NR_fsetxattr, __VA_ARGS__)
#define getline
_
_getline
#define getline
compat
_getline
ssize_t
_
_getline
(
char
**
,
size_t
*
,
FILE
*
);
ssize_t
compat
_getline
(
char
**
,
size_t
*
,
FILE
*
);
// Rename symbols
// Rename symbols
#pragma redefine_extname __system_property_set _system_property_set2
#pragma redefine_extname __system_property_set _system_property_set2
...
...
native/jni/utils/missing.cpp
View file @
ffb42246
...
@@ -10,83 +10,53 @@
...
@@ -10,83 +10,53 @@
#include "missing.hpp"
#include "missing.hpp"
/* Original source: https://opensource.apple.com/source/cvs/cvs-19/cvs/lib/getline.c
/* Original source: https://github.com/freebsd/freebsd/blob/master/contrib/file/src/getline.c
* License: GPL 2 or later
* License: BSD, full copyright notice please check original source */
* Adjusted to match POSIX */
#define MIN_CHUNK 64
ssize_t
__getdelim
(
char
**
lineptr
,
size_t
*
n
,
int
delim
,
FILE
*
stream
)
{
size_t
nchars_avail
;
char
*
read_pos
;
if
(
!
lineptr
||
!
n
||
!
stream
)
{
ssize_t
compat_getdelim
(
char
**
buf
,
size_t
*
bufsiz
,
int
delimiter
,
FILE
*
fp
)
{
errno
=
EINVAL
;
char
*
ptr
,
*
eptr
;
return
-
1
;
}
if
(
!*
lineptr
)
{
if
(
*
buf
==
nullptr
||
*
bufsiz
==
0
)
{
*
n
=
MIN_CHUNK
;
*
bufsiz
=
BUFSIZ
;
*
lineptr
=
(
char
*
)
malloc
(
*
n
);
if
((
*
buf
=
(
char
*
)
malloc
(
*
bufsiz
))
==
nullptr
)
if
(
!*
lineptr
)
{
errno
=
ENOMEM
;
return
-
1
;
return
-
1
;
}
}
}
nchars_avail
=
*
n
;
for
(
ptr
=
*
buf
,
eptr
=
*
buf
+
*
bufsiz
;;)
{
read_pos
=
*
lineptr
;
int
c
=
fgetc
(
fp
);
if
(
c
==
-
1
)
{
for
(;;)
{
if
(
feof
(
fp
))
int
save_errno
;
return
ptr
==
*
buf
?
-
1
:
ptr
-
*
buf
;
int
c
=
getc
(
stream
);
save_errno
=
errno
;
if
(
nchars_avail
<
2
)
{
if
(
*
n
>
MIN_CHUNK
)
*
n
*=
2
;
else
else
*
n
+=
MIN_CHUNK
;
nchars_avail
=
*
n
+
*
lineptr
-
read_pos
;
*
lineptr
=
(
char
*
)
realloc
(
*
lineptr
,
*
n
);
if
(
!*
lineptr
)
{
errno
=
ENOMEM
;
return
-
1
;
return
-
1
;
}
read_pos
=
*
n
-
nchars_avail
+
*
lineptr
;
}
}
*
ptr
++
=
c
;
if
(
ferror
(
stream
)
)
{
if
(
c
==
delimiter
)
{
errno
=
save_errno
;
*
ptr
=
'\0'
;
return
-
1
;
return
ptr
-
*
buf
;
}
}
if
(
ptr
+
2
>=
eptr
)
{
if
(
c
==
EOF
)
{
char
*
nbuf
;
if
(
read_pos
==
*
lineptr
)
size_t
nbufsiz
=
*
bufsiz
*
2
;
ssize_t
d
=
ptr
-
*
buf
;
if
((
nbuf
=
(
char
*
)
realloc
(
*
buf
,
nbufsiz
))
==
nullptr
)
return
-
1
;
return
-
1
;
else
*
buf
=
nbuf
;
break
;
*
bufsiz
=
nbufsiz
;
eptr
=
nbuf
+
nbufsiz
;
ptr
=
nbuf
+
d
;
}
}
*
read_pos
++
=
c
;
nchars_avail
--
;
if
(
c
==
delim
)
break
;
}
}
*
read_pos
=
'\0'
;
return
read_pos
-
*
lineptr
;
}
}
ssize_t
__getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
)
{
ssize_t
compat_getline
(
char
**
buf
,
size_t
*
bufsiz
,
FILE
*
fp
)
{
return
getdelim
(
lineptr
,
n
,
'\n'
,
stream
);
return
getdelim
(
buf
,
bufsiz
,
'\n'
,
fp
);
}
}
/* mntent functions are copied from AOSP libc/bionic/mntent.cpp */
/* Original source: https://android.googlesource.com/platform/bionic/+/master/libc/bionic/mntent.cpp
* License: AOSP, full copyright notice please check original source */
struct
mntent
*
_
_getmntent_r
(
FILE
*
fp
,
struct
mntent
*
e
,
char
*
buf
,
int
buf_len
)
{
struct
mntent
*
compat
_getmntent_r
(
FILE
*
fp
,
struct
mntent
*
e
,
char
*
buf
,
int
buf_len
)
{
memset
(
e
,
0
,
sizeof
(
*
e
));
memset
(
e
,
0
,
sizeof
(
*
e
));
while
(
fgets
(
buf
,
buf_len
,
fp
)
!=
nullptr
)
{
while
(
fgets
(
buf
,
buf_len
,
fp
)
!=
nullptr
)
{
// Entries look like "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0".
// Entries look like "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0".
...
@@ -109,18 +79,18 @@ struct mntent *__getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf_len)
...
@@ -109,18 +79,18 @@ struct mntent *__getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf_len)
return
nullptr
;
return
nullptr
;
}
}
FILE
*
_
_setmntent
(
const
char
*
path
,
const
char
*
mode
)
{
FILE
*
compat
_setmntent
(
const
char
*
path
,
const
char
*
mode
)
{
return
fopen
(
path
,
mode
);
return
fopen
(
path
,
mode
);
}
}
int
_
_endmntent
(
FILE
*
fp
)
{
int
compat
_endmntent
(
FILE
*
fp
)
{
if
(
fp
!=
nullptr
)
{
if
(
fp
!=
nullptr
)
{
fclose
(
fp
);
fclose
(
fp
);
}
}
return
1
;
return
1
;
}
}
char
*
_
_hasmntopt
(
const
struct
mntent
*
mnt
,
const
char
*
opt
)
{
char
*
compat
_hasmntopt
(
const
struct
mntent
*
mnt
,
const
char
*
opt
)
{
char
*
token
=
mnt
->
mnt_opts
;
char
*
token
=
mnt
->
mnt_opts
;
char
*
const
end
=
mnt
->
mnt_opts
+
strlen
(
mnt
->
mnt_opts
);
char
*
const
end
=
mnt
->
mnt_opts
+
strlen
(
mnt
->
mnt_opts
);
const
size_t
optLen
=
strlen
(
opt
);
const
size_t
optLen
=
strlen
(
opt
);
...
...
native/jni/utils/missing.hpp
View file @
ffb42246
...
@@ -4,62 +4,65 @@
...
@@ -4,62 +4,65 @@
#include <unistd.h>
#include <unistd.h>
#include <mntent.h>
#include <mntent.h>
#define getline __getline
// Missing libc functions
#define getdelim __getdelim
#define getline compat_getline
#define setns __setns
#define getdelim compat_getdelim
#define unshare __unshare
#define getmntent_r compat_getmntent_r
#define accept4 __accept4
#define setmntent compat_setmntent
#define dup3 __dup3
#define endmntent compat_endmntent
#define readlinkat __readlinkat
#define hasmntopt compat_hasmntopt
#define symlinkat __symlinkat
#define linkat __linkat
#define inotify_init1 __inotify_init1
#define getmntent_r __getmntent_r
#define setmntent __setmntent
#define endmntent __endmntent
#define hasmntopt __hasmntopt
#define faccessat __faccessat
ssize_t
__getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
);
// Missing syscall wrappers
ssize_t
__getdelim
(
char
**
lineptr
,
size_t
*
n
,
int
delim
,
FILE
*
stream
);
#define setns compat_setns
struct
mntent
*
__getmntent_r
(
FILE
*
fp
,
struct
mntent
*
e
,
char
*
buf
,
int
buf_len
);
#define unshare compat_unshare
FILE
*
__setmntent
(
const
char
*
path
,
const
char
*
mode
);
#define accept4 compat_accept4
int
__endmntent
(
FILE
*
fp
);
#define dup3 compat_dup3
char
*
__hasmntopt
(
const
struct
mntent
*
mnt
,
const
char
*
opt
);
#define readlinkat compat_readlinkat
#define symlinkat compat_symlinkat
#define linkat compat_linkat
#define inotify_init1 compat_inotify_init1
#define faccessat compat_faccessat
static
inline
int
__setns
(
int
fd
,
int
nstype
)
{
ssize_t
compat_getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
);
ssize_t
compat_getdelim
(
char
**
lineptr
,
size_t
*
n
,
int
delim
,
FILE
*
stream
);
struct
mntent
*
compat_getmntent_r
(
FILE
*
fp
,
struct
mntent
*
e
,
char
*
buf
,
int
buf_len
);
FILE
*
compat_setmntent
(
const
char
*
path
,
const
char
*
mode
);
int
compat_endmntent
(
FILE
*
fp
);
char
*
compat_hasmntopt
(
const
struct
mntent
*
mnt
,
const
char
*
opt
);
static
inline
int
compat_setns
(
int
fd
,
int
nstype
)
{
return
syscall
(
__NR_setns
,
fd
,
nstype
);
return
syscall
(
__NR_setns
,
fd
,
nstype
);
}
}
static
inline
int
_
_unshare
(
int
flags
)
{
static
inline
int
compat
_unshare
(
int
flags
)
{
return
syscall
(
__NR_unshare
,
flags
);
return
syscall
(
__NR_unshare
,
flags
);
}
}
static
inline
int
_
_accept4
(
int
sockfd
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
,
int
flags
)
{
static
inline
int
compat
_accept4
(
int
sockfd
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
,
int
flags
)
{
return
syscall
(
__NR_accept4
,
sockfd
,
addr
,
addrlen
,
flags
);
return
syscall
(
__NR_accept4
,
sockfd
,
addr
,
addrlen
,
flags
);
}
}
static
inline
int
_
_dup3
(
int
oldfd
,
int
newfd
,
int
flags
)
{
static
inline
int
compat
_dup3
(
int
oldfd
,
int
newfd
,
int
flags
)
{
return
syscall
(
__NR_dup3
,
oldfd
,
newfd
,
flags
);
return
syscall
(
__NR_dup3
,
oldfd
,
newfd
,
flags
);
}
}
static
inline
ssize_t
_
_readlinkat
(
int
dirfd
,
const
char
*
pathname
,
char
*
buf
,
size_t
bufsiz
)
{
static
inline
ssize_t
compat
_readlinkat
(
int
dirfd
,
const
char
*
pathname
,
char
*
buf
,
size_t
bufsiz
)
{
return
syscall
(
__NR_readlinkat
,
dirfd
,
pathname
,
buf
,
bufsiz
);
return
syscall
(
__NR_readlinkat
,
dirfd
,
pathname
,
buf
,
bufsiz
);
}
}
static
inline
int
_
_symlinkat
(
const
char
*
target
,
int
newdirfd
,
const
char
*
linkpath
)
{
static
inline
int
compat
_symlinkat
(
const
char
*
target
,
int
newdirfd
,
const
char
*
linkpath
)
{
return
syscall
(
__NR_symlinkat
,
target
,
newdirfd
,
linkpath
);
return
syscall
(
__NR_symlinkat
,
target
,
newdirfd
,
linkpath
);
}
}
static
inline
int
_
_linkat
(
int
olddirfd
,
const
char
*
oldpath
,
static
inline
int
compat
_linkat
(
int
olddirfd
,
const
char
*
oldpath
,
int
newdirfd
,
const
char
*
newpath
,
int
flags
)
{
int
newdirfd
,
const
char
*
newpath
,
int
flags
)
{
return
syscall
(
__NR_linkat
,
olddirfd
,
oldpath
,
newdirfd
,
newpath
,
flags
);
return
syscall
(
__NR_linkat
,
olddirfd
,
oldpath
,
newdirfd
,
newpath
,
flags
);
}
}
static
inline
int
_
_inotify_init1
(
int
flags
)
{
static
inline
int
compat
_inotify_init1
(
int
flags
)
{
return
syscall
(
__NR_inotify_init1
,
flags
);
return
syscall
(
__NR_inotify_init1
,
flags
);
}
}
static
inline
int
_
_faccessat
(
int
dirfd
,
const
char
*
pathname
,
int
mode
,
int
flags
)
{
static
inline
int
compat
_faccessat
(
int
dirfd
,
const
char
*
pathname
,
int
mode
,
int
flags
)
{
return
syscall
(
__NR_faccessat
,
dirfd
,
pathname
,
mode
,
flags
);
return
syscall
(
__NR_faccessat
,
dirfd
,
pathname
,
mode
,
flags
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment