2000-02-13 14:56:13 +01:00
|
|
|
/*
|
|
|
|
* Server-side atom management
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999, 2000 Alexandre Julliard
|
|
|
|
* Copyright (C) 2000 Turchanov Sergei
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-02-13 14:56:13 +01:00
|
|
|
*/
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2000-02-13 14:56:13 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2001-03-21 21:30:46 +01:00
|
|
|
#include <string.h>
|
2000-02-13 14:56:13 +01:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
|
2000-02-13 14:56:13 +01:00
|
|
|
#include "unicode.h"
|
|
|
|
#include "request.h"
|
|
|
|
#include "object.h"
|
2000-05-30 22:32:06 +02:00
|
|
|
#include "process.h"
|
2005-05-10 17:15:50 +02:00
|
|
|
#include "handle.h"
|
2005-07-07 13:29:23 +02:00
|
|
|
#include "user.h"
|
|
|
|
#include "winuser.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "winternl.h"
|
2000-02-13 14:56:13 +01:00
|
|
|
|
|
|
|
#define HASH_SIZE 37
|
2000-05-30 22:32:06 +02:00
|
|
|
#define MIN_HASH_SIZE 4
|
|
|
|
#define MAX_HASH_SIZE 0x200
|
|
|
|
|
2008-06-25 14:03:08 +02:00
|
|
|
#define MAX_ATOM_LEN (255 * sizeof(WCHAR))
|
2001-10-12 20:45:29 +02:00
|
|
|
#define MIN_STR_ATOM 0xc000
|
2000-02-13 14:56:13 +01:00
|
|
|
#define MAX_ATOMS 0x4000
|
|
|
|
|
|
|
|
struct atom_entry
|
|
|
|
{
|
|
|
|
struct atom_entry *next; /* hash table list */
|
|
|
|
struct atom_entry *prev; /* hash table list */
|
|
|
|
int count; /* reference count */
|
2005-05-11 20:25:27 +02:00
|
|
|
short pinned; /* whether the atom is pinned or not */
|
2001-10-12 20:45:29 +02:00
|
|
|
atom_t atom; /* atom handle */
|
2005-05-11 20:25:27 +02:00
|
|
|
unsigned short hash; /* string hash */
|
|
|
|
unsigned short len; /* string len */
|
2000-02-13 14:56:13 +01:00
|
|
|
WCHAR str[1]; /* atom string */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct atom_table
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
int count; /* count of atom handles */
|
|
|
|
int last; /* last handle in-use */
|
|
|
|
struct atom_entry **handles; /* atom handles */
|
2008-04-07 13:01:02 +02:00
|
|
|
int entries_count; /* number of hash entries */
|
2000-05-30 22:32:06 +02:00
|
|
|
struct atom_entry **entries; /* hash table entries */
|
2000-02-13 14:56:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void atom_table_dump( struct object *obj, int verbose );
|
|
|
|
static void atom_table_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops atom_table_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct atom_table), /* size */
|
2021-02-04 13:44:18 +01:00
|
|
|
&no_type, /* type */
|
2000-02-13 14:56:13 +01:00
|
|
|
atom_table_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
2005-04-24 19:35:52 +02:00
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
2000-12-19 03:12:45 +01:00
|
|
|
no_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 16:52:31 +02:00
|
|
|
no_get_full_name, /* get_full_name */
|
2005-11-22 15:55:42 +01:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 13:07:19 +01:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2007-03-22 11:44:29 +01:00
|
|
|
no_open_file, /* open_file */
|
2019-03-25 14:37:09 +01:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2005-06-09 17:39:52 +02:00
|
|
|
no_close_handle, /* close_handle */
|
2000-02-13 14:56:13 +01:00
|
|
|
atom_table_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2006-03-22 22:13:40 +01:00
|
|
|
static struct atom_table *global_table;
|
2000-02-13 14:56:13 +01:00
|
|
|
|
|
|
|
/* create an atom table */
|
2000-05-30 22:32:06 +02:00
|
|
|
static struct atom_table *create_table(int entries_count)
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
struct atom_table *table;
|
|
|
|
|
2003-02-19 01:33:32 +01:00
|
|
|
if ((table = alloc_object( &atom_table_ops )))
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
2000-05-30 22:32:06 +02:00
|
|
|
if ((entries_count < MIN_HASH_SIZE) ||
|
|
|
|
(entries_count > MAX_HASH_SIZE)) entries_count = HASH_SIZE;
|
2015-08-19 12:04:55 +02:00
|
|
|
table->handles = NULL;
|
2000-05-30 22:32:06 +02:00
|
|
|
table->entries_count = entries_count;
|
|
|
|
if (!(table->entries = malloc( sizeof(*table->entries) * table->entries_count )))
|
|
|
|
{
|
|
|
|
set_error( STATUS_NO_MEMORY );
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
memset( table->entries, 0, sizeof(*table->entries) * table->entries_count );
|
2000-02-13 14:56:13 +01:00
|
|
|
table->count = 64;
|
|
|
|
table->last = -1;
|
|
|
|
if ((table->handles = mem_alloc( sizeof(*table->handles) * table->count )))
|
|
|
|
return table;
|
2000-05-30 22:32:06 +02:00
|
|
|
fail:
|
2000-02-13 14:56:13 +01:00
|
|
|
release_object( table );
|
|
|
|
table = NULL;
|
|
|
|
}
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve an entry pointer from its atom */
|
2001-10-12 20:45:29 +02:00
|
|
|
static struct atom_entry *get_atom_entry( struct atom_table *table, atom_t atom )
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
struct atom_entry *entry = NULL;
|
2001-10-12 20:45:29 +02:00
|
|
|
if (table && (atom >= MIN_STR_ATOM) && (atom <= MIN_STR_ATOM + table->last))
|
|
|
|
entry = table->handles[atom - MIN_STR_ATOM];
|
2000-02-13 14:56:13 +01:00
|
|
|
if (!entry) set_error( STATUS_INVALID_HANDLE );
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add an atom entry in the table and return its handle */
|
2001-10-12 20:45:29 +02:00
|
|
|
static atom_t add_atom_entry( struct atom_table *table, struct atom_entry *entry )
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i <= table->last; i++)
|
|
|
|
if (!table->handles[i]) goto found;
|
|
|
|
if (i == table->count)
|
|
|
|
{
|
|
|
|
struct atom_entry **new_table = NULL;
|
|
|
|
int new_size = table->count + table->count / 2;
|
|
|
|
if (new_size > MAX_ATOMS) new_size = MAX_ATOMS;
|
|
|
|
if (new_size > table->count)
|
|
|
|
new_table = realloc( table->handles, sizeof(*table->handles) * new_size );
|
|
|
|
if (!new_table)
|
|
|
|
{
|
|
|
|
set_error( STATUS_NO_MEMORY );
|
2001-10-12 20:45:29 +02:00
|
|
|
return 0;
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|
|
|
|
table->count = new_size;
|
|
|
|
table->handles = new_table;
|
|
|
|
}
|
|
|
|
table->last = i;
|
|
|
|
found:
|
|
|
|
table->handles[i] = entry;
|
2001-10-12 20:45:29 +02:00
|
|
|
entry->atom = i + MIN_STR_ATOM;
|
|
|
|
return entry->atom;
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* dump an atom table */
|
|
|
|
static void atom_table_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct atom_table *table = (struct atom_table *)obj;
|
|
|
|
assert( obj->ops == &atom_table_ops );
|
|
|
|
|
2000-05-30 22:32:06 +02:00
|
|
|
fprintf( stderr, "Atom table size=%d entries=%d\n",
|
|
|
|
table->last + 1, table->entries_count );
|
2000-02-13 14:56:13 +01:00
|
|
|
if (!verbose) return;
|
|
|
|
for (i = 0; i <= table->last; i++)
|
|
|
|
{
|
|
|
|
struct atom_entry *entry = table->handles[i];
|
|
|
|
if (!entry) continue;
|
2005-05-11 20:25:27 +02:00
|
|
|
fprintf( stderr, " %04x: ref=%d pinned=%c hash=%d \"",
|
2005-05-10 17:15:50 +02:00
|
|
|
entry->atom, entry->count, entry->pinned ? 'Y' : 'N', entry->hash );
|
2020-03-21 11:36:33 +01:00
|
|
|
dump_strW( entry->str, entry->len, stderr, "\"\"");
|
2000-02-13 14:56:13 +01:00
|
|
|
fprintf( stderr, "\"\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* destroy the atom table */
|
|
|
|
static void atom_table_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct atom_table *table = (struct atom_table *)obj;
|
|
|
|
assert( obj->ops == &atom_table_ops );
|
2000-05-30 22:32:06 +02:00
|
|
|
if (table->handles)
|
|
|
|
{
|
|
|
|
for (i = 0; i <= table->last; i++) free( table->handles[i] );
|
|
|
|
free( table->handles );
|
|
|
|
}
|
2006-10-09 23:34:36 +02:00
|
|
|
free( table->entries );
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find an atom entry in its hash list */
|
2008-06-25 14:03:08 +02:00
|
|
|
static struct atom_entry *find_atom_entry( struct atom_table *table, const struct unicode_str *str,
|
|
|
|
unsigned short hash )
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
struct atom_entry *entry = table->entries[hash];
|
|
|
|
while (entry)
|
|
|
|
{
|
2020-03-24 12:48:19 +01:00
|
|
|
if (entry->len == str->len && !memicmp_strW( entry->str, str->str, str->len )) break;
|
2000-02-13 14:56:13 +01:00
|
|
|
entry = entry->next;
|
|
|
|
}
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add an atom to the table */
|
2008-06-25 14:03:08 +02:00
|
|
|
static atom_t add_atom( struct atom_table *table, const struct unicode_str *str )
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
struct atom_entry *entry;
|
2020-03-24 12:48:26 +01:00
|
|
|
unsigned short hash = hash_strW( str->str, str->len, table->entries_count );
|
2001-10-12 20:45:29 +02:00
|
|
|
atom_t atom = 0;
|
2000-02-13 14:56:13 +01:00
|
|
|
|
2008-06-25 14:03:08 +02:00
|
|
|
if (!str->len)
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
set_error( STATUS_OBJECT_NAME_INVALID );
|
2001-10-12 20:45:29 +02:00
|
|
|
return 0;
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|
2008-06-25 14:03:08 +02:00
|
|
|
if (str->len > MAX_ATOM_LEN)
|
2005-05-11 20:25:27 +02:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-25 14:03:08 +02:00
|
|
|
if ((entry = find_atom_entry( table, str, hash ))) /* exists already */
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
entry->count++;
|
|
|
|
return entry->atom;
|
|
|
|
}
|
|
|
|
|
2008-06-25 14:03:08 +02:00
|
|
|
if ((entry = mem_alloc( FIELD_OFFSET( struct atom_entry, str[str->len / sizeof(WCHAR)] ) )))
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
2001-10-12 20:45:29 +02:00
|
|
|
if ((atom = add_atom_entry( table, entry )))
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
entry->prev = NULL;
|
|
|
|
if ((entry->next = table->entries[hash])) entry->next->prev = entry;
|
|
|
|
table->entries[hash] = entry;
|
2005-05-11 20:25:27 +02:00
|
|
|
entry->count = 1;
|
2005-05-10 17:15:50 +02:00
|
|
|
entry->pinned = 0;
|
2005-05-11 20:25:27 +02:00
|
|
|
entry->hash = hash;
|
2008-06-25 14:03:08 +02:00
|
|
|
entry->len = str->len;
|
|
|
|
memcpy( entry->str, str->str, str->len );
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|
|
|
|
else free( entry );
|
|
|
|
}
|
|
|
|
else set_error( STATUS_NO_MEMORY );
|
|
|
|
return atom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete an atom from the table */
|
2005-05-14 13:11:21 +02:00
|
|
|
static void delete_atom( struct atom_table *table, atom_t atom, int if_pinned )
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
struct atom_entry *entry = get_atom_entry( table, atom );
|
2005-05-14 13:11:21 +02:00
|
|
|
if (!entry) return;
|
|
|
|
if (entry->pinned && !if_pinned) set_error( STATUS_WAS_LOCKED );
|
|
|
|
else if (!--entry->count)
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
if (entry->next) entry->next->prev = entry->prev;
|
|
|
|
if (entry->prev) entry->prev->next = entry->next;
|
|
|
|
else table->entries[entry->hash] = entry->next;
|
2001-10-12 20:45:29 +02:00
|
|
|
table->handles[atom - MIN_STR_ATOM] = NULL;
|
2000-02-13 14:56:13 +01:00
|
|
|
free( entry );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find an atom in the table */
|
2008-06-25 14:03:08 +02:00
|
|
|
static atom_t find_atom( struct atom_table *table, const struct unicode_str *str )
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
|
|
|
struct atom_entry *entry;
|
|
|
|
|
2008-06-25 14:03:08 +02:00
|
|
|
if (!str->len)
|
2005-05-11 20:25:27 +02:00
|
|
|
{
|
|
|
|
set_error( STATUS_OBJECT_NAME_INVALID );
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-25 14:03:08 +02:00
|
|
|
if (str->len > MAX_ATOM_LEN)
|
2005-05-11 20:25:27 +02:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
2020-03-24 12:48:26 +01:00
|
|
|
if (table && (entry = find_atom_entry( table, str,
|
|
|
|
hash_strW( str->str, str->len, table->entries_count ))))
|
2005-05-11 20:25:27 +02:00
|
|
|
return entry->atom;
|
|
|
|
set_error( STATUS_OBJECT_NAME_NOT_FOUND );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-08 16:23:27 +02:00
|
|
|
static struct atom_table *get_global_table( struct winstation *winstation, int create )
|
2005-07-07 13:29:23 +02:00
|
|
|
{
|
2006-03-22 22:13:40 +01:00
|
|
|
struct atom_table *table = winstation ? winstation->atom_table : global_table;
|
|
|
|
if (!table)
|
2005-07-07 13:29:23 +02:00
|
|
|
{
|
2006-03-22 22:13:40 +01:00
|
|
|
if (create)
|
|
|
|
{
|
|
|
|
table = create_table( HASH_SIZE );
|
|
|
|
if (winstation) winstation->atom_table = table;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
global_table = table;
|
2020-09-23 15:26:10 +02:00
|
|
|
make_object_permanent( &global_table->obj );
|
2006-03-22 22:13:40 +01:00
|
|
|
}
|
|
|
|
}
|
2005-07-07 13:29:23 +02:00
|
|
|
else set_error( STATUS_OBJECT_NAME_NOT_FOUND );
|
|
|
|
}
|
2006-03-22 22:13:40 +01:00
|
|
|
return table;
|
2005-07-07 13:29:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct atom_table *get_table( obj_handle_t h, int create )
|
2005-05-11 20:25:27 +02:00
|
|
|
{
|
2005-07-08 16:23:27 +02:00
|
|
|
struct atom_table *table = NULL;
|
2005-05-11 20:25:27 +02:00
|
|
|
|
2005-07-07 13:29:23 +02:00
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
table = (struct atom_table *)get_handle_obj( current->process, h, 0, &atom_table_ops );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-22 22:13:40 +01:00
|
|
|
table = get_global_table( NULL, 1 );
|
|
|
|
if (table) grab_object( table );
|
2005-07-07 13:29:23 +02:00
|
|
|
}
|
|
|
|
return table;
|
2005-05-11 20:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add an atom in the global table; used for window properties */
|
2008-06-25 14:03:08 +02:00
|
|
|
atom_t add_global_atom( struct winstation *winstation, const struct unicode_str *str )
|
2005-05-11 20:25:27 +02:00
|
|
|
{
|
2011-02-25 16:36:07 +01:00
|
|
|
struct atom_table *table = get_global_table( winstation, 1 );
|
|
|
|
if (!table) return 0;
|
|
|
|
return add_atom( table, str );
|
2005-05-11 20:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find an atom in the global table; used for window properties */
|
2008-06-25 14:03:08 +02:00
|
|
|
atom_t find_global_atom( struct winstation *winstation, const struct unicode_str *str )
|
2005-05-11 20:25:27 +02:00
|
|
|
{
|
2011-02-25 16:36:07 +01:00
|
|
|
struct atom_table *table = get_global_table( winstation, 0 );
|
2005-05-11 20:25:27 +02:00
|
|
|
struct atom_entry *entry;
|
|
|
|
|
2011-02-25 16:36:07 +01:00
|
|
|
if (!str->len || str->len > MAX_ATOM_LEN || !table) return 0;
|
2020-03-24 12:48:26 +01:00
|
|
|
if ((entry = find_atom_entry( table, str, hash_strW( str->str, str->len, table->entries_count ))))
|
2001-10-12 20:45:29 +02:00
|
|
|
return entry->atom;
|
|
|
|
return 0;
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|
|
|
|
|
2001-10-12 20:45:29 +02:00
|
|
|
/* increment the ref count of a global atom; used for window properties */
|
2005-07-08 16:23:27 +02:00
|
|
|
int grab_global_atom( struct winstation *winstation, atom_t atom )
|
2001-10-12 20:45:29 +02:00
|
|
|
{
|
2002-02-01 00:34:18 +01:00
|
|
|
if (atom >= MIN_STR_ATOM)
|
|
|
|
{
|
2011-02-25 16:36:07 +01:00
|
|
|
struct atom_table *table = get_global_table( winstation, 0 );
|
|
|
|
if (table)
|
2005-07-07 13:29:23 +02:00
|
|
|
{
|
2011-02-25 16:36:07 +01:00
|
|
|
struct atom_entry *entry = get_atom_entry( table, atom );
|
2005-07-07 13:29:23 +02:00
|
|
|
if (entry) entry->count++;
|
|
|
|
return (entry != NULL);
|
|
|
|
}
|
|
|
|
else return 0;
|
2002-02-01 00:34:18 +01:00
|
|
|
}
|
|
|
|
else return 1;
|
2001-10-12 20:45:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* decrement the ref count of a global atom; used for window properties */
|
2005-07-08 16:23:27 +02:00
|
|
|
void release_global_atom( struct winstation *winstation, atom_t atom )
|
2001-10-12 20:45:29 +02:00
|
|
|
{
|
2005-07-07 13:29:23 +02:00
|
|
|
if (atom >= MIN_STR_ATOM)
|
|
|
|
{
|
2011-02-25 16:36:07 +01:00
|
|
|
struct atom_table *table = get_global_table( winstation, 0 );
|
|
|
|
if (table) delete_atom( table, atom, 1 );
|
2005-07-07 13:29:23 +02:00
|
|
|
}
|
2001-10-12 20:45:29 +02:00
|
|
|
}
|
|
|
|
|
2000-02-13 14:56:13 +01:00
|
|
|
/* add a global atom */
|
|
|
|
DECL_HANDLER(add_atom)
|
|
|
|
{
|
2016-01-29 08:36:45 +01:00
|
|
|
struct unicode_str name = get_req_unicode_str();
|
2005-07-07 13:29:23 +02:00
|
|
|
struct atom_table *table = get_table( req->table, 1 );
|
2008-06-25 14:03:08 +02:00
|
|
|
|
2005-05-10 17:15:50 +02:00
|
|
|
if (table)
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
2008-06-25 14:03:08 +02:00
|
|
|
reply->atom = add_atom( table, &name );
|
2005-05-10 17:15:50 +02:00
|
|
|
release_object( table );
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* delete a global atom */
|
|
|
|
DECL_HANDLER(delete_atom)
|
|
|
|
{
|
2005-07-07 13:29:23 +02:00
|
|
|
struct atom_table *table = get_table( req->table, 0 );
|
2005-05-10 17:15:50 +02:00
|
|
|
if (table)
|
|
|
|
{
|
2005-05-14 13:11:21 +02:00
|
|
|
delete_atom( table, req->atom, 0 );
|
2005-05-10 17:15:50 +02:00
|
|
|
release_object( table );
|
|
|
|
}
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find a global atom */
|
|
|
|
DECL_HANDLER(find_atom)
|
|
|
|
{
|
2016-01-29 08:36:45 +01:00
|
|
|
struct unicode_str name = get_req_unicode_str();
|
2005-07-07 13:29:23 +02:00
|
|
|
struct atom_table *table = get_table( req->table, 0 );
|
2008-06-25 14:03:08 +02:00
|
|
|
|
2005-05-10 17:15:50 +02:00
|
|
|
if (table)
|
|
|
|
{
|
2008-06-25 14:03:08 +02:00
|
|
|
reply->atom = find_atom( table, &name );
|
2005-05-10 17:15:50 +02:00
|
|
|
release_object( table );
|
|
|
|
}
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get global atom name */
|
2005-05-10 17:15:50 +02:00
|
|
|
DECL_HANDLER(get_atom_information)
|
2000-02-13 14:56:13 +01:00
|
|
|
{
|
2005-07-07 13:29:23 +02:00
|
|
|
struct atom_table *table = get_table( req->table, 0 );
|
2005-05-10 17:15:50 +02:00
|
|
|
if (table)
|
|
|
|
{
|
|
|
|
struct atom_entry *entry;
|
2001-11-30 19:46:42 +01:00
|
|
|
|
2005-05-10 17:15:50 +02:00
|
|
|
if ((entry = get_atom_entry( table, req->atom )))
|
|
|
|
{
|
2008-06-25 14:03:08 +02:00
|
|
|
set_reply_data( entry->str, min( entry->len, get_reply_max_size() ));
|
2005-05-10 17:15:50 +02:00
|
|
|
reply->count = entry->count;
|
|
|
|
reply->pinned = entry->pinned;
|
2008-06-25 14:03:08 +02:00
|
|
|
reply->total = entry->len;
|
2005-05-10 17:15:50 +02:00
|
|
|
}
|
|
|
|
else reply->count = -1;
|
|
|
|
release_object( table );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set global atom name */
|
|
|
|
DECL_HANDLER(set_atom_information)
|
|
|
|
{
|
2005-07-07 13:29:23 +02:00
|
|
|
struct atom_table *table = get_table( req->table, 0 );
|
2005-05-10 17:15:50 +02:00
|
|
|
if (table)
|
2001-11-30 19:46:42 +01:00
|
|
|
{
|
2005-05-10 17:15:50 +02:00
|
|
|
struct atom_entry *entry;
|
|
|
|
|
|
|
|
if ((entry = get_atom_entry( table, req->atom )))
|
|
|
|
{
|
|
|
|
if (req->pinned) entry->pinned = 1;
|
|
|
|
}
|
|
|
|
release_object( table );
|
2001-11-30 19:46:42 +01:00
|
|
|
}
|
2000-05-30 22:32:06 +02:00
|
|
|
}
|
|
|
|
|
2005-05-10 17:15:50 +02:00
|
|
|
/* init a (local) atom table */
|
2000-05-30 22:32:06 +02:00
|
|
|
DECL_HANDLER(init_atom_table)
|
|
|
|
{
|
2005-05-11 20:25:27 +02:00
|
|
|
struct atom_table* table = create_table( req->entries );
|
2005-05-10 17:15:50 +02:00
|
|
|
|
2005-05-11 20:25:27 +02:00
|
|
|
if (table)
|
|
|
|
{
|
2005-12-09 13:58:25 +01:00
|
|
|
reply->table = alloc_handle( current->process, table, 0, 0 );
|
2005-05-11 20:25:27 +02:00
|
|
|
release_object( table );
|
|
|
|
}
|
2005-05-10 17:15:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set global atom name */
|
|
|
|
DECL_HANDLER(empty_atom_table)
|
|
|
|
{
|
2005-07-07 13:29:23 +02:00
|
|
|
struct atom_table *table = get_table( req->table, 1 );
|
2005-05-10 17:15:50 +02:00
|
|
|
if (table)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct atom_entry *entry;
|
|
|
|
|
|
|
|
for (i = 0; i <= table->last; i++)
|
|
|
|
{
|
|
|
|
entry = table->handles[i];
|
|
|
|
if (entry && (!entry->pinned || req->if_pinned))
|
|
|
|
{
|
|
|
|
if (entry->next) entry->next->prev = entry->prev;
|
|
|
|
if (entry->prev) entry->prev->next = entry->next;
|
|
|
|
else table->entries[entry->hash] = entry->next;
|
|
|
|
table->handles[i] = NULL;
|
|
|
|
free( entry );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
release_object( table );
|
|
|
|
}
|
2000-02-13 14:56:13 +01:00
|
|
|
}
|