lkml.org 
[lkml]   [2019]   [Mar]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 2/4] arm64: Define Documentation/arm64/elf_at_flags.txt
On Fri, Mar 22, 2019 at 11:52:37AM +0530, Amit Daniel Kachhap wrote:
> On Mon, Mar 18, 2019 at 10:06 PM Vincenzo Frascino
> <vincenzo.frascino@arm.com> wrote:
> > +Example of correct usage (pseudo-code) for a userspace application:
> > +
> > +bool arm64_syscall_tbi_is_present(void)
> > +{
> > + unsigned long at_flags = getauxval(AT_FLAGS);
> > + if (at_flags & ARM64_AT_FLAGS_SYSCALL_TBI)
> > + return true;
> > +
> > + return false;
> > +}
> > +
> > +void main(void)
> > +{
> > + char *addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
> > + MAP_ANONYMOUS, -1, 0);
> > +
> > + int fd = open("test.txt", O_WRONLY);
> > +
> > + /* Check if the relaxed ABI is supported */
> > + if (arm64_syscall_tbi_is_present()) {
> > + /* Add a tag to the pointer */
> > + addr = tag_pointer(addr);
> > + }
> > +
> > + strcpy("Hello World\n", addr);
>
> Nit: s/strcpy("Hello World\n", addr)/strcpy(addr, "Hello World\n")

Not exactly a nit ;).

> > +
> > + /* Write to a file */
> > + write(fd, addr, sizeof(addr));

I presume this was supposed to write "Hello World\n" to a file but
sizeof(addr) is 1.

Since we already support tagged pointers in user space (as long as they
are not passed into the kernel), the above example could tag the pointer
unconditionally and only clear it before write() if
!arm64_syscall_tbi_is_present().

--
Catalin

\
 
 \ /
  Last update: 2019-03-22 11:49    [W:0.043 / U:9.048 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site