Merge ^/head r311460 through r311545.

This commit is contained in:
Dimitry Andric 2017-01-06 20:33:48 +00:00
commit 7fa59e6718
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/clang400-import/; revision=311547
131 changed files with 3548 additions and 1526 deletions

View file

@ -109,7 +109,8 @@ ls_list(ARCHD *arcn, time_t now, FILE *fp)
*/
if (strftime(f_date,DATELEN,timefrmt,localtime(&(sbp->st_mtime))) == 0)
f_date[0] = '\0';
(void)fprintf(fp, "%s%2u %-12s %-12s ", f_mode, sbp->st_nlink,
(void)fprintf(fp, "%s%2ju %-12s %-12s ", f_mode,
(uintmax_t)sbp->st_nlink,
name_uid(sbp->st_uid, 1), name_gid(sbp->st_gid, 1));
/*

View file

@ -37,7 +37,7 @@
* Scalars
*/
int
op_begemot_mibII(struct snmp_context *ctx __unused, struct snmp_value *value,
op_begemot_mibII(struct snmp_context *ctx, struct snmp_value *value,
u_int sub, u_int idx __unused, enum snmp_op op)
{
switch (op) {

View file

@ -224,7 +224,8 @@ statf(FILE *fp, int indent, FTSENT *p)
output(fp, indent, &offset, "device=%#jx",
(uintmax_t)p->fts_statp->st_rdev);
if (keys & F_NLINK && p->fts_statp->st_nlink != 1)
output(fp, indent, &offset, "nlink=%u", p->fts_statp->st_nlink);
output(fp, indent, &offset, "nlink=%ju",
(uintmax_t)p->fts_statp->st_nlink);
if (keys & F_SIZE &&
(flavor == F_FREEBSD9 || S_ISREG(p->fts_statp->st_mode)))
output(fp, indent, &offset, "size=%ju",

View file

@ -363,7 +363,8 @@ dump_nodes(FILE *fp, const char *dir, NODE *root, int pathlast)
appendfield(fp, pathlast, "device=%#jx",
(uintmax_t)cur->st_rdev);
if (MATCHFLAG(F_NLINK))
appendfield(fp, pathlast, "nlink=%d", cur->st_nlink);
appendfield(fp, pathlast, "nlink=%ju",
(uintmax_t)cur->st_nlink);
if (MATCHFLAG(F_SLINK))
appendfield(fp, pathlast, "link=%s",
vispath(cur->slink));

View file

@ -73,7 +73,7 @@ shownode(NODE *n, int f, char const *path)
if (f & F_MODE)
printf(" mode=%o", n->st_mode);
if (f & F_NLINK)
printf(" nlink=%d", n->st_nlink);
printf(" nlink=%ju", (uintmax_t)n->st_nlink);
if (f & F_SIZE)
printf(" size=%jd", (intmax_t)n->st_size);
if (f & F_UID)

View file

@ -69,22 +69,22 @@ extern char paranoid[];
/* Global functions. */
#if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT)
extern void fromhost(struct request_info *); /* get/validate client host info */
void fromhost(struct request_info *); /* get/validate client host info */
#else
#define fromhost sock_host /* no TLI support needed */
#define fromhost sock_host /* no TLI support needed */
#endif
extern int hosts_access(struct request_info *); /* access control */
extern int hosts_ctl(char *, char *, char *, char *); /* wrapper around request_init() */
extern void shell_cmd(char *); /* execute shell command */
extern char *percent_x(char *, int, char *, struct request_info *); /* do %<char> expansion */
extern void rfc931(TCPD_SOCKADDR *, TCPD_SOCKADDR *, char *); /* client name from RFC 931 daemon */
extern void clean_exit(struct request_info *); /* clean up and exit */
extern void refuse(struct request_info *); /* clean up and exit */
extern char *xgets(char *, int, FILE *); /* fgets() on steroids */
int hosts_access(struct request_info *); /* access control */
int hosts_ctl(char *, char *, char *, char *); /* wrapper around request_init() */
void shell_cmd(char *); /* execute shell command */
char *percent_x(char *, int, char *, struct request_info *); /* do %<char> expansion */
void rfc931(TCPD_SOCKADDR *, TCPD_SOCKADDR *, char *); /* client name from RFC 931 daemon */
void clean_exit(struct request_info *); /* clean up and exit */
void refuse(struct request_info *); /* clean up and exit */
char *xgets(char *, int, FILE *); /* fgets() on steroids */
extern char *split_at(char *, int); /* strchr() and split */
extern unsigned long dot_quad_addr(char *); /* restricted inet_addr() */
char *split_at(char *, int); /* strchr() and split */
unsigned long dot_quad_addr(char *); /* restricted inet_addr() */
/* Global variables. */
@ -101,8 +101,8 @@ extern int resident; /* > 0 if resident process */
* attributes. Each attribute has its own key.
*/
extern struct request_info *request_init(struct request_info *,...); /* initialize request */
extern struct request_info *request_set(struct request_info *,...); /* update request structure */
struct request_info *request_init(struct request_info *,...); /* initialize request */
struct request_info *request_set(struct request_info *,...); /* update request structure */
#define RQ_FILE 1 /* file descriptor */
#define RQ_DAEMON 2 /* server process (argv[0]) */
@ -122,27 +122,27 @@ extern struct request_info *request_set(struct request_info *,...); /* update re
* host_info structures serve as caches for the lookup results.
*/
extern char *eval_user(struct request_info *); /* client user */
extern char *eval_hostname(struct host_info *); /* printable hostname */
extern char *eval_hostaddr(struct host_info *); /* printable host address */
extern char *eval_hostinfo(struct host_info *); /* host name or address */
extern char *eval_client(struct request_info *); /* whatever is available */
extern char *eval_server(struct request_info *); /* whatever is available */
char *eval_user(struct request_info *); /* client user */
char *eval_hostname(struct host_info *); /* printable hostname */
char *eval_hostaddr(struct host_info *); /* printable host address */
char *eval_hostinfo(struct host_info *); /* host name or address */
char *eval_client(struct request_info *); /* whatever is available */
char *eval_server(struct request_info *); /* whatever is available */
#define eval_daemon(r) ((r)->daemon) /* daemon process name */
#define eval_pid(r) ((r)->pid) /* process id */
/* Socket-specific methods, including DNS hostname lookups. */
extern void sock_host(struct request_info *); /* look up endpoint addresses */
extern void sock_hostname(struct host_info *); /* translate address to hostname */
extern void sock_hostaddr(struct host_info *); /* address to printable address */
void sock_host(struct request_info *); /* look up endpoint addresses */
void sock_hostname(struct host_info *); /* translate address to hostname */
void sock_hostaddr(struct host_info *); /* address to printable address */
#define sock_methods(r) \
{ (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; }
/* The System V Transport-Level Interface (TLI) interface. */
#if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT)
extern void tli_host(struct request_info *); /* look up endpoint addresses etc. */
void tli_host(struct request_info *); /* look up endpoint addresses etc. */
#endif
/*
@ -151,8 +151,8 @@ extern void tli_host(struct request_info *); /* look up endpoint addresses etc.
* everyone would have to include <setjmp.h>.
*/
extern void tcpd_warn(char *, ...); /* report problem and proceed */
extern void tcpd_jump(char *, ...); /* report problem and jump */
void tcpd_warn(char *, ...); /* report problem and proceed */
void tcpd_jump(char *, ...); /* report problem and jump */
struct tcpd_context {
char *file; /* current file */
@ -178,42 +178,42 @@ extern struct tcpd_context tcpd_context;
* behavior.
*/
extern void process_options(char *, struct request_info *); /* execute options */
extern int dry_run; /* verification flag */
void process_options(char *, struct request_info *); /* execute options */
extern int dry_run; /* verification flag */
/* Bug workarounds. */
#ifdef INET_ADDR_BUG /* inet_addr() returns struct */
#define inet_addr fix_inet_addr
extern long fix_inet_addr(char *);
long fix_inet_addr(char *);
#endif
#ifdef BROKEN_FGETS /* partial reads from sockets */
#define fgets fix_fgets
extern char *fix_fgets(char *, int, FILE *);
char *fix_fgets(char *, int, FILE *);
#endif
#ifdef RECVFROM_BUG /* no address family info */
#define recvfrom fix_recvfrom
extern int fix_recvfrom(int, char *, int, int, struct sockaddr *, int *);
int fix_recvfrom(int, char *, int, int, struct sockaddr *, int *);
#endif
#ifdef GETPEERNAME_BUG /* claims success with UDP */
#define getpeername fix_getpeername
extern int fix_getpeername(int, struct sockaddr *, int *);
int fix_getpeername(int, struct sockaddr *, int *);
#endif
#ifdef SOLARIS_24_GETHOSTBYNAME_BUG /* lists addresses as aliases */
#define gethostbyname fix_gethostbyname
extern struct hostent *fix_gethostbyname(char *);
struct hostent *fix_gethostbyname(char *);
#endif
#ifdef USE_STRSEP /* libc calls strtok() */
#define strtok fix_strtok
extern char *fix_strtok(char *, char *);
char *fix_strtok(char *, char *);
#endif
#ifdef LIBC_CALLS_STRTOK /* libc calls strtok() */
#define strtok my_strtok
extern char *my_strtok(char *, char *);
char *my_strtok(char *, char *);
#endif

File diff suppressed because it is too large Load diff

View file

@ -64,6 +64,7 @@ has been important. :-) In alphabetical order:
- Conley Moorhous
- Rafał Mużyło
- Adrien Nader
- Evan Nemerson
- Hongbo Ni
- Jonathan Nieder
- Andre Noll
@ -74,6 +75,7 @@ has been important. :-) In alphabetical order:
- Diego Elio Pettenò
- Elbert Pol
- Mikko Pouru
- Rich Prohaska
- Trần Ngọc Quân
- Pavel Raiskup
- Ole André Vadla Ravnås
@ -89,6 +91,7 @@ has been important. :-) In alphabetical order:
- Andreas Schwab
- Dan Shechter
- Stuart Shelton
- Sebastian Andrzej Siewior
- Brad Smith
- Jonathan Stott
- Dan Stromberg
@ -102,6 +105,7 @@ has been important. :-) In alphabetical order:
- Christian Weisgerber
- Bert Wesarg
- Fredrik Wikstrom
- Jim Wilcoxson
- Ralf Wildenhues
- Charles Wilson
- Lars Wirzenius

View file

@ -18,6 +18,10 @@
# endif
# include <windows.h>
// glibc >= 2.9
#elif defined(TUKLIB_CPUCORES_SCHED_GETAFFINITY)
# include <sched.h>
// FreeBSD
#elif defined(TUKLIB_CPUCORES_CPUSET)
# include <sys/param.h>
@ -49,6 +53,11 @@ tuklib_cpucores(void)
GetSystemInfo(&sysinfo);
ret = sysinfo.dwNumberOfProcessors;
#elif defined(TUKLIB_CPUCORES_SCHED_GETAFFINITY)
cpu_set_t cpu_mask;
if (sched_getaffinity(0, sizeof(cpu_mask), &cpu_mask) == 0)
ret = CPU_COUNT(&cpu_mask);
#elif defined(TUKLIB_CPUCORES_CPUSET)
cpuset_t set;
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1,

View file

@ -86,7 +86,8 @@ tuklib_physmem(void)
// GlobalMemoryStatusEx() conditionally.
HMODULE kernel32 = GetModuleHandle("kernel32.dll");
if (kernel32 != NULL) {
BOOL (WINAPI *gmse)(LPMEMORYSTATUSEX) = GetProcAddress(
typedef BOOL (WINAPI *gmse_type)(LPMEMORYSTATUSEX);
gmse_type gmse = (gmse_type)GetProcAddress(
kernel32, "GlobalMemoryStatusEx");
if (gmse != NULL) {
MEMORYSTATUSEX meminfo;

View file

@ -22,7 +22,7 @@
*/
#define LZMA_VERSION_MAJOR 5
#define LZMA_VERSION_MINOR 2
#define LZMA_VERSION_PATCH 2
#define LZMA_VERSION_PATCH 3
#define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE
#ifndef LZMA_VERSION_COMMIT

View file

@ -15,7 +15,18 @@
#include "common.h"
#if defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
// If the function for external SHA-256 is missing, use the internal SHA-256
// code. Due to how configure works, these defines can only get defined when
// both a usable header and a type have already been found.
#if !(defined(HAVE_CC_SHA256_INIT) \
|| defined(HAVE_SHA256_INIT) \
|| defined(HAVE_SHA256INIT))
# define HAVE_INTERNAL_SHA256 1
#endif
#if defined(HAVE_INTERNAL_SHA256)
// Nothing
#elif defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
# include <CommonCrypto/CommonDigest.h>
#elif defined(HAVE_SHA256_H)
# include <sys/types.h>
@ -23,18 +34,9 @@
#elif defined(HAVE_SHA2_H)
# include <sys/types.h>
# include <sha2.h>
#elif defined(HAVE_MINIX_SHA2_H)
# include <sys/types.h>
# include <minix/sha2.h>
#endif
#if defined(HAVE_CC_SHA256_CTX)
typedef CC_SHA256_CTX lzma_sha256_state;
#elif defined(HAVE_SHA256_CTX)
typedef SHA256_CTX lzma_sha256_state;
#elif defined(HAVE_SHA2_CTX)
typedef SHA2_CTX lzma_sha256_state;
#else
#if defined(HAVE_INTERNAL_SHA256)
/// State for the internal SHA-256 implementation
typedef struct {
/// Internal state
@ -43,9 +45,17 @@ typedef struct {
/// Size of the message excluding padding
uint64_t size;
} lzma_sha256_state;
#elif defined(HAVE_CC_SHA256_CTX)
typedef CC_SHA256_CTX lzma_sha256_state;
#elif defined(HAVE_SHA256_CTX)
typedef SHA256_CTX lzma_sha256_state;
#elif defined(HAVE_SHA2_CTX)
typedef SHA2_CTX lzma_sha256_state;
#endif
#if defined(HAVE_CC_SHA256_INIT)
#if defined(HAVE_INTERNAL_SHA256)
// Nothing
#elif defined(HAVE_CC_SHA256_INIT)
# define LZMA_SHA256FUNC(x) CC_SHA256_ ## x
#elif defined(HAVE_SHA256_INIT)
# define LZMA_SHA256FUNC(x) SHA256_ ## x

View file

@ -15,7 +15,7 @@
#include "lz_decoder.h"
struct lzma_coder_s {
typedef struct {
lzma_next_coder next;
enum {
@ -46,17 +46,19 @@ struct lzma_coder_s {
/// Options decoded from the header needed to initialize
/// the LZMA decoder
lzma_options_lzma options;
};
} lzma_alone_coder;
static lzma_ret
alone_decode(lzma_coder *coder,
alone_decode(void *coder_ptr,
const lzma_allocator *allocator lzma_attribute((__unused__)),
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
lzma_action action)
{
lzma_alone_coder *coder = coder_ptr;
while (*out_pos < out_size
&& (coder->sequence == SEQ_CODE || *in_pos < in_size))
switch (coder->sequence) {
@ -166,8 +168,9 @@ alone_decode(lzma_coder *coder,
static void
alone_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
alone_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_alone_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@ -175,9 +178,11 @@ alone_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
alone_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
alone_decoder_memconfig(void *coder_ptr, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit)
{
lzma_alone_coder *coder = coder_ptr;
*memusage = coder->memusage;
*old_memlimit = coder->memlimit;
@ -201,26 +206,29 @@ lzma_alone_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
if (memlimit == 0)
return LZMA_PROG_ERROR;
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_alone_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_alone_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &alone_decode;
next->end = &alone_decoder_end;
next->memconfig = &alone_decoder_memconfig;
next->coder->next = LZMA_NEXT_CODER_INIT;
coder->next = LZMA_NEXT_CODER_INIT;
}
next->coder->sequence = SEQ_PROPERTIES;
next->coder->picky = picky;
next->coder->pos = 0;
next->coder->options.dict_size = 0;
next->coder->options.preset_dict = NULL;
next->coder->options.preset_dict_size = 0;
next->coder->uncompressed_size = 0;
next->coder->memlimit = memlimit;
next->coder->memusage = LZMA_MEMUSAGE_BASE;
coder->sequence = SEQ_PROPERTIES;
coder->picky = picky;
coder->pos = 0;
coder->options.dict_size = 0;
coder->options.preset_dict = NULL;
coder->options.preset_dict_size = 0;
coder->uncompressed_size = 0;
coder->memlimit = memlimit;
coder->memusage = LZMA_MEMUSAGE_BASE;
return LZMA_OK;
}

View file

@ -17,7 +17,7 @@
#define ALONE_HEADER_SIZE (1 + 4 + 8)
struct lzma_coder_s {
typedef struct {
lzma_next_coder next;
enum {
@ -27,17 +27,19 @@ struct lzma_coder_s {
size_t header_pos;
uint8_t header[ALONE_HEADER_SIZE];
};
} lzma_alone_coder;
static lzma_ret
alone_encode(lzma_coder *coder,
alone_encode(void *coder_ptr,
const lzma_allocator *allocator lzma_attribute((__unused__)),
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
lzma_action action)
{
lzma_alone_coder *coder = coder_ptr;
while (*out_pos < out_size)
switch (coder->sequence) {
case SEQ_HEADER:
@ -65,8 +67,9 @@ alone_encode(lzma_coder *coder,
static void
alone_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
alone_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_alone_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@ -80,23 +83,26 @@ alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
{
lzma_next_coder_init(&alone_encoder_init, next, allocator);
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_alone_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_alone_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &alone_encode;
next->end = &alone_encoder_end;
next->coder->next = LZMA_NEXT_CODER_INIT;
coder->next = LZMA_NEXT_CODER_INIT;
}
// Basic initializations
next->coder->sequence = SEQ_HEADER;
next->coder->header_pos = 0;
coder->sequence = SEQ_HEADER;
coder->header_pos = 0;
// Encode the header:
// - Properties (1 byte)
if (lzma_lzma_lclppb_encode(options, next->coder->header))
if (lzma_lzma_lclppb_encode(options, coder->header))
return LZMA_OPTIONS_ERROR;
// - Dictionary size (4 bytes)
@ -116,10 +122,10 @@ alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
if (d != UINT32_MAX)
++d;
unaligned_write32le(next->coder->header + 1, d);
unaligned_write32le(coder->header + 1, d);
// - Uncompressed size (always unknown and using EOPM)
memset(next->coder->header + 1 + 4, 0xFF, 8);
memset(coder->header + 1 + 4, 0xFF, 8);
// Initialize the LZMA encoder.
const lzma_filter_info filters[2] = {
@ -131,7 +137,7 @@ alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
}
};
return lzma_next_filter_init(&next->coder->next, allocator, filters);
return lzma_next_filter_init(&coder->next, allocator, filters);
}

View file

@ -14,7 +14,7 @@
#include "alone_decoder.h"
struct lzma_coder_s {
typedef struct {
/// Stream decoder or LZMA_Alone decoder
lzma_next_coder next;
@ -26,15 +26,17 @@ struct lzma_coder_s {
SEQ_CODE,
SEQ_FINISH,
} sequence;
};
} lzma_auto_coder;
static lzma_ret
auto_decode(lzma_coder *coder, const lzma_allocator *allocator,
auto_decode(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
lzma_auto_coder *coder = coder_ptr;
switch (coder->sequence) {
case SEQ_INIT:
if (*in_pos >= in_size)
@ -100,8 +102,9 @@ auto_decode(lzma_coder *coder, const lzma_allocator *allocator,
static void
auto_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
auto_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_auto_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@ -109,8 +112,10 @@ auto_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_check
auto_decoder_get_check(const lzma_coder *coder)
auto_decoder_get_check(const void *coder_ptr)
{
const lzma_auto_coder *coder = coder_ptr;
// It is LZMA_Alone if get_check is NULL.
return coder->next.get_check == NULL ? LZMA_CHECK_NONE
: coder->next.get_check(coder->next.coder);
@ -118,9 +123,11 @@ auto_decoder_get_check(const lzma_coder *coder)
static lzma_ret
auto_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
auto_decoder_memconfig(void *coder_ptr, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit)
{
lzma_auto_coder *coder = coder_ptr;
lzma_ret ret;
if (coder->next.memconfig != NULL) {
@ -154,21 +161,23 @@ auto_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
if (flags & ~LZMA_SUPPORTED_FLAGS)
return LZMA_OPTIONS_ERROR;
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_auto_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_auto_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &auto_decode;
next->end = &auto_decoder_end;
next->get_check = &auto_decoder_get_check;
next->memconfig = &auto_decoder_memconfig;
next->coder->next = LZMA_NEXT_CODER_INIT;
coder->next = LZMA_NEXT_CODER_INIT;
}
next->coder->memlimit = memlimit;
next->coder->flags = flags;
next->coder->sequence = SEQ_INIT;
coder->memlimit = memlimit;
coder->flags = flags;
coder->sequence = SEQ_INIT;
return LZMA_OK;
}

View file

@ -15,7 +15,7 @@
#include "check.h"
struct lzma_coder_s {
typedef struct {
enum {
SEQ_CODE,
SEQ_PADDING,
@ -48,7 +48,7 @@ struct lzma_coder_s {
/// True if the integrity check won't be calculated and verified.
bool ignore_check;
};
} lzma_block_coder;
static inline bool
@ -74,11 +74,13 @@ is_size_valid(lzma_vli size, lzma_vli reference)
static lzma_ret
block_decode(lzma_coder *coder, const lzma_allocator *allocator,
block_decode(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
lzma_block_coder *coder = coder_ptr;
switch (coder->sequence) {
case SEQ_CODE: {
const size_t in_start = *in_pos;
@ -177,8 +179,9 @@ block_decode(lzma_coder *coder, const lzma_allocator *allocator,
static void
block_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
block_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_block_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@ -198,27 +201,29 @@ lzma_block_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|| !lzma_vli_is_valid(block->uncompressed_size))
return LZMA_PROG_ERROR;
// Allocate and initialize *next->coder if needed.
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
// Allocate *next->coder if needed.
lzma_block_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_block_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &block_decode;
next->end = &block_decoder_end;
next->coder->next = LZMA_NEXT_CODER_INIT;
coder->next = LZMA_NEXT_CODER_INIT;
}
// Basic initializations
next->coder->sequence = SEQ_CODE;
next->coder->block = block;
next->coder->compressed_size = 0;
next->coder->uncompressed_size = 0;
coder->sequence = SEQ_CODE;
coder->block = block;
coder->compressed_size = 0;
coder->uncompressed_size = 0;
// If Compressed Size is not known, we calculate the maximum allowed
// value so that encoded size of the Block (including Block Padding)
// is still a valid VLI and a multiple of four.
next->coder->compressed_limit
coder->compressed_limit
= block->compressed_size == LZMA_VLI_UNKNOWN
? (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
- block->header_size
@ -228,14 +233,14 @@ lzma_block_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
// Initialize the check. It's caller's problem if the Check ID is not
// supported, and the Block decoder cannot verify the Check field.
// Caller can test lzma_check_is_supported(block->check).
next->coder->check_pos = 0;
lzma_check_init(&next->coder->check, block->check);
coder->check_pos = 0;
lzma_check_init(&coder->check, block->check);
next->coder->ignore_check = block->version >= 1
coder->ignore_check = block->version >= 1
? block->ignore_check : false;
// Initialize the filter chain.
return lzma_raw_decoder_init(&next->coder->next, allocator,
return lzma_raw_decoder_init(&coder->next, allocator,
block->filters);
}

View file

@ -15,7 +15,7 @@
#include "check.h"
struct lzma_coder_s {
typedef struct {
/// The filters in the chain; initialized with lzma_raw_decoder_init().
lzma_next_coder next;
@ -41,15 +41,17 @@ struct lzma_coder_s {
/// Check of the uncompressed data
lzma_check_state check;
};
} lzma_block_coder;
static lzma_ret
block_encode(lzma_coder *coder, const lzma_allocator *allocator,
block_encode(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
lzma_block_coder *coder = coder_ptr;
// Check that our amount of input stays in proper limits.
if (LZMA_VLI_MAX - coder->uncompressed_size < in_size - *in_pos)
return LZMA_DATA_ERROR;
@ -134,8 +136,9 @@ block_encode(lzma_coder *coder, const lzma_allocator *allocator,
static void
block_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
block_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_block_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@ -143,10 +146,12 @@ block_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
block_encoder_update(lzma_coder *coder, const lzma_allocator *allocator,
block_encoder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters lzma_attribute((__unused__)),
const lzma_filter *reversed_filters)
{
lzma_block_coder *coder = coder_ptr;
if (coder->sequence != SEQ_CODE)
return LZMA_PROG_ERROR;
@ -178,30 +183,31 @@ lzma_block_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
return LZMA_UNSUPPORTED_CHECK;
// Allocate and initialize *next->coder if needed.
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_block_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_block_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &block_encode;
next->end = &block_encoder_end;
next->update = &block_encoder_update;
next->coder->next = LZMA_NEXT_CODER_INIT;
coder->next = LZMA_NEXT_CODER_INIT;
}
// Basic initializations
next->coder->sequence = SEQ_CODE;
next->coder->block = block;
next->coder->compressed_size = 0;
next->coder->uncompressed_size = 0;
next->coder->pos = 0;
coder->sequence = SEQ_CODE;
coder->block = block;
coder->compressed_size = 0;
coder->uncompressed_size = 0;
coder->pos = 0;
// Initialize the check
lzma_check_init(&next->coder->check, block->check);
lzma_check_init(&coder->check, block->check);
// Initialize the requested filters.
return lzma_raw_encoder_init(&next->coder->next, allocator,
block->filters);
return lzma_raw_encoder_init(&coder->next, allocator, block->filters);
}

View file

@ -88,10 +88,6 @@
#define LZMA_TIMED_OUT 32
/// Type of encoder/decoder specific data; the actual structure is defined
/// differently in different coders.
typedef struct lzma_coder_s lzma_coder;
typedef struct lzma_next_coder_s lzma_next_coder;
typedef struct lzma_filter_info_s lzma_filter_info;
@ -107,7 +103,7 @@ typedef lzma_ret (*lzma_init_function)(
/// input and output buffers, but for simplicity they still use this same
/// function prototype.
typedef lzma_ret (*lzma_code_function)(
lzma_coder *coder, const lzma_allocator *allocator,
void *coder, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
@ -115,7 +111,7 @@ typedef lzma_ret (*lzma_code_function)(
/// Type of a function to free the memory allocated for the coder
typedef void (*lzma_end_function)(
lzma_coder *coder, const lzma_allocator *allocator);
void *coder, const lzma_allocator *allocator);
/// Raw coder validates and converts an array of lzma_filter structures to
@ -138,7 +134,7 @@ struct lzma_filter_info_s {
/// Hold data and function pointers of the next filter in the chain.
struct lzma_next_coder_s {
/// Pointer to coder-specific data
lzma_coder *coder;
void *coder;
/// Filter ID. This is LZMA_VLI_UNKNOWN when this structure doesn't
/// point to a filter coder.
@ -160,21 +156,21 @@ struct lzma_next_coder_s {
/// Pointer to a function to get progress information. If this is NULL,
/// lzma_stream.total_in and .total_out are used instead.
void (*get_progress)(lzma_coder *coder,
void (*get_progress)(void *coder,
uint64_t *progress_in, uint64_t *progress_out);
/// Pointer to function to return the type of the integrity check.
/// Most coders won't support this.
lzma_check (*get_check)(const lzma_coder *coder);
lzma_check (*get_check)(const void *coder);
/// Pointer to function to get and/or change the memory usage limit.
/// If new_memlimit == 0, the limit is not changed.
lzma_ret (*memconfig)(lzma_coder *coder, uint64_t *memusage,
lzma_ret (*memconfig)(void *coder, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit);
/// Update the filter-specific options or the whole filter chain
/// in the encoder.
lzma_ret (*update)(lzma_coder *coder, const lzma_allocator *allocator,
lzma_ret (*update)(void *coder, const lzma_allocator *allocator,
const lzma_filter *filters,
const lzma_filter *reversed_filters);
};

View file

@ -202,22 +202,21 @@ index_tree_node_end(index_tree_node *node, const lzma_allocator *allocator,
if (node->right != NULL)
index_tree_node_end(node->right, allocator, free_func);
if (free_func != NULL)
free_func(node, allocator);
lzma_free(node, allocator);
free_func(node, allocator);
return;
}
/// Free the meory allocated for a tree. If free_func is not NULL,
/// it is called on each node before freeing the node. This is used
/// to free the Record groups from each index_stream before freeing
/// the index_stream itself.
/// Free the memory allocated for a tree. Each node is freed using the
/// given free_func which is either &lzma_free or &index_stream_end.
/// The latter is used to free the Record groups from each index_stream
/// before freeing the index_stream itself.
static void
index_tree_end(index_tree *tree, const lzma_allocator *allocator,
void (*free_func)(void *node, const lzma_allocator *allocator))
{
assert(free_func != NULL);
if (tree->root != NULL)
index_tree_node_end(tree->root, allocator, free_func);
@ -371,7 +370,8 @@ static void
index_stream_end(void *node, const lzma_allocator *allocator)
{
index_stream *s = node;
index_tree_end(&s->groups, allocator, NULL);
index_tree_end(&s->groups, allocator, &lzma_free);
lzma_free(s, allocator);
return;
}
@ -829,6 +829,9 @@ lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src,
s->groups.rightmost = &newg->node;
lzma_free(g, allocator);
// NOTE: newg isn't leaked here because
// newg == (void *)&newg->node.
}
}
@ -869,11 +872,8 @@ index_dup_stream(const index_stream *src, const lzma_allocator *allocator)
index_stream *dest = index_stream_init(src->node.compressed_base,
src->node.uncompressed_base, src->number,
src->block_number_base, allocator);
// Return immediately if allocation failed or if there are
// no groups to duplicate.
if (dest == NULL || src->groups.leftmost == NULL)
return dest;
if (dest == NULL)
return NULL;
// Copy the overall information.
dest->record_count = src->record_count;
@ -881,6 +881,10 @@ index_dup_stream(const index_stream *src, const lzma_allocator *allocator)
dest->stream_flags = src->stream_flags;
dest->stream_padding = src->stream_padding;
// Return if there are no groups to duplicate.
if (src->groups.leftmost == NULL)
return dest;
// Allocate memory for the Records. We put all the Records into
// a single group. It's simplest and also tends to make
// lzma_index_locate() a little bit faster with very big Indexes.

View file

@ -14,7 +14,7 @@
#include "check.h"
struct lzma_coder_s {
typedef struct {
enum {
SEQ_INDICATOR,
SEQ_COUNT,
@ -50,11 +50,11 @@ struct lzma_coder_s {
/// CRC32 of the List of Records field
uint32_t crc32;
};
} lzma_index_coder;
static lzma_ret
index_decode(lzma_coder *coder, const lzma_allocator *allocator,
index_decode(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size,
uint8_t *restrict out lzma_attribute((__unused__)),
@ -62,6 +62,8 @@ index_decode(lzma_coder *coder, const lzma_allocator *allocator,
size_t out_size lzma_attribute((__unused__)),
lzma_action action lzma_attribute((__unused__)))
{
lzma_index_coder *coder = coder_ptr;
// Similar optimization as in index_encoder.c
const size_t in_start = *in_pos;
lzma_ret ret = LZMA_OK;
@ -207,8 +209,9 @@ index_decode(lzma_coder *coder, const lzma_allocator *allocator,
static void
index_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
index_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_index_coder *coder = coder_ptr;
lzma_index_end(coder->index, allocator);
lzma_free(coder, allocator);
return;
@ -216,9 +219,11 @@ index_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
index_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
index_decoder_memconfig(void *coder_ptr, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit)
{
lzma_index_coder *coder = coder_ptr;
*memusage = lzma_index_memusage(1, coder->count);
*old_memlimit = coder->memlimit;
@ -234,7 +239,7 @@ index_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
static lzma_ret
index_decoder_reset(lzma_coder *coder, const lzma_allocator *allocator,
index_decoder_reset(lzma_index_coder *coder, const lzma_allocator *allocator,
lzma_index **i, uint64_t memlimit)
{
// Remember the pointer given by the application. We will set it
@ -269,20 +274,22 @@ index_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
if (i == NULL || memlimit == 0)
return LZMA_PROG_ERROR;
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_index_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_index_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &index_decode;
next->end = &index_decoder_end;
next->memconfig = &index_decoder_memconfig;
next->coder->index = NULL;
coder->index = NULL;
} else {
lzma_index_end(next->coder->index, allocator);
lzma_index_end(coder->index, allocator);
}
return index_decoder_reset(next->coder, allocator, i, memlimit);
return index_decoder_reset(coder, allocator, i, memlimit);
}
@ -309,7 +316,7 @@ lzma_index_buffer_decode(lzma_index **i, uint64_t *memlimit,
return LZMA_PROG_ERROR;
// Initialize the decoder.
lzma_coder coder;
lzma_index_coder coder;
return_if_error(index_decoder_reset(&coder, allocator, i, *memlimit));
// Store the input start position so that we can restore it in case

View file

@ -15,7 +15,7 @@
#include "check.h"
struct lzma_coder_s {
typedef struct {
enum {
SEQ_INDICATOR,
SEQ_COUNT,
@ -37,11 +37,11 @@ struct lzma_coder_s {
/// CRC32 of the List of Records field
uint32_t crc32;
};
} lzma_index_coder;
static lzma_ret
index_encode(lzma_coder *coder,
index_encode(void *coder_ptr,
const lzma_allocator *allocator lzma_attribute((__unused__)),
const uint8_t *restrict in lzma_attribute((__unused__)),
size_t *restrict in_pos lzma_attribute((__unused__)),
@ -50,6 +50,8 @@ index_encode(lzma_coder *coder,
size_t out_size,
lzma_action action lzma_attribute((__unused__)))
{
lzma_index_coder *coder = coder_ptr;
// Position where to start calculating CRC32. The idea is that we
// need to call lzma_crc32() only once per call to index_encode().
const size_t out_start = *out_pos;
@ -159,7 +161,7 @@ index_encode(lzma_coder *coder,
static void
index_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
index_encoder_end(void *coder, const lzma_allocator *allocator)
{
lzma_free(coder, allocator);
return;
@ -167,7 +169,7 @@ index_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
static void
index_encoder_reset(lzma_coder *coder, const lzma_index *i)
index_encoder_reset(lzma_index_coder *coder, const lzma_index *i)
{
lzma_index_iter_init(&coder->iter, i);
@ -190,7 +192,7 @@ lzma_index_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
return LZMA_PROG_ERROR;
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
next->coder = lzma_alloc(sizeof(lzma_index_coder), allocator);
if (next->coder == NULL)
return LZMA_MEM_ERROR;
@ -230,7 +232,7 @@ lzma_index_buffer_encode(const lzma_index *i,
// The Index encoder needs just one small data structure so we can
// allocate it on stack.
lzma_coder coder;
lzma_index_coder coder;
index_encoder_reset(&coder, i);
// Do the actual encoding. This should never fail, but store

View file

@ -14,7 +14,7 @@
#include "block_decoder.h"
struct lzma_coder_s {
typedef struct {
enum {
SEQ_STREAM_HEADER,
SEQ_BLOCK_HEADER,
@ -80,11 +80,11 @@ struct lzma_coder_s {
/// Buffer to hold Stream Header, Block Header, and Stream Footer.
/// Block Header has biggest maximum size.
uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX];
};
} lzma_stream_coder;
static lzma_ret
stream_decoder_reset(lzma_coder *coder, const lzma_allocator *allocator)
stream_decoder_reset(lzma_stream_coder *coder, const lzma_allocator *allocator)
{
// Initialize the Index hash used to verify the Index.
coder->index_hash = lzma_index_hash_init(coder->index_hash, allocator);
@ -100,11 +100,13 @@ stream_decoder_reset(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
stream_decode(lzma_coder *coder, const lzma_allocator *allocator,
stream_decode(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
lzma_stream_coder *coder = coder_ptr;
// When decoding the actual Block, it may be able to produce more
// output even if we don't give it any new input.
while (true)
@ -375,8 +377,9 @@ stream_decode(lzma_coder *coder, const lzma_allocator *allocator,
static void
stream_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
stream_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_stream_coder *coder = coder_ptr;
lzma_next_end(&coder->block_decoder, allocator);
lzma_index_hash_end(coder->index_hash, allocator);
lzma_free(coder, allocator);
@ -385,16 +388,19 @@ stream_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_check
stream_decoder_get_check(const lzma_coder *coder)
stream_decoder_get_check(const void *coder_ptr)
{
const lzma_stream_coder *coder = coder_ptr;
return coder->stream_flags.check;
}
static lzma_ret
stream_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
stream_decoder_memconfig(void *coder_ptr, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit)
{
lzma_stream_coder *coder = coder_ptr;
*memusage = coder->memusage;
*old_memlimit = coder->memlimit;
@ -422,31 +428,33 @@ lzma_stream_decoder_init(
if (flags & ~LZMA_SUPPORTED_FLAGS)
return LZMA_OPTIONS_ERROR;
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_stream_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_stream_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &stream_decode;
next->end = &stream_decoder_end;
next->get_check = &stream_decoder_get_check;
next->memconfig = &stream_decoder_memconfig;
next->coder->block_decoder = LZMA_NEXT_CODER_INIT;
next->coder->index_hash = NULL;
coder->block_decoder = LZMA_NEXT_CODER_INIT;
coder->index_hash = NULL;
}
next->coder->memlimit = memlimit;
next->coder->memusage = LZMA_MEMUSAGE_BASE;
next->coder->tell_no_check = (flags & LZMA_TELL_NO_CHECK) != 0;
next->coder->tell_unsupported_check
coder->memlimit = memlimit;
coder->memusage = LZMA_MEMUSAGE_BASE;
coder->tell_no_check = (flags & LZMA_TELL_NO_CHECK) != 0;
coder->tell_unsupported_check
= (flags & LZMA_TELL_UNSUPPORTED_CHECK) != 0;
next->coder->tell_any_check = (flags & LZMA_TELL_ANY_CHECK) != 0;
next->coder->ignore_check = (flags & LZMA_IGNORE_CHECK) != 0;
next->coder->concatenated = (flags & LZMA_CONCATENATED) != 0;
next->coder->first_stream = true;
coder->tell_any_check = (flags & LZMA_TELL_ANY_CHECK) != 0;
coder->ignore_check = (flags & LZMA_IGNORE_CHECK) != 0;
coder->concatenated = (flags & LZMA_CONCATENATED) != 0;
coder->first_stream = true;
return stream_decoder_reset(next->coder, allocator);
return stream_decoder_reset(coder, allocator);
}

View file

@ -14,7 +14,7 @@
#include "index_encoder.h"
struct lzma_coder_s {
typedef struct {
enum {
SEQ_STREAM_HEADER,
SEQ_BLOCK_INIT,
@ -55,11 +55,11 @@ struct lzma_coder_s {
/// Buffer to hold Stream Header, Block Header, and Stream Footer.
/// Block Header has biggest maximum size.
uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX];
};
} lzma_stream_coder;
static lzma_ret
block_encoder_init(lzma_coder *coder, const lzma_allocator *allocator)
block_encoder_init(lzma_stream_coder *coder, const lzma_allocator *allocator)
{
// Prepare the Block options. Even though Block encoder doesn't need
// compressed_size, uncompressed_size, and header_size to be
@ -78,11 +78,13 @@ block_encoder_init(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
stream_encode(lzma_coder *coder, const lzma_allocator *allocator,
stream_encode(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
lzma_stream_coder *coder = coder_ptr;
// Main loop
while (*out_pos < out_size)
switch (coder->sequence) {
@ -209,8 +211,10 @@ stream_encode(lzma_coder *coder, const lzma_allocator *allocator,
static void
stream_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
stream_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_stream_coder *coder = coder_ptr;
lzma_next_end(&coder->block_encoder, allocator);
lzma_next_end(&coder->index_encoder, allocator);
lzma_index_end(coder->index, allocator);
@ -224,10 +228,12 @@ stream_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
stream_encoder_update(lzma_coder *coder, const lzma_allocator *allocator,
stream_encoder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters,
const lzma_filter *reversed_filters)
{
lzma_stream_coder *coder = coder_ptr;
if (coder->sequence <= SEQ_BLOCK_INIT) {
// There is no incomplete Block waiting to be finished,
// thus we can change the whole filter chain. Start by
@ -271,30 +277,33 @@ stream_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
if (filters == NULL)
return LZMA_PROG_ERROR;
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_stream_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_stream_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &stream_encode;
next->end = &stream_encoder_end;
next->update = &stream_encoder_update;
next->coder->filters[0].id = LZMA_VLI_UNKNOWN;
next->coder->block_encoder = LZMA_NEXT_CODER_INIT;
next->coder->index_encoder = LZMA_NEXT_CODER_INIT;
next->coder->index = NULL;
coder->filters[0].id = LZMA_VLI_UNKNOWN;
coder->block_encoder = LZMA_NEXT_CODER_INIT;
coder->index_encoder = LZMA_NEXT_CODER_INIT;
coder->index = NULL;
}
// Basic initializations
next->coder->sequence = SEQ_STREAM_HEADER;
next->coder->block_options.version = 0;
next->coder->block_options.check = check;
coder->sequence = SEQ_STREAM_HEADER;
coder->block_options.version = 0;
coder->block_options.check = check;
// Initialize the Index
lzma_index_end(next->coder->index, allocator);
next->coder->index = lzma_index_init(allocator);
if (next->coder->index == NULL)
lzma_index_end(coder->index, allocator);
coder->index = lzma_index_init(allocator);
if (coder->index == NULL)
return LZMA_MEM_ERROR;
// Encode the Stream Header
@ -303,16 +312,15 @@ stream_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
.check = check,
};
return_if_error(lzma_stream_header_encode(
&stream_flags, next->coder->buffer));
&stream_flags, coder->buffer));
next->coder->buffer_pos = 0;
next->coder->buffer_size = LZMA_STREAM_HEADER_SIZE;
coder->buffer_pos = 0;
coder->buffer_size = LZMA_STREAM_HEADER_SIZE;
// Initialize the Block encoder. This way we detect unsupported
// filter chains when initializing the Stream encoder instead of
// giving an error after Stream Header has already written out.
return stream_encoder_update(
next->coder, allocator, filters, NULL);
return stream_encoder_update(coder, allocator, filters, NULL);
}

View file

@ -44,6 +44,7 @@ typedef enum {
} worker_state;
typedef struct lzma_stream_coder_s lzma_stream_coder;
typedef struct worker_thread_s worker_thread;
struct worker_thread_s {
@ -65,7 +66,7 @@ struct worker_thread_s {
/// Pointer to the main structure is needed when putting this
/// thread back to the stack of free threads.
lzma_coder *coder;
lzma_stream_coder *coder;
/// The allocator is set by the main thread. Since a copy of the
/// pointer is kept here, the application must not change the
@ -96,7 +97,7 @@ struct worker_thread_s {
};
struct lzma_coder_s {
struct lzma_stream_coder_s {
enum {
SEQ_STREAM_HEADER,
SEQ_BLOCK,
@ -417,7 +418,7 @@ worker_start(void *thr_ptr)
/// Make the threads stop but not exit. Optionally wait for them to stop.
static void
threads_stop(lzma_coder *coder, bool wait_for_threads)
threads_stop(lzma_stream_coder *coder, bool wait_for_threads)
{
// Tell the threads to stop.
for (uint32_t i = 0; i < coder->threads_initialized; ++i) {
@ -446,7 +447,7 @@ threads_stop(lzma_coder *coder, bool wait_for_threads)
/// Stop the threads and free the resources associated with them.
/// Wait until the threads have exited.
static void
threads_end(lzma_coder *coder, const lzma_allocator *allocator)
threads_end(lzma_stream_coder *coder, const lzma_allocator *allocator)
{
for (uint32_t i = 0; i < coder->threads_initialized; ++i) {
mythread_sync(coder->threads[i].mutex) {
@ -468,7 +469,8 @@ threads_end(lzma_coder *coder, const lzma_allocator *allocator)
/// Initialize a new worker_thread structure and create a new thread.
static lzma_ret
initialize_new_thread(lzma_coder *coder, const lzma_allocator *allocator)
initialize_new_thread(lzma_stream_coder *coder,
const lzma_allocator *allocator)
{
worker_thread *thr = &coder->threads[coder->threads_initialized];
@ -510,7 +512,7 @@ initialize_new_thread(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
get_thread(lzma_coder *coder, const lzma_allocator *allocator)
get_thread(lzma_stream_coder *coder, const lzma_allocator *allocator)
{
// If there are no free output subqueues, there is no
// point to try getting a thread.
@ -548,7 +550,7 @@ get_thread(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
stream_encode_in(lzma_coder *coder, const lzma_allocator *allocator,
stream_encode_in(lzma_stream_coder *coder, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, lzma_action action)
{
@ -616,7 +618,7 @@ stream_encode_in(lzma_coder *coder, const lzma_allocator *allocator,
/// Wait until more input can be consumed, more output can be read, or
/// an optional timeout is reached.
static bool
wait_for_work(lzma_coder *coder, mythread_condtime *wait_abs,
wait_for_work(lzma_stream_coder *coder, mythread_condtime *wait_abs,
bool *has_blocked, bool has_input)
{
if (coder->timeout != 0 && !*has_blocked) {
@ -662,11 +664,13 @@ wait_for_work(lzma_coder *coder, mythread_condtime *wait_abs,
static lzma_ret
stream_encode_mt(lzma_coder *coder, const lzma_allocator *allocator,
stream_encode_mt(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
lzma_stream_coder *coder = coder_ptr;
switch (coder->sequence) {
case SEQ_STREAM_HEADER:
lzma_bufcpy(coder->header, &coder->header_pos,
@ -834,8 +838,10 @@ stream_encode_mt(lzma_coder *coder, const lzma_allocator *allocator,
static void
stream_encoder_mt_end(lzma_coder *coder, const lzma_allocator *allocator)
stream_encoder_mt_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_stream_coder *coder = coder_ptr;
// Threads must be killed before the output queue can be freed.
threads_end(coder, allocator);
lzma_outq_end(&coder->outq, allocator);
@ -907,10 +913,12 @@ get_options(const lzma_mt *options, lzma_options_easy *opt_easy,
static void
get_progress(lzma_coder *coder, uint64_t *progress_in, uint64_t *progress_out)
get_progress(void *coder_ptr, uint64_t *progress_in, uint64_t *progress_out)
{
lzma_stream_coder *coder = coder_ptr;
// Lock coder->mutex to prevent finishing threads from moving their
// progress info from the worker_thread structure to lzma_coder.
// progress info from the worker_thread structure to lzma_stream_coder.
mythread_sync(coder->mutex) {
*progress_in = coder->progress_in;
*progress_out = coder->progress_out;
@ -962,24 +970,27 @@ stream_encoder_mt_init(lzma_next_coder *next, const lzma_allocator *allocator,
return LZMA_UNSUPPORTED_CHECK;
// Allocate and initialize the base structure if needed.
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_stream_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_stream_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
// For the mutex and condition variable initializations
// the error handling has to be done here because
// stream_encoder_mt_end() doesn't know if they have
// already been initialized or not.
if (mythread_mutex_init(&next->coder->mutex)) {
lzma_free(next->coder, allocator);
if (mythread_mutex_init(&coder->mutex)) {
lzma_free(coder, allocator);
next->coder = NULL;
return LZMA_MEM_ERROR;
}
if (mythread_cond_init(&next->coder->cond)) {
mythread_mutex_destroy(&next->coder->mutex);
lzma_free(next->coder, allocator);
if (mythread_cond_init(&coder->cond)) {
mythread_mutex_destroy(&coder->mutex);
lzma_free(coder, allocator);
next->coder = NULL;
return LZMA_MEM_ERROR;
}
@ -989,76 +1000,76 @@ stream_encoder_mt_init(lzma_next_coder *next, const lzma_allocator *allocator,
next->get_progress = &get_progress;
// next->update = &stream_encoder_mt_update;
next->coder->filters[0].id = LZMA_VLI_UNKNOWN;
next->coder->index_encoder = LZMA_NEXT_CODER_INIT;
next->coder->index = NULL;
memzero(&next->coder->outq, sizeof(next->coder->outq));
next->coder->threads = NULL;
next->coder->threads_max = 0;
next->coder->threads_initialized = 0;
coder->filters[0].id = LZMA_VLI_UNKNOWN;
coder->index_encoder = LZMA_NEXT_CODER_INIT;
coder->index = NULL;
memzero(&coder->outq, sizeof(coder->outq));
coder->threads = NULL;
coder->threads_max = 0;
coder->threads_initialized = 0;
}
// Basic initializations
next->coder->sequence = SEQ_STREAM_HEADER;
next->coder->block_size = (size_t)(block_size);
next->coder->thread_error = LZMA_OK;
next->coder->thr = NULL;
coder->sequence = SEQ_STREAM_HEADER;
coder->block_size = (size_t)(block_size);
coder->thread_error = LZMA_OK;
coder->thr = NULL;
// Allocate the thread-specific base structures.
assert(options->threads > 0);
if (next->coder->threads_max != options->threads) {
threads_end(next->coder, allocator);
if (coder->threads_max != options->threads) {
threads_end(coder, allocator);
next->coder->threads = NULL;
next->coder->threads_max = 0;
coder->threads = NULL;
coder->threads_max = 0;
next->coder->threads_initialized = 0;
next->coder->threads_free = NULL;
coder->threads_initialized = 0;
coder->threads_free = NULL;
next->coder->threads = lzma_alloc(
coder->threads = lzma_alloc(
options->threads * sizeof(worker_thread),
allocator);
if (next->coder->threads == NULL)
if (coder->threads == NULL)
return LZMA_MEM_ERROR;
next->coder->threads_max = options->threads;
coder->threads_max = options->threads;
} else {
// Reuse the old structures and threads. Tell the running
// threads to stop and wait until they have stopped.
threads_stop(next->coder, true);
threads_stop(coder, true);
}
// Output queue
return_if_error(lzma_outq_init(&next->coder->outq, allocator,
return_if_error(lzma_outq_init(&coder->outq, allocator,
outbuf_size_max, options->threads));
// Timeout
next->coder->timeout = options->timeout;
coder->timeout = options->timeout;
// Free the old filter chain and copy the new one.
for (size_t i = 0; next->coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i)
lzma_free(next->coder->filters[i].options, allocator);
for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i)
lzma_free(coder->filters[i].options, allocator);
return_if_error(lzma_filters_copy(
filters, next->coder->filters, allocator));
filters, coder->filters, allocator));
// Index
lzma_index_end(next->coder->index, allocator);
next->coder->index = lzma_index_init(allocator);
if (next->coder->index == NULL)
lzma_index_end(coder->index, allocator);
coder->index = lzma_index_init(allocator);
if (coder->index == NULL)
return LZMA_MEM_ERROR;
// Stream Header
next->coder->stream_flags.version = 0;
next->coder->stream_flags.check = options->check;
coder->stream_flags.version = 0;
coder->stream_flags.check = options->check;
return_if_error(lzma_stream_header_encode(
&next->coder->stream_flags, next->coder->header));
&coder->stream_flags, coder->header));
next->coder->header_pos = 0;
coder->header_pos = 0;
// Progress info
next->coder->progress_in = 0;
next->coder->progress_out = LZMA_STREAM_HEADER_SIZE;
coder->progress_in = 0;
coder->progress_out = LZMA_STREAM_HEADER_SIZE;
return LZMA_OK;
}
@ -1111,7 +1122,8 @@ lzma_stream_encoder_mt_memusage(const lzma_mt *options)
return UINT64_MAX;
// Sum them with overflow checking.
uint64_t total_memusage = LZMA_MEMUSAGE_BASE + sizeof(lzma_coder)
uint64_t total_memusage = LZMA_MEMUSAGE_BASE
+ sizeof(lzma_stream_coder)
+ options->threads * sizeof(worker_thread);
if (UINT64_MAX - total_memusage < inbuf_memusage)

View file

@ -15,8 +15,9 @@
static void
delta_coder_end(lzma_coder *coder, const lzma_allocator *allocator)
delta_coder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_delta_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@ -28,14 +29,17 @@ lzma_delta_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
// Allocate memory for the decoder if needed.
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_delta_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_delta_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
// End function is the same for encoder and decoder.
next->end = &delta_coder_end;
next->coder->next = LZMA_NEXT_CODER_INIT;
coder->next = LZMA_NEXT_CODER_INIT;
}
// Validate the options.
@ -44,15 +48,14 @@ lzma_delta_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
// Set the delta distance.
const lzma_options_delta *opt = filters[0].options;
next->coder->distance = opt->dist;
coder->distance = opt->dist;
// Initialize the rest of the variables.
next->coder->pos = 0;
memzero(next->coder->history, LZMA_DELTA_DIST_MAX);
coder->pos = 0;
memzero(coder->history, LZMA_DELTA_DIST_MAX);
// Initialize the next decoder in the chain, if any.
return lzma_next_filter_init(&next->coder->next,
allocator, filters + 1);
return lzma_next_filter_init(&coder->next, allocator, filters + 1);
}
@ -66,5 +69,5 @@ lzma_delta_coder_memusage(const void *options)
|| opt->dist > LZMA_DELTA_DIST_MAX)
return UINT64_MAX;
return sizeof(lzma_coder);
return sizeof(lzma_delta_coder);
}

View file

@ -15,7 +15,7 @@
static void
decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
decode_buffer(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
{
const size_t distance = coder->distance;
@ -27,11 +27,13 @@ decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
static lzma_ret
delta_decode(lzma_coder *coder, const lzma_allocator *allocator,
delta_decode(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
lzma_delta_coder *coder = coder_ptr;
assert(coder->next.code != NULL);
const size_t out_start = *out_pos;

View file

@ -18,7 +18,7 @@
/// is the first filter in the chain (and thus the last filter in the
/// encoder's filter stack).
static void
copy_and_encode(lzma_coder *coder,
copy_and_encode(lzma_delta_coder *coder,
const uint8_t *restrict in, uint8_t *restrict out, size_t size)
{
const size_t distance = coder->distance;
@ -35,7 +35,7 @@ copy_and_encode(lzma_coder *coder,
/// Encodes the data in place. This is used when we are the last filter
/// in the chain (and thus non-last filter in the encoder's filter stack).
static void
encode_in_place(lzma_coder *coder, uint8_t *buffer, size_t size)
encode_in_place(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
{
const size_t distance = coder->distance;
@ -49,11 +49,13 @@ encode_in_place(lzma_coder *coder, uint8_t *buffer, size_t size)
static lzma_ret
delta_encode(lzma_coder *coder, const lzma_allocator *allocator,
delta_encode(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
lzma_delta_coder *coder = coder_ptr;
lzma_ret ret;
if (coder->next.code == NULL) {
@ -84,10 +86,12 @@ delta_encode(lzma_coder *coder, const lzma_allocator *allocator,
static lzma_ret
delta_encoder_update(lzma_coder *coder, const lzma_allocator *allocator,
delta_encoder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters_null lzma_attribute((__unused__)),
const lzma_filter *reversed_filters)
{
lzma_delta_coder *coder = coder_ptr;
// Delta doesn't and will never support changing the options in
// the middle of encoding. If the app tries to change them, we
// simply ignore them.

View file

@ -15,7 +15,7 @@
#include "delta_common.h"
struct lzma_coder_s {
typedef struct {
/// Next coder in the chain
lzma_next_coder next;
@ -27,7 +27,7 @@ struct lzma_coder_s {
/// Buffer to hold history of the original data
uint8_t history[LZMA_DELTA_DIST_MAX];
};
} lzma_delta_coder;
extern lzma_ret lzma_delta_coder_init(

View file

@ -20,7 +20,7 @@
#include "lz_decoder.h"
struct lzma_coder_s {
typedef struct {
/// Dictionary (history buffer)
lzma_dict dict;
@ -48,7 +48,7 @@ struct lzma_coder_s {
size_t size;
uint8_t buffer[LZMA_BUFFER_SIZE];
} temp;
};
} lzma_coder;
static void
@ -125,13 +125,15 @@ decode_buffer(lzma_coder *coder,
static lzma_ret
lz_decode(lzma_coder *coder,
lz_decode(void *coder_ptr,
const lzma_allocator *allocator lzma_attribute((__unused__)),
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
lzma_action action)
{
lzma_coder *coder = coder_ptr;
if (coder->next.code == NULL)
return decode_buffer(coder, in, in_pos, in_size,
out, out_pos, out_size);
@ -184,8 +186,10 @@ lz_decode(lzma_coder *coder,
static void
lz_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
lz_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder->dict.buf, allocator);
@ -207,24 +211,26 @@ lzma_lz_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
lzma_lz_options *lz_options))
{
// Allocate the base structure if it isn't already allocated.
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &lz_decode;
next->end = &lz_decoder_end;
next->coder->dict.buf = NULL;
next->coder->dict.size = 0;
next->coder->lz = LZMA_LZ_DECODER_INIT;
next->coder->next = LZMA_NEXT_CODER_INIT;
coder->dict.buf = NULL;
coder->dict.size = 0;
coder->lz = LZMA_LZ_DECODER_INIT;
coder->next = LZMA_NEXT_CODER_INIT;
}
// Allocate and initialize the LZ-based decoder. It will also give
// us the dictionary size.
lzma_lz_options lz_options;
return_if_error(lz_init(&next->coder->lz, allocator,
return_if_error(lz_init(&coder->lz, allocator,
filters[0].options, &lz_options));
// If the dictionary size is very small, increase it to 4096 bytes.
@ -248,14 +254,14 @@ lzma_lz_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
lz_options.dict_size = (lz_options.dict_size + 15) & ~((size_t)(15));
// Allocate and initialize the dictionary.
if (next->coder->dict.size != lz_options.dict_size) {
lzma_free(next->coder->dict.buf, allocator);
next->coder->dict.buf
if (coder->dict.size != lz_options.dict_size) {
lzma_free(coder->dict.buf, allocator);
coder->dict.buf
= lzma_alloc(lz_options.dict_size, allocator);
if (next->coder->dict.buf == NULL)
if (coder->dict.buf == NULL)
return LZMA_MEM_ERROR;
next->coder->dict.size = lz_options.dict_size;
coder->dict.size = lz_options.dict_size;
}
lz_decoder_reset(next->coder);
@ -268,21 +274,20 @@ lzma_lz_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const size_t copy_size = my_min(lz_options.preset_dict_size,
lz_options.dict_size);
const size_t offset = lz_options.preset_dict_size - copy_size;
memcpy(next->coder->dict.buf, lz_options.preset_dict + offset,
memcpy(coder->dict.buf, lz_options.preset_dict + offset,
copy_size);
next->coder->dict.pos = copy_size;
next->coder->dict.full = copy_size;
coder->dict.pos = copy_size;
coder->dict.full = copy_size;
}
// Miscellaneous initializations
next->coder->next_finished = false;
next->coder->this_finished = false;
next->coder->temp.pos = 0;
next->coder->temp.size = 0;
coder->next_finished = false;
coder->this_finished = false;
coder->temp.pos = 0;
coder->temp.size = 0;
// Initialize the next filter in the chain, if any.
return lzma_next_filter_init(&next->coder->next, allocator,
filters + 1);
return lzma_next_filter_init(&coder->next, allocator, filters + 1);
}
@ -294,7 +299,8 @@ lzma_lz_decoder_memusage(size_t dictionary_size)
extern void
lzma_lz_decoder_uncompressed(lzma_coder *coder, lzma_vli uncompressed_size)
lzma_lz_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size)
{
lzma_coder *coder = coder_ptr;
coder->lz.set_uncompressed(coder->lz.coder, uncompressed_size);
}

View file

@ -53,21 +53,20 @@ typedef struct {
typedef struct {
/// Data specific to the LZ-based decoder
lzma_coder *coder;
void *coder;
/// Function to decode from in[] to *dict
lzma_ret (*code)(lzma_coder *restrict coder,
lzma_ret (*code)(void *coder,
lzma_dict *restrict dict, const uint8_t *restrict in,
size_t *restrict in_pos, size_t in_size);
void (*reset)(lzma_coder *coder, const void *options);
void (*reset)(void *coder, const void *options);
/// Set the uncompressed size
void (*set_uncompressed)(lzma_coder *coder,
lzma_vli uncompressed_size);
void (*set_uncompressed)(void *coder, lzma_vli uncompressed_size);
/// Free allocated resources
void (*end)(lzma_coder *coder, const lzma_allocator *allocator);
void (*end)(void *coder, const lzma_allocator *allocator);
} lzma_lz_decoder;
@ -92,7 +91,7 @@ extern lzma_ret lzma_lz_decoder_init(lzma_next_coder *next,
extern uint64_t lzma_lz_decoder_memusage(size_t dictionary_size);
extern void lzma_lz_decoder_uncompressed(
lzma_coder *coder, lzma_vli uncompressed_size);
void *coder, lzma_vli uncompressed_size);
//////////////////////

View file

@ -23,7 +23,7 @@
#include "memcmplen.h"
struct lzma_coder_s {
typedef struct {
/// LZ-based encoder e.g. LZMA
lzma_lz_encoder lz;
@ -32,7 +32,7 @@ struct lzma_coder_s {
/// Next coder in the chain
lzma_next_coder next;
};
} lzma_coder;
/// \brief Moves the data in the input window to free space for new data
@ -157,12 +157,14 @@ fill_window(lzma_coder *coder, const lzma_allocator *allocator,
static lzma_ret
lz_encode(lzma_coder *coder, const lzma_allocator *allocator,
lz_encode(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size,
uint8_t *restrict out, size_t *restrict out_pos,
size_t out_size, lzma_action action)
{
lzma_coder *coder = coder_ptr;
while (*out_pos < out_size
&& (*in_pos < in_size || action != LZMA_RUN)) {
// Read more data to coder->mf.buffer if needed.
@ -481,8 +483,10 @@ lzma_lz_encoder_memusage(const lzma_lz_options *lz_options)
static void
lz_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
lz_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder->mf.son, allocator);
@ -500,10 +504,12 @@ lz_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
lz_encoder_update(lzma_coder *coder, const lzma_allocator *allocator,
lz_encoder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters_null lzma_attribute((__unused__)),
const lzma_filter *reversed_filters)
{
lzma_coder *coder = coder_ptr;
if (coder->lz.options_update == NULL)
return LZMA_PROG_ERROR;
@ -528,46 +534,51 @@ lzma_lz_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
#endif
// Allocate and initialize the base data structure.
if (next->coder == NULL) {
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (next->coder == NULL)
lzma_coder *coder = next->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &lz_encode;
next->end = &lz_encoder_end;
next->update = &lz_encoder_update;
next->coder->lz.coder = NULL;
next->coder->lz.code = NULL;
next->coder->lz.end = NULL;
coder->lz.coder = NULL;
coder->lz.code = NULL;
coder->lz.end = NULL;
next->coder->mf.buffer = NULL;
next->coder->mf.hash = NULL;
next->coder->mf.son = NULL;
next->coder->mf.hash_count = 0;
next->coder->mf.sons_count = 0;
// mf.size is initialized to silence Valgrind
// when used on optimized binaries (GCC may reorder
// code in a way that Valgrind gets unhappy).
coder->mf.buffer = NULL;
coder->mf.size = 0;
coder->mf.hash = NULL;
coder->mf.son = NULL;
coder->mf.hash_count = 0;
coder->mf.sons_count = 0;
next->coder->next = LZMA_NEXT_CODER_INIT;
coder->next = LZMA_NEXT_CODER_INIT;
}
// Initialize the LZ-based encoder.
lzma_lz_options lz_options;
return_if_error(lz_init(&next->coder->lz, allocator,
return_if_error(lz_init(&coder->lz, allocator,
filters[0].options, &lz_options));
// Setup the size information into next->coder->mf and deallocate
// Setup the size information into coder->mf and deallocate
// old buffers if they have wrong size.
if (lz_encoder_prepare(&next->coder->mf, allocator, &lz_options))
if (lz_encoder_prepare(&coder->mf, allocator, &lz_options))
return LZMA_OPTIONS_ERROR;
// Allocate new buffers if needed, and do the rest of
// the initialization.
if (lz_encoder_init(&next->coder->mf, allocator, &lz_options))
if (lz_encoder_init(&coder->mf, allocator, &lz_options))
return LZMA_MEM_ERROR;
// Initialize the next filter in the chain, if any.
return lzma_next_filter_init(&next->coder->next, allocator,
filters + 1);
return lzma_next_filter_init(&coder->next, allocator, filters + 1);
}

View file

@ -191,19 +191,18 @@ typedef struct {
typedef struct {
/// Data specific to the LZ-based encoder
lzma_coder *coder;
void *coder;
/// Function to encode from *dict to out[]
lzma_ret (*code)(lzma_coder *restrict coder,
lzma_ret (*code)(void *coder,
lzma_mf *restrict mf, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size);
/// Free allocated resources
void (*end)(lzma_coder *coder, const lzma_allocator *allocator);
void (*end)(void *coder, const lzma_allocator *allocator);
/// Update the options in the middle of the encoding.
lzma_ret (*options_update)(lzma_coder *coder,
const lzma_filter *filter);
lzma_ret (*options_update)(void *coder, const lzma_filter *filter);
} lzma_lz_encoder;

View file

@ -16,7 +16,7 @@
#include "lzma_decoder.h"
struct lzma_coder_s {
typedef struct {
enum sequence {
SEQ_CONTROL,
SEQ_UNCOMPRESSED_1,
@ -50,14 +50,16 @@ struct lzma_coder_s {
bool need_dictionary_reset;
lzma_options_lzma options;
};
} lzma_lzma2_coder;
static lzma_ret
lzma2_decode(lzma_coder *restrict coder, lzma_dict *restrict dict,
lzma2_decode(void *coder_ptr, lzma_dict *restrict dict,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size)
{
lzma_lzma2_coder *restrict coder = coder_ptr;
// With SEQ_LZMA it is possible that no new input is needed to do
// some progress. The rest of the sequences assume that there is
// at least one byte of input.
@ -209,8 +211,10 @@ lzma2_decode(lzma_coder *restrict coder, lzma_dict *restrict dict,
static void
lzma2_decoder_end(lzma_coder *coder, const lzma_allocator *allocator)
lzma2_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_lzma2_coder *coder = coder_ptr;
assert(coder->lzma.end == NULL);
lzma_free(coder->lzma.coder, allocator);
@ -224,25 +228,27 @@ static lzma_ret
lzma2_decoder_init(lzma_lz_decoder *lz, const lzma_allocator *allocator,
const void *opt, lzma_lz_options *lz_options)
{
if (lz->coder == NULL) {
lz->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (lz->coder == NULL)
lzma_lzma2_coder *coder = lz->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_lzma2_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
lz->coder = coder;
lz->code = &lzma2_decode;
lz->end = &lzma2_decoder_end;
lz->coder->lzma = LZMA_LZ_DECODER_INIT;
coder->lzma = LZMA_LZ_DECODER_INIT;
}
const lzma_options_lzma *options = opt;
lz->coder->sequence = SEQ_CONTROL;
lz->coder->need_properties = true;
lz->coder->need_dictionary_reset = options->preset_dict == NULL
coder->sequence = SEQ_CONTROL;
coder->need_properties = true;
coder->need_dictionary_reset = options->preset_dict == NULL
|| options->preset_dict_size == 0;
return lzma_lzma_decoder_create(&lz->coder->lzma,
return lzma_lzma_decoder_create(&coder->lzma,
allocator, options, lz_options);
}
@ -263,7 +269,7 @@ lzma_lzma2_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
extern uint64_t
lzma_lzma2_decoder_memusage(const void *options)
{
return sizeof(lzma_coder)
return sizeof(lzma_lzma2_coder)
+ lzma_lzma_decoder_memusage_nocheck(options);
}

View file

@ -17,7 +17,7 @@
#include "lzma2_encoder.h"
struct lzma_coder_s {
typedef struct {
enum {
SEQ_INIT,
SEQ_LZMA_ENCODE,
@ -27,7 +27,7 @@ struct lzma_coder_s {
} sequence;
/// LZMA encoder
lzma_coder *lzma;
void *lzma;
/// LZMA options currently in use.
lzma_options_lzma opt_cur;
@ -48,11 +48,11 @@ struct lzma_coder_s {
/// Buffer to hold the chunk header and LZMA compressed data
uint8_t buf[LZMA2_HEADER_MAX + LZMA2_CHUNK_MAX];
};
} lzma_lzma2_coder;
static void
lzma2_header_lzma(lzma_coder *coder)
lzma2_header_lzma(lzma_lzma2_coder *coder)
{
assert(coder->uncompressed_size > 0);
assert(coder->uncompressed_size <= LZMA2_UNCOMPRESSED_MAX);
@ -108,7 +108,7 @@ lzma2_header_lzma(lzma_coder *coder)
static void
lzma2_header_uncompressed(lzma_coder *coder)
lzma2_header_uncompressed(lzma_lzma2_coder *coder)
{
assert(coder->uncompressed_size > 0);
assert(coder->uncompressed_size <= LZMA2_CHUNK_MAX);
@ -133,10 +133,12 @@ lzma2_header_uncompressed(lzma_coder *coder)
static lzma_ret
lzma2_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
lzma2_encode(void *coder_ptr, lzma_mf *restrict mf,
uint8_t *restrict out, size_t *restrict out_pos,
size_t out_size)
{
lzma_lzma2_coder *restrict coder = coder_ptr;
while (*out_pos < out_size)
switch (coder->sequence) {
case SEQ_INIT:
@ -262,8 +264,9 @@ lzma2_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
static void
lzma2_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
lzma2_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_lzma2_coder *coder = coder_ptr;
lzma_free(coder->lzma, allocator);
lzma_free(coder, allocator);
return;
@ -271,8 +274,10 @@ lzma2_encoder_end(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
lzma2_encoder_options_update(lzma_coder *coder, const lzma_filter *filter)
lzma2_encoder_options_update(void *coder_ptr, const lzma_filter *filter)
{
lzma_lzma2_coder *coder = coder_ptr;
// New options can be set only when there is no incomplete chunk.
// This is the case at the beginning of the raw stream and right
// after LZMA_SYNC_FLUSH.
@ -310,30 +315,32 @@ lzma2_encoder_init(lzma_lz_encoder *lz, const lzma_allocator *allocator,
if (options == NULL)
return LZMA_PROG_ERROR;
if (lz->coder == NULL) {
lz->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (lz->coder == NULL)
lzma_lzma2_coder *coder = lz->coder;
if (coder == NULL) {
coder = lzma_alloc(sizeof(lzma_lzma2_coder), allocator);
if (coder == NULL)
return LZMA_MEM_ERROR;
lz->coder = coder;
lz->code = &lzma2_encode;
lz->end = &lzma2_encoder_end;
lz->options_update = &lzma2_encoder_options_update;
lz->coder->lzma = NULL;
coder->lzma = NULL;
}
lz->coder->opt_cur = *(const lzma_options_lzma *)(options);
coder->opt_cur = *(const lzma_options_lzma *)(options);
lz->coder->sequence = SEQ_INIT;
lz->coder->need_properties = true;
lz->coder->need_state_reset = false;
lz->coder->need_dictionary_reset
= lz->coder->opt_cur.preset_dict == NULL
|| lz->coder->opt_cur.preset_dict_size == 0;
coder->sequence = SEQ_INIT;
coder->need_properties = true;
coder->need_state_reset = false;
coder->need_dictionary_reset
= coder->opt_cur.preset_dict == NULL
|| coder->opt_cur.preset_dict_size == 0;
// Initialize LZMA encoder
return_if_error(lzma_lzma_encoder_create(&lz->coder->lzma, allocator,
&lz->coder->opt_cur, lz_options));
return_if_error(lzma_lzma_encoder_create(&coder->lzma, allocator,
&coder->opt_cur, lz_options));
// Make sure that we will always have enough history available in
// case we need to use uncompressed chunks. They are used when the
@ -364,7 +371,7 @@ lzma_lzma2_encoder_memusage(const void *options)
if (lzma_mem == UINT64_MAX)
return UINT64_MAX;
return sizeof(lzma_coder) + lzma_mem;
return sizeof(lzma_lzma2_coder) + lzma_mem;
}

View file

@ -161,7 +161,7 @@ typedef struct {
} lzma_length_decoder;
struct lzma_coder_s {
typedef struct {
///////////////////
// Probabilities //
///////////////////
@ -277,14 +277,16 @@ struct lzma_coder_s {
/// If decoding a literal: match byte.
/// If decoding a match: length of the match.
uint32_t len;
};
} lzma_lzma1_decoder;
static lzma_ret
lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
lzma_decode(void *coder_ptr, lzma_dict *restrict dictptr,
const uint8_t *restrict in,
size_t *restrict in_pos, size_t in_size)
{
lzma_lzma1_decoder *restrict coder = coder_ptr;
////////////////////
// Initialization //
////////////////////
@ -840,23 +842,17 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
static void
lzma_decoder_uncompressed(lzma_coder *coder, lzma_vli uncompressed_size)
lzma_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size)
{
lzma_lzma1_decoder *coder = coder_ptr;
coder->uncompressed_size = uncompressed_size;
}
/*
extern void
lzma_lzma_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size)
{
// This is hack.
(*(lzma_coder **)(coder))->uncompressed_size = uncompressed_size;
}
*/
static void
lzma_decoder_reset(lzma_coder *coder, const void *opt)
lzma_decoder_reset(void *coder_ptr, const void *opt)
{
lzma_lzma1_decoder *coder = coder_ptr;
const lzma_options_lzma *options = opt;
// NOTE: We assume that lc/lp/pb are valid since they were
@ -941,7 +937,7 @@ lzma_lzma_decoder_create(lzma_lz_decoder *lz, const lzma_allocator *allocator,
const void *opt, lzma_lz_options *lz_options)
{
if (lz->coder == NULL) {
lz->coder = lzma_alloc(sizeof(lzma_coder), allocator);
lz->coder = lzma_alloc(sizeof(lzma_lzma1_decoder), allocator);
if (lz->coder == NULL)
return LZMA_MEM_ERROR;
@ -1014,7 +1010,8 @@ extern uint64_t
lzma_lzma_decoder_memusage_nocheck(const void *options)
{
const lzma_options_lzma *const opt = options;
return sizeof(lzma_coder) + lzma_lz_decoder_memusage(opt->dict_size);
return sizeof(lzma_lzma1_decoder)
+ lzma_lz_decoder_memusage(opt->dict_size);
}

View file

@ -43,7 +43,7 @@ literal_matched(lzma_range_encoder *rc, probability *subcoder,
static inline void
literal(lzma_coder *coder, lzma_mf *mf, uint32_t position)
literal(lzma_lzma1_encoder *coder, lzma_mf *mf, uint32_t position)
{
// Locate the literal byte to be encoded and the subcoder.
const uint8_t cur_byte = mf->buffer[
@ -140,7 +140,7 @@ length(lzma_range_encoder *rc, lzma_length_encoder *lc,
///////////
static inline void
match(lzma_coder *coder, const uint32_t pos_state,
match(lzma_lzma1_encoder *coder, const uint32_t pos_state,
const uint32_t distance, const uint32_t len)
{
update_match(coder->state);
@ -187,7 +187,7 @@ match(lzma_coder *coder, const uint32_t pos_state,
////////////////////
static inline void
rep_match(lzma_coder *coder, const uint32_t pos_state,
rep_match(lzma_lzma1_encoder *coder, const uint32_t pos_state,
const uint32_t rep, const uint32_t len)
{
if (rep == 0) {
@ -231,7 +231,7 @@ rep_match(lzma_coder *coder, const uint32_t pos_state,
//////////
static void
encode_symbol(lzma_coder *coder, lzma_mf *mf,
encode_symbol(lzma_lzma1_encoder *coder, lzma_mf *mf,
uint32_t back, uint32_t len, uint32_t position)
{
const uint32_t pos_state = position & coder->pos_mask;
@ -265,7 +265,7 @@ encode_symbol(lzma_coder *coder, lzma_mf *mf,
static bool
encode_init(lzma_coder *coder, lzma_mf *mf)
encode_init(lzma_lzma1_encoder *coder, lzma_mf *mf)
{
assert(mf_position(mf) == 0);
@ -293,7 +293,7 @@ encode_init(lzma_coder *coder, lzma_mf *mf)
static void
encode_eopm(lzma_coder *coder, uint32_t position)
encode_eopm(lzma_lzma1_encoder *coder, uint32_t position)
{
const uint32_t pos_state = position & coder->pos_mask;
rc_bit(&coder->rc, &coder->is_match[coder->state][pos_state], 1);
@ -309,7 +309,7 @@ encode_eopm(lzma_coder *coder, uint32_t position)
extern lzma_ret
lzma_lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
lzma_lzma_encode(lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf,
uint8_t *restrict out, size_t *restrict out_pos,
size_t out_size, uint32_t limit)
{
@ -402,7 +402,7 @@ lzma_lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
static lzma_ret
lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
lzma_encode(void *coder, lzma_mf *restrict mf,
uint8_t *restrict out, size_t *restrict out_pos,
size_t out_size)
{
@ -473,7 +473,8 @@ length_encoder_reset(lzma_length_encoder *lencoder,
extern lzma_ret
lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
lzma_lzma_encoder_reset(lzma_lzma1_encoder *coder,
const lzma_options_lzma *options)
{
if (!is_options_valid(options))
return LZMA_OPTIONS_ERROR;
@ -545,18 +546,18 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
extern lzma_ret
lzma_lzma_encoder_create(lzma_coder **coder_ptr,
lzma_lzma_encoder_create(void **coder_ptr,
const lzma_allocator *allocator,
const lzma_options_lzma *options, lzma_lz_options *lz_options)
{
// Allocate lzma_coder if it wasn't already allocated.
// Allocate lzma_lzma1_encoder if it wasn't already allocated.
if (*coder_ptr == NULL) {
*coder_ptr = lzma_alloc(sizeof(lzma_coder), allocator);
*coder_ptr = lzma_alloc(sizeof(lzma_lzma1_encoder), allocator);
if (*coder_ptr == NULL)
return LZMA_MEM_ERROR;
}
lzma_coder *coder = *coder_ptr;
lzma_lzma1_encoder *coder = *coder_ptr;
// Set compression mode. We haven't validates the options yet,
// but it's OK here, since nothing bad happens with invalid
@ -636,7 +637,7 @@ lzma_lzma_encoder_memusage(const void *options)
if (lz_memusage == UINT64_MAX)
return UINT64_MAX;
return (uint64_t)(sizeof(lzma_coder)) + lz_memusage;
return (uint64_t)(sizeof(lzma_lzma1_encoder)) + lz_memusage;
}

View file

@ -17,6 +17,9 @@
#include "common.h"
typedef struct lzma_lzma1_encoder_s lzma_lzma1_encoder;
extern lzma_ret lzma_lzma_encoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
const lzma_filter_info *filters);
@ -36,16 +39,16 @@ extern bool lzma_lzma_lclppb_encode(
/// Initializes raw LZMA encoder; this is used by LZMA2.
extern lzma_ret lzma_lzma_encoder_create(
lzma_coder **coder_ptr, const lzma_allocator *allocator,
void **coder_ptr, const lzma_allocator *allocator,
const lzma_options_lzma *options, lzma_lz_options *lz_options);
/// Resets an already initialized LZMA encoder; this is used by LZMA2.
extern lzma_ret lzma_lzma_encoder_reset(
lzma_coder *coder, const lzma_options_lzma *options);
lzma_lzma1_encoder *coder, const lzma_options_lzma *options);
extern lzma_ret lzma_lzma_encode(lzma_coder *restrict coder,
extern lzma_ret lzma_lzma_encode(lzma_lzma1_encoder *restrict coder,
lzma_mf *restrict mf, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size,
uint32_t read_limit);

View file

@ -18,7 +18,8 @@
extern void
lzma_lzma_optimum_fast(lzma_coder *restrict coder, lzma_mf *restrict mf,
lzma_lzma_optimum_fast(lzma_lzma1_encoder *restrict coder,
lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res)
{
const uint32_t nice_len = mf->nice_len;

View file

@ -19,7 +19,7 @@
////////////
static uint32_t
get_literal_price(const lzma_coder *const coder, const uint32_t pos,
get_literal_price(const lzma_lzma1_encoder *const coder, const uint32_t pos,
const uint32_t prev_byte, const bool match_mode,
uint32_t match_byte, uint32_t symbol)
{
@ -65,7 +65,7 @@ get_len_price(const lzma_length_encoder *const lencoder,
static inline uint32_t
get_short_rep_price(const lzma_coder *const coder,
get_short_rep_price(const lzma_lzma1_encoder *const coder,
const lzma_lzma_state state, const uint32_t pos_state)
{
return rc_bit_0_price(coder->is_rep0[state])
@ -74,7 +74,7 @@ get_short_rep_price(const lzma_coder *const coder,
static inline uint32_t
get_pure_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
get_pure_rep_price(const lzma_lzma1_encoder *const coder, const uint32_t rep_index,
const lzma_lzma_state state, uint32_t pos_state)
{
uint32_t price;
@ -99,7 +99,7 @@ get_pure_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
static inline uint32_t
get_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
get_rep_price(const lzma_lzma1_encoder *const coder, const uint32_t rep_index,
const uint32_t len, const lzma_lzma_state state,
const uint32_t pos_state)
{
@ -109,7 +109,7 @@ get_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
static inline uint32_t
get_dist_len_price(const lzma_coder *const coder, const uint32_t dist,
get_dist_len_price(const lzma_lzma1_encoder *const coder, const uint32_t dist,
const uint32_t len, const uint32_t pos_state)
{
const uint32_t dist_state = get_dist_state(len);
@ -130,7 +130,7 @@ get_dist_len_price(const lzma_coder *const coder, const uint32_t dist,
static void
fill_dist_prices(lzma_coder *coder)
fill_dist_prices(lzma_lzma1_encoder *coder)
{
for (uint32_t dist_state = 0; dist_state < DIST_STATES; ++dist_state) {
@ -185,7 +185,7 @@ fill_dist_prices(lzma_coder *coder)
static void
fill_align_prices(lzma_coder *coder)
fill_align_prices(lzma_lzma1_encoder *coder)
{
for (uint32_t i = 0; i < ALIGN_SIZE; ++i)
coder->align_prices[i] = rc_bittree_reverse_price(
@ -221,7 +221,7 @@ make_short_rep(lzma_optimal *optimal)
static void
backward(lzma_coder *restrict coder, uint32_t *restrict len_res,
backward(lzma_lzma1_encoder *restrict coder, uint32_t *restrict len_res,
uint32_t *restrict back_res, uint32_t cur)
{
coder->opts_end_index = cur;
@ -269,7 +269,7 @@ backward(lzma_coder *restrict coder, uint32_t *restrict len_res,
//////////
static inline uint32_t
helper1(lzma_coder *restrict coder, lzma_mf *restrict mf,
helper1(lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res,
uint32_t position)
{
@ -441,7 +441,7 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf,
static inline uint32_t
helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
helper2(lzma_lzma1_encoder *coder, uint32_t *reps, const uint8_t *buf,
uint32_t len_end, uint32_t position, const uint32_t cur,
const uint32_t nice_len, const uint32_t buf_avail_full)
{
@ -797,7 +797,8 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
extern void
lzma_lzma_optimum_normal(lzma_coder *restrict coder, lzma_mf *restrict mf,
lzma_lzma_optimum_normal(lzma_lzma1_encoder *restrict coder,
lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res,
uint32_t position)
{

View file

@ -2,6 +2,7 @@
//
/// \file lzma_encoder_presets.c
/// \brief Encoder presets
/// \note xz needs this even when only decoding is enabled.
//
// Author: Lasse Collin
//

View file

@ -69,7 +69,7 @@ typedef struct {
} lzma_optimal;
struct lzma_coder_s {
struct lzma_lzma1_encoder_s {
/// Range encoder
lzma_range_encoder rc;
@ -138,10 +138,10 @@ struct lzma_coder_s {
extern void lzma_lzma_optimum_fast(
lzma_coder *restrict coder, lzma_mf *restrict mf,
lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf,
uint32_t *restrict back_res, uint32_t *restrict len_res);
extern void lzma_lzma_optimum_normal(lzma_coder *restrict coder,
extern void lzma_lzma_optimum_normal(lzma_lzma1_encoder *restrict coder,
lzma_mf *restrict mf, uint32_t *restrict back_res,
uint32_t *restrict len_res, uint32_t position);

View file

@ -15,7 +15,7 @@
static size_t
arm_code(lzma_simple *simple lzma_attribute((__unused__)),
arm_code(void *simple lzma_attribute((__unused__)),
uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{

View file

@ -15,7 +15,7 @@
static size_t
armthumb_code(lzma_simple *simple lzma_attribute((__unused__)),
armthumb_code(void *simple lzma_attribute((__unused__)),
uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{

View file

@ -15,7 +15,7 @@
static size_t
ia64_code(lzma_simple *simple lzma_attribute((__unused__)),
ia64_code(void *simple lzma_attribute((__unused__)),
uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{

View file

@ -15,7 +15,7 @@
static size_t
powerpc_code(lzma_simple *simple lzma_attribute((__unused__)),
powerpc_code(void *simple lzma_attribute((__unused__)),
uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{

View file

@ -18,7 +18,7 @@
/// Copied or encodes/decodes more data to out[].
static lzma_ret
copy_or_code(lzma_coder *coder, const lzma_allocator *allocator,
copy_or_code(lzma_simple_coder *coder, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
@ -55,7 +55,7 @@ copy_or_code(lzma_coder *coder, const lzma_allocator *allocator,
static size_t
call_filter(lzma_coder *coder, uint8_t *buffer, size_t size)
call_filter(lzma_simple_coder *coder, uint8_t *buffer, size_t size)
{
const size_t filtered = coder->filter(coder->simple,
coder->now_pos, coder->is_encoder,
@ -66,11 +66,13 @@ call_filter(lzma_coder *coder, uint8_t *buffer, size_t size)
static lzma_ret
simple_code(lzma_coder *coder, const lzma_allocator *allocator,
simple_code(void *coder_ptr, const lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
lzma_simple_coder *coder = coder_ptr;
// TODO: Add partial support for LZMA_SYNC_FLUSH. We can support it
// in cases when the filter is able to filter everything. With most
// simple filters it can be done at offset that is a multiple of 2,
@ -198,8 +200,9 @@ simple_code(lzma_coder *coder, const lzma_allocator *allocator,
static void
simple_coder_end(lzma_coder *coder, const lzma_allocator *allocator)
simple_coder_end(void *coder_ptr, const lzma_allocator *allocator)
{
lzma_simple_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder->simple, allocator);
lzma_free(coder, allocator);
@ -208,10 +211,12 @@ simple_coder_end(lzma_coder *coder, const lzma_allocator *allocator)
static lzma_ret
simple_coder_update(lzma_coder *coder, const lzma_allocator *allocator,
simple_coder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters_null lzma_attribute((__unused__)),
const lzma_filter *reversed_filters)
{
lzma_simple_coder *coder = coder_ptr;
// No update support, just call the next filter in the chain.
return lzma_next_filter_update(
&coder->next, allocator, reversed_filters + 1);
@ -221,57 +226,57 @@ simple_coder_update(lzma_coder *coder, const lzma_allocator *allocator,
extern lzma_ret
lzma_simple_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters,
size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
size_t (*filter)(void *simple, uint32_t now_pos,
bool is_encoder, uint8_t *buffer, size_t size),
size_t simple_size, size_t unfiltered_max,
uint32_t alignment, bool is_encoder)
{
// Allocate memory for the lzma_coder structure if needed.
if (next->coder == NULL) {
// Allocate memory for the lzma_simple_coder structure if needed.
lzma_simple_coder *coder = next->coder;
if (coder == NULL) {
// Here we allocate space also for the temporary buffer. We
// need twice the size of unfiltered_max, because then it
// is always possible to filter at least unfiltered_max bytes
// more data in coder->buffer[] if it can be filled completely.
next->coder = lzma_alloc(sizeof(lzma_coder)
coder = lzma_alloc(sizeof(lzma_simple_coder)
+ 2 * unfiltered_max, allocator);
if (next->coder == NULL)
if (coder == NULL)
return LZMA_MEM_ERROR;
next->coder = coder;
next->code = &simple_code;
next->end = &simple_coder_end;
next->update = &simple_coder_update;
next->coder->next = LZMA_NEXT_CODER_INIT;
next->coder->filter = filter;
next->coder->allocated = 2 * unfiltered_max;
coder->next = LZMA_NEXT_CODER_INIT;
coder->filter = filter;
coder->allocated = 2 * unfiltered_max;
// Allocate memory for filter-specific data structure.
if (simple_size > 0) {
next->coder->simple = lzma_alloc(
simple_size, allocator);
if (next->coder->simple == NULL)
coder->simple = lzma_alloc(simple_size, allocator);
if (coder->simple == NULL)
return LZMA_MEM_ERROR;
} else {
next->coder->simple = NULL;
coder->simple = NULL;
}
}
if (filters[0].options != NULL) {
const lzma_options_bcj *simple = filters[0].options;
next->coder->now_pos = simple->start_offset;
if (next->coder->now_pos & (alignment - 1))
coder->now_pos = simple->start_offset;
if (coder->now_pos & (alignment - 1))
return LZMA_OPTIONS_ERROR;
} else {
next->coder->now_pos = 0;
coder->now_pos = 0;
}
// Reset variables.
next->coder->is_encoder = is_encoder;
next->coder->end_was_reached = false;
next->coder->pos = 0;
next->coder->filtered = 0;
next->coder->size = 0;
coder->is_encoder = is_encoder;
coder->end_was_reached = false;
coder->pos = 0;
coder->filtered = 0;
coder->size = 0;
return lzma_next_filter_init(
&next->coder->next, allocator, filters + 1);
return lzma_next_filter_init(&coder->next, allocator, filters + 1);
}

View file

@ -16,9 +16,7 @@
#include "simple_coder.h"
typedef struct lzma_simple_s lzma_simple;
struct lzma_coder_s {
typedef struct {
/// Next filter in the chain
lzma_next_coder next;
@ -33,12 +31,12 @@ struct lzma_coder_s {
/// Pointer to filter-specific function, which does
/// the actual filtering.
size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
size_t (*filter)(void *simple, uint32_t now_pos,
bool is_encoder, uint8_t *buffer, size_t size);
/// Pointer to filter-specific data, or NULL if filter doesn't need
/// any extra data.
lzma_simple *simple;
void *simple;
/// The lowest 32 bits of the current position in the data. Most
/// filters need this to do conversions between absolute and relative
@ -62,13 +60,13 @@ struct lzma_coder_s {
/// Temporary buffer
uint8_t buffer[];
};
} lzma_simple_coder;
extern lzma_ret lzma_simple_coder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
const lzma_filter_info *filters,
size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
size_t (*filter)(void *simple, uint32_t now_pos,
bool is_encoder, uint8_t *buffer, size_t size),
size_t simple_size, size_t unfiltered_max,
uint32_t alignment, bool is_encoder);

View file

@ -15,7 +15,7 @@
static size_t
sparc_code(lzma_simple *simple lzma_attribute((__unused__)),
sparc_code(void *simple lzma_attribute((__unused__)),
uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{

View file

@ -17,14 +17,14 @@
#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
struct lzma_simple_s {
typedef struct {
uint32_t prev_mask;
uint32_t prev_pos;
};
} lzma_simple_x86;
static size_t
x86_code(lzma_simple *simple, uint32_t now_pos, bool is_encoder,
x86_code(void *simple_ptr, uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{
static const bool MASK_TO_ALLOWED_STATUS[8]
@ -33,6 +33,7 @@ x86_code(lzma_simple *simple, uint32_t now_pos, bool is_encoder,
static const uint32_t MASK_TO_BIT_NUMBER[8]
= { 0, 1, 2, 2, 3, 3, 3, 3 };
lzma_simple_x86 *simple = simple_ptr;
uint32_t prev_mask = simple->prev_mask;
uint32_t prev_pos = simple->prev_pos;
@ -127,11 +128,13 @@ x86_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder)
{
const lzma_ret ret = lzma_simple_coder_init(next, allocator, filters,
&x86_code, sizeof(lzma_simple), 5, 1, is_encoder);
&x86_code, sizeof(lzma_simple_x86), 5, 1, is_encoder);
if (ret == LZMA_OK) {
next->coder->simple->prev_mask = 0;
next->coder->simple->prev_pos = (uint32_t)(-5);
lzma_simple_coder *coder = next->coder;
lzma_simple_x86 *simple = coder->simple;
simple->prev_mask = 0;
simple->prev_pos = (uint32_t)(-5);
}
return ret;

View file

@ -635,6 +635,22 @@ args_parse(args_info *args, int argc, char **argv)
// Then from the command line
parse_real(args, argc, argv);
// If encoder or decoder support was omitted at build time,
// show an error now so that the rest of the code can rely on
// that whatever is in opt_mode is also supported.
#ifndef HAVE_ENCODERS
if (opt_mode == MODE_COMPRESS)
message_fatal(_("Compression support was disabled "
"at build time"));
#endif
#ifndef HAVE_DECODERS
// Even MODE_LIST cannot work without decoder support so MODE_COMPRESS
// is the only valid choice.
if (opt_mode != MODE_COMPRESS)
message_fatal(_("Decompression support was disabled "
"at build time"));
#endif
// Never remove the source file when the destination is not on disk.
// In test mode the data is written nowhere, but setting opt_stdout
// will make the rest of the code behave well.

View file

@ -51,7 +51,7 @@ static lzma_check check;
/// This becomes false if the --check=CHECK option is used.
static bool check_default = true;
#ifdef MYTHREAD_ENABLED
#if defined(HAVE_ENCODERS) && defined(MYTHREAD_ENABLED)
static lzma_mt mt_options = {
.flags = 0,
.timeout = 300,
@ -221,9 +221,10 @@ coder_set_compression_settings(void)
// Get the memory usage. Note that if --format=raw was used,
// we can be decompressing.
const uint64_t memory_limit = hardware_memlimit_get(opt_mode);
uint64_t memory_usage;
uint64_t memory_usage = UINT64_MAX;
if (opt_mode == MODE_COMPRESS) {
#ifdef MYTHREAD_ENABLED
#ifdef HAVE_ENCODERS
# ifdef MYTHREAD_ENABLED
if (opt_format == FORMAT_XZ && hardware_threads_get() > 1) {
mt_options.threads = hardware_threads_get();
mt_options.block_size = opt_block_size;
@ -235,12 +236,15 @@ coder_set_compression_settings(void)
" threads."),
mt_options.threads);
} else
#endif
# endif
{
memory_usage = lzma_raw_encoder_memusage(filters);
}
#endif
} else {
#ifdef HAVE_DECODERS
memory_usage = lzma_raw_decoder_memusage(filters);
#endif
}
if (memory_usage == UINT64_MAX)
@ -248,7 +252,11 @@ coder_set_compression_settings(void)
// Print memory usage info before possible dictionary
// size auto-adjusting.
//
// NOTE: If only encoder support was built, we cannot show the
// what the decoder memory usage will be.
message_mem_needed(V_DEBUG, memory_usage);
#ifdef HAVE_DECODERS
if (opt_mode == MODE_COMPRESS) {
const uint64_t decmem = lzma_raw_decoder_memusage(filters);
if (decmem != UINT64_MAX)
@ -256,6 +264,7 @@ coder_set_compression_settings(void)
"%s MiB of memory."), uint64_to_str(
round_up_to_mib(decmem), 0));
}
#endif
if (memory_usage <= memory_limit)
return;
@ -268,7 +277,8 @@ coder_set_compression_settings(void)
assert(opt_mode == MODE_COMPRESS);
#ifdef MYTHREAD_ENABLED
#ifdef HAVE_ENCODERS
# ifdef MYTHREAD_ENABLED
if (opt_format == FORMAT_XZ && mt_options.threads > 1) {
// Try to reduce the number of threads before
// adjusting the compression settings down.
@ -295,7 +305,7 @@ coder_set_compression_settings(void)
uint64_to_str(round_up_to_mib(
memory_limit), 2));
}
#endif
# endif
if (memory_usage <= memory_limit)
return;
@ -349,11 +359,13 @@ coder_set_compression_settings(void)
uint64_to_str(orig_dict_size >> 20, 0),
uint64_to_str(opt->dict_size >> 20, 1),
uint64_to_str(round_up_to_mib(memory_limit), 2));
#endif
return;
}
#ifdef HAVE_DECODERS
/// Return true if the data in in_buf seems to be in the .xz format.
static bool
is_format_xz(void)
@ -411,6 +423,7 @@ is_format_lzma(void)
return true;
}
#endif
/// Detect the input file type (for now, this done only when decompressing),
@ -424,6 +437,7 @@ coder_init(file_pair *pair)
lzma_ret ret = LZMA_PROG_ERROR;
if (opt_mode == MODE_COMPRESS) {
#ifdef HAVE_ENCODERS
switch (opt_format) {
case FORMAT_AUTO:
// args.c ensures this.
@ -431,12 +445,12 @@ coder_init(file_pair *pair)
break;
case FORMAT_XZ:
#ifdef MYTHREAD_ENABLED
# ifdef MYTHREAD_ENABLED
if (hardware_threads_get() > 1)
ret = lzma_stream_encoder_mt(
&strm, &mt_options);
else
#endif
# endif
ret = lzma_stream_encoder(
&strm, filters, check);
break;
@ -449,7 +463,9 @@ coder_init(file_pair *pair)
ret = lzma_raw_encoder(&strm, filters);
break;
}
#endif
} else {
#ifdef HAVE_DECODERS
uint32_t flags = 0;
// It seems silly to warn about unsupported check if the
@ -531,6 +547,7 @@ coder_init(file_pair *pair)
strm.avail_out = 0;
ret = lzma_code(&strm, LZMA_RUN);
}
#endif
}
if (ret != LZMA_OK) {

View file

@ -23,10 +23,20 @@ static bool warn_fchown;
#if defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT) || defined(HAVE_UTIMES)
# include <sys/time.h>
#elif defined(HAVE__FUTIME)
# include <sys/utime.h>
#elif defined(HAVE_UTIME)
# include <utime.h>
#endif
#ifdef HAVE_CAPSICUM
# ifdef HAVE_SYS_CAPSICUM_H
# include <sys/capsicum.h>
# else
# include <sys/capability.h>
# endif
#endif
#include "tuklib_open_stdxxx.h"
#ifndef O_BINARY
@ -37,6 +47,14 @@ static bool warn_fchown;
# define O_NOCTTY 0
#endif
// Using this macro to silence a warning from gcc -Wlogical-op.
#if EAGAIN == EWOULDBLOCK
# define IS_EAGAIN_OR_EWOULDBLOCK(e) ((e) == EAGAIN)
#else
# define IS_EAGAIN_OR_EWOULDBLOCK(e) \
((e) == EAGAIN || (e) == EWOULDBLOCK)
#endif
typedef enum {
IO_WAIT_MORE, // Reading or writing is possible.
@ -48,6 +66,11 @@ typedef enum {
/// If true, try to create sparse files when decompressing.
static bool try_sparse = true;
#ifdef ENABLE_SANDBOX
/// True if the conditions for sandboxing (described in main()) have been met.
static bool sandbox_allowed = false;
#endif
#ifndef TUKLIB_DOSLIKE
/// File status flags of standard input. This is used by io_open_src()
/// and io_close_src().
@ -132,6 +155,73 @@ io_no_sparse(void)
}
#ifdef ENABLE_SANDBOX
extern void
io_allow_sandbox(void)
{
sandbox_allowed = true;
return;
}
/// Enables operating-system-specific sandbox if it is possible.
/// src_fd is the file descriptor of the input file.
static void
io_sandbox_enter(int src_fd)
{
if (!sandbox_allowed) {
message(V_DEBUG, _("Sandbox is disabled due "
"to incompatible command line arguments"));
return;
}
const char dummy_str[] = "x";
// Try to ensure that both libc and xz locale files have been
// loaded when NLS is enabled.
snprintf(NULL, 0, "%s%s", _(dummy_str), strerror(EINVAL));
// Try to ensure that iconv data files needed for handling multibyte
// characters have been loaded. This is needed at least with glibc.
tuklib_mbstr_width(dummy_str, NULL);
#ifdef HAVE_CAPSICUM
// Capsicum needs FreeBSD 10.0 or later.
cap_rights_t rights;
if (cap_rights_limit(src_fd, cap_rights_init(&rights,
CAP_EVENT, CAP_FCNTL, CAP_LOOKUP, CAP_READ, CAP_SEEK)))
goto error;
if (cap_rights_limit(STDOUT_FILENO, cap_rights_init(&rights,
CAP_EVENT, CAP_FCNTL, CAP_FSTAT, CAP_LOOKUP,
CAP_WRITE, CAP_SEEK)))
goto error;
if (cap_rights_limit(user_abort_pipe[0], cap_rights_init(&rights,
CAP_EVENT)))
goto error;
if (cap_rights_limit(user_abort_pipe[1], cap_rights_init(&rights,
CAP_WRITE)))
goto error;
if (cap_enter())
goto error;
#else
# error ENABLE_SANDBOX is defined but no sandboxing method was found.
#endif
message(V_DEBUG, _("Sandbox was successfully enabled"));
return;
error:
message(V_DEBUG, _("Failed to enable the sandbox"));
}
#endif // ENABLE_SANDBOX
#ifndef TUKLIB_DOSLIKE
/// \brief Waits for input or output to become available or for a signal
///
@ -369,6 +459,22 @@ io_copy_attrs(const file_pair *pair)
(void)utimes(pair->dest_name, tv);
# endif
#elif defined(HAVE__FUTIME)
// Use one-second precision with Windows-specific _futime().
// We could use utime() too except that for some reason the
// timestamp will get reset at close(). With _futime() it works.
// This struct cannot be const as _futime() takes a non-const pointer.
struct _utimbuf buf = {
.actime = pair->src_st.st_atime,
.modtime = pair->src_st.st_mtime,
};
// Avoid warnings.
(void)atime_nsec;
(void)mtime_nsec;
(void)_futime(pair->dest_fd, &buf);
#elif defined(HAVE_UTIME)
// Use one-second precision. utime() doesn't support using file
// descriptor either. Some systems have broken utime() prototype
@ -649,6 +755,11 @@ io_open_src(const char *src_name)
const bool error = io_open_src_real(&pair);
signals_unblock();
#ifdef ENABLE_SANDBOX
if (!error)
io_sandbox_enter(pair.src_fd);
#endif
return error ? NULL : &pair;
}
@ -675,23 +786,22 @@ io_close_src(file_pair *pair, bool success)
#endif
if (pair->src_fd != STDIN_FILENO && pair->src_fd != -1) {
#ifdef TUKLIB_DOSLIKE
(void)close(pair->src_fd);
#endif
// If we are going to unlink(), do it before closing the file.
// This way there's no risk that someone replaces the file and
// happens to get same inode number, which would make us
// unlink() wrong file.
// Close the file before possibly unlinking it. On DOS-like
// systems this is always required since unlinking will fail
// if the file is open. On POSIX systems it usually works
// to unlink open files, but in some cases it doesn't and
// one gets EBUSY in errno.
//
// NOTE: DOS-like systems are an exception to this, because
// they don't allow unlinking files that are open. *sigh*
// xz 5.2.2 and older unlinked the file before closing it
// (except on DOS-like systems). The old code didn't handle
// EBUSY and could fail e.g. on some CIFS shares. The
// advantage of unlinking before closing is negligible
// (avoids a race between close() and stat()/lstat() and
// unlink()), so let's keep this simple.
(void)close(pair->src_fd);
if (success && !opt_keep_original)
io_unlink(pair->src_name, &pair->src_st);
#ifndef TUKLIB_DOSLIKE
(void)close(pair->src_fd);
#endif
}
return;
@ -1018,7 +1128,7 @@ io_read(file_pair *pair, io_buf *buf_union, size_t size)
}
#ifndef TUKLIB_DOSLIKE
if (errno == EAGAIN || errno == EWOULDBLOCK) {
if (IS_EAGAIN_OR_EWOULDBLOCK(errno)) {
const io_wait_ret ret = io_wait(pair,
mytime_get_flush_timeout(),
true);
@ -1106,7 +1216,7 @@ io_write_buf(file_pair *pair, const uint8_t *buf, size_t size)
}
#ifndef TUKLIB_DOSLIKE
if (errno == EAGAIN || errno == EWOULDBLOCK) {
if (IS_EAGAIN_OR_EWOULDBLOCK(errno)) {
if (io_wait(pair, -1, false) == IO_WAIT_MORE)
continue;

View file

@ -80,6 +80,12 @@ extern void io_write_to_user_abort_pipe(void);
extern void io_no_sparse(void);
#ifdef ENABLE_SANDBOX
/// \brief main() calls this if conditions for sandboxing have been met.
extern void io_allow_sandbox(void);
#endif
/// \brief Open the source file
extern file_pair *io_open_src(const char *src_name);

View file

@ -205,10 +205,31 @@ main(int argc, char **argv)
if (opt_mode != MODE_LIST)
signals_init();
#ifdef ENABLE_SANDBOX
// Set a flag that sandboxing is allowed if all these are true:
// - --files or --files0 wasn't used.
// - There is exactly one input file or we are reading from stdin.
// - We won't create any files: output goes to stdout or --test
// or --list was used. Note that --test implies opt_stdout = true
// but --list doesn't.
//
// This is obviously not ideal but it was easy to implement and
// it covers the most common use cases.
//
// TODO: Make sandboxing work for other situations too.
if (args.files_name == NULL && args.arg_count == 1
&& (opt_stdout || strcmp("-", args.arg_names[0]) == 0
|| opt_mode == MODE_LIST))
io_allow_sandbox();
#endif
// coder_run() handles compression, decompression, and testing.
// list_file() is for --list.
void (*run)(const char *filename) = opt_mode == MODE_LIST
? &list_file : &coder_run;
void (*run)(const char *filename) = &coder_run;
#ifdef HAVE_DECODERS
if (opt_mode == MODE_LIST)
run = &list_file;
#endif
// Process the files given on the command line. Note that if no names
// were given, args_parse() gave us a fake "-" filename.
@ -267,6 +288,7 @@ main(int argc, char **argv)
(void)fclose(args.files_file);
}
#ifdef HAVE_DECODERS
// All files have now been handled. If in --list mode, display
// the totals before exiting. We don't have signal handlers
// enabled in --list mode, so we don't need to check user_abort.
@ -274,6 +296,7 @@ main(int argc, char **argv)
assert(!user_abort);
list_totals();
}
#endif
#ifndef NDEBUG
coder_free();

View file

@ -45,6 +45,10 @@
# define STDERR_FILENO (fileno(stderr))
#endif
#ifdef HAVE_CAPSICUM
# define ENABLE_SANDBOX 1
#endif
#include "main.h"
#include "mytime.h"
#include "coder.h"
@ -56,4 +60,7 @@
#include "signals.h"
#include "suffix.h"
#include "util.h"
#include "list.h"
#ifdef HAVE_DECODERS
# include "list.h"
#endif

View file

@ -25,17 +25,20 @@
/* Define to 1 if you have the <byteswap.h> header file. */
/* #undef HAVE_BYTESWAP_H */
/* Define to 1 if Capsicum is available. */
/* #undef HAVE_CAPSICUM */
/* Define to 1 if the system has the type `CC_SHA256_CTX'. */
/* #undef HAVE_CC_SHA256_CTX */
/* Define to 1 if you have the `CC_SHA256_Init' function. */
/* #undef HAVE_CC_SHA256_INIT */
/* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the
/* Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the
CoreFoundation framework. */
/* #undef HAVE_CFLOCALECOPYCURRENT */
/* Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in
/* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in
the CoreFoundation framework. */
/* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
@ -67,6 +70,9 @@
to 0 if you don't. */
#define HAVE_DECL_PROGRAM_INVOCATION_NAME 0
/* Define to 1 if any of HAVE_DECODER_foo have been defined. */
#define HAVE_DECODERS 1
/* Define to 1 if arm decoder is enabled. */
#define HAVE_DECODER_ARM 1
@ -97,6 +103,9 @@
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if any of HAVE_ENCODER_foo have been defined. */
#define HAVE_ENCODERS 1
/* Define to 1 if arm encoder is enabled. */
#define HAVE_ENCODER_ARM 1
@ -182,9 +191,6 @@
/* Define to 1 to enable hc4 match finder. */
#define HAVE_MF_HC4 1
/* Define to 1 if you have the <minix/sha2.h> header file. */
/* #undef HAVE_MINIX_SHA2_H */
/* Define to 1 if getopt.h declares extern int optreset. */
#define HAVE_OPTRESET 1
@ -254,6 +260,9 @@
/* Define to 1 if you have the <sys/byteorder.h> header file. */
/* #undef HAVE_SYS_BYTEORDER_H */
/* Define to 1 if you have the <sys/capsicum.h> header file. */
/* #undef HAVE_SYS_CAPSICUM_H */
/* Define to 1 if you have the <sys/endian.h> header file. */
#define HAVE_SYS_ENDIAN_H 1
@ -291,6 +300,9 @@
/* Define to 1 if the system has the type `_Bool'. */
#define HAVE__BOOL 1
/* Define to 1 if you have the `_futime' function. */
/* #undef HAVE__FUTIME */
/* Define to 1 if _mm_movemask_epi8 is available. */
#if defined(__FreeBSD__) && defined(__amd64__)
#define HAVE__MM_MOVEMASK_EPI8 1
@ -323,7 +335,7 @@
#define PACKAGE_NAME "XZ Utils"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "XZ Utils 5.2.2"
#define PACKAGE_STRING "XZ Utils 5.2.3"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "xz"
@ -332,7 +344,7 @@
#define PACKAGE_URL "http://tukaani.org/xz/"
/* Define to the version of this package. */
#define PACKAGE_VERSION "5.2.2"
#define PACKAGE_VERSION "5.2.3"
/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
@ -352,6 +364,10 @@
pstat_getdynamic(). */
/* #undef TUKLIB_CPUCORES_PSTAT_GETDYNAMIC */
/* Define to 1 if the number of available CPU cores can be detected with
sched_getaffinity() */
/* #undef TUKLIB_CPUCORES_SCHED_GETAFFINITY */
/* Define to 1 if the number of available CPU cores can be detected with
sysconf(_SC_NPROCESSORS_ONLN) or sysconf(_SC_NPROC_ONLN). */
/* #undef TUKLIB_CPUCORES_SYSCONF */
@ -416,7 +432,7 @@
/* Version number of package */
#define VERSION "5.2.2"
#define VERSION "5.2.3"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */

View file

@ -1,12 +1,17 @@
# @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD$
.include <src.opts.mk>
PROG= tftpd
MAN= tftpd.8
SRCS= tftp-file.c tftp-io.c tftp-options.c tftp-transfer.c tftp-utils.c
SRCS+= tftpd.c
WFORMAT=0
.if ${MK_TCP_WRAPPERS} != "no"
CFLAGS+= -DLIBWRAP
LIBADD= wrap
.endif
.include <bsd.prog.mk>

View file

@ -66,7 +66,6 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <tcpd.h>
#include <unistd.h>
#include "tftp-file.h"
@ -75,6 +74,10 @@ __FBSDID("$FreeBSD$");
#include "tftp-transfer.h"
#include "tftp-options.h"
#ifdef LIBWRAP
#include <tcpd.h>
#endif
static void tftp_wrq(int peer, char *, ssize_t);
static void tftp_rrq(int peer, char *, ssize_t);
@ -281,6 +284,7 @@ main(int argc, char *argv[])
}
}
#ifdef LIBWRAP
/*
* See if the client is allowed to talk to me.
* (This needs to be done before the chroot())
@ -329,6 +333,7 @@ main(int argc, char *argv[])
"Full access allowed"
"in /etc/hosts.allow");
}
#endif
/*
* Since we exit here, we should do that only after the above

View file

@ -1396,11 +1396,12 @@ ino_adjust(struct suj_ino *sino)
ip = ino_read(ino);
mode = DIP(ip, di_mode) & IFMT;
if (nlink > LINK_MAX)
err_suj("ino %ju nlink manipulation error, new %d, old %d\n",
(uintmax_t)ino, nlink, DIP(ip, di_nlink));
err_suj("ino %ju nlink manipulation error, new %ju, old %d\n",
(uintmax_t)ino, (uintmax_t)nlink, DIP(ip, di_nlink));
if (debug)
printf("Adjusting ino %ju, nlink %d, old link %d lastmode %o\n",
(uintmax_t)ino, nlink, DIP(ip, di_nlink), sino->si_mode);
printf("Adjusting ino %ju, nlink %ju, old link %d lastmode %o\n",
(uintmax_t)ino, (uintmax_t)nlink, DIP(ip, di_nlink),
sino->si_mode);
if (mode == 0) {
if (debug)
printf("ino %ju, zero inode freeing bitmap\n",
@ -1419,8 +1420,9 @@ ino_adjust(struct suj_ino *sino)
/* If the inode doesn't have enough links to live, free it. */
if (nlink < reqlink) {
if (debug)
printf("ino %ju not enough links to live %d < %d\n",
(uintmax_t)ino, nlink, reqlink);
printf("ino %ju not enough links to live %ju < %ju\n",
(uintmax_t)ino, (uintmax_t)nlink,
(uintmax_t)reqlink);
ino_reclaim(ip, ino, mode);
return;
}
@ -1657,10 +1659,12 @@ ino_check(struct suj_ino *sino)
err_suj("Inode mode/directory type mismatch %o != %o\n",
mode, rrec->jr_mode);
if (debug)
printf("jrefrec: op %d ino %ju, nlink %d, parent %d, "
printf("jrefrec: op %d ino %ju, nlink %ju, parent %ju, "
"diroff %jd, mode %o, isat %d, isdot %d\n",
rrec->jr_op, (uintmax_t)rrec->jr_ino,
rrec->jr_nlink, rrec->jr_parent, rrec->jr_diroff,
(uintmax_t)rrec->jr_nlink,
(uintmax_t)rrec->jr_parent,
(uintmax_t)rrec->jr_diroff,
rrec->jr_mode, isat, isdot);
mode = rrec->jr_mode & IFMT;
if (rrec->jr_op == JOP_REMREF)
@ -1677,8 +1681,10 @@ ino_check(struct suj_ino *sino)
* by one.
*/
if (debug)
printf("ino %ju nlink %d newlinks %d removes %d dotlinks %d\n",
(uintmax_t)ino, nlink, newlinks, removes, dotlinks);
printf(
"ino %ju nlink %ju newlinks %ju removes %ju dotlinks %ju\n",
(uintmax_t)ino, (uintmax_t)nlink, (uintmax_t)newlinks,
(uintmax_t)removes, (uintmax_t)dotlinks);
nlink += newlinks;
nlink -= removes;
sino->si_linkadj = 1;
@ -1962,15 +1968,17 @@ ino_append(union jrec *rec)
mvrec = &rec->rec_jmvrec;
refrec = &rec->rec_jrefrec;
if (debug && mvrec->jm_op == JOP_MVREF)
printf("ino move: ino %d, parent %d, diroff %jd, oldoff %jd\n",
mvrec->jm_ino, mvrec->jm_parent, mvrec->jm_newoff,
mvrec->jm_oldoff);
printf("ino move: ino %ju, parent %ju, "
"diroff %jd, oldoff %jd\n",
(uintmax_t)mvrec->jm_ino, (uintmax_t)mvrec->jm_parent,
(uintmax_t)mvrec->jm_newoff, (uintmax_t)mvrec->jm_oldoff);
else if (debug &&
(refrec->jr_op == JOP_ADDREF || refrec->jr_op == JOP_REMREF))
printf("ino ref: op %d, ino %d, nlink %d, "
"parent %d, diroff %jd\n",
refrec->jr_op, refrec->jr_ino, refrec->jr_nlink,
refrec->jr_parent, refrec->jr_diroff);
printf("ino ref: op %d, ino %ju, nlink %ju, "
"parent %ju, diroff %jd\n",
refrec->jr_op, (uintmax_t)refrec->jr_ino,
(uintmax_t)refrec->jr_nlink,
(uintmax_t)refrec->jr_parent, (uintmax_t)refrec->jr_diroff);
sino = ino_lookup(((struct jrefrec *)rec)->jr_ino, 1);
sino->si_hasrecs = 1;
srec = errmalloc(sizeof(*srec));
@ -2182,9 +2190,10 @@ blk_build(struct jblkrec *blkrec)
if (debug)
printf("blk_build: op %d blkno %jd frags %d oldfrags %d "
"ino %d lbn %jd\n",
blkrec->jb_op, blkrec->jb_blkno, blkrec->jb_frags,
blkrec->jb_oldfrags, blkrec->jb_ino, blkrec->jb_lbn);
"ino %ju lbn %jd\n",
blkrec->jb_op, (uintmax_t)blkrec->jb_blkno,
blkrec->jb_frags, blkrec->jb_oldfrags,
(uintmax_t)blkrec->jb_ino, (uintmax_t)blkrec->jb_lbn);
blk = blknum(fs, blkrec->jb_blkno);
frag = fragnum(fs, blkrec->jb_blkno);
@ -2232,8 +2241,9 @@ ino_build_trunc(struct jtrncrec *rec)
struct suj_ino *sino;
if (debug)
printf("ino_build_trunc: op %d ino %d, size %jd\n",
rec->jt_op, rec->jt_ino, rec->jt_size);
printf("ino_build_trunc: op %d ino %ju, size %jd\n",
rec->jt_op, (uintmax_t)rec->jt_ino,
(uintmax_t)rec->jt_size);
sino = ino_lookup(rec->jt_ino, 1);
if (rec->jt_op == JOP_SYNC) {
sino->si_trunc = NULL;

View file

@ -1666,6 +1666,7 @@ pr_icmph(struct icmp *icp)
static void
pr_iph(struct ip *ip)
{
struct in_addr ina;
u_char *cp;
int hlen;
@ -1681,8 +1682,10 @@ pr_iph(struct ip *ip)
(u_long) ntohl(ip->ip_off) & 0x1fff);
(void)printf(" %02x %02x %04x", ip->ip_ttl, ip->ip_p,
ntohs(ip->ip_sum));
(void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_src.s_addr));
(void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_dst.s_addr));
memcpy(&ina, &ip->ip_src.s_addr, sizeof ina);
(void)printf(" %s ", inet_ntoa(ina));
memcpy(&ina, &ip->ip_dst.s_addr, sizeof ina);
(void)printf(" %s ", inet_ntoa(ina));
/* dump any option bytes */
while (hlen-- > 20) {
(void)printf("%02x", *cp++);

View file

@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"/
.Dd October 17, 2016
.Dd January 6, 2017
.Dt RTWN_USB 4
.Os
.Sh NAME
@ -93,6 +93,8 @@ based USB wireless network adapters, including:
.It "TP-Link Archer T4U" Ta USB 3.0
.It "TP-LINK TL-WN723N v3" Ta USB 2.0
.It "TP-LINK TL-WN725N v2" Ta USB 2.0
.It "TP-LINK TL-WN821N v4" Ta USB 2.0
.It "TP-LINK TL-WN823N v1" Ta USB 2.0
.It "TRENDnet TEW-805UB" Ta USB 3.0
.It "ZyXEL NWD6605" Ta USB 3.0
.El

View file

@ -1629,7 +1629,7 @@ and related programs.
Set to not build USB-related programs and libraries.
.It Va WITHOUT_USB_GADGET_EXAMPLES
.\" from FreeBSD: head/tools/build/options/WITHOUT_USB_GADGET_EXAMPLES 274665 2014-11-18 17:06:50Z imp
Set to build USB gadget kernel modules.
Set to not build USB gadget kernel modules.
.It Va WITHOUT_UTMPX
.\" from FreeBSD: head/tools/build/options/WITHOUT_UTMPX 231530 2012-02-11 20:28:42Z ed
Set to not build user accounting tools such as

View file

@ -71,7 +71,7 @@
{TAS} t1
{ATMPE} t1
{RWWP} t1
{Reserved} *t1
{SBLP (Supported Block Lengths and Protection)} t1
{Autoload Mode} t3
{Ready AEN Holdoff Period} i2
{Busy Timeout Period} i2
@ -148,6 +148,15 @@
{Minimum Pre-fetch} i2
{Maximum Pre-fetch} i2
{Maximum Pre-fetch Ceiling} i2
{FSW (Force Sequential Write)} t1
{LBCSS (Logical Block Cache Segment Size)} t1
{DRA (Disable Read-Ahead)} t1
{Vendor Specific} t2
{SYNC_PROG} t1
{NV_DIS} t1
{Number of Cache Segments} i1
{Cache Segment Size} i2
{Reserved} *t4
}
0x05 "Flexible Disk Page" {
@ -224,7 +233,8 @@
{Head Offset Count} i1
{Data Strobe Offset Count} i1
{LBPERE (LBP Error Reporting Enabled)} t1
{Reserved} *t7
{MWR (Misaligned Write Reporting)} t2
{Reserved} *t5
{Write Retry Count} i1
{Reserved} *i1
{Recovery Time Limit} i2

View file

@ -775,6 +775,7 @@ linux_connect(struct thread *td, struct linux_connect_args *args)
cap_rights_t rights;
struct socket *so;
struct sockaddr *sa;
struct file *fp;
u_int fflag;
int error;
@ -792,24 +793,23 @@ linux_connect(struct thread *td, struct linux_connect_args *args)
* Linux doesn't return EISCONN the first time it occurs,
* when on a non-blocking socket. Instead it returns the
* error getsockopt(SOL_SOCKET, SO_ERROR) would return on BSD.
*
* XXXRW: Instead of using fgetsock(), check that it is a
* socket and use the file descriptor reference instead of
* creating a new one.
*/
error = fgetsock(td, args->s, cap_rights_init(&rights, CAP_CONNECT),
&so, &fflag);
if (error == 0) {
error = EISCONN;
if (fflag & FNONBLOCK) {
SOCK_LOCK(so);
if (so->so_emuldata == 0)
error = so->so_error;
so->so_emuldata = (void *)1;
SOCK_UNLOCK(so);
}
fputsock(so);
error = getsock_cap(td, args->s, cap_rights_init(&rights, CAP_CONNECT),
&fp, &fflag, NULL);
if (error != 0)
return (error);
error = EISCONN;
so = fp->f_data;
if (fflag & FNONBLOCK) {
SOCK_LOCK(so);
if (so->so_emuldata == 0)
error = so->so_error;
so->so_emuldata = (void *)1;
SOCK_UNLOCK(so);
}
fdrop(fp, td);
return (error);
}

View file

@ -496,7 +496,7 @@ contrib/dev/acpica/components/utilities/utuuid.c optional acpi acpi_debug
contrib/dev/acpica/components/utilities/utxface.c optional acpi
contrib/dev/acpica/components/utilities/utxferror.c optional acpi
contrib/dev/acpica/components/utilities/utxfinit.c optional acpi
#contrib/dev/acpica/components/utilities/utxfmutex.c optional acpi
contrib/dev/acpica/os_specific/service_layers/osgendbg.c optional acpi acpi_debug
contrib/ipfilter/netinet/fil.c optional ipfilter inet \
compile-with "${NORMAL_C} ${NO_WSELF_ASSIGN} -Wno-unused -I$S/contrib/ipfilter"
contrib/ipfilter/netinet/ip_auth.c optional ipfilter inet \

View file

@ -17,7 +17,7 @@ dst="$(realpath .)/acpi_ca_destination"
fulldirs="common compiler components include os_specific"
# files to remove
stripdirs="generate libraries tests tools"
stripdirs="generate libraries parsers preprocessor tests tools"
stripfiles="Makefile README accygwin.h acdragonfly.h acdragonflyex.h \
acefi.h acefiex.h achaiku.h acintel.h aclinux.h aclinuxex.h \
acmacosx.h acmsvc.h acmsvcex.h acnetbsd.h acos2.h acqnx.h \

View file

@ -1,3 +1,92 @@
----------------------------------------
22 December 2016. Summary of changes for version 20161222:
1) ACPICA kernel-resident subsystem:
AML Debugger: Implemented a new mechanism to simplify and enhance
debugger integration into all environments, including kernel debuggers
and user-space utilities, as well as remote debug services. This
mechanism essentially consists of new OSL interfaces to support debugger
initialization/termination, as well as wait/notify interfaces to perform
the debugger handshake with the host. Lv Zheng.
New OSL interfaces:
AcpiOsInitializeDebugger (void)
AcpiOsTerminateDebugger (void)
AcpiOsWaitCommandReady (void)
AcpiOsNotifyCommandComplete (void)
New OS services layer:
osgendbg.c -- Example implementation, and used for AcpiExec
Update for Generic Address Space (GAS) support: Although the AccessWidth
and/or BitOffset fields of the GAS are not often used, this change now
fully supports these fields. This affects the internal support for FADT
registers, registers in other ACPI data tables, and the AcpiRead and
AcpiWrite public interfaces. Lv Zheng.
Sleep support: In order to simplify integration of ACPI sleep for the
various host operating systems, a new OSL interface has been introduced.
AcpiOsEnterSleep allows the host to perform any required operations
before the final write to the sleep control register(s) is performed by
ACPICA. Lv Zheng.
New OSL interface:
AcpiOsEnterSleep(SleepState, RegisterAValue, RegisterBValue)
Called from these internal interfaces:
AcpiHwLegacySleep
AcpiHwExtendedSleep
EFI support: Added a very small EFI/ACPICA example application. Provides
a simple demo for EFI integration, as well as assisting with resolution
of issues related to customer ACPICA/EFI integration. Lv Zheng. See:
source/tools/efihello/efihello.c
Local C library: Implemented several new functions to enhance ACPICA
portability, for environments where these clib functions are not
available (such as EFI). Lv Zheng:
putchar
getchar
strpbrk
strtok
memmove
Fixed a regression where occasionally a valid resource descriptor was
incorrectly detected as invalid at runtime, and a
AE_AML_NO_RESOURCE_END_TAG was returned.
Fixed a problem with the recently implemented support that enables
control method invocations as Target operands to many ASL operators.
Warnings of this form: "Needed type [Reference], found [Processor]" were
seen at runtime for some method invocations.
Example Code and Data Size: These are the sizes for the OS-independent
acpica.lib produced by the Microsoft Visual C++ 9.0 32-bit compiler. The
debug version of the code includes the debug output trace mechanism and
has a much larger code and data size.
Current Release:
Non-Debug Version: 141.5K Code, 58.5K Data, 200.0K Total
Debug Version: 201.7K Code, 82.7K Data, 284.4K Total
Previous Release:
Non-Debug Version: 140.5K Code, 58.5K Data, 198.9K Total
Debug Version: 201.3K Code, 82.7K Data, 284.0K Total
2) iASL Compiler/Disassembler and Tools:
Disassembler: Enhanced output by adding the capability to detect and
disassemble ASL Switch/Case statements back to the original ASL source
code instead of if/else blocks. David Box.
AcpiHelp: Split a large file into separate files based upon
functionality/purpose. New files are:
ahaml.c
ahasl.c
----------------------------------------
17 November 2016. Summary of changes for version 20161117:

View file

@ -403,7 +403,7 @@ AcValidateTableHeader (
UINT32 i;
ACPI_FUNCTION_TRACE ("AcValidateTableHeader");
ACPI_FUNCTION_TRACE (AcValidateTableHeader);
/* Read a potential table header */

View file

@ -51,7 +51,7 @@ const AH_TABLE *
AcpiAhGetTableInfo (
char *Signature);
extern const AH_TABLE AcpiSupportedTables[];
extern const AH_TABLE Gbl_AcpiSupportedTables[];
/*******************************************************************************
@ -73,7 +73,7 @@ AcpiAhGetTableInfo (
const AH_TABLE *Info;
for (Info = AcpiSupportedTables; Info->Signature; Info++)
for (Info = Gbl_AcpiSupportedTables; Info->Signature; Info++)
{
if (ACPI_COMPARE_NAME (Signature, Info->Signature))
{
@ -89,7 +89,7 @@ AcpiAhGetTableInfo (
* Note: Any tables added here should be duplicated within AcpiDmTableData
* in the file common/dmtable.c
*/
const AH_TABLE AcpiSupportedTables[] =
const AH_TABLE Gbl_AcpiSupportedTables[] =
{
{ACPI_SIG_ASF, "Alert Standard Format table"},
{ACPI_SIG_BERT, "Boot Error Record Table"},

View file

@ -52,7 +52,7 @@
/*
* Table of "known" (ACPI-related) UUIDs
*/
const AH_UUID AcpiUuids[] =
const AH_UUID Gbl_AcpiUuids[] =
{
{"[Controllers]", NULL},
{"GPIO Controller", UUID_GPIO_CONTROLLER},
@ -112,7 +112,7 @@ AcpiAhMatchUuid (
/* Walk the table of known ACPI-related UUIDs */
for (Info = AcpiUuids; Info->Description; Info++)
for (Info = Gbl_AcpiUuids; Info->Description; Info++)
{
/* Null string means desciption is a UUID class */

View file

@ -73,7 +73,6 @@ Usage (
ACPI_OPTION ("-I <dir>", "Specify additional include directory");
ACPI_OPTION ("-p <prefix>", "Specify path/filename prefix for all output files");
ACPI_OPTION ("-v", "Display compiler version");
ACPI_OPTION ("-vd", "Display compiler build date and time");
ACPI_OPTION ("-vo", "Enable optimization comments");
ACPI_OPTION ("-vs", "Disable signon");

View file

@ -70,9 +70,6 @@ AslDoResponseFile (
#define ASL_TOKEN_SEPARATORS " \t\n"
#define ASL_SUPPORTED_OPTIONS "@:a:b|c|d^D:e:f^gh^i|I:l^m:no|p:P^r:s|t|T+G^v^w|x:z"
static char ASL_BUILD_DATE[] = __DATE__;
static char ASL_BUILD_TIME[] = __TIME__;
/*******************************************************************************
*
@ -727,12 +724,6 @@ AslDoOptions (
Gbl_NoErrors = TRUE;
break;
case 'd':
printf ("%s Build date/time: %s %s\n",
ASL_COMPILER_NAME, ASL_BUILD_DATE, ASL_BUILD_TIME);
exit (0);
case 'e':
/* Disable all warning/remark messages (errors only) */

View file

@ -155,7 +155,7 @@ UtDisplaySupportedTables (
/* All ACPI tables with the common table header */
printf ("\n Supported ACPI tables:\n");
for (TableData = AcpiSupportedTables, i = 1;
for (TableData = Gbl_AcpiSupportedTables, i = 1;
TableData->Signature; TableData++, i++)
{
printf ("%8u) %s %s\n", i,

View file

@ -63,10 +63,6 @@ static UINT32
AcpiDbMatchCommand (
char *UserCommand);
static void
AcpiDbSingleThread (
void);
static void
AcpiDbDisplayCommandInfo (
const char *Command,
@ -1231,61 +1227,17 @@ void ACPI_SYSTEM_XFACE
AcpiDbExecuteThread (
void *Context)
{
ACPI_STATUS Status = AE_OK;
ACPI_STATUS MStatus;
while (Status != AE_CTRL_TERMINATE && !AcpiGbl_DbTerminateLoop)
{
AcpiGbl_MethodExecuting = FALSE;
AcpiGbl_StepToNextCall = FALSE;
MStatus = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
ACPI_WAIT_FOREVER);
if (ACPI_FAILURE (MStatus))
{
return;
}
Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete);
}
(void) AcpiDbUserCommands ();
AcpiGbl_DbThreadsTerminated = TRUE;
}
/*******************************************************************************
*
* FUNCTION: AcpiDbSingleThread
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Debugger execute thread. Waits for a command line, then
* simply dispatches it.
*
******************************************************************************/
static void
AcpiDbSingleThread (
void)
{
AcpiGbl_MethodExecuting = FALSE;
AcpiGbl_StepToNextCall = FALSE;
(void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
}
/*******************************************************************************
*
* FUNCTION: AcpiDbUserCommands
*
* PARAMETERS: Prompt - User prompt (depends on mode)
* Op - Current executing parse op
* PARAMETERS: None
*
* RETURN: None
*
@ -1296,8 +1248,7 @@ AcpiDbSingleThread (
ACPI_STATUS
AcpiDbUserCommands (
char Prompt,
ACPI_PARSE_OBJECT *Op)
void)
{
ACPI_STATUS Status = AE_OK;
@ -1308,55 +1259,33 @@ AcpiDbUserCommands (
while (!AcpiGbl_DbTerminateLoop)
{
/* Force output to console until a command is entered */
/* Wait the readiness of the command */
AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
/* Different prompt if method is executing */
if (!AcpiGbl_MethodExecuting)
{
AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
}
else
{
AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
}
/* Get the user input line */
Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
ACPI_DB_LINE_BUFFER_SIZE, NULL);
Status = AcpiOsWaitCommandReady ();
if (ACPI_FAILURE (Status))
{
ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
return (Status);
break;
}
/* Check for single or multithreaded debug */
/* Just call to the command line interpreter */
if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
AcpiGbl_MethodExecuting = FALSE;
AcpiGbl_StepToNextCall = FALSE;
(void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
/* Notify the completion of the command */
Status = AcpiOsNotifyCommandComplete ();
if (ACPI_FAILURE (Status))
{
/*
* Signal the debug thread that we have a command to execute,
* and wait for the command to complete.
*/
AcpiOsReleaseMutex (AcpiGbl_DbCommandReady);
Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete,
ACPI_WAIT_FOREVER);
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
else
{
/* Just call to the command line interpreter */
AcpiDbSingleThread ();
break;
}
}
if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
{
ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
}
return (Status);
}

View file

@ -95,50 +95,23 @@ AcpiDbStartCommand (
AcpiGbl_MethodExecuting = TRUE;
Status = AE_CTRL_TRUE;
while (Status == AE_CTRL_TRUE)
{
if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
/* Notify the completion of the command */
Status = AcpiOsNotifyCommandComplete ();
if (ACPI_FAILURE (Status))
{
/* Handshake with the front-end that gets user command lines */
AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete);
Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
ACPI_WAIT_FOREVER);
if (ACPI_FAILURE (Status))
{
return (Status);
}
goto ErrorExit;
}
else
/* Wait the readiness of the command */
Status = AcpiOsWaitCommandReady ();
if (ACPI_FAILURE (Status))
{
/* Single threaded, we must get a command line ourselves */
/* Force output to console until a command is entered */
AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
/* Different prompt if method is executing */
if (!AcpiGbl_MethodExecuting)
{
AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
}
else
{
AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
}
/* Get the user input line */
Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
ACPI_DB_LINE_BUFFER_SIZE, NULL);
if (ACPI_FAILURE (Status))
{
ACPI_EXCEPTION ((AE_INFO, Status,
"While parsing command line"));
return (Status);
}
goto ErrorExit;
}
Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);
@ -146,6 +119,12 @@ AcpiDbStartCommand (
/* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */
ErrorExit:
if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
{
ACPI_EXCEPTION ((AE_INFO, Status,
"While parsing/handling command line"));
}
return (Status);
}
@ -493,16 +472,7 @@ AcpiInitializeDebugger (
{
/* These were created with one unit, grab it */
Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete,
ACPI_WAIT_FOREVER);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not get debugger mutex\n");
return_ACPI_STATUS (Status);
}
Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
ACPI_WAIT_FOREVER);
Status = AcpiOsInitializeDebugger ();
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not get debugger mutex\n");
@ -556,14 +526,14 @@ AcpiTerminateDebugger (
if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
{
AcpiOsReleaseMutex (AcpiGbl_DbCommandReady);
/* Wait the AML Debugger threads */
while (!AcpiGbl_DbThreadsTerminated)
{
AcpiOsSleep (100);
}
AcpiOsTerminateDebugger ();
}
if (AcpiGbl_DbBuffer)

View file

@ -68,6 +68,13 @@ static void
AcpiDmPromoteSubtree (
ACPI_PARSE_OBJECT *StartOp);
static BOOLEAN
AcpiDmIsSwitchBlock (
ACPI_PARSE_OBJECT *Op);
static BOOLEAN
AcpiDmIsCaseBlock (
ACPI_PARSE_OBJECT *Op);
/*******************************************************************************
*
@ -968,6 +975,28 @@ AcpiDmDisassembleOneOp (
AcpiDmNamestring (Op->Common.Value.Name);
break;
case AML_WHILE_OP:
if (AcpiDmIsSwitchBlock(Op))
{
AcpiOsPrintf ("%s", "Switch");
break;
}
AcpiOsPrintf ("%s", OpInfo->Name);
break;
case AML_IF_OP:
if (Op->Common.DisasmOpcode == ACPI_DASM_CASE)
{
AcpiOsPrintf ("%s", "Case");
break;
}
AcpiOsPrintf ("%s", OpInfo->Name);
break;
case AML_ELSE_OP:
AcpiDmConvertToElseIf (Op);
@ -1078,6 +1107,12 @@ AcpiDmConvertToElseIf (
{
/* Not a proper Else..If sequence, cannot convert to ElseIf */
if (OriginalElseOp->Common.DisasmOpcode == ACPI_DASM_DEFAULT)
{
AcpiOsPrintf ("%s", "Default");
return;
}
AcpiOsPrintf ("%s", "Else");
return;
}
@ -1087,13 +1122,42 @@ AcpiDmConvertToElseIf (
ElseOp = IfOp->Common.Next;
if (ElseOp && ElseOp->Common.Next)
{
if (OriginalElseOp->Common.DisasmOpcode == ACPI_DASM_DEFAULT)
{
AcpiOsPrintf ("%s", "Default");
return;
}
AcpiOsPrintf ("%s", "Else");
return;
}
/* Emit ElseIf, mark the IF as now an ELSEIF */
if (OriginalElseOp->Common.DisasmOpcode == ACPI_DASM_DEFAULT)
{
/*
* There is an ElseIf but in this case the Else is actually
* a Default block for a Switch/Case statement. No conversion.
*/
AcpiOsPrintf ("%s", "Default");
return;
}
if (OriginalElseOp->Common.DisasmOpcode == ACPI_DASM_CASE)
{
/*
* This ElseIf is actually a Case block for a Switch/Case
* statement. Print Case but do not return so that we can
* promote the subtree and keep the indentation level.
*/
AcpiOsPrintf ("%s", "Case");
}
else
{
/* Emit ElseIf, mark the IF as now an ELSEIF */
AcpiOsPrintf ("%s", "ElseIf");
}
AcpiOsPrintf ("%s", "ElseIf");
IfOp->Common.DisasmFlags |= ACPI_PARSEOP_ELSEIF;
/* The IF parent will now be the same as the original ELSE parent */
@ -1184,3 +1248,400 @@ AcpiDmPromoteSubtree (
Op = Op->Common.Next;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmIsTempName
*
* PARAMETERS: Op - Object to be examined
*
* RETURN: TRUE if object is a temporary (_T_x) name
*
* DESCRIPTION: Determine if an object is a temporary name and ignore it.
* Temporary names are only used for Switch statements. This
* function depends on this restriced usage.
*
******************************************************************************/
BOOLEAN
AcpiDmIsTempName (
ACPI_PARSE_OBJECT *Op)
{
char *Temp;
if (Op->Common.AmlOpcode != AML_NAME_OP)
{
return (FALSE);
}
Temp = (char *)(Op->Common.Aml);
++Temp;
if (strncmp(Temp, "_T_", 3))
{
return (FALSE);
}
/* Ignore Op */
Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
return (TRUE);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmIsSwitchBlock
*
* PARAMETERS: Op - While Object
*
* RETURN: TRUE if While block can be converted to a Switch/Case block
*
* DESCRIPTION: Determines if While block is a Switch/Case statement. Modifies
* parse tree to allow for Switch/Case disassembly during walk.
*
* EXAMPLE: Example of parse tree to be converted
*
* While
* One
* Store
* ByteConst
* -NamePath-
* If
* LEqual
* -NamePath-
* Zero
* Return
* One
* Else
* Return
* WordConst
* Break
*
******************************************************************************/
static BOOLEAN
AcpiDmIsSwitchBlock (
ACPI_PARSE_OBJECT *Op)
{
ACPI_PARSE_OBJECT *OneOp;
ACPI_PARSE_OBJECT *StoreOp;
ACPI_PARSE_OBJECT *NamePathOp;
ACPI_PARSE_OBJECT *PredicateOp;
ACPI_PARSE_OBJECT *CurrentOp;
ACPI_PARSE_OBJECT *TempOp;
/* Check for One Op Predicate */
OneOp = AcpiPsGetArg (Op, 0);
if (!OneOp || (OneOp->Common.AmlOpcode != AML_ONE_OP))
{
return (FALSE);
}
/* Check for Store Op */
StoreOp = OneOp->Common.Next;
if (!StoreOp || (StoreOp->Common.AmlOpcode != AML_STORE_OP))
{
return (FALSE);
}
/* Check for Name Op with _T_ string */
NamePathOp = AcpiPsGetArg (StoreOp, 1);
if (!NamePathOp || (NamePathOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP))
{
return (FALSE);
}
if (strncmp((char *)(NamePathOp->Common.Aml), "_T_", 3))
{
return (FALSE);
}
/* This is a Switch/Case control block */
/* Ignore the One Op Predicate */
OneOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
/* Ignore the Store Op, but not the children */
StoreOp->Common.DisasmOpcode = ACPI_DASM_IGNORE_SINGLE;
/*
* First arg of Store Op is the Switch condition.
* Mark it as a Switch predicate and as a parameter list for paren
* closing and correct indentation.
*/
PredicateOp = AcpiPsGetArg (StoreOp, 0);
PredicateOp->Common.DisasmOpcode = ACPI_DASM_SWITCH_PREDICATE;
PredicateOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
/* Ignore the Name Op */
NamePathOp->Common.DisasmFlags = ACPI_PARSEOP_IGNORE;
/* Remaining opcodes are the Case statements (If/ElseIf's) */
CurrentOp = StoreOp->Common.Next;
while (AcpiDmIsCaseBlock (CurrentOp))
{
/* Block is a Case structure */
if (CurrentOp->Common.AmlOpcode == AML_ELSE_OP)
{
/* ElseIf */
CurrentOp->Common.DisasmOpcode = ACPI_DASM_CASE;
CurrentOp = AcpiPsGetArg (CurrentOp, 0);
}
/* If */
CurrentOp->Common.DisasmOpcode = ACPI_DASM_CASE;
/*
* Mark the parse tree for Case disassembly. There are two
* types of Case statements. The first type of statement begins with
* an LEqual. The second starts with an LNot and uses a Match statement
* on a Package of constants.
*/
TempOp = AcpiPsGetArg (CurrentOp, 0);
switch (TempOp->Common.AmlOpcode)
{
case (AML_LEQUAL_OP):
/* Ignore just the LEqual Op */
TempOp->Common.DisasmOpcode = ACPI_DASM_IGNORE_SINGLE;
/* Ignore the NamePath Op */
TempOp = AcpiPsGetArg (TempOp, 0);
TempOp->Common.DisasmFlags = ACPI_PARSEOP_IGNORE;
/*
* Second arg of LEqual will be the Case predicate.
* Mark it as a predicate and also as a parameter list for paren
* closing and correct indentation.
*/
PredicateOp = TempOp->Common.Next;
PredicateOp->Common.DisasmOpcode = ACPI_DASM_SWITCH_PREDICATE;
PredicateOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
break;
case (AML_LNOT_OP):
/*
* The Package will be the predicate of the Case statement.
* It's under:
* LNOT
* LEQUAL
* MATCH
* PACKAGE
*/
/* Get the LEqual Op from LNot */
TempOp = AcpiPsGetArg (TempOp, 0);
/* Get the Match Op from LEqual */
TempOp = AcpiPsGetArg (TempOp, 0);
/* Get the Package Op from Match */
PredicateOp = AcpiPsGetArg (TempOp, 0);
/* Mark as parameter list for paren closing */
PredicateOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
/*
* The Package list would be too deeply indented if we
* chose to simply ignore the all the parent opcodes, so
* we rearrange the parse tree instead.
*/
/*
* Save the second arg of the If/Else Op which is the
* block code of code for this Case statement.
*/
TempOp = AcpiPsGetArg (CurrentOp, 1);
/*
* Move the Package Op to the child (predicate) of the
* Case statement.
*/
CurrentOp->Common.Value.Arg = PredicateOp;
PredicateOp->Common.Parent = CurrentOp;
/* Add the block code */
PredicateOp->Common.Next = TempOp;
break;
default:
/* Should never get here */
break;
}
/* Advance to next Case block */
CurrentOp = CurrentOp->Common.Next;
}
/* If CurrentOp is now an Else, then this is a Default block */
if (CurrentOp && CurrentOp->Common.AmlOpcode == AML_ELSE_OP)
{
CurrentOp->Common.DisasmOpcode = ACPI_DASM_DEFAULT;
}
/*
* From the first If advance to the Break op. It's possible to
* have an Else (Default) op here when there is only one Case
* statement, so check for it.
*/
CurrentOp = StoreOp->Common.Next->Common.Next;
if (CurrentOp->Common.AmlOpcode == AML_ELSE_OP)
{
CurrentOp = CurrentOp->Common.Next;
}
/* Ignore the Break Op */
CurrentOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
return (TRUE);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmIsCaseBlock
*
* PARAMETERS: Op - Object to test
*
* RETURN: TRUE if Object is beginning of a Case block.
*
* DESCRIPTION: Determines if an Object is the beginning of a Case block for a
* Switch/Case statement. Parse tree must be one of the following
* forms:
*
* Else (Optional)
* If
* LEqual
* -NamePath- _T_x
*
* Else (Optional)
* If
* LNot
* LEqual
* Match
* Package
* ByteConst
* -NamePath- _T_x
*
******************************************************************************/
static BOOLEAN
AcpiDmIsCaseBlock (
ACPI_PARSE_OBJECT *Op)
{
ACPI_PARSE_OBJECT *CurrentOp;
if (!Op)
{
return (FALSE);
}
/* Look for an If or ElseIf */
CurrentOp = Op;
if (CurrentOp->Common.AmlOpcode == AML_ELSE_OP)
{
CurrentOp = AcpiPsGetArg (CurrentOp, 0);
if (!CurrentOp)
{
return (FALSE);
}
}
if (!CurrentOp || CurrentOp->Common.AmlOpcode != AML_IF_OP)
{
return (FALSE);
}
/* Child must be LEqual or LNot */
CurrentOp = AcpiPsGetArg (CurrentOp, 0);
if (!CurrentOp)
{
return (FALSE);
}
switch (CurrentOp->Common.AmlOpcode)
{
case (AML_LEQUAL_OP):
/* Next child must be NamePath with string _T_ */
CurrentOp = AcpiPsGetArg (CurrentOp, 0);
if (!CurrentOp || !CurrentOp->Common.Value.Name ||
strncmp(CurrentOp->Common.Value.Name, "_T_", 3))
{
return (FALSE);
}
break;
case (AML_LNOT_OP):
/* Child of LNot must be LEqual op */
CurrentOp = AcpiPsGetArg (CurrentOp, 0);
if (!CurrentOp || (CurrentOp->Common.AmlOpcode != AML_LEQUAL_OP))
{
return (FALSE);
}
/* Child of LNot must be Match op */
CurrentOp = AcpiPsGetArg (CurrentOp, 0);
if (!CurrentOp || (CurrentOp->Common.AmlOpcode != AML_MATCH_OP))
{
return (FALSE);
}
/* First child of Match must be Package op */
CurrentOp = AcpiPsGetArg (CurrentOp, 0);
if (!CurrentOp || (CurrentOp->Common.AmlOpcode != AML_PACKAGE_OP))
{
return (FALSE);
}
/* Third child of Match must be NamePath with string _T_ */
CurrentOp = AcpiPsGetArg (CurrentOp->Common.Parent, 2);
if (!CurrentOp || !CurrentOp->Common.Value.Name ||
strncmp(CurrentOp->Common.Value.Name, "_T_", 3))
{
return (FALSE);
}
break;
default:
return (FALSE);
}
return (TRUE);
}

View file

@ -455,6 +455,20 @@ AcpiDmDescendingOp (
return (AE_CTRL_DEPTH);
}
if (AcpiDmIsTempName(Op))
{
/* Ignore compiler generated temporary names */
return (AE_CTRL_DEPTH);
}
if (Op->Common.DisasmOpcode == ACPI_DASM_IGNORE_SINGLE)
{
/* Ignore this op, but not it's children */
return (AE_OK);
}
if (Op->Common.AmlOpcode == AML_IF_OP)
{
NextOp = AcpiPsGetDepthNext (NULL, Op);
@ -889,7 +903,8 @@ AcpiDmAscendingOp (
ACPI_PARSE_OBJECT *ParentOp;
if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE ||
Op->Common.DisasmOpcode == ACPI_DASM_IGNORE_SINGLE)
{
/* Ignore this op -- it was handled elsewhere */
@ -1049,9 +1064,12 @@ AcpiDmAscendingOp (
/*
* Just completed a parameter node for something like "Buffer (param)".
* Close the paren and open up the term list block with a brace
* Close the paren and open up the term list block with a brace.
*
* Switch predicates don't have a Next node but require a closing paren
* and opening brace.
*/
if (Op->Common.Next)
if (Op->Common.Next || Op->Common.DisasmOpcode == ACPI_DASM_SWITCH_PREDICATE)
{
AcpiOsPrintf (")");
@ -1066,6 +1084,13 @@ AcpiDmAscendingOp (
AcpiDmPredefinedDescription (ParentOp);
}
/* Correct the indentation level for Switch and Case predicates */
if (Op->Common.DisasmOpcode == ACPI_DASM_SWITCH_PREDICATE)
{
--Level;
}
AcpiOsPrintf ("\n");
AcpiDmIndent (Level - 1);
AcpiOsPrintf ("{\n");

View file

@ -224,7 +224,7 @@ AcpiExLoadTableOp (
AcpiExEnterInterpreter ();
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
return_ACPI_STATUS (Status);
}
Status = AcpiExAddTable (TableIndex, &DdbHandle);

View file

@ -946,20 +946,9 @@ AcpiExInsertIntoField (
AccessBitWidth = ACPI_MUL_8 (ObjDesc->CommonField.AccessByteWidth);
/*
* Create the bitmasks used for bit insertion.
* Note: This if/else is used to bypass compiler differences with the
* shift operator
*/
if (AccessBitWidth == ACPI_INTEGER_BIT_SIZE)
{
WidthMask = ACPI_UINT64_MAX;
}
else
{
WidthMask = ACPI_MASK_BITS_ABOVE (AccessBitWidth);
}
/* Create the bitmasks used for bit insertion */
WidthMask = ACPI_MASK_BITS_ABOVE_64 (AccessBitWidth);
Mask = WidthMask &
ACPI_MASK_BITS_BELOW (ObjDesc->CommonField.StartFieldBitOffset);

View file

@ -113,7 +113,7 @@ AcpiHwExtendedSleep (
UINT8 SleepState)
{
ACPI_STATUS Status;
UINT8 SleepTypeValue;
UINT8 SleepControl;
UINT64 SleepStatus;
@ -139,10 +139,6 @@ AcpiHwExtendedSleep (
AcpiGbl_SystemAwakeAndRunning = FALSE;
/* Flush caches, as per ACPI specification */
ACPI_FLUSH_CPU_CACHE ();
/*
* Set the SLP_TYP and SLP_EN bits.
*
@ -152,11 +148,24 @@ AcpiHwExtendedSleep (
ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
"Entering sleep state [S%u]\n", SleepState));
SleepTypeValue = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) &
ACPI_X_SLEEP_TYPE_MASK);
SleepControl = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) &
ACPI_X_SLEEP_TYPE_MASK) | ACPI_X_SLEEP_ENABLE;
Status = AcpiWrite ((UINT64) (SleepTypeValue | ACPI_X_SLEEP_ENABLE),
&AcpiGbl_FADT.SleepControl);
/* Flush caches, as per ACPI specification */
ACPI_FLUSH_CPU_CACHE ();
Status = AcpiOsEnterSleep (SleepState, SleepControl, 0);
if (Status == AE_CTRL_TERMINATE)
{
return_ACPI_STATUS (AE_OK);
}
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
Status = AcpiWrite ((UINT64) SleepControl, &AcpiGbl_FADT.SleepControl);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);

View file

@ -54,6 +54,12 @@
/* Local Prototypes */
static UINT8
AcpiHwGetAccessBitWidth (
UINT64 Address,
ACPI_GENERIC_ADDRESS *Reg,
UINT8 MaxBitWidth);
static ACPI_STATUS
AcpiHwReadMultiple (
UINT32 *Value,
@ -69,6 +75,90 @@ AcpiHwWriteMultiple (
#endif /* !ACPI_REDUCED_HARDWARE */
/******************************************************************************
*
* FUNCTION: AcpiHwGetAccessBitWidth
*
* PARAMETERS: Address - GAS register address
* Reg - GAS register structure
* MaxBitWidth - Max BitWidth supported (32 or 64)
*
* RETURN: Status
*
* DESCRIPTION: Obtain optimal access bit width
*
******************************************************************************/
static UINT8
AcpiHwGetAccessBitWidth (
UINT64 Address,
ACPI_GENERIC_ADDRESS *Reg,
UINT8 MaxBitWidth)
{
UINT8 AccessBitWidth;
/*
* GAS format "register", used by FADT:
* 1. Detected if BitOffset is 0 and BitWidth is 8/16/32/64;
* 2. AccessSize field is ignored and BitWidth field is used for
* determining the boundary of the IO accesses.
* GAS format "region", used by APEI registers:
* 1. Detected if BitOffset is not 0 or BitWidth is not 8/16/32/64;
* 2. AccessSize field is used for determining the boundary of the
* IO accesses;
* 3. BitOffset/BitWidth fields are used to describe the "region".
*
* Note: This algorithm assumes that the "Address" fields should always
* contain aligned values.
*/
if (!Reg->BitOffset && Reg->BitWidth &&
ACPI_IS_POWER_OF_TWO (Reg->BitWidth) &&
ACPI_IS_ALIGNED (Reg->BitWidth, 8))
{
AccessBitWidth = Reg->BitWidth;
}
else if (Reg->AccessWidth)
{
AccessBitWidth = (1 << (Reg->AccessWidth + 2));
}
else
{
AccessBitWidth = ACPI_ROUND_UP_POWER_OF_TWO_8 (
Reg->BitOffset + Reg->BitWidth);
if (AccessBitWidth <= 8)
{
AccessBitWidth = 8;
}
else
{
while (!ACPI_IS_ALIGNED (Address, AccessBitWidth >> 3))
{
AccessBitWidth >>= 1;
}
}
}
/* Maximum IO port access bit width is 32 */
if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_IO)
{
MaxBitWidth = 32;
}
/*
* Return access width according to the requested maximum access bit width,
* as the caller should know the format of the register and may enforce
* a 32-bit accesses.
*/
if (AccessBitWidth < MaxBitWidth)
{
return (AccessBitWidth);
}
return (MaxBitWidth);
}
/******************************************************************************
*
* FUNCTION: AcpiHwValidateRegister
@ -91,6 +181,9 @@ AcpiHwValidateRegister (
UINT8 MaxBitWidth,
UINT64 *Address)
{
UINT8 BitWidth;
UINT8 AccessWidth;
/* Must have a valid pointer to a GAS structure */
@ -120,24 +213,25 @@ AcpiHwValidateRegister (
return (AE_SUPPORT);
}
/* Validate the BitWidth */
/* Validate the AccessWidth */
if ((Reg->BitWidth != 8) &&
(Reg->BitWidth != 16) &&
(Reg->BitWidth != 32) &&
(Reg->BitWidth != MaxBitWidth))
if (Reg->AccessWidth > 4)
{
ACPI_ERROR ((AE_INFO,
"Unsupported register bit width: 0x%X", Reg->BitWidth));
"Unsupported register access width: 0x%X", Reg->AccessWidth));
return (AE_SUPPORT);
}
/* Validate the BitOffset. Just a warning for now. */
/* Validate the BitWidth, convert AccessWidth into number of bits */
if (Reg->BitOffset != 0)
AccessWidth = AcpiHwGetAccessBitWidth (*Address, Reg, MaxBitWidth);
BitWidth = ACPI_ROUND_UP (Reg->BitOffset + Reg->BitWidth, AccessWidth);
if (MaxBitWidth < BitWidth)
{
ACPI_WARNING ((AE_INFO,
"Unsupported register bit offset: 0x%X", Reg->BitOffset));
"Requested bit width 0x%X is smaller than register bit width 0x%X",
MaxBitWidth, BitWidth));
return (AE_SUPPORT);
}
return (AE_OK);
@ -158,10 +252,7 @@ AcpiHwValidateRegister (
* 64-bit values is not needed.
*
* LIMITATIONS: <These limitations also apply to AcpiHwWrite>
* BitWidth must be exactly 8, 16, or 32.
* SpaceID must be SystemMemory or SystemIO.
* BitOffset and AccessWidth are currently ignored, as there has
* not been a need to implement these.
*
******************************************************************************/
@ -171,7 +262,12 @@ AcpiHwRead (
ACPI_GENERIC_ADDRESS *Reg)
{
UINT64 Address;
UINT8 AccessWidth;
UINT32 BitWidth;
UINT8 BitOffset;
UINT64 Value64;
UINT32 Value32;
UINT8 Index;
ACPI_STATUS Status;
@ -186,30 +282,58 @@ AcpiHwRead (
return (Status);
}
/* Initialize entire 32-bit return value to zero */
/*
* Initialize entire 32-bit return value to zero, convert AccessWidth
* into number of bits based
*/
*Value = 0;
AccessWidth = AcpiHwGetAccessBitWidth (Address, Reg, 32);
BitWidth = Reg->BitOffset + Reg->BitWidth;
BitOffset = Reg->BitOffset;
/*
* Two address spaces supported: Memory or IO. PCI_Config is
* not supported here because the GAS structure is insufficient
*/
if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Index = 0;
while (BitWidth)
{
Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
Address, &Value64, Reg->BitWidth);
if (BitOffset >= AccessWidth)
{
Value32 = 0;
BitOffset -= AccessWidth;
}
else
{
if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
{
Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
Address + Index * ACPI_DIV_8 (AccessWidth),
&Value64, AccessWidth);
Value32 = (UINT32) Value64;
}
else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
{
Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
Address + Index * ACPI_DIV_8 (AccessWidth),
&Value32, AccessWidth);
}
}
*Value = (UINT32) Value64;
}
else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
{
Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
Address, Value, Reg->BitWidth);
/*
* Use offset style bit writes because "Index * AccessWidth" is
* ensured to be less than 32-bits by AcpiHwValidateRegister().
*/
ACPI_SET_BITS (Value, Index * AccessWidth,
ACPI_MASK_BITS_ABOVE_32 (AccessWidth), Value32);
BitWidth -= BitWidth > AccessWidth ? AccessWidth : BitWidth;
Index++;
}
ACPI_DEBUG_PRINT ((ACPI_DB_IO,
"Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
*Value, Reg->BitWidth, ACPI_FORMAT_UINT64 (Address),
*Value, AccessWidth, ACPI_FORMAT_UINT64 (Address),
AcpiUtGetRegionName (Reg->SpaceId)));
return (Status);
@ -237,6 +361,12 @@ AcpiHwWrite (
ACPI_GENERIC_ADDRESS *Reg)
{
UINT64 Address;
UINT8 AccessWidth;
UINT32 BitWidth;
UINT8 BitOffset;
UINT64 Value64;
UINT32 Value32;
UINT8 Index;
ACPI_STATUS Status;
@ -251,24 +381,58 @@ AcpiHwWrite (
return (Status);
}
/* Convert AccessWidth into number of bits based */
AccessWidth = AcpiHwGetAccessBitWidth (Address, Reg, 32);
BitWidth = Reg->BitOffset + Reg->BitWidth;
BitOffset = Reg->BitOffset;
/*
* Two address spaces supported: Memory or IO. PCI_Config is
* not supported here because the GAS structure is insufficient
*/
if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Index = 0;
while (BitWidth)
{
Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
Address, (UINT64) Value, Reg->BitWidth);
}
else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
{
Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
Address, Value, Reg->BitWidth);
/*
* Use offset style bit reads because "Index * AccessWidth" is
* ensured to be less than 32-bits by AcpiHwValidateRegister().
*/
Value32 = ACPI_GET_BITS (&Value, Index * AccessWidth,
ACPI_MASK_BITS_ABOVE_32 (AccessWidth));
if (BitOffset >= AccessWidth)
{
BitOffset -= AccessWidth;
}
else
{
if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
{
Value64 = (UINT64) Value32;
Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
Address + Index * ACPI_DIV_8 (AccessWidth),
Value64, AccessWidth);
}
else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
{
Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
Address + Index * ACPI_DIV_8 (AccessWidth),
Value32, AccessWidth);
}
}
/*
* Index * AccessWidth is ensured to be less than 32-bits by
* AcpiHwValidateRegister().
*/
BitWidth -= BitWidth > AccessWidth ? AccessWidth : BitWidth;
Index++;
}
ACPI_DEBUG_PRINT ((ACPI_DB_IO,
"Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
Value, Reg->BitWidth, ACPI_FORMAT_UINT64 (Address),
Value, AccessWidth, ACPI_FORMAT_UINT64 (Address),
AcpiUtGetRegionName (Reg->SpaceId)));
return (Status);

View file

@ -159,6 +159,16 @@ AcpiHwLegacySleep (
ACPI_FLUSH_CPU_CACHE ();
Status = AcpiOsEnterSleep (SleepState, Pm1aControl, Pm1bControl);
if (Status == AE_CTRL_TERMINATE)
{
return_ACPI_STATUS (AE_OK);
}
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
/* Write #2: Write both SLP_TYP + SLP_EN */
Status = AcpiHwWritePm1Control (Pm1aControl, Pm1bControl);

View file

@ -298,6 +298,20 @@ AcpiPsGetNextNamepath (
PossibleMethodCall &&
(Node->Type == ACPI_TYPE_METHOD))
{
if ((GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) == ARGP_SUPERNAME) ||
(GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) == ARGP_TARGET))
{
/*
* AcpiPsGetNextNamestring has increased the AML pointer past
* the method invocation namestring, so we need to restore the
* saved AML pointer back to the original method invocation
* namestring.
*/
WalkState->ParserState.Aml = Start;
WalkState->ArgCount = 1;
AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
}
/* This name is actually a control method invocation */
MethodDesc = AcpiNsGetAttachedObject (Node);
@ -887,7 +901,10 @@ AcpiPsGetNextArg (
AcpiUtGetArgumentTypeName (ArgType), ArgType));
Subop = AcpiPsPeekOpcode (ParserState);
if (Subop == 0)
if (Subop == 0 ||
AcpiPsIsLeadingChar (Subop) ||
ACPI_IS_ROOT_PREFIX (Subop) ||
ACPI_IS_PARENT_PREFIX (Subop))
{
/* NULL target (zero). Convert to a NULL namepath */
@ -899,6 +916,13 @@ AcpiPsGetNextArg (
Status = AcpiPsGetNextNamepath (WalkState, ParserState,
Arg, ACPI_POSSIBLE_METHOD_CALL);
if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)
{
AcpiPsFreeOp (Arg);
Arg = NULL;
WalkState->ArgCount = 1;
}
}
else
{

View file

@ -142,7 +142,7 @@ AcpiPsAppendArg (
const ACPI_OPCODE_INFO *OpInfo;
ACPI_FUNCTION_TRACE ("PsAppendArg");
ACPI_FUNCTION_TRACE (PsAppendArg);
if (!Op)

View file

@ -269,7 +269,7 @@ AcpiUtGetObjectTypeName (
if (!ObjDesc)
{
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Null Object Descriptor\n"));
return_PTR ("[NULL Object Descriptor]");
return_STR ("[NULL Object Descriptor]");
}
/* These descriptor types share a common area */
@ -282,7 +282,7 @@ AcpiUtGetObjectTypeName (
ACPI_GET_DESCRIPTOR_TYPE (ObjDesc),
AcpiUtGetDescriptorName (ObjDesc), ObjDesc));
return_PTR ("Invalid object");
return_STR ("Invalid object");
}
return_STR (AcpiUtGetTypeName (ObjDesc->Common.Type));

View file

@ -449,8 +449,9 @@ AcpiUtUpdateRefCount (
}
ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
"Obj %p Type %.2X Refs %.2X [Incremented]\n",
Object, Object->Common.Type, NewCount));
"Obj %p Type %.2X [%s] Refs %.2X [Incremented]\n",
Object, Object->Common.Type,
AcpiUtGetObjectTypeName (Object), NewCount));
break;
case REF_DECREMENT:

View file

@ -129,19 +129,6 @@ AcpiUtMutexInitialize (
return_ACPI_STATUS (Status);
}
#ifdef ACPI_DEBUGGER
/* Debugger Support */
Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandReady);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandComplete);
#endif
return_ACPI_STATUS (Status);
}
@ -187,12 +174,6 @@ AcpiUtMutexTerminate (
/* Delete the reader/writer lock */
AcpiUtDeleteRwLock (&AcpiGbl_NamespaceRwLock);
#ifdef ACPI_DEBUGGER
AcpiOsDeleteMutex (AcpiGbl_DbCommandReady);
AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete);
#endif
return_VOID;
}

View file

@ -472,7 +472,7 @@ AcpiUtWalkAmlResources (
* The absolute minimum resource template is one EndTag descriptor.
* However, we will treat a lone EndTag as just a simple buffer.
*/
if (AmlLength <= sizeof (AML_RESOURCE_END_TAG))
if (AmlLength < sizeof (AML_RESOURCE_END_TAG))
{
return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
}

View file

@ -103,6 +103,16 @@ strchr (
const char *String,
int ch);
char *
strpbrk (
const char *String,
const char *Delimiters);
char *
strtok (
char *String,
const char *Delimiters);
char *
strcpy (
char *DstString,
@ -164,6 +174,12 @@ memcpy (
const void *Src,
ACPI_SIZE Count);
void *
memmove (
void *Dest,
const void *Src,
ACPI_SIZE Count);
void *
memset (
void *Dest,
@ -226,6 +242,13 @@ sprintf (
*/
extern int errno;
#ifndef EOF
#define EOF (-1)
#endif
#define putchar(c) fputc(stdout, c)
#define getchar(c) fgetc(stdin)
int
vprintf (
const char *Format,
@ -280,6 +303,21 @@ fseek (
long
ftell (
FILE *File);
int
fgetc (
FILE *File);
int
fputc (
FILE *File,
char c);
char *
fgets (
char *s,
ACPI_SIZE Size,
FILE *File);
#endif
#endif /* _ACCLIB_H */

View file

@ -421,8 +421,7 @@ AcpiDbExecuteThread (
ACPI_STATUS
AcpiDbUserCommands (
char Prompt,
ACPI_PARSE_OBJECT *Op);
void);
char *
AcpiDbGetNextToken (

View file

@ -429,7 +429,7 @@ extern ACPI_DMTABLE_INFO AcpiDmTableInfoGeneric[][2];
* dmtable and ahtable
*/
extern const ACPI_DMTABLE_DATA AcpiDmTableData[];
extern const AH_TABLE AcpiSupportedTables[];
extern const AH_TABLE Gbl_AcpiSupportedTables[];
UINT8
AcpiDmGenerateChecksum (
@ -651,6 +651,10 @@ AcpiDmDisassembleOneOp (
ACPI_OP_WALK_INFO *Info,
ACPI_PARSE_OBJECT *Op);
BOOLEAN
AcpiDmIsTempName (
ACPI_PARSE_OBJECT *Op);
UINT32
AcpiDmListType (
ACPI_PARSE_OBJECT *Op);

View file

@ -217,11 +217,10 @@ typedef struct acpi_exception_info
#define AE_CTRL_TRANSFER EXCEP_CTL (0x0008)
#define AE_CTRL_BREAK EXCEP_CTL (0x0009)
#define AE_CTRL_CONTINUE EXCEP_CTL (0x000A)
#define AE_CTRL_SKIP EXCEP_CTL (0x000B)
#define AE_CTRL_PARSE_CONTINUE EXCEP_CTL (0x000C)
#define AE_CTRL_PARSE_PENDING EXCEP_CTL (0x000D)
#define AE_CTRL_PARSE_CONTINUE EXCEP_CTL (0x000B)
#define AE_CTRL_PARSE_PENDING EXCEP_CTL (0x000C)
#define AE_CODE_CTRL_MAX 0x000D
#define AE_CODE_CTRL_MAX 0x000C
/* Exception strings for AcpiFormatException */
@ -344,7 +343,6 @@ static const ACPI_EXCEPTION_INFO AcpiGbl_ExceptionNames_Ctrl[] =
EXCEP_TXT ("AE_CTRL_TRANSFER", "Transfer control to called method"),
EXCEP_TXT ("AE_CTRL_BREAK", "A Break has been executed"),
EXCEP_TXT ("AE_CTRL_CONTINUE", "A Continue has been executed"),
EXCEP_TXT ("AE_CTRL_SKIP", "Not currently used"),
EXCEP_TXT ("AE_CTRL_PARSE_CONTINUE", "Used to skip over bad opcodes"),
EXCEP_TXT ("AE_CTRL_PARSE_PENDING", "Used to implement AML While loops")
};

View file

@ -331,7 +331,6 @@ ACPI_GLOBAL (ACPI_EXTERNAL_FILE *, AcpiGbl_ExternalFileList);
#ifdef ACPI_DEBUGGER
ACPI_INIT_GLOBAL (BOOLEAN, AcpiGbl_AbortMethod, FALSE);
ACPI_INIT_GLOBAL (BOOLEAN, AcpiGbl_MethodExecuting, FALSE);
ACPI_INIT_GLOBAL (ACPI_THREAD_ID, AcpiGbl_DbThreadId, ACPI_INVALID_THREAD_ID);
ACPI_GLOBAL (BOOLEAN, AcpiGbl_DbOpt_NoIniMethods);
@ -350,7 +349,6 @@ ACPI_GLOBAL (ACPI_OBJECT_TYPE, AcpiGbl_DbArgTypes[ACPI_DEBUGGER_MAX_ARG
/* These buffers should all be the same size */
ACPI_GLOBAL (char, AcpiGbl_DbLineBuf[ACPI_DB_LINE_BUFFER_SIZE]);
ACPI_GLOBAL (char, AcpiGbl_DbParsedBuf[ACPI_DB_LINE_BUFFER_SIZE]);
ACPI_GLOBAL (char, AcpiGbl_DbScopeBuf[ACPI_DB_LINE_BUFFER_SIZE]);
ACPI_GLOBAL (char, AcpiGbl_DbDebugFilename[ACPI_DB_LINE_BUFFER_SIZE]);
@ -365,9 +363,6 @@ ACPI_GLOBAL (UINT16, AcpiGbl_NodeTypeCountMisc);
ACPI_GLOBAL (UINT32, AcpiGbl_NumNodes);
ACPI_GLOBAL (UINT32, AcpiGbl_NumObjects);
ACPI_GLOBAL (ACPI_MUTEX, AcpiGbl_DbCommandReady);
ACPI_GLOBAL (ACPI_MUTEX, AcpiGbl_DbCommandComplete);
#endif /* ACPI_DEBUGGER */
#if defined (ACPI_DISASSEMBLER) || defined (ACPI_ASL_COMPILER)

View file

@ -923,7 +923,7 @@ typedef union acpi_parse_value
char AmlOpName[16]) /* Op name (debug only) */
/* Flags for DisasmFlags field above */
/* Internal opcodes for DisasmOpcode field above */
#define ACPI_DASM_BUFFER 0x00 /* Buffer is a simple data buffer */
#define ACPI_DASM_RESOURCE 0x01 /* Buffer is a Resource Descriptor */
@ -936,7 +936,10 @@ typedef union acpi_parse_value
#define ACPI_DASM_LNOT_PREFIX 0x08 /* Start of a LNotEqual (etc.) pair of opcodes */
#define ACPI_DASM_LNOT_SUFFIX 0x09 /* End of a LNotEqual (etc.) pair of opcodes */
#define ACPI_DASM_HID_STRING 0x0A /* String is a _HID or _CID */
#define ACPI_DASM_IGNORE 0x0B /* Not used at this time */
#define ACPI_DASM_IGNORE_SINGLE 0x0B /* Ignore the opcode but not it's children */
#define ACPI_DASM_SWITCH_PREDICATE 0x0C /* Object is a predicate for a Switch or Case block */
#define ACPI_DASM_CASE 0x0D /* If/Else is a Case in a Switch/Case block */
#define ACPI_DASM_DEFAULT 0x0E /* Else is a Default in a Switch/Case block */
/*
* Generic operation (for example: If, While, Store)

View file

@ -47,7 +47,7 @@
/*
* Extract data using a pointer. Any more than a byte and we
* get into potential aligment issues -- see the STORE macros below.
* get into potential alignment issues -- see the STORE macros below.
* Use with care.
*/
#define ACPI_CAST8(ptr) ACPI_CAST_PTR (UINT8, (ptr))
@ -64,7 +64,7 @@
#define ACPI_SET64(ptr, val) (*ACPI_CAST64 (ptr) = (UINT64) (val))
/*
* printf() format helper. This macros is a workaround for the difficulties
* printf() format helper. This macro is a workaround for the difficulties
* with emitting 64-bit integers and 64-bit pointers with the same code
* for both 32-bit and 64-bit hosts.
*/
@ -264,14 +264,93 @@
#define ACPI_IS_MISALIGNED(value) (((ACPI_SIZE) value) & (sizeof(ACPI_SIZE)-1))
/* Generic bit manipulation */
#ifndef ACPI_USE_NATIVE_BIT_FINDER
#define __ACPI_FIND_LAST_BIT_2(a, r) ((((UINT8) (a)) & 0x02) ? (r)+1 : (r))
#define __ACPI_FIND_LAST_BIT_4(a, r) ((((UINT8) (a)) & 0x0C) ? \
__ACPI_FIND_LAST_BIT_2 ((a)>>2, (r)+2) : \
__ACPI_FIND_LAST_BIT_2 ((a), (r)))
#define __ACPI_FIND_LAST_BIT_8(a, r) ((((UINT8) (a)) & 0xF0) ? \
__ACPI_FIND_LAST_BIT_4 ((a)>>4, (r)+4) : \
__ACPI_FIND_LAST_BIT_4 ((a), (r)))
#define __ACPI_FIND_LAST_BIT_16(a, r) ((((UINT16) (a)) & 0xFF00) ? \
__ACPI_FIND_LAST_BIT_8 ((a)>>8, (r)+8) : \
__ACPI_FIND_LAST_BIT_8 ((a), (r)))
#define __ACPI_FIND_LAST_BIT_32(a, r) ((((UINT32) (a)) & 0xFFFF0000) ? \
__ACPI_FIND_LAST_BIT_16 ((a)>>16, (r)+16) : \
__ACPI_FIND_LAST_BIT_16 ((a), (r)))
#define __ACPI_FIND_LAST_BIT_64(a, r) ((((UINT64) (a)) & 0xFFFFFFFF00000000) ? \
__ACPI_FIND_LAST_BIT_32 ((a)>>32, (r)+32) : \
__ACPI_FIND_LAST_BIT_32 ((a), (r)))
#define ACPI_FIND_LAST_BIT_8(a) ((a) ? __ACPI_FIND_LAST_BIT_8 (a, 1) : 0)
#define ACPI_FIND_LAST_BIT_16(a) ((a) ? __ACPI_FIND_LAST_BIT_16 (a, 1) : 0)
#define ACPI_FIND_LAST_BIT_32(a) ((a) ? __ACPI_FIND_LAST_BIT_32 (a, 1) : 0)
#define ACPI_FIND_LAST_BIT_64(a) ((a) ? __ACPI_FIND_LAST_BIT_64 (a, 1) : 0)
#define __ACPI_FIND_FIRST_BIT_2(a, r) ((((UINT8) (a)) & 0x01) ? (r) : (r)+1)
#define __ACPI_FIND_FIRST_BIT_4(a, r) ((((UINT8) (a)) & 0x03) ? \
__ACPI_FIND_FIRST_BIT_2 ((a), (r)) : \
__ACPI_FIND_FIRST_BIT_2 ((a)>>2, (r)+2))
#define __ACPI_FIND_FIRST_BIT_8(a, r) ((((UINT8) (a)) & 0x0F) ? \
__ACPI_FIND_FIRST_BIT_4 ((a), (r)) : \
__ACPI_FIND_FIRST_BIT_4 ((a)>>4, (r)+4))
#define __ACPI_FIND_FIRST_BIT_16(a, r) ((((UINT16) (a)) & 0x00FF) ? \
__ACPI_FIND_FIRST_BIT_8 ((a), (r)) : \
__ACPI_FIND_FIRST_BIT_8 ((a)>>8, (r)+8))
#define __ACPI_FIND_FIRST_BIT_32(a, r) ((((UINT32) (a)) & 0x0000FFFF) ? \
__ACPI_FIND_FIRST_BIT_16 ((a), (r)) : \
__ACPI_FIND_FIRST_BIT_16 ((a)>>16, (r)+16))
#define __ACPI_FIND_FIRST_BIT_64(a, r) ((((UINT64) (a)) & 0x00000000FFFFFFFF) ? \
__ACPI_FIND_FIRST_BIT_32 ((a), (r)) : \
__ACPI_FIND_FIRST_BIT_32 ((a)>>32, (r)+32))
#define ACPI_FIND_FIRST_BIT_8(a) ((a) ? __ACPI_FIND_FIRST_BIT_8 (a, 1) : 0)
#define ACPI_FIND_FIRST_BIT_16(a) ((a) ? __ACPI_FIND_FIRST_BIT_16 (a, 1) : 0)
#define ACPI_FIND_FIRST_BIT_32(a) ((a) ? __ACPI_FIND_FIRST_BIT_32 (a, 1) : 0)
#define ACPI_FIND_FIRST_BIT_64(a) ((a) ? __ACPI_FIND_FIRST_BIT_64 (a, 1) : 0)
#endif /* ACPI_USE_NATIVE_BIT_FINDER */
/* Generic (power-of-two) rounding */
#define ACPI_ROUND_UP_POWER_OF_TWO_8(a) ((UINT8) \
(((UINT16) 1) << ACPI_FIND_LAST_BIT_8 ((a) - 1)))
#define ACPI_ROUND_DOWN_POWER_OF_TWO_8(a) ((UINT8) \
(((UINT16) 1) << (ACPI_FIND_LAST_BIT_8 ((a)) - 1)))
#define ACPI_ROUND_UP_POWER_OF_TWO_16(a) ((UINT16) \
(((UINT32) 1) << ACPI_FIND_LAST_BIT_16 ((a) - 1)))
#define ACPI_ROUND_DOWN_POWER_OF_TWO_16(a) ((UINT16) \
(((UINT32) 1) << (ACPI_FIND_LAST_BIT_16 ((a)) - 1)))
#define ACPI_ROUND_UP_POWER_OF_TWO_32(a) ((UINT32) \
(((UINT64) 1) << ACPI_FIND_LAST_BIT_32 ((a) - 1)))
#define ACPI_ROUND_DOWN_POWER_OF_TWO_32(a) ((UINT32) \
(((UINT64) 1) << (ACPI_FIND_LAST_BIT_32 ((a)) - 1)))
#define ACPI_IS_ALIGNED(a, s) (((a) & ((s) - 1)) == 0)
#define ACPI_IS_POWER_OF_TWO(a) ACPI_IS_ALIGNED(a, a)
/*
* Bitmask creation
* Bit positions start at zero.
* MASK_BITS_ABOVE creates a mask starting AT the position and above
* MASK_BITS_BELOW creates a mask starting one bit BELOW the position
* MASK_BITS_ABOVE/BELOW accepts a bit offset to create a mask
* MASK_BITS_ABOVE/BELOW_32/64 accepts a bit width to create a mask
* Note: The ACPI_INTEGER_BIT_SIZE check is used to bypass compiler
* differences with the shift operator
*/
#define ACPI_MASK_BITS_ABOVE(position) (~((ACPI_UINT64_MAX) << ((UINT32) (position))))
#define ACPI_MASK_BITS_BELOW(position) ((ACPI_UINT64_MAX) << ((UINT32) (position)))
#define ACPI_MASK_BITS_ABOVE_32(width) ((UINT32) ACPI_MASK_BITS_ABOVE(width))
#define ACPI_MASK_BITS_BELOW_32(width) ((UINT32) ACPI_MASK_BITS_BELOW(width))
#define ACPI_MASK_BITS_ABOVE_64(width) ((width) == ACPI_INTEGER_BIT_SIZE ? \
ACPI_UINT64_MAX : \
ACPI_MASK_BITS_ABOVE(width))
#define ACPI_MASK_BITS_BELOW_64(width) ((width) == ACPI_INTEGER_BIT_SIZE ? \
(UINT64) 0 : \
ACPI_MASK_BITS_BELOW(width))
/* Bitfields within ACPI registers */
@ -376,7 +455,7 @@
*/
#ifndef ACPI_NO_ERROR_MESSAGES
/*
* Error reporting. Callers module and line number are inserted by AE_INFO,
* Error reporting. The callers module and line number are inserted by AE_INFO,
* the plist contains a set of parens to allow variable-length lists.
* These macros are used for both the debug and non-debug versions of the code.
*/

View file

@ -456,6 +456,14 @@ AcpiOsSignal (
void *Info);
#endif
#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsEnterSleep
ACPI_STATUS
AcpiOsEnterSleep (
UINT8 SleepState,
UINT32 RegaValue,
UINT32 RegbValue);
#endif
/*
* Debug print routines
@ -482,7 +490,7 @@ AcpiOsRedirectOutput (
/*
* Debug input
* Debug IO
*/
#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetLine
ACPI_STATUS
@ -492,6 +500,30 @@ AcpiOsGetLine (
UINT32 *BytesRead);
#endif
#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsInitializeDebugger
ACPI_STATUS
AcpiOsInitializeDebugger (
void);
#endif
#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTerminateDebugger
void
AcpiOsTerminateDebugger (
void);
#endif
#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWaitCommandReady
ACPI_STATUS
AcpiOsWaitCommandReady (
void);
#endif
#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsNotifyCommandComplete
ACPI_STATUS
AcpiOsNotifyCommandComplete (
void);
#endif
#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTracePoint
void
AcpiOsTracePoint (

View file

@ -46,7 +46,7 @@
/* Current ACPICA subsystem version in YYYYMMDD format */
#define ACPI_CA_VERSION 0x20161117
#define ACPI_CA_VERSION 0x20161222
#include <contrib/dev/acpica/include/acconfig.h>
#include <contrib/dev/acpica/include/actypes.h>
@ -292,6 +292,15 @@ ACPI_INIT_GLOBAL (UINT32, AcpiDbgLayer, ACPI_COMPONENT_DEFAULT);
ACPI_INIT_GLOBAL (UINT8, AcpiGbl_DisplayDebugTimer, FALSE);
/*
* Debugger command handshake globals. Host OSes need to access these
* variables to implement their own command handshake mechanism.
*/
#ifdef ACPI_DEBUGGER
ACPI_INIT_GLOBAL (BOOLEAN, AcpiGbl_MethodExecuting, FALSE);
ACPI_GLOBAL (char, AcpiGbl_DbLineBuf[ACPI_DB_LINE_BUFFER_SIZE]);
#endif
/*
* Other miscellaneous globals
*/
@ -1266,6 +1275,10 @@ void
AcpiTerminateDebugger (
void);
void
AcpiRunDebugger (
char *BatchBuffer);
void
AcpiSetDebuggerThreadId (
ACPI_THREAD_ID ThreadId);

View file

@ -76,7 +76,8 @@
(defined ACPI_NAMES_APP) || \
(defined ACPI_SRC_APP) || \
(defined ACPI_XTRACT_APP) || \
(defined ACPI_EXAMPLE_APP)
(defined ACPI_EXAMPLE_APP) || \
(defined ACPI_EFI_HELLO)
#define ACPI_APPLICATION
#define ACPI_SINGLE_THREADED
#define USE_NATIVE_ALLOCATE_ZEROED
@ -361,7 +362,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef ACPI_APPLICATION
#if defined (ACPI_APPLICATION) || defined(ACPI_LIBRARY)
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>

View file

@ -0,0 +1,366 @@
/******************************************************************************
*
* Module Name: osgendbg - Generic debugger command singalling
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2016, Intel Corp.
* 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,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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 DAMAGES.
*/
#include <contrib/dev/acpica/include/acpi.h>
#include <contrib/dev/acpica/include/accommon.h>
#include <contrib/dev/acpica/include/acdebug.h>
#define _COMPONENT ACPI_CA_DEBUGGER
ACPI_MODULE_NAME ("osgendbg")
/* Local prototypes */
static void
AcpiDbRunRemoteDebugger (
char *BatchBuffer);
static ACPI_MUTEX AcpiGbl_DbCommandReady;
static ACPI_MUTEX AcpiGbl_DbCommandComplete;
static BOOLEAN AcpiGbl_DbCommandSignalsInitialized = FALSE;
/******************************************************************************
*
* FUNCTION: AcpiDbRunRemoteDebugger
*
* PARAMETERS: BatchBuffer - Buffer containing commands running in
* the batch mode
*
* RETURN: None
*
* DESCRIPTION: Run multi-threading debugger remotely
*
*****************************************************************************/
static void
AcpiDbRunRemoteDebugger (
char *BatchBuffer)
{
ACPI_STATUS Status;
char *Ptr = BatchBuffer;
char *Cmd = Ptr;
while (!AcpiGbl_DbTerminateLoop)
{
if (BatchBuffer)
{
if (*Ptr)
{
while (*Ptr)
{
if (*Ptr == ',')
{
/* Convert commas to spaces */
*Ptr = ' ';
}
else if (*Ptr == ';')
{
*Ptr = '\0';
continue;
}
Ptr++;
}
strncpy (AcpiGbl_DbLineBuf, Cmd, ACPI_DB_LINE_BUFFER_SIZE);
Ptr++;
Cmd = Ptr;
}
else
{
return;
}
}
else
{
/* Force output to console until a command is entered */
AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
/* Different prompt if method is executing */
if (!AcpiGbl_MethodExecuting)
{
AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
}
else
{
AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
}
/* Get the user input line */
Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
ACPI_DB_LINE_BUFFER_SIZE, NULL);
if (ACPI_FAILURE (Status))
{
return;
}
}
/*
* Signal the debug thread that we have a command to execute,
* and wait for the command to complete.
*/
AcpiOsReleaseMutex (AcpiGbl_DbCommandReady);
Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete,
ACPI_WAIT_FOREVER);
if (ACPI_FAILURE (Status))
{
return;
}
}
}
/******************************************************************************
*
* FUNCTION: AcpiOsWaitCommandReady
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Negotiate with the debugger foreground thread (the user
* thread) to wait the readiness of a command.
*
*****************************************************************************/
ACPI_STATUS
AcpiOsWaitCommandReady (
void)
{
ACPI_STATUS Status = AE_OK;
if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
{
Status = AE_TIME;
while (Status == AE_TIME)
{
if (AcpiGbl_DbTerminateLoop)
{
Status = AE_CTRL_TERMINATE;
}
else
{
Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady, 1000);
}
}
}
else
{
/* Force output to console until a command is entered */
AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
/* Different prompt if method is executing */
if (!AcpiGbl_MethodExecuting)
{
AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
}
else
{
AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
}
/* Get the user input line */
Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
ACPI_DB_LINE_BUFFER_SIZE, NULL);
}
if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
{
ACPI_EXCEPTION ((AE_INFO, Status,
"While parsing/handling command line"));
}
return (Status);
}
/******************************************************************************
*
* FUNCTION: AcpiOsNotifyCommandComplete
*
* PARAMETERS: void
*
* RETURN: Status
*
* DESCRIPTION: Negotiate with the debugger foreground thread (the user
* thread) to notify the completion of a command.
*
*****************************************************************************/
ACPI_STATUS
AcpiOsNotifyCommandComplete (
void)
{
if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED)
{
AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete);
}
return (AE_OK);
}
/******************************************************************************
*
* FUNCTION: AcpiOsInitializeDebugger
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Initialize OSPM specific part of the debugger
*
*****************************************************************************/
ACPI_STATUS
AcpiOsInitializeDebugger (
void)
{
ACPI_STATUS Status;
/* Create command signals */
Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandReady);
if (ACPI_FAILURE (Status))
{
return (Status);
}
Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandComplete);
if (ACPI_FAILURE (Status))
{
goto ErrorReady;
}
/* Initialize the states of the command signals */
Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete,
ACPI_WAIT_FOREVER);
if (ACPI_FAILURE (Status))
{
goto ErrorComplete;
}
Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady,
ACPI_WAIT_FOREVER);
if (ACPI_FAILURE (Status))
{
goto ErrorComplete;
}
AcpiGbl_DbCommandSignalsInitialized = TRUE;
return (Status);
ErrorComplete:
AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete);
ErrorReady:
AcpiOsDeleteMutex (AcpiGbl_DbCommandReady);
return (Status);
}
/******************************************************************************
*
* FUNCTION: AcpiOsTerminateDebugger
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Terminate signals used by the multi-threading debugger
*
*****************************************************************************/
void
AcpiOsTerminateDebugger (
void)
{
if (AcpiGbl_DbCommandSignalsInitialized)
{
AcpiOsDeleteMutex (AcpiGbl_DbCommandReady);
AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete);
}
}
/******************************************************************************
*
* FUNCTION: AcpiRunDebugger
*
* PARAMETERS: BatchBuffer - Buffer containing commands running in
* the batch mode
*
* RETURN: None
*
* DESCRIPTION: Run a local/remote debugger
*
*****************************************************************************/
void
AcpiRunDebugger (
char *BatchBuffer)
{
/* Check for single or multithreaded debug */
if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
{
AcpiDbRunRemoteDebugger (BatchBuffer);
}
else
{
AcpiDbUserCommands ();
}
}
ACPI_EXPORT_SYMBOL (AcpiRunDebugger)

View file

@ -359,6 +359,33 @@ AcpiOsPhysicalTableOverride (
}
/******************************************************************************
*
* FUNCTION: AcpiOsEnterSleep
*
* PARAMETERS: SleepState - Which sleep state to enter
* RegaValue - Register A value
* RegbValue - Register B value
*
* RETURN: Status
*
* DESCRIPTION: A hook before writing sleep registers to enter the sleep
* state. Return AE_CTRL_SKIP to skip further sleep register
* writes.
*
*****************************************************************************/
ACPI_STATUS
AcpiOsEnterSleep (
UINT8 SleepState,
UINT32 RegaValue,
UINT32 RegbValue)
{
return (AE_OK);
}
/******************************************************************************
*
* FUNCTION: AcpiOsRedirectOutput

Some files were not shown because too many files have changed in this diff Show more