merge from eclair
This commit is contained in:
commit
333a80cf9f
150 changed files with 15959 additions and 1309 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
*~
|
||||||
|
|
@ -28,18 +28,35 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
/* TODO:
|
/* TODO:
|
||||||
** - grab the current buffer, not the first buffer
|
|
||||||
** - sync with vsync to avoid tearing
|
** - sync with vsync to avoid tearing
|
||||||
*/
|
*/
|
||||||
|
/* This version number defines the format of the fbinfo struct.
|
||||||
|
It must match versioning in ddms where this data is consumed. */
|
||||||
|
#define DDMS_RAWIMAGE_VERSION 1
|
||||||
|
struct fbinfo {
|
||||||
|
unsigned int version;
|
||||||
|
unsigned int bpp;
|
||||||
|
unsigned int size;
|
||||||
|
unsigned int width;
|
||||||
|
unsigned int height;
|
||||||
|
unsigned int red_offset;
|
||||||
|
unsigned int red_length;
|
||||||
|
unsigned int blue_offset;
|
||||||
|
unsigned int blue_length;
|
||||||
|
unsigned int green_offset;
|
||||||
|
unsigned int green_length;
|
||||||
|
unsigned int alpha_offset;
|
||||||
|
unsigned int alpha_length;
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
void framebuffer_service(int fd, void *cookie)
|
void framebuffer_service(int fd, void *cookie)
|
||||||
{
|
{
|
||||||
struct fb_var_screeninfo vinfo;
|
struct fb_var_screeninfo vinfo;
|
||||||
int fb;
|
int fb, offset;
|
||||||
void *ptr = MAP_FAILED;
|
char x[256];
|
||||||
char x;
|
|
||||||
|
|
||||||
unsigned fbinfo[4];
|
struct fbinfo fbinfo;
|
||||||
|
unsigned i, bytespp;
|
||||||
|
|
||||||
fb = open("/dev/graphics/fb0", O_RDONLY);
|
fb = open("/dev/graphics/fb0", O_RDONLY);
|
||||||
if(fb < 0) goto done;
|
if(fb < 0) goto done;
|
||||||
|
|
@ -47,24 +64,43 @@ void framebuffer_service(int fd, void *cookie)
|
||||||
if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) goto done;
|
if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) goto done;
|
||||||
fcntl(fb, F_SETFD, FD_CLOEXEC);
|
fcntl(fb, F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
fbinfo[0] = 16;
|
bytespp = vinfo.bits_per_pixel / 8;
|
||||||
fbinfo[1] = vinfo.xres * vinfo.yres * 2;
|
|
||||||
fbinfo[2] = vinfo.xres;
|
|
||||||
fbinfo[3] = vinfo.yres;
|
|
||||||
|
|
||||||
ptr = mmap(0, fbinfo[1], PROT_READ, MAP_SHARED, fb, 0);
|
fbinfo.version = DDMS_RAWIMAGE_VERSION;
|
||||||
if(ptr == MAP_FAILED) goto done;
|
fbinfo.bpp = vinfo.bits_per_pixel;
|
||||||
|
fbinfo.size = vinfo.xres * vinfo.yres * bytespp;
|
||||||
|
fbinfo.width = vinfo.xres;
|
||||||
|
fbinfo.height = vinfo.yres;
|
||||||
|
fbinfo.red_offset = vinfo.red.offset;
|
||||||
|
fbinfo.red_length = vinfo.red.length;
|
||||||
|
fbinfo.green_offset = vinfo.green.offset;
|
||||||
|
fbinfo.green_length = vinfo.green.length;
|
||||||
|
fbinfo.blue_offset = vinfo.blue.offset;
|
||||||
|
fbinfo.blue_length = vinfo.blue.length;
|
||||||
|
fbinfo.alpha_offset = vinfo.transp.offset;
|
||||||
|
fbinfo.alpha_length = vinfo.transp.length;
|
||||||
|
|
||||||
if(writex(fd, fbinfo, sizeof(unsigned) * 4)) goto done;
|
/* HACK: for several of our 3d cores a specific alignment
|
||||||
|
* is required so the start of the fb may not be an integer number of lines
|
||||||
|
* from the base. As a result we are storing the additional offset in
|
||||||
|
* xoffset. This is not the correct usage for xoffset, it should be added
|
||||||
|
* to each line, not just once at the beginning */
|
||||||
|
offset = vinfo.xoffset * bytespp;
|
||||||
|
|
||||||
for(;;) {
|
offset += vinfo.xres * vinfo.yoffset * bytespp;
|
||||||
if(readx(fd, &x, 1)) goto done;
|
|
||||||
if(writex(fd, ptr, fbinfo[1])) goto done;
|
if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done;
|
||||||
|
|
||||||
|
lseek(fb, offset, SEEK_SET);
|
||||||
|
for(i = 0; i < fbinfo.size; i += 256) {
|
||||||
|
if(readx(fb, &x, 256)) goto done;
|
||||||
|
if(writex(fd, &x, 256)) goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(readx(fb, &x, fbinfo.size % 256)) goto done;
|
||||||
|
if(writex(fd, &x, fbinfo.size % 256)) goto done;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if(ptr != MAP_FAILED) munmap(ptr, fbinfo[1]);
|
|
||||||
if(fb >= 0) close(fb);
|
if(fb >= 0) close(fb);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@
|
||||||
#define VENDOR_ID_HUAWEI 0x12D1
|
#define VENDOR_ID_HUAWEI 0x12D1
|
||||||
// Acer's USB Vendor ID
|
// Acer's USB Vendor ID
|
||||||
#define VENDOR_ID_ACER 0x0502
|
#define VENDOR_ID_ACER 0x0502
|
||||||
|
// Sony Ericsson's USB Vendor ID
|
||||||
|
#define VENDOR_ID_SONY_ERICSSON 0x0FCE
|
||||||
|
|
||||||
/** built-in vendor list */
|
/** built-in vendor list */
|
||||||
int builtInVendorIds[] = {
|
int builtInVendorIds[] = {
|
||||||
|
|
@ -59,6 +61,7 @@ int builtInVendorIds[] = {
|
||||||
VENDOR_ID_LGE,
|
VENDOR_ID_LGE,
|
||||||
VENDOR_ID_HUAWEI,
|
VENDOR_ID_HUAWEI,
|
||||||
VENDOR_ID_ACER,
|
VENDOR_ID_ACER,
|
||||||
|
VENDOR_ID_SONY_ERICSSON,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
|
#define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,16 @@
|
||||||
**
|
**
|
||||||
** Copyright 2006, The Android Open Source Project
|
** Copyright 2006, The Android Open Source Project
|
||||||
**
|
**
|
||||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
** you may not use this file except in compliance with the License.
|
** you may not use this file except in compliance with the License.
|
||||||
** You may obtain a copy of the License at
|
** You may obtain a copy of the License at
|
||||||
**
|
**
|
||||||
** http://www.apache.org/licenses/LICENSE-2.0
|
** http://www.apache.org/licenses/LICENSE-2.0
|
||||||
**
|
**
|
||||||
** Unless required by applicable law or agreed to in writing, software
|
** Unless required by applicable law or agreed to in writing, software
|
||||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
** See the License for the specific language governing permissions and
|
** See the License for the specific language governing permissions and
|
||||||
** limitations under the License.
|
** limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -48,8 +48,6 @@ extern int unwind_backtrace_with_ptrace(int tfd, pid_t pid, mapinfo *map,
|
||||||
int *frame0_pc_sane,
|
int *frame0_pc_sane,
|
||||||
bool at_fault);
|
bool at_fault);
|
||||||
|
|
||||||
static char **process_name_ptr;
|
|
||||||
|
|
||||||
static int logsocket = -1;
|
static int logsocket = -1;
|
||||||
|
|
||||||
#define ANDROID_LOG_INFO 4
|
#define ANDROID_LOG_INFO 4
|
||||||
|
|
@ -58,7 +56,7 @@ static int logsocket = -1;
|
||||||
void _LOG(int tfd, bool in_tombstone_only, const char *fmt, ...)
|
void _LOG(int tfd, bool in_tombstone_only, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
||||||
|
|
@ -91,16 +89,16 @@ mapinfo *parse_maps_line(char *line)
|
||||||
|
|
||||||
if(len < 1) return 0;
|
if(len < 1) return 0;
|
||||||
line[--len] = 0;
|
line[--len] = 0;
|
||||||
|
|
||||||
if(len < 50) return 0;
|
if(len < 50) return 0;
|
||||||
if(line[20] != 'x') return 0;
|
if(line[20] != 'x') return 0;
|
||||||
|
|
||||||
mi = malloc(sizeof(mapinfo) + (len - 47));
|
mi = malloc(sizeof(mapinfo) + (len - 47));
|
||||||
if(mi == 0) return 0;
|
if(mi == 0) return 0;
|
||||||
|
|
||||||
mi->start = strtoul(line, 0, 16);
|
mi->start = strtoul(line, 0, 16);
|
||||||
mi->end = strtoul(line + 9, 0, 16);
|
mi->end = strtoul(line + 9, 0, 16);
|
||||||
/* To be filled in parse_exidx_info if the mapped section starts with
|
/* To be filled in parse_exidx_info if the mapped section starts with
|
||||||
* elf_header
|
* elf_header
|
||||||
*/
|
*/
|
||||||
mi->exidx_start = mi->exidx_end = 0;
|
mi->exidx_start = mi->exidx_end = 0;
|
||||||
|
|
@ -120,7 +118,7 @@ void dump_build_info(int tfd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void dump_stack_and_code(int tfd, int pid, mapinfo *map,
|
void dump_stack_and_code(int tfd, int pid, mapinfo *map,
|
||||||
int unwind_depth, unsigned int sp_list[],
|
int unwind_depth, unsigned int sp_list[],
|
||||||
int frame0_pc_sane, bool at_fault)
|
int frame0_pc_sane, bool at_fault)
|
||||||
{
|
{
|
||||||
|
|
@ -128,6 +126,7 @@ void dump_stack_and_code(int tfd, int pid, mapinfo *map,
|
||||||
struct pt_regs r;
|
struct pt_regs r;
|
||||||
int sp_depth;
|
int sp_depth;
|
||||||
bool only_in_tombstone = !at_fault;
|
bool only_in_tombstone = !at_fault;
|
||||||
|
char code_buffer[80];
|
||||||
|
|
||||||
if(ptrace(PTRACE_GETREGS, pid, 0, &r)) return;
|
if(ptrace(PTRACE_GETREGS, pid, 0, &r)) return;
|
||||||
sp = r.ARM_sp;
|
sp = r.ARM_sp;
|
||||||
|
|
@ -140,26 +139,53 @@ void dump_stack_and_code(int tfd, int pid, mapinfo *map,
|
||||||
pc = r.ARM_lr;
|
pc = r.ARM_lr;
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOG(tfd, true, "code%s:\n", frame0_pc_sane ? "" : " (around frame #01)");
|
_LOG(tfd, only_in_tombstone,
|
||||||
|
"\ncode around %s:\n", frame0_pc_sane ? "pc" : "lr");
|
||||||
|
|
||||||
end = p = pc & ~3;
|
end = p = pc & ~3;
|
||||||
p -= 16;
|
p -= 16;
|
||||||
|
end += 16;
|
||||||
|
|
||||||
/* Dump the code as:
|
/* Dump the code around PC as:
|
||||||
* PC contents
|
* addr contents
|
||||||
* 00008d34 fffffcd0 4c0eb530 b0934a0e 1c05447c
|
* 00008d34 fffffcd0 4c0eb530 b0934a0e 1c05447c
|
||||||
* 00008d44 f7ff18a0 490ced94 68035860 d0012b00
|
* 00008d44 f7ff18a0 490ced94 68035860 d0012b00
|
||||||
*/
|
*/
|
||||||
while (p <= end) {
|
while (p <= end) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
_LOG(tfd, true, " %08x ", p);
|
sprintf(code_buffer, "%08x ", p);
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
data = ptrace(PTRACE_PEEKTEXT, pid, (void*)p, NULL);
|
data = ptrace(PTRACE_PEEKTEXT, pid, (void*)p, NULL);
|
||||||
_LOG(tfd, true, " %08x", data);
|
sprintf(code_buffer + strlen(code_buffer), "%08x ", data);
|
||||||
p += 4;
|
p += 4;
|
||||||
}
|
}
|
||||||
_LOG(tfd, true, "\n", p);
|
_LOG(tfd, only_in_tombstone, "%s\n", code_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame0_pc_sane) {
|
||||||
|
_LOG(tfd, only_in_tombstone, "\ncode around lr:\n");
|
||||||
|
|
||||||
|
end = p = r.ARM_lr & ~3;
|
||||||
|
p -= 16;
|
||||||
|
end += 16;
|
||||||
|
|
||||||
|
/* Dump the code around LR as:
|
||||||
|
* addr contents
|
||||||
|
* 00008d34 fffffcd0 4c0eb530 b0934a0e 1c05447c
|
||||||
|
* 00008d44 f7ff18a0 490ced94 68035860 d0012b00
|
||||||
|
*/
|
||||||
|
while (p <= end) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
sprintf(code_buffer, "%08x ", p);
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
data = ptrace(PTRACE_PEEKTEXT, pid, (void*)p, NULL);
|
||||||
|
sprintf(code_buffer + strlen(code_buffer), "%08x ", data);
|
||||||
|
p += 4;
|
||||||
|
}
|
||||||
|
_LOG(tfd, only_in_tombstone, "%s\n", code_buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p = sp - 64;
|
p = sp - 64;
|
||||||
|
|
@ -177,7 +203,7 @@ void dump_stack_and_code(int tfd, int pid, mapinfo *map,
|
||||||
end += 0xff;
|
end += 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOG(tfd, only_in_tombstone, "stack:\n");
|
_LOG(tfd, only_in_tombstone, "\nstack:\n");
|
||||||
|
|
||||||
/* If the crash is due to PC == 0, there will be two frames that
|
/* If the crash is due to PC == 0, there will be two frames that
|
||||||
* have identical SP value.
|
* have identical SP value.
|
||||||
|
|
@ -190,7 +216,7 @@ void dump_stack_and_code(int tfd, int pid, mapinfo *map,
|
||||||
}
|
}
|
||||||
|
|
||||||
while (p <= end) {
|
while (p <= end) {
|
||||||
char *prompt;
|
char *prompt;
|
||||||
char level[16];
|
char level[16];
|
||||||
data = ptrace(PTRACE_PEEKTEXT, pid, (void*)p, NULL);
|
data = ptrace(PTRACE_PEEKTEXT, pid, (void*)p, NULL);
|
||||||
if (p == sp_list[sp_depth]) {
|
if (p == sp_list[sp_depth]) {
|
||||||
|
|
@ -200,12 +226,12 @@ void dump_stack_and_code(int tfd, int pid, mapinfo *map,
|
||||||
else {
|
else {
|
||||||
prompt = " ";
|
prompt = " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print the stack content in the log for the first 3 frames. For the
|
/* Print the stack content in the log for the first 3 frames. For the
|
||||||
* rest only print them in the tombstone file.
|
* rest only print them in the tombstone file.
|
||||||
*/
|
*/
|
||||||
_LOG(tfd, (sp_depth > 2) || only_in_tombstone,
|
_LOG(tfd, (sp_depth > 2) || only_in_tombstone,
|
||||||
"%s %08x %08x %s\n", prompt, p, data,
|
"%s %08x %08x %s\n", prompt, p, data,
|
||||||
map_to_name(map, data, ""));
|
map_to_name(map, data, ""));
|
||||||
p += 4;
|
p += 4;
|
||||||
}
|
}
|
||||||
|
|
@ -214,14 +240,14 @@ void dump_stack_and_code(int tfd, int pid, mapinfo *map,
|
||||||
end = p+64;
|
end = p+64;
|
||||||
while (p <= end) {
|
while (p <= end) {
|
||||||
data = ptrace(PTRACE_PEEKTEXT, pid, (void*)p, NULL);
|
data = ptrace(PTRACE_PEEKTEXT, pid, (void*)p, NULL);
|
||||||
_LOG(tfd, (sp_depth > 2) || only_in_tombstone,
|
_LOG(tfd, (sp_depth > 2) || only_in_tombstone,
|
||||||
" %08x %08x %s\n", p, data,
|
" %08x %08x %s\n", p, data,
|
||||||
map_to_name(map, data, ""));
|
map_to_name(map, data, ""));
|
||||||
p += 4;
|
p += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump_pc_and_lr(int tfd, int pid, mapinfo *map, int unwound_level,
|
void dump_pc_and_lr(int tfd, int pid, mapinfo *map, int unwound_level,
|
||||||
bool at_fault)
|
bool at_fault)
|
||||||
{
|
{
|
||||||
struct pt_regs r;
|
struct pt_regs r;
|
||||||
|
|
@ -239,26 +265,26 @@ void dump_pc_and_lr(int tfd, int pid, mapinfo *map, int unwound_level,
|
||||||
map_to_name(map, r.ARM_lr, "<unknown>"));
|
map_to_name(map, r.ARM_lr, "<unknown>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump_registers(int tfd, int pid, bool at_fault)
|
void dump_registers(int tfd, int pid, bool at_fault)
|
||||||
{
|
{
|
||||||
struct pt_regs r;
|
struct pt_regs r;
|
||||||
bool only_in_tombstone = !at_fault;
|
bool only_in_tombstone = !at_fault;
|
||||||
|
|
||||||
if(ptrace(PTRACE_GETREGS, pid, 0, &r)) {
|
if(ptrace(PTRACE_GETREGS, pid, 0, &r)) {
|
||||||
_LOG(tfd, only_in_tombstone,
|
_LOG(tfd, only_in_tombstone,
|
||||||
"cannot get registers: %s\n", strerror(errno));
|
"cannot get registers: %s\n", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOG(tfd, only_in_tombstone, " r0 %08x r1 %08x r2 %08x r3 %08x\n",
|
_LOG(tfd, only_in_tombstone, " r0 %08x r1 %08x r2 %08x r3 %08x\n",
|
||||||
r.ARM_r0, r.ARM_r1, r.ARM_r2, r.ARM_r3);
|
r.ARM_r0, r.ARM_r1, r.ARM_r2, r.ARM_r3);
|
||||||
_LOG(tfd, only_in_tombstone, " r4 %08x r5 %08x r6 %08x r7 %08x\n",
|
_LOG(tfd, only_in_tombstone, " r4 %08x r5 %08x r6 %08x r7 %08x\n",
|
||||||
r.ARM_r4, r.ARM_r5, r.ARM_r6, r.ARM_r7);
|
r.ARM_r4, r.ARM_r5, r.ARM_r6, r.ARM_r7);
|
||||||
_LOG(tfd, only_in_tombstone, " r8 %08x r9 %08x 10 %08x fp %08x\n",
|
_LOG(tfd, only_in_tombstone, " r8 %08x r9 %08x 10 %08x fp %08x\n",
|
||||||
r.ARM_r8, r.ARM_r9, r.ARM_r10, r.ARM_fp);
|
r.ARM_r8, r.ARM_r9, r.ARM_r10, r.ARM_fp);
|
||||||
_LOG(tfd, only_in_tombstone,
|
_LOG(tfd, only_in_tombstone,
|
||||||
" ip %08x sp %08x lr %08x pc %08x cpsr %08x\n",
|
" ip %08x sp %08x lr %08x pc %08x cpsr %08x\n",
|
||||||
r.ARM_ip, r.ARM_sp, r.ARM_lr, r.ARM_pc, r.ARM_cpsr);
|
r.ARM_ip, r.ARM_sp, r.ARM_lr, r.ARM_pc, r.ARM_cpsr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *get_signame(int sig)
|
const char *get_signame(int sig)
|
||||||
|
|
@ -277,7 +303,7 @@ const char *get_signame(int sig)
|
||||||
void dump_fault_addr(int tfd, int pid, int sig)
|
void dump_fault_addr(int tfd, int pid, int sig)
|
||||||
{
|
{
|
||||||
siginfo_t si;
|
siginfo_t si;
|
||||||
|
|
||||||
memset(&si, 0, sizeof(si));
|
memset(&si, 0, sizeof(si));
|
||||||
if(ptrace(PTRACE_GETSIGINFO, pid, 0, &si)){
|
if(ptrace(PTRACE_GETSIGINFO, pid, 0, &si)){
|
||||||
_LOG(tfd, false, "cannot get siginfo: %s\n", strerror(errno));
|
_LOG(tfd, false, "cannot get siginfo: %s\n", strerror(errno));
|
||||||
|
|
@ -292,20 +318,20 @@ void dump_crash_banner(int tfd, unsigned pid, unsigned tid, int sig)
|
||||||
char data[1024];
|
char data[1024];
|
||||||
char *x = 0;
|
char *x = 0;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
sprintf(data, "/proc/%d/cmdline", pid);
|
sprintf(data, "/proc/%d/cmdline", pid);
|
||||||
fp = fopen(data, "r");
|
fp = fopen(data, "r");
|
||||||
if(fp) {
|
if(fp) {
|
||||||
x = fgets(data, 1024, fp);
|
x = fgets(data, 1024, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOG(tfd, false,
|
_LOG(tfd, false,
|
||||||
"*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n");
|
"*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n");
|
||||||
dump_build_info(tfd);
|
dump_build_info(tfd);
|
||||||
_LOG(tfd, false, "pid: %d, tid: %d >>> %s <<<\n",
|
_LOG(tfd, false, "pid: %d, tid: %d >>> %s <<<\n",
|
||||||
pid, tid, x ? x : "UNKNOWN");
|
pid, tid, x ? x : "UNKNOWN");
|
||||||
|
|
||||||
if(sig) dump_fault_addr(tfd, tid, sig);
|
if(sig) dump_fault_addr(tfd, tid, sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,10 +342,10 @@ static void parse_exidx_info(mapinfo *milist, pid_t pid)
|
||||||
Elf32_Ehdr ehdr;
|
Elf32_Ehdr ehdr;
|
||||||
|
|
||||||
memset(&ehdr, 0, sizeof(Elf32_Ehdr));
|
memset(&ehdr, 0, sizeof(Elf32_Ehdr));
|
||||||
/* Read in sizeof(Elf32_Ehdr) worth of data from the beginning of
|
/* Read in sizeof(Elf32_Ehdr) worth of data from the beginning of
|
||||||
* mapped section.
|
* mapped section.
|
||||||
*/
|
*/
|
||||||
get_remote_struct(pid, (void *) (mi->start), &ehdr,
|
get_remote_struct(pid, (void *) (mi->start), &ehdr,
|
||||||
sizeof(Elf32_Ehdr));
|
sizeof(Elf32_Ehdr));
|
||||||
/* Check if it has the matching magic words */
|
/* Check if it has the matching magic words */
|
||||||
if (IS_ELF(ehdr)) {
|
if (IS_ELF(ehdr)) {
|
||||||
|
|
@ -330,7 +356,7 @@ static void parse_exidx_info(mapinfo *milist, pid_t pid)
|
||||||
ptr = (Elf32_Phdr *) (mi->start + ehdr.e_phoff);
|
ptr = (Elf32_Phdr *) (mi->start + ehdr.e_phoff);
|
||||||
for (i = 0; i < ehdr.e_phnum; i++) {
|
for (i = 0; i < ehdr.e_phnum; i++) {
|
||||||
/* Parse the program header */
|
/* Parse the program header */
|
||||||
get_remote_struct(pid, (void *) ptr+i, &phdr,
|
get_remote_struct(pid, (char *) ptr+i, &phdr,
|
||||||
sizeof(Elf32_Phdr));
|
sizeof(Elf32_Phdr));
|
||||||
/* Found a EXIDX segment? */
|
/* Found a EXIDX segment? */
|
||||||
if (phdr.p_type == PT_ARM_EXIDX) {
|
if (phdr.p_type == PT_ARM_EXIDX) {
|
||||||
|
|
@ -351,7 +377,7 @@ void dump_crash_report(int tfd, unsigned pid, unsigned tid, bool at_fault)
|
||||||
unsigned int sp_list[STACK_CONTENT_DEPTH];
|
unsigned int sp_list[STACK_CONTENT_DEPTH];
|
||||||
int stack_depth;
|
int stack_depth;
|
||||||
int frame0_pc_sane = 1;
|
int frame0_pc_sane = 1;
|
||||||
|
|
||||||
if (!at_fault) {
|
if (!at_fault) {
|
||||||
_LOG(tfd, true,
|
_LOG(tfd, true,
|
||||||
"--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n");
|
"--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n");
|
||||||
|
|
@ -359,7 +385,7 @@ void dump_crash_report(int tfd, unsigned pid, unsigned tid, bool at_fault)
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_registers(tfd, tid, at_fault);
|
dump_registers(tfd, tid, at_fault);
|
||||||
|
|
||||||
/* Clear stack pointer records */
|
/* Clear stack pointer records */
|
||||||
memset(sp_list, 0, sizeof(sp_list));
|
memset(sp_list, 0, sizeof(sp_list));
|
||||||
|
|
||||||
|
|
@ -401,40 +427,6 @@ void dump_crash_report(int tfd, unsigned pid, unsigned tid, bool at_fault)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: unused: use it or lose it*/
|
|
||||||
#if 0
|
|
||||||
static
|
|
||||||
void start_gdbserver_vs(int pid, int port)
|
|
||||||
{
|
|
||||||
pid_t p;
|
|
||||||
char *args[5];
|
|
||||||
char commspec[16];
|
|
||||||
char pidspec[16];
|
|
||||||
|
|
||||||
p = fork();
|
|
||||||
if(p < 0) {
|
|
||||||
LOG("could not fork()\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(p == 0) {
|
|
||||||
sprintf(commspec, ":%d", port);
|
|
||||||
sprintf(pidspec, "%d", pid);
|
|
||||||
args[0] = "/system/bin/gdbserver";
|
|
||||||
args[1] = commspec;
|
|
||||||
args[2] = "--attach";
|
|
||||||
args[3] = pidspec;
|
|
||||||
args[4] = 0;
|
|
||||||
exit(execv(args[0], args));
|
|
||||||
} else {
|
|
||||||
LOG("gdbserver pid=%d port=%d targetpid=%d\n",
|
|
||||||
p, port, pid);
|
|
||||||
|
|
||||||
sleep(5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_TOMBSTONES 10
|
#define MAX_TOMBSTONES 10
|
||||||
|
|
||||||
#define typecheck(x,y) { \
|
#define typecheck(x,y) { \
|
||||||
|
|
@ -514,7 +506,7 @@ static bool dump_sibling_thread_report(int tfd, unsigned pid, unsigned tid)
|
||||||
while ((de = readdir(d)) != NULL) {
|
while ((de = readdir(d)) != NULL) {
|
||||||
unsigned new_tid;
|
unsigned new_tid;
|
||||||
/* Ignore "." and ".." */
|
/* Ignore "." and ".." */
|
||||||
if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
|
if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
|
||||||
continue;
|
continue;
|
||||||
new_tid = atoi(de->d_name);
|
new_tid = atoi(de->d_name);
|
||||||
/* The main thread at fault has been handled individually */
|
/* The main thread at fault has been handled individually */
|
||||||
|
|
@ -533,7 +525,7 @@ static bool dump_sibling_thread_report(int tfd, unsigned pid, unsigned tid)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return true if some thread is not detached cleanly */
|
/* Return true if some thread is not detached cleanly */
|
||||||
static bool engrave_tombstone(unsigned pid, unsigned tid, int debug_uid,
|
static bool engrave_tombstone(unsigned pid, unsigned tid, int debug_uid,
|
||||||
int signal)
|
int signal)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
@ -548,7 +540,7 @@ static bool engrave_tombstone(unsigned pid, unsigned tid, int debug_uid,
|
||||||
|
|
||||||
dump_crash_banner(fd, pid, tid, signal);
|
dump_crash_banner(fd, pid, tid, signal);
|
||||||
dump_crash_report(fd, pid, tid, true);
|
dump_crash_report(fd, pid, tid, true);
|
||||||
/*
|
/*
|
||||||
* If the user has requested to attach gdb, don't collect the per-thread
|
* If the user has requested to attach gdb, don't collect the per-thread
|
||||||
* information as it increases the chance to lose track of the process.
|
* information as it increases the chance to lose track of the process.
|
||||||
*/
|
*/
|
||||||
|
|
@ -619,7 +611,7 @@ static void wait_for_user_action(unsigned tid, struct ucred* cr)
|
||||||
"* adb shell gdbserver :port --attach %d & \n"
|
"* adb shell gdbserver :port --attach %d & \n"
|
||||||
"* \n"
|
"* \n"
|
||||||
"* and press the HOME key. \n"
|
"* and press the HOME key. \n"
|
||||||
"********************************************************\n",
|
"********************************************************\n",
|
||||||
cr->pid, cr->pid);
|
cr->pid, cr->pid);
|
||||||
|
|
||||||
/* wait for HOME key */
|
/* wait for HOME key */
|
||||||
|
|
@ -653,13 +645,13 @@ static void wait_for_user_action(unsigned tid, struct ucred* cr)
|
||||||
disable_debug_led();
|
disable_debug_led();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (!home);
|
} while (!home);
|
||||||
uninit_getevent();
|
uninit_getevent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* don't forget to turn debug led off */
|
/* don't forget to turn debug led off */
|
||||||
disable_debug_led();
|
disable_debug_led();
|
||||||
|
|
||||||
/* close filedescriptor */
|
/* close filedescriptor */
|
||||||
LOG("debuggerd resuming process %d", cr->pid);
|
LOG("debuggerd resuming process %d", cr->pid);
|
||||||
}
|
}
|
||||||
|
|
@ -670,7 +662,7 @@ static void handle_crashing_process(int fd)
|
||||||
struct stat s;
|
struct stat s;
|
||||||
unsigned tid;
|
unsigned tid;
|
||||||
struct ucred cr;
|
struct ucred cr;
|
||||||
int n, len, status;
|
int n, len, status;
|
||||||
int tid_attach_status = -1;
|
int tid_attach_status = -1;
|
||||||
unsigned retry = 30;
|
unsigned retry = 30;
|
||||||
bool need_cleanup = false;
|
bool need_cleanup = false;
|
||||||
|
|
@ -678,9 +670,9 @@ static void handle_crashing_process(int fd)
|
||||||
char value[PROPERTY_VALUE_MAX];
|
char value[PROPERTY_VALUE_MAX];
|
||||||
property_get("debug.db.uid", value, "-1");
|
property_get("debug.db.uid", value, "-1");
|
||||||
int debug_uid = atoi(value);
|
int debug_uid = atoi(value);
|
||||||
|
|
||||||
XLOG("handle_crashing_process(%d)\n", fd);
|
XLOG("handle_crashing_process(%d)\n", fd);
|
||||||
|
|
||||||
len = sizeof(cr);
|
len = sizeof(cr);
|
||||||
n = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &len);
|
n = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &len);
|
||||||
if(n != 0) {
|
if(n != 0) {
|
||||||
|
|
@ -688,7 +680,7 @@ static void handle_crashing_process(int fd)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
XLOG("reading tid\n");
|
XLOG("reading tid\n");
|
||||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||||
while((n = read(fd, &tid, sizeof(unsigned))) != sizeof(unsigned)) {
|
while((n = read(fd, &tid, sizeof(unsigned))) != sizeof(unsigned)) {
|
||||||
if(errno == EINTR) continue;
|
if(errno == EINTR) continue;
|
||||||
|
|
@ -711,7 +703,7 @@ static void handle_crashing_process(int fd)
|
||||||
close(fd);
|
close(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
XLOG("BOOM: pid=%d uid=%d gid=%d tid=%d\n", cr.pid, cr.uid, cr.gid, tid);
|
XLOG("BOOM: pid=%d uid=%d gid=%d tid=%d\n", cr.pid, cr.uid, cr.gid, tid);
|
||||||
|
|
||||||
tid_attach_status = ptrace(PTRACE_ATTACH, tid, 0, 0);
|
tid_attach_status = ptrace(PTRACE_ATTACH, tid, 0, 0);
|
||||||
|
|
@ -725,7 +717,7 @@ static void handle_crashing_process(int fd)
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
n = waitpid(tid, &status, __WALL);
|
n = waitpid(tid, &status, __WALL);
|
||||||
|
|
||||||
if(n < 0) {
|
if(n < 0) {
|
||||||
if(errno == EAGAIN) continue;
|
if(errno == EAGAIN) continue;
|
||||||
LOG("waitpid failed: %s\n", strerror(errno));
|
LOG("waitpid failed: %s\n", strerror(errno));
|
||||||
|
|
@ -745,7 +737,7 @@ static void handle_crashing_process(int fd)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case SIGILL:
|
case SIGILL:
|
||||||
case SIGABRT:
|
case SIGABRT:
|
||||||
case SIGBUS:
|
case SIGBUS:
|
||||||
|
|
@ -767,17 +759,17 @@ static void handle_crashing_process(int fd)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
XLOG("detaching\n");
|
XLOG("detaching\n");
|
||||||
|
|
||||||
/* stop the process so we can debug */
|
/* stop the process so we can debug */
|
||||||
kill(cr.pid, SIGSTOP);
|
kill(cr.pid, SIGSTOP);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If a thread has been attached by ptrace, make sure it is detached
|
* If a thread has been attached by ptrace, make sure it is detached
|
||||||
* successfully otherwise we will get a zombie.
|
* successfully otherwise we will get a zombie.
|
||||||
*/
|
*/
|
||||||
if (tid_attach_status == 0) {
|
if (tid_attach_status == 0) {
|
||||||
int detach_status;
|
int detach_status;
|
||||||
/* detach so we can attach gdbserver */
|
/* detach so we can attach gdbserver */
|
||||||
|
|
@ -807,14 +799,12 @@ done:
|
||||||
if(fd != -1) close(fd);
|
if(fd != -1) close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main()
|
||||||
{
|
{
|
||||||
int s;
|
int s;
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
|
|
||||||
process_name_ptr = argv;
|
logsocket = socket_local_client("logd",
|
||||||
|
|
||||||
logsocket = socket_local_client("logd",
|
|
||||||
ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_DGRAM);
|
ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_DGRAM);
|
||||||
if(logsocket < 0) {
|
if(logsocket < 0) {
|
||||||
logsocket = -1;
|
logsocket = -1;
|
||||||
|
|
@ -827,23 +817,23 @@ int main(int argc, char **argv)
|
||||||
sigaddset(&act.sa_mask,SIGCHLD);
|
sigaddset(&act.sa_mask,SIGCHLD);
|
||||||
act.sa_flags = SA_NOCLDWAIT;
|
act.sa_flags = SA_NOCLDWAIT;
|
||||||
sigaction(SIGCHLD, &act, 0);
|
sigaction(SIGCHLD, &act, 0);
|
||||||
|
|
||||||
s = socket_local_server("android:debuggerd",
|
s = socket_local_server("android:debuggerd",
|
||||||
ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
|
ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
|
||||||
if(s < 0) return -1;
|
if(s < 0) return -1;
|
||||||
fcntl(s, F_SETFD, FD_CLOEXEC);
|
fcntl(s, F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
LOG("debuggerd: " __DATE__ " " __TIME__ "\n");
|
LOG("debuggerd: " __DATE__ " " __TIME__ "\n");
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
struct sockaddr addr;
|
struct sockaddr addr;
|
||||||
socklen_t alen;
|
socklen_t alen;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
alen = sizeof(addr);
|
alen = sizeof(addr);
|
||||||
fd = accept(s, &addr, &alen);
|
fd = accept(s, &addr, &alen);
|
||||||
if(fd < 0) continue;
|
if(fd < 0) continue;
|
||||||
|
|
||||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
handle_crashing_process(fd);
|
handle_crashing_process(fd);
|
||||||
|
|
|
||||||
|
|
@ -147,10 +147,12 @@ oops:
|
||||||
int match_fastboot(usb_ifc_info *info)
|
int match_fastboot(usb_ifc_info *info)
|
||||||
{
|
{
|
||||||
if(!(vendor_id && (info->dev_vendor == vendor_id)) &&
|
if(!(vendor_id && (info->dev_vendor == vendor_id)) &&
|
||||||
(info->dev_vendor != 0x18d1) &&
|
(info->dev_vendor != 0x18d1) && // Google
|
||||||
(info->dev_vendor != 0x0451) &&
|
(info->dev_vendor != 0x0451) &&
|
||||||
|
(info->dev_vendor != 0x22b8) && // Motorola
|
||||||
(info->dev_vendor != 0x0502) &&
|
(info->dev_vendor != 0x0502) &&
|
||||||
(info->dev_vendor != 0x0bb4)) return -1;
|
(info->dev_vendor != 0x0bb4)) // HTC
|
||||||
|
return -1;
|
||||||
if(info->ifc_class != 0xff) return -1;
|
if(info->ifc_class != 0xff) return -1;
|
||||||
if(info->ifc_subclass != 0x42) return -1;
|
if(info->ifc_subclass != 0x42) return -1;
|
||||||
if(info->ifc_protocol != 0x03) return -1;
|
if(info->ifc_protocol != 0x03) return -1;
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,9 @@
|
||||||
|
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
#if TRACE_USB
|
#define MAX_RETRIES 5
|
||||||
|
|
||||||
|
#ifdef TRACE_USB
|
||||||
#define DBG1(x...) fprintf(stderr, x)
|
#define DBG1(x...) fprintf(stderr, x)
|
||||||
#define DBG(x...) fprintf(stderr, x)
|
#define DBG(x...) fprintf(stderr, x)
|
||||||
#else
|
#else
|
||||||
|
|
@ -303,7 +305,7 @@ int usb_read(usb_handle *h, void *_data, int len)
|
||||||
unsigned char *data = (unsigned char*) _data;
|
unsigned char *data = (unsigned char*) _data;
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
struct usbdevfs_bulktransfer bulk;
|
struct usbdevfs_bulktransfer bulk;
|
||||||
int n;
|
int n, retry;
|
||||||
|
|
||||||
if(h->ep_in == 0) {
|
if(h->ep_in == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -316,16 +318,20 @@ int usb_read(usb_handle *h, void *_data, int len)
|
||||||
bulk.len = xfer;
|
bulk.len = xfer;
|
||||||
bulk.data = data;
|
bulk.data = data;
|
||||||
bulk.timeout = 0;
|
bulk.timeout = 0;
|
||||||
|
retry = 0;
|
||||||
DBG("[ usb read %d fd = %d], fname=%s\n", xfer, h->desc, h->fname);
|
|
||||||
n = ioctl(h->desc, USBDEVFS_BULK, &bulk);
|
|
||||||
DBG("[ usb read %d ] = %d, fname=%s\n", xfer, n, h->fname);
|
|
||||||
|
|
||||||
if(n < 0) {
|
do{
|
||||||
DBG1("ERROR: n = %d, errno = %d (%s)\n",
|
DBG("[ usb read %d fd = %d], fname=%s\n", xfer, h->desc, h->fname);
|
||||||
n, errno, strerror(errno));
|
n = ioctl(h->desc, USBDEVFS_BULK, &bulk);
|
||||||
return -1;
|
DBG("[ usb read %d ] = %d, fname=%s, Retry %d \n", xfer, n, h->fname, retry);
|
||||||
|
|
||||||
|
if( n < 0 ) {
|
||||||
|
DBG1("ERROR: n = %d, errno = %d (%s)\n",n, errno, strerror(errno));
|
||||||
|
if ( ++retry > MAX_RETRIES ) return -1;
|
||||||
|
sleep( 1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while( n < 0 );
|
||||||
|
|
||||||
count += n;
|
count += n;
|
||||||
len -= n;
|
len -= n;
|
||||||
|
|
|
||||||
92
include/acc/acc.h
Normal file
92
include/acc/acc.h
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2009 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANDROID_ACC_ACC_H
|
||||||
|
#define ANDROID_ACC_ACC_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
typedef char ACCchar;
|
||||||
|
typedef int32_t ACCint;
|
||||||
|
typedef uint32_t ACCuint;
|
||||||
|
typedef ssize_t ACCsizei;
|
||||||
|
typedef unsigned int ACCenum;
|
||||||
|
typedef void ACCvoid;
|
||||||
|
typedef struct ACCscript ACCscript;
|
||||||
|
|
||||||
|
#define ACC_NO_ERROR 0x0000
|
||||||
|
#define ACC_INVALID_ENUM 0x0500
|
||||||
|
#define ACC_INVALID_OPERATION 0x0502
|
||||||
|
#define ACC_INVALID_VALUE 0x0501
|
||||||
|
#define ACC_OUT_OF_MEMORY 0x0505
|
||||||
|
|
||||||
|
#define ACC_COMPILE_STATUS 0x8B81
|
||||||
|
#define ACC_INFO_LOG_LENGTH 0x8B84
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ACCscript* accCreateScript();
|
||||||
|
|
||||||
|
void accDeleteScript(ACCscript* script);
|
||||||
|
|
||||||
|
typedef ACCvoid* (*ACCSymbolLookupFn)(ACCvoid* pContext, const ACCchar * name);
|
||||||
|
|
||||||
|
void accRegisterSymbolCallback(ACCscript* script, ACCSymbolLookupFn pFn,
|
||||||
|
ACCvoid* pContext);
|
||||||
|
|
||||||
|
ACCenum accGetError( ACCscript* script );
|
||||||
|
|
||||||
|
void accScriptSource(ACCscript* script,
|
||||||
|
ACCsizei count,
|
||||||
|
const ACCchar** string,
|
||||||
|
const ACCint* length);
|
||||||
|
|
||||||
|
void accCompileScript(ACCscript* script);
|
||||||
|
|
||||||
|
void accGetScriptiv(ACCscript* script,
|
||||||
|
ACCenum pname,
|
||||||
|
ACCint* params);
|
||||||
|
|
||||||
|
void accGetScriptInfoLog(ACCscript* script,
|
||||||
|
ACCsizei maxLength,
|
||||||
|
ACCsizei* length,
|
||||||
|
ACCchar* infoLog);
|
||||||
|
|
||||||
|
void accGetScriptLabel(ACCscript* script, const ACCchar * name,
|
||||||
|
ACCvoid** address);
|
||||||
|
|
||||||
|
void accGetPragmas(ACCscript* script, ACCsizei* actualStringCount,
|
||||||
|
ACCsizei maxStringCount, ACCchar** strings);
|
||||||
|
|
||||||
|
/* Used to implement disassembly */
|
||||||
|
|
||||||
|
void accGetProgramBinary(ACCscript* script,
|
||||||
|
ACCvoid** base,
|
||||||
|
ACCsizei* length);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -15,9 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Android config -- "Darwin". Used for PPC Mac OS X.
|
* Android config -- "Darwin". Used for X86 Mac OS X.
|
||||||
*
|
|
||||||
* TODO: split this into "x86" and "ppc" versions
|
|
||||||
*/
|
*/
|
||||||
#ifndef _ANDROID_CONFIG_H
|
#ifndef _ANDROID_CONFIG_H
|
||||||
#define _ANDROID_CONFIG_H
|
#define _ANDROID_CONFIG_H
|
||||||
|
|
@ -257,4 +255,19 @@
|
||||||
*/
|
*/
|
||||||
#define HAVE_WRITEV 1
|
#define HAVE_WRITEV 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdint.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_STDINT_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdbool.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_STDBOOL_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <sched.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_SCHED_H 1
|
||||||
|
|
||||||
#endif /*_ANDROID_CONFIG_H*/
|
#endif /*_ANDROID_CONFIG_H*/
|
||||||
|
|
|
||||||
|
|
@ -314,4 +314,19 @@
|
||||||
#define CLOCK_PROCESS_CPUTIME_ID CLOCK_PROF
|
#define CLOCK_PROCESS_CPUTIME_ID CLOCK_PROF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdint.h> exists.
|
||||||
|
*/
|
||||||
|
/* #define HAVE_STDINT_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdbool.h> exists.
|
||||||
|
*/
|
||||||
|
/* #define HAVE_STDBOOL_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <sched.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_SCHED_H 1
|
||||||
|
|
||||||
#endif /*_ANDROID_CONFIG_H*/
|
#endif /*_ANDROID_CONFIG_H*/
|
||||||
|
|
|
||||||
|
|
@ -302,4 +302,19 @@
|
||||||
*/
|
*/
|
||||||
#define HAVE_WRITEV 1
|
#define HAVE_WRITEV 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdint.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_STDINT_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdbool.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_STDBOOL_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <sched.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_SCHED_H 1
|
||||||
|
|
||||||
#endif /* _ANDROID_CONFIG_H */
|
#endif /* _ANDROID_CONFIG_H */
|
||||||
|
|
|
||||||
|
|
@ -283,4 +283,19 @@
|
||||||
*/
|
*/
|
||||||
#define HAVE_WRITEV 1
|
#define HAVE_WRITEV 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdint.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_STDINT_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdbool.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_STDBOOL_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <sched.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_SCHED_H 1
|
||||||
|
|
||||||
#endif /*_ANDROID_CONFIG_H*/
|
#endif /*_ANDROID_CONFIG_H*/
|
||||||
|
|
|
||||||
|
|
@ -293,4 +293,19 @@
|
||||||
*/
|
*/
|
||||||
#define HAVE_UNWIND_CONTEXT_STRUCT
|
#define HAVE_UNWIND_CONTEXT_STRUCT
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdint.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_STDINT_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdbool.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_STDBOOL_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <sched.h> exists.
|
||||||
|
*/
|
||||||
|
#define HAVE_SCHED_H 1
|
||||||
|
|
||||||
#endif /* _ANDROID_CONFIG_H */
|
#endif /* _ANDROID_CONFIG_H */
|
||||||
|
|
|
||||||
|
|
@ -287,4 +287,19 @@
|
||||||
*/
|
*/
|
||||||
/* #define HAVE_WRITEV */
|
/* #define HAVE_WRITEV */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdint.h> exists.
|
||||||
|
*/
|
||||||
|
/* #define HAVE_STDINT_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <stdbool.h> exists.
|
||||||
|
*/
|
||||||
|
/* #define HAVE_STDBOOL_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if <sched.h> exists.
|
||||||
|
*/
|
||||||
|
/* #define HAVE_SCHED_H */
|
||||||
|
|
||||||
#endif /*_ANDROID_CONFIG_H*/
|
#endif /*_ANDROID_CONFIG_H*/
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@
|
||||||
#ifndef _CUTILS_ASHMEM_H
|
#ifndef _CUTILS_ASHMEM_H
|
||||||
#define _CUTILS_ASHMEM_H
|
#define _CUTILS_ASHMEM_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
32
include/cutils/compiler.h
Normal file
32
include/cutils/compiler.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2009 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANDROID_CUTILS_COMPILER_H
|
||||||
|
#define ANDROID_CUTILS_COMPILER_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* helps the compiler's optimizer predicting branches
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
# define CC_LIKELY( exp ) (__builtin_expect( !!(exp), true ))
|
||||||
|
# define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), false ))
|
||||||
|
#else
|
||||||
|
# define CC_LIKELY( exp ) (__builtin_expect( !!(exp), 1 ))
|
||||||
|
# define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), 0 ))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ANDROID_CUTILS_COMPILER_H
|
||||||
36
include/cutils/sched_policy.h
Normal file
36
include/cutils/sched_policy.h
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CUTILS_SCHED_POLICY_H
|
||||||
|
#define __CUTILS_SCHED_POLICY_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SP_BACKGROUND = 0,
|
||||||
|
SP_FOREGROUND = 1,
|
||||||
|
} SchedPolicy;
|
||||||
|
|
||||||
|
extern int set_sched_policy(int tid, SchedPolicy policy);
|
||||||
|
extern int get_sched_policy(int tid, SchedPolicy *policy);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __CUTILS_SCHED_POLICY_H */
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
#ifndef _CUTILS_TZTIME_H
|
#ifndef _CUTILS_TZTIME_H
|
||||||
#define _CUTILS_TZTIME_H
|
#define _CUTILS_TZTIME_H
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -24,6 +26,9 @@ extern "C" {
|
||||||
time_t mktime_tz(struct tm * const tmp, char const * tz);
|
time_t mktime_tz(struct tm * const tmp, char const * tz);
|
||||||
void localtime_tz(const time_t * const timep, struct tm * tmp, const char* tz);
|
void localtime_tz(const time_t * const timep, struct tm * tmp, const char* tz);
|
||||||
|
|
||||||
|
#ifndef HAVE_ANDROID_OS
|
||||||
|
/* the following is defined in <time.h> in Bionic */
|
||||||
|
|
||||||
struct strftime_locale {
|
struct strftime_locale {
|
||||||
const char *mon[12]; /* short names */
|
const char *mon[12]; /* short names */
|
||||||
const char *month[12]; /* long names */
|
const char *month[12]; /* long names */
|
||||||
|
|
@ -40,6 +45,8 @@ struct strftime_locale {
|
||||||
|
|
||||||
size_t strftime_tz(char *s, size_t max, const char *format, const struct tm *tm, const struct strftime_locale *locale);
|
size_t strftime_tz(char *s, size_t max, const char *format, const struct tm *tm, const struct strftime_locale *locale);
|
||||||
|
|
||||||
|
#endif /* !HAVE_ANDROID_OS */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@
|
||||||
** be used to endorse or promote products derived from this software
|
** be used to endorse or promote products derived from this software
|
||||||
** without specific prior written permission.
|
** without specific prior written permission.
|
||||||
**
|
**
|
||||||
** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
|
** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
|
||||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
@ -36,16 +36,23 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct SHA_CTX {
|
typedef struct SHA_CTX {
|
||||||
uint64_t count;
|
uint64_t count;
|
||||||
uint8_t buf[64];
|
|
||||||
uint32_t state[5];
|
uint32_t state[5];
|
||||||
|
#if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN)
|
||||||
|
union {
|
||||||
|
uint8_t b[64];
|
||||||
|
uint32_t w[16];
|
||||||
|
} buf;
|
||||||
|
#else
|
||||||
|
uint8_t buf[64];
|
||||||
|
#endif
|
||||||
} SHA_CTX;
|
} SHA_CTX;
|
||||||
|
|
||||||
void SHA_init(SHA_CTX *ctx);
|
void SHA_init(SHA_CTX* ctx);
|
||||||
void SHA_update(SHA_CTX *ctx, const void* data, int len);
|
void SHA_update(SHA_CTX* ctx, const void* data, int len);
|
||||||
const uint8_t* SHA_final(SHA_CTX *ctx);
|
const uint8_t* SHA_final(SHA_CTX* ctx);
|
||||||
|
|
||||||
/* Convenience method. Returns digest parameter value. */
|
/* Convenience method. Returns digest parameter value. */
|
||||||
const uint8_t* SHA(const void *data, int len, uint8_t *digest);
|
const uint8_t* SHA(const void* data, int len, uint8_t* digest);
|
||||||
|
|
||||||
#define SHA_DIGEST_SIZE 20
|
#define SHA_DIGEST_SIZE 20
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,10 +156,10 @@ static struct fs_path_config android_files[] = {
|
||||||
{ 00550, AID_ROOT, AID_SHELL, "system/etc/init.testmenu" },
|
{ 00550, AID_ROOT, AID_SHELL, "system/etc/init.testmenu" },
|
||||||
{ 00550, AID_DHCP, AID_SHELL, "system/etc/dhcpcd/dhcpcd-run-hooks" },
|
{ 00550, AID_DHCP, AID_SHELL, "system/etc/dhcpcd/dhcpcd-run-hooks" },
|
||||||
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" },
|
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" },
|
||||||
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluez/hcid.conf" },
|
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluez/main.conf" },
|
||||||
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluez/input.conf" },
|
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluez/input.conf" },
|
||||||
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluez/audio.conf" },
|
{ 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluez/audio.conf" },
|
||||||
{ 00440, AID_RADIO, AID_AUDIO, "system/etc/AudioPara4.csv" },
|
{ 00444, AID_RADIO, AID_AUDIO, "system/etc/AudioPara4.csv" },
|
||||||
{ 00555, AID_ROOT, AID_ROOT, "system/etc/ppp/*" },
|
{ 00555, AID_ROOT, AID_ROOT, "system/etc/ppp/*" },
|
||||||
{ 00644, AID_SYSTEM, AID_SYSTEM, "data/app/*" },
|
{ 00644, AID_SYSTEM, AID_SYSTEM, "data/app/*" },
|
||||||
{ 00644, AID_SYSTEM, AID_SYSTEM, "data/app-private/*" },
|
{ 00644, AID_SYSTEM, AID_SYSTEM, "data/app-private/*" },
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <endian.h>
|
||||||
|
|
||||||
#include <utils/Endian.h>
|
|
||||||
#include <pixelflinger/pixelflinger.h>
|
#include <pixelflinger/pixelflinger.h>
|
||||||
#include <private/pixelflinger/ggl_fixed.h>
|
#include <private/pixelflinger/ggl_fixed.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public:
|
||||||
SocketListener(const char *socketNames, bool listen);
|
SocketListener(const char *socketNames, bool listen);
|
||||||
SocketListener(int socketFd, bool listen);
|
SocketListener(int socketFd, bool listen);
|
||||||
|
|
||||||
virtual ~SocketListener() {}
|
virtual ~SocketListener();
|
||||||
int startListener();
|
int startListener();
|
||||||
int stopListener();
|
int stopListener();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ static int write_file(const char *path, const char *value)
|
||||||
fd = open(path, O_WRONLY|O_CREAT, 0622);
|
fd = open(path, O_WRONLY|O_CREAT, 0622);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -errno;
|
||||||
|
|
||||||
len = strlen(value);
|
len = strlen(value);
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ static int write_file(const char *path, const char *value)
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -errno;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -441,6 +441,68 @@ int do_write(int nargs, char **args)
|
||||||
return write_file(args[1], args[2]);
|
return write_file(args[1], args[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int do_copy(int nargs, char **args)
|
||||||
|
{
|
||||||
|
char *buffer = NULL;
|
||||||
|
int rc = 0;
|
||||||
|
int fd1 = -1, fd2 = -1;
|
||||||
|
struct stat info;
|
||||||
|
int brtw, brtr;
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if (nargs != 3)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (stat(args[1], &info) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if ((fd1 = open(args[1], O_RDONLY)) < 0)
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
|
if ((fd2 = open(args[2], O_WRONLY|O_CREAT|O_TRUNC, 0660)) < 0)
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
|
if (!(buffer = malloc(info.st_size)))
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
|
p = buffer;
|
||||||
|
brtr = info.st_size;
|
||||||
|
while(brtr) {
|
||||||
|
rc = read(fd1, p, brtr);
|
||||||
|
if (rc < 0)
|
||||||
|
goto out_err;
|
||||||
|
if (rc == 0)
|
||||||
|
break;
|
||||||
|
p += rc;
|
||||||
|
brtr -= rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = buffer;
|
||||||
|
brtw = info.st_size;
|
||||||
|
while(brtw) {
|
||||||
|
rc = write(fd2, p, brtw);
|
||||||
|
if (rc < 0)
|
||||||
|
goto out_err;
|
||||||
|
if (rc == 0)
|
||||||
|
break;
|
||||||
|
p += rc;
|
||||||
|
brtw -= rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = 0;
|
||||||
|
goto out;
|
||||||
|
out_err:
|
||||||
|
rc = -1;
|
||||||
|
out:
|
||||||
|
if (buffer)
|
||||||
|
free(buffer);
|
||||||
|
if (fd1 >= 0)
|
||||||
|
close(fd1);
|
||||||
|
if (fd2 >= 0)
|
||||||
|
close(fd2);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
int do_chown(int nargs, char **args) {
|
int do_chown(int nargs, char **args) {
|
||||||
/* GID is optional. */
|
/* GID is optional. */
|
||||||
if (nargs == 3) {
|
if (nargs == 3) {
|
||||||
|
|
|
||||||
|
|
@ -95,21 +95,28 @@ static struct perms_ devperms[] = {
|
||||||
/* logger should be world writable (for logging) but not readable */
|
/* logger should be world writable (for logging) but not readable */
|
||||||
{ "/dev/log/", 0662, AID_ROOT, AID_LOG, 1 },
|
{ "/dev/log/", 0662, AID_ROOT, AID_LOG, 1 },
|
||||||
|
|
||||||
|
/* the msm hw3d client device node is world writable/readable. */
|
||||||
|
{ "/dev/msm_hw3dc", 0666, AID_ROOT, AID_ROOT, 0 },
|
||||||
|
|
||||||
|
/* gpu driver for adreno200 is globally accessible */
|
||||||
|
{ "/dev/kgsl", 0666, AID_ROOT, AID_ROOT, 0 },
|
||||||
|
|
||||||
/* these should not be world writable */
|
/* these should not be world writable */
|
||||||
|
{ "/dev/diag", 0660, AID_RADIO, AID_RADIO, 0 },
|
||||||
|
{ "/dev/diag_arm9", 0660, AID_RADIO, AID_RADIO, 0 },
|
||||||
{ "/dev/android_adb", 0660, AID_ADB, AID_ADB, 0 },
|
{ "/dev/android_adb", 0660, AID_ADB, AID_ADB, 0 },
|
||||||
{ "/dev/android_adb_enable", 0660, AID_ADB, AID_ADB, 0 },
|
{ "/dev/android_adb_enable", 0660, AID_ADB, AID_ADB, 0 },
|
||||||
{ "/dev/ttyMSM0", 0600, AID_BLUETOOTH, AID_BLUETOOTH, 0 },
|
{ "/dev/ttyMSM0", 0600, AID_BLUETOOTH, AID_BLUETOOTH, 0 },
|
||||||
{ "/dev/ttyHS0", 0600, AID_BLUETOOTH, AID_BLUETOOTH, 0 },
|
{ "/dev/ttyHS0", 0600, AID_BLUETOOTH, AID_BLUETOOTH, 0 },
|
||||||
{ "/dev/uinput", 0600, AID_BLUETOOTH, AID_BLUETOOTH, 0 },
|
{ "/dev/uinput", 0660, AID_SYSTEM, AID_BLUETOOTH, 0 },
|
||||||
{ "/dev/alarm", 0664, AID_SYSTEM, AID_RADIO, 0 },
|
{ "/dev/alarm", 0664, AID_SYSTEM, AID_RADIO, 0 },
|
||||||
{ "/dev/tty0", 0660, AID_ROOT, AID_SYSTEM, 0 },
|
{ "/dev/tty0", 0660, AID_ROOT, AID_SYSTEM, 0 },
|
||||||
{ "/dev/graphics/", 0660, AID_ROOT, AID_GRAPHICS, 1 },
|
{ "/dev/graphics/", 0660, AID_ROOT, AID_GRAPHICS, 1 },
|
||||||
{ "/dev/hw3d", 0660, AID_SYSTEM, AID_GRAPHICS, 0 },
|
{ "/dev/msm_hw3dm", 0660, AID_SYSTEM, AID_GRAPHICS, 0 },
|
||||||
{ "/dev/input/", 0660, AID_ROOT, AID_INPUT, 1 },
|
{ "/dev/input/", 0660, AID_ROOT, AID_INPUT, 1 },
|
||||||
{ "/dev/eac", 0660, AID_ROOT, AID_AUDIO, 0 },
|
{ "/dev/eac", 0660, AID_ROOT, AID_AUDIO, 0 },
|
||||||
{ "/dev/cam", 0660, AID_ROOT, AID_CAMERA, 0 },
|
{ "/dev/cam", 0660, AID_ROOT, AID_CAMERA, 0 },
|
||||||
{ "/dev/pmem", 0660, AID_SYSTEM, AID_GRAPHICS, 0 },
|
{ "/dev/pmem", 0660, AID_SYSTEM, AID_GRAPHICS, 0 },
|
||||||
{ "/dev/pmem_gpu", 0660, AID_SYSTEM, AID_GRAPHICS, 1 },
|
|
||||||
{ "/dev/pmem_adsp", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
{ "/dev/pmem_adsp", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
||||||
{ "/dev/pmem_camera", 0660, AID_SYSTEM, AID_CAMERA, 1 },
|
{ "/dev/pmem_camera", 0660, AID_SYSTEM, AID_CAMERA, 1 },
|
||||||
{ "/dev/oncrpc/", 0660, AID_ROOT, AID_SYSTEM, 1 },
|
{ "/dev/oncrpc/", 0660, AID_ROOT, AID_SYSTEM, 1 },
|
||||||
|
|
@ -119,20 +126,34 @@ static struct perms_ devperms[] = {
|
||||||
{ "/dev/msm_camera/", 0660, AID_SYSTEM, AID_SYSTEM, 1 },
|
{ "/dev/msm_camera/", 0660, AID_SYSTEM, AID_SYSTEM, 1 },
|
||||||
{ "/dev/akm8976_daemon",0640, AID_COMPASS, AID_SYSTEM, 0 },
|
{ "/dev/akm8976_daemon",0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||||
{ "/dev/akm8976_aot", 0640, AID_COMPASS, AID_SYSTEM, 0 },
|
{ "/dev/akm8976_aot", 0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||||
|
{ "/dev/akm8973_daemon",0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||||
|
{ "/dev/akm8973_aot", 0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||||
|
{ "/dev/bma150", 0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||||
|
{ "/dev/cm3602", 0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||||
{ "/dev/akm8976_pffd", 0640, AID_COMPASS, AID_SYSTEM, 0 },
|
{ "/dev/akm8976_pffd", 0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||||
|
{ "/dev/lightsensor", 0640, AID_SYSTEM, AID_SYSTEM, 0 },
|
||||||
{ "/dev/msm_pcm_out", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
{ "/dev/msm_pcm_out", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
||||||
{ "/dev/msm_pcm_in", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
{ "/dev/msm_pcm_in", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
||||||
{ "/dev/msm_pcm_ctl", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
{ "/dev/msm_pcm_ctl", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
||||||
{ "/dev/msm_snd", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
{ "/dev/msm_snd", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
||||||
{ "/dev/msm_mp3", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
{ "/dev/msm_mp3", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
||||||
|
{ "/dev/audience_a1026", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
||||||
{ "/dev/msm_audpre", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
{ "/dev/msm_audpre", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
||||||
|
{ "/dev/msm_audio_ctl", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
||||||
{ "/dev/htc-acoustic", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
{ "/dev/htc-acoustic", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
||||||
|
{ "/dev/vdec", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
||||||
|
{ "/dev/q6venc", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
||||||
|
{ "/dev/snd/dsp", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
||||||
|
{ "/dev/snd/dsp1", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
||||||
|
{ "/dev/snd/mixer", 0660, AID_SYSTEM, AID_AUDIO, 0 },
|
||||||
{ "/dev/smd0", 0640, AID_RADIO, AID_RADIO, 0 },
|
{ "/dev/smd0", 0640, AID_RADIO, AID_RADIO, 0 },
|
||||||
{ "/dev/qemu_trace", 0666, AID_SYSTEM, AID_SYSTEM, 0 },
|
{ "/dev/qemu_trace", 0666, AID_SYSTEM, AID_SYSTEM, 0 },
|
||||||
{ "/dev/qmi", 0640, AID_RADIO, AID_RADIO, 0 },
|
{ "/dev/qmi", 0640, AID_RADIO, AID_RADIO, 0 },
|
||||||
{ "/dev/qmi0", 0640, AID_RADIO, AID_RADIO, 0 },
|
{ "/dev/qmi0", 0640, AID_RADIO, AID_RADIO, 0 },
|
||||||
{ "/dev/qmi1", 0640, AID_RADIO, AID_RADIO, 0 },
|
{ "/dev/qmi1", 0640, AID_RADIO, AID_RADIO, 0 },
|
||||||
{ "/dev/qmi2", 0640, AID_RADIO, AID_RADIO, 0 },
|
{ "/dev/qmi2", 0640, AID_RADIO, AID_RADIO, 0 },
|
||||||
|
/* CDMA radio interface MUX */
|
||||||
|
{ "/dev/ts0710mux", 0640, AID_RADIO, AID_RADIO, 1 },
|
||||||
{ "/dev/ppp", 0660, AID_RADIO, AID_VPN, 0 },
|
{ "/dev/ppp", 0660, AID_RADIO, AID_VPN, 0 },
|
||||||
{ "/dev/tun", 0640, AID_VPN, AID_VPN, 0 },
|
{ "/dev/tun", 0640, AID_VPN, AID_VPN, 0 },
|
||||||
{ NULL, 0, 0, 0, 0 },
|
{ NULL, 0, 0, 0, 0 },
|
||||||
|
|
|
||||||
10
init/init.c
10
init/init.c
|
|
@ -253,10 +253,11 @@ void service_start(struct service *svc, const char *dynamic_args)
|
||||||
setuid(svc->uid);
|
setuid(svc->uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dynamic_args)
|
if (!dynamic_args) {
|
||||||
if (execve(svc->args[0], (char**) svc->args, (char**) ENV) < 0)
|
if (execve(svc->args[0], (char**) svc->args, (char**) ENV) < 0) {
|
||||||
ERROR("cannot execve('%s'): %s\n", svc->args[0], strerror(errno));
|
ERROR("cannot execve('%s'): %s\n", svc->args[0], strerror(errno));
|
||||||
else {
|
}
|
||||||
|
} else {
|
||||||
char *arg_ptrs[SVC_MAXARGS+1];
|
char *arg_ptrs[SVC_MAXARGS+1];
|
||||||
int arg_idx = svc->nargs;
|
int arg_idx = svc->nargs;
|
||||||
char *tmp = strdup(dynamic_args);
|
char *tmp = strdup(dynamic_args);
|
||||||
|
|
@ -272,8 +273,7 @@ void service_start(struct service *svc, const char *dynamic_args)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
arg_ptrs[arg_idx] = '\0';
|
arg_ptrs[arg_idx] = '\0';
|
||||||
if (execve(svc->args[0], (char**) arg_ptrs, (char**) ENV) < 0)
|
execve(svc->args[0], (char**) arg_ptrs, (char**) ENV);
|
||||||
ERROR("cannot execve('%s'): %s\n", svc->args[0], strerror(errno));
|
|
||||||
}
|
}
|
||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ int do_trigger(int nargs, char **args);
|
||||||
int do_symlink(int nargs, char **args);
|
int do_symlink(int nargs, char **args);
|
||||||
int do_sysclktz(int nargs, char **args);
|
int do_sysclktz(int nargs, char **args);
|
||||||
int do_write(int nargs, char **args);
|
int do_write(int nargs, char **args);
|
||||||
|
int do_copy(int nargs, char **args);
|
||||||
int do_chown(int nargs, char **args);
|
int do_chown(int nargs, char **args);
|
||||||
int do_chmod(int nargs, char **args);
|
int do_chmod(int nargs, char **args);
|
||||||
int do_loglevel(int nargs, char **args);
|
int do_loglevel(int nargs, char **args);
|
||||||
|
|
@ -69,6 +70,7 @@ enum {
|
||||||
KEYWORD(sysclktz, COMMAND, 1, do_sysclktz)
|
KEYWORD(sysclktz, COMMAND, 1, do_sysclktz)
|
||||||
KEYWORD(user, OPTION, 0, 0)
|
KEYWORD(user, OPTION, 0, 0)
|
||||||
KEYWORD(write, COMMAND, 2, do_write)
|
KEYWORD(write, COMMAND, 2, do_write)
|
||||||
|
KEYWORD(copy, COMMAND, 2, do_copy)
|
||||||
KEYWORD(chown, COMMAND, 2, do_chown)
|
KEYWORD(chown, COMMAND, 2, do_chown)
|
||||||
KEYWORD(chmod, COMMAND, 2, do_chmod)
|
KEYWORD(chmod, COMMAND, 2, do_chmod)
|
||||||
KEYWORD(loglevel, COMMAND, 1, do_loglevel)
|
KEYWORD(loglevel, COMMAND, 1, do_loglevel)
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ int lookup_keyword(const char *s)
|
||||||
{
|
{
|
||||||
switch (*s++) {
|
switch (*s++) {
|
||||||
case 'c':
|
case 'c':
|
||||||
|
if (!strcmp(s, "opy")) return K_copy;
|
||||||
if (!strcmp(s, "apability")) return K_capability;
|
if (!strcmp(s, "apability")) return K_capability;
|
||||||
if (!strcmp(s, "hdir")) return K_chdir;
|
if (!strcmp(s, "hdir")) return K_chdir;
|
||||||
if (!strcmp(s, "hroot")) return K_chroot;
|
if (!strcmp(s, "hroot")) return K_chroot;
|
||||||
|
|
|
||||||
|
|
@ -52,29 +52,32 @@ static int persistent_properties_loaded = 0;
|
||||||
struct {
|
struct {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
unsigned int uid;
|
unsigned int uid;
|
||||||
|
unsigned int gid;
|
||||||
} property_perms[] = {
|
} property_perms[] = {
|
||||||
{ "net.rmnet0.", AID_RADIO },
|
{ "net.rmnet0.", AID_RADIO, 0 },
|
||||||
{ "net.gprs.", AID_RADIO },
|
{ "net.gprs.", AID_RADIO, 0 },
|
||||||
{ "ril.", AID_RADIO },
|
{ "net.ppp", AID_RADIO, 0 },
|
||||||
{ "gsm.", AID_RADIO },
|
{ "ril.", AID_RADIO, 0 },
|
||||||
{ "net.dns", AID_RADIO },
|
{ "gsm.", AID_RADIO, 0 },
|
||||||
{ "net.", AID_SYSTEM },
|
{ "persist.radio", AID_RADIO, 0 },
|
||||||
{ "dev.", AID_SYSTEM },
|
{ "net.dns", AID_RADIO, 0 },
|
||||||
{ "runtime.", AID_SYSTEM },
|
{ "net.", AID_SYSTEM, 0 },
|
||||||
{ "hw.", AID_SYSTEM },
|
{ "dev.", AID_SYSTEM, 0 },
|
||||||
{ "sys.", AID_SYSTEM },
|
{ "runtime.", AID_SYSTEM, 0 },
|
||||||
{ "service.", AID_SYSTEM },
|
{ "hw.", AID_SYSTEM, 0 },
|
||||||
{ "wlan.", AID_SYSTEM },
|
{ "sys.", AID_SYSTEM, 0 },
|
||||||
{ "dhcp.", AID_SYSTEM },
|
{ "service.", AID_SYSTEM, 0 },
|
||||||
{ "dhcp.", AID_DHCP },
|
{ "wlan.", AID_SYSTEM, 0 },
|
||||||
{ "vpn.", AID_SYSTEM },
|
{ "dhcp.", AID_SYSTEM, 0 },
|
||||||
{ "vpn.", AID_VPN },
|
{ "dhcp.", AID_DHCP, 0 },
|
||||||
{ "debug.", AID_SHELL },
|
{ "vpn.", AID_SYSTEM, 0 },
|
||||||
{ "log.", AID_SHELL },
|
{ "vpn.", AID_VPN, 0 },
|
||||||
{ "service.adb.root", AID_SHELL },
|
{ "debug.", AID_SHELL, 0 },
|
||||||
{ "persist.sys.", AID_SYSTEM },
|
{ "log.", AID_SHELL, 0 },
|
||||||
{ "persist.service.", AID_SYSTEM },
|
{ "service.adb.root", AID_SHELL, 0 },
|
||||||
{ NULL, 0 }
|
{ "persist.sys.", AID_SYSTEM, 0 },
|
||||||
|
{ "persist.service.", AID_SYSTEM, 0 },
|
||||||
|
{ NULL, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -84,8 +87,10 @@ struct {
|
||||||
struct {
|
struct {
|
||||||
const char *service;
|
const char *service;
|
||||||
unsigned int uid;
|
unsigned int uid;
|
||||||
|
unsigned int gid;
|
||||||
} control_perms[] = {
|
} control_perms[] = {
|
||||||
{NULL, 0 }
|
{ "dumpstate",AID_SHELL, AID_LOG },
|
||||||
|
{NULL, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -181,7 +186,7 @@ static int property_write(prop_info *pi, const char *value)
|
||||||
*
|
*
|
||||||
* Returns 1 if uid allowed, 0 otherwise.
|
* Returns 1 if uid allowed, 0 otherwise.
|
||||||
*/
|
*/
|
||||||
static int check_control_perms(const char *name, int uid) {
|
static int check_control_perms(const char *name, int uid, int gid) {
|
||||||
int i;
|
int i;
|
||||||
if (uid == AID_SYSTEM || uid == AID_ROOT)
|
if (uid == AID_SYSTEM || uid == AID_ROOT)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -189,8 +194,10 @@ static int check_control_perms(const char *name, int uid) {
|
||||||
/* Search the ACL */
|
/* Search the ACL */
|
||||||
for (i = 0; control_perms[i].service; i++) {
|
for (i = 0; control_perms[i].service; i++) {
|
||||||
if (strcmp(control_perms[i].service, name) == 0) {
|
if (strcmp(control_perms[i].service, name) == 0) {
|
||||||
if (control_perms[i].uid == uid)
|
if ((uid && control_perms[i].uid == uid) ||
|
||||||
|
(gid && control_perms[i].gid == gid)) {
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -200,7 +207,7 @@ static int check_control_perms(const char *name, int uid) {
|
||||||
* Checks permissions for setting system properties.
|
* Checks permissions for setting system properties.
|
||||||
* Returns 1 if uid allowed, 0 otherwise.
|
* Returns 1 if uid allowed, 0 otherwise.
|
||||||
*/
|
*/
|
||||||
static int check_perms(const char *name, unsigned int uid)
|
static int check_perms(const char *name, unsigned int uid, int gid)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if (uid == 0)
|
if (uid == 0)
|
||||||
|
|
@ -213,7 +220,8 @@ static int check_perms(const char *name, unsigned int uid)
|
||||||
int tmp;
|
int tmp;
|
||||||
if (strncmp(property_perms[i].prefix, name,
|
if (strncmp(property_perms[i].prefix, name,
|
||||||
strlen(property_perms[i].prefix)) == 0) {
|
strlen(property_perms[i].prefix)) == 0) {
|
||||||
if (property_perms[i].uid == uid) {
|
if ((uid && property_perms[i].uid == uid) ||
|
||||||
|
(gid && property_perms[i].gid == gid)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -237,7 +245,7 @@ const char* property_get(const char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_peristent_property(const char *name, const char *value)
|
static void write_persistent_property(const char *name, const char *value)
|
||||||
{
|
{
|
||||||
const char *tempPath = PERSISTENT_PROPERTY_DIR "/.temp";
|
const char *tempPath = PERSISTENT_PROPERTY_DIR "/.temp";
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
@ -248,7 +256,7 @@ static void write_peristent_property(const char *name, const char *value)
|
||||||
fd = open(tempPath, O_WRONLY|O_CREAT|O_TRUNC, 0600);
|
fd = open(tempPath, O_WRONLY|O_CREAT|O_TRUNC, 0600);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
ERROR("Unable to write persistent property to temp file %s errno: %d\n", tempPath, errno);
|
ERROR("Unable to write persistent property to temp file %s errno: %d\n", tempPath, errno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
write(fd, value, strlen(value));
|
write(fd, value, strlen(value));
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
@ -302,7 +310,7 @@ int property_set(const char *name, const char *value)
|
||||||
if (strcmp("net.change", name) == 0) {
|
if (strcmp("net.change", name) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* The 'net.change' property is a special property used track when any
|
* The 'net.change' property is a special property used track when any
|
||||||
* 'net.*' property name is updated. It is _ONLY_ updated here. Its value
|
* 'net.*' property name is updated. It is _ONLY_ updated here. Its value
|
||||||
* contains the last updated 'net.*' property.
|
* contains the last updated 'net.*' property.
|
||||||
|
|
@ -310,11 +318,11 @@ int property_set(const char *name, const char *value)
|
||||||
property_set("net.change", name);
|
property_set("net.change", name);
|
||||||
} else if (persistent_properties_loaded &&
|
} else if (persistent_properties_loaded &&
|
||||||
strncmp("persist.", name, strlen("persist.")) == 0) {
|
strncmp("persist.", name, strlen("persist.")) == 0) {
|
||||||
/*
|
/*
|
||||||
* Don't write properties to disk until after we have read all default properties
|
* Don't write properties to disk until after we have read all default properties
|
||||||
* to prevent them from being overwritten by default values.
|
* to prevent them from being overwritten by default values.
|
||||||
*/
|
*/
|
||||||
write_peristent_property(name, value);
|
write_persistent_property(name, value);
|
||||||
}
|
}
|
||||||
property_changed(name, value);
|
property_changed(name, value);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -371,14 +379,14 @@ void handle_property_set_fd(int fd)
|
||||||
msg.value[PROP_VALUE_MAX-1] = 0;
|
msg.value[PROP_VALUE_MAX-1] = 0;
|
||||||
|
|
||||||
if(memcmp(msg.name,"ctl.",4) == 0) {
|
if(memcmp(msg.name,"ctl.",4) == 0) {
|
||||||
if (check_control_perms(msg.value, cr.uid)) {
|
if (check_control_perms(msg.value, cr.uid, cr.gid)) {
|
||||||
handle_control_message((char*) msg.name + 4, (char*) msg.value);
|
handle_control_message((char*) msg.name + 4, (char*) msg.value);
|
||||||
} else {
|
} else {
|
||||||
ERROR("sys_prop: Unable to %s service ctl [%s] uid: %d pid:%d\n",
|
ERROR("sys_prop: Unable to %s service ctl [%s] uid: %d pid:%d\n",
|
||||||
msg.name + 4, msg.value, cr.uid, cr.pid);
|
msg.name + 4, msg.value, cr.uid, cr.pid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (check_perms(msg.name, cr.uid)) {
|
if (check_perms(msg.name, cr.uid, cr.gid)) {
|
||||||
property_set((char*) msg.name, (char*) msg.value);
|
property_set((char*) msg.name, (char*) msg.value);
|
||||||
} else {
|
} else {
|
||||||
ERROR("sys_prop: permission denied uid:%d name:%s\n",
|
ERROR("sys_prop: permission denied uid:%d name:%s\n",
|
||||||
|
|
@ -474,7 +482,7 @@ static void load_persistent_properties()
|
||||||
} else {
|
} else {
|
||||||
ERROR("Unable to open persistent property directory %s errno: %d\n", PERSISTENT_PROPERTY_DIR, errno);
|
ERROR("Unable to open persistent property directory %s errno: %d\n", PERSISTENT_PROPERTY_DIR, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
persistent_properties_loaded = 1;
|
persistent_properties_loaded = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
31
libacc/Android.mk
Normal file
31
libacc/Android.mk
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
LOCAL_PATH:= $(call my-dir)
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
# Shared library for target
|
||||||
|
# ========================================================
|
||||||
|
|
||||||
|
LOCAL_MODULE:= libacc
|
||||||
|
LOCAL_SRC_FILES := acc.cpp
|
||||||
|
|
||||||
|
LOCAL_SHARED_LIBRARIES := libdl libcutils
|
||||||
|
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
# Shared library for host
|
||||||
|
# ========================================================
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE:= libacc
|
||||||
|
LOCAL_SRC_FILES := acc.cpp
|
||||||
|
|
||||||
|
LOCAL_CFLAGS := -O0 -g
|
||||||
|
|
||||||
|
LOCAL_STATIC_LIBRARIES := libcutils
|
||||||
|
LOCAL_LDLIBS := -ldl
|
||||||
|
|
||||||
|
include $(BUILD_HOST_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
# Build children
|
||||||
|
# ========================================================
|
||||||
|
|
||||||
|
include $(call all-makefiles-under,$(LOCAL_PATH))
|
||||||
83
libacc/FEATURES
Normal file
83
libacc/FEATURES
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
|
||||||
|
Supported C language subset:
|
||||||
|
|
||||||
|
- Expressions:
|
||||||
|
|
||||||
|
* binary operators, by decreasing priority order: '*' '/' '%',
|
||||||
|
'+' '-', '>>' '<<', '<' '<=' '>' '>=', '==' '!=', '&',
|
||||||
|
'^', '|', '=', '&&', '||'.
|
||||||
|
|
||||||
|
* '&&' and '||' have the same semantics as C : left to right
|
||||||
|
evaluation and early exit.
|
||||||
|
|
||||||
|
* Parenthesis are supported.
|
||||||
|
|
||||||
|
* Comma operator is supported.
|
||||||
|
|
||||||
|
* Trinary operator (?:) is not supported.
|
||||||
|
|
||||||
|
* Unary operators: '&', '*' (pointer indirection), '-'
|
||||||
|
(negation), '+', '!', '~', '++' and '--'.
|
||||||
|
|
||||||
|
* Pointer indirection ('*') is supported.
|
||||||
|
|
||||||
|
* Square brackets can be used for pointer arithmetic.
|
||||||
|
|
||||||
|
* '=' and <op>= are supported.
|
||||||
|
|
||||||
|
* Function calls are supported with standard Linux calling
|
||||||
|
convention. Function pointers are supported.
|
||||||
|
Functions can be used before being declared.
|
||||||
|
|
||||||
|
- sizeof() is not supported.
|
||||||
|
|
||||||
|
- Types:
|
||||||
|
+ int, short, char, float, double
|
||||||
|
+ pointers
|
||||||
|
+ variables can be initialized in declarations.
|
||||||
|
+ Only ANSI-style function declarations are supported.
|
||||||
|
- "..." is not supported.
|
||||||
|
- short is not supported
|
||||||
|
- const is not supported
|
||||||
|
- arrays are not supported
|
||||||
|
- long doubles are not supported
|
||||||
|
- structs are not supported
|
||||||
|
|
||||||
|
- Unknown functions and variables are bound at compile time by calling
|
||||||
|
back to the caller. For the 'acc' command-line tool unknown functions
|
||||||
|
and variables are looked up using dlsym, to allow using many libc
|
||||||
|
functions and variables.
|
||||||
|
|
||||||
|
- Instructions: blocks ('{' '}') are supported as in C. 'if' and
|
||||||
|
'else' can be used for tests. The 'while' and 'for' C constructs
|
||||||
|
are supported for loops. 'break' can be used to exit
|
||||||
|
loops. 'return' is used for the return value of a function.
|
||||||
|
|
||||||
|
- switch / case is not supported.
|
||||||
|
- goto and labels are not supported.
|
||||||
|
- continue is not supported.
|
||||||
|
|
||||||
|
- Identifiers are parsed the same way as C. Local variables are
|
||||||
|
handled, but there is no local name space (not a problem if
|
||||||
|
different names are used for local and global variables).
|
||||||
|
|
||||||
|
- Numbers can be entered in decimal, hexadecimal ('0x' or '0X'
|
||||||
|
prefix), or octal ('0' prefix).
|
||||||
|
|
||||||
|
- Float and double constants are supported.
|
||||||
|
|
||||||
|
- '#define' is supported without function like arguments. No macro
|
||||||
|
recursion is tolerated. Other preprocessor directives are
|
||||||
|
ignored.
|
||||||
|
|
||||||
|
- C Strings and C character constants are supported. All ANSI C
|
||||||
|
character escapes are supported.
|
||||||
|
|
||||||
|
- Both C comments ( /* */ ) and C++ comments ( // ... end-of-line ) are
|
||||||
|
supported.
|
||||||
|
|
||||||
|
- Some syntax errors are reported, others may cause a crash.
|
||||||
|
|
||||||
|
- Memory: the code, data, and symbol sizes are limited to 100KB
|
||||||
|
(it can be changed in the source code).
|
||||||
|
|
||||||
21
libacc/LICENSE
Normal file
21
libacc/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
Obfuscated Tiny C Compiler
|
||||||
|
|
||||||
|
Copyright (C) 2001-2003 Fabrice Bellard
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product and its documentation
|
||||||
|
*is* required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
|
||||||
0
libacc/MODULE_LICENSE_BSD_LIKE
Normal file
0
libacc/MODULE_LICENSE_BSD_LIKE
Normal file
6241
libacc/acc.cpp
Normal file
6241
libacc/acc.cpp
Normal file
File diff suppressed because it is too large
Load diff
2
libacc/tests/.gitignore
vendored
Normal file
2
libacc/tests/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
test-acc
|
||||||
|
*.out
|
||||||
66
libacc/tests/Android.mk
Normal file
66
libacc/tests/Android.mk
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
LOCAL_PATH:= $(call my-dir)
|
||||||
|
|
||||||
|
# Executable for host
|
||||||
|
# ========================================================
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE:= acc
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES:= \
|
||||||
|
main.cpp
|
||||||
|
|
||||||
|
LOCAL_SHARED_LIBRARIES := \
|
||||||
|
libacc
|
||||||
|
|
||||||
|
LOCAL_MODULE_TAGS := tests
|
||||||
|
|
||||||
|
include $(BUILD_HOST_EXECUTABLE)
|
||||||
|
|
||||||
|
# Executable for target
|
||||||
|
# ========================================================
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE:= acc
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES:= \
|
||||||
|
main.cpp \
|
||||||
|
disassem.cpp
|
||||||
|
|
||||||
|
LOCAL_SHARED_LIBRARIES := \
|
||||||
|
libacc
|
||||||
|
|
||||||
|
LOCAL_CFLAGS := -O0 -g
|
||||||
|
|
||||||
|
LOCAL_MODULE_TAGS := tests
|
||||||
|
|
||||||
|
include $(BUILD_EXECUTABLE)
|
||||||
|
|
||||||
|
# Runtime tests for host
|
||||||
|
# ========================================================
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE:= accRuntimeTest
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES:= \
|
||||||
|
runtimeTest.cpp
|
||||||
|
|
||||||
|
LOCAL_SHARED_LIBRARIES := \
|
||||||
|
libacc
|
||||||
|
|
||||||
|
LOCAL_MODULE_TAGS := tests
|
||||||
|
|
||||||
|
include $(BUILD_HOST_EXECUTABLE)
|
||||||
|
|
||||||
|
# Runtime tests for target
|
||||||
|
# ========================================================
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE:= accRuntimeTest
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES:= \
|
||||||
|
runtimeTest.cpp
|
||||||
|
|
||||||
|
LOCAL_SHARED_LIBRARIES := \
|
||||||
|
libacc
|
||||||
|
|
||||||
|
LOCAL_CFLAGS := -O0 -g
|
||||||
|
|
||||||
|
LOCAL_MODULE_TAGS := tests
|
||||||
|
|
||||||
|
include $(BUILD_EXECUTABLE)
|
||||||
69
libacc/tests/accarm
Executable file
69
libacc/tests/accarm
Executable file
|
|
@ -0,0 +1,69 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
#
|
||||||
|
# Run a test on the ARM version of acc.
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def compile(args):
|
||||||
|
proc = subprocess.Popen(["acc"] + args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
result = proc.communicate()
|
||||||
|
return result
|
||||||
|
|
||||||
|
def runCmd(args):
|
||||||
|
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
result = proc.communicate()
|
||||||
|
return result[0].strip()
|
||||||
|
|
||||||
|
def uname():
|
||||||
|
return runCmd(["uname"])
|
||||||
|
|
||||||
|
def unameM():
|
||||||
|
return runCmd(["uname", "-m"])
|
||||||
|
|
||||||
|
def which(item):
|
||||||
|
return runCmd(["which", item])
|
||||||
|
|
||||||
|
def adb(args):
|
||||||
|
return runCmd(["adb"] + args)
|
||||||
|
|
||||||
|
def setupArm(file):
|
||||||
|
print "Setting up arm"
|
||||||
|
adb(["remount"])
|
||||||
|
adb(["shell", "rm", "/system/bin/acc"])
|
||||||
|
adb(["shell", "mkdir", "/system/bin/accdata"])
|
||||||
|
adb(["shell", "mkdir", "/system/bin/accdata/data"])
|
||||||
|
|
||||||
|
remoteFileName = os.path.join("/system/bin/accdata", file)
|
||||||
|
adb(["push", file, remoteFileName])
|
||||||
|
|
||||||
|
# Copy over compiler
|
||||||
|
adb(["sync"])
|
||||||
|
return remoteFileName
|
||||||
|
|
||||||
|
def compileArm(args):
|
||||||
|
remoteArgs = []
|
||||||
|
fileName = ""
|
||||||
|
for arg in sys.argv[1:]:
|
||||||
|
if arg.startswith('-'):
|
||||||
|
remoteArgs.append(arg)
|
||||||
|
else:
|
||||||
|
fileName = arg
|
||||||
|
|
||||||
|
remoteFileName = setupArm(fileName)
|
||||||
|
remoteArgs.append(remoteFileName)
|
||||||
|
remoteCmdLine = ["adb", "shell", "/system/bin/acc"] + remoteArgs
|
||||||
|
proc = subprocess.Popen(remoteCmdLine, stdout=subprocess.PIPE)
|
||||||
|
result = proc.communicate()
|
||||||
|
return result[0].replace("\r","")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print compileArm(sys.argv[1:])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
||||||
300
libacc/tests/armreg.h
Normal file
300
libacc/tests/armreg.h
Normal file
|
|
@ -0,0 +1,300 @@
|
||||||
|
/* $NetBSD: armreg.h,v 1.28 2003/10/31 16:30:15 scw Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1998, 2001 Ben Harris
|
||||||
|
* Copyright (c) 1994-1996 Mark Brinicombe.
|
||||||
|
* Copyright (c) 1994 Brini.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software written for Brini by Mark Brinicombe
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by Brini.
|
||||||
|
* 4. The name of the company nor the name of the author may be used to
|
||||||
|
* endorse or promote products derived from this software without specific
|
||||||
|
* prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* $FreeBSD: /repoman/r/ncvs/src/sys/arm/include/armreg.h,v 1.3 2005/11/21 19:06:25 cognet Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MACHINE_ARMREG_H
|
||||||
|
#define MACHINE_ARMREG_H
|
||||||
|
#define INSN_SIZE 4
|
||||||
|
#define INSN_COND_MASK 0xf0000000 /* Condition mask */
|
||||||
|
#define PSR_MODE 0x0000001f /* mode mask */
|
||||||
|
#define PSR_USR26_MODE 0x00000000
|
||||||
|
#define PSR_FIQ26_MODE 0x00000001
|
||||||
|
#define PSR_IRQ26_MODE 0x00000002
|
||||||
|
#define PSR_SVC26_MODE 0x00000003
|
||||||
|
#define PSR_USR32_MODE 0x00000010
|
||||||
|
#define PSR_FIQ32_MODE 0x00000011
|
||||||
|
#define PSR_IRQ32_MODE 0x00000012
|
||||||
|
#define PSR_SVC32_MODE 0x00000013
|
||||||
|
#define PSR_ABT32_MODE 0x00000017
|
||||||
|
#define PSR_UND32_MODE 0x0000001b
|
||||||
|
#define PSR_SYS32_MODE 0x0000001f
|
||||||
|
#define PSR_32_MODE 0x00000010
|
||||||
|
#define PSR_FLAGS 0xf0000000 /* flags */
|
||||||
|
|
||||||
|
#define PSR_C_bit (1 << 29) /* carry */
|
||||||
|
|
||||||
|
/* The high-order byte is always the implementor */
|
||||||
|
#define CPU_ID_IMPLEMENTOR_MASK 0xff000000
|
||||||
|
#define CPU_ID_ARM_LTD 0x41000000 /* 'A' */
|
||||||
|
#define CPU_ID_DEC 0x44000000 /* 'D' */
|
||||||
|
#define CPU_ID_INTEL 0x69000000 /* 'i' */
|
||||||
|
#define CPU_ID_TI 0x54000000 /* 'T' */
|
||||||
|
|
||||||
|
/* How to decide what format the CPUID is in. */
|
||||||
|
#define CPU_ID_ISOLD(x) (((x) & 0x0000f000) == 0x00000000)
|
||||||
|
#define CPU_ID_IS7(x) (((x) & 0x0000f000) == 0x00007000)
|
||||||
|
#define CPU_ID_ISNEW(x) (!CPU_ID_ISOLD(x) && !CPU_ID_IS7(x))
|
||||||
|
|
||||||
|
/* On ARM3 and ARM6, this byte holds the foundry ID. */
|
||||||
|
#define CPU_ID_FOUNDRY_MASK 0x00ff0000
|
||||||
|
#define CPU_ID_FOUNDRY_VLSI 0x00560000
|
||||||
|
|
||||||
|
/* On ARM7 it holds the architecture and variant (sub-model) */
|
||||||
|
#define CPU_ID_7ARCH_MASK 0x00800000
|
||||||
|
#define CPU_ID_7ARCH_V3 0x00000000
|
||||||
|
#define CPU_ID_7ARCH_V4T 0x00800000
|
||||||
|
#define CPU_ID_7VARIANT_MASK 0x007f0000
|
||||||
|
|
||||||
|
/* On more recent ARMs, it does the same, but in a different format */
|
||||||
|
#define CPU_ID_ARCH_MASK 0x000f0000
|
||||||
|
#define CPU_ID_ARCH_V3 0x00000000
|
||||||
|
#define CPU_ID_ARCH_V4 0x00010000
|
||||||
|
#define CPU_ID_ARCH_V4T 0x00020000
|
||||||
|
#define CPU_ID_ARCH_V5 0x00030000
|
||||||
|
#define CPU_ID_ARCH_V5T 0x00040000
|
||||||
|
#define CPU_ID_ARCH_V5TE 0x00050000
|
||||||
|
#define CPU_ID_VARIANT_MASK 0x00f00000
|
||||||
|
|
||||||
|
/* Next three nybbles are part number */
|
||||||
|
#define CPU_ID_PARTNO_MASK 0x0000fff0
|
||||||
|
|
||||||
|
/* Intel XScale has sub fields in part number */
|
||||||
|
#define CPU_ID_XSCALE_COREGEN_MASK 0x0000e000 /* core generation */
|
||||||
|
#define CPU_ID_XSCALE_COREREV_MASK 0x00001c00 /* core revision */
|
||||||
|
#define CPU_ID_XSCALE_PRODUCT_MASK 0x000003f0 /* product number */
|
||||||
|
|
||||||
|
/* And finally, the revision number. */
|
||||||
|
#define CPU_ID_REVISION_MASK 0x0000000f
|
||||||
|
|
||||||
|
/* Individual CPUs are probably best IDed by everything but the revision. */
|
||||||
|
#define CPU_ID_CPU_MASK 0xfffffff0
|
||||||
|
|
||||||
|
/* Fake CPU IDs for ARMs without CP15 */
|
||||||
|
#define CPU_ID_ARM2 0x41560200
|
||||||
|
#define CPU_ID_ARM250 0x41560250
|
||||||
|
|
||||||
|
/* Pre-ARM7 CPUs -- [15:12] == 0 */
|
||||||
|
#define CPU_ID_ARM3 0x41560300
|
||||||
|
#define CPU_ID_ARM600 0x41560600
|
||||||
|
#define CPU_ID_ARM610 0x41560610
|
||||||
|
#define CPU_ID_ARM620 0x41560620
|
||||||
|
|
||||||
|
/* ARM7 CPUs -- [15:12] == 7 */
|
||||||
|
#define CPU_ID_ARM700 0x41007000 /* XXX This is a guess. */
|
||||||
|
#define CPU_ID_ARM710 0x41007100
|
||||||
|
#define CPU_ID_ARM7500 0x41027100 /* XXX This is a guess. */
|
||||||
|
#define CPU_ID_ARM710A 0x41047100 /* inc ARM7100 */
|
||||||
|
#define CPU_ID_ARM7500FE 0x41077100
|
||||||
|
#define CPU_ID_ARM710T 0x41807100
|
||||||
|
#define CPU_ID_ARM720T 0x41807200
|
||||||
|
#define CPU_ID_ARM740T8K 0x41807400 /* XXX no MMU, 8KB cache */
|
||||||
|
#define CPU_ID_ARM740T4K 0x41817400 /* XXX no MMU, 4KB cache */
|
||||||
|
|
||||||
|
/* Post-ARM7 CPUs */
|
||||||
|
#define CPU_ID_ARM810 0x41018100
|
||||||
|
#define CPU_ID_ARM920T 0x41129200
|
||||||
|
#define CPU_ID_ARM920T_ALT 0x41009200
|
||||||
|
#define CPU_ID_ARM922T 0x41029220
|
||||||
|
#define CPU_ID_ARM940T 0x41029400 /* XXX no MMU */
|
||||||
|
#define CPU_ID_ARM946ES 0x41049460 /* XXX no MMU */
|
||||||
|
#define CPU_ID_ARM966ES 0x41049660 /* XXX no MMU */
|
||||||
|
#define CPU_ID_ARM966ESR1 0x41059660 /* XXX no MMU */
|
||||||
|
#define CPU_ID_ARM1020E 0x4115a200 /* (AKA arm10 rev 1) */
|
||||||
|
#define CPU_ID_ARM1022ES 0x4105a220
|
||||||
|
#define CPU_ID_SA110 0x4401a100
|
||||||
|
#define CPU_ID_SA1100 0x4401a110
|
||||||
|
#define CPU_ID_TI925T 0x54029250
|
||||||
|
#define CPU_ID_SA1110 0x6901b110
|
||||||
|
#define CPU_ID_IXP1200 0x6901c120
|
||||||
|
#define CPU_ID_80200 0x69052000
|
||||||
|
#define CPU_ID_PXA250 0x69052100 /* sans core revision */
|
||||||
|
#define CPU_ID_PXA210 0x69052120
|
||||||
|
#define CPU_ID_PXA250A 0x69052100 /* 1st version Core */
|
||||||
|
#define CPU_ID_PXA210A 0x69052120 /* 1st version Core */
|
||||||
|
#define CPU_ID_PXA250B 0x69052900 /* 3rd version Core */
|
||||||
|
#define CPU_ID_PXA210B 0x69052920 /* 3rd version Core */
|
||||||
|
#define CPU_ID_PXA250C 0x69052d00 /* 4th version Core */
|
||||||
|
#define CPU_ID_PXA210C 0x69052d20 /* 4th version Core */
|
||||||
|
#define CPU_ID_80321_400 0x69052420
|
||||||
|
#define CPU_ID_80321_600 0x69052430
|
||||||
|
#define CPU_ID_80321_400_B0 0x69052c20
|
||||||
|
#define CPU_ID_80321_600_B0 0x69052c30
|
||||||
|
#define CPU_ID_IXP425_533 0x690541c0
|
||||||
|
#define CPU_ID_IXP425_400 0x690541d0
|
||||||
|
#define CPU_ID_IXP425_266 0x690541f0
|
||||||
|
|
||||||
|
/* ARM3-specific coprocessor 15 registers */
|
||||||
|
#define ARM3_CP15_FLUSH 1
|
||||||
|
#define ARM3_CP15_CONTROL 2
|
||||||
|
#define ARM3_CP15_CACHEABLE 3
|
||||||
|
#define ARM3_CP15_UPDATEABLE 4
|
||||||
|
#define ARM3_CP15_DISRUPTIVE 5
|
||||||
|
|
||||||
|
/* ARM3 Control register bits */
|
||||||
|
#define ARM3_CTL_CACHE_ON 0x00000001
|
||||||
|
#define ARM3_CTL_SHARED 0x00000002
|
||||||
|
#define ARM3_CTL_MONITOR 0x00000004
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Post-ARM3 CP15 registers:
|
||||||
|
*
|
||||||
|
* 1 Control register
|
||||||
|
*
|
||||||
|
* 2 Translation Table Base
|
||||||
|
*
|
||||||
|
* 3 Domain Access Control
|
||||||
|
*
|
||||||
|
* 4 Reserved
|
||||||
|
*
|
||||||
|
* 5 Fault Status
|
||||||
|
*
|
||||||
|
* 6 Fault Address
|
||||||
|
*
|
||||||
|
* 7 Cache/write-buffer Control
|
||||||
|
*
|
||||||
|
* 8 TLB Control
|
||||||
|
*
|
||||||
|
* 9 Cache Lockdown
|
||||||
|
*
|
||||||
|
* 10 TLB Lockdown
|
||||||
|
*
|
||||||
|
* 11 Reserved
|
||||||
|
*
|
||||||
|
* 12 Reserved
|
||||||
|
*
|
||||||
|
* 13 Process ID (for FCSE)
|
||||||
|
*
|
||||||
|
* 14 Reserved
|
||||||
|
*
|
||||||
|
* 15 Implementation Dependent
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Some of the definitions below need cleaning up for V3/V4 architectures */
|
||||||
|
|
||||||
|
/* CPU control register (CP15 register 1) */
|
||||||
|
#define CPU_CONTROL_MMU_ENABLE 0x00000001 /* M: MMU/Protection unit enable */
|
||||||
|
#define CPU_CONTROL_AFLT_ENABLE 0x00000002 /* A: Alignment fault enable */
|
||||||
|
#define CPU_CONTROL_DC_ENABLE 0x00000004 /* C: IDC/DC enable */
|
||||||
|
#define CPU_CONTROL_WBUF_ENABLE 0x00000008 /* W: Write buffer enable */
|
||||||
|
#define CPU_CONTROL_32BP_ENABLE 0x00000010 /* P: 32-bit exception handlers */
|
||||||
|
#define CPU_CONTROL_32BD_ENABLE 0x00000020 /* D: 32-bit addressing */
|
||||||
|
#define CPU_CONTROL_LABT_ENABLE 0x00000040 /* L: Late abort enable */
|
||||||
|
#define CPU_CONTROL_BEND_ENABLE 0x00000080 /* B: Big-endian mode */
|
||||||
|
#define CPU_CONTROL_SYST_ENABLE 0x00000100 /* S: System protection bit */
|
||||||
|
#define CPU_CONTROL_ROM_ENABLE 0x00000200 /* R: ROM protection bit */
|
||||||
|
#define CPU_CONTROL_CPCLK 0x00000400 /* F: Implementation defined */
|
||||||
|
#define CPU_CONTROL_BPRD_ENABLE 0x00000800 /* Z: Branch prediction enable */
|
||||||
|
#define CPU_CONTROL_IC_ENABLE 0x00001000 /* I: IC enable */
|
||||||
|
#define CPU_CONTROL_VECRELOC 0x00002000 /* V: Vector relocation */
|
||||||
|
#define CPU_CONTROL_ROUNDROBIN 0x00004000 /* RR: Predictable replacement */
|
||||||
|
#define CPU_CONTROL_V4COMPAT 0x00008000 /* L4: ARMv4 compat LDR R15 etc */
|
||||||
|
|
||||||
|
#define CPU_CONTROL_IDC_ENABLE CPU_CONTROL_DC_ENABLE
|
||||||
|
|
||||||
|
/* XScale Auxillary Control Register (CP15 register 1, opcode2 1) */
|
||||||
|
#define XSCALE_AUXCTL_K 0x00000001 /* dis. write buffer coalescing */
|
||||||
|
#define XSCALE_AUXCTL_P 0x00000002 /* ECC protect page table access */
|
||||||
|
#define XSCALE_AUXCTL_MD_WB_RA 0x00000000 /* mini-D$ wb, read-allocate */
|
||||||
|
#define XSCALE_AUXCTL_MD_WB_RWA 0x00000010 /* mini-D$ wb, read/write-allocate */
|
||||||
|
#define XSCALE_AUXCTL_MD_WT 0x00000020 /* mini-D$ wt, read-allocate */
|
||||||
|
#define XSCALE_AUXCTL_MD_MASK 0x00000030
|
||||||
|
|
||||||
|
/* Cache type register definitions */
|
||||||
|
#define CPU_CT_ISIZE(x) ((x) & 0xfff) /* I$ info */
|
||||||
|
#define CPU_CT_DSIZE(x) (((x) >> 12) & 0xfff) /* D$ info */
|
||||||
|
#define CPU_CT_S (1U << 24) /* split cache */
|
||||||
|
#define CPU_CT_CTYPE(x) (((x) >> 25) & 0xf) /* cache type */
|
||||||
|
|
||||||
|
#define CPU_CT_CTYPE_WT 0 /* write-through */
|
||||||
|
#define CPU_CT_CTYPE_WB1 1 /* write-back, clean w/ read */
|
||||||
|
#define CPU_CT_CTYPE_WB2 2 /* w/b, clean w/ cp15,7 */
|
||||||
|
#define CPU_CT_CTYPE_WB6 6 /* w/b, cp15,7, lockdown fmt A */
|
||||||
|
#define CPU_CT_CTYPE_WB7 7 /* w/b, cp15,7, lockdown fmt B */
|
||||||
|
|
||||||
|
#define CPU_CT_xSIZE_LEN(x) ((x) & 0x3) /* line size */
|
||||||
|
#define CPU_CT_xSIZE_M (1U << 2) /* multiplier */
|
||||||
|
#define CPU_CT_xSIZE_ASSOC(x) (((x) >> 3) & 0x7) /* associativity */
|
||||||
|
#define CPU_CT_xSIZE_SIZE(x) (((x) >> 6) & 0x7) /* size */
|
||||||
|
|
||||||
|
/* Fault status register definitions */
|
||||||
|
|
||||||
|
#define FAULT_TYPE_MASK 0x0f
|
||||||
|
#define FAULT_USER 0x10
|
||||||
|
|
||||||
|
#define FAULT_WRTBUF_0 0x00 /* Vector Exception */
|
||||||
|
#define FAULT_WRTBUF_1 0x02 /* Terminal Exception */
|
||||||
|
#define FAULT_BUSERR_0 0x04 /* External Abort on Linefetch -- Section */
|
||||||
|
#define FAULT_BUSERR_1 0x06 /* External Abort on Linefetch -- Page */
|
||||||
|
#define FAULT_BUSERR_2 0x08 /* External Abort on Non-linefetch -- Section */
|
||||||
|
#define FAULT_BUSERR_3 0x0a /* External Abort on Non-linefetch -- Page */
|
||||||
|
#define FAULT_BUSTRNL1 0x0c /* External abort on Translation -- Level 1 */
|
||||||
|
#define FAULT_BUSTRNL2 0x0e /* External abort on Translation -- Level 2 */
|
||||||
|
#define FAULT_ALIGN_0 0x01 /* Alignment */
|
||||||
|
#define FAULT_ALIGN_1 0x03 /* Alignment */
|
||||||
|
#define FAULT_TRANS_S 0x05 /* Translation -- Section */
|
||||||
|
#define FAULT_TRANS_P 0x07 /* Translation -- Page */
|
||||||
|
#define FAULT_DOMAIN_S 0x09 /* Domain -- Section */
|
||||||
|
#define FAULT_DOMAIN_P 0x0b /* Domain -- Page */
|
||||||
|
#define FAULT_PERM_S 0x0d /* Permission -- Section */
|
||||||
|
#define FAULT_PERM_P 0x0f /* Permission -- Page */
|
||||||
|
|
||||||
|
#define FAULT_IMPRECISE 0x400 /* Imprecise exception (XSCALE) */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Address of the vector page, low and high versions.
|
||||||
|
*/
|
||||||
|
#define ARM_VECTORS_LOW 0x00000000U
|
||||||
|
#define ARM_VECTORS_HIGH 0xffff0000U
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ARM Instructions
|
||||||
|
*
|
||||||
|
* 3 3 2 2 2
|
||||||
|
* 1 0 9 8 7 0
|
||||||
|
* +-------+-------------------------------------------------------+
|
||||||
|
* | cond | instruction dependant |
|
||||||
|
* |c c c c| |
|
||||||
|
* +-------+-------------------------------------------------------+
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define INSN_SIZE 4 /* Always 4 bytes */
|
||||||
|
#define INSN_COND_MASK 0xf0000000 /* Condition mask */
|
||||||
|
#define INSN_COND_AL 0xe0000000 /* Always condition */
|
||||||
|
|
||||||
|
#endif /* !MACHINE_ARMREG_H */
|
||||||
31
libacc/tests/data/addressOf.c
Normal file
31
libacc/tests/data/addressOf.c
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
void testStruct() {
|
||||||
|
struct str {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct str base;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
base.x = 10.0;
|
||||||
|
struct str *s = &base;
|
||||||
|
|
||||||
|
float *v = &(*s).x;
|
||||||
|
float *v2 = &s[index].x;
|
||||||
|
printf("testStruct: %g %g %g\n",base.x, *v, *v2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testArray() {
|
||||||
|
int a[2];
|
||||||
|
a[0] = 1;
|
||||||
|
a[1] = 2;
|
||||||
|
int* p = &a[0];
|
||||||
|
int* p2 = a;
|
||||||
|
printf("testArray: %d %d %d\n", a[0], *p, *p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
testStruct();
|
||||||
|
testArray();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
107
libacc/tests/data/array.c
Normal file
107
libacc/tests/data/array.c
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
// Array allocation tests
|
||||||
|
|
||||||
|
void testLocalInt()
|
||||||
|
{
|
||||||
|
int a[3];
|
||||||
|
a[0] = 1;
|
||||||
|
a[1] = 2;
|
||||||
|
a[2] = a[0] + a[1];
|
||||||
|
printf("localInt: %d\n", a[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
char a[3];
|
||||||
|
double d[3];
|
||||||
|
|
||||||
|
void testGlobalChar()
|
||||||
|
{
|
||||||
|
a[0] = 1;
|
||||||
|
a[1] = 2;
|
||||||
|
a[2] = a[0] + a[1];
|
||||||
|
printf("globalChar: %d\n", a[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testGlobalDouble()
|
||||||
|
{
|
||||||
|
d[0] = 1;
|
||||||
|
d[1] = 2;
|
||||||
|
d[2] = d[0] + d[1];
|
||||||
|
printf("globalDouble: %g\n", d[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testLocalDouble()
|
||||||
|
{
|
||||||
|
double d[3];
|
||||||
|
float m[12];
|
||||||
|
m[0] = 1.0f;
|
||||||
|
m[1] = 2.0f;
|
||||||
|
d[0] = 1.0;
|
||||||
|
d[1] = 2.0;
|
||||||
|
d[2] = d[0] + d[1];
|
||||||
|
m[2] = m[0] + m[1];
|
||||||
|
printf("localDouble: %g %g\n", d[2], m[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vectorAdd(int* a, int* b, float* c, int len) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < len; i++) {
|
||||||
|
c[i] = a[i] + b[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void testArgs() {
|
||||||
|
int a[3], b[3];
|
||||||
|
float c[3];
|
||||||
|
int i;
|
||||||
|
int len = 3;
|
||||||
|
for(i = 0; i < len; i++) {
|
||||||
|
a[i] = i;
|
||||||
|
b[i] = i;
|
||||||
|
c[i] = 0;
|
||||||
|
}
|
||||||
|
vectorAdd(a,b,c, len);
|
||||||
|
printf("testArgs:");
|
||||||
|
for(i = 0; i < len; i++) {
|
||||||
|
printf(" %g", c[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void testDecay() {
|
||||||
|
char c[4];
|
||||||
|
c[0] = 'H';
|
||||||
|
c[1] = 'i';
|
||||||
|
c[2] = '!';
|
||||||
|
c[3] = 0;
|
||||||
|
printf("testDecay: %s\n", c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test2D() {
|
||||||
|
char c[10][20];
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
printf("test2D:\n");
|
||||||
|
for(y = 0; y < 10; y++) {
|
||||||
|
for(x = 0; x < 20; x++) {
|
||||||
|
c[y][x] = 'a' + (15 & (y * 19 + x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(y = 0; y < 10; y++) {
|
||||||
|
for(x = 0; x < 20; x++) {
|
||||||
|
printf("%c", c[y][x]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
testLocalInt();
|
||||||
|
testLocalDouble();
|
||||||
|
testGlobalChar();
|
||||||
|
testGlobalDouble();
|
||||||
|
testArgs();
|
||||||
|
testDecay();
|
||||||
|
test2D();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
9
libacc/tests/data/assignment.c
Normal file
9
libacc/tests/data/assignment.c
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
int main() {
|
||||||
|
int a = 0;
|
||||||
|
int b = 1;
|
||||||
|
a = b = 2; // Test that "b = 2" generates an rvalue.
|
||||||
|
if (a = 7) { // Test that a = 7 generates an rvalue.
|
||||||
|
b = 3;
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
62
libacc/tests/data/assignmentop.c
Normal file
62
libacc/tests/data/assignmentop.c
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
// Test assignment operations
|
||||||
|
|
||||||
|
void testAssignment() {
|
||||||
|
int a = 2;
|
||||||
|
a *= 5;
|
||||||
|
printf("2 *= 5 %d\n", a);
|
||||||
|
a = 20;
|
||||||
|
a /= 5;
|
||||||
|
printf("20 /= 5 %d\n", a);
|
||||||
|
a = 17;
|
||||||
|
a %= 5;
|
||||||
|
printf("17 %%= 5 %d\n", a);
|
||||||
|
a = 17;
|
||||||
|
a += 5;
|
||||||
|
printf("17 += 5 %d\n", a);
|
||||||
|
a = 17;
|
||||||
|
a-=5;
|
||||||
|
printf("17 -= 5 %d\n", a);
|
||||||
|
a = 17;
|
||||||
|
a<<=1;
|
||||||
|
printf("17<<= 1 %d\n", a);
|
||||||
|
a = 17;
|
||||||
|
a>>=1;
|
||||||
|
printf("17>>= 1 %d\n", a);
|
||||||
|
a = 17;
|
||||||
|
a&=1;
|
||||||
|
printf("17&= 1 %d\n", a);
|
||||||
|
a = 17;
|
||||||
|
a^=1;
|
||||||
|
printf("17^= 1 %d\n", a);
|
||||||
|
a = 16;
|
||||||
|
a^=1;
|
||||||
|
printf("16|= 1 %d\n", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
int a;
|
||||||
|
|
||||||
|
int* f() {
|
||||||
|
printf("f()\n");
|
||||||
|
return &a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testEval() {
|
||||||
|
a = 0;
|
||||||
|
printf("*f() = *f() + 10;\n");
|
||||||
|
*f() = *f() + 10;
|
||||||
|
printf("a = %d\n", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testOpEval() {
|
||||||
|
a = 0;
|
||||||
|
printf("*f() += 10;\n");
|
||||||
|
*f() += 10;
|
||||||
|
printf("a = %d\n", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
testAssignment();
|
||||||
|
testEval();
|
||||||
|
testOpEval();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
9
libacc/tests/data/b2071670.c
Normal file
9
libacc/tests/data/b2071670.c
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
// See http://b/2071670
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
float f = 10.0f;
|
||||||
|
float* floatPointer = &f;
|
||||||
|
// The following line used to incorrectly error: "Incompatible pointer or array types"
|
||||||
|
int* buffer = (int*) floatPointer;
|
||||||
|
return *buffer;
|
||||||
|
}
|
||||||
126
libacc/tests/data/bellard.otccex.c
Normal file
126
libacc/tests/data/bellard.otccex.c
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
/* #!/usr/local/bin/otcc */
|
||||||
|
/*
|
||||||
|
* Sample OTCC C example. You can uncomment the first line and install
|
||||||
|
* otcc in /usr/local/bin to make otcc scripts !
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Any preprocessor directive except #define are ignored. We put this
|
||||||
|
include so that a standard C compiler can compile this code too. */
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* defines are handled, but macro arguments cannot be given. No
|
||||||
|
recursive defines are tolerated */
|
||||||
|
#define DEFAULT_BASE 10
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only old style K&R prototypes are parsed. Only int arguments are
|
||||||
|
* allowed (implicit types).
|
||||||
|
*
|
||||||
|
* By benchmarking the execution time of this function (for example
|
||||||
|
* for fib(35)), you'll notice that OTCC is quite fast because it
|
||||||
|
* generates native i386 machine code.
|
||||||
|
*/
|
||||||
|
fib(n)
|
||||||
|
{
|
||||||
|
if (n <= 2)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return fib(n-1) + fib(n-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Identifiers are parsed the same way as C: begins with letter or
|
||||||
|
'_', and then letters, '_' or digits */
|
||||||
|
fact(n)
|
||||||
|
{
|
||||||
|
/* local variables can be declared. Only 'int' type is supported */
|
||||||
|
int i, r;
|
||||||
|
r = 1;
|
||||||
|
/* 'while' and 'for' loops are supported */
|
||||||
|
for(i=2;i<=n;i++)
|
||||||
|
r = r * i;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Well, we could use printf, but it would be too easy */
|
||||||
|
print_num(n, b)
|
||||||
|
{
|
||||||
|
int tab, p, c;
|
||||||
|
/* Numbers can be entered in decimal, hexadecimal ('0x' prefix) and
|
||||||
|
octal ('0' prefix) */
|
||||||
|
/* more complex programs use malloc */
|
||||||
|
tab = malloc(0x100);
|
||||||
|
p = tab;
|
||||||
|
while (1) {
|
||||||
|
c = n % b;
|
||||||
|
/* Character constants can be used */
|
||||||
|
if (c >= 10)
|
||||||
|
c = c + 'a' - 10;
|
||||||
|
else
|
||||||
|
c = c + '0';
|
||||||
|
*(char *)p = c;
|
||||||
|
p++;
|
||||||
|
n = n / b;
|
||||||
|
/* 'break' is supported */
|
||||||
|
if (n == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (p != tab) {
|
||||||
|
p--;
|
||||||
|
printf("%c", *(char *)p);
|
||||||
|
}
|
||||||
|
free(tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 'main' takes standard 'argc' and 'argv' parameters */
|
||||||
|
main(argc, argv)
|
||||||
|
{
|
||||||
|
/* no local name space is supported, but local variables ARE
|
||||||
|
supported. As long as you do not use a globally defined
|
||||||
|
variable name as local variable (which is a bad habbit), you
|
||||||
|
won't have any problem */
|
||||||
|
int s, n, f, base;
|
||||||
|
|
||||||
|
/* && and || operator have the same semantics as C (left to right
|
||||||
|
evaluation and early exit) */
|
||||||
|
if (argc != 2 && argc != 3) {
|
||||||
|
/* '*' operator is supported with explicit casting to 'int *',
|
||||||
|
'char *' or 'int (*)()' (function pointer). Of course, 'int'
|
||||||
|
are supposed to be used as pointers too. */
|
||||||
|
s = *(int *)argv;
|
||||||
|
help(s);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* Any libc function can be used because OTCC uses dynamic linking */
|
||||||
|
n = atoi(*(int *)(argv + 4));
|
||||||
|
base = DEFAULT_BASE;
|
||||||
|
if (argc >= 3) {
|
||||||
|
base = atoi(*(int *)(argv + 8));
|
||||||
|
if (base < 2 || base > 36) {
|
||||||
|
/* external variables can be used too (here: 'stderr') */
|
||||||
|
fprintf(stderr, "Invalid base\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("fib(%d) = ", n);
|
||||||
|
print_num(fib(n), base);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
printf("fact(%d) = ", n);
|
||||||
|
if (n > 12) {
|
||||||
|
printf("Overflow");
|
||||||
|
} else {
|
||||||
|
/* why not using a function pointer ? */
|
||||||
|
f = &fact;
|
||||||
|
print_num((*(int (*)())f)(n), base);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* functions can be used before being defined */
|
||||||
|
help(name)
|
||||||
|
{
|
||||||
|
printf("usage: %s n [base]\n", name);
|
||||||
|
printf("Compute fib(n) and fact(n) and output the result in base 'base'\n");
|
||||||
|
}
|
||||||
|
|
||||||
61
libacc/tests/data/brackets.c
Normal file
61
libacc/tests/data/brackets.c
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
void testBrackets(int* ar, int len) {
|
||||||
|
int i;
|
||||||
|
int errors = 0;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
ar[i] = i;
|
||||||
|
}
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
if (ar[i] != i) {
|
||||||
|
printf("error: [%d] %d != %d\n", i, ar[i], i);
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Errors: %d\n", errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testBrackets2D(int** ar2D, int lenX, int lenY) {
|
||||||
|
int x, y;
|
||||||
|
int errors = 0;
|
||||||
|
for (x = 0; x < lenX; x++) {
|
||||||
|
for (y = 0; y < lenY; y++) {
|
||||||
|
ar2D[x][y] = x * lenY + y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (x = 0; x < lenX; x++) {
|
||||||
|
for (y = 0; y < lenY; y++) {
|
||||||
|
int expected = x * lenY + y;
|
||||||
|
int val = ar2D[x][y];
|
||||||
|
if (val != expected) {
|
||||||
|
printf("error: [%d][%d] %d != %d\n", x, y, val, expected);
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("2D Errors: %d\n", errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testHeap() {
|
||||||
|
int* ar = (int*) malloc(100);
|
||||||
|
testBrackets(ar, 25);
|
||||||
|
free(ar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testHeap2D() {
|
||||||
|
int lenX = 10;
|
||||||
|
int lenY = 5;
|
||||||
|
int* ar = (int*) malloc(lenX * lenY * 4);
|
||||||
|
int** ar2D = (int**) malloc(lenX * 4);
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < lenX; i++) {
|
||||||
|
ar2D[i] = ar + lenY * i;
|
||||||
|
}
|
||||||
|
testBrackets2D(ar2D, lenX, lenY);
|
||||||
|
free(ar);
|
||||||
|
free(ar2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
testHeap();
|
||||||
|
testHeap2D();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
85
libacc/tests/data/casts.c
Normal file
85
libacc/tests/data/casts.c
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
void test1() {
|
||||||
|
int a = 3;
|
||||||
|
int* pb = &a;
|
||||||
|
int c = *pb;
|
||||||
|
printf("Reading from a pointer: %d %d\n", a, c);
|
||||||
|
*pb = 4;
|
||||||
|
printf("Writing to a pointer: %d\n", a);
|
||||||
|
printf("Testing casts: %d %g %g %d\n", 3, (float) 3, 4.5, (int) 4.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test2() {
|
||||||
|
int x = 4;
|
||||||
|
int px = &x;
|
||||||
|
// int z = * px; // An error, expected a pointer type
|
||||||
|
int y = * (int*) px;
|
||||||
|
printf("Testing reading (int*): %d\n", y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test3() {
|
||||||
|
int px = (int) malloc(120);
|
||||||
|
* (int*) px = 8;
|
||||||
|
* (int*) (px + 4) = 9;
|
||||||
|
printf("Testing writing (int*): %d %d\n", * (int*) px, * (int*) (px + 4));
|
||||||
|
free((void*) px);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test4() {
|
||||||
|
int x = 0x12345678;
|
||||||
|
int px = &x;
|
||||||
|
int a = * (char*) px;
|
||||||
|
int b = * (char*) (px + 1);
|
||||||
|
int c = * (char*) (px + 2);
|
||||||
|
int d = * (char*) (px + 3);
|
||||||
|
printf("Testing reading (char*): 0x%02x 0x%02x 0x%02x 0x%02x\n", a, b, c, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test5() {
|
||||||
|
int x = 0xFFFFFFFF;
|
||||||
|
int px = &x;
|
||||||
|
* (char*) px = 0x21;
|
||||||
|
* (char*) (px + 1) = 0x43;
|
||||||
|
* (char*) (px + 2) = 0x65;
|
||||||
|
* (char*) (px + 3) = 0x87;
|
||||||
|
printf("Testing writing (char*): 0x%08x\n", x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int f(int b) {
|
||||||
|
printf("f(%d)\n", b);
|
||||||
|
return 7 * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test6() {
|
||||||
|
int fp = &f;
|
||||||
|
int x = (*(int(*)()) fp)(10);
|
||||||
|
printf("Function pointer result: %d\n", x);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test7() {
|
||||||
|
int px = (int) malloc(120);
|
||||||
|
* (float*) px = 8.8f;
|
||||||
|
* (float*) (px + 4) = 9.9f;
|
||||||
|
printf("Testing read/write (float*): %g %g\n", * (float*) px, * (float*) (px + 4));
|
||||||
|
free((void*) px);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test8() {
|
||||||
|
int px = (int) malloc(120);
|
||||||
|
* (double*) px = 8.8;
|
||||||
|
* (double*) (px + 8) = 9.9;
|
||||||
|
printf("Testing read/write (double*): %g %g\n", * (double*) px, * (double*) (px + 8));
|
||||||
|
free((void*) px);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
test1();
|
||||||
|
test2();
|
||||||
|
test3();
|
||||||
|
test4();
|
||||||
|
test5();
|
||||||
|
test6();
|
||||||
|
test7();
|
||||||
|
test8();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
13
libacc/tests/data/char.c
Normal file
13
libacc/tests/data/char.c
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
char ga;
|
||||||
|
char gb;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
char a = 'c';
|
||||||
|
char b = a * 3;
|
||||||
|
printf("a = %d, b = %d\n", a, b);
|
||||||
|
ga = 'd';
|
||||||
|
gb = ga * 3;
|
||||||
|
printf("ga = %d, gb = %d\n", ga, gb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
35
libacc/tests/data/comma.c
Normal file
35
libacc/tests/data/comma.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
int testReturn() {
|
||||||
|
return 10, 20, 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
int testArg(int a) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testComma() {
|
||||||
|
int a;
|
||||||
|
0, a = 10,20;
|
||||||
|
printf("statement: %d\n", a);
|
||||||
|
a = 1;
|
||||||
|
if (a = 0, 1) {
|
||||||
|
printf("if: a = %d\n", a);
|
||||||
|
}
|
||||||
|
int b = 0;
|
||||||
|
a = 10;
|
||||||
|
while(b++,a--) {}
|
||||||
|
printf("while: b = %d\n", b);
|
||||||
|
b = 0;
|
||||||
|
for(b++,a = 0;b++, a < 10; b++, a++) {}
|
||||||
|
printf("for: b = %d\n", b);
|
||||||
|
b = testReturn();
|
||||||
|
printf("return: %d\n", b);
|
||||||
|
b = testArg((a,12));
|
||||||
|
printf("arg: %d\n", b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
testComma();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
30
libacc/tests/data/constants.c
Normal file
30
libacc/tests/data/constants.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#define FOO 0x10
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("0 = %d\n", 0);
|
||||||
|
printf("010 = %d\n", 010);
|
||||||
|
printf("0x10 = %d\n", FOO);
|
||||||
|
printf("'\\a' = %d\n", '\a');
|
||||||
|
printf("'\\b' = %d\n", '\b');
|
||||||
|
printf("'\\f' = %d\n", '\f');
|
||||||
|
printf("'\\n' = %d\n", '\n');
|
||||||
|
printf("'\\r' = %d\n", '\r');
|
||||||
|
printf("'\\t' = %d\n", '\t');
|
||||||
|
printf("'\\v' = %d\n", '\v');
|
||||||
|
// Undefined
|
||||||
|
// printf("'\\z' = %d\n", '\z');
|
||||||
|
printf("'\\\\' = %d\n", '\\');
|
||||||
|
printf("'\\'' = %d\n", '\'');
|
||||||
|
printf("'\\\"' = %d\n", '\"');
|
||||||
|
printf("'\\?' = %d\n", '\?');
|
||||||
|
printf("'\\0' = %d\n", '\0');
|
||||||
|
printf("'\\1' = %d\n", '\1');
|
||||||
|
printf("'\\12' = %d\n", '\12');
|
||||||
|
printf("'\\123' = %d\n", '\123');
|
||||||
|
printf("'\\x0' = %d\n", '\x0');
|
||||||
|
printf("'\\x1' = %d\n", '\x1');
|
||||||
|
printf("'\\x12' = %d\n", '\x12');
|
||||||
|
printf("'\\x123' = %d\n", '\x123');
|
||||||
|
printf("'\\x1f' = %d\n", '\x1f');
|
||||||
|
printf("'\\x1F' = %d\n", '\x1F');
|
||||||
|
}
|
||||||
9
libacc/tests/data/defines.c
Normal file
9
libacc/tests/data/defines.c
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
// Simple tests of the C preprocessor
|
||||||
|
|
||||||
|
#define A 1
|
||||||
|
#define A (4 / 2)
|
||||||
|
#define B 1 // This is a comment. With a / in it.
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
return A + B;
|
||||||
|
}
|
||||||
7
libacc/tests/data/double.c
Normal file
7
libacc/tests/data/double.c
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
double atof(char *nptr);
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("Value = %g\n", atof("10.42"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
2
libacc/tests/data/error.c
Normal file
2
libacc/tests/data/error.c
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
void foo;
|
||||||
|
|
||||||
60
libacc/tests/data/expr-ansi.c
Normal file
60
libacc/tests/data/expr-ansi.c
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* Test operators */
|
||||||
|
|
||||||
|
void testInc() { int a, b; a = 3; b = a++; printf("3++ = %d %d\n", b, a); }
|
||||||
|
void testDec() { int a, b; a = 3; b = a--; printf("3-- = %d %d\n", b, a); }
|
||||||
|
void testTimes(){ printf("%d * %d = %d\n", 10, 4, 10 * 4); }
|
||||||
|
void testDiv(){ printf("%d / %d = %d\n", 11, 4, 11 / 4); }
|
||||||
|
void testMod(){ printf("%d %% %d = %d\n", 11, 4, 11 % 4); }
|
||||||
|
void testPlus(){ printf("%d + %d = %d\n", 10, 4, 10 + 4); }
|
||||||
|
void testMinus(){ printf("%d - %d = %d\n", 10, 4, 10 - 4); }
|
||||||
|
void testShiftLeft(){ printf("%d << %d = %d\n", 10, 4, 10 << 4); }
|
||||||
|
void testShiftRight(){ printf("%d >> %d = %d\n", 100, 4, 100 >> 4); }
|
||||||
|
void testLess(){ printf("%d < %d = %d\n", 10, 4, 10 < 4); }
|
||||||
|
void testLesEqual(){ printf("%d <= %d = %d\n", 10, 4, 10 <= 4); }
|
||||||
|
void testGreater(){ printf("%d > %d = %d\n", 10, 4, 10 > 4); }
|
||||||
|
void testGreaterEqual(){ printf("%d >= %d = %d\n", 10, 4, 10 >= 4); }
|
||||||
|
void testEqualTo(){ printf("%d == %d = %d\n", 10, 4, 10 == 4); }
|
||||||
|
void testNotEqualTo(){ printf("%d != %d = %d\n", 10, 4, 10 != 4); }
|
||||||
|
void testBitAnd(){ printf("%d & %d = %d\n", 10, 7, 10 & 7); }
|
||||||
|
void testBitXor(){ printf("%d ^ %d = %d\n", 10, 7, 10 ^ 7); }
|
||||||
|
void testBitOr(){ printf("%d | %d = %d\n", 10, 4, 10 | 4); }
|
||||||
|
void testAssignment(){ int a, b; a = 3; b = a; printf("b == %d\n", b); }
|
||||||
|
void testLogicalAnd(){ printf("%d && %d = %d\n", 10, 4, 10 && 4); }
|
||||||
|
void testLogicalOr(){ printf("%d || %d = %d\n", 10, 4, 10 || 4); }
|
||||||
|
void testAddressOf(){ int a; printf("&a is %d\n", &a); }
|
||||||
|
void testPointerIndirection(){ int a, b; a = &b; b = 17; printf("*%d = %d =?= %d\n", a, * (int*) a, b); }
|
||||||
|
void testNegation(){ printf("-%d = %d\n", 10, -10); }
|
||||||
|
void testUnaryPlus(){ printf("+%d = %d\n", 10, +10); }
|
||||||
|
void testUnaryNot(){ printf("!%d = %d\n", 10, !10); }
|
||||||
|
void testBitNot(){ printf("~%d = %d\n", 10, ~10); }
|
||||||
|
|
||||||
|
int main(int a, char** b) {
|
||||||
|
testInc();
|
||||||
|
testDec();
|
||||||
|
testTimes();
|
||||||
|
testDiv();
|
||||||
|
testMod();
|
||||||
|
testPlus();
|
||||||
|
testMinus();
|
||||||
|
testShiftLeft();
|
||||||
|
testShiftRight();
|
||||||
|
testLess();
|
||||||
|
testLesEqual();
|
||||||
|
testGreater();
|
||||||
|
testGreaterEqual();
|
||||||
|
testEqualTo();
|
||||||
|
testNotEqualTo();
|
||||||
|
testBitAnd();
|
||||||
|
testBinXor();
|
||||||
|
testBitOr();
|
||||||
|
testAssignment();
|
||||||
|
testLogicalAnd();
|
||||||
|
testLogicalOr();
|
||||||
|
testAddressOf();
|
||||||
|
testPointerIndirection();
|
||||||
|
testNegation();
|
||||||
|
testUnaryPlus();
|
||||||
|
testUnaryNot();
|
||||||
|
testBitNot();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
60
libacc/tests/data/expr.c
Normal file
60
libacc/tests/data/expr.c
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* Test operators */
|
||||||
|
|
||||||
|
testInc() { int a, b; a = 3; b = a++; printf("3++ = %d %d\n", b, a); }
|
||||||
|
testDec() { int a, b; a = 3; b = a--; printf("3-- = %d %d\n", b, a); }
|
||||||
|
testTimes(){ printf("%d * %d = %d\n", 10, 4, 10 * 4); }
|
||||||
|
testDiv(){ printf("%d / %d = %d\n", 11, 4, 11 / 4); }
|
||||||
|
testMod(){ printf("%d %% %d = %d\n", 11, 4, 11 % 4); }
|
||||||
|
testPlus(){ printf("%d + %d = %d\n", 10, 4, 10 + 4); }
|
||||||
|
testMinus(){ printf("%d - %d = %d\n", 10, 4, 10 - 4); }
|
||||||
|
testShiftLeft(){ printf("%d << %d = %d\n", 10, 4, 10 << 4); }
|
||||||
|
testShiftRight(){ printf("%d >> %d = %d\n", 100, 4, 100 >> 4); }
|
||||||
|
testLess(){ printf("%d < %d = %d\n", 10, 4, 10 < 4); }
|
||||||
|
testLesEqual(){ printf("%d <= %d = %d\n", 10, 4, 10 <= 4); }
|
||||||
|
testGreater(){ printf("%d > %d = %d\n", 10, 4, 10 > 4); }
|
||||||
|
testGreaterEqual(){ printf("%d >= %d = %d\n", 10, 4, 10 >= 4); }
|
||||||
|
testEqualTo(){ printf("%d == %d = %d\n", 10, 4, 10 == 4); }
|
||||||
|
testNotEqualTo(){ printf("%d != %d = %d\n", 10, 4, 10 != 4); }
|
||||||
|
testBitAnd(){ printf("%d & %d = %d\n", 10, 7, 10 & 7); }
|
||||||
|
testBitXor(){ printf("%d ^ %d = %d\n", 10, 7, 10 ^ 7); }
|
||||||
|
testBitOr(){ printf("%d | %d = %d\n", 10, 4, 10 | 4); }
|
||||||
|
testAssignment(){ int a, b; a = 3; b = a; printf("b == %d\n", b); }
|
||||||
|
testLogicalAnd(){ printf("%d && %d = %d\n", 10, 4, 10 && 4); }
|
||||||
|
testLogicalOr(){ printf("%d || %d = %d\n", 10, 4, 10 || 4); }
|
||||||
|
testAddressOf(){ int a; printf("&a is %d\n", &a); }
|
||||||
|
testPointerIndirection(){ int a, b; a = &b; b = 17; printf("*%d = %d =?= %d\n", a, * (int*) a, b); }
|
||||||
|
testNegation(){ printf("-%d = %d\n", 10, -10); }
|
||||||
|
testUnaryPlus(){ printf("+%d = %d\n", 10, +10); }
|
||||||
|
testUnaryNot(){ printf("!%d = %d\n", 10, !10); }
|
||||||
|
testBitNot(){ printf("~%d = %d\n", 10, ~10); }
|
||||||
|
|
||||||
|
main(a,b) {
|
||||||
|
testInc();
|
||||||
|
testDec();
|
||||||
|
testTimes();
|
||||||
|
testDiv();
|
||||||
|
testMod();
|
||||||
|
testPlus();
|
||||||
|
testMinus();
|
||||||
|
testShiftLeft();
|
||||||
|
testShiftRight();
|
||||||
|
testLess();
|
||||||
|
testLesEqual();
|
||||||
|
testGreater();
|
||||||
|
testGreaterEqual();
|
||||||
|
testEqualTo();
|
||||||
|
testNotEqualTo();
|
||||||
|
testBitAnd();
|
||||||
|
testBinXor();
|
||||||
|
testBitOr();
|
||||||
|
testAssignment();
|
||||||
|
testLogicalAnd();
|
||||||
|
testLogicalOr();
|
||||||
|
testAddressOf();
|
||||||
|
testPointerIndirection();
|
||||||
|
testNegation();
|
||||||
|
testUnaryPlus();
|
||||||
|
testUnaryNot();
|
||||||
|
testBitNot();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
6
libacc/tests/data/expr2.c
Normal file
6
libacc/tests/data/expr2.c
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
/* Test operators */
|
||||||
|
|
||||||
|
main() {
|
||||||
|
int a;
|
||||||
|
a = a++;
|
||||||
|
}
|
||||||
53
libacc/tests/data/film.c
Normal file
53
libacc/tests/data/film.c
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
// Test logical and bitwise AND and OR
|
||||||
|
|
||||||
|
int test(int x, int y) {
|
||||||
|
int v = x || y;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test2(int x, int y) {
|
||||||
|
if(x | y) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int test3(int x, int y) {
|
||||||
|
int v = x && y;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test4(int x, int y) {
|
||||||
|
if(x & y) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int index)
|
||||||
|
{
|
||||||
|
int x,y;
|
||||||
|
printf("testing...\n");
|
||||||
|
int totalBad = 0;
|
||||||
|
for(y = 0; y < 2; y++) {
|
||||||
|
for(x = 0; x < 2; x++) {
|
||||||
|
int a = test(x,y);
|
||||||
|
int b = test2(x,y);
|
||||||
|
if (a != b) {
|
||||||
|
printf("Results differ: OR x=%d y=%d a=%d b=%d\n", x, y, a, b);
|
||||||
|
totalBad++;
|
||||||
|
}
|
||||||
|
a = test3(x,y);
|
||||||
|
b = test4(x,y);
|
||||||
|
if (a != b) {
|
||||||
|
printf("Results differ: AND x=%d y=%d a=%d b=%d\n", x, y, a, b);
|
||||||
|
totalBad++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Total bad: %d\n", totalBad);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
57
libacc/tests/data/float.c
Normal file
57
libacc/tests/data/float.c
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
int ftoi(float f) {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dtoi(double d) {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
float itof(int i) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
double itod(int i) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
float f0, f1;
|
||||||
|
double d0, d1;
|
||||||
|
|
||||||
|
void testParseConsts() {
|
||||||
|
printf("Constants: %g %g %g %g %g %g %g %g %g\n", 0e1, 0E1, 0.f, .01f,
|
||||||
|
.01e0f, 1.0e-1, 1.0e1, 1.0e+1,
|
||||||
|
.1f);
|
||||||
|
}
|
||||||
|
void testVars(float arg0, float arg1, double arg2, double arg3) {
|
||||||
|
float local0, local1;
|
||||||
|
double local2, local3;
|
||||||
|
f0 = arg0;
|
||||||
|
f1 = arg1;
|
||||||
|
d0 = arg2;
|
||||||
|
d1 = arg3;
|
||||||
|
local0 = arg0;
|
||||||
|
local1 = arg1;
|
||||||
|
local2 = arg2;
|
||||||
|
local3 = arg3;
|
||||||
|
printf("globals: %g %g %g %g\n", f0, f1, d0, d1);
|
||||||
|
printf("args: %g %g %g %g\n", arg0, arg1, arg2, arg3);
|
||||||
|
printf("locals: %g %g %g %g\n", local0, local1, local2, local3);
|
||||||
|
|
||||||
|
|
||||||
|
printf("cast rval: %g %g\n", * (float*) & f1, * (double*) & d1);
|
||||||
|
|
||||||
|
* (float*) & f0 = 1.1f;
|
||||||
|
* (double*) & d0 = 3.3;
|
||||||
|
printf("cast lval: %g %g %g %g\n", f0, f1, d0, d1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
testParseConsts();
|
||||||
|
printf("int: %d float: %g double: %g\n", 1, 2.2f, 3.3);
|
||||||
|
printf(" ftoi(1.4f)=%d\n", ftoi(1.4f));
|
||||||
|
printf(" dtoi(2.4)=%d\n", dtoi(2.4));
|
||||||
|
printf(" itof(3)=%g\n", itof(3));
|
||||||
|
printf(" itod(4)=%g\n", itod(4));
|
||||||
|
testVars(1.0f, 2.0f, 3.0, 4.0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
9
libacc/tests/data/floatdouble.c
Normal file
9
libacc/tests/data/floatdouble.c
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Test coercing values when storing.
|
||||||
|
float a = 0.002;
|
||||||
|
double b = 0.1f;
|
||||||
|
int c = 10.002;
|
||||||
|
printf("%g %g %d\n", a, b, c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
158
libacc/tests/data/flops.c
Normal file
158
libacc/tests/data/flops.c
Normal file
|
|
@ -0,0 +1,158 @@
|
||||||
|
// Test floating point operations.
|
||||||
|
|
||||||
|
void unaryOps() {
|
||||||
|
// Unary ops
|
||||||
|
printf("-%g = %g\n", 1.1, -1.1);
|
||||||
|
printf("!%g = %d\n", 1.2, !1.2);
|
||||||
|
printf("!%g = %d\n", 0.0, !0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void binaryOps() {
|
||||||
|
printf("double op double:\n");
|
||||||
|
printf("%g + %g = %g\n", 1.0, 2.0, 1.0 + 2.0);
|
||||||
|
printf("%g - %g = %g\n", 1.0, 2.0, 1.0 - 2.0);
|
||||||
|
printf("%g * %g = %g\n", 1.0, 2.0, 1.0 * 2.0);
|
||||||
|
printf("%g / %g = %g\n", 1.0, 2.0, 1.0 / 2.0);
|
||||||
|
|
||||||
|
printf("float op float:\n");
|
||||||
|
printf("%g + %g = %g\n", 1.0f, 2.0f, 1.0f + 2.0f);
|
||||||
|
printf("%g - %g = %g\n", 1.0f, 2.0f, 1.0f - 2.0f);
|
||||||
|
printf("%g * %g = %g\n", 1.0f, 2.0f, 1.0f * 2.0f);
|
||||||
|
printf("%g / %g = %g\n", 1.0f, 2.0f, 1.0f / 2.0f);
|
||||||
|
|
||||||
|
printf("double op float:\n");
|
||||||
|
printf("%g + %g = %g\n", 1.0, 2.0f, 1.0 + 2.0f);
|
||||||
|
printf("%g - %g = %g\n", 1.0, 2.0f, 1.0 - 2.0f);
|
||||||
|
printf("%g * %g = %g\n", 1.0, 2.0f, 1.0 * 2.0f);
|
||||||
|
printf("%g / %g = %g\n", 1.0, 2.0f, 1.0 / 2.0f);
|
||||||
|
|
||||||
|
printf("double op int:\n");
|
||||||
|
printf("%g + %d = %g\n", 1.0, 2, 1.0 + 2);
|
||||||
|
printf("%g - %d = %g\n", 1.0, 2, 1.0 - 2);
|
||||||
|
printf("%g * %d = %g\n", 1.0, 2, 1.0 * 2);
|
||||||
|
printf("%g / %d = %g\n", 1.0, 2, 1.0 / 2);
|
||||||
|
|
||||||
|
printf("int op double:\n");
|
||||||
|
printf("%d + %g = %g\n", 1, 2.0, 1 + 2.0);
|
||||||
|
printf("%d - %g = %g\n", 1, 2.0, 1 - 2.0);
|
||||||
|
printf("%d * %g = %g\n", 1, 2.0, 1 * 2.0);
|
||||||
|
printf("%d / %g = %g\n", 1, 2.0, 1 / 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void comparisonTestdd(double a, double b) {
|
||||||
|
printf("%g op %g: < %d <= %d == %d >= %d > %d != %d\n",
|
||||||
|
a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void comparisonOpsdd() {
|
||||||
|
printf("double op double:\n");
|
||||||
|
comparisonTestdd(1.0, 2.0);
|
||||||
|
comparisonTestdd(1.0, 1.0);
|
||||||
|
comparisonTestdd(2.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void comparisonTestdf(double a, float b) {
|
||||||
|
printf("%g op %g: < %d <= %d == %d >= %d > %d != %d\n",
|
||||||
|
a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void comparisonOpsdf() {
|
||||||
|
printf("double op float:\n");
|
||||||
|
comparisonTestdf(1.0, 2.0f);
|
||||||
|
comparisonTestdf(1.0, 1.0f);
|
||||||
|
comparisonTestdf(2.0, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void comparisonTestff(float a, float b) {
|
||||||
|
printf("%g op %g: < %d <= %d == %d >= %d > %d != %d\n",
|
||||||
|
a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void comparisonOpsff() {
|
||||||
|
printf("float op float:\n");
|
||||||
|
comparisonTestff(1.0f, 2.0f);
|
||||||
|
comparisonTestff(1.0f, 1.0f);
|
||||||
|
comparisonTestff(2.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void comparisonTestid(int a, double b) {
|
||||||
|
printf("%d op %g: < %d <= %d == %d >= %d > %d != %d\n",
|
||||||
|
a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void comparisonOpsid() {
|
||||||
|
printf("int op double:\n");
|
||||||
|
comparisonTestid(1, 2.0);
|
||||||
|
comparisonTestid(1, 1.0);
|
||||||
|
comparisonTestid(2, 1.0);
|
||||||
|
}
|
||||||
|
void comparisonTestdi(double a, int b) {
|
||||||
|
printf("%g op %d: < %d <= %d == %d >= %d > %d != %d\n",
|
||||||
|
a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void comparisonOpsdi() {
|
||||||
|
printf("double op int:\n");
|
||||||
|
comparisonTestdi(1.0f, 2);
|
||||||
|
comparisonTestdi(1.0f, 1);
|
||||||
|
comparisonTestdi(2.0f, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void comparisonOps() {
|
||||||
|
comparisonOpsdd();
|
||||||
|
comparisonOpsdf();
|
||||||
|
comparisonOpsff();
|
||||||
|
comparisonOpsid();
|
||||||
|
comparisonOpsdi();
|
||||||
|
}
|
||||||
|
|
||||||
|
int branch(double d) {
|
||||||
|
if (d) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testBranching() {
|
||||||
|
printf("branching: %d %d %d\n", branch(-1.0), branch(0.0), branch(1.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void testpassi(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l) {
|
||||||
|
printf("testpassi: %d %d %d %d %d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h, i, j, k, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testpassf(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l) {
|
||||||
|
printf("testpassf: %g %g %g %g %g %g %g %g %g %g %g %g\n", a, b, c, d, e, f, g, h, i, j, k, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testpassd(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k, double l) {
|
||||||
|
printf("testpassd: %g %g %g %g %g %g %g %g %g %g %g %g\n", a, b, c, d, e, f, g, h, i, j, k, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testpassidf(int i, double d, float f) {
|
||||||
|
printf("testpassidf: %d %g %g\n", i, d, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testParameterPassing() {
|
||||||
|
float x;
|
||||||
|
testpassi(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
|
||||||
|
testpassf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
|
||||||
|
testpassd(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
|
||||||
|
testpassi(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f);
|
||||||
|
testpassf(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f);
|
||||||
|
testpassd(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f);
|
||||||
|
testpassi(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
|
||||||
|
testpassf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
|
||||||
|
testpassd(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
|
||||||
|
testpassidf(1, 2.0, 3.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
unaryOps();
|
||||||
|
binaryOps();
|
||||||
|
comparisonOps();
|
||||||
|
testBranching();
|
||||||
|
testParameterPassing();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
8
libacc/tests/data/funcargs.c
Normal file
8
libacc/tests/data/funcargs.c
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
int f(int a,int, int c) {
|
||||||
|
return a + c;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
return f(1,2,3);
|
||||||
|
}
|
||||||
|
|
||||||
3
libacc/tests/data/hello.c
Normal file
3
libacc/tests/data/hello.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
main(a,b) {
|
||||||
|
printf("Hello, world\n");
|
||||||
|
}
|
||||||
14
libacc/tests/data/inc.c
Normal file
14
libacc/tests/data/inc.c
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Check integer operations
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int a = 0;
|
||||||
|
printf("%d\n", a++);
|
||||||
|
printf("%d\n", a++);
|
||||||
|
printf("%d\n", a--);
|
||||||
|
printf("%d\n", a--);
|
||||||
|
printf("%d\n", ++a);
|
||||||
|
printf("%d\n", ++a);
|
||||||
|
printf("%d\n", --a);
|
||||||
|
printf("%d\n", --a);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
23
libacc/tests/data/iops.c
Normal file
23
libacc/tests/data/iops.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Check integer operations
|
||||||
|
|
||||||
|
void loops() {
|
||||||
|
int y;
|
||||||
|
printf("++\n");
|
||||||
|
for(y = 0; y < 10; y++) {
|
||||||
|
printf("%d\n", y);
|
||||||
|
}
|
||||||
|
printf("--\n");
|
||||||
|
for(y = 10; y >= 0; y--) {
|
||||||
|
printf("%d\n", y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkLiterals() {
|
||||||
|
printf("Literals: %d %d\n", 1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
checkLiterals();
|
||||||
|
loops();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
71
libacc/tests/data/locals.c
Normal file
71
libacc/tests/data/locals.c
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
int a;
|
||||||
|
|
||||||
|
int f() {
|
||||||
|
int a;
|
||||||
|
// Undefined variable b
|
||||||
|
// printf("f 0: a = %d b = %d\n", a, b);
|
||||||
|
printf("f 0: a = %d\n", a);
|
||||||
|
a = 2;
|
||||||
|
printf("f 1: a = %d\n", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
int g(int a) {
|
||||||
|
printf("g 0: a = %d\n", a);
|
||||||
|
a = 3;
|
||||||
|
printf("g 1: a = %d\n", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
int h(int a) {
|
||||||
|
// int a; // gcc 4.3 says error: 'a' redeclared as different kind of symbol
|
||||||
|
|
||||||
|
printf("h 0: a = %d\n", a);
|
||||||
|
a = 4;
|
||||||
|
printf("h 1: a = %d\n", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Already defined global
|
||||||
|
// int h() {}
|
||||||
|
int globCheck() {
|
||||||
|
fprintf(stdout, "globCheck()\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int fwdCheck() {
|
||||||
|
b();
|
||||||
|
// Undefined forward reference
|
||||||
|
// c();
|
||||||
|
}
|
||||||
|
|
||||||
|
int b() {
|
||||||
|
printf("b()\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int nested() {
|
||||||
|
int a;
|
||||||
|
printf("nested 0: a = %d\n", a);
|
||||||
|
a = 50;
|
||||||
|
printf("nested 1: a = %d\n", a);
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
printf("nested 2: a = %d\n", a);
|
||||||
|
a = 51;
|
||||||
|
printf("nested 3: a = %d\n", a);
|
||||||
|
}
|
||||||
|
printf("nested 4: a = %d\n", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
globCheck();
|
||||||
|
fwdCheck();
|
||||||
|
printf("main 0: a = %d\n", a);
|
||||||
|
a = 5;
|
||||||
|
printf("main 1: a = %d\n", a);
|
||||||
|
f();
|
||||||
|
printf("main 2: a = %d\n", a);
|
||||||
|
g(77);
|
||||||
|
printf("main 3: a = %d\n", a);
|
||||||
|
h(30);
|
||||||
|
printf("main 4: a = %d\n", a);
|
||||||
|
nested();
|
||||||
|
printf("main 5: a = %d\n", a);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
4
libacc/tests/data/missing-main.c
Normal file
4
libacc/tests/data/missing-main.c
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
/* No main. */
|
||||||
|
|
||||||
|
a() {
|
||||||
|
}
|
||||||
466
libacc/tests/data/otcc-ansi.c
Normal file
466
libacc/tests/data/otcc-ansi.c
Normal file
|
|
@ -0,0 +1,466 @@
|
||||||
|
// #include <stdio.h>
|
||||||
|
int d, z, C, h, P, K, ac, q, G, v, Q, R, D, L, W, M;
|
||||||
|
|
||||||
|
void E(int e) {
|
||||||
|
*(char*) D++ = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void o() {
|
||||||
|
if (L) {
|
||||||
|
h = *(char*) L++;
|
||||||
|
if (h == 2) {
|
||||||
|
L = 0;
|
||||||
|
h = W;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
h = fgetc(Q);
|
||||||
|
}
|
||||||
|
|
||||||
|
int X() {
|
||||||
|
return isalnum(h) | h == 95;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Y() {
|
||||||
|
if (h == 92) {
|
||||||
|
o();
|
||||||
|
if (h == 110)
|
||||||
|
h = 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad() {
|
||||||
|
int e, j, m;
|
||||||
|
while (isspace(h) | h == 35) {
|
||||||
|
if (h == 35) {
|
||||||
|
o();
|
||||||
|
ad();
|
||||||
|
if (d == 536) {
|
||||||
|
ad();
|
||||||
|
E(32);
|
||||||
|
*(int*) d = 1;
|
||||||
|
*(int*) (d + 4) = D;
|
||||||
|
}
|
||||||
|
while (h != 10) {
|
||||||
|
E(h);
|
||||||
|
o();
|
||||||
|
}
|
||||||
|
E(h);
|
||||||
|
E(2);
|
||||||
|
}
|
||||||
|
o();
|
||||||
|
}
|
||||||
|
C = 0;
|
||||||
|
d = h;
|
||||||
|
if (X()) {
|
||||||
|
E(32);
|
||||||
|
M = D;
|
||||||
|
while (X()) {
|
||||||
|
E(h);
|
||||||
|
o();
|
||||||
|
}
|
||||||
|
if (isdigit(d)) {
|
||||||
|
z = strtol(M, 0, 0);
|
||||||
|
d = 2;
|
||||||
|
} else {
|
||||||
|
*(char*) D = 32;
|
||||||
|
d = strstr(R, M - 1) - R;
|
||||||
|
*(char*) D = 0;
|
||||||
|
d = d * 8 + 256;
|
||||||
|
if (d > 536) {
|
||||||
|
d = P + d;
|
||||||
|
if (*(int*) d == 1) {
|
||||||
|
L = *(int*) (d + 4);
|
||||||
|
W = h;
|
||||||
|
o();
|
||||||
|
ad();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
o();
|
||||||
|
if (d == 39) {
|
||||||
|
d = 2;
|
||||||
|
Y();
|
||||||
|
z = h;
|
||||||
|
o();
|
||||||
|
o();
|
||||||
|
} else if (d == 47 & h == 42) {
|
||||||
|
o();
|
||||||
|
while (h) {
|
||||||
|
while (h != 42)
|
||||||
|
o();
|
||||||
|
o();
|
||||||
|
if (h == 47)
|
||||||
|
h = 0;
|
||||||
|
}
|
||||||
|
o();
|
||||||
|
ad();
|
||||||
|
} else {
|
||||||
|
e
|
||||||
|
= "++#m--%am*@R<^1c/@%[_[H3c%@%[_[H3c+@.B#d-@%:_^BKd<<Z/03e>>`/03e<=0f>=/f<@.f>@1f==&g!='g&&k||#l&@.BCh^@.BSi|@.B+j~@/%Yd!@&d*@b";
|
||||||
|
while (j = *(char*) e++) {
|
||||||
|
m = *(char*) e++;
|
||||||
|
z = 0;
|
||||||
|
while ((C = *(char*) e++ - 98) < 0)
|
||||||
|
z = z * 64 + C + 64;
|
||||||
|
if (j == d & (m == h | m == 64)) {
|
||||||
|
if (m == h) {
|
||||||
|
o();
|
||||||
|
d = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ae(int g) {
|
||||||
|
while( g&&g!=-1) {
|
||||||
|
*(char*) q++=g;
|
||||||
|
g=g>>8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void A(int e) {
|
||||||
|
int g;
|
||||||
|
while( e) {
|
||||||
|
g=*(int*) e;
|
||||||
|
*(int*) e=q-e-4;
|
||||||
|
e=g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int s(int g, int e) {
|
||||||
|
ae(g);
|
||||||
|
*(int*) q = e;
|
||||||
|
e = q;
|
||||||
|
q = q + 4;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void H(int e) {
|
||||||
|
s(184,e);
|
||||||
|
}
|
||||||
|
|
||||||
|
int B(int e) {
|
||||||
|
return s(233,e);
|
||||||
|
}
|
||||||
|
|
||||||
|
int S(int j, int e) {
|
||||||
|
ae(1032325);
|
||||||
|
return s(132 + j, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Z(int e) {
|
||||||
|
ae( 49465);
|
||||||
|
H(0);
|
||||||
|
ae( 15);
|
||||||
|
ae( e+144);
|
||||||
|
ae( 192);
|
||||||
|
}
|
||||||
|
|
||||||
|
void N(int j, int e) {
|
||||||
|
ae(j + 131);
|
||||||
|
s((e > -512 && e < 512) << 7 | 5, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void T (int j) {
|
||||||
|
int g,e,m,aa;
|
||||||
|
g=1;
|
||||||
|
if( d == 34) {
|
||||||
|
H(v);
|
||||||
|
while( h!=34) {
|
||||||
|
Y ();
|
||||||
|
*(char*) v++=h;
|
||||||
|
o ();
|
||||||
|
}
|
||||||
|
*(char*) v=0;
|
||||||
|
v=v +4&-4;
|
||||||
|
o ();
|
||||||
|
ad();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
aa=C;
|
||||||
|
m= z;
|
||||||
|
e=d;
|
||||||
|
ad();
|
||||||
|
if( e == 2) {
|
||||||
|
H(m);
|
||||||
|
}
|
||||||
|
else if( aa == 2) {
|
||||||
|
T(0);
|
||||||
|
s(185,0);
|
||||||
|
if( e == 33)Z(m);
|
||||||
|
else ae( m);
|
||||||
|
}
|
||||||
|
else if( e == 40) {
|
||||||
|
w ();
|
||||||
|
ad();
|
||||||
|
}
|
||||||
|
else if( e == 42) {
|
||||||
|
ad();
|
||||||
|
e=d;
|
||||||
|
ad();
|
||||||
|
ad();
|
||||||
|
if( d == 42) {
|
||||||
|
ad();
|
||||||
|
ad();
|
||||||
|
ad();
|
||||||
|
ad();
|
||||||
|
e=0;
|
||||||
|
}
|
||||||
|
ad();
|
||||||
|
T(0);
|
||||||
|
if( d == 61) {
|
||||||
|
ad();
|
||||||
|
ae( 80);
|
||||||
|
w ();
|
||||||
|
ae( 89);
|
||||||
|
ae( 392+(e == 256));
|
||||||
|
}
|
||||||
|
else if( e) {
|
||||||
|
if( e == 256)ae( 139);
|
||||||
|
else ae( 48655);
|
||||||
|
q++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( e == 38) {
|
||||||
|
N(10,*(int*) d);
|
||||||
|
ad();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g=*(int*) e;
|
||||||
|
if(!g)g=dlsym(0,M);
|
||||||
|
if( d == 61&j) {
|
||||||
|
ad();
|
||||||
|
w ();
|
||||||
|
N(6,g);
|
||||||
|
}
|
||||||
|
else if( d!= 40) {
|
||||||
|
N(8,g);
|
||||||
|
if( C == 11) {
|
||||||
|
N(0,g);
|
||||||
|
ae( z);
|
||||||
|
ad();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( d == 40) {
|
||||||
|
if( g == 1)ae( 80);
|
||||||
|
m= s(60545,0);
|
||||||
|
ad();
|
||||||
|
j=0;
|
||||||
|
while( d!= 41) {
|
||||||
|
w ();
|
||||||
|
s(2393225,j);
|
||||||
|
if( d == 44)ad();
|
||||||
|
j=j +4;
|
||||||
|
}
|
||||||
|
*(int*) m= j;
|
||||||
|
ad();
|
||||||
|
if(!g) {
|
||||||
|
e=e +4;
|
||||||
|
*(int*) e=s(232,*(int*) e);
|
||||||
|
}
|
||||||
|
else if( g == 1) {
|
||||||
|
s(2397439,j);
|
||||||
|
j=j +4;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
s(232,g-q-5);
|
||||||
|
}
|
||||||
|
if( j)s(50305,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void O (int j) {
|
||||||
|
int e,g,m;
|
||||||
|
if( j--== 1)T(1);
|
||||||
|
else {
|
||||||
|
O (j);
|
||||||
|
m= 0;
|
||||||
|
while( j == C) {
|
||||||
|
g=d;
|
||||||
|
e=z;
|
||||||
|
ad();
|
||||||
|
if( j>8) {
|
||||||
|
m= S(e,m);
|
||||||
|
O (j);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ae( 80);
|
||||||
|
O (j);
|
||||||
|
ae( 89);
|
||||||
|
if( j == 4|j == 5) {
|
||||||
|
Z(e);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ae( e);
|
||||||
|
if( g == 37)ae( 146);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( m&&j>8) {
|
||||||
|
m= S(e,m);
|
||||||
|
H(e^1);
|
||||||
|
B(5);
|
||||||
|
A(m);
|
||||||
|
H(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void w() {
|
||||||
|
O(11);
|
||||||
|
}
|
||||||
|
|
||||||
|
int U() {
|
||||||
|
w();
|
||||||
|
return S(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void I (int j) {
|
||||||
|
int m,g,e;
|
||||||
|
if( d == 288) {
|
||||||
|
ad();
|
||||||
|
ad();
|
||||||
|
m= U ();
|
||||||
|
ad();
|
||||||
|
I (j);
|
||||||
|
if( d == 312) {
|
||||||
|
ad();
|
||||||
|
g=B(0);
|
||||||
|
A(m);
|
||||||
|
I (j);
|
||||||
|
A(g);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
A(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( d == 352|d == 504) {
|
||||||
|
e=d;
|
||||||
|
ad();
|
||||||
|
ad();
|
||||||
|
if( e == 352) {
|
||||||
|
g=q;
|
||||||
|
m= U ();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if( d!= 59)w ();
|
||||||
|
ad();
|
||||||
|
g=q;
|
||||||
|
m= 0;
|
||||||
|
if( d!= 59)m= U ();
|
||||||
|
ad();
|
||||||
|
if( d!= 41) {
|
||||||
|
e=B(0);
|
||||||
|
w ();
|
||||||
|
B(g-q-5);
|
||||||
|
A(e);
|
||||||
|
g=e +4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ad();
|
||||||
|
I(&m);
|
||||||
|
B(g-q-5);
|
||||||
|
A(m);
|
||||||
|
}
|
||||||
|
else if( d == 123) {
|
||||||
|
ad();
|
||||||
|
ab(1);
|
||||||
|
while( d!= 125)I (j);
|
||||||
|
ad();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if( d == 448) {
|
||||||
|
ad();
|
||||||
|
if( d!= 59)w ();
|
||||||
|
K=B(K);
|
||||||
|
}
|
||||||
|
else if( d == 400) {
|
||||||
|
ad();
|
||||||
|
*(int*) j=B(*(int*) j);
|
||||||
|
}
|
||||||
|
else if( d!= 59)w ();
|
||||||
|
ad();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ab (int j) {
|
||||||
|
int m;
|
||||||
|
while( d == 256|d!=-1&!j) {
|
||||||
|
if( d == 256) {
|
||||||
|
ad();
|
||||||
|
while( d!= 59) {
|
||||||
|
if( j) {
|
||||||
|
G=G +4;
|
||||||
|
*(int*) d=-G;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*(int*) d=v;
|
||||||
|
v=v +4;
|
||||||
|
}
|
||||||
|
ad();
|
||||||
|
if( d == 44)ad() ;
|
||||||
|
}
|
||||||
|
ad();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
A(*(int*)(d +4));
|
||||||
|
*(int*) d=q;
|
||||||
|
ad();
|
||||||
|
ad();
|
||||||
|
m= 8;
|
||||||
|
while( d!= 41) {
|
||||||
|
*(int*) d=m;
|
||||||
|
m= m +4;
|
||||||
|
ad();
|
||||||
|
if( d == 44)ad();
|
||||||
|
}
|
||||||
|
ad();
|
||||||
|
K=G=0;
|
||||||
|
ae( 15042901);
|
||||||
|
m= s(60545,0);
|
||||||
|
I(0);
|
||||||
|
A(K);
|
||||||
|
ae( 50121);
|
||||||
|
*(int*) m= G;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int run(int g, int e) {
|
||||||
|
return (*(int(*)()) *(int*) (P + 592))(g, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int g, int e) {
|
||||||
|
int result;
|
||||||
|
Q = stdin;
|
||||||
|
if (g-- > 1) {
|
||||||
|
e = e + 4;
|
||||||
|
Q = fopen(*(int*) e, "r");
|
||||||
|
if (!Q) {
|
||||||
|
fprintf(stderr, "otcc-ansi.c: could not open file %s\n", *(int*) e);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
D = strcpy(R = calloc(1, 99999), " int if else while break return for define main ") + 48;
|
||||||
|
v = calloc(1, 99999);
|
||||||
|
q = ac = calloc(1, 99999);
|
||||||
|
P = calloc(1, 99999);
|
||||||
|
o();
|
||||||
|
ad();
|
||||||
|
ab(0);
|
||||||
|
if (mprotect(ac & (~ 4095), (99999 + 4095) & (~ 4095), 7)) {
|
||||||
|
printf("Mprotect failed. %d\n", errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "otcc-ansi.c: About to execute compiled code:\n");
|
||||||
|
result = run(g, e);
|
||||||
|
fprintf(stderr, "atcc-ansi.c: result: %d\n", result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
446
libacc/tests/data/otcc-noinclude.c
Normal file
446
libacc/tests/data/otcc-noinclude.c
Normal file
|
|
@ -0,0 +1,446 @@
|
||||||
|
// #include <stdio.h>
|
||||||
|
#define k *(int*)
|
||||||
|
#define a if(
|
||||||
|
#define c ad()
|
||||||
|
#define i else
|
||||||
|
#define p while(
|
||||||
|
#define x *(char*)
|
||||||
|
#define b ==
|
||||||
|
#define V =calloc(1,99999)
|
||||||
|
#define f ()
|
||||||
|
#define J return
|
||||||
|
#define l ae(
|
||||||
|
#define n e)
|
||||||
|
#define u d!=
|
||||||
|
#define F int
|
||||||
|
#define y (j)
|
||||||
|
#define r m=
|
||||||
|
#define t +4
|
||||||
|
F d,z,C,h,P,K,ac,q,G,v,Q,R,D,L,W,M;
|
||||||
|
E(n{
|
||||||
|
x D++=e;
|
||||||
|
}
|
||||||
|
o f{
|
||||||
|
a L){
|
||||||
|
h=x L++;
|
||||||
|
a h b 2){
|
||||||
|
L=0;
|
||||||
|
h=W;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i h=fgetc(Q);
|
||||||
|
}
|
||||||
|
X f{
|
||||||
|
J isalnum(h)|h b 95;
|
||||||
|
}
|
||||||
|
Y f{
|
||||||
|
a h b 92){
|
||||||
|
o f;
|
||||||
|
a h b 110)h=10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c{
|
||||||
|
F e,j,m;
|
||||||
|
p isspace(h)|h b 35){
|
||||||
|
a h b 35){
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
a d b 536){
|
||||||
|
c;
|
||||||
|
E(32);
|
||||||
|
k d=1;
|
||||||
|
k(d t)=D;
|
||||||
|
}
|
||||||
|
p h!=10){
|
||||||
|
E(h);
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
E(h);
|
||||||
|
E(2);
|
||||||
|
}
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
C=0;
|
||||||
|
d=h;
|
||||||
|
a X f){
|
||||||
|
E(32);
|
||||||
|
M=D;
|
||||||
|
p X f){
|
||||||
|
E(h);
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
a isdigit(d)){
|
||||||
|
z=strtol(M,0,0);
|
||||||
|
d=2;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
x D=32;
|
||||||
|
d=strstr(R,M-1)-R;
|
||||||
|
x D=0;
|
||||||
|
d=d*8+256;
|
||||||
|
a d>536){
|
||||||
|
d=P+d;
|
||||||
|
a k d b 1){
|
||||||
|
L=k(d t);
|
||||||
|
W=h;
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
o f;
|
||||||
|
a d b 39){
|
||||||
|
d=2;
|
||||||
|
Y f;
|
||||||
|
z=h;
|
||||||
|
o f;
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
i a d b 47&h b 42){
|
||||||
|
o f;
|
||||||
|
p h){
|
||||||
|
p h!=42)o f;
|
||||||
|
o f;
|
||||||
|
a h b 47)h=0;
|
||||||
|
}
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
e="++#m--%am*@R<^1c/@%[_[H3c%@%[_[H3c+@.B#d-@%:_^BKd<<Z/03e>>`/03e<=0f>=/f<@.f>@1f==&g!='g&&k||#l&@.BCh^@.BSi|@.B+j~@/%Yd!@&d*@b";
|
||||||
|
p j=x e++){
|
||||||
|
r x e++;
|
||||||
|
z=0;
|
||||||
|
p(C=x e++-98)<0)z=z*64+C+64;
|
||||||
|
a j b d&(m b h|m b 64)){
|
||||||
|
a m b h){
|
||||||
|
o f;
|
||||||
|
d=1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l g){
|
||||||
|
p g&&g!=-1){
|
||||||
|
x q++=g;
|
||||||
|
g=g>>8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
A(n{
|
||||||
|
F g;
|
||||||
|
p n{
|
||||||
|
g=k e;
|
||||||
|
k e=q-e-4;
|
||||||
|
e=g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s(g,n{
|
||||||
|
l g);
|
||||||
|
k q=e;
|
||||||
|
e=q;
|
||||||
|
q=q t;
|
||||||
|
J e;
|
||||||
|
}
|
||||||
|
H(n{
|
||||||
|
s(184,n;
|
||||||
|
}
|
||||||
|
B(n{
|
||||||
|
J s(233,n;
|
||||||
|
}
|
||||||
|
S(j,n{
|
||||||
|
l 1032325);
|
||||||
|
J s(132+j,n;
|
||||||
|
}
|
||||||
|
Z(n{
|
||||||
|
l 49465);
|
||||||
|
H(0);
|
||||||
|
l 15);
|
||||||
|
l e+144);
|
||||||
|
l 192);
|
||||||
|
}
|
||||||
|
N(j,n{
|
||||||
|
l j+131);
|
||||||
|
s((e<512)<<7|5,n;
|
||||||
|
}
|
||||||
|
T y{
|
||||||
|
F g,e,m,aa;
|
||||||
|
g=1;
|
||||||
|
a d b 34){
|
||||||
|
H(v);
|
||||||
|
p h!=34){
|
||||||
|
Y f;
|
||||||
|
x v++=h;
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
x v=0;
|
||||||
|
v=v t&-4;
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
aa=C;
|
||||||
|
r z;
|
||||||
|
e=d;
|
||||||
|
c;
|
||||||
|
a e b 2){
|
||||||
|
H(m);
|
||||||
|
}
|
||||||
|
i a aa b 2){
|
||||||
|
T(0);
|
||||||
|
s(185,0);
|
||||||
|
a e b 33)Z(m);
|
||||||
|
i l m);
|
||||||
|
}
|
||||||
|
i a e b 40){
|
||||||
|
w f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i a e b 42){
|
||||||
|
c;
|
||||||
|
e=d;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
a d b 42){
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
e=0;
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
T(0);
|
||||||
|
a d b 61){
|
||||||
|
c;
|
||||||
|
l 80);
|
||||||
|
w f;
|
||||||
|
l 89);
|
||||||
|
l 392+(e b 256));
|
||||||
|
}
|
||||||
|
i a n{
|
||||||
|
a e b 256)l 139);
|
||||||
|
i l 48655);
|
||||||
|
q++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i a e b 38){
|
||||||
|
N(10,k d);
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
g=k e;
|
||||||
|
a!g)g=dlsym(0,M);
|
||||||
|
a d b 61&j){
|
||||||
|
c;
|
||||||
|
w f;
|
||||||
|
N(6,g);
|
||||||
|
}
|
||||||
|
i a u 40){
|
||||||
|
N(8,g);
|
||||||
|
a C b 11){
|
||||||
|
N(0,g);
|
||||||
|
l z);
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a d b 40){
|
||||||
|
a g b 1)l 80);
|
||||||
|
r s(60545,0);
|
||||||
|
c;
|
||||||
|
j=0;
|
||||||
|
p u 41){
|
||||||
|
w f;
|
||||||
|
s(2393225,j);
|
||||||
|
a d b 44)c;
|
||||||
|
j=j t;
|
||||||
|
}
|
||||||
|
k r j;
|
||||||
|
c;
|
||||||
|
a!g){
|
||||||
|
e=e t;
|
||||||
|
k e=s(232,k n;
|
||||||
|
}
|
||||||
|
i a g b 1){
|
||||||
|
s(2397439,j);
|
||||||
|
j=j t;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
s(232,g-q-5);
|
||||||
|
}
|
||||||
|
a j)s(50305,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
O y{
|
||||||
|
F e,g,m;
|
||||||
|
a j--b 1)T(1);
|
||||||
|
i{
|
||||||
|
O y;
|
||||||
|
r 0;
|
||||||
|
p j b C){
|
||||||
|
g=d;
|
||||||
|
e=z;
|
||||||
|
c;
|
||||||
|
a j>8){
|
||||||
|
r S(e,m);
|
||||||
|
O y;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
l 80);
|
||||||
|
O y;
|
||||||
|
l 89);
|
||||||
|
a j b 4|j b 5){
|
||||||
|
Z(n;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
l n;
|
||||||
|
a g b 37)l 146);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a m&&j>8){
|
||||||
|
r S(e,m);
|
||||||
|
H(e^1);
|
||||||
|
B(5);
|
||||||
|
A(m);
|
||||||
|
H(n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w f{
|
||||||
|
O(11);
|
||||||
|
}
|
||||||
|
U f{
|
||||||
|
w f;
|
||||||
|
J S(0,0);
|
||||||
|
}
|
||||||
|
I y{
|
||||||
|
F m,g,e;
|
||||||
|
a d b 288){
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
r U f;
|
||||||
|
c;
|
||||||
|
I y;
|
||||||
|
a d b 312){
|
||||||
|
c;
|
||||||
|
g=B(0);
|
||||||
|
A(m);
|
||||||
|
I y;
|
||||||
|
A(g);
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
A(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i a d b 352|d b 504){
|
||||||
|
e=d;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
a e b 352){
|
||||||
|
g=q;
|
||||||
|
r U f;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
a u 59)w f;
|
||||||
|
c;
|
||||||
|
g=q;
|
||||||
|
r 0;
|
||||||
|
a u 59)r U f;
|
||||||
|
c;
|
||||||
|
a u 41){
|
||||||
|
e=B(0);
|
||||||
|
w f;
|
||||||
|
B(g-q-5);
|
||||||
|
A(n;
|
||||||
|
g=e t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
I(&m);
|
||||||
|
B(g-q-5);
|
||||||
|
A(m);
|
||||||
|
}
|
||||||
|
i a d b 123){
|
||||||
|
c;
|
||||||
|
ab(1);
|
||||||
|
p u 125)I y;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
a d b 448){
|
||||||
|
c;
|
||||||
|
a u 59)w f;
|
||||||
|
K=B(K);
|
||||||
|
}
|
||||||
|
i a d b 400){
|
||||||
|
c;
|
||||||
|
k j=B(k j);
|
||||||
|
}
|
||||||
|
i a u 59)w f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ab y{
|
||||||
|
F m;
|
||||||
|
p d b 256|u-1&!j){
|
||||||
|
a d b 256){
|
||||||
|
c;
|
||||||
|
p u 59){
|
||||||
|
a j){
|
||||||
|
G=G t;
|
||||||
|
k d=-G;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
k d=v;
|
||||||
|
v=v t;
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
a d b 44)c;
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
A(k(d t));
|
||||||
|
k d=q;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
r 8;
|
||||||
|
p u 41){
|
||||||
|
k d=m;
|
||||||
|
r m t;
|
||||||
|
c;
|
||||||
|
a d b 44)c;
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
K=G=0;
|
||||||
|
l 15042901);
|
||||||
|
r s(60545,0);
|
||||||
|
I(0);
|
||||||
|
A(K);
|
||||||
|
l 50121);
|
||||||
|
k r G;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
main(g,n{
|
||||||
|
Q=stdin;
|
||||||
|
a g-->1){
|
||||||
|
e=e t;
|
||||||
|
Q=fopen(k e,"r");
|
||||||
|
}
|
||||||
|
D=strcpy(R V," int if else while break return for define main ")+48;
|
||||||
|
v V;
|
||||||
|
q=ac V;
|
||||||
|
P V;
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
ab(0);
|
||||||
|
J(*(int(*)f)k(P+592))(g,n;
|
||||||
|
}
|
||||||
|
|
||||||
448
libacc/tests/data/otcc.c
Normal file
448
libacc/tests/data/otcc.c
Normal file
|
|
@ -0,0 +1,448 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#define k *(int*)
|
||||||
|
#define a if(
|
||||||
|
#define c ad()
|
||||||
|
#define i else
|
||||||
|
#define p while(
|
||||||
|
#define x *(char*)
|
||||||
|
#define b ==
|
||||||
|
#define V =calloc(1,99999)
|
||||||
|
#define f ()
|
||||||
|
#define J return
|
||||||
|
#define l ae(
|
||||||
|
#define n e)
|
||||||
|
#define u d!=
|
||||||
|
#define F int
|
||||||
|
#define y (j)
|
||||||
|
#define r m=
|
||||||
|
#define t +4
|
||||||
|
F d,z,C,h,P,K,ac,q,G,v,Q,R,D,L,W,M;
|
||||||
|
E(n{
|
||||||
|
x D++=e;
|
||||||
|
}
|
||||||
|
o f{
|
||||||
|
a L){
|
||||||
|
h=x L++;
|
||||||
|
a h b 2){
|
||||||
|
L=0;
|
||||||
|
h=W;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i h=fgetc(Q);
|
||||||
|
}
|
||||||
|
X f{
|
||||||
|
J isalnum(h)|h b 95;
|
||||||
|
}
|
||||||
|
Y f{
|
||||||
|
a h b 92){
|
||||||
|
o f;
|
||||||
|
a h b 110)h=10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c{
|
||||||
|
F e,j,m;
|
||||||
|
p isspace(h)|h b 35){
|
||||||
|
a h b 35){
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
a d b 536){
|
||||||
|
c;
|
||||||
|
E(32);
|
||||||
|
k d=1;
|
||||||
|
k(d t)=D;
|
||||||
|
}
|
||||||
|
p h!=10){
|
||||||
|
E(h);
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
E(h);
|
||||||
|
E(2);
|
||||||
|
}
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
C=0;
|
||||||
|
d=h;
|
||||||
|
a X f){
|
||||||
|
E(32);
|
||||||
|
M=D;
|
||||||
|
p X f){
|
||||||
|
E(h);
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
a isdigit(d)){
|
||||||
|
z=strtol(M,0,0);
|
||||||
|
d=2;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
x D=32;
|
||||||
|
d=strstr(R,M-1)-R;
|
||||||
|
x D=0;
|
||||||
|
d=d*8+256;
|
||||||
|
a d>536){
|
||||||
|
d=P+d;
|
||||||
|
a k d b 1){
|
||||||
|
L=k(d t);
|
||||||
|
W=h;
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
o f;
|
||||||
|
a d b 39){
|
||||||
|
d=2;
|
||||||
|
Y f;
|
||||||
|
z=h;
|
||||||
|
o f;
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
i a d b 47&h b 42){
|
||||||
|
o f;
|
||||||
|
p h){
|
||||||
|
p h!=42)o f;
|
||||||
|
o f;
|
||||||
|
a h b 47)h=0;
|
||||||
|
}
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
e="++#m--%am*@R<^1c/@%[_[H3c%@%[_[H3c+@.B#d-@%:_^BKd<<Z/03e>>`/03e<=0f>=/f<@.f>@1f==&g!='g&&k||#l&@.BCh^@.BSi|@.B+j~@/%Yd!@&d*@b";
|
||||||
|
p j=x e++){
|
||||||
|
r x e++;
|
||||||
|
z=0;
|
||||||
|
p(C=x e++-98)<0)z=z*64+C+64;
|
||||||
|
a j b d&(m b h|m b 64)){
|
||||||
|
a m b h){
|
||||||
|
o f;
|
||||||
|
d=1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l g){
|
||||||
|
p g&&g!=-1){
|
||||||
|
x q++=g;
|
||||||
|
g=g>>8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
A(n{
|
||||||
|
F g;
|
||||||
|
p n{
|
||||||
|
g=k e;
|
||||||
|
k e=q-e-4;
|
||||||
|
e=g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s(g,n{
|
||||||
|
l g);
|
||||||
|
k q=e;
|
||||||
|
e=q;
|
||||||
|
q=q t;
|
||||||
|
J e;
|
||||||
|
}
|
||||||
|
H(n{
|
||||||
|
s(184,n;
|
||||||
|
}
|
||||||
|
B(n{
|
||||||
|
J s(233,n;
|
||||||
|
}
|
||||||
|
S(j,n{
|
||||||
|
l 1032325);
|
||||||
|
J s(132+j,n;
|
||||||
|
}
|
||||||
|
Z(n{
|
||||||
|
l 49465);
|
||||||
|
H(0);
|
||||||
|
l 15);
|
||||||
|
l e+144);
|
||||||
|
l 192);
|
||||||
|
}
|
||||||
|
N(j,n{
|
||||||
|
l j+131);
|
||||||
|
s((e<512)<<7|5,n;
|
||||||
|
}
|
||||||
|
T y{
|
||||||
|
F g,e,m,aa;
|
||||||
|
g=1;
|
||||||
|
a d b 34){
|
||||||
|
H(v);
|
||||||
|
p h!=34){
|
||||||
|
Y f;
|
||||||
|
x v++=h;
|
||||||
|
o f;
|
||||||
|
}
|
||||||
|
x v=0;
|
||||||
|
v=v t&-4;
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
aa=C;
|
||||||
|
r z;
|
||||||
|
e=d;
|
||||||
|
c;
|
||||||
|
a e b 2){
|
||||||
|
H(m);
|
||||||
|
}
|
||||||
|
i a aa b 2){
|
||||||
|
T(0);
|
||||||
|
s(185,0);
|
||||||
|
a e b 33)Z(m);
|
||||||
|
i l m);
|
||||||
|
}
|
||||||
|
i a e b 40){
|
||||||
|
w f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i a e b 42){
|
||||||
|
c;
|
||||||
|
e=d;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
a d b 42){
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
e=0;
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
T(0);
|
||||||
|
a d b 61){
|
||||||
|
c;
|
||||||
|
l 80);
|
||||||
|
w f;
|
||||||
|
l 89);
|
||||||
|
l 392+(e b 256));
|
||||||
|
}
|
||||||
|
i a n{
|
||||||
|
a e b 256)l 139);
|
||||||
|
i l 48655);
|
||||||
|
q++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i a e b 38){
|
||||||
|
N(10,k d);
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
g=k e;
|
||||||
|
a!g)g=dlsym(0,M);
|
||||||
|
a d b 61&j){
|
||||||
|
c;
|
||||||
|
w f;
|
||||||
|
N(6,g);
|
||||||
|
}
|
||||||
|
i a u 40){
|
||||||
|
N(8,g);
|
||||||
|
a C b 11){
|
||||||
|
N(0,g);
|
||||||
|
l z);
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a d b 40){
|
||||||
|
a g b 1)l 80);
|
||||||
|
r s(60545,0);
|
||||||
|
c;
|
||||||
|
j=0;
|
||||||
|
p u 41){
|
||||||
|
w f;
|
||||||
|
s(2393225,j);
|
||||||
|
a d b 44)c;
|
||||||
|
j=j t;
|
||||||
|
}
|
||||||
|
k r j;
|
||||||
|
c;
|
||||||
|
a!g){
|
||||||
|
e=e t;
|
||||||
|
k e=s(232,k n;
|
||||||
|
}
|
||||||
|
i a g b 1){
|
||||||
|
s(2397439,j);
|
||||||
|
j=j t;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
s(232,g-q-5);
|
||||||
|
}
|
||||||
|
a j)s(50305,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
O y{
|
||||||
|
F e,g,m;
|
||||||
|
a j--b 1)T(1);
|
||||||
|
i{
|
||||||
|
O y;
|
||||||
|
r 0;
|
||||||
|
p j b C){
|
||||||
|
g=d;
|
||||||
|
e=z;
|
||||||
|
c;
|
||||||
|
a j>8){
|
||||||
|
r S(e,m);
|
||||||
|
O y;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
l 80);
|
||||||
|
O y;
|
||||||
|
l 89);
|
||||||
|
a j b 4|j b 5){
|
||||||
|
Z(n;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
l n;
|
||||||
|
a g b 37)l 146);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a m&&j>8){
|
||||||
|
r S(e,m);
|
||||||
|
H(e^1);
|
||||||
|
B(5);
|
||||||
|
A(m);
|
||||||
|
H(n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w f{
|
||||||
|
O(11);
|
||||||
|
}
|
||||||
|
U f{
|
||||||
|
w f;
|
||||||
|
J S(0,0);
|
||||||
|
}
|
||||||
|
I y{
|
||||||
|
F m,g,e;
|
||||||
|
a d b 288){
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
r U f;
|
||||||
|
c;
|
||||||
|
I y;
|
||||||
|
a d b 312){
|
||||||
|
c;
|
||||||
|
g=B(0);
|
||||||
|
A(m);
|
||||||
|
I y;
|
||||||
|
A(g);
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
A(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i a d b 352|d b 504){
|
||||||
|
e=d;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
a e b 352){
|
||||||
|
g=q;
|
||||||
|
r U f;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
a u 59)w f;
|
||||||
|
c;
|
||||||
|
g=q;
|
||||||
|
r 0;
|
||||||
|
a u 59)r U f;
|
||||||
|
c;
|
||||||
|
a u 41){
|
||||||
|
e=B(0);
|
||||||
|
w f;
|
||||||
|
B(g-q-5);
|
||||||
|
A(n;
|
||||||
|
g=e t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
I(&m);
|
||||||
|
B(g-q-5);
|
||||||
|
A(m);
|
||||||
|
}
|
||||||
|
i a d b 123){
|
||||||
|
c;
|
||||||
|
ab(1);
|
||||||
|
p u 125)I y;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
a d b 448){
|
||||||
|
c;
|
||||||
|
a u 59)w f;
|
||||||
|
K=B(K);
|
||||||
|
}
|
||||||
|
i a d b 400){
|
||||||
|
c;
|
||||||
|
k j=B(k j);
|
||||||
|
}
|
||||||
|
i a u 59)w f;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ab y{
|
||||||
|
F m;
|
||||||
|
p d b 256|u-1&!j){
|
||||||
|
a d b 256){
|
||||||
|
c;
|
||||||
|
p u 59){
|
||||||
|
a j){
|
||||||
|
G=G t;
|
||||||
|
k d=-G;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
k d=v;
|
||||||
|
v=v t;
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
a d b 44)c;
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
i{
|
||||||
|
A(k(d t));
|
||||||
|
k d=q;
|
||||||
|
c;
|
||||||
|
c;
|
||||||
|
r 8;
|
||||||
|
p u 41){
|
||||||
|
k d=m;
|
||||||
|
r m t;
|
||||||
|
c;
|
||||||
|
a d b 44)c;
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
K=G=0;
|
||||||
|
l 15042901);
|
||||||
|
r s(60545,0);
|
||||||
|
I(0);
|
||||||
|
A(K);
|
||||||
|
l 50121);
|
||||||
|
k r G;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
main(g,n{
|
||||||
|
Q=stdin;
|
||||||
|
a g-->1){
|
||||||
|
e=e t;
|
||||||
|
Q=fopen(k e,"r");
|
||||||
|
}
|
||||||
|
D=strcpy(R V," int if else while break return for define main ")+48;
|
||||||
|
v V;
|
||||||
|
q=ac V;
|
||||||
|
P V;
|
||||||
|
o f;
|
||||||
|
c;
|
||||||
|
ab(0);
|
||||||
|
mprotect(ac & (~ 4095), (99999 + 4095) & (~ 4095), 7);
|
||||||
|
fprintf(stderr, "otcc.c: about to execute compiled code.\n");
|
||||||
|
J(*(int(*)f)k(P+592))(g,n;
|
||||||
|
}
|
||||||
|
|
||||||
15
libacc/tests/data/pointers.c
Normal file
15
libacc/tests/data/pointers.c
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
int main() {
|
||||||
|
int* pa = (int*) malloc(100);
|
||||||
|
int* pb = pa + 1;
|
||||||
|
int* pc = (int*) 0;
|
||||||
|
*pa = 1;
|
||||||
|
*pb = 2;
|
||||||
|
printf("Pointer difference: %d %d\n", pb - pa, ((int) pb) - ((int) pa));
|
||||||
|
int c = * (pa + 1);
|
||||||
|
printf("Pointer addition: %d\n", c);
|
||||||
|
printf("Pointer comparison to zero: %d %d %d\n", pa == 0, pb == 0, pc == 0);
|
||||||
|
printf("Pointer comparison: %d %d %d %d %d\n", pa < pb, pa == pb, pa > pb, ! pb, ! pc);
|
||||||
|
free(pa);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
35
libacc/tests/data/pointers2.c
Normal file
35
libacc/tests/data/pointers2.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
// Test multiple levels of indirection
|
||||||
|
|
||||||
|
void testsingle() {
|
||||||
|
int a = 0;
|
||||||
|
int* pa = &a;
|
||||||
|
printf("a = %d, *pa = %d\n", a, *pa);
|
||||||
|
*pa = 2;
|
||||||
|
printf("a = %d, *pa = %d\n", a, *pa);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testdouble() {
|
||||||
|
int a = 0;
|
||||||
|
int* pa = &a;
|
||||||
|
int** ppa = &pa;
|
||||||
|
printf("a = %d, *pa = %d **ppa = %d\n", a, *pa, **ppa);
|
||||||
|
**ppa = 2;
|
||||||
|
printf("a = %d, *pa = %d **ppa = %d\n", a, *pa, **ppa);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testtripple() {
|
||||||
|
int a = 0;
|
||||||
|
int* pa = &a;
|
||||||
|
int** ppa = &pa;
|
||||||
|
int*** pppa = &ppa;
|
||||||
|
printf("a = %d, *pa = %d **ppa = %d\n ***pppa = %d", a, *pa, **ppa, ***pppa);
|
||||||
|
***pppa = 2;
|
||||||
|
printf("a = %d, *pa = %d **ppa = %d\n ***pppa = %d", a, *pa, **ppa, ***pppa);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
testsingle();
|
||||||
|
testdouble();
|
||||||
|
testdouble();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
8
libacc/tests/data/returnval-ansi.c
Normal file
8
libacc/tests/data/returnval-ansi.c
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
return f();
|
||||||
|
}
|
||||||
|
|
||||||
|
int f() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
4
libacc/tests/data/returnval.c
Normal file
4
libacc/tests/data/returnval.c
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
main() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
|
||||||
9
libacc/tests/data/rollo3.c
Normal file
9
libacc/tests/data/rollo3.c
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
float fabsf(float);
|
||||||
|
|
||||||
|
int main(void* con, int ft, int launchID)
|
||||||
|
{
|
||||||
|
float f = fabsf(-10.0f);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
6
libacc/tests/data/short.c
Normal file
6
libacc/tests/data/short.c
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
short a = 3;
|
||||||
|
int main() {
|
||||||
|
short* b = &a;
|
||||||
|
*b = *b - 5;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
1
libacc/tests/data/simplest.c
Normal file
1
libacc/tests/data/simplest.c
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
main() {}
|
||||||
95
libacc/tests/data/structs.c
Normal file
95
libacc/tests/data/structs.c
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
// struct definition and declaration
|
||||||
|
struct a {
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
} c;
|
||||||
|
|
||||||
|
// Useless, but legal struct declaration
|
||||||
|
struct {
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Useful anonymous struct declaration
|
||||||
|
struct {
|
||||||
|
int y;
|
||||||
|
} anon1, anon2;
|
||||||
|
|
||||||
|
// forward declarations
|
||||||
|
struct a;
|
||||||
|
struct b;
|
||||||
|
struct c;
|
||||||
|
|
||||||
|
struct b {int a; int b; };
|
||||||
|
|
||||||
|
// struct c {b g; }; // syntax error.
|
||||||
|
|
||||||
|
// struct s {float c,a,b,c;} s; // duplicate struct member
|
||||||
|
|
||||||
|
struct c {struct b g; };
|
||||||
|
|
||||||
|
// struct a { int w; }; // error
|
||||||
|
|
||||||
|
void testCopying() {
|
||||||
|
struct a {int a[10]; char c;} a, b;
|
||||||
|
a.c = 37;
|
||||||
|
b.c = 38;
|
||||||
|
b = a;
|
||||||
|
printf("testCopying: %d == %d\n", a.c, b.c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testUnion() {
|
||||||
|
union u;
|
||||||
|
union u {float f;int i;} u;
|
||||||
|
u.f = 1.0f;
|
||||||
|
printf("testUnion: %g == 0x%08x\n", u.f, u.i);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct v {float x, y, z, w; };
|
||||||
|
|
||||||
|
void add(struct v* result, struct v* a, struct v* b) {
|
||||||
|
result->x = a->x + b->x;
|
||||||
|
result->y = a->y + b->y;
|
||||||
|
result->z = a->z + b->z;
|
||||||
|
result->w = a->w + b->w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(struct v* v, float x, float y, float z, float w) {
|
||||||
|
v->x = x;
|
||||||
|
v->y = y;
|
||||||
|
v->z = z;
|
||||||
|
v->w = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(struct v* v) {
|
||||||
|
printf("(%g, %g, %g, %g)\n", v->x, v->y, v->z, v->w);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testArgs() {
|
||||||
|
struct v a, b, c;
|
||||||
|
set(&a, 1.0f, 2.0f, 3.0f, 4.0f);
|
||||||
|
set(&b, 5.0f, 6.0f, 7.0f, 8.0f);
|
||||||
|
add(&c, &a, &b);
|
||||||
|
printf("testArgs: ");
|
||||||
|
print(&c);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
anon1.y = 3;
|
||||||
|
anon2.y = anon1.y;
|
||||||
|
|
||||||
|
testCopying();
|
||||||
|
testUnion();
|
||||||
|
testArgs();
|
||||||
|
|
||||||
|
struct c cc;
|
||||||
|
cc.g.a = 3;
|
||||||
|
c.a = 1;
|
||||||
|
c.b = 3;
|
||||||
|
struct a {int x, y; } z;
|
||||||
|
// struct a {int x, y; } z2;
|
||||||
|
z.x = c.a;
|
||||||
|
struct a *pA;
|
||||||
|
pA = &z;
|
||||||
|
pA->x += 5;
|
||||||
|
return pA->x;
|
||||||
|
}
|
||||||
4
libacc/tests/data/testStringConcat.c
Normal file
4
libacc/tests/data/testStringConcat.c
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
int main() {
|
||||||
|
return printf("Hello" "," " world\n");
|
||||||
|
}
|
||||||
|
|
||||||
711
libacc/tests/disassem.cpp
Normal file
711
libacc/tests/disassem.cpp
Normal file
|
|
@ -0,0 +1,711 @@
|
||||||
|
/* $NetBSD: disassem.c,v 1.14 2003/03/27 16:58:36 mycroft Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1996 Mark Brinicombe.
|
||||||
|
* Copyright (c) 1996 Brini.
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by Brini.
|
||||||
|
* 4. The name of the company nor the name of the author may be used to
|
||||||
|
* endorse or promote products derived from this software without specific
|
||||||
|
* prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* RiscBSD kernel project
|
||||||
|
*
|
||||||
|
* db_disasm.c
|
||||||
|
*
|
||||||
|
* Kernel disassembler
|
||||||
|
*
|
||||||
|
* Created : 10/02/96
|
||||||
|
*
|
||||||
|
* Structured after the sparc/sparc/db_disasm.c by David S. Miller &
|
||||||
|
* Paul Kranenburg
|
||||||
|
*
|
||||||
|
* This code is not complete. Not all instructions are disassembled.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
//__FBSDID("$FreeBSD: /repoman/r/ncvs/src/sys/arm/arm/disassem.c,v 1.2 2005/01/05 21:58:47 imp Exp $");
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "disassem.h"
|
||||||
|
#include "armreg.h"
|
||||||
|
//#include <ddb/ddb.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* General instruction format
|
||||||
|
*
|
||||||
|
* insn[cc][mod] [operands]
|
||||||
|
*
|
||||||
|
* Those fields with an uppercase format code indicate that the field
|
||||||
|
* follows directly after the instruction before the separator i.e.
|
||||||
|
* they modify the instruction rather than just being an operand to
|
||||||
|
* the instruction. The only exception is the writeback flag which
|
||||||
|
* follows a operand.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* 2 - print Operand 2 of a data processing instruction
|
||||||
|
* d - destination register (bits 12-15)
|
||||||
|
* n - n register (bits 16-19)
|
||||||
|
* s - s register (bits 8-11)
|
||||||
|
* o - indirect register rn (bits 16-19) (used by swap)
|
||||||
|
* m - m register (bits 0-3)
|
||||||
|
* a - address operand of ldr/str instruction
|
||||||
|
* e - address operand of ldrh/strh instruction
|
||||||
|
* l - register list for ldm/stm instruction
|
||||||
|
* f - 1st fp operand (register) (bits 12-14)
|
||||||
|
* g - 2nd fp operand (register) (bits 16-18)
|
||||||
|
* h - 3rd fp operand (register/immediate) (bits 0-4)
|
||||||
|
* b - branch address
|
||||||
|
* t - thumb branch address (bits 24, 0-23)
|
||||||
|
* k - breakpoint comment (bits 0-3, 8-19)
|
||||||
|
* X - block transfer type
|
||||||
|
* Y - block transfer type (r13 base)
|
||||||
|
* c - comment field bits(0-23)
|
||||||
|
* p - saved or current status register
|
||||||
|
* F - PSR transfer fields
|
||||||
|
* D - destination-is-r15 (P) flag on TST, TEQ, CMP, CMN
|
||||||
|
* L - co-processor transfer size
|
||||||
|
* S - set status flag
|
||||||
|
* P - fp precision
|
||||||
|
* Q - fp precision (for ldf/stf)
|
||||||
|
* R - fp rounding
|
||||||
|
* v - co-processor data transfer registers + addressing mode
|
||||||
|
* W - writeback flag
|
||||||
|
* x - instruction in hex
|
||||||
|
* # - co-processor number
|
||||||
|
* y - co-processor data processing registers
|
||||||
|
* z - co-processor register transfer registers
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct arm32_insn {
|
||||||
|
u_int mask;
|
||||||
|
u_int pattern;
|
||||||
|
const char* name;
|
||||||
|
const char* format;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct arm32_insn arm32_i[] = {
|
||||||
|
{ 0x0fffffff, 0x0ff00000, "imb", "c" }, /* Before swi */
|
||||||
|
{ 0x0fffffff, 0x0ff00001, "imbrange", "c" }, /* Before swi */
|
||||||
|
{ 0x0f000000, 0x0f000000, "swi", "c" },
|
||||||
|
{ 0xfe000000, 0xfa000000, "blx", "t" }, /* Before b and bl */
|
||||||
|
{ 0x0f000000, 0x0a000000, "b", "b" },
|
||||||
|
{ 0x0f000000, 0x0b000000, "bl", "b" },
|
||||||
|
{ 0x0fe000f0, 0x00000090, "mul", "Snms" },
|
||||||
|
{ 0x0fe000f0, 0x00200090, "mla", "Snmsd" },
|
||||||
|
{ 0x0fe000f0, 0x00800090, "umull", "Sdnms" },
|
||||||
|
{ 0x0fe000f0, 0x00c00090, "smull", "Sdnms" },
|
||||||
|
{ 0x0fe000f0, 0x00a00090, "umlal", "Sdnms" },
|
||||||
|
{ 0x0fe000f0, 0x00e00090, "smlal", "Sdnms" },
|
||||||
|
{ 0x0d700000, 0x04200000, "strt", "daW" },
|
||||||
|
{ 0x0d700000, 0x04300000, "ldrt", "daW" },
|
||||||
|
{ 0x0d700000, 0x04600000, "strbt", "daW" },
|
||||||
|
{ 0x0d700000, 0x04700000, "ldrbt", "daW" },
|
||||||
|
{ 0x0c500000, 0x04000000, "str", "daW" },
|
||||||
|
{ 0x0c500000, 0x04100000, "ldr", "daW" },
|
||||||
|
{ 0x0c500000, 0x04400000, "strb", "daW" },
|
||||||
|
{ 0x0c500000, 0x04500000, "ldrb", "daW" },
|
||||||
|
{ 0x0e1f0000, 0x080d0000, "stm", "YnWl" },/* separate out r13 base */
|
||||||
|
{ 0x0e1f0000, 0x081d0000, "ldm", "YnWl" },/* separate out r13 base */
|
||||||
|
{ 0x0e100000, 0x08000000, "stm", "XnWl" },
|
||||||
|
{ 0x0e100000, 0x08100000, "ldm", "XnWl" },
|
||||||
|
{ 0x0e1000f0, 0x00100090, "ldrb", "deW" },
|
||||||
|
{ 0x0e1000f0, 0x00000090, "strb", "deW" },
|
||||||
|
{ 0x0e1000f0, 0x001000d0, "ldrsb", "deW" },
|
||||||
|
{ 0x0e1000f0, 0x001000b0, "ldrh", "deW" },
|
||||||
|
{ 0x0e1000f0, 0x000000b0, "strh", "deW" },
|
||||||
|
{ 0x0e1000f0, 0x001000f0, "ldrsh", "deW" },
|
||||||
|
{ 0x0f200090, 0x00200090, "und", "x" }, /* Before data processing */
|
||||||
|
{ 0x0e1000d0, 0x000000d0, "und", "x" }, /* Before data processing */
|
||||||
|
{ 0x0ff00ff0, 0x01000090, "swp", "dmo" },
|
||||||
|
{ 0x0ff00ff0, 0x01400090, "swpb", "dmo" },
|
||||||
|
{ 0x0fbf0fff, 0x010f0000, "mrs", "dp" }, /* Before data processing */
|
||||||
|
{ 0x0fb0fff0, 0x0120f000, "msr", "pFm" },/* Before data processing */
|
||||||
|
{ 0x0fb0f000, 0x0320f000, "msr", "pF2" },/* Before data processing */
|
||||||
|
{ 0x0ffffff0, 0x012fff10, "bx", "m" },
|
||||||
|
{ 0x0fff0ff0, 0x016f0f10, "clz", "dm" },
|
||||||
|
{ 0x0ffffff0, 0x012fff30, "blx", "m" },
|
||||||
|
{ 0xfff000f0, 0xe1200070, "bkpt", "k" },
|
||||||
|
{ 0x0de00000, 0x00000000, "and", "Sdn2" },
|
||||||
|
{ 0x0de00000, 0x00200000, "eor", "Sdn2" },
|
||||||
|
{ 0x0de00000, 0x00400000, "sub", "Sdn2" },
|
||||||
|
{ 0x0de00000, 0x00600000, "rsb", "Sdn2" },
|
||||||
|
{ 0x0de00000, 0x00800000, "add", "Sdn2" },
|
||||||
|
{ 0x0de00000, 0x00a00000, "adc", "Sdn2" },
|
||||||
|
{ 0x0de00000, 0x00c00000, "sbc", "Sdn2" },
|
||||||
|
{ 0x0de00000, 0x00e00000, "rsc", "Sdn2" },
|
||||||
|
{ 0x0df00000, 0x01100000, "tst", "Dn2" },
|
||||||
|
{ 0x0df00000, 0x01300000, "teq", "Dn2" },
|
||||||
|
{ 0x0df00000, 0x01500000, "cmp", "Dn2" },
|
||||||
|
{ 0x0df00000, 0x01700000, "cmn", "Dn2" },
|
||||||
|
{ 0x0de00000, 0x01800000, "orr", "Sdn2" },
|
||||||
|
{ 0x0de00000, 0x01a00000, "mov", "Sd2" },
|
||||||
|
{ 0x0de00000, 0x01c00000, "bic", "Sdn2" },
|
||||||
|
{ 0x0de00000, 0x01e00000, "mvn", "Sd2" },
|
||||||
|
{ 0x0ff08f10, 0x0e000100, "adf", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e100100, "muf", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e200100, "suf", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e300100, "rsf", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e400100, "dvf", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e500100, "rdf", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e600100, "pow", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e700100, "rpw", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e800100, "rmf", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e900100, "fml", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0ea00100, "fdv", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0eb00100, "frd", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0ec00100, "pol", "PRfgh" },
|
||||||
|
{ 0x0f008f10, 0x0e000100, "fpbop", "PRfgh" },
|
||||||
|
{ 0x0ff08f10, 0x0e008100, "mvf", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0e108100, "mnf", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0e208100, "abs", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0e308100, "rnd", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0e408100, "sqt", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0e508100, "log", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0e608100, "lgn", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0e708100, "exp", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0e808100, "sin", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0e908100, "cos", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0ea08100, "tan", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0eb08100, "asn", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0ec08100, "acs", "PRfh" },
|
||||||
|
{ 0x0ff08f10, 0x0ed08100, "atn", "PRfh" },
|
||||||
|
{ 0x0f008f10, 0x0e008100, "fpuop", "PRfh" },
|
||||||
|
{ 0x0e100f00, 0x0c000100, "stf", "QLv" },
|
||||||
|
{ 0x0e100f00, 0x0c100100, "ldf", "QLv" },
|
||||||
|
{ 0x0ff00f10, 0x0e000110, "flt", "PRgd" },
|
||||||
|
{ 0x0ff00f10, 0x0e100110, "fix", "PRdh" },
|
||||||
|
{ 0x0ff00f10, 0x0e200110, "wfs", "d" },
|
||||||
|
{ 0x0ff00f10, 0x0e300110, "rfs", "d" },
|
||||||
|
{ 0x0ff00f10, 0x0e400110, "wfc", "d" },
|
||||||
|
{ 0x0ff00f10, 0x0e500110, "rfc", "d" },
|
||||||
|
{ 0x0ff0ff10, 0x0e90f110, "cmf", "PRgh" },
|
||||||
|
{ 0x0ff0ff10, 0x0eb0f110, "cnf", "PRgh" },
|
||||||
|
{ 0x0ff0ff10, 0x0ed0f110, "cmfe", "PRgh" },
|
||||||
|
{ 0x0ff0ff10, 0x0ef0f110, "cnfe", "PRgh" },
|
||||||
|
{ 0xff100010, 0xfe000010, "mcr2", "#z" },
|
||||||
|
{ 0x0f100010, 0x0e000010, "mcr", "#z" },
|
||||||
|
{ 0xff100010, 0xfe100010, "mrc2", "#z" },
|
||||||
|
{ 0x0f100010, 0x0e100010, "mrc", "#z" },
|
||||||
|
{ 0xff000010, 0xfe000000, "cdp2", "#y" },
|
||||||
|
{ 0x0f000010, 0x0e000000, "cdp", "#y" },
|
||||||
|
{ 0xfe100090, 0xfc100000, "ldc2", "L#v" },
|
||||||
|
{ 0x0e100090, 0x0c100000, "ldc", "L#v" },
|
||||||
|
{ 0xfe100090, 0xfc000000, "stc2", "L#v" },
|
||||||
|
{ 0x0e100090, 0x0c000000, "stc", "L#v" },
|
||||||
|
{ 0xf550f000, 0xf550f000, "pld", "ne" },
|
||||||
|
{ 0x0ff00ff0, 0x01000050, "qaad", "dmn" },
|
||||||
|
{ 0x0ff00ff0, 0x01400050, "qdaad", "dmn" },
|
||||||
|
{ 0x0ff00ff0, 0x01600050, "qdsub", "dmn" },
|
||||||
|
{ 0x0ff00ff0, 0x01200050, "dsub", "dmn" },
|
||||||
|
{ 0x0ff000f0, 0x01000080, "smlabb", "nmsd" }, // d & n inverted!!
|
||||||
|
{ 0x0ff000f0, 0x010000a0, "smlatb", "nmsd" }, // d & n inverted!!
|
||||||
|
{ 0x0ff000f0, 0x010000c0, "smlabt", "nmsd" }, // d & n inverted!!
|
||||||
|
{ 0x0ff000f0, 0x010000e0, "smlatt", "nmsd" }, // d & n inverted!!
|
||||||
|
{ 0x0ff000f0, 0x01400080, "smlalbb","ndms" }, // d & n inverted!!
|
||||||
|
{ 0x0ff000f0, 0x014000a0, "smlaltb","ndms" }, // d & n inverted!!
|
||||||
|
{ 0x0ff000f0, 0x014000c0, "smlalbt","ndms" }, // d & n inverted!!
|
||||||
|
{ 0x0ff000f0, 0x014000e0, "smlaltt","ndms" }, // d & n inverted!!
|
||||||
|
{ 0x0ff000f0, 0x01200080, "smlawb", "nmsd" }, // d & n inverted!!
|
||||||
|
{ 0x0ff0f0f0, 0x012000a0, "smulwb","nms" }, // d & n inverted!!
|
||||||
|
{ 0x0ff000f0, 0x012000c0, "smlawt", "nmsd" }, // d & n inverted!!
|
||||||
|
{ 0x0ff0f0f0, 0x012000e0, "smulwt","nms" }, // d & n inverted!!
|
||||||
|
{ 0x0ff0f0f0, 0x01600080, "smulbb","nms" }, // d & n inverted!!
|
||||||
|
{ 0x0ff0f0f0, 0x016000a0, "smultb","nms" }, // d & n inverted!!
|
||||||
|
{ 0x0ff0f0f0, 0x016000c0, "smulbt","nms" }, // d & n inverted!!
|
||||||
|
{ 0x0ff0f0f0, 0x016000e0, "smultt","nms" }, // d & n inverted!!
|
||||||
|
{ 0x00000000, 0x00000000, NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static char const arm32_insn_conditions[][4] = {
|
||||||
|
"eq", "ne", "cs", "cc",
|
||||||
|
"mi", "pl", "vs", "vc",
|
||||||
|
"hi", "ls", "ge", "lt",
|
||||||
|
"gt", "le", "", "nv"
|
||||||
|
};
|
||||||
|
|
||||||
|
static char const insn_block_transfers[][4] = {
|
||||||
|
"da", "ia", "db", "ib"
|
||||||
|
};
|
||||||
|
|
||||||
|
static char const insn_stack_block_transfers[][4] = {
|
||||||
|
"ed", "ea", "fd", "fa"
|
||||||
|
};
|
||||||
|
|
||||||
|
static char const op_shifts[][4] = {
|
||||||
|
"lsl", "lsr", "asr", "ror"
|
||||||
|
};
|
||||||
|
|
||||||
|
static char const insn_fpa_rounding[][2] = {
|
||||||
|
"", "p", "m", "z"
|
||||||
|
};
|
||||||
|
|
||||||
|
static char const insn_fpa_precision[][2] = {
|
||||||
|
"s", "d", "e", "p"
|
||||||
|
};
|
||||||
|
|
||||||
|
static char const insn_fpaconstants[][8] = {
|
||||||
|
"0.0", "1.0", "2.0", "3.0",
|
||||||
|
"4.0", "5.0", "0.5", "10.0"
|
||||||
|
};
|
||||||
|
|
||||||
|
#define insn_condition(x) arm32_insn_conditions[(x >> 28) & 0x0f]
|
||||||
|
#define insn_blktrans(x) insn_block_transfers[(x >> 23) & 3]
|
||||||
|
#define insn_stkblktrans(x) insn_stack_block_transfers[(x >> 23) & 3]
|
||||||
|
#define op2_shift(x) op_shifts[(x >> 5) & 3]
|
||||||
|
#define insn_fparnd(x) insn_fpa_rounding[(x >> 5) & 0x03]
|
||||||
|
#define insn_fpaprec(x) insn_fpa_precision[(((x >> 18) & 2)|(x >> 7)) & 1]
|
||||||
|
#define insn_fpaprect(x) insn_fpa_precision[(((x >> 21) & 2)|(x >> 15)) & 1]
|
||||||
|
#define insn_fpaimm(x) insn_fpaconstants[x & 0x07]
|
||||||
|
|
||||||
|
/* Local prototypes */
|
||||||
|
static void disasm_register_shift(const disasm_interface_t *di, u_int insn);
|
||||||
|
static void disasm_print_reglist(const disasm_interface_t *di, u_int insn);
|
||||||
|
static void disasm_insn_ldrstr(const disasm_interface_t *di, u_int insn,
|
||||||
|
u_int loc);
|
||||||
|
static void disasm_insn_ldrhstrh(const disasm_interface_t *di, u_int insn,
|
||||||
|
u_int loc);
|
||||||
|
static void disasm_insn_ldcstc(const disasm_interface_t *di, u_int insn,
|
||||||
|
u_int loc);
|
||||||
|
static u_int disassemble_readword(u_int address);
|
||||||
|
static void disassemble_printaddr(u_int address);
|
||||||
|
|
||||||
|
u_int
|
||||||
|
disasm(const disasm_interface_t *di, u_int loc, int altfmt)
|
||||||
|
{
|
||||||
|
const struct arm32_insn *i_ptr = &arm32_i[0];
|
||||||
|
|
||||||
|
u_int insn;
|
||||||
|
int matchp;
|
||||||
|
int branch;
|
||||||
|
const char* f_ptr;
|
||||||
|
int fmt;
|
||||||
|
|
||||||
|
fmt = 0;
|
||||||
|
matchp = 0;
|
||||||
|
insn = di->di_readword(loc);
|
||||||
|
|
||||||
|
/* di->di_printf("loc=%08x insn=%08x : ", loc, insn);*/
|
||||||
|
|
||||||
|
while (i_ptr->name) {
|
||||||
|
if ((insn & i_ptr->mask) == i_ptr->pattern) {
|
||||||
|
matchp = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i_ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!matchp) {
|
||||||
|
di->di_printf("und%s\t%08x\n", insn_condition(insn), insn);
|
||||||
|
return(loc + INSN_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If instruction forces condition code, don't print it. */
|
||||||
|
if ((i_ptr->mask & 0xf0000000) == 0xf0000000)
|
||||||
|
di->di_printf("%s", i_ptr->name);
|
||||||
|
else
|
||||||
|
di->di_printf("%s%s", i_ptr->name, insn_condition(insn));
|
||||||
|
|
||||||
|
f_ptr = i_ptr->format;
|
||||||
|
|
||||||
|
/* Insert tab if there are no instruction modifiers */
|
||||||
|
|
||||||
|
if (*(f_ptr) < 'A' || *(f_ptr) > 'Z') {
|
||||||
|
++fmt;
|
||||||
|
di->di_printf("\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*f_ptr) {
|
||||||
|
switch (*f_ptr) {
|
||||||
|
/* 2 - print Operand 2 of a data processing instruction */
|
||||||
|
case '2':
|
||||||
|
if (insn & 0x02000000) {
|
||||||
|
int rotate= ((insn >> 7) & 0x1e);
|
||||||
|
|
||||||
|
di->di_printf("#0x%08x",
|
||||||
|
(insn & 0xff) << (32 - rotate) |
|
||||||
|
(insn & 0xff) >> rotate);
|
||||||
|
} else {
|
||||||
|
disasm_register_shift(di, insn);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* d - destination register (bits 12-15) */
|
||||||
|
case 'd':
|
||||||
|
di->di_printf("r%d", ((insn >> 12) & 0x0f));
|
||||||
|
break;
|
||||||
|
/* D - insert 'p' if Rd is R15 */
|
||||||
|
case 'D':
|
||||||
|
if (((insn >> 12) & 0x0f) == 15)
|
||||||
|
di->di_printf("p");
|
||||||
|
break;
|
||||||
|
/* n - n register (bits 16-19) */
|
||||||
|
case 'n':
|
||||||
|
di->di_printf("r%d", ((insn >> 16) & 0x0f));
|
||||||
|
break;
|
||||||
|
/* s - s register (bits 8-11) */
|
||||||
|
case 's':
|
||||||
|
di->di_printf("r%d", ((insn >> 8) & 0x0f));
|
||||||
|
break;
|
||||||
|
/* o - indirect register rn (bits 16-19) (used by swap) */
|
||||||
|
case 'o':
|
||||||
|
di->di_printf("[r%d]", ((insn >> 16) & 0x0f));
|
||||||
|
break;
|
||||||
|
/* m - m register (bits 0-4) */
|
||||||
|
case 'm':
|
||||||
|
di->di_printf("r%d", ((insn >> 0) & 0x0f));
|
||||||
|
break;
|
||||||
|
/* a - address operand of ldr/str instruction */
|
||||||
|
case 'a':
|
||||||
|
disasm_insn_ldrstr(di, insn, loc);
|
||||||
|
break;
|
||||||
|
/* e - address operand of ldrh/strh instruction */
|
||||||
|
case 'e':
|
||||||
|
disasm_insn_ldrhstrh(di, insn, loc);
|
||||||
|
break;
|
||||||
|
/* l - register list for ldm/stm instruction */
|
||||||
|
case 'l':
|
||||||
|
disasm_print_reglist(di, insn);
|
||||||
|
break;
|
||||||
|
/* f - 1st fp operand (register) (bits 12-14) */
|
||||||
|
case 'f':
|
||||||
|
di->di_printf("f%d", (insn >> 12) & 7);
|
||||||
|
break;
|
||||||
|
/* g - 2nd fp operand (register) (bits 16-18) */
|
||||||
|
case 'g':
|
||||||
|
di->di_printf("f%d", (insn >> 16) & 7);
|
||||||
|
break;
|
||||||
|
/* h - 3rd fp operand (register/immediate) (bits 0-4) */
|
||||||
|
case 'h':
|
||||||
|
if (insn & (1 << 3))
|
||||||
|
di->di_printf("#%s", insn_fpaimm(insn));
|
||||||
|
else
|
||||||
|
di->di_printf("f%d", insn & 7);
|
||||||
|
break;
|
||||||
|
/* b - branch address */
|
||||||
|
case 'b':
|
||||||
|
branch = ((insn << 2) & 0x03ffffff);
|
||||||
|
if (branch & 0x02000000)
|
||||||
|
branch |= 0xfc000000;
|
||||||
|
di->di_printaddr(loc + 8 + branch);
|
||||||
|
break;
|
||||||
|
/* t - blx address */
|
||||||
|
case 't':
|
||||||
|
branch = ((insn << 2) & 0x03ffffff) |
|
||||||
|
(insn >> 23 & 0x00000002);
|
||||||
|
if (branch & 0x02000000)
|
||||||
|
branch |= 0xfc000000;
|
||||||
|
di->di_printaddr(loc + 8 + branch);
|
||||||
|
break;
|
||||||
|
/* X - block transfer type */
|
||||||
|
case 'X':
|
||||||
|
di->di_printf("%s", insn_blktrans(insn));
|
||||||
|
break;
|
||||||
|
/* Y - block transfer type (r13 base) */
|
||||||
|
case 'Y':
|
||||||
|
di->di_printf("%s", insn_stkblktrans(insn));
|
||||||
|
break;
|
||||||
|
/* c - comment field bits(0-23) */
|
||||||
|
case 'c':
|
||||||
|
di->di_printf("0x%08x", (insn & 0x00ffffff));
|
||||||
|
break;
|
||||||
|
/* k - breakpoint comment (bits 0-3, 8-19) */
|
||||||
|
case 'k':
|
||||||
|
di->di_printf("0x%04x",
|
||||||
|
(insn & 0x000fff00) >> 4 | (insn & 0x0000000f));
|
||||||
|
break;
|
||||||
|
/* p - saved or current status register */
|
||||||
|
case 'p':
|
||||||
|
if (insn & 0x00400000)
|
||||||
|
di->di_printf("spsr");
|
||||||
|
else
|
||||||
|
di->di_printf("cpsr");
|
||||||
|
break;
|
||||||
|
/* F - PSR transfer fields */
|
||||||
|
case 'F':
|
||||||
|
di->di_printf("_");
|
||||||
|
if (insn & (1 << 16))
|
||||||
|
di->di_printf("c");
|
||||||
|
if (insn & (1 << 17))
|
||||||
|
di->di_printf("x");
|
||||||
|
if (insn & (1 << 18))
|
||||||
|
di->di_printf("s");
|
||||||
|
if (insn & (1 << 19))
|
||||||
|
di->di_printf("f");
|
||||||
|
break;
|
||||||
|
/* B - byte transfer flag */
|
||||||
|
case 'B':
|
||||||
|
if (insn & 0x00400000)
|
||||||
|
di->di_printf("b");
|
||||||
|
break;
|
||||||
|
/* L - co-processor transfer size */
|
||||||
|
case 'L':
|
||||||
|
if (insn & (1 << 22))
|
||||||
|
di->di_printf("l");
|
||||||
|
break;
|
||||||
|
/* S - set status flag */
|
||||||
|
case 'S':
|
||||||
|
if (insn & 0x00100000)
|
||||||
|
di->di_printf("s");
|
||||||
|
break;
|
||||||
|
/* P - fp precision */
|
||||||
|
case 'P':
|
||||||
|
di->di_printf("%s", insn_fpaprec(insn));
|
||||||
|
break;
|
||||||
|
/* Q - fp precision (for ldf/stf) */
|
||||||
|
case 'Q':
|
||||||
|
break;
|
||||||
|
/* R - fp rounding */
|
||||||
|
case 'R':
|
||||||
|
di->di_printf("%s", insn_fparnd(insn));
|
||||||
|
break;
|
||||||
|
/* W - writeback flag */
|
||||||
|
case 'W':
|
||||||
|
if (insn & (1 << 21))
|
||||||
|
di->di_printf("!");
|
||||||
|
break;
|
||||||
|
/* # - co-processor number */
|
||||||
|
case '#':
|
||||||
|
di->di_printf("p%d", (insn >> 8) & 0x0f);
|
||||||
|
break;
|
||||||
|
/* v - co-processor data transfer registers+addressing mode */
|
||||||
|
case 'v':
|
||||||
|
disasm_insn_ldcstc(di, insn, loc);
|
||||||
|
break;
|
||||||
|
/* x - instruction in hex */
|
||||||
|
case 'x':
|
||||||
|
di->di_printf("0x%08x", insn);
|
||||||
|
break;
|
||||||
|
/* y - co-processor data processing registers */
|
||||||
|
case 'y':
|
||||||
|
di->di_printf("%d, ", (insn >> 20) & 0x0f);
|
||||||
|
|
||||||
|
di->di_printf("c%d, c%d, c%d", (insn >> 12) & 0x0f,
|
||||||
|
(insn >> 16) & 0x0f, insn & 0x0f);
|
||||||
|
|
||||||
|
di->di_printf(", %d", (insn >> 5) & 0x07);
|
||||||
|
break;
|
||||||
|
/* z - co-processor register transfer registers */
|
||||||
|
case 'z':
|
||||||
|
di->di_printf("%d, ", (insn >> 21) & 0x07);
|
||||||
|
di->di_printf("r%d, c%d, c%d, %d",
|
||||||
|
(insn >> 12) & 0x0f, (insn >> 16) & 0x0f,
|
||||||
|
insn & 0x0f, (insn >> 5) & 0x07);
|
||||||
|
|
||||||
|
/* if (((insn >> 5) & 0x07) != 0)
|
||||||
|
di->di_printf(", %d", (insn >> 5) & 0x07);*/
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
di->di_printf("[%c - unknown]", *f_ptr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (*(f_ptr+1) >= 'A' && *(f_ptr+1) <= 'Z')
|
||||||
|
++f_ptr;
|
||||||
|
else if (*(++f_ptr)) {
|
||||||
|
++fmt;
|
||||||
|
if (fmt == 1)
|
||||||
|
di->di_printf("\t");
|
||||||
|
else
|
||||||
|
di->di_printf(", ");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
di->di_printf("\n");
|
||||||
|
|
||||||
|
return(loc + INSN_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
disasm_register_shift(const disasm_interface_t *di, u_int insn)
|
||||||
|
{
|
||||||
|
di->di_printf("r%d", (insn & 0x0f));
|
||||||
|
if ((insn & 0x00000ff0) == 0)
|
||||||
|
;
|
||||||
|
else if ((insn & 0x00000ff0) == 0x00000060)
|
||||||
|
di->di_printf(", rrx");
|
||||||
|
else {
|
||||||
|
if (insn & 0x10)
|
||||||
|
di->di_printf(", %s r%d", op2_shift(insn),
|
||||||
|
(insn >> 8) & 0x0f);
|
||||||
|
else
|
||||||
|
di->di_printf(", %s #%d", op2_shift(insn),
|
||||||
|
(insn >> 7) & 0x1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
disasm_print_reglist(const disasm_interface_t *di, u_int insn)
|
||||||
|
{
|
||||||
|
int loop;
|
||||||
|
int start;
|
||||||
|
int comma;
|
||||||
|
|
||||||
|
di->di_printf("{");
|
||||||
|
start = -1;
|
||||||
|
comma = 0;
|
||||||
|
|
||||||
|
for (loop = 0; loop < 17; ++loop) {
|
||||||
|
if (start != -1) {
|
||||||
|
if (loop == 16 || !(insn & (1 << loop))) {
|
||||||
|
if (comma)
|
||||||
|
di->di_printf(", ");
|
||||||
|
else
|
||||||
|
comma = 1;
|
||||||
|
if (start == loop - 1)
|
||||||
|
di->di_printf("r%d", start);
|
||||||
|
else
|
||||||
|
di->di_printf("r%d-r%d", start, loop - 1);
|
||||||
|
start = -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (insn & (1 << loop))
|
||||||
|
start = loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
di->di_printf("}");
|
||||||
|
|
||||||
|
if (insn & (1 << 22))
|
||||||
|
di->di_printf("^");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
disasm_insn_ldrstr(const disasm_interface_t *di, u_int insn, u_int loc)
|
||||||
|
{
|
||||||
|
int offset;
|
||||||
|
|
||||||
|
offset = insn & 0xfff;
|
||||||
|
if ((insn & 0x032f0000) == 0x010f0000) {
|
||||||
|
/* rA = pc, immediate index */
|
||||||
|
if (insn & 0x00800000)
|
||||||
|
loc += offset;
|
||||||
|
else
|
||||||
|
loc -= offset;
|
||||||
|
di->di_printaddr(loc + 8);
|
||||||
|
} else {
|
||||||
|
di->di_printf("[r%d", (insn >> 16) & 0x0f);
|
||||||
|
if ((insn & 0x03000fff) != 0x01000000) {
|
||||||
|
di->di_printf("%s, ", (insn & (1 << 24)) ? "" : "]");
|
||||||
|
if (!(insn & 0x00800000))
|
||||||
|
di->di_printf("-");
|
||||||
|
if (insn & (1 << 25))
|
||||||
|
disasm_register_shift(di, insn);
|
||||||
|
else
|
||||||
|
di->di_printf("#0x%03x", offset);
|
||||||
|
}
|
||||||
|
if (insn & (1 << 24))
|
||||||
|
di->di_printf("]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
disasm_insn_ldrhstrh(const disasm_interface_t *di, u_int insn, u_int loc)
|
||||||
|
{
|
||||||
|
int offset;
|
||||||
|
|
||||||
|
offset = ((insn & 0xf00) >> 4) | (insn & 0xf);
|
||||||
|
if ((insn & 0x004f0000) == 0x004f0000) {
|
||||||
|
/* rA = pc, immediate index */
|
||||||
|
if (insn & 0x00800000)
|
||||||
|
loc += offset;
|
||||||
|
else
|
||||||
|
loc -= offset;
|
||||||
|
di->di_printaddr(loc + 8);
|
||||||
|
} else {
|
||||||
|
di->di_printf("[r%d", (insn >> 16) & 0x0f);
|
||||||
|
if ((insn & 0x01400f0f) != 0x01400000) {
|
||||||
|
di->di_printf("%s, ", (insn & (1 << 24)) ? "" : "]");
|
||||||
|
if (!(insn & 0x00800000))
|
||||||
|
di->di_printf("-");
|
||||||
|
if (insn & (1 << 22))
|
||||||
|
di->di_printf("#0x%02x", offset);
|
||||||
|
else
|
||||||
|
di->di_printf("r%d", (insn & 0x0f));
|
||||||
|
}
|
||||||
|
if (insn & (1 << 24))
|
||||||
|
di->di_printf("]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
disasm_insn_ldcstc(const disasm_interface_t *di, u_int insn, u_int loc)
|
||||||
|
{
|
||||||
|
if (((insn >> 8) & 0xf) == 1)
|
||||||
|
di->di_printf("f%d, ", (insn >> 12) & 0x07);
|
||||||
|
else
|
||||||
|
di->di_printf("c%d, ", (insn >> 12) & 0x0f);
|
||||||
|
|
||||||
|
di->di_printf("[r%d", (insn >> 16) & 0x0f);
|
||||||
|
|
||||||
|
di->di_printf("%s, ", (insn & (1 << 24)) ? "" : "]");
|
||||||
|
|
||||||
|
if (!(insn & (1 << 23)))
|
||||||
|
di->di_printf("-");
|
||||||
|
|
||||||
|
di->di_printf("#0x%03x", (insn & 0xff) << 2);
|
||||||
|
|
||||||
|
if (insn & (1 << 24))
|
||||||
|
di->di_printf("]");
|
||||||
|
|
||||||
|
if (insn & (1 << 21))
|
||||||
|
di->di_printf("!");
|
||||||
|
}
|
||||||
|
|
||||||
|
static u_int
|
||||||
|
disassemble_readword(u_int address)
|
||||||
|
{
|
||||||
|
return(*((u_int *)address));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
disassemble_printaddr(u_int address)
|
||||||
|
{
|
||||||
|
printf("0x%08x", address);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
disassemble_printf(const char *fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vprintf(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const disasm_interface_t disassemble_di = {
|
||||||
|
disassemble_readword, disassemble_printaddr, disassemble_printf
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
disassemble(u_int address)
|
||||||
|
{
|
||||||
|
|
||||||
|
(void)disasm(&disassemble_di, address, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of disassem.c */
|
||||||
65
libacc/tests/disassem.h
Normal file
65
libacc/tests/disassem.h
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
/* $NetBSD: disassem.h,v 1.4 2001/03/04 04:15:58 matt Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1997 Mark Brinicombe.
|
||||||
|
* Copyright (c) 1997 Causality Limited.
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by Mark Brinicombe.
|
||||||
|
* 4. The name of the company nor the name of the author may be used to
|
||||||
|
* endorse or promote products derived from this software without specific
|
||||||
|
* prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* Define the interface structure required by the disassembler.
|
||||||
|
*
|
||||||
|
* $FreeBSD: /repoman/r/ncvs/src/sys/arm/include/disassem.h,v 1.2 2005/01/05 21:58:48 imp Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANDROID_MACHINE_DISASSEM_H
|
||||||
|
#define ANDROID_MACHINE_DISASSEM_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u_int (*di_readword)(u_int);
|
||||||
|
void (*di_printaddr)(u_int);
|
||||||
|
void (*di_printf)(const char *, ...);
|
||||||
|
} disasm_interface_t;
|
||||||
|
|
||||||
|
/* Prototypes for callable functions */
|
||||||
|
|
||||||
|
u_int disasm(const disasm_interface_t *, u_int, int);
|
||||||
|
void disassemble(u_int);
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !ANDROID_MACHINE_DISASSEM_H */
|
||||||
207
libacc/tests/main.cpp
Normal file
207
libacc/tests/main.cpp
Normal file
|
|
@ -0,0 +1,207 @@
|
||||||
|
/*
|
||||||
|
* Android "Almost" C Compiler.
|
||||||
|
* This is a compiler for a small subset of the C language, intended for use
|
||||||
|
* in scripting environments where speed and memory footprint are important.
|
||||||
|
*
|
||||||
|
* This code is based upon the "unobfuscated" version of the
|
||||||
|
* Obfuscated Tiny C compiler, see the file LICENSE for details.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#if defined(__arm__)
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__arm__)
|
||||||
|
#define PROVIDE_ARM_DISASSEMBLY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PROVIDE_ARM_DISASSEMBLY
|
||||||
|
#include "disassem.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <acc/acc.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef int (*MainPtr)(int, char**);
|
||||||
|
// This is a separate function so it can easily be set by breakpoint in gdb.
|
||||||
|
int run(MainPtr mainFunc, int argc, char** argv) {
|
||||||
|
return mainFunc(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) {
|
||||||
|
return (ACCvoid*) dlsym(RTLD_DEFAULT, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PROVIDE_ARM_DISASSEMBLY
|
||||||
|
|
||||||
|
static FILE* disasmOut;
|
||||||
|
|
||||||
|
static u_int
|
||||||
|
disassemble_readword(u_int address)
|
||||||
|
{
|
||||||
|
return(*((u_int *)address));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
disassemble_printaddr(u_int address)
|
||||||
|
{
|
||||||
|
fprintf(disasmOut, "0x%08x", address);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
disassemble_printf(const char *fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vfprintf(disasmOut, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int disassemble(ACCscript* script, FILE* out) {
|
||||||
|
disasmOut = out;
|
||||||
|
disasm_interface_t di;
|
||||||
|
di.di_readword = disassemble_readword;
|
||||||
|
di.di_printaddr = disassemble_printaddr;
|
||||||
|
di.di_printf = disassemble_printf;
|
||||||
|
|
||||||
|
ACCvoid* base;
|
||||||
|
ACCsizei length;
|
||||||
|
|
||||||
|
accGetProgramBinary(script, &base, &length);
|
||||||
|
unsigned long* pBase = (unsigned long*) base;
|
||||||
|
unsigned long* pEnd = (unsigned long*) (((unsigned char*) base) + length);
|
||||||
|
|
||||||
|
for(unsigned long* pInstruction = pBase; pInstruction < pEnd; pInstruction++) {
|
||||||
|
fprintf(out, "%08x: %08x ", (int) pInstruction, (int) *pInstruction);
|
||||||
|
::disasm(&di, (uint) pInstruction, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // PROVIDE_ARM_DISASSEMBLY
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
const char* inFile = NULL;
|
||||||
|
bool printListing;
|
||||||
|
bool runResults = false;
|
||||||
|
FILE* in = stdin;
|
||||||
|
int i;
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
char* arg = argv[i];
|
||||||
|
if (arg[0] == '-') {
|
||||||
|
switch (arg[1]) {
|
||||||
|
case 'S':
|
||||||
|
printListing = true;
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
runResults = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Unrecognized flag %s\n", arg);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
} else if (inFile == NULL) {
|
||||||
|
inFile = arg;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! inFile) {
|
||||||
|
fprintf(stderr, "input file required\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inFile) {
|
||||||
|
in = fopen(inFile, "r");
|
||||||
|
if (!in) {
|
||||||
|
fprintf(stderr, "Could not open input file %s\n", inFile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(in, 0, SEEK_END);
|
||||||
|
size_t fileSize = (size_t) ftell(in);
|
||||||
|
rewind(in);
|
||||||
|
ACCchar* text = new ACCchar[fileSize + 1];
|
||||||
|
size_t bytesRead = fread(text, 1, fileSize, in);
|
||||||
|
if (bytesRead != fileSize) {
|
||||||
|
fprintf(stderr, "Could not read all of file %s\n", inFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
text[fileSize] = '\0';
|
||||||
|
|
||||||
|
ACCscript* script = accCreateScript();
|
||||||
|
|
||||||
|
const ACCchar* scriptSource[] = {text};
|
||||||
|
accScriptSource(script, 1, scriptSource, NULL);
|
||||||
|
delete[] text;
|
||||||
|
|
||||||
|
accRegisterSymbolCallback(script, symbolLookup, NULL);
|
||||||
|
|
||||||
|
accCompileScript(script);
|
||||||
|
int result = accGetError(script);
|
||||||
|
MainPtr mainPointer = 0;
|
||||||
|
if (result != 0) {
|
||||||
|
ACCsizei bufferLength;
|
||||||
|
accGetScriptInfoLog(script, 0, &bufferLength, NULL);
|
||||||
|
char* buf = (char*) malloc(bufferLength + 1);
|
||||||
|
if (buf != NULL) {
|
||||||
|
accGetScriptInfoLog(script, bufferLength + 1, NULL, buf);
|
||||||
|
fprintf(stderr, "%s", buf);
|
||||||
|
free(buf);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Out of memory.\n");
|
||||||
|
}
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ACCsizei numPragmaStrings;
|
||||||
|
accGetPragmas(script, &numPragmaStrings, 0, NULL);
|
||||||
|
if (numPragmaStrings) {
|
||||||
|
char** strings = new char*[numPragmaStrings];
|
||||||
|
accGetPragmas(script, NULL, numPragmaStrings, strings);
|
||||||
|
for(ACCsizei i = 0; i < numPragmaStrings; i += 2) {
|
||||||
|
fprintf(stderr, "#pragma %s(%s)\n", strings[i], strings[i+1]);
|
||||||
|
}
|
||||||
|
delete[] strings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (printListing) {
|
||||||
|
#ifdef PROVIDE_ARM_DISASSEMBLY
|
||||||
|
disassemble(script, stderr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (runResults) {
|
||||||
|
accGetScriptLabel(script, "main", (ACCvoid**) & mainPointer);
|
||||||
|
|
||||||
|
result = accGetError(script);
|
||||||
|
if (result != ACC_NO_ERROR) {
|
||||||
|
fprintf(stderr, "Could not find main: %d\n", result);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Executing compiled code:\n");
|
||||||
|
int codeArgc = argc - i + 1;
|
||||||
|
char** codeArgv = argv + i - 1;
|
||||||
|
codeArgv[0] = (char*) (inFile ? inFile : "stdin");
|
||||||
|
result = run(mainPointer, codeArgc, codeArgv);
|
||||||
|
fprintf(stderr, "result: %d\n", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
|
||||||
|
accDeleteScript(script);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
118
libacc/tests/runtimeTest.cpp
Normal file
118
libacc/tests/runtimeTest.cpp
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
* RuntimeTest for ACC compiler.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#if defined(__arm__)
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <acc/acc.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef void (*ScriptPtr)();
|
||||||
|
|
||||||
|
// This is a separate function so it can easily be set by breakpoint in gdb.
|
||||||
|
void run(ScriptPtr scriptFn) {
|
||||||
|
scriptFn();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private API for development:
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
void accDisassemble(ACCscript* script);
|
||||||
|
|
||||||
|
int globalVar;
|
||||||
|
|
||||||
|
void op_int(int a) {
|
||||||
|
printf("op_int(%d)\n", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void op_float12(float a, float b, float c, float d,
|
||||||
|
float e, float f, float g, float h,
|
||||||
|
float i, float j, float k, float l) {
|
||||||
|
printf("op_float12(%g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g)\n",
|
||||||
|
a, b, c, d, e, f, g, h, i, j, k, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* text = "void op_int(int a);\n"
|
||||||
|
"void op_float12(float a, float b, float c, float d,\n"
|
||||||
|
" float e, float f, float g, float h,\n"
|
||||||
|
" float i, float j, float k, float l);\n"
|
||||||
|
"void script() {\n"
|
||||||
|
" globalVar += 3;\n"
|
||||||
|
" op_int(123);\n"
|
||||||
|
" op_float12(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) {
|
||||||
|
if (strcmp("op_int", name) == 0) {
|
||||||
|
return (ACCvoid*) op_int;
|
||||||
|
}
|
||||||
|
if (strcmp("op_float12", name) == 0) {
|
||||||
|
return (ACCvoid*) op_float12;
|
||||||
|
}
|
||||||
|
if (strcmp("globalVar", name) == 0) {
|
||||||
|
return (ACCvoid*) &globalVar;
|
||||||
|
}
|
||||||
|
return (ACCvoid*) dlsym(RTLD_DEFAULT, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
ACCscript* script = accCreateScript();
|
||||||
|
|
||||||
|
accRegisterSymbolCallback(script, symbolLookup, NULL);
|
||||||
|
|
||||||
|
const ACCchar* scriptSource[] = {text};
|
||||||
|
accScriptSource(script, 1, scriptSource, NULL);
|
||||||
|
|
||||||
|
accCompileScript(script);
|
||||||
|
int result = accGetError(script);
|
||||||
|
ScriptPtr scriptPointer = 0;
|
||||||
|
if (result != 0) {
|
||||||
|
char buf[1024];
|
||||||
|
accGetScriptInfoLog(script, sizeof(buf), NULL, buf);
|
||||||
|
fprintf(stderr, "%s", buf);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ACCsizei numPragmaStrings;
|
||||||
|
accGetPragmas(script, &numPragmaStrings, 0, NULL);
|
||||||
|
if (numPragmaStrings) {
|
||||||
|
char** strings = new char*[numPragmaStrings];
|
||||||
|
accGetPragmas(script, NULL, numPragmaStrings, strings);
|
||||||
|
for(ACCsizei i = 0; i < numPragmaStrings; i += 2) {
|
||||||
|
fprintf(stderr, "#pragma %s(%s)\n", strings[i], strings[i+1]);
|
||||||
|
}
|
||||||
|
delete[] strings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
accGetScriptLabel(script, "script", (ACCvoid**) & scriptPointer);
|
||||||
|
|
||||||
|
result = accGetError(script);
|
||||||
|
if (result != ACC_NO_ERROR) {
|
||||||
|
fprintf(stderr, "Could not find script: %d\n", result);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Executing script:\n");
|
||||||
|
globalVar = 17;
|
||||||
|
run(scriptPointer);
|
||||||
|
fprintf(stderr, "After script globalVar = %d\n", globalVar);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exit:
|
||||||
|
|
||||||
|
accDeleteScript(script);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
6
libacc/tests/test
Executable file
6
libacc/tests/test
Executable file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SCRIPT_DIR=`dirname $BASH_SOURCE`
|
||||||
|
cd $SCRIPT_DIR
|
||||||
|
python test.py "$@"
|
||||||
|
|
||||||
493
libacc/tests/test.py
Normal file
493
libacc/tests/test.py
Normal file
|
|
@ -0,0 +1,493 @@
|
||||||
|
#
|
||||||
|
# Test the acc compiler
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
gArmInitialized = False
|
||||||
|
gUseArm = True
|
||||||
|
gUseX86 = True
|
||||||
|
gRunOTCCOutput = True
|
||||||
|
|
||||||
|
|
||||||
|
def parseArgv():
|
||||||
|
global gUseArm
|
||||||
|
global gUseX86
|
||||||
|
global gRunOTCCOutput
|
||||||
|
for arg in sys.argv[1:]:
|
||||||
|
if arg == "--noarm":
|
||||||
|
print "--noarm: not testing ARM"
|
||||||
|
gUseArm = False
|
||||||
|
elif arg == "--nox86":
|
||||||
|
print "--nox86: not testing x86"
|
||||||
|
gUseX86 = False
|
||||||
|
elif arg == "--norunotcc":
|
||||||
|
print "--norunotcc detected, not running OTCC output"
|
||||||
|
gRunOTCCOutput = False
|
||||||
|
else:
|
||||||
|
print "Unknown parameter: ", arg
|
||||||
|
raise "Unknown parameter"
|
||||||
|
sys.argv = sys.argv[0:1]
|
||||||
|
|
||||||
|
def compile(args):
|
||||||
|
proc = subprocess.Popen(["acc"] + args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
result = proc.communicate()
|
||||||
|
return result
|
||||||
|
|
||||||
|
def runCmd(args):
|
||||||
|
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
result = proc.communicate()
|
||||||
|
return result[0].strip()
|
||||||
|
|
||||||
|
def uname():
|
||||||
|
return runCmd(["uname"])
|
||||||
|
|
||||||
|
def unameM():
|
||||||
|
return runCmd(["uname", "-m"])
|
||||||
|
|
||||||
|
def which(item):
|
||||||
|
return runCmd(["which", item])
|
||||||
|
|
||||||
|
def fileType(item):
|
||||||
|
return runCmd(["file", item])
|
||||||
|
|
||||||
|
def outputCanRun():
|
||||||
|
ft = fileType(which("acc"))
|
||||||
|
return ft.find("ELF 32-bit LSB executable, Intel 80386") >= 0
|
||||||
|
|
||||||
|
def checkEnvironment():
|
||||||
|
global gRunOTCCOutput
|
||||||
|
gRunOTCCOutput = uname() == "Linux" and unameM() != "x86_64" and outputCanRun()
|
||||||
|
|
||||||
|
def adb(args):
|
||||||
|
return runCmd(["adb"] + args)
|
||||||
|
|
||||||
|
def setupArm():
|
||||||
|
global gArmInitialized
|
||||||
|
if gArmInitialized:
|
||||||
|
return
|
||||||
|
print "Setting up arm"
|
||||||
|
adb(["remount"])
|
||||||
|
adb(["shell", "rm", "/system/bin/acc"])
|
||||||
|
adb(["shell", "mkdir", "/system/bin/accdata"])
|
||||||
|
adb(["shell", "mkdir", "/system/bin/accdata/data"])
|
||||||
|
# Clear out old data TODO: handle recursion
|
||||||
|
adb(["shell", "rm", "/system/bin/accdata/data/*"])
|
||||||
|
# Copy over data
|
||||||
|
for root, dirs, files in os.walk("data"):
|
||||||
|
for d in dirs:
|
||||||
|
adb(["shell", "mkdir", os.path.join(root, d)])
|
||||||
|
for f in files:
|
||||||
|
adb(["push", os.path.join(root, f), os.path.join("/system/bin/accdata", root, f)])
|
||||||
|
# Copy over compiler
|
||||||
|
adb(["sync"])
|
||||||
|
gArmInitialized = True
|
||||||
|
|
||||||
|
def compileArm(args):
|
||||||
|
setupArm()
|
||||||
|
proc = subprocess.Popen(["adb", "shell", "/system/bin/acc"] + args, stdout=subprocess.PIPE)
|
||||||
|
result = proc.communicate()
|
||||||
|
return result[0].replace("\r","")
|
||||||
|
|
||||||
|
def compare(a, b):
|
||||||
|
if a != b:
|
||||||
|
firstDiff = firstDifference(a, b)
|
||||||
|
print "Strings differ at character %d. Common: %s. Difference '%s' != '%s'" % (
|
||||||
|
firstDiff, a[0:firstDiff], safeAccess(a, firstDiff), safeAccess(b, firstDiff))
|
||||||
|
|
||||||
|
def safeAccess(s, i):
|
||||||
|
if 0 <= i < len(s):
|
||||||
|
return s[i]
|
||||||
|
else:
|
||||||
|
return '?'
|
||||||
|
|
||||||
|
def firstDifference(a, b):
|
||||||
|
commonLen = min(len(a), len(b))
|
||||||
|
for i in xrange(0, commonLen):
|
||||||
|
if a[i] != b[i]:
|
||||||
|
return i
|
||||||
|
return commonLen
|
||||||
|
|
||||||
|
# a1 and a2 are the expected stdout and stderr.
|
||||||
|
# b1 and b2 are the actual stdout and stderr.
|
||||||
|
# Compare the two, sets. Allow any individual line
|
||||||
|
# to appear in either stdout or stderr. This is because
|
||||||
|
# the way we obtain output on the ARM combines both
|
||||||
|
# streams into one sequence.
|
||||||
|
|
||||||
|
def compareOuput(a1,a2,b1,b2):
|
||||||
|
while True:
|
||||||
|
totalLen = len(a1) + len(a2) + len(b1) + len(b2)
|
||||||
|
a1, b1 = matchCommon(a1, b1)
|
||||||
|
a1, b2 = matchCommon(a1, b2)
|
||||||
|
a2, b1 = matchCommon(a2, b1)
|
||||||
|
a2, b2 = matchCommon(a2, b2)
|
||||||
|
newTotalLen = len(a1) + len(a2) + len(b1) + len(b2)
|
||||||
|
if newTotalLen == 0:
|
||||||
|
return True
|
||||||
|
if newTotalLen == totalLen:
|
||||||
|
print "Failed at %d %d %d %d" % (len(a1), len(a2), len(b1), len(b2))
|
||||||
|
print "a1", a1
|
||||||
|
print "a2", a2
|
||||||
|
print "b1", b1
|
||||||
|
print "b2", b2
|
||||||
|
return False
|
||||||
|
|
||||||
|
def matchCommon(a, b):
|
||||||
|
"""Remove common items from the beginning of a and b,
|
||||||
|
return just the tails that are different."""
|
||||||
|
while len(a) > 0 and len(b) > 0 and a[0] == b[0]:
|
||||||
|
a = a[1:]
|
||||||
|
b = b[1:]
|
||||||
|
return a, b
|
||||||
|
|
||||||
|
def rewritePaths(args):
|
||||||
|
return [rewritePath(x) for x in args]
|
||||||
|
|
||||||
|
def rewritePath(p):
|
||||||
|
"""Take a path that's correct on the x86 and convert to a path
|
||||||
|
that's correct on ARM."""
|
||||||
|
if p.startswith("data/"):
|
||||||
|
p = "/system/bin/accdata/" + p
|
||||||
|
return p
|
||||||
|
|
||||||
|
class TestACC(unittest.TestCase):
|
||||||
|
|
||||||
|
def checkResult(self, out, err, stdErrResult, stdOutResult=""):
|
||||||
|
a1 = out.splitlines()
|
||||||
|
a2 = err.splitlines()
|
||||||
|
b2 = stdErrResult.splitlines()
|
||||||
|
b1 = stdOutResult.splitlines()
|
||||||
|
self.assertEqual(True, compareOuput(a1,a2,b1,b2))
|
||||||
|
|
||||||
|
def compileCheck(self, args, stdErrResult, stdOutResult="",
|
||||||
|
targets=['arm', 'x86']):
|
||||||
|
global gUseArm
|
||||||
|
global gUseX86
|
||||||
|
targetSet = frozenset(targets)
|
||||||
|
if gUseX86 and 'x86' in targetSet:
|
||||||
|
out, err = compile(args)
|
||||||
|
self.checkResult(out, err, stdErrResult, stdOutResult)
|
||||||
|
if gUseArm and 'arm' in targetSet:
|
||||||
|
out = compileArm(rewritePaths(args))
|
||||||
|
self.checkResult(out, "", stdErrResult, stdOutResult)
|
||||||
|
|
||||||
|
def compileCheckArm(self, args, result):
|
||||||
|
self.assertEqual(compileArm(args), result)
|
||||||
|
|
||||||
|
def testCompileReturnVal(self):
|
||||||
|
self.compileCheck(["data/returnval-ansi.c"], "")
|
||||||
|
|
||||||
|
def testCompileOTCCANSII(self):
|
||||||
|
self.compileCheck(["data/otcc-ansi.c"], "", "", ['x86'])
|
||||||
|
|
||||||
|
def testRunReturnVal(self):
|
||||||
|
self.compileCheck(["-R", "data/returnval-ansi.c"],
|
||||||
|
"Executing compiled code:\nresult: 42\n")
|
||||||
|
|
||||||
|
def testStringLiteralConcatenation(self):
|
||||||
|
self.compileCheck(["-R", "data/testStringConcat.c"],
|
||||||
|
"Executing compiled code:\nresult: 13\n", "Hello, world\n")
|
||||||
|
|
||||||
|
def testRunOTCCANSI(self):
|
||||||
|
global gRunOTCCOutput
|
||||||
|
if gRunOTCCOutput:
|
||||||
|
self.compileCheck(["-R", "data/otcc-ansi.c", "data/returnval.c"],
|
||||||
|
"Executing compiled code:\notcc-ansi.c: About to execute compiled code:\natcc-ansi.c: result: 42\nresult: 42\n", "",
|
||||||
|
['x86'])
|
||||||
|
|
||||||
|
def testRunOTCCANSI2(self):
|
||||||
|
global gRunOTCCOutput
|
||||||
|
if gRunOTCCOutput:
|
||||||
|
self.compileCheck(["-R", "data/otcc-ansi.c", "data/otcc.c", "data/returnval.c"],
|
||||||
|
"Executing compiled code:\notcc-ansi.c: About to execute compiled code:\notcc.c: about to execute compiled code.\natcc-ansi.c: result: 42\nresult: 42\n", "",['x86'])
|
||||||
|
|
||||||
|
def testRunConstants(self):
|
||||||
|
self.compileCheck(["-R", "data/constants.c"],
|
||||||
|
"Executing compiled code:\nresult: 12\n",
|
||||||
|
"0 = 0\n010 = 8\n0x10 = 16\n'\\a' = 7\n'\\b' = 8\n'\\f' = 12\n'\\n' = 10\n'\\r' = 13\n'\\t' = 9\n'\\v' = 11\n'\\\\' = 92\n'\\'' = 39\n" +
|
||||||
|
"'\\\"' = 34\n'\\?' = 63\n'\\0' = 0\n'\\1' = 1\n'\\12' = 10\n'\\123' = 83\n'\\x0' = 0\n'\\x1' = 1\n'\\x12' = 18\n'\\x123' = 291\n'\\x1f' = 31\n'\\x1F' = 31\n")
|
||||||
|
|
||||||
|
def testRunFloat(self):
|
||||||
|
self.compileCheck(["-R", "data/float.c"],
|
||||||
|
"Executing compiled code:\nresult: 0\n",
|
||||||
|
"""Constants: 0 0 0 0.01 0.01 0.1 10 10 0.1
|
||||||
|
int: 1 float: 2.2 double: 3.3
|
||||||
|
ftoi(1.4f)=1
|
||||||
|
dtoi(2.4)=2
|
||||||
|
itof(3)=3
|
||||||
|
itod(4)=4
|
||||||
|
globals: 1 2 3 4
|
||||||
|
args: 1 2 3 4
|
||||||
|
locals: 1 2 3 4
|
||||||
|
cast rval: 2 4
|
||||||
|
cast lval: 1.1 2 3.3 4
|
||||||
|
""")
|
||||||
|
|
||||||
|
def testRunFlops(self):
|
||||||
|
self.compileCheck(["-R", "data/flops.c"],
|
||||||
|
"""Executing compiled code:
|
||||||
|
result: 0""",
|
||||||
|
"""-1.1 = -1.1
|
||||||
|
!1.2 = 0
|
||||||
|
!0 = 1
|
||||||
|
double op double:
|
||||||
|
1 + 2 = 3
|
||||||
|
1 - 2 = -1
|
||||||
|
1 * 2 = 2
|
||||||
|
1 / 2 = 0.5
|
||||||
|
float op float:
|
||||||
|
1 + 2 = 3
|
||||||
|
1 - 2 = -1
|
||||||
|
1 * 2 = 2
|
||||||
|
1 / 2 = 0.5
|
||||||
|
double op float:
|
||||||
|
1 + 2 = 3
|
||||||
|
1 - 2 = -1
|
||||||
|
1 * 2 = 2
|
||||||
|
1 / 2 = 0.5
|
||||||
|
double op int:
|
||||||
|
1 + 2 = 3
|
||||||
|
1 - 2 = -1
|
||||||
|
1 * 2 = 2
|
||||||
|
1 / 2 = 0.5
|
||||||
|
int op double:
|
||||||
|
1 + 2 = 3
|
||||||
|
1 - 2 = -1
|
||||||
|
1 * 2 = 2
|
||||||
|
1 / 2 = 0.5
|
||||||
|
double op double:
|
||||||
|
1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1
|
||||||
|
1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0
|
||||||
|
2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1
|
||||||
|
double op float:
|
||||||
|
1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1
|
||||||
|
1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0
|
||||||
|
2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1
|
||||||
|
float op float:
|
||||||
|
1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1
|
||||||
|
1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0
|
||||||
|
2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1
|
||||||
|
int op double:
|
||||||
|
1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1
|
||||||
|
1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0
|
||||||
|
2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1
|
||||||
|
double op int:
|
||||||
|
1 op 2: < 1 <= 1 == 0 >= 0 > 0 != 1
|
||||||
|
1 op 1: < 0 <= 1 == 1 >= 1 > 0 != 0
|
||||||
|
2 op 1: < 0 <= 0 == 0 >= 1 > 1 != 1
|
||||||
|
branching: 1 0 1
|
||||||
|
testpassi: 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
testpassf: 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
testpassd: 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
testpassi: 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
testpassf: 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
testpassd: 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
testpassi: 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
testpassf: 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
testpassd: 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
testpassidf: 1 2 3
|
||||||
|
""")
|
||||||
|
def testCasts(self):
|
||||||
|
self.compileCheck(["-R", "data/casts.c"],
|
||||||
|
"""Executing compiled code:
|
||||||
|
result: 0""", """Reading from a pointer: 3 3
|
||||||
|
Writing to a pointer: 4
|
||||||
|
Testing casts: 3 3 4.5 4
|
||||||
|
Testing reading (int*): 4
|
||||||
|
Testing writing (int*): 8 9
|
||||||
|
Testing reading (char*): 0x78 0x56 0x34 0x12
|
||||||
|
Testing writing (char*): 0x87654321
|
||||||
|
f(10)
|
||||||
|
Function pointer result: 70
|
||||||
|
Testing read/write (float*): 8.8 9.9
|
||||||
|
Testing read/write (double*): 8.8 9.9
|
||||||
|
""")
|
||||||
|
|
||||||
|
def testChar(self):
|
||||||
|
self.compileCheck(["-R", "data/char.c"], """Executing compiled code:
|
||||||
|
result: 0""", """a = 99, b = 41
|
||||||
|
ga = 100, gb = 44""")
|
||||||
|
|
||||||
|
def testPointerArithmetic(self):
|
||||||
|
self.compileCheck(["-R", "data/pointers.c"], """Executing compiled code:
|
||||||
|
result: 0""", """Pointer difference: 1 4
|
||||||
|
Pointer addition: 2
|
||||||
|
Pointer comparison to zero: 0 0 1
|
||||||
|
Pointer comparison: 1 0 0 0 1
|
||||||
|
""")
|
||||||
|
def testRollo3(self):
|
||||||
|
self.compileCheck(["-R", "data/rollo3.c"], """Executing compiled code:
|
||||||
|
result: 10""", """""")
|
||||||
|
|
||||||
|
def testFloatDouble(self):
|
||||||
|
self.compileCheck(["-R", "data/floatdouble.c"], """Executing compiled code:
|
||||||
|
result: 0""", """0.002 0.1 10""")
|
||||||
|
|
||||||
|
def testIncDec(self):
|
||||||
|
self.compileCheck(["-R", "data/inc.c"], """Executing compiled code:
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
1
|
||||||
|
0
|
||||||
|
result: 0
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def testIops(self):
|
||||||
|
self.compileCheck(["-R", "data/iops.c"], """Executing compiled code:
|
||||||
|
result: 0""", """Literals: 1 -1
|
||||||
|
++
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
||||||
|
--
|
||||||
|
10
|
||||||
|
9
|
||||||
|
8
|
||||||
|
7
|
||||||
|
6
|
||||||
|
5
|
||||||
|
4
|
||||||
|
3
|
||||||
|
2
|
||||||
|
1
|
||||||
|
0
|
||||||
|
""")
|
||||||
|
|
||||||
|
def testFilm(self):
|
||||||
|
self.compileCheck(["-R", "data/film.c"], """Executing compiled code:
|
||||||
|
result: 0""", """testing...
|
||||||
|
Total bad: 0
|
||||||
|
""")
|
||||||
|
|
||||||
|
def testpointers2(self):
|
||||||
|
self.compileCheck(["-R", "data/pointers2.c"], """Executing compiled code:
|
||||||
|
result: 0""", """a = 0, *pa = 0
|
||||||
|
a = 2, *pa = 2
|
||||||
|
a = 0, *pa = 0 **ppa = 0
|
||||||
|
a = 2, *pa = 2 **ppa = 2
|
||||||
|
a = 0, *pa = 0 **ppa = 0
|
||||||
|
a = 2, *pa = 2 **ppa = 2
|
||||||
|
""")
|
||||||
|
|
||||||
|
def testassignmentop(self):
|
||||||
|
self.compileCheck(["-R", "data/assignmentop.c"], """Executing compiled code:
|
||||||
|
result: 0""", """2 *= 5 10
|
||||||
|
20 /= 5 4
|
||||||
|
17 %= 5 2
|
||||||
|
17 += 5 22
|
||||||
|
17 -= 5 12
|
||||||
|
17<<= 1 34
|
||||||
|
17>>= 1 8
|
||||||
|
17&= 1 1
|
||||||
|
17^= 1 16
|
||||||
|
16|= 1 17
|
||||||
|
*f() = *f() + 10;
|
||||||
|
f()
|
||||||
|
f()
|
||||||
|
a = 10
|
||||||
|
*f() += 10;
|
||||||
|
f()
|
||||||
|
a = 10
|
||||||
|
""")
|
||||||
|
|
||||||
|
def testcomma(self):
|
||||||
|
self.compileCheck(["-R", "data/comma.c"], """Executing compiled code:
|
||||||
|
result: 0""", """statement: 10
|
||||||
|
if: a = 0
|
||||||
|
while: b = 11
|
||||||
|
for: b = 22
|
||||||
|
return: 30
|
||||||
|
arg: 12
|
||||||
|
""")
|
||||||
|
|
||||||
|
def testBrackets(self):
|
||||||
|
self.compileCheck(["-R", "data/brackets.c"], """Executing compiled code:
|
||||||
|
Errors: 0
|
||||||
|
2D Errors: 0
|
||||||
|
result: 0
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def testShort(self):
|
||||||
|
self.compileCheck(["-R", "data/short.c"], """Executing compiled code:
|
||||||
|
result: -2
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def testAssignment(self):
|
||||||
|
self.compileCheck(["-R", "data/assignment.c"], """Executing compiled code:
|
||||||
|
result: 7
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def testArray(self):
|
||||||
|
self.compileCheck(["-R", "data/array.c"], """Executing compiled code:
|
||||||
|
localInt: 3
|
||||||
|
localDouble: 3 3
|
||||||
|
globalChar: 3
|
||||||
|
globalDouble: 3
|
||||||
|
testArgs: 0 2 4
|
||||||
|
testDecay: Hi!
|
||||||
|
test2D:
|
||||||
|
abcdefghijdefghijklm
|
||||||
|
defghijklmghijklmnop
|
||||||
|
ghijklmnopjklmnopabc
|
||||||
|
jklmnopabcmnopabcdef
|
||||||
|
mnopabcdefpabcdefghi
|
||||||
|
pabcdefghicdefghijkl
|
||||||
|
cdefghijklfghijklmno
|
||||||
|
fghijklmnoijklmnopab
|
||||||
|
ijklmnopablmnopabcde
|
||||||
|
lmnopabcdefghijklmno
|
||||||
|
result: 0
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def testDefines(self):
|
||||||
|
self.compileCheck(["-R", "data/defines.c"], """Executing compiled code:
|
||||||
|
result: 3
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def testFuncArgs(self):
|
||||||
|
self.compileCheck(["-R", "data/funcargs.c"], """Executing compiled code:
|
||||||
|
result: 4
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def testB2071670(self):
|
||||||
|
self.compileCheck(["-R", "data/b2071670.c"], """Executing compiled code:
|
||||||
|
result: 1092616192
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def testStructs(self):
|
||||||
|
self.compileCheck(["-R", "data/structs.c"], """Executing compiled code:
|
||||||
|
testCopying: 37 == 37
|
||||||
|
testUnion: 1 == 0x3f800000
|
||||||
|
testArgs: (6, 8, 10, 12)
|
||||||
|
result: 6
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def testAddressOf(self):
|
||||||
|
self.compileCheck(["-R", "data/addressOf.c"], """Executing compiled code:
|
||||||
|
testStruct: 10 10 10
|
||||||
|
testArray: 1 1 1
|
||||||
|
result: 0
|
||||||
|
""","""""")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
checkEnvironment()
|
||||||
|
parseArgv()
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
@ -17,11 +17,10 @@ LOCAL_PATH := $(my-dir)
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
commonSources := \
|
commonSources := \
|
||||||
abort_socket.c \
|
|
||||||
array.c \
|
array.c \
|
||||||
hashmap.c \
|
hashmap.c \
|
||||||
atomic.c \
|
atomic.c \
|
||||||
native_handle.c \
|
native_handle.c \
|
||||||
buffer.c \
|
buffer.c \
|
||||||
socket_inaddr_any_server.c \
|
socket_inaddr_any_server.c \
|
||||||
socket_local_client.c \
|
socket_local_client.c \
|
||||||
|
|
@ -37,40 +36,47 @@ commonSources := \
|
||||||
record_stream.c \
|
record_stream.c \
|
||||||
process_name.c \
|
process_name.c \
|
||||||
properties.c \
|
properties.c \
|
||||||
threads.c
|
threads.c \
|
||||||
|
sched_policy.c
|
||||||
|
|
||||||
|
commonHostSources := \
|
||||||
|
ashmem-host.c
|
||||||
|
|
||||||
# some files must not be compiled when building against Mingw
|
# some files must not be compiled when building against Mingw
|
||||||
# they correspond to features not used by our host development tools
|
# they correspond to features not used by our host development tools
|
||||||
# which are also hard or even impossible to port to native Win32
|
# which are also hard or even impossible to port to native Win32
|
||||||
WITH_MINGW :=
|
WINDOWS_HOST_ONLY :=
|
||||||
ifeq ($(HOST_OS),windows)
|
ifeq ($(HOST_OS),windows)
|
||||||
ifeq ($(strip $(USE_CYGWIN)),)
|
ifeq ($(strip $(USE_CYGWIN)),)
|
||||||
WITH_MINGW := 1
|
WINDOWS_HOST_ONLY := 1
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
# USE_MINGW is defined when we build against Mingw on Linux
|
# USE_MINGW is defined when we build against Mingw on Linux
|
||||||
ifneq ($(strip $(USE_MINGW)),)
|
ifneq ($(strip $(USE_MINGW)),)
|
||||||
WITH_MINGW := 1
|
WINDOWS_HOST_ONLY := 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(WITH_MINGW),1)
|
ifeq ($(WINDOWS_HOST_ONLY),1)
|
||||||
commonSources += \
|
commonSources += \
|
||||||
uio.c
|
uio.c
|
||||||
else
|
else
|
||||||
commonSources += \
|
commonSources += \
|
||||||
|
abort_socket.c \
|
||||||
mspace.c \
|
mspace.c \
|
||||||
selector.c \
|
selector.c \
|
||||||
tztime.c \
|
tztime.c \
|
||||||
tzstrftime.c \
|
|
||||||
adb_networking.c \
|
adb_networking.c \
|
||||||
zygote.c
|
zygote.c
|
||||||
|
|
||||||
|
commonHostSources += \
|
||||||
|
tzstrftime.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
# Static library for host
|
# Static library for host
|
||||||
# ========================================================
|
# ========================================================
|
||||||
LOCAL_MODULE := libcutils
|
LOCAL_MODULE := libcutils
|
||||||
LOCAL_SRC_FILES := $(commonSources) ashmem-host.c
|
LOCAL_SRC_FILES := $(commonSources) $(commonHostSources)
|
||||||
LOCAL_LDLIBS := -lpthread
|
LOCAL_LDLIBS := -lpthread
|
||||||
LOCAL_STATIC_LIBRARIES := liblog
|
LOCAL_STATIC_LIBRARIES := liblog
|
||||||
include $(BUILD_HOST_STATIC_LIBRARY)
|
include $(BUILD_HOST_STATIC_LIBRARY)
|
||||||
|
|
@ -82,7 +88,7 @@ ifeq ($(TARGET_SIMULATOR),true)
|
||||||
# ========================================================
|
# ========================================================
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_MODULE := libcutils
|
LOCAL_MODULE := libcutils
|
||||||
LOCAL_SRC_FILES := $(commonSources) memory.c dlmalloc_stubs.c ashmem-host.c
|
LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) memory.c dlmalloc_stubs.c
|
||||||
LOCAL_LDLIBS := -lpthread
|
LOCAL_LDLIBS := -lpthread
|
||||||
LOCAL_SHARED_LIBRARIES := liblog
|
LOCAL_SHARED_LIBRARIES := liblog
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
|
||||||
|
|
@ -54,23 +54,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
android_atomic_write:
|
android_atomic_write:
|
||||||
stmdb sp!, {r4, lr}
|
str r0, [r1]
|
||||||
mov r2, r1
|
bx lr;
|
||||||
mov r1, r0
|
|
||||||
1: @ android_atomic_write
|
|
||||||
ldr r0, [r2]
|
|
||||||
mov r3, #kernel_atomic_base
|
|
||||||
#ifdef __ARM_HAVE_PC_INTERWORK
|
|
||||||
add lr, pc, #4
|
|
||||||
add pc, r3, #(kernel_cmpxchg - kernel_atomic_base)
|
|
||||||
#else
|
|
||||||
add r3, r3, #(kernel_cmpxchg - kernel_atomic_base)
|
|
||||||
mov lr, pc
|
|
||||||
bx r3
|
|
||||||
#endif
|
|
||||||
bcc 1b
|
|
||||||
ldmia sp!, {r4, lr}
|
|
||||||
bx lr
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
|
|
@ -80,6 +65,8 @@ android_atomic_write:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
android_atomic_inc:
|
android_atomic_inc:
|
||||||
|
.fnstart
|
||||||
|
.save {r4, lr}
|
||||||
stmdb sp!, {r4, lr}
|
stmdb sp!, {r4, lr}
|
||||||
mov r2, r0
|
mov r2, r0
|
||||||
1: @ android_atomic_inc
|
1: @ android_atomic_inc
|
||||||
|
|
@ -99,6 +86,7 @@ android_atomic_inc:
|
||||||
sub r0, r1, #1
|
sub r0, r1, #1
|
||||||
ldmia sp!, {r4, lr}
|
ldmia sp!, {r4, lr}
|
||||||
bx lr
|
bx lr
|
||||||
|
.fnend
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
|
|
@ -108,6 +96,8 @@ android_atomic_inc:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
android_atomic_dec:
|
android_atomic_dec:
|
||||||
|
.fnstart
|
||||||
|
.save {r4, lr}
|
||||||
stmdb sp!, {r4, lr}
|
stmdb sp!, {r4, lr}
|
||||||
mov r2, r0
|
mov r2, r0
|
||||||
1: @ android_atomic_dec
|
1: @ android_atomic_dec
|
||||||
|
|
@ -127,6 +117,7 @@ android_atomic_dec:
|
||||||
add r0, r1, #1
|
add r0, r1, #1
|
||||||
ldmia sp!, {r4, lr}
|
ldmia sp!, {r4, lr}
|
||||||
bx lr
|
bx lr
|
||||||
|
.fnend
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
|
|
@ -136,6 +127,8 @@ android_atomic_dec:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
android_atomic_add:
|
android_atomic_add:
|
||||||
|
.fnstart
|
||||||
|
.save {r4, lr}
|
||||||
stmdb sp!, {r4, lr}
|
stmdb sp!, {r4, lr}
|
||||||
mov r2, r1
|
mov r2, r1
|
||||||
mov r4, r0
|
mov r4, r0
|
||||||
|
|
@ -156,6 +149,7 @@ android_atomic_add:
|
||||||
sub r0, r1, r4
|
sub r0, r1, r4
|
||||||
ldmia sp!, {r4, lr}
|
ldmia sp!, {r4, lr}
|
||||||
bx lr
|
bx lr
|
||||||
|
.fnend
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -166,6 +160,8 @@ android_atomic_add:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
android_atomic_and:
|
android_atomic_and:
|
||||||
|
.fnstart
|
||||||
|
.save {r4, r5, lr}
|
||||||
stmdb sp!, {r4, r5, lr}
|
stmdb sp!, {r4, r5, lr}
|
||||||
mov r2, r1 /* r2 = address */
|
mov r2, r1 /* r2 = address */
|
||||||
mov r4, r0 /* r4 = the value */
|
mov r4, r0 /* r4 = the value */
|
||||||
|
|
@ -188,6 +184,7 @@ android_atomic_and:
|
||||||
mov r0, r5
|
mov r0, r5
|
||||||
ldmia sp!, {r4, r5, lr}
|
ldmia sp!, {r4, r5, lr}
|
||||||
bx lr
|
bx lr
|
||||||
|
.fnend
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
|
|
@ -197,6 +194,8 @@ android_atomic_and:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
android_atomic_or:
|
android_atomic_or:
|
||||||
|
.fnstart
|
||||||
|
.save {r4, r5, lr}
|
||||||
stmdb sp!, {r4, r5, lr}
|
stmdb sp!, {r4, r5, lr}
|
||||||
mov r2, r1 /* r2 = address */
|
mov r2, r1 /* r2 = address */
|
||||||
mov r4, r0 /* r4 = the value */
|
mov r4, r0 /* r4 = the value */
|
||||||
|
|
@ -219,6 +218,7 @@ android_atomic_or:
|
||||||
mov r0, r5
|
mov r0, r5
|
||||||
ldmia sp!, {r4, r5, lr}
|
ldmia sp!, {r4, r5, lr}
|
||||||
bx lr
|
bx lr
|
||||||
|
.fnend
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
|
|
@ -249,6 +249,8 @@ android_atomic_swap:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
android_atomic_cmpxchg:
|
android_atomic_cmpxchg:
|
||||||
|
.fnstart
|
||||||
|
.save {r4, lr}
|
||||||
stmdb sp!, {r4, lr}
|
stmdb sp!, {r4, lr}
|
||||||
mov r4, r0 /* r4 = save oldvalue */
|
mov r4, r0 /* r4 = save oldvalue */
|
||||||
1: @ android_atomic_cmpxchg
|
1: @ android_atomic_cmpxchg
|
||||||
|
|
@ -270,6 +272,7 @@ android_atomic_cmpxchg:
|
||||||
2: @ android_atomic_cmpxchg
|
2: @ android_atomic_cmpxchg
|
||||||
ldmia sp!, {r4, lr}
|
ldmia sp!, {r4, lr}
|
||||||
bx lr
|
bx lr
|
||||||
|
.fnend
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
android_atomic_write:
|
android_atomic_write:
|
||||||
1: ldrex r12, [r1]
|
str r0, [r1]
|
||||||
strex r12, r0, [r1]
|
bx lr;
|
||||||
cmp r12, #0
|
|
||||||
bne 1b
|
|
||||||
bx lr
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#if defined(HAVE_PRCTL)
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PROCESS_NAME_DEVICE "/sys/qemu_trace/process_name"
|
#define PROCESS_NAME_DEVICE "/sys/qemu_trace/process_name"
|
||||||
|
|
||||||
static const char* process_name = "unknown";
|
static const char* process_name = "unknown";
|
||||||
|
|
@ -35,10 +39,19 @@ void set_process_name(const char* new_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We never free the old name. Someone else could be using it.
|
// We never free the old name. Someone else could be using it.
|
||||||
char* copy = (char*) malloc(strlen(new_name) + 1);
|
int len = strlen(new_name);
|
||||||
|
char* copy = (char*) malloc(len + 1);
|
||||||
strcpy(copy, new_name);
|
strcpy(copy, new_name);
|
||||||
process_name = (const char*) copy;
|
process_name = (const char*) copy;
|
||||||
|
|
||||||
|
#if defined(HAVE_PRCTL)
|
||||||
|
if (len < 16) {
|
||||||
|
prctl(PR_SET_NAME, (unsigned long) new_name, 0, 0, 0);
|
||||||
|
} else {
|
||||||
|
prctl(PR_SET_NAME, (unsigned long) new_name + len - 15, 0, 0, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// If we know we are not running in the emulator, then return.
|
// If we know we are not running in the emulator, then return.
|
||||||
if (running_in_emulator == 0) {
|
if (running_in_emulator == 0) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
221
libcutils/sched_policy.c
Normal file
221
libcutils/sched_policy.c
Normal file
|
|
@ -0,0 +1,221 @@
|
||||||
|
|
||||||
|
/* libs/cutils/sched_policy.c
|
||||||
|
**
|
||||||
|
** Copyright 2007, The Android Open Source Project
|
||||||
|
**
|
||||||
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
** you may not use this file except in compliance with the License.
|
||||||
|
** You may obtain a copy of the License at
|
||||||
|
**
|
||||||
|
** http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
**
|
||||||
|
** Unless required by applicable law or agreed to in writing, software
|
||||||
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
** See the License for the specific language governing permissions and
|
||||||
|
** limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#define LOG_TAG "SchedPolicy"
|
||||||
|
#include "cutils/log.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_SCHED_H
|
||||||
|
|
||||||
|
#include <sched.h>
|
||||||
|
|
||||||
|
#include <cutils/sched_policy.h>
|
||||||
|
|
||||||
|
#ifndef SCHED_NORMAL
|
||||||
|
#define SCHED_NORMAL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SCHED_BATCH
|
||||||
|
#define SCHED_BATCH 3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define POLICY_DEBUG 0
|
||||||
|
|
||||||
|
static int __sys_supports_schedgroups = -1;
|
||||||
|
|
||||||
|
static int add_tid_to_cgroup(int tid, const char *grp_name)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char path[255];
|
||||||
|
char text[64];
|
||||||
|
|
||||||
|
sprintf(path, "/dev/cpuctl/%s/tasks", grp_name);
|
||||||
|
|
||||||
|
if ((fd = open(path, O_WRONLY)) < 0) {
|
||||||
|
LOGE("add_tid_to_cgroup failed to open '%s' (%s)\n", path, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(text, "%d", tid);
|
||||||
|
if (write(fd, text, strlen(text)) < 0) {
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void initialize()
|
||||||
|
{
|
||||||
|
if (__sys_supports_schedgroups < 0) {
|
||||||
|
if (!access("/dev/cpuctl/tasks", F_OK)) {
|
||||||
|
__sys_supports_schedgroups = 1;
|
||||||
|
} else {
|
||||||
|
__sys_supports_schedgroups = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to get the scheduler group.
|
||||||
|
*
|
||||||
|
* The data from /proc/<pid>/cgroup looks like:
|
||||||
|
* 2:cpu:/bg_non_interactive
|
||||||
|
*
|
||||||
|
* We return the part after the "/", which will be an empty string for
|
||||||
|
* the default cgroup. If the string is longer than "bufLen", the string
|
||||||
|
* will be truncated.
|
||||||
|
*/
|
||||||
|
static int getSchedulerGroup(int tid, char* buf, size_t bufLen)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_ANDROID_OS
|
||||||
|
char pathBuf[32];
|
||||||
|
char readBuf[256];
|
||||||
|
ssize_t count;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
snprintf(pathBuf, sizeof(pathBuf), "/proc/%d/cgroup", tid);
|
||||||
|
if ((fd = open(pathBuf, O_RDONLY)) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
count = read(fd, readBuf, sizeof(readBuf));
|
||||||
|
if (count <= 0) {
|
||||||
|
close(fd);
|
||||||
|
errno = ENODATA;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
readBuf[--count] = '\0'; /* remove the '\n', now count==strlen */
|
||||||
|
|
||||||
|
char* cp = strchr(readBuf, '/');
|
||||||
|
if (cp == NULL) {
|
||||||
|
readBuf[sizeof(readBuf)-1] = '\0';
|
||||||
|
errno = ENODATA;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(buf, cp+1, count); /* count-1 for cp+1, count+1 for NUL */
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
errno = ENOSYS;
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_sched_policy(int tid, SchedPolicy *policy)
|
||||||
|
{
|
||||||
|
initialize();
|
||||||
|
|
||||||
|
if (__sys_supports_schedgroups) {
|
||||||
|
char grpBuf[32];
|
||||||
|
if (getSchedulerGroup(tid, grpBuf, sizeof(grpBuf)) < 0)
|
||||||
|
return -1;
|
||||||
|
if (grpBuf[0] == '\0') {
|
||||||
|
*policy = SP_FOREGROUND;
|
||||||
|
} else if (!strcmp(grpBuf, "bg_non_interactive")) {
|
||||||
|
*policy = SP_BACKGROUND;
|
||||||
|
} else {
|
||||||
|
errno = ERANGE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int rc = sched_getscheduler(tid);
|
||||||
|
if (rc < 0)
|
||||||
|
return -1;
|
||||||
|
else if (rc == SCHED_NORMAL)
|
||||||
|
*policy = SP_FOREGROUND;
|
||||||
|
else if (rc == SCHED_BATCH)
|
||||||
|
*policy = SP_BACKGROUND;
|
||||||
|
else {
|
||||||
|
errno = ERANGE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int set_sched_policy(int tid, SchedPolicy policy)
|
||||||
|
{
|
||||||
|
initialize();
|
||||||
|
|
||||||
|
#if POLICY_DEBUG
|
||||||
|
char statfile[64];
|
||||||
|
char statline[1024];
|
||||||
|
char thread_name[255];
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
sprintf(statfile, "/proc/%d/stat", tid);
|
||||||
|
memset(thread_name, 0, sizeof(thread_name));
|
||||||
|
|
||||||
|
fd = open(statfile, O_RDONLY);
|
||||||
|
if (fd >= 0) {
|
||||||
|
int rc = read(fd, statline, 1023);
|
||||||
|
close(fd);
|
||||||
|
statline[rc] = 0;
|
||||||
|
char *p = statline;
|
||||||
|
char *q;
|
||||||
|
|
||||||
|
for (p = statline; *p != '('; p++);
|
||||||
|
p++;
|
||||||
|
for (q = p; *q != ')'; q++);
|
||||||
|
|
||||||
|
strncpy(thread_name, p, (q-p));
|
||||||
|
}
|
||||||
|
if (policy == SP_BACKGROUND) {
|
||||||
|
LOGD("vvv tid %d (%s)", tid, thread_name);
|
||||||
|
} else if (policy == SP_FOREGROUND) {
|
||||||
|
LOGD("^^^ tid %d (%s)", tid, thread_name);
|
||||||
|
} else {
|
||||||
|
LOGD("??? tid %d (%s)", tid, thread_name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (__sys_supports_schedgroups) {
|
||||||
|
const char *grp = "";
|
||||||
|
|
||||||
|
if (policy == SP_BACKGROUND) {
|
||||||
|
grp = "bg_non_interactive";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (add_tid_to_cgroup(tid, grp)) {
|
||||||
|
if (errno != ESRCH && errno != ENOENT)
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
struct sched_param param;
|
||||||
|
|
||||||
|
param.sched_priority = 0;
|
||||||
|
sched_setscheduler(tid,
|
||||||
|
(policy == SP_BACKGROUND) ?
|
||||||
|
SCHED_BATCH : SCHED_NORMAL,
|
||||||
|
¶m);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_SCHED_H */
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
** limitations under the License.
|
** limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <limits.h> /* for SIZE_MAX */
|
||||||
|
|
||||||
#include <cutils/jstring.h>
|
#include <cutils/jstring.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -26,19 +28,67 @@
|
||||||
*/
|
*/
|
||||||
extern size_t strnlen16to8(const char16_t* utf16Str, size_t len)
|
extern size_t strnlen16to8(const char16_t* utf16Str, size_t len)
|
||||||
{
|
{
|
||||||
size_t utf8Len = 0;
|
size_t utf8Len = 0;
|
||||||
|
|
||||||
while (len--) {
|
/* A small note on integer overflow. The result can
|
||||||
unsigned int uic = *utf16Str++;
|
* potentially be as big as 3*len, which will overflow
|
||||||
|
* for len > SIZE_MAX/3.
|
||||||
|
*
|
||||||
|
* Moreover, the result of a strnlen16to8 is typically used
|
||||||
|
* to allocate a destination buffer to strncpy16to8 which
|
||||||
|
* requires one more byte to terminate the UTF-8 copy, and
|
||||||
|
* this is generally done by careless users by incrementing
|
||||||
|
* the result without checking for integer overflows, e.g.:
|
||||||
|
*
|
||||||
|
* dst = malloc(strnlen16to8(utf16,len)+1)
|
||||||
|
*
|
||||||
|
* Due to this, the following code will try to detect
|
||||||
|
* overflows, and never return more than (SIZE_MAX-1)
|
||||||
|
* when it detects one. A careless user will try to malloc
|
||||||
|
* SIZE_MAX bytes, which will return NULL which can at least
|
||||||
|
* be detected appropriately.
|
||||||
|
*
|
||||||
|
* As far as I know, this function is only used by strndup16(),
|
||||||
|
* but better be safe than sorry.
|
||||||
|
*/
|
||||||
|
|
||||||
if (uic > 0x07ff)
|
/* Fast path for the usual case where 3*len is < SIZE_MAX-1.
|
||||||
utf8Len += 3;
|
*/
|
||||||
else if (uic > 0x7f || uic == 0)
|
if (len < (SIZE_MAX-1)/3) {
|
||||||
utf8Len += 2;
|
while (len--) {
|
||||||
else
|
unsigned int uic = *utf16Str++;
|
||||||
utf8Len++;
|
|
||||||
}
|
if (uic > 0x07ff)
|
||||||
return utf8Len;
|
utf8Len += 3;
|
||||||
|
else if (uic > 0x7f || uic == 0)
|
||||||
|
utf8Len += 2;
|
||||||
|
else
|
||||||
|
utf8Len++;
|
||||||
|
}
|
||||||
|
return utf8Len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The slower but paranoid version */
|
||||||
|
while (len--) {
|
||||||
|
unsigned int uic = *utf16Str++;
|
||||||
|
size_t utf8Cur = utf8Len;
|
||||||
|
|
||||||
|
if (uic > 0x07ff)
|
||||||
|
utf8Len += 3;
|
||||||
|
else if (uic > 0x7f || uic == 0)
|
||||||
|
utf8Len += 2;
|
||||||
|
else
|
||||||
|
utf8Len++;
|
||||||
|
|
||||||
|
if (utf8Len < utf8Cur) /* overflow detected */
|
||||||
|
return SIZE_MAX-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* don't return SIZE_MAX to avoid common user bug */
|
||||||
|
if (utf8Len == SIZE_MAX)
|
||||||
|
utf8Len = SIZE_MAX-1;
|
||||||
|
|
||||||
|
return utf8Len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -50,7 +100,7 @@ extern size_t strnlen16to8(const char16_t* utf16Str, size_t len)
|
||||||
*
|
*
|
||||||
* Make sure you allocate "utf8Str" with the result of strlen16to8() + 1,
|
* Make sure you allocate "utf8Str" with the result of strlen16to8() + 1,
|
||||||
* not just "len".
|
* not just "len".
|
||||||
*
|
*
|
||||||
* Please note, a terminated \0 is always added, so your result will always
|
* Please note, a terminated \0 is always added, so your result will always
|
||||||
* be "strlen16to8() + 1" bytes long.
|
* be "strlen16to8() + 1" bytes long.
|
||||||
*/
|
*/
|
||||||
|
|
@ -58,6 +108,10 @@ extern char* strncpy16to8(char* utf8Str, const char16_t* utf16Str, size_t len)
|
||||||
{
|
{
|
||||||
char* utf8cur = utf8Str;
|
char* utf8cur = utf8Str;
|
||||||
|
|
||||||
|
/* Note on overflows: We assume the user did check the result of
|
||||||
|
* strnlen16to8() properly or at a minimum checked the result of
|
||||||
|
* its malloc(SIZE_MAX) in case of overflow.
|
||||||
|
*/
|
||||||
while (len--) {
|
while (len--) {
|
||||||
unsigned int uic = *utf16Str++;
|
unsigned int uic = *utf16Str++;
|
||||||
|
|
||||||
|
|
@ -73,8 +127,8 @@ extern char* strncpy16to8(char* utf8Str, const char16_t* utf16Str, size_t len)
|
||||||
|
|
||||||
if (uic == 0) {
|
if (uic == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*utf8cur = '\0';
|
*utf8cur = '\0';
|
||||||
|
|
@ -85,20 +139,30 @@ extern char* strncpy16to8(char* utf8Str, const char16_t* utf16Str, size_t len)
|
||||||
/**
|
/**
|
||||||
* Convert a UTF-16 string to UTF-8.
|
* Convert a UTF-16 string to UTF-8.
|
||||||
*
|
*
|
||||||
* Make sure you allocate "dest" with the result of strblen16to8(),
|
|
||||||
* not just "strlen16()".
|
|
||||||
*/
|
*/
|
||||||
char * strndup16to8 (const char16_t* s, size_t n)
|
char * strndup16to8 (const char16_t* s, size_t n)
|
||||||
{
|
{
|
||||||
char *ret;
|
char* ret;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = malloc(strnlen16to8(s, n) + 1);
|
len = strnlen16to8(s, n);
|
||||||
|
|
||||||
|
/* We are paranoid, and we check for SIZE_MAX-1
|
||||||
|
* too since it is an overflow value for our
|
||||||
|
* strnlen16to8 implementation.
|
||||||
|
*/
|
||||||
|
if (len >= SIZE_MAX-1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ret = malloc(len + 1);
|
||||||
|
if (ret == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
strncpy16to8 (ret, s, n);
|
strncpy16to8 (ret, s, n);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,31 @@ static char elsieid[] = "@(#)localtime.c 8.3";
|
||||||
#define OPEN_MODE O_RDONLY
|
#define OPEN_MODE O_RDONLY
|
||||||
#endif /* !defined O_BINARY */
|
#endif /* !defined O_BINARY */
|
||||||
|
|
||||||
|
/* Complex computations to determine the min/max of time_t depending
|
||||||
|
* on TYPE_BIT / TYPE_SIGNED / TYPE_INTEGRAL.
|
||||||
|
* These macros cannot be used in pre-processor directives, so we
|
||||||
|
* let the C compiler do the work, which makes things a bit funky.
|
||||||
|
*/
|
||||||
|
static const time_t TIME_T_MAX =
|
||||||
|
TYPE_INTEGRAL(time_t) ?
|
||||||
|
( TYPE_SIGNED(time_t) ?
|
||||||
|
~((time_t)1 << (TYPE_BIT(time_t)-1))
|
||||||
|
:
|
||||||
|
~(time_t)0
|
||||||
|
)
|
||||||
|
: /* if time_t is a floating point number */
|
||||||
|
( sizeof(time_t) > sizeof(float) ? (time_t)DBL_MAX : (time_t)FLT_MAX );
|
||||||
|
|
||||||
|
static const time_t TIME_T_MIN =
|
||||||
|
TYPE_INTEGRAL(time_t) ?
|
||||||
|
( TYPE_SIGNED(time_t) ?
|
||||||
|
((time_t)1 << (TYPE_BIT(time_t)-1))
|
||||||
|
:
|
||||||
|
0
|
||||||
|
)
|
||||||
|
:
|
||||||
|
( sizeof(time_t) > sizeof(float) ? (time_t)DBL_MIN : (time_t)FLT_MIN );
|
||||||
|
|
||||||
#ifndef WILDABBR
|
#ifndef WILDABBR
|
||||||
/*
|
/*
|
||||||
** Someone might make incorrect use of a time zone abbreviation:
|
** Someone might make incorrect use of a time zone abbreviation:
|
||||||
|
|
@ -158,7 +183,7 @@ static void gmtload P((struct state * sp));
|
||||||
static struct tm * gmtsub P((const time_t * timep, long offset,
|
static struct tm * gmtsub P((const time_t * timep, long offset,
|
||||||
struct tm * tmp));
|
struct tm * tmp));
|
||||||
static struct tm * localsub P((const time_t * timep, long offset,
|
static struct tm * localsub P((const time_t * timep, long offset,
|
||||||
struct tm * tmp, struct state *sp));
|
struct tm * tmp, const struct state *sp));
|
||||||
static int increment_overflow P((int * number, int delta));
|
static int increment_overflow P((int * number, int delta));
|
||||||
static int leaps_thru_end_of P((int y));
|
static int leaps_thru_end_of P((int y));
|
||||||
static int long_increment_overflow P((long * number, int delta));
|
static int long_increment_overflow P((long * number, int delta));
|
||||||
|
|
@ -1157,7 +1182,7 @@ localsub(timep, offset, tmp, sp)
|
||||||
const time_t * const timep;
|
const time_t * const timep;
|
||||||
const long offset;
|
const long offset;
|
||||||
struct tm * const tmp;
|
struct tm * const tmp;
|
||||||
struct state * sp;
|
const struct state * sp;
|
||||||
{
|
{
|
||||||
register const struct ttinfo * ttisp;
|
register const struct ttinfo * ttisp;
|
||||||
register int i;
|
register int i;
|
||||||
|
|
@ -1553,26 +1578,36 @@ char * buf;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
increment_overflow(number, delta)
|
increment_overflow(number, delta)
|
||||||
int * number;
|
int * number;
|
||||||
int delta;
|
int delta;
|
||||||
{
|
{
|
||||||
int number0;
|
unsigned number0 = (unsigned)*number;
|
||||||
|
unsigned number1 = (unsigned)(number0 + delta);
|
||||||
|
|
||||||
number0 = *number;
|
*number = (int)number1;
|
||||||
*number += delta;
|
|
||||||
return (*number < number0) != (delta < 0);
|
if (delta >= 0) {
|
||||||
|
return ((int)number1 < (int)number0);
|
||||||
|
} else {
|
||||||
|
return ((int)number1 > (int)number0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
long_increment_overflow(number, delta)
|
long_increment_overflow(number, delta)
|
||||||
long * number;
|
long * number;
|
||||||
int delta;
|
int delta;
|
||||||
{
|
{
|
||||||
long number0;
|
unsigned long number0 = (unsigned long)*number;
|
||||||
|
unsigned long number1 = (unsigned long)(number0 + delta);
|
||||||
|
|
||||||
number0 = *number;
|
*number = (long)number1;
|
||||||
*number += delta;
|
|
||||||
return (*number < number0) != (delta < 0);
|
if (delta >= 0) {
|
||||||
|
return ((long)number1 < (long)number0);
|
||||||
|
} else {
|
||||||
|
return ((long)number1 > (long)number0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -1741,14 +1776,14 @@ const struct state * sp;
|
||||||
} else dir = tmcomp(&mytm, &yourtm);
|
} else dir = tmcomp(&mytm, &yourtm);
|
||||||
if (dir != 0) {
|
if (dir != 0) {
|
||||||
if (t == lo) {
|
if (t == lo) {
|
||||||
|
if (t == TIME_T_MAX)
|
||||||
|
return WRONG;
|
||||||
++t;
|
++t;
|
||||||
if (t <= lo)
|
|
||||||
return WRONG;
|
|
||||||
++lo;
|
++lo;
|
||||||
} else if (t == hi) {
|
} else if (t == hi) {
|
||||||
|
if (t == TIME_T_MIN)
|
||||||
|
return WRONG;
|
||||||
--t;
|
--t;
|
||||||
if (t >= hi)
|
|
||||||
return WRONG;
|
|
||||||
--hi;
|
--hi;
|
||||||
}
|
}
|
||||||
if (lo > hi)
|
if (lo > hi)
|
||||||
|
|
|
||||||
|
|
@ -142,11 +142,7 @@ int __android_log_write(int prio, const char *tag, const char *msg)
|
||||||
|
|
||||||
/* XXX: This needs to go! */
|
/* XXX: This needs to go! */
|
||||||
if (!strcmp(tag, "HTC_RIL") ||
|
if (!strcmp(tag, "HTC_RIL") ||
|
||||||
!strcmp(tag, "RILJ") ||
|
!strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
|
||||||
!strcmp(tag, "RILB") ||
|
|
||||||
!strcmp(tag, "RILC") ||
|
|
||||||
!strcmp(tag, "RILD") ||
|
|
||||||
!strcmp(tag, "RIL") ||
|
|
||||||
!strcmp(tag, "AT") ||
|
!strcmp(tag, "AT") ||
|
||||||
!strcmp(tag, "GSM") ||
|
!strcmp(tag, "GSM") ||
|
||||||
!strcmp(tag, "STK") ||
|
!strcmp(tag, "STK") ||
|
||||||
|
|
|
||||||
|
|
@ -13,20 +13,183 @@
|
||||||
** be used to endorse or promote products derived from this software
|
** be used to endorse or promote products derived from this software
|
||||||
** without specific prior written permission.
|
** without specific prior written permission.
|
||||||
**
|
**
|
||||||
** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
|
** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
|
||||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mincrypt/sha.h"
|
#include "mincrypt/sha.h"
|
||||||
|
|
||||||
|
// Some machines lack byteswap.h and endian.h. These have to use the
|
||||||
|
// slower code, even if they're little-endian.
|
||||||
|
|
||||||
|
#if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN)
|
||||||
|
|
||||||
|
#include <byteswap.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
|
// This version is about 28% faster than the generic version below,
|
||||||
|
// but assumes little-endianness.
|
||||||
|
|
||||||
|
static inline uint32_t ror27(uint32_t val) {
|
||||||
|
return (val >> 27) | (val << 5);
|
||||||
|
}
|
||||||
|
static inline uint32_t ror2(uint32_t val) {
|
||||||
|
return (val >> 2) | (val << 30);
|
||||||
|
}
|
||||||
|
static inline uint32_t ror31(uint32_t val) {
|
||||||
|
return (val >> 31) | (val << 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SHA1_Transform(SHA_CTX* ctx) {
|
||||||
|
uint32_t W[80];
|
||||||
|
register uint32_t A, B, C, D, E;
|
||||||
|
int t;
|
||||||
|
|
||||||
|
A = ctx->state[0];
|
||||||
|
B = ctx->state[1];
|
||||||
|
C = ctx->state[2];
|
||||||
|
D = ctx->state[3];
|
||||||
|
E = ctx->state[4];
|
||||||
|
|
||||||
|
#define SHA_F1(A,B,C,D,E,t) \
|
||||||
|
E += ror27(A) + \
|
||||||
|
(W[t] = bswap_32(ctx->buf.w[t])) + \
|
||||||
|
(D^(B&(C^D))) + 0x5A827999; \
|
||||||
|
B = ror2(B);
|
||||||
|
|
||||||
|
for (t = 0; t < 15; t += 5) {
|
||||||
|
SHA_F1(A,B,C,D,E,t + 0);
|
||||||
|
SHA_F1(E,A,B,C,D,t + 1);
|
||||||
|
SHA_F1(D,E,A,B,C,t + 2);
|
||||||
|
SHA_F1(C,D,E,A,B,t + 3);
|
||||||
|
SHA_F1(B,C,D,E,A,t + 4);
|
||||||
|
}
|
||||||
|
SHA_F1(A,B,C,D,E,t + 0); // 16th one, t == 15
|
||||||
|
|
||||||
|
#undef SHA_F1
|
||||||
|
|
||||||
|
#define SHA_F1(A,B,C,D,E,t) \
|
||||||
|
E += ror27(A) + \
|
||||||
|
(W[t] = ror31(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16])) + \
|
||||||
|
(D^(B&(C^D))) + 0x5A827999; \
|
||||||
|
B = ror2(B);
|
||||||
|
|
||||||
|
SHA_F1(E,A,B,C,D,t + 1);
|
||||||
|
SHA_F1(D,E,A,B,C,t + 2);
|
||||||
|
SHA_F1(C,D,E,A,B,t + 3);
|
||||||
|
SHA_F1(B,C,D,E,A,t + 4);
|
||||||
|
|
||||||
|
#undef SHA_F1
|
||||||
|
|
||||||
|
#define SHA_F2(A,B,C,D,E,t) \
|
||||||
|
E += ror27(A) + \
|
||||||
|
(W[t] = ror31(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16])) + \
|
||||||
|
(B^C^D) + 0x6ED9EBA1; \
|
||||||
|
B = ror2(B);
|
||||||
|
|
||||||
|
for (t = 20; t < 40; t += 5) {
|
||||||
|
SHA_F2(A,B,C,D,E,t + 0);
|
||||||
|
SHA_F2(E,A,B,C,D,t + 1);
|
||||||
|
SHA_F2(D,E,A,B,C,t + 2);
|
||||||
|
SHA_F2(C,D,E,A,B,t + 3);
|
||||||
|
SHA_F2(B,C,D,E,A,t + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef SHA_F2
|
||||||
|
|
||||||
|
#define SHA_F3(A,B,C,D,E,t) \
|
||||||
|
E += ror27(A) + \
|
||||||
|
(W[t] = ror31(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16])) + \
|
||||||
|
((B&C)|(D&(B|C))) + 0x8F1BBCDC; \
|
||||||
|
B = ror2(B);
|
||||||
|
|
||||||
|
for (; t < 60; t += 5) {
|
||||||
|
SHA_F3(A,B,C,D,E,t + 0);
|
||||||
|
SHA_F3(E,A,B,C,D,t + 1);
|
||||||
|
SHA_F3(D,E,A,B,C,t + 2);
|
||||||
|
SHA_F3(C,D,E,A,B,t + 3);
|
||||||
|
SHA_F3(B,C,D,E,A,t + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef SHA_F3
|
||||||
|
|
||||||
|
#define SHA_F4(A,B,C,D,E,t) \
|
||||||
|
E += ror27(A) + \
|
||||||
|
(W[t] = ror31(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16])) + \
|
||||||
|
(B^C^D) + 0xCA62C1D6; \
|
||||||
|
B = ror2(B);
|
||||||
|
|
||||||
|
for (; t < 80; t += 5) {
|
||||||
|
SHA_F4(A,B,C,D,E,t + 0);
|
||||||
|
SHA_F4(E,A,B,C,D,t + 1);
|
||||||
|
SHA_F4(D,E,A,B,C,t + 2);
|
||||||
|
SHA_F4(C,D,E,A,B,t + 3);
|
||||||
|
SHA_F4(B,C,D,E,A,t + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef SHA_F4
|
||||||
|
|
||||||
|
ctx->state[0] += A;
|
||||||
|
ctx->state[1] += B;
|
||||||
|
ctx->state[2] += C;
|
||||||
|
ctx->state[3] += D;
|
||||||
|
ctx->state[4] += E;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHA_update(SHA_CTX* ctx, const void* data, int len) {
|
||||||
|
int i = ctx->count % sizeof(ctx->buf);
|
||||||
|
const uint8_t* p = (const uint8_t*)data;
|
||||||
|
|
||||||
|
ctx->count += len;
|
||||||
|
|
||||||
|
while (len > sizeof(ctx->buf) - i) {
|
||||||
|
memcpy(&ctx->buf.b[i], p, sizeof(ctx->buf) - i);
|
||||||
|
len -= sizeof(ctx->buf) - i;
|
||||||
|
p += sizeof(ctx->buf) - i;
|
||||||
|
SHA1_Transform(ctx);
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (len--) {
|
||||||
|
ctx->buf.b[i++] = *p++;
|
||||||
|
if (i == sizeof(ctx->buf)) {
|
||||||
|
SHA1_Transform(ctx);
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const uint8_t* SHA_final(SHA_CTX* ctx) {
|
||||||
|
uint64_t cnt = ctx->count * 8;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
SHA_update(ctx, (uint8_t*)"\x80", 1);
|
||||||
|
while ((ctx->count % sizeof(ctx->buf)) != (sizeof(ctx->buf) - 8)) {
|
||||||
|
SHA_update(ctx, (uint8_t*)"\0", 1);
|
||||||
|
}
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
uint8_t tmp = cnt >> ((7 - i) * 8);
|
||||||
|
SHA_update(ctx, &tmp, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 5; i++) {
|
||||||
|
ctx->buf.w[i] = bswap_32(ctx->state[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx->buf.b;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN)
|
||||||
|
|
||||||
#define rol(bits, value) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
#define rol(bits, value) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||||
|
|
||||||
static void SHA1_transform(SHA_CTX *ctx) {
|
static void SHA1_transform(SHA_CTX *ctx) {
|
||||||
|
|
@ -79,15 +242,6 @@ static void SHA1_transform(SHA_CTX *ctx) {
|
||||||
ctx->state[4] += E;
|
ctx->state[4] += E;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHA_init(SHA_CTX *ctx) {
|
|
||||||
ctx->state[0] = 0x67452301;
|
|
||||||
ctx->state[1] = 0xEFCDAB89;
|
|
||||||
ctx->state[2] = 0x98BADCFE;
|
|
||||||
ctx->state[3] = 0x10325476;
|
|
||||||
ctx->state[4] = 0xC3D2E1F0;
|
|
||||||
ctx->count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SHA_update(SHA_CTX *ctx, const void *data, int len) {
|
void SHA_update(SHA_CTX *ctx, const void *data, int len) {
|
||||||
int i = ctx->count % sizeof(ctx->buf);
|
int i = ctx->count % sizeof(ctx->buf);
|
||||||
const uint8_t* p = (const uint8_t*)data;
|
const uint8_t* p = (const uint8_t*)data;
|
||||||
|
|
@ -127,6 +281,17 @@ const uint8_t *SHA_final(SHA_CTX *ctx) {
|
||||||
return ctx->buf;
|
return ctx->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // endianness
|
||||||
|
|
||||||
|
void SHA_init(SHA_CTX* ctx) {
|
||||||
|
ctx->state[0] = 0x67452301;
|
||||||
|
ctx->state[1] = 0xEFCDAB89;
|
||||||
|
ctx->state[2] = 0x98BADCFE;
|
||||||
|
ctx->state[3] = 0x10325476;
|
||||||
|
ctx->state[4] = 0xC3D2E1F0;
|
||||||
|
ctx->count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Convenience function */
|
/* Convenience function */
|
||||||
const uint8_t* SHA(const void *data, int len, uint8_t *digest) {
|
const uint8_t* SHA(const void *data, int len, uint8_t *digest) {
|
||||||
const uint8_t *p;
|
const uint8_t *p;
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,16 @@ int ifc_add_host_route(const char *name, in_addr_t addr)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ifc_enable(const char *ifname)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
ifc_init();
|
||||||
|
result = ifc_up(ifname);
|
||||||
|
ifc_close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int ifc_disable(const char *ifname)
|
int ifc_disable(const char *ifname)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
|
||||||
|
|
@ -221,17 +221,7 @@ void GGLAssembler::build_blending(
|
||||||
build_blend_factor(dst_factor, fd,
|
build_blend_factor(dst_factor, fd,
|
||||||
component, pixel, fragment, fb, scratches);
|
component, pixel, fragment, fb, scratches);
|
||||||
mul_factor_add(temp, fb, dst_factor, component_t(fragment));
|
mul_factor_add(temp, fb, dst_factor, component_t(fragment));
|
||||||
if (fd==GGL_ONE_MINUS_SRC_ALPHA) {
|
component_sat(temp);
|
||||||
// XXX: in theory this is not correct, we should
|
|
||||||
// saturate here. However, this mode is often
|
|
||||||
// used for displaying alpha-premultiplied graphics,
|
|
||||||
// in which case, saturation is not necessary.
|
|
||||||
// unfortunatelly, we have no way to know.
|
|
||||||
// This is a case, where we sacrifice correctness for
|
|
||||||
// performance. we should probably have some heuristics.
|
|
||||||
} else {
|
|
||||||
component_sat(temp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// compute fs
|
// compute fs
|
||||||
|
|
|
||||||
|
|
@ -21,53 +21,80 @@
|
||||||
|
|
||||||
.global scanline_t32cb16blend_arm
|
.global scanline_t32cb16blend_arm
|
||||||
|
|
||||||
// uses r6, r7, lr
|
|
||||||
|
|
||||||
.macro pixel, DREG, SRC, FB, OFFSET
|
/*
|
||||||
|
* .macro pixel
|
||||||
|
*
|
||||||
|
* \DREG is a 32-bit register containing *two* original destination RGB565
|
||||||
|
* pixels, with the even one in the low-16 bits, and the odd one in the
|
||||||
|
* high 16 bits.
|
||||||
|
*
|
||||||
|
* \SRC is a 32-bit 0xAABBGGRR pixel value, with pre-multiplied colors.
|
||||||
|
*
|
||||||
|
* \FB is a target register that will contain the blended pixel values.
|
||||||
|
*
|
||||||
|
* \ODD is either 0 or 1 and indicates if we're blending the lower or
|
||||||
|
* upper 16-bit pixels in DREG into FB
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* clobbered: r6, r7, lr
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
// SRC = AARRGGBB
|
.macro pixel, DREG, SRC, FB, ODD
|
||||||
|
|
||||||
|
// SRC = 0xAABBGGRR
|
||||||
mov r7, \SRC, lsr #24 // sA
|
mov r7, \SRC, lsr #24 // sA
|
||||||
add r7, r7, r7, lsr #7 // sA + (sA >> 7)
|
add r7, r7, r7, lsr #7 // sA + (sA >> 7)
|
||||||
rsb r7, r7, #0x100 // sA = 0x100 - (sA+(sA>>7))
|
rsb r7, r7, #0x100 // sA = 0x100 - (sA+(sA>>7))
|
||||||
|
|
||||||
1:
|
1:
|
||||||
|
|
||||||
.if \OFFSET
|
.if \ODD
|
||||||
|
|
||||||
// red
|
// red
|
||||||
mov lr, \DREG, lsr #(\OFFSET + 6 + 5)
|
mov lr, \DREG, lsr #(16 + 11)
|
||||||
smulbb lr, r7, lr
|
smulbb lr, r7, lr
|
||||||
mov r6, \SRC, lsr #3
|
mov r6, \SRC, lsr #3
|
||||||
and r6, r6, #0x1F
|
and r6, r6, #0x1F
|
||||||
add lr, r6, lr, lsr #8
|
add lr, r6, lr, lsr #8
|
||||||
orr \FB, lr, lsl #(\OFFSET + 11)
|
cmp lr, #0x1F
|
||||||
|
orrhs \FB, \FB, #(0x1F<<(16 + 11))
|
||||||
|
orrlo \FB, \FB, lr, lsl #(16 + 11)
|
||||||
|
|
||||||
// green
|
// green
|
||||||
and r6, \DREG, #(0x3F<<(\OFFSET + 5))
|
and r6, \DREG, #(0x3F<<(16 + 5))
|
||||||
smulbt r6, r7, r6
|
smulbt r6, r7, r6
|
||||||
mov lr, \SRC, lsr #(8+2)
|
mov lr, \SRC, lsr #(8+2)
|
||||||
and lr, lr, #0x3F
|
and lr, lr, #0x3F
|
||||||
add r6, lr, r6, lsr #(5+8)
|
add r6, lr, r6, lsr #(5+8)
|
||||||
orr \FB, \FB, r6, lsl #(\OFFSET + 5)
|
cmp r6, #0x3F
|
||||||
|
orrhs \FB, \FB, #(0x3F<<(16 + 5))
|
||||||
|
orrlo \FB, \FB, r6, lsl #(16 + 5)
|
||||||
|
|
||||||
// blue
|
// blue
|
||||||
and lr, \DREG, #(0x1F << \OFFSET)
|
and lr, \DREG, #(0x1F << 16)
|
||||||
smulbt lr, r7, lr
|
smulbt lr, r7, lr
|
||||||
mov r6, \SRC, lsr #(8+8+3)
|
mov r6, \SRC, lsr #(8+8+3)
|
||||||
and r6, r6, #0x1F
|
and r6, r6, #0x1F
|
||||||
add lr, r6, lr, lsr #8
|
add lr, r6, lr, lsr #8
|
||||||
orr \FB, \FB, lr, lsl #\OFFSET
|
cmp lr, #0x1F
|
||||||
|
orrhs \FB, \FB, #(0x1F << 16)
|
||||||
|
orrlo \FB, \FB, lr, lsl #16
|
||||||
|
|
||||||
.else
|
.else
|
||||||
|
|
||||||
// red
|
// red
|
||||||
mov lr, \DREG, lsr #(6+5)
|
mov lr, \DREG, lsr #11
|
||||||
and lr, lr, #0x1F
|
and lr, lr, #0x1F
|
||||||
smulbb lr, r7, lr
|
smulbb lr, r7, lr
|
||||||
mov r6, \SRC, lsr #3
|
mov r6, \SRC, lsr #3
|
||||||
and r6, r6, #0x1F
|
and r6, r6, #0x1F
|
||||||
add lr, r6, lr, lsr #8
|
add lr, r6, lr, lsr #8
|
||||||
mov \FB, lr, lsl #11
|
cmp lr, #0x1F
|
||||||
|
movhs \FB, #(0x1F<<11)
|
||||||
|
movlo \FB, lr, lsl #11
|
||||||
|
|
||||||
|
|
||||||
// green
|
// green
|
||||||
and r6, \DREG, #(0x3F<<5)
|
and r6, \DREG, #(0x3F<<5)
|
||||||
|
|
@ -75,7 +102,9 @@
|
||||||
mov lr, \SRC, lsr #(8+2)
|
mov lr, \SRC, lsr #(8+2)
|
||||||
and lr, lr, #0x3F
|
and lr, lr, #0x3F
|
||||||
add r6, lr, r6, lsr #(5+8)
|
add r6, lr, r6, lsr #(5+8)
|
||||||
orr \FB, \FB, r6, lsl #5
|
cmp r6, #0x3F
|
||||||
|
orrhs \FB, \FB, #(0x3F<<5)
|
||||||
|
orrlo \FB, \FB, r6, lsl #5
|
||||||
|
|
||||||
// blue
|
// blue
|
||||||
and lr, \DREG, #0x1F
|
and lr, \DREG, #0x1F
|
||||||
|
|
@ -83,7 +112,9 @@
|
||||||
mov r6, \SRC, lsr #(8+8+3)
|
mov r6, \SRC, lsr #(8+8+3)
|
||||||
and r6, r6, #0x1F
|
and r6, r6, #0x1F
|
||||||
add lr, r6, lr, lsr #8
|
add lr, r6, lr, lsr #8
|
||||||
orr \FB, \FB, lr
|
cmp lr, #0x1F
|
||||||
|
orrhs \FB, \FB, #0x1F
|
||||||
|
orrlo \FB, \FB, lr
|
||||||
|
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
|
|
@ -128,7 +159,7 @@ aligned:
|
||||||
subs r2, r2, #2
|
subs r2, r2, #2
|
||||||
blo 9f
|
blo 9f
|
||||||
|
|
||||||
// The main loop is unrolled twice and process 4 pixels
|
// The main loop is unrolled twice and processes 4 pixels
|
||||||
8: ldmia r1!, {r4, r5}
|
8: ldmia r1!, {r4, r5}
|
||||||
// stream the source
|
// stream the source
|
||||||
pld [r1, #32]
|
pld [r1, #32]
|
||||||
|
|
@ -142,7 +173,7 @@ aligned:
|
||||||
// stream the destination
|
// stream the destination
|
||||||
pld [r0, #32]
|
pld [r0, #32]
|
||||||
pixel r3, r4, r12, 0
|
pixel r3, r4, r12, 0
|
||||||
pixel r3, r5, r12, 16
|
pixel r3, r5, r12, 1
|
||||||
// effectively, we're getting write-combining by virtue of the
|
// effectively, we're getting write-combining by virtue of the
|
||||||
// cpu's write-back cache.
|
// cpu's write-back cache.
|
||||||
str r12, [r0, #-4]
|
str r12, [r0, #-4]
|
||||||
|
|
|
||||||
|
|
@ -56,24 +56,73 @@ void FrameworkListener::registerCmd(FrameworkCommand *cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) {
|
void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) {
|
||||||
int argc;
|
FrameworkCommandCollection::iterator i;
|
||||||
|
int argc = 0;
|
||||||
char *argv[FrameworkListener::CMD_ARGS_MAX];
|
char *argv[FrameworkListener::CMD_ARGS_MAX];
|
||||||
|
char tmp[255];
|
||||||
|
char *p = data;
|
||||||
|
char *q = tmp;
|
||||||
|
bool esc = false;
|
||||||
|
bool quote = false;
|
||||||
|
int k;
|
||||||
|
|
||||||
if (!index(data, '"')) {
|
memset(argv, 0, sizeof(argv));
|
||||||
char *next = data;
|
memset(tmp, 0, sizeof(tmp));
|
||||||
char *field;
|
while(*p) {
|
||||||
int i;
|
if (*p == '\\') {
|
||||||
|
if (esc) {
|
||||||
|
*q++ = '\\';
|
||||||
|
esc = false;
|
||||||
|
} else
|
||||||
|
esc = true;
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
|
} else if (esc) {
|
||||||
|
if (*p == '"')
|
||||||
|
*q++ = '"';
|
||||||
|
else if (*p == '\\')
|
||||||
|
*q++ = '\\';
|
||||||
|
else {
|
||||||
|
cli->sendMsg(500, "Unsupported escape sequence", false);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
esc = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; (i < FrameworkListener::CMD_ARGS_MAX) &&
|
if (*p == '"') {
|
||||||
(argv[i] = strsep(&next, " ")); i++);
|
if (quote)
|
||||||
argc = i+1;
|
quote = false;
|
||||||
} else {
|
else
|
||||||
LOGD("blehhh not supported");
|
quote = true;
|
||||||
return;
|
p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
*q = *p++;
|
||||||
|
if (!quote && *q == ' ') {
|
||||||
|
*q = '\0';
|
||||||
|
argv[argc++] = strdup(tmp);
|
||||||
|
memset(tmp, 0, sizeof(tmp));
|
||||||
|
q = tmp;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
q++;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameworkCommandCollection::iterator i;
|
argv[argc++] = strdup(tmp);
|
||||||
|
#if 0
|
||||||
|
for (k = 0; k < argc; k++) {
|
||||||
|
LOGD("arg[%d] = '%s'", k, argv[k]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (quote) {
|
||||||
|
cli->sendMsg(500, "Unclosed quotes error", false);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = mCommands->begin(); i != mCommands->end(); ++i) {
|
for (i = mCommands->begin(); i != mCommands->end(); ++i) {
|
||||||
FrameworkCommand *c = *i;
|
FrameworkCommand *c = *i;
|
||||||
|
|
||||||
|
|
@ -81,10 +130,14 @@ void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) {
|
||||||
if (c->runCommand(cli, argc, argv)) {
|
if (c->runCommand(cli, argc, argv)) {
|
||||||
LOGW("Handler '%s' error (%s)", c->getCommand(), strerror(errno));
|
LOGW("Handler '%s' error (%s)", c->getCommand(), strerror(errno));
|
||||||
}
|
}
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cli->sendMsg(500, "Command not recognized", false);
|
cli->sendMsg(500, "Command not recognized", false);
|
||||||
|
out:
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < argc; j++)
|
||||||
|
free(argv[j]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,26 @@ SocketListener::SocketListener(int socketFd, bool listen) {
|
||||||
mClients = new SocketClientCollection();
|
mClients = new SocketClientCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SocketListener::~SocketListener() {
|
||||||
|
if (mSocketName && mSock > -1)
|
||||||
|
close(mSock);
|
||||||
|
|
||||||
|
if (mCtrlPipe[0] != -1) {
|
||||||
|
close(mCtrlPipe[0]);
|
||||||
|
close(mCtrlPipe[1]);
|
||||||
|
}
|
||||||
|
SocketClientCollection::iterator it;
|
||||||
|
for (it = mClients->begin(); it != mClients->end(); ++it) {
|
||||||
|
delete (*it);
|
||||||
|
it = mClients->erase(it);
|
||||||
|
}
|
||||||
|
delete mClients;
|
||||||
|
}
|
||||||
|
|
||||||
int SocketListener::startListener() {
|
int SocketListener::startListener() {
|
||||||
|
|
||||||
if (!mSocketName && mSock == -1) {
|
if (!mSocketName && mSock == -1) {
|
||||||
|
LOGE("Failed to start unbound listener");
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
} else if (mSocketName) {
|
} else if (mSocketName) {
|
||||||
|
|
@ -64,11 +81,15 @@ int SocketListener::startListener() {
|
||||||
} else if (!mListen)
|
} else if (!mListen)
|
||||||
mClients->push_back(new SocketClient(mSock));
|
mClients->push_back(new SocketClient(mSock));
|
||||||
|
|
||||||
if (pipe(mCtrlPipe))
|
if (pipe(mCtrlPipe)) {
|
||||||
|
LOGE("pipe failed (%s)", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (pthread_create(&mThread, NULL, SocketListener::threadStart, this))
|
if (pthread_create(&mThread, NULL, SocketListener::threadStart, this)) {
|
||||||
|
LOGE("pthread_create (%s)", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -88,6 +109,19 @@ int SocketListener::stopListener() {
|
||||||
}
|
}
|
||||||
close(mCtrlPipe[0]);
|
close(mCtrlPipe[0]);
|
||||||
close(mCtrlPipe[1]);
|
close(mCtrlPipe[1]);
|
||||||
|
mCtrlPipe[0] = -1;
|
||||||
|
mCtrlPipe[1] = -1;
|
||||||
|
|
||||||
|
if (mSocketName && mSock > -1) {
|
||||||
|
close(mSock);
|
||||||
|
mSock = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SocketClientCollection::iterator it;
|
||||||
|
for (it = mClients->begin(); it != mClients->end(); ++it) {
|
||||||
|
delete (*it);
|
||||||
|
it = mClients->erase(it);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ enum {
|
||||||
// central directory entries
|
// central directory entries
|
||||||
ENTRY_SIGNATURE = 0x02014b50,
|
ENTRY_SIGNATURE = 0x02014b50,
|
||||||
ENTRY_LEN = 46, // CentralDirEnt len, excl. var fields
|
ENTRY_LEN = 46, // CentralDirEnt len, excl. var fields
|
||||||
|
|
||||||
// local file header
|
// local file header
|
||||||
LFH_SIZE = 30,
|
LFH_SIZE = 30,
|
||||||
};
|
};
|
||||||
|
|
@ -73,8 +73,6 @@ read_central_directory_entry(Zipfile* file, Zipentry* entry,
|
||||||
unsigned short lastModFileTime;
|
unsigned short lastModFileTime;
|
||||||
unsigned short lastModFileDate;
|
unsigned short lastModFileDate;
|
||||||
unsigned long crc32;
|
unsigned long crc32;
|
||||||
unsigned long compressedSize;
|
|
||||||
unsigned long uncompressedSize;
|
|
||||||
unsigned short extraFieldLength;
|
unsigned short extraFieldLength;
|
||||||
unsigned short fileCommentLength;
|
unsigned short fileCommentLength;
|
||||||
unsigned short diskNumberStart;
|
unsigned short diskNumberStart;
|
||||||
|
|
@ -85,7 +83,7 @@ read_central_directory_entry(Zipfile* file, Zipentry* entry,
|
||||||
const unsigned char* fileComment;
|
const unsigned char* fileComment;
|
||||||
unsigned int dataOffset;
|
unsigned int dataOffset;
|
||||||
unsigned short lfhExtraFieldSize;
|
unsigned short lfhExtraFieldSize;
|
||||||
|
|
||||||
|
|
||||||
p = *buf;
|
p = *buf;
|
||||||
|
|
||||||
|
|
@ -106,7 +104,7 @@ read_central_directory_entry(Zipfile* file, Zipentry* entry,
|
||||||
lastModFileTime = read_le_short(&p[0x0c]);
|
lastModFileTime = read_le_short(&p[0x0c]);
|
||||||
lastModFileDate = read_le_short(&p[0x0e]);
|
lastModFileDate = read_le_short(&p[0x0e]);
|
||||||
crc32 = read_le_int(&p[0x10]);
|
crc32 = read_le_int(&p[0x10]);
|
||||||
compressedSize = read_le_int(&p[0x14]);
|
entry->compressedSize = read_le_int(&p[0x14]);
|
||||||
entry->uncompressedSize = read_le_int(&p[0x18]);
|
entry->uncompressedSize = read_le_int(&p[0x18]);
|
||||||
entry->fileNameLength = read_le_short(&p[0x1c]);
|
entry->fileNameLength = read_le_short(&p[0x1c]);
|
||||||
extraFieldLength = read_le_short(&p[0x1e]);
|
extraFieldLength = read_le_short(&p[0x1e]);
|
||||||
|
|
@ -141,14 +139,14 @@ read_central_directory_entry(Zipfile* file, Zipentry* entry,
|
||||||
fileComment = NULL;
|
fileComment = NULL;
|
||||||
}
|
}
|
||||||
p += fileCommentLength;
|
p += fileCommentLength;
|
||||||
|
|
||||||
*buf = p;
|
*buf = p;
|
||||||
|
|
||||||
// the size of the extraField in the central dir is how much data there is,
|
// the size of the extraField in the central dir is how much data there is,
|
||||||
// but the one in the local file header also contains some padding.
|
// but the one in the local file header also contains some padding.
|
||||||
p = file->buf + localHeaderRelOffset;
|
p = file->buf + localHeaderRelOffset;
|
||||||
extraFieldLength = read_le_short(&p[0x1c]);
|
extraFieldLength = read_le_short(&p[0x1c]);
|
||||||
|
|
||||||
dataOffset = localHeaderRelOffset + LFH_SIZE
|
dataOffset = localHeaderRelOffset + LFH_SIZE
|
||||||
+ entry->fileNameLength + extraFieldLength;
|
+ entry->fileNameLength + extraFieldLength;
|
||||||
entry->data = file->buf + dataOffset;
|
entry->data = file->buf + dataOffset;
|
||||||
|
|
@ -243,7 +241,7 @@ read_central_dir(Zipfile *file)
|
||||||
free(entry);
|
free(entry);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add it to our list
|
// add it to our list
|
||||||
entry->next = file->entries;
|
entry->next = file->entries;
|
||||||
file->entries = entry;
|
file->entries = entry;
|
||||||
|
|
@ -253,4 +251,3 @@ read_central_dir(Zipfile *file)
|
||||||
bail:
|
bail:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,13 +82,13 @@ uninflate(unsigned char* out, int unlen, const unsigned char* in, int clen)
|
||||||
unsigned long crc;
|
unsigned long crc;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int zerr;
|
int zerr;
|
||||||
|
|
||||||
memset(&zstream, 0, sizeof(zstream));
|
memset(&zstream, 0, sizeof(zstream));
|
||||||
zstream.zalloc = Z_NULL;
|
zstream.zalloc = Z_NULL;
|
||||||
zstream.zfree = Z_NULL;
|
zstream.zfree = Z_NULL;
|
||||||
zstream.opaque = Z_NULL;
|
zstream.opaque = Z_NULL;
|
||||||
zstream.next_in = (void*)in;
|
zstream.next_in = (void*)in;
|
||||||
zstream.avail_in = unlen;
|
zstream.avail_in = clen;
|
||||||
zstream.next_out = (Bytef*) out;
|
zstream.next_out = (Bytef*) out;
|
||||||
zstream.avail_out = unlen;
|
zstream.avail_out = unlen;
|
||||||
zstream.data_type = Z_UNKNOWN;
|
zstream.data_type = Z_UNKNOWN;
|
||||||
|
|
@ -99,7 +99,7 @@ uninflate(unsigned char* out, int unlen, const unsigned char* in, int clen)
|
||||||
if (zerr != Z_OK) {
|
if (zerr != Z_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// uncompress the data
|
// uncompress the data
|
||||||
zerr = inflate(&zstream, Z_FINISH);
|
zerr = inflate(&zstream, Z_FINISH);
|
||||||
if (zerr != Z_STREAM_END) {
|
if (zerr != Z_STREAM_END) {
|
||||||
|
|
@ -107,7 +107,7 @@ uninflate(unsigned char* out, int unlen, const unsigned char* in, int clen)
|
||||||
zstream.total_out);
|
zstream.total_out);
|
||||||
err = -1;
|
err = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inflateEnd(&zstream);
|
inflateEnd(&zstream);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
# 2: long
|
# 2: long
|
||||||
# 3: string
|
# 3: string
|
||||||
# 4: list
|
# 4: list
|
||||||
#
|
#
|
||||||
# The data unit is a number taken from the following list:
|
# The data unit is a number taken from the following list:
|
||||||
# 1: Number of objects
|
# 1: Number of objects
|
||||||
# 2: Number of bytes
|
# 2: Number of bytes
|
||||||
|
|
@ -40,7 +40,8 @@
|
||||||
2718 e
|
2718 e
|
||||||
|
|
||||||
2719 configuration_changed (config mask|1|5)
|
2719 configuration_changed (config mask|1|5)
|
||||||
2720 sync (id|3),(event|1|5),(source|1|5)
|
# "account" is the java hash of the account name
|
||||||
|
2720 sync (id|3),(event|1|5),(source|1|5),(account|1|5)
|
||||||
2721 cpu (total|1|6),(user|1|6),(system|1|6),(iowait|1|6),(irq|1|6),(softirq|1|6)
|
2721 cpu (total|1|6),(user|1|6),(system|1|6),(iowait|1|6),(irq|1|6),(softirq|1|6)
|
||||||
2722 battery_level (level|1|6),(voltage|1|1),(temperature|1|1)
|
2722 battery_level (level|1|6),(voltage|1|1),(temperature|1|1)
|
||||||
2723 battery_status (status|1|5),(health|1|5),(present|1|5),(plugged|1|5),(technology|3)
|
2723 battery_status (status|1|5),(health|1|5),(present|1|5),(plugged|1|5),(technology|3)
|
||||||
|
|
@ -58,11 +59,11 @@
|
||||||
# This is logged when the partial wake lock (keeping the device awake
|
# This is logged when the partial wake lock (keeping the device awake
|
||||||
# regardless of whether the screen is off) is acquired or released.
|
# regardless of whether the screen is off) is acquired or released.
|
||||||
2729 power_partial_wake_state (releasedorAcquired|1|5),(tag|3)
|
2729 power_partial_wake_state (releasedorAcquired|1|5),(tag|3)
|
||||||
# This is logged when battery goes from discharging to charging.
|
# This is logged when battery goes from discharging to charging.
|
||||||
# It lets us count the total amount of time between charges and the discharge level
|
# It lets us count the total amount of time between charges and the discharge level
|
||||||
2730 battery_discharge (duration|2|3),(minLevel|1|6),(maxLevel|1|6)
|
2730 battery_discharge (duration|2|3),(minLevel|1|6),(maxLevel|1|6)
|
||||||
#
|
#
|
||||||
# Leave IDs through 2739 for more power logs
|
# Leave IDs through 2739 for more power logs
|
||||||
#
|
#
|
||||||
|
|
||||||
# This event is logged when the location service uploads location data.
|
# This event is logged when the location service uploads location data.
|
||||||
|
|
@ -79,8 +80,12 @@
|
||||||
2744 free_storage_changed (data|2|2)
|
2744 free_storage_changed (data|2|2)
|
||||||
# Device low memory notification and disk space free on the /data partition, in bytes at that time
|
# Device low memory notification and disk space free on the /data partition, in bytes at that time
|
||||||
2745 low_storage (data|2|2)
|
2745 low_storage (data|2|2)
|
||||||
# disk space free on the /data partition in bytes
|
# disk space free on the /data, /system, and /cache partitions in bytes
|
||||||
2746 free_storage_left (data|2|2)
|
2746 free_storage_left (data|2|2),(system|2|2),(cache|2|2)
|
||||||
|
|
||||||
|
# contacts aggregation: time and number of contacts.
|
||||||
|
# count is negative for query phase, positive for merge phase
|
||||||
|
2747 contacts_aggregation (aggregation time|2|3), (count|1|1)
|
||||||
|
|
||||||
# when a NotificationManager.notify is called
|
# when a NotificationManager.notify is called
|
||||||
2750 notification_enqueue (pkg|3),(id|1|5),(notification|3)
|
2750 notification_enqueue (pkg|3),(id|1|5),(notification|3)
|
||||||
|
|
@ -94,7 +99,7 @@
|
||||||
2800 gtalkservice (eventType|1)
|
2800 gtalkservice (eventType|1)
|
||||||
# This event is logged for GTalk connection state changes. The status field is an int, but
|
# This event is logged for GTalk connection state changes. The status field is an int, but
|
||||||
# it really contains 4 separate values, each taking up a byte
|
# it really contains 4 separate values, each taking up a byte
|
||||||
# (eventType, connection state, connection error, network state)
|
# (eventType << 24) + (connection state << 16) + (connection error << 8) + network state
|
||||||
2801 gtalk_connection (status|1)
|
2801 gtalk_connection (status|1)
|
||||||
|
|
||||||
2802 watchdog (Service|3)
|
2802 watchdog (Service|3)
|
||||||
|
|
@ -108,6 +113,21 @@
|
||||||
2810 watchdog_vmstat (runtime|2|3),(pgfree|1|1),(pgactivate|1|1),(pgdeactivate|1|1),(pgfault|1|1),(pgmajfault|1|1)
|
2810 watchdog_vmstat (runtime|2|3),(pgfree|1|1),(pgactivate|1|1),(pgdeactivate|1|1),(pgfault|1|1),(pgmajfault|1|1)
|
||||||
2811 watchdog_requested_reboot (NoWait|1|1),(ScheduleInterval|1|3),(RecheckInterval|1|3),(StartTime|1|3),(Window|1|3),(MinScreenOff|1|3),(MinNextAlarm|1|3)
|
2811 watchdog_requested_reboot (NoWait|1|1),(ScheduleInterval|1|3),(RecheckInterval|1|3),(StartTime|1|3),(Window|1|3),(MinScreenOff|1|3),(MinNextAlarm|1|3)
|
||||||
|
|
||||||
|
2820 backup_data_changed (Package|3)
|
||||||
|
2821 backup_start (Transport|3)
|
||||||
|
2822 backup_transport_failure (Package|3)
|
||||||
|
2823 backup_agent_failure (Package|3),(Message|3)
|
||||||
|
2824 backup_package (Package|3),(Size|1|2)
|
||||||
|
2825 backup_success (Packages|1|1),(Time|1|3)
|
||||||
|
2826 backup_reset (Transport|3)
|
||||||
|
2827 backup_initialize
|
||||||
|
|
||||||
|
2830 restore_start (Transport|3),(Source|2|5)
|
||||||
|
2831 restore_transport_failure
|
||||||
|
2832 restore_agent_failure (Package|3),(Message|3)
|
||||||
|
2833 restore_package (Package|3),(Size|1|2)
|
||||||
|
2834 restore_success (Packages|1|1),(Time|1|3)
|
||||||
|
|
||||||
# Device boot timings. We include monotonic clock values because the
|
# Device boot timings. We include monotonic clock values because the
|
||||||
# intrinsic event log times are wall-clock.
|
# intrinsic event log times are wall-clock.
|
||||||
#
|
#
|
||||||
|
|
@ -135,6 +155,67 @@
|
||||||
3100 boot_progress_pms_ready (time|2|3)
|
3100 boot_progress_pms_ready (time|2|3)
|
||||||
# + check activity_launch_time for Home app
|
# + check activity_launch_time for Home app
|
||||||
|
|
||||||
|
# This event is logged when GTalk connection is closed.
|
||||||
|
# The status field is an int, but contains 2 different values, it's represented as
|
||||||
|
#
|
||||||
|
# (networkType << 8) + connection error
|
||||||
|
#
|
||||||
|
# the possible error values are
|
||||||
|
#
|
||||||
|
# no_error=0, no_network=1, connection_failed=2, unknown_host=3, auth_failed=4,
|
||||||
|
# auth_expired=5, heart_beat_timeout=6, server_error=7, server_reject_rate_limiting=8, unknown=10
|
||||||
|
#
|
||||||
|
# duration is the connection duration.
|
||||||
|
4000 gtalk_conn_close (status|1),(duration|1)
|
||||||
|
|
||||||
|
# This event is logged for GTalk heartbeat resets
|
||||||
|
# interval_and_nt contains both the heartbeat interval and the network type, It's represented as
|
||||||
|
# (networkType << 16) + interval
|
||||||
|
# interval is in seconds; network type can be 0 (mobile) or 1 (wifi); ip is the host ip addr.
|
||||||
|
4001 gtalk_heartbeat_reset (interval_and_nt|1),(ip|3)
|
||||||
|
|
||||||
|
# dvm_gc_info: LIST (LONG, LONG, LONG)
|
||||||
|
#
|
||||||
|
# First LONG:
|
||||||
|
#
|
||||||
|
# [63] 1
|
||||||
|
# [62-24] ASCII process identifier
|
||||||
|
# [23-12] GC time in ms
|
||||||
|
# [11- 0] Bytes freed
|
||||||
|
#
|
||||||
|
# Second LONG (aggregated heap info):
|
||||||
|
#
|
||||||
|
# [63-62] 10
|
||||||
|
# [61-60] Reserved; must be zero
|
||||||
|
# [59-48] Objects freed
|
||||||
|
# [47-36] Actual size (current footprint)
|
||||||
|
# [35-24] Allowed size (current hard max)
|
||||||
|
# [23-12] Objects allocated
|
||||||
|
# [11- 0] Bytes allocated
|
||||||
|
#
|
||||||
|
# Third LONG (zygote heap info):
|
||||||
|
#
|
||||||
|
# [63-62] 11
|
||||||
|
# [61-60] Reserved; must be zero
|
||||||
|
# [59-48] Soft limit
|
||||||
|
# [47-36] Actual size (current footprint)
|
||||||
|
# [35-24] Allowed size (current hard max)
|
||||||
|
# [23-12] Objects allocated
|
||||||
|
# [11- 0] Bytes allocated
|
||||||
|
#
|
||||||
|
# Fourth LONG:
|
||||||
|
#
|
||||||
|
# [63-48] Reserved; must be zero
|
||||||
|
# [47-36] dlmallocFootprint
|
||||||
|
# [35-24] mallinfo: total allocated space
|
||||||
|
# [23-12] External byte limit
|
||||||
|
# [11- 0] External bytes allocated
|
||||||
|
#
|
||||||
|
# See HeapDebug.c
|
||||||
|
#
|
||||||
|
20001 dvm_gc_info (custom|2),(custom|2),(custom|2),(custom|2)
|
||||||
|
20002 dvm_gc_madvise_info (total|1|2),(zygote|1|2)
|
||||||
|
|
||||||
# Do not change these names without updating the checkin_events setting in
|
# Do not change these names without updating the checkin_events setting in
|
||||||
# google3/googledata/wireless/android/provisioning/gservices.config !!
|
# google3/googledata/wireless/android/provisioning/gservices.config !!
|
||||||
#
|
#
|
||||||
|
|
@ -160,9 +241,9 @@
|
||||||
30010 am_proc_bound (PID|1|5),(Process Name|3)
|
30010 am_proc_bound (PID|1|5),(Process Name|3)
|
||||||
# Application process died
|
# Application process died
|
||||||
30011 am_proc_died (PID|1|5),(Process Name|3)
|
30011 am_proc_died (PID|1|5),(Process Name|3)
|
||||||
# The Activity Manager failed to pause the given activity.
|
# The Activity Manager failed to pause the given activity.
|
||||||
30012 am_failed_to_pause (Token|1|5),(Wanting to pause|3),(Currently pausing|3)
|
30012 am_failed_to_pause (Token|1|5),(Wanting to pause|3),(Currently pausing|3)
|
||||||
# Attempting to pause the current activity
|
# Attempting to pause the current activity
|
||||||
30013 am_pause_activity (Token|1|5),(Component Name|3)
|
30013 am_pause_activity (Token|1|5),(Component Name|3)
|
||||||
# Application process has been started
|
# Application process has been started
|
||||||
30014 am_proc_start (PID|1|5),(UID|1|5),(Process Name|3),(Type|3),(Component|3)
|
30014 am_proc_start (PID|1|5),(UID|1|5),(Process Name|3),(Type|3),(Component|3)
|
||||||
|
|
@ -208,52 +289,11 @@
|
||||||
# Re-connecting to input method service because we haven't received its interface
|
# Re-connecting to input method service because we haven't received its interface
|
||||||
32000 imf_force_reconnect_ime (IME|4),(Time Since Connect|2|3),(Showing|1|1)
|
32000 imf_force_reconnect_ime (IME|4),(Time Since Connect|2|3),(Showing|1|1)
|
||||||
|
|
||||||
# dvm_gc_info: LIST (LONG, LONG, LONG)
|
|
||||||
#
|
|
||||||
# First LONG:
|
|
||||||
#
|
|
||||||
# [63] 1
|
|
||||||
# [62-24] ASCII process identifier
|
|
||||||
# [23-12] GC time in ms
|
|
||||||
# [11- 0] Bytes freed
|
|
||||||
#
|
|
||||||
# Second LONG (aggregated heap info):
|
|
||||||
#
|
|
||||||
# [63-62] 10
|
|
||||||
# [61-60] Reserved; must be zero
|
|
||||||
# [59-48] Objects freed
|
|
||||||
# [47-36] Actual size (current footprint)
|
|
||||||
# [35-24] Allowed size (current hard max)
|
|
||||||
# [23-12] Objects allocated
|
|
||||||
# [11- 0] Bytes allocated
|
|
||||||
#
|
|
||||||
# Third LONG (zygote heap info):
|
|
||||||
#
|
|
||||||
# [63-62] 11
|
|
||||||
# [61-60] Reserved; must be zero
|
|
||||||
# [59-48] Soft limit
|
|
||||||
# [47-36] Actual size (current footprint)
|
|
||||||
# [35-24] Allowed size (current hard max)
|
|
||||||
# [23-12] Objects allocated
|
|
||||||
# [11- 0] Bytes allocated
|
|
||||||
#
|
|
||||||
# Fourth LONG:
|
|
||||||
#
|
|
||||||
# [63-48] Reserved; must be zero
|
|
||||||
# [47-36] dlmallocFootprint
|
|
||||||
# [35-24] mallinfo: total allocated space
|
|
||||||
# [23-12] External byte limit
|
|
||||||
# [11- 0] External bytes allocated
|
|
||||||
#
|
|
||||||
# See HeapDebug.c
|
|
||||||
#
|
|
||||||
20001 dvm_gc_info (custom|2),(custom|2),(custom|2),(custom|2)
|
|
||||||
20002 dvm_gc_madvise_info (total|1|2),(zygote|1|2)
|
|
||||||
|
|
||||||
75000 sqlite_mem_alarm_current (current|1|2)
|
75000 sqlite_mem_alarm_current (current|1|2)
|
||||||
75001 sqlite_mem_alarm_max (max|1|2)
|
75001 sqlite_mem_alarm_max (max|1|2)
|
||||||
75002 sqlite_mem_alarm_alloc_attempt (attempts|1|4)
|
75002 sqlite_mem_alarm_alloc_attempt (attempts|1|4)
|
||||||
75003 sqlite_mem_released (Memory released|1|2)
|
75003 sqlite_mem_released (Memory released|1|2)
|
||||||
|
75004 sqlite_db_corrupt (Database file corrupt|3)
|
||||||
|
|
||||||
40000 checkin (Check in time|2|3)
|
40000 checkin (Check in time|2|3)
|
||||||
|
|
||||||
|
|
@ -262,28 +302,28 @@
|
||||||
# Connectivity state changed:
|
# Connectivity state changed:
|
||||||
# [31-13] Reserved for future use
|
# [31-13] Reserved for future use
|
||||||
# [12- 9] Network subtype (for mobile network, as defined by TelephonyManager)
|
# [12- 9] Network subtype (for mobile network, as defined by TelephonyManager)
|
||||||
# [ 8- 3] Detailed state ordinal (as defined by NetworkInfo.DetailedState)
|
# [ 8- 3] Detailed state ordinal (as defined by NetworkInfo.DetailedState)
|
||||||
# [ 2- 0] Network type (as defined by ConnectivityManager)
|
# [ 2- 0] Network type (as defined by ConnectivityManager)
|
||||||
50020 connectivity_state_changed (custom|1|5)
|
50020 connectivity_state_changed (custom|1|5)
|
||||||
|
|
||||||
# Wi-Fi network state changed:
|
# Wi-Fi network state changed:
|
||||||
# [31- 6] Reserved for future use
|
# [31- 6] Reserved for future use
|
||||||
# [ 5- 0] Detailed state ordinal (as defined by NetworkInfo.DetailedState)
|
# [ 5- 0] Detailed state ordinal (as defined by NetworkInfo.DetailedState)
|
||||||
50021 wifi_network_state_changed (network_state|1|5)
|
50021 wifi_network_state_changed (network_state|1|5)
|
||||||
|
|
||||||
# Wi-Fi supplicant state changed:
|
# Wi-Fi supplicant state changed:
|
||||||
# [31- 6] Reserved for future use
|
# [31- 6] Reserved for future use
|
||||||
# [ 5- 0] Supplicant state ordinal (as defined by SupplicantState)
|
# [ 5- 0] Supplicant state ordinal (as defined by SupplicantState)
|
||||||
50022 wifi_supplicant_state_changed (supplicant_state|1|5)
|
50022 wifi_supplicant_state_changed (supplicant_state|1|5)
|
||||||
|
|
||||||
# Wi-Fi driver state changed:
|
# Wi-Fi driver state changed:
|
||||||
# [31- 1] Reserved for future use
|
# [31- 1] Reserved for future use
|
||||||
# [ 0- 0] Driver start (1) or stopped (0)
|
# [ 0- 0] Driver start (1) or stopped (0)
|
||||||
50023 wifi_driver_state_changed (driver_state|1|5)
|
50023 wifi_driver_state_changed (driver_state|1|5)
|
||||||
|
|
||||||
# Wi-Fi interface configuration state changed:
|
# Wi-Fi interface configuration state changed:
|
||||||
# [31- 1] Reserved for future use
|
# [31- 1] Reserved for future use
|
||||||
# [ 0- 0] Interface configuration succeeded (1) or failed (0)
|
# [ 0- 0] Interface configuration succeeded (1) or failed (0)
|
||||||
50024 wifi_interface_configuration_state_changed (IP_configuration|1|5)
|
50024 wifi_interface_configuration_state_changed (IP_configuration|1|5)
|
||||||
|
|
||||||
# Wi-Fi supplicant connection state changed:
|
# Wi-Fi supplicant connection state changed:
|
||||||
|
|
@ -333,7 +373,7 @@
|
||||||
#//device/dalvik/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.c
|
#//device/dalvik/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.c
|
||||||
51000 socket_stats (send|1|2),(recv|1|2),(ip|1|5),(port|1|5),(close|1|5)
|
51000 socket_stats (send|1|2),(recv|1|2),(ip|1|5),(port|1|5),(close|1|5)
|
||||||
|
|
||||||
# db stats. 0 is query, 1 is write (may become more fine grained in the
|
# db stats. 0 is query, 1 is write (may become more fine grained in the
|
||||||
# future)
|
# future)
|
||||||
52000 db_operation (name|3),(op_type|1|5),(time|2|3)
|
52000 db_operation (name|3),(op_type|1|5),(time|2|3)
|
||||||
|
|
||||||
|
|
@ -351,5 +391,9 @@
|
||||||
70101 browser_zoom_level_change (start level|1|5),(end level|1|5),(time|2|3)
|
70101 browser_zoom_level_change (start level|1|5),(end level|1|5),(time|2|3)
|
||||||
70102 browser_double_tap_duration (duration|1|3),(time|2|3)
|
70102 browser_double_tap_duration (duration|1|3),(time|2|3)
|
||||||
|
|
||||||
|
# aggregation service
|
||||||
|
70200 aggregation (aggregation time|2|3)
|
||||||
|
70201 aggregation_test (field1|1|2),(field2|1|2),(field3|1|2),(field4|1|2),(field5|1|2)
|
||||||
|
|
||||||
# NOTE - the range 1000000-2000000 is reserved for partners and others who
|
# NOTE - the range 1000000-2000000 is reserved for partners and others who
|
||||||
# want to define their own log tags without conflicting with the core platform.
|
# want to define their own log tags without conflicting with the core platform.
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,22 @@ include $(CLEAR_VARS)
|
||||||
|
|
||||||
LOCAL_SRC_FILES:= \
|
LOCAL_SRC_FILES:= \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
NetworkManager.cpp \
|
NexusCommand.cpp \
|
||||||
CommandListener.cpp \
|
CommandListener.cpp \
|
||||||
|
Property.cpp \
|
||||||
|
PropertyManager.cpp \
|
||||||
|
InterfaceConfig.cpp \
|
||||||
|
NetworkManager.cpp \
|
||||||
Controller.cpp \
|
Controller.cpp \
|
||||||
WifiController.cpp \
|
WifiController.cpp \
|
||||||
LoopController.cpp \
|
|
||||||
NexusCommand.cpp \
|
|
||||||
TiwlanWifiController.cpp \
|
TiwlanWifiController.cpp \
|
||||||
|
TiwlanEventListener.cpp \
|
||||||
|
WifiNetwork.cpp \
|
||||||
|
WifiStatusPoller.cpp \
|
||||||
|
ScanResult.cpp \
|
||||||
Supplicant.cpp \
|
Supplicant.cpp \
|
||||||
SupplicantEvent.cpp \
|
SupplicantEvent.cpp \
|
||||||
SupplicantListener.cpp \
|
SupplicantListener.cpp \
|
||||||
VpnController.cpp \
|
|
||||||
ScanResult.cpp \
|
|
||||||
WifiScanner.cpp \
|
|
||||||
WifiNetwork.cpp \
|
|
||||||
OpenVpnController.cpp \
|
|
||||||
InterfaceConfig.cpp \
|
|
||||||
PropertyManager.cpp \
|
|
||||||
SupplicantState.cpp \
|
SupplicantState.cpp \
|
||||||
SupplicantEventFactory.cpp \
|
SupplicantEventFactory.cpp \
|
||||||
SupplicantConnectedEvent.cpp \
|
SupplicantConnectedEvent.cpp \
|
||||||
|
|
@ -34,8 +33,11 @@ LOCAL_SRC_FILES:= \
|
||||||
SupplicantConnectionTimeoutEvent.cpp \
|
SupplicantConnectionTimeoutEvent.cpp \
|
||||||
SupplicantDisconnectedEvent.cpp \
|
SupplicantDisconnectedEvent.cpp \
|
||||||
SupplicantStatus.cpp \
|
SupplicantStatus.cpp \
|
||||||
TiwlanEventListener.cpp \
|
OpenVpnController.cpp \
|
||||||
|
VpnController.cpp \
|
||||||
|
LoopController.cpp \
|
||||||
DhcpClient.cpp DhcpListener.cpp \
|
DhcpClient.cpp DhcpListener.cpp \
|
||||||
|
DhcpState.cpp DhcpEvent.cpp \
|
||||||
|
|
||||||
LOCAL_MODULE:= nexus
|
LOCAL_MODULE:= nexus
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
#include "NetworkManager.h"
|
#include "NetworkManager.h"
|
||||||
#include "WifiController.h"
|
#include "WifiController.h"
|
||||||
#include "VpnController.h"
|
#include "VpnController.h"
|
||||||
#include "ErrorCode.h"
|
#include "ResponseCode.h"
|
||||||
|
|
||||||
CommandListener::CommandListener() :
|
CommandListener::CommandListener() :
|
||||||
FrameworkListener("nexus") {
|
FrameworkListener("nexus") {
|
||||||
|
|
@ -60,11 +60,11 @@ int CommandListener::WifiCreateNetworkCmd::runCommand(SocketClient *cli,
|
||||||
WifiNetwork *wn;
|
WifiNetwork *wn;
|
||||||
|
|
||||||
if (!(wn = wc->createNetwork()))
|
if (!(wn = wc->createNetwork()))
|
||||||
cli->sendMsg(ErrorCode::OperationFailed, "Failed to create network", true);
|
cli->sendMsg(ResponseCode::OperationFailed, "Failed to create network", true);
|
||||||
else {
|
else {
|
||||||
char tmp[128];
|
char tmp[128];
|
||||||
sprintf(tmp, "Created network id %d.", wn->getNetworkId());
|
sprintf(tmp, "Created network id %d.", wn->getNetworkId());
|
||||||
cli->sendMsg(ErrorCode::CommandOkay, tmp, false);
|
cli->sendMsg(ResponseCode::CommandOkay, tmp, false);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -79,9 +79,9 @@ int CommandListener::WifiRemoveNetworkCmd::runCommand(SocketClient *cli,
|
||||||
WifiController *wc = (WifiController *) nm->findController("WIFI");
|
WifiController *wc = (WifiController *) nm->findController("WIFI");
|
||||||
|
|
||||||
if (wc->removeNetwork(atoi(argv[1])))
|
if (wc->removeNetwork(atoi(argv[1])))
|
||||||
cli->sendMsg(ErrorCode::OperationFailed, "Failed to remove network", true);
|
cli->sendMsg(ResponseCode::OperationFailed, "Failed to remove network", true);
|
||||||
else {
|
else {
|
||||||
cli->sendMsg(ErrorCode::CommandOkay, "Network removed.", false);
|
cli->sendMsg(ResponseCode::CommandOkay, "Network removed.", false);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -100,16 +100,16 @@ int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli,
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
|
|
||||||
for(it = src->begin(); it != src->end(); ++it) {
|
for(it = src->begin(); it != src->end(); ++it) {
|
||||||
sprintf(buffer, "%s:%u:%d:%s:%s",
|
sprintf(buffer, "%s %u %d %s %s",
|
||||||
(*it)->getBssid(), (*it)->getFreq(), (*it)->getLevel(),
|
(*it)->getBssid(), (*it)->getFreq(), (*it)->getLevel(),
|
||||||
(*it)->getFlags(), (*it)->getSsid());
|
(*it)->getFlags(), (*it)->getSsid());
|
||||||
cli->sendMsg(ErrorCode::WifiScanResult, buffer, false);
|
cli->sendMsg(ResponseCode::WifiScanResult, buffer, false);
|
||||||
delete (*it);
|
delete (*it);
|
||||||
it = src->erase(it);
|
it = src->erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete src;
|
delete src;
|
||||||
cli->sendMsg(ErrorCode::CommandOkay, "Scan results complete.", false);
|
cli->sendMsg(ResponseCode::CommandOkay, "Scan results complete.", false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,12 +128,12 @@ int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli,
|
||||||
|
|
||||||
for(it = src->begin(); it != src->end(); ++it) {
|
for(it = src->begin(); it != src->end(); ++it) {
|
||||||
sprintf(buffer, "%d:%s", (*it)->getNetworkId(), (*it)->getSsid());
|
sprintf(buffer, "%d:%s", (*it)->getNetworkId(), (*it)->getSsid());
|
||||||
cli->sendMsg(ErrorCode::WifiNetworkList, buffer, false);
|
cli->sendMsg(ResponseCode::WifiNetworkList, buffer, false);
|
||||||
delete (*it);
|
delete (*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete src;
|
delete src;
|
||||||
cli->sendMsg(ErrorCode::CommandOkay, "Network listing complete.", false);
|
cli->sendMsg(ResponseCode::CommandOkay, "Network listing complete.", false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,14 +159,14 @@ int CommandListener::GetCmd::runCommand(SocketClient *cli, int argc, char **argv
|
||||||
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
asprintf(&tmp, "%s %s", argv[1], val);
|
asprintf(&tmp, "%s %s", argv[1], val);
|
||||||
cli->sendMsg(ErrorCode::PropertyRead, tmp, false);
|
cli->sendMsg(ResponseCode::PropertyRead, tmp, false);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
cli->sendMsg(ErrorCode::CommandOkay, "Property read.", false);
|
cli->sendMsg(ResponseCode::CommandOkay, "Property read.", false);
|
||||||
return 0;
|
return 0;
|
||||||
out_inval:
|
out_inval:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
cli->sendMsg(ErrorCode::CommandParameterError, "Failed to read property.", true);
|
cli->sendMsg(ResponseCode::CommandParameterError, "Failed to read property.", true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,12 +179,12 @@ int CommandListener::SetCmd::runCommand(SocketClient *cli, int argc,
|
||||||
if (NetworkManager::Instance()->getPropMngr()->set(argv[1], argv[2]))
|
if (NetworkManager::Instance()->getPropMngr()->set(argv[1], argv[2]))
|
||||||
goto out_inval;
|
goto out_inval;
|
||||||
|
|
||||||
cli->sendMsg(ErrorCode::CommandOkay, "Property set.", false);
|
cli->sendMsg(ResponseCode::CommandOkay, "Property set.", false);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_inval:
|
out_inval:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set property.", true);
|
cli->sendMsg(ResponseCode::CommandParameterError, "Failed to set property.", true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,10 +194,14 @@ CommandListener::ListCmd::ListCmd() :
|
||||||
|
|
||||||
int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **argv) {
|
int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **argv) {
|
||||||
android::List<char *> *pc;
|
android::List<char *> *pc;
|
||||||
|
char *prefix = NULL;
|
||||||
|
|
||||||
if (!(pc = NetworkManager::Instance()->getPropMngr()->createPropertyList())) {
|
if (argc > 1)
|
||||||
|
prefix = argv[1];
|
||||||
|
|
||||||
|
if (!(pc = NetworkManager::Instance()->getPropMngr()->createPropertyList(prefix))) {
|
||||||
errno = ENODATA;
|
errno = ENODATA;
|
||||||
cli->sendMsg(ErrorCode::CommandParameterError, "Failed to list properties.", true);
|
cli->sendMsg(ResponseCode::CommandParameterError, "Failed to list properties.", true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -218,7 +222,7 @@ int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **arg
|
||||||
free((*it));
|
free((*it));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cli->sendMsg(ErrorCode::PropertyList, buf, false);
|
cli->sendMsg(ResponseCode::PropertyList, buf, false);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
free((*it));
|
free((*it));
|
||||||
|
|
@ -226,6 +230,6 @@ int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **arg
|
||||||
|
|
||||||
delete pc;
|
delete pc;
|
||||||
|
|
||||||
cli->sendMsg(ErrorCode::CommandOkay, "Properties list complete.", false);
|
cli->sendMsg(ResponseCode::CommandOkay, "Properties list complete.", false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue